Update npm packages (73 packages including @jqhtml 2.3.36)
Update npm registry domain from privatenpm.hanson.xyz to npm.internal.hanson.xyz 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
64
node_modules/webpack/lib/dependencies/ImportMetaPlugin.js
generated
vendored
64
node_modules/webpack/lib/dependencies/ImportMetaPlugin.js
generated
vendored
@@ -28,6 +28,7 @@ const propertyAccess = require("../util/propertyAccess");
|
||||
const ConstDependency = require("./ConstDependency");
|
||||
|
||||
/** @typedef {import("estree").MemberExpression} MemberExpression */
|
||||
/** @typedef {import("estree").Identifier} Identifier */
|
||||
/** @typedef {import("../../declarations/WebpackOptions").JavascriptParserOptions} JavascriptParserOptions */
|
||||
/** @typedef {import("../Compiler")} Compiler */
|
||||
/** @typedef {import("../Dependency").DependencyLocation} DependencyLocation */
|
||||
@@ -44,18 +45,24 @@ const getCriticalDependencyWarning = memoize(() =>
|
||||
|
||||
const PLUGIN_NAME = "ImportMetaPlugin";
|
||||
|
||||
/** @type {WeakMap<Compilation, { stringify: string, env: Record<string, string> }>} */
|
||||
const compilationMetaEnvMap = new WeakMap();
|
||||
|
||||
/**
|
||||
* Collect import.meta.env definitions from DefinePlugin and build JSON string
|
||||
* @param {Compilation} compilation the compilation
|
||||
* @returns {string} env object as JSON string
|
||||
* @returns {{ stringify: string, env: Record<string, string> }} env object as JSON string
|
||||
*/
|
||||
const collectImportMetaEnvDefinitions = (compilation) => {
|
||||
const definePluginHooks = DefinePlugin.getCompilationHooks(compilation);
|
||||
const definitions = definePluginHooks.definitions.call({});
|
||||
if (!definitions) {
|
||||
return "{}";
|
||||
const cached = compilationMetaEnvMap.get(compilation);
|
||||
if (cached) {
|
||||
return cached;
|
||||
}
|
||||
|
||||
const definePluginHooks = DefinePlugin.getCompilationHooks(compilation);
|
||||
const definitions = definePluginHooks.definitions.call({});
|
||||
/** @type {Record<string, string>} */
|
||||
const env = {};
|
||||
/** @type {string[]} */
|
||||
const pairs = [];
|
||||
for (const key of Object.keys(definitions)) {
|
||||
@@ -63,10 +70,12 @@ const collectImportMetaEnvDefinitions = (compilation) => {
|
||||
const envKey = key.slice("import.meta.env.".length);
|
||||
const value = definitions[key];
|
||||
pairs.push(`${JSON.stringify(envKey)}:${value}`);
|
||||
env[envKey] = /** @type {string} */ (value);
|
||||
}
|
||||
}
|
||||
|
||||
return `{${pairs.join(",")}}`;
|
||||
const result = { stringify: `{${pairs.join(",")}}`, env };
|
||||
compilationMetaEnvMap.set(compilation, result);
|
||||
return result;
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -148,10 +157,15 @@ class ImportMetaPlugin {
|
||||
* @param {Members} members members
|
||||
* @returns {string} error message
|
||||
*/
|
||||
const importMetaUnknownProperty = (members) =>
|
||||
`${Template.toNormalComment(
|
||||
const importMetaUnknownProperty = (members) => {
|
||||
if (importMeta === "preserve-unknown") {
|
||||
return `import.meta${propertyAccess(members, 0)}`;
|
||||
}
|
||||
return `${Template.toNormalComment(
|
||||
`unsupported import.meta.${members.join(".")}`
|
||||
)} undefined${propertyAccess(members, 1)}`;
|
||||
};
|
||||
|
||||
parser.hooks.typeof
|
||||
.for("import.meta")
|
||||
.tap(
|
||||
@@ -223,6 +237,9 @@ class ImportMetaPlugin {
|
||||
RuntimeGlobals.module
|
||||
);
|
||||
break;
|
||||
case "env":
|
||||
str += `env: ${collectImportMetaEnvDefinitions(compilation).stringify},`;
|
||||
break;
|
||||
default:
|
||||
str += `[${JSON.stringify(
|
||||
prop.id
|
||||
@@ -327,12 +344,31 @@ class ImportMetaPlugin {
|
||||
PLUGIN_NAME,
|
||||
toConstantDependency(parser, JSON.stringify("object"))
|
||||
);
|
||||
parser.hooks.expressionMemberChain
|
||||
.for("import.meta")
|
||||
.tap(PLUGIN_NAME, (expr, members) => {
|
||||
if (members[0] === "env" && members[1]) {
|
||||
const name = members[1];
|
||||
const { env } = collectImportMetaEnvDefinitions(compilation);
|
||||
if (!Object.prototype.hasOwnProperty.call(env, name)) {
|
||||
const dep = new ConstDependency(
|
||||
"undefined",
|
||||
/** @type {Range} */ (expr.range)
|
||||
);
|
||||
dep.loc = /** @type {DependencyLocation} */ (expr.loc);
|
||||
parser.state.module.addPresentationalDependency(dep);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
});
|
||||
parser.hooks.expression
|
||||
.for("import.meta.env")
|
||||
.tap(PLUGIN_NAME, (expr) => {
|
||||
const envCode = collectImportMetaEnvDefinitions(compilation);
|
||||
const { stringify } =
|
||||
collectImportMetaEnvDefinitions(compilation);
|
||||
|
||||
const dep = new ConstDependency(
|
||||
envCode,
|
||||
stringify,
|
||||
/** @type {Range} */ (expr.range)
|
||||
);
|
||||
dep.loc = /** @type {DependencyLocation} */ (expr.loc);
|
||||
@@ -355,6 +391,11 @@ class ImportMetaPlugin {
|
||||
parser.hooks.unhandledExpressionMemberChain
|
||||
.for("import.meta")
|
||||
.tap(PLUGIN_NAME, (expr, members) => {
|
||||
// unknown import.meta properties should be determined at runtime
|
||||
if (importMeta === "preserve-unknown") {
|
||||
return true;
|
||||
}
|
||||
|
||||
// keep import.meta.env unknown property
|
||||
// don't evaluate import.meta.env.UNKNOWN_PROPERTY -> undefined.UNKNOWN_PROPERTY
|
||||
// `dirname` and `filename` logic in NodeStuffPlugin
|
||||
@@ -373,6 +414,7 @@ class ImportMetaPlugin {
|
||||
parser.state.module.addPresentationalDependency(dep);
|
||||
return true;
|
||||
});
|
||||
|
||||
parser.hooks.evaluate
|
||||
.for("MemberExpression")
|
||||
.tap(PLUGIN_NAME, (expression) => {
|
||||
|
||||
Reference in New Issue
Block a user