webpack 5.102.1 → 5.103.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +121 -134
- package/lib/CompatibilityPlugin.js +25 -2
- package/lib/Compilation.js +25 -2
- package/lib/ConcatenationScope.js +0 -15
- package/lib/CssModule.js +6 -1
- package/lib/DefinePlugin.js +11 -11
- package/lib/Dependency.js +8 -1
- package/lib/DependencyTemplate.js +1 -0
- package/lib/DotenvPlugin.js +457 -0
- package/lib/EnvironmentPlugin.js +19 -16
- package/lib/EvalSourceMapDevToolPlugin.js +16 -0
- package/lib/ExportsInfo.js +6 -2
- package/lib/ExternalModule.js +20 -28
- package/lib/ExternalModuleFactoryPlugin.js +10 -8
- package/lib/ExternalsPlugin.js +2 -1
- package/lib/ManifestPlugin.js +235 -0
- package/lib/Module.js +3 -0
- package/lib/ModuleGraph.js +2 -1
- package/lib/ModuleSourceTypesConstants.js +0 -6
- package/lib/MultiCompiler.js +1 -1
- package/lib/NodeStuffPlugin.js +419 -121
- package/lib/NormalModule.js +17 -16
- package/lib/RuntimeGlobals.js +22 -4
- package/lib/RuntimePlugin.js +27 -6
- package/lib/RuntimeTemplate.js +115 -56
- package/lib/SourceMapDevToolPlugin.js +20 -0
- package/lib/WebpackOptionsApply.js +33 -9
- package/lib/asset/AssetBytesGenerator.js +1 -1
- package/lib/asset/AssetGenerator.js +1 -2
- package/lib/asset/AssetSourceGenerator.js +1 -1
- package/lib/config/browserslistTargetHandler.js +5 -0
- package/lib/config/defaults.js +98 -18
- package/lib/config/normalization.js +2 -1
- package/lib/config/target.js +6 -0
- package/lib/css/CssGenerator.js +283 -57
- package/lib/css/CssLoadingRuntimeModule.js +2 -0
- package/lib/css/CssMergeStyleSheetsRuntimeModule.js +56 -0
- package/lib/css/CssModulesPlugin.js +84 -34
- package/lib/css/CssParser.js +1174 -667
- package/lib/css/walkCssTokens.js +97 -0
- package/lib/dependencies/CommonJsImportsParserPlugin.js +0 -9
- package/lib/dependencies/CommonJsPlugin.js +12 -0
- package/lib/dependencies/CssIcssExportDependency.js +247 -8
- package/lib/dependencies/CssIcssFromIdentifierDependency.js +124 -0
- package/lib/dependencies/CssIcssGlobalIdentifierDependency.js +48 -0
- package/lib/dependencies/CssIcssImportDependency.js +60 -54
- package/lib/dependencies/CssIcssLocalIdentifierDependency.js +61 -0
- package/lib/dependencies/{CssSelfLocalIdentifierDependency.js → CssIcssSelfLocalIdentifierDependency.js} +88 -10
- package/lib/dependencies/CssIcssSymbolDependency.js +31 -29
- package/lib/dependencies/CssImportDependency.js +15 -5
- package/lib/dependencies/ExternalModuleInitFragment.js +1 -1
- package/lib/dependencies/ExternalModuleInitFragmentDependency.js +95 -0
- package/lib/dependencies/HarmonyAcceptDependency.js +6 -1
- package/lib/dependencies/HarmonyAcceptImportDependency.js +2 -1
- package/lib/dependencies/HarmonyEvaluatedImportSpecifierDependency.js +12 -1
- package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +32 -21
- package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +12 -8
- package/lib/dependencies/HarmonyImportDependency.js +23 -27
- package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +28 -69
- package/lib/dependencies/HarmonyImportSideEffectDependency.js +4 -3
- package/lib/dependencies/HarmonyImportSpecifierDependency.js +10 -8
- package/lib/dependencies/ImportDependency.js +8 -2
- package/lib/dependencies/ImportEagerDependency.js +6 -3
- package/lib/dependencies/ImportMetaPlugin.js +97 -9
- package/lib/dependencies/ImportParserPlugin.js +19 -21
- package/lib/dependencies/ImportPhase.js +121 -0
- package/lib/dependencies/ImportWeakDependency.js +6 -3
- package/lib/dependencies/ModuleDependency.js +5 -1
- package/lib/dependencies/ModuleHotAcceptDependency.js +1 -1
- package/lib/esm/ExportWebpackRequireRuntimeModule.js +1 -8
- package/lib/hmr/LazyCompilationPlugin.js +1 -0
- package/lib/ids/IdHelpers.js +4 -1
- package/lib/index.js +6 -0
- package/lib/javascript/ChunkHelpers.js +16 -5
- package/lib/javascript/JavascriptGenerator.js +101 -101
- package/lib/javascript/JavascriptModulesPlugin.js +23 -13
- package/lib/javascript/JavascriptParser.js +142 -38
- package/lib/json/JsonParser.js +7 -1
- package/lib/library/ModuleLibraryPlugin.js +0 -10
- package/lib/library/SystemLibraryPlugin.js +4 -0
- package/lib/library/UmdLibraryPlugin.js +1 -1
- package/lib/node/NodeTargetPlugin.js +9 -1
- package/lib/node/ReadFileCompileWasmPlugin.js +0 -2
- package/lib/optimize/ConcatenatedModule.js +161 -135
- package/lib/runtime/AsyncModuleRuntimeModule.js +28 -18
- package/lib/runtime/AutoPublicPathRuntimeModule.js +8 -3
- package/lib/runtime/MakeDeferredNamespaceObjectRuntime.js +89 -55
- package/lib/util/comparators.js +4 -3
- package/lib/util/internalSerializables.js +4 -4
- package/lib/util/jsonParseEvenBetterErrors.js +10 -0
- package/lib/wasm/EnableWasmLoadingPlugin.js +10 -4
- package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +8 -5
- package/lib/wasm-sync/WebAssemblyJavascriptGenerator.js +8 -4
- package/lib/web/FetchCompileWasmPlugin.js +0 -2
- package/lib/webpack.js +85 -82
- package/module.d.ts +5 -0
- package/package.json +16 -14
- package/schemas/WebpackOptions.check.js +1 -1
- package/schemas/WebpackOptions.json +109 -27
- package/schemas/plugins/ManifestPlugin.check.d.ts +7 -0
- package/schemas/plugins/ManifestPlugin.check.js +6 -0
- package/schemas/plugins/ManifestPlugin.json +98 -0
- package/schemas/plugins/SourceMapDevToolPlugin.check.js +1 -1
- package/schemas/plugins/SourceMapDevToolPlugin.json +16 -3
- package/schemas/plugins/container/ContainerReferencePlugin.check.js +1 -1
- package/schemas/plugins/container/ContainerReferencePlugin.json +4 -1
- package/schemas/plugins/container/ExternalsType.check.js +1 -1
- package/schemas/plugins/container/ModuleFederationPlugin.check.js +1 -1
- package/schemas/plugins/container/ModuleFederationPlugin.json +4 -1
- package/schemas/plugins/css/CssAutoParserOptions.check.js +1 -1
- package/schemas/plugins/css/CssGlobalGeneratorOptions.check.js +1 -1
- package/schemas/plugins/css/CssGlobalParserOptions.check.js +1 -1
- package/schemas/plugins/css/CssModuleGeneratorOptions.check.js +1 -1
- package/schemas/plugins/css/CssModuleParserOptions.check.js +1 -1
- package/schemas/plugins/css/CssParserOptions.check.js +1 -1
- package/schemas/plugins/json/JsonModulesPluginParser.check.js +1 -1
- package/types.d.ts +560 -293
- package/lib/dependencies/CssLocalIdentifierDependency.js +0 -250
|
@@ -164,6 +164,10 @@ class SystemLibraryPlugin extends AbstractLibraryPlugin {
|
|
|
164
164
|
`Object.defineProperty(${external}, "__esModule", { value: true });`
|
|
165
165
|
);
|
|
166
166
|
}
|
|
167
|
+
// See comment above
|
|
168
|
+
instructions.push(
|
|
169
|
+
`${external}["default"] = module["default"] || module;`
|
|
170
|
+
);
|
|
167
171
|
if (handledNames.length > 0) {
|
|
168
172
|
const name = `${external}handledNames`;
|
|
169
173
|
externalVarInitialization.push(
|
|
@@ -338,7 +338,7 @@ class UmdLibraryPlugin extends AbstractLibraryPlugin {
|
|
|
338
338
|
: " var a = factory();\n"
|
|
339
339
|
} for(var i in a) (typeof exports === 'object' ? exports : root)[i] = a[i];\n` +
|
|
340
340
|
" }\n"
|
|
341
|
-
}})(${runtimeTemplate.
|
|
341
|
+
}})(${runtimeTemplate.globalObject}, ${
|
|
342
342
|
runtimeTemplate.supportsArrowFunction()
|
|
343
343
|
? `(${externalsArguments(externals)}) =>`
|
|
344
344
|
: `function(${externalsArguments(externals)})`
|
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
|
|
8
8
|
const ExternalsPlugin = require("../ExternalsPlugin");
|
|
9
9
|
|
|
10
|
+
/** @typedef {import("../../declarations/WebpackOptions").ExternalsType} ExternalsType */
|
|
10
11
|
/** @typedef {import("../Compiler")} Compiler */
|
|
11
12
|
|
|
12
13
|
const builtins = [
|
|
@@ -72,13 +73,20 @@ const builtins = [
|
|
|
72
73
|
];
|
|
73
74
|
|
|
74
75
|
class NodeTargetPlugin {
|
|
76
|
+
/**
|
|
77
|
+
* @param {ExternalsType} type default external type
|
|
78
|
+
*/
|
|
79
|
+
constructor(type = "node-commonjs") {
|
|
80
|
+
this.type = type;
|
|
81
|
+
}
|
|
82
|
+
|
|
75
83
|
/**
|
|
76
84
|
* Apply the plugin
|
|
77
85
|
* @param {Compiler} compiler the compiler instance
|
|
78
86
|
* @returns {void}
|
|
79
87
|
*/
|
|
80
88
|
apply(compiler) {
|
|
81
|
-
new ExternalsPlugin(
|
|
89
|
+
new ExternalsPlugin(this.type, builtins).apply(compiler);
|
|
82
90
|
}
|
|
83
91
|
}
|
|
84
92
|
|
|
@@ -22,8 +22,7 @@ const RuntimeGlobals = require("../RuntimeGlobals");
|
|
|
22
22
|
const Template = require("../Template");
|
|
23
23
|
const { DEFAULTS } = require("../config/defaults");
|
|
24
24
|
const HarmonyImportDependency = require("../dependencies/HarmonyImportDependency");
|
|
25
|
-
const
|
|
26
|
-
const HarmonyImportSpecifierDependency = require("../dependencies/HarmonyImportSpecifierDependency");
|
|
25
|
+
const { ImportPhaseUtils } = require("../dependencies/ImportPhase");
|
|
27
26
|
const JavascriptParser = require("../javascript/JavascriptParser");
|
|
28
27
|
const {
|
|
29
28
|
getMakeDeferredNamespaceModeFromExportsType,
|
|
@@ -167,6 +166,7 @@ if (!ReferencerClass.prototype.PropertyDefinition) {
|
|
|
167
166
|
* @property {"external"} type
|
|
168
167
|
* @property {Module} module
|
|
169
168
|
* @property {RuntimeSpec | boolean} runtimeCondition
|
|
169
|
+
* @property {NonDeferAccess} nonDeferAccess
|
|
170
170
|
* @property {number} index
|
|
171
171
|
* @property {string | undefined} name module.exports / harmony namespace object
|
|
172
172
|
* @property {string | undefined} deferredName deferred module.exports / harmony namespace object
|
|
@@ -185,6 +185,7 @@ if (!ReferencerClass.prototype.PropertyDefinition) {
|
|
|
185
185
|
* @typedef {object} ReferenceToModuleInfo
|
|
186
186
|
* @property {"reference"} type
|
|
187
187
|
* @property {RuntimeSpec | boolean} runtimeCondition
|
|
188
|
+
* @property {NonDeferAccess} nonDeferAccess
|
|
188
189
|
* @property {ModuleInfo} target
|
|
189
190
|
*/
|
|
190
191
|
|
|
@@ -223,16 +224,6 @@ const compareNumbers = (a, b) => {
|
|
|
223
224
|
};
|
|
224
225
|
const bySourceOrder = createComparator("sourceOrder", compareNumbers);
|
|
225
226
|
const byRangeStart = createComparator("rangeStart", compareNumbers);
|
|
226
|
-
const moveDeferToLast = (
|
|
227
|
-
/** @type {{ defer?: boolean }} */ a,
|
|
228
|
-
/** @type {{ defer?: boolean }} */ b
|
|
229
|
-
) => {
|
|
230
|
-
if (a.defer === b.defer) return 0;
|
|
231
|
-
if (a.defer) return 1;
|
|
232
|
-
return -1;
|
|
233
|
-
};
|
|
234
|
-
|
|
235
|
-
const INITIAL_USED_NAMES = new Set(RESERVED_NAMES);
|
|
236
227
|
|
|
237
228
|
/**
|
|
238
229
|
* @param {Iterable<string>} iterable iterable object
|
|
@@ -254,11 +245,28 @@ const joinIterableWithComma = (iterable) => {
|
|
|
254
245
|
return str;
|
|
255
246
|
};
|
|
256
247
|
|
|
248
|
+
/** @typedef {boolean} NonDeferAccess */
|
|
249
|
+
|
|
250
|
+
/**
|
|
251
|
+
* @param {NonDeferAccess} a a
|
|
252
|
+
* @param {NonDeferAccess} b b
|
|
253
|
+
* @returns {NonDeferAccess} merged
|
|
254
|
+
*/
|
|
255
|
+
const mergeNonDeferAccess = (a, b) => a || b;
|
|
256
|
+
|
|
257
|
+
/**
|
|
258
|
+
* @param {NonDeferAccess} a first
|
|
259
|
+
* @param {NonDeferAccess} b second
|
|
260
|
+
* @returns {NonDeferAccess} first - second
|
|
261
|
+
*/
|
|
262
|
+
const subtractNonDeferAccess = (a, b) => a && !b;
|
|
263
|
+
|
|
257
264
|
/**
|
|
258
265
|
* @typedef {object} ConcatenationEntry
|
|
259
266
|
* @property {"concatenated" | "external"} type
|
|
260
267
|
* @property {Module} module
|
|
261
268
|
* @property {RuntimeSpec | boolean} runtimeCondition
|
|
269
|
+
* @property {NonDeferAccess} nonDeferAccess
|
|
262
270
|
*/
|
|
263
271
|
|
|
264
272
|
/** @typedef {Set<ConcatenatedModuleInfo>} NeededNamespaceObjects */
|
|
@@ -300,11 +308,11 @@ const getFinalBinding = (
|
|
|
300
308
|
moduleGraph,
|
|
301
309
|
strictHarmonyModule
|
|
302
310
|
);
|
|
303
|
-
const
|
|
304
|
-
depDeferred &&
|
|
311
|
+
const moduleDeferred =
|
|
305
312
|
info.type === "external" &&
|
|
306
313
|
info.deferred &&
|
|
307
|
-
!
|
|
314
|
+
!(/** @type {BuildMeta} */ (info.module.buildMeta).async);
|
|
315
|
+
const deferred = depDeferred && moduleDeferred;
|
|
308
316
|
if (exportName.length === 0) {
|
|
309
317
|
switch (exportsType) {
|
|
310
318
|
case "default-only":
|
|
@@ -391,6 +399,14 @@ const getFinalBinding = (
|
|
|
391
399
|
exportName
|
|
392
400
|
};
|
|
393
401
|
}
|
|
402
|
+
if (moduleDeferred) {
|
|
403
|
+
return {
|
|
404
|
+
info,
|
|
405
|
+
rawName: /** @type {string} */ (info.name),
|
|
406
|
+
ids: exportName,
|
|
407
|
+
exportName
|
|
408
|
+
};
|
|
409
|
+
}
|
|
394
410
|
info.interopDefaultAccessUsed = true;
|
|
395
411
|
const defaultExport = asCall
|
|
396
412
|
? `${info.interopDefaultAccessName}()`
|
|
@@ -951,13 +967,12 @@ class ConcatenatedModule extends Module {
|
|
|
951
967
|
_createConcatenationList(rootModule, modulesSet, runtime, moduleGraph) {
|
|
952
968
|
/** @type {ConcatenationEntry[]} */
|
|
953
969
|
const list = [];
|
|
954
|
-
/** @type {Map<Module, RuntimeSpec | true>} */
|
|
970
|
+
/** @type {Map<Module, { runtimeCondition: RuntimeSpec | true, nonDeferAccess: NonDeferAccess }>} */
|
|
955
971
|
const existingEntries = new Map();
|
|
956
|
-
const deferEnabled = this.compilation.options.experiments.deferImport;
|
|
957
972
|
|
|
958
973
|
/**
|
|
959
974
|
* @param {Module} module a module
|
|
960
|
-
* @returns {Iterable<{ connection: ModuleGraphConnection, runtimeCondition: RuntimeSpec | true }>} imported modules in order
|
|
975
|
+
* @returns {Iterable<{ connection: ModuleGraphConnection, runtimeCondition: RuntimeSpec | true, nonDeferAccess: NonDeferAccess }>} imported modules in order
|
|
961
976
|
*/
|
|
962
977
|
const getConcatenatedImports = (module) => {
|
|
963
978
|
const connections = [...moduleGraph.getOutgoingConnections(module)];
|
|
@@ -987,9 +1002,9 @@ class ConcatenatedModule extends Module {
|
|
|
987
1002
|
(connection.dependency);
|
|
988
1003
|
return {
|
|
989
1004
|
connection,
|
|
990
|
-
sourceOrder: dep.sourceOrder,
|
|
1005
|
+
sourceOrder: /** @type {number} */ (dep.sourceOrder),
|
|
991
1006
|
rangeStart: dep.range && dep.range[0],
|
|
992
|
-
defer: dep.
|
|
1007
|
+
defer: ImportPhaseUtils.isDefer(dep.phase)
|
|
993
1008
|
};
|
|
994
1009
|
});
|
|
995
1010
|
/**
|
|
@@ -1004,27 +1019,27 @@ class ConcatenatedModule extends Module {
|
|
|
1004
1019
|
* a.a(); // first range
|
|
1005
1020
|
* b.b(); // second range
|
|
1006
1021
|
*
|
|
1007
|
-
* If the import is deferred, we always move it to the last.
|
|
1008
1022
|
* If there is no reexport, we have the same source.
|
|
1009
1023
|
* If there is reexport, but module has side effects, this will lead to reexport module only.
|
|
1010
1024
|
* If there is side-effects-free reexport, we can get simple deterministic result with range start comparison.
|
|
1011
1025
|
*/
|
|
1012
1026
|
references.sort(concatComparators(bySourceOrder, byRangeStart));
|
|
1013
|
-
|
|
1014
|
-
// do not combine those two sorts. defer is not the same as source or range which has a comparable number, defer is only moving them.
|
|
1015
|
-
references.sort(moveDeferToLast);
|
|
1016
|
-
}
|
|
1017
|
-
/** @type {Map<Module, { connection: ModuleGraphConnection, runtimeCondition: RuntimeSpec | true }>} */
|
|
1027
|
+
/** @type {Map<Module, { connection: ModuleGraphConnection, runtimeCondition: RuntimeSpec | true, nonDeferAccess: NonDeferAccess }>} */
|
|
1018
1028
|
const referencesMap = new Map();
|
|
1019
|
-
for (const { connection } of references) {
|
|
1029
|
+
for (const { connection, defer } of references) {
|
|
1020
1030
|
const runtimeCondition = filterRuntime(runtime, (r) =>
|
|
1021
1031
|
connection.isTargetActive(r)
|
|
1022
1032
|
);
|
|
1023
1033
|
if (runtimeCondition === false) continue;
|
|
1034
|
+
const nonDeferAccess = !defer;
|
|
1024
1035
|
const module = connection.module;
|
|
1025
1036
|
const entry = referencesMap.get(module);
|
|
1026
1037
|
if (entry === undefined) {
|
|
1027
|
-
referencesMap.set(module, {
|
|
1038
|
+
referencesMap.set(module, {
|
|
1039
|
+
connection,
|
|
1040
|
+
runtimeCondition,
|
|
1041
|
+
nonDeferAccess
|
|
1042
|
+
});
|
|
1028
1043
|
continue;
|
|
1029
1044
|
}
|
|
1030
1045
|
entry.runtimeCondition = mergeRuntimeConditionNonFalse(
|
|
@@ -1032,6 +1047,10 @@ class ConcatenatedModule extends Module {
|
|
|
1032
1047
|
runtimeCondition,
|
|
1033
1048
|
runtime
|
|
1034
1049
|
);
|
|
1050
|
+
entry.nonDeferAccess = mergeNonDeferAccess(
|
|
1051
|
+
entry.nonDeferAccess,
|
|
1052
|
+
nonDeferAccess
|
|
1053
|
+
);
|
|
1035
1054
|
}
|
|
1036
1055
|
return referencesMap.values();
|
|
1037
1056
|
};
|
|
@@ -1039,17 +1058,25 @@ class ConcatenatedModule extends Module {
|
|
|
1039
1058
|
/**
|
|
1040
1059
|
* @param {ModuleGraphConnection} connection graph connection
|
|
1041
1060
|
* @param {RuntimeSpec | true} runtimeCondition runtime condition
|
|
1061
|
+
* @param {NonDeferAccess} nonDeferAccess non-defer access
|
|
1042
1062
|
* @returns {void}
|
|
1043
1063
|
*/
|
|
1044
|
-
const enterModule = (connection, runtimeCondition) => {
|
|
1064
|
+
const enterModule = (connection, runtimeCondition, nonDeferAccess) => {
|
|
1045
1065
|
const module = connection.module;
|
|
1046
1066
|
if (!module) return;
|
|
1047
1067
|
const existingEntry = existingEntries.get(module);
|
|
1048
|
-
if (
|
|
1068
|
+
if (
|
|
1069
|
+
existingEntry &&
|
|
1070
|
+
existingEntry.runtimeCondition === true &&
|
|
1071
|
+
existingEntry.nonDeferAccess === true
|
|
1072
|
+
) {
|
|
1049
1073
|
return;
|
|
1050
1074
|
}
|
|
1051
1075
|
if (modulesSet.has(module)) {
|
|
1052
|
-
existingEntries.set(module,
|
|
1076
|
+
existingEntries.set(module, {
|
|
1077
|
+
runtimeCondition: true,
|
|
1078
|
+
nonDeferAccess: true
|
|
1079
|
+
});
|
|
1053
1080
|
if (runtimeCondition !== true) {
|
|
1054
1081
|
throw new Error(
|
|
1055
1082
|
`Cannot runtime-conditional concatenate a module (${module.identifier()} in ${this.rootModule.identifier()}, ${runtimeConditionToString(
|
|
@@ -1057,34 +1084,66 @@ class ConcatenatedModule extends Module {
|
|
|
1057
1084
|
)}). This should not happen.`
|
|
1058
1085
|
);
|
|
1059
1086
|
}
|
|
1087
|
+
if (nonDeferAccess !== true) {
|
|
1088
|
+
throw new Error(
|
|
1089
|
+
`Cannot deferred concatenate a module (${module.identifier()} in ${this.rootModule.identifier()}. This should not happen.`
|
|
1090
|
+
);
|
|
1091
|
+
}
|
|
1060
1092
|
const imports = getConcatenatedImports(module);
|
|
1061
|
-
for (const {
|
|
1062
|
-
|
|
1093
|
+
for (const {
|
|
1094
|
+
connection,
|
|
1095
|
+
runtimeCondition,
|
|
1096
|
+
nonDeferAccess
|
|
1097
|
+
} of imports) {
|
|
1098
|
+
enterModule(connection, runtimeCondition, nonDeferAccess);
|
|
1063
1099
|
}
|
|
1064
1100
|
list.push({
|
|
1065
1101
|
type: "concatenated",
|
|
1066
1102
|
module: connection.module,
|
|
1067
|
-
runtimeCondition
|
|
1103
|
+
runtimeCondition,
|
|
1104
|
+
nonDeferAccess
|
|
1068
1105
|
});
|
|
1069
1106
|
} else {
|
|
1107
|
+
/** @type {RuntimeSpec | boolean} */
|
|
1108
|
+
let reducedRuntimeCondition;
|
|
1109
|
+
/** @type {NonDeferAccess} */
|
|
1110
|
+
let reducedNonDeferAccess;
|
|
1070
1111
|
if (existingEntry !== undefined) {
|
|
1071
|
-
|
|
1112
|
+
reducedRuntimeCondition = subtractRuntimeCondition(
|
|
1072
1113
|
runtimeCondition,
|
|
1073
|
-
existingEntry,
|
|
1114
|
+
existingEntry.runtimeCondition,
|
|
1074
1115
|
runtime
|
|
1075
1116
|
);
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
connection.module,
|
|
1080
|
-
mergeRuntimeConditionNonFalse(
|
|
1081
|
-
existingEntry,
|
|
1082
|
-
runtimeCondition,
|
|
1083
|
-
runtime
|
|
1084
|
-
)
|
|
1117
|
+
reducedNonDeferAccess = subtractNonDeferAccess(
|
|
1118
|
+
nonDeferAccess,
|
|
1119
|
+
existingEntry.nonDeferAccess
|
|
1085
1120
|
);
|
|
1121
|
+
if (
|
|
1122
|
+
reducedRuntimeCondition === false &&
|
|
1123
|
+
reducedNonDeferAccess === false
|
|
1124
|
+
) {
|
|
1125
|
+
return;
|
|
1126
|
+
}
|
|
1127
|
+
if (reducedRuntimeCondition !== false) {
|
|
1128
|
+
existingEntry.runtimeCondition = mergeRuntimeConditionNonFalse(
|
|
1129
|
+
existingEntry.runtimeCondition,
|
|
1130
|
+
reducedRuntimeCondition,
|
|
1131
|
+
runtime
|
|
1132
|
+
);
|
|
1133
|
+
}
|
|
1134
|
+
if (reducedNonDeferAccess !== false) {
|
|
1135
|
+
existingEntry.nonDeferAccess = mergeNonDeferAccess(
|
|
1136
|
+
existingEntry.nonDeferAccess,
|
|
1137
|
+
reducedNonDeferAccess
|
|
1138
|
+
);
|
|
1139
|
+
}
|
|
1086
1140
|
} else {
|
|
1087
|
-
|
|
1141
|
+
reducedRuntimeCondition = runtimeCondition;
|
|
1142
|
+
reducedNonDeferAccess = nonDeferAccess;
|
|
1143
|
+
existingEntries.set(connection.module, {
|
|
1144
|
+
runtimeCondition,
|
|
1145
|
+
nonDeferAccess
|
|
1146
|
+
});
|
|
1088
1147
|
}
|
|
1089
1148
|
if (list.length > 0) {
|
|
1090
1149
|
const lastItem = list[list.length - 1];
|
|
@@ -1094,9 +1153,13 @@ class ConcatenatedModule extends Module {
|
|
|
1094
1153
|
) {
|
|
1095
1154
|
lastItem.runtimeCondition = mergeRuntimeCondition(
|
|
1096
1155
|
lastItem.runtimeCondition,
|
|
1097
|
-
|
|
1156
|
+
reducedRuntimeCondition,
|
|
1098
1157
|
runtime
|
|
1099
1158
|
);
|
|
1159
|
+
lastItem.nonDeferAccess = mergeNonDeferAccess(
|
|
1160
|
+
lastItem.nonDeferAccess,
|
|
1161
|
+
reducedNonDeferAccess
|
|
1162
|
+
);
|
|
1100
1163
|
return;
|
|
1101
1164
|
}
|
|
1102
1165
|
}
|
|
@@ -1108,20 +1171,25 @@ class ConcatenatedModule extends Module {
|
|
|
1108
1171
|
// concatenated module)
|
|
1109
1172
|
return connection.module;
|
|
1110
1173
|
},
|
|
1111
|
-
runtimeCondition
|
|
1174
|
+
runtimeCondition: reducedRuntimeCondition,
|
|
1175
|
+
nonDeferAccess: reducedNonDeferAccess
|
|
1112
1176
|
});
|
|
1113
1177
|
}
|
|
1114
1178
|
};
|
|
1115
1179
|
|
|
1116
|
-
existingEntries.set(rootModule,
|
|
1180
|
+
existingEntries.set(rootModule, {
|
|
1181
|
+
runtimeCondition: true,
|
|
1182
|
+
nonDeferAccess: true
|
|
1183
|
+
});
|
|
1117
1184
|
const imports = getConcatenatedImports(rootModule);
|
|
1118
|
-
for (const { connection, runtimeCondition } of imports) {
|
|
1119
|
-
enterModule(connection, runtimeCondition);
|
|
1185
|
+
for (const { connection, runtimeCondition, nonDeferAccess } of imports) {
|
|
1186
|
+
enterModule(connection, runtimeCondition, nonDeferAccess);
|
|
1120
1187
|
}
|
|
1121
1188
|
list.push({
|
|
1122
1189
|
type: "concatenated",
|
|
1123
1190
|
module: rootModule,
|
|
1124
|
-
runtimeCondition: true
|
|
1191
|
+
runtimeCondition: true,
|
|
1192
|
+
nonDeferAccess: true
|
|
1125
1193
|
});
|
|
1126
1194
|
|
|
1127
1195
|
return list;
|
|
@@ -1207,18 +1275,8 @@ class ConcatenatedModule extends Module {
|
|
|
1207
1275
|
/** @type {NeededNamespaceObjects} */
|
|
1208
1276
|
const neededNamespaceObjects = new Set();
|
|
1209
1277
|
|
|
1210
|
-
//
|
|
1211
|
-
const allUsedNames = new Set(
|
|
1212
|
-
const chunks = chunkGraph.getModuleChunks(this);
|
|
1213
|
-
|
|
1214
|
-
// Add names already used in the current chunk scope
|
|
1215
|
-
for (const chunk of chunks) {
|
|
1216
|
-
if (ConcatenationScope.chunkUsedNames.has(chunk)) {
|
|
1217
|
-
for (const name of ConcatenationScope.chunkUsedNames.get(chunk) || []) {
|
|
1218
|
-
allUsedNames.add(name);
|
|
1219
|
-
}
|
|
1220
|
-
}
|
|
1221
|
-
}
|
|
1278
|
+
// List of all used names to avoid conflicts
|
|
1279
|
+
const allUsedNames = new Set(RESERVED_NAMES);
|
|
1222
1280
|
|
|
1223
1281
|
// Generate source code and analyse scopes
|
|
1224
1282
|
// Prepare a ReplaceSource for the final source
|
|
@@ -1237,23 +1295,6 @@ class ConcatenatedModule extends Module {
|
|
|
1237
1295
|
);
|
|
1238
1296
|
}
|
|
1239
1297
|
|
|
1240
|
-
// Record the names registered by the current ConcatenatedModule into the chunk scope
|
|
1241
|
-
if (INITIAL_USED_NAMES.size !== allUsedNames.size) {
|
|
1242
|
-
for (const name of allUsedNames) {
|
|
1243
|
-
if (INITIAL_USED_NAMES.has(name)) continue;
|
|
1244
|
-
|
|
1245
|
-
for (const chunk of chunks) {
|
|
1246
|
-
if (!ConcatenationScope.chunkUsedNames.has(chunk)) {
|
|
1247
|
-
ConcatenationScope.chunkUsedNames.set(chunk, new Set([name]));
|
|
1248
|
-
} else {
|
|
1249
|
-
/** @type {Set<string>} */ (
|
|
1250
|
-
ConcatenationScope.chunkUsedNames.get(chunk)
|
|
1251
|
-
).add(name);
|
|
1252
|
-
}
|
|
1253
|
-
}
|
|
1254
|
-
}
|
|
1255
|
-
}
|
|
1256
|
-
|
|
1257
1298
|
// Updated Top level declarations are created by renaming
|
|
1258
1299
|
/** @type {TopLevelDeclarations} */
|
|
1259
1300
|
const topLevelDeclarations = new Set();
|
|
@@ -1837,26 +1878,37 @@ ${defineGetters}`
|
|
|
1837
1878
|
if (info.type === "external" && info.deferred) {
|
|
1838
1879
|
const moduleId = JSON.stringify(chunkGraph.getModuleId(info.module));
|
|
1839
1880
|
const loader = getOptimizedDeferredModule(
|
|
1840
|
-
|
|
1881
|
+
moduleId,
|
|
1841
1882
|
info.module.getExportsType(
|
|
1842
1883
|
moduleGraph,
|
|
1843
1884
|
/** @type {BuildMeta} */
|
|
1844
1885
|
(this.rootModule.buildMeta).strictHarmonyModule
|
|
1845
1886
|
),
|
|
1846
|
-
moduleId,
|
|
1847
1887
|
// an async module will opt-out of the concat module optimization.
|
|
1848
|
-
[]
|
|
1888
|
+
[],
|
|
1889
|
+
runtimeRequirements
|
|
1849
1890
|
);
|
|
1850
1891
|
runtimeRequirements.add(RuntimeGlobals.require);
|
|
1851
1892
|
result.add(
|
|
1852
1893
|
`\n// DEFERRED EXTERNAL MODULE: ${info.module.readableIdentifier(requestShortener)}\nvar ${info.deferredName} = ${loader};`
|
|
1853
1894
|
);
|
|
1895
|
+
if (info.deferredNamespaceObjectUsed) {
|
|
1896
|
+
runtimeRequirements.add(RuntimeGlobals.makeDeferredNamespaceObject);
|
|
1897
|
+
result.add(
|
|
1898
|
+
`\nvar ${info.deferredNamespaceObjectName} = /*#__PURE__*/${
|
|
1899
|
+
RuntimeGlobals.makeDeferredNamespaceObject
|
|
1900
|
+
}(${JSON.stringify(
|
|
1901
|
+
chunkGraph.getModuleId(info.module)
|
|
1902
|
+
)}, ${getMakeDeferredNamespaceModeFromExportsType(
|
|
1903
|
+
info.module.getExportsType(moduleGraph, strictHarmonyModule)
|
|
1904
|
+
)});`
|
|
1905
|
+
);
|
|
1906
|
+
}
|
|
1854
1907
|
}
|
|
1855
1908
|
}
|
|
1856
1909
|
|
|
1857
1910
|
/** @type {InitFragment<ChunkRenderContext>[]} */
|
|
1858
1911
|
const chunkInitFragments = [];
|
|
1859
|
-
const deferEnabled = this.compilation.options.experiments.deferImport;
|
|
1860
1912
|
|
|
1861
1913
|
// evaluate modules in order
|
|
1862
1914
|
for (const rawInfo of modulesWithInfo) {
|
|
@@ -1868,41 +1920,6 @@ ${defineGetters}`
|
|
|
1868
1920
|
result.add(
|
|
1869
1921
|
`\n;// ${info.module.readableIdentifier(requestShortener)}\n`
|
|
1870
1922
|
);
|
|
1871
|
-
// If a module is deferred in other places, but used as non-deferred here,
|
|
1872
|
-
// the module itself will be emitted as mod_deferred (in the case "external"),
|
|
1873
|
-
// we need to emit an extra import declaration to evaluate it in order.
|
|
1874
|
-
if (deferEnabled) {
|
|
1875
|
-
for (const dep of info.module.dependencies) {
|
|
1876
|
-
if (
|
|
1877
|
-
!(/** @type {HarmonyImportDependency} */ (dep).defer) &&
|
|
1878
|
-
(dep instanceof HarmonyImportSideEffectDependency ||
|
|
1879
|
-
dep instanceof HarmonyImportSpecifierDependency)
|
|
1880
|
-
) {
|
|
1881
|
-
const referredModule = moduleGraph.getModule(dep);
|
|
1882
|
-
if (!referredModule) {
|
|
1883
|
-
if (dep instanceof HarmonyImportSideEffectDependency) {
|
|
1884
|
-
continue;
|
|
1885
|
-
} else {
|
|
1886
|
-
throw new Error(
|
|
1887
|
-
"Deferred module used, but no module in the graph."
|
|
1888
|
-
);
|
|
1889
|
-
}
|
|
1890
|
-
}
|
|
1891
|
-
if (moduleGraph.isDeferred(referredModule)) {
|
|
1892
|
-
const deferredModuleInfo = /** @type {ExternalModuleInfo} */ (
|
|
1893
|
-
modulesWithInfo.find(
|
|
1894
|
-
(i) =>
|
|
1895
|
-
i.type === "external" && i.module === referredModule
|
|
1896
|
-
)
|
|
1897
|
-
);
|
|
1898
|
-
if (!deferredModuleInfo) continue;
|
|
1899
|
-
result.add(
|
|
1900
|
-
`\n// non-deferred import to a deferred module (${referredModule.readableIdentifier(requestShortener)})\nvar ${deferredModuleInfo.name} = ${deferredModuleInfo.deferredName}.a;`
|
|
1901
|
-
);
|
|
1902
|
-
}
|
|
1903
|
-
}
|
|
1904
|
-
}
|
|
1905
|
-
}
|
|
1906
1923
|
result.add(/** @type {ReplaceSource} */ (info.source));
|
|
1907
1924
|
if (info.chunkInitFragments) {
|
|
1908
1925
|
for (const f of info.chunkInitFragments) chunkInitFragments.push(f);
|
|
@@ -1943,24 +1960,23 @@ ${defineGetters}`
|
|
|
1943
1960
|
result.add(`var ${info.name} = __webpack_require__(${moduleId});`);
|
|
1944
1961
|
name = info.name;
|
|
1945
1962
|
}
|
|
1963
|
+
// If a module is deferred in other places, but used as non-deferred here,
|
|
1964
|
+
// the module itself will be emitted as mod_deferred (in the case "external"),
|
|
1965
|
+
// we need to emit an extra import declaration to evaluate it in order.
|
|
1966
|
+
const { nonDeferAccess } =
|
|
1967
|
+
/** @type {ExternalModuleInfo | ReferenceToModuleInfo} */
|
|
1968
|
+
(rawInfo);
|
|
1969
|
+
if (info.deferred && nonDeferAccess) {
|
|
1970
|
+
result.add(
|
|
1971
|
+
`\n// non-deferred import to a deferred module (${info.module.readableIdentifier(requestShortener)})\nvar ${info.name} = ${info.deferredName}.a;`
|
|
1972
|
+
);
|
|
1973
|
+
}
|
|
1946
1974
|
break;
|
|
1947
1975
|
}
|
|
1948
1976
|
default:
|
|
1949
1977
|
// @ts-expect-error never is expected here
|
|
1950
1978
|
throw new Error(`Unsupported concatenation entry type ${info.type}`);
|
|
1951
1979
|
}
|
|
1952
|
-
if (info.type === "external" && info.deferredNamespaceObjectUsed) {
|
|
1953
|
-
runtimeRequirements.add(RuntimeGlobals.makeDeferredNamespaceObject);
|
|
1954
|
-
result.add(
|
|
1955
|
-
`\nvar ${info.deferredNamespaceObjectName} = /*#__PURE__*/${
|
|
1956
|
-
RuntimeGlobals.makeDeferredNamespaceObject
|
|
1957
|
-
}(${JSON.stringify(
|
|
1958
|
-
chunkGraph.getModuleId(info.module)
|
|
1959
|
-
)}, ${getMakeDeferredNamespaceModeFromExportsType(
|
|
1960
|
-
info.module.getExportsType(moduleGraph, strictHarmonyModule)
|
|
1961
|
-
)});`
|
|
1962
|
-
);
|
|
1963
|
-
}
|
|
1964
1980
|
if (info.interopNamespaceObjectUsed) {
|
|
1965
1981
|
runtimeRequirements.add(RuntimeGlobals.createFakeNamespaceObject);
|
|
1966
1982
|
result.add(
|
|
@@ -2049,11 +2065,19 @@ ${defineGetters}`
|
|
|
2049
2065
|
const data = codeGenResult.data;
|
|
2050
2066
|
const chunkInitFragments = data && data.get("chunkInitFragments");
|
|
2051
2067
|
const code = source.source().toString();
|
|
2068
|
+
|
|
2069
|
+
/** @type {Program} */
|
|
2052
2070
|
let ast;
|
|
2071
|
+
|
|
2053
2072
|
try {
|
|
2054
|
-
ast = JavascriptParser._parse(
|
|
2055
|
-
|
|
2056
|
-
|
|
2073
|
+
({ ast } = JavascriptParser._parse(
|
|
2074
|
+
code,
|
|
2075
|
+
{
|
|
2076
|
+
sourceType: "module",
|
|
2077
|
+
ranges: true
|
|
2078
|
+
},
|
|
2079
|
+
JavascriptParser._getModuleParseFunction(this.compilation, m)
|
|
2080
|
+
));
|
|
2057
2081
|
} catch (_err) {
|
|
2058
2082
|
const err =
|
|
2059
2083
|
/** @type {Error & { loc?: { line: number, column: number } }} */
|
|
@@ -2148,6 +2172,7 @@ ${defineGetters}`
|
|
|
2148
2172
|
type: "external",
|
|
2149
2173
|
module: info.module,
|
|
2150
2174
|
runtimeCondition: info.runtimeCondition,
|
|
2175
|
+
nonDeferAccess: info.nonDeferAccess,
|
|
2151
2176
|
index,
|
|
2152
2177
|
name: undefined,
|
|
2153
2178
|
deferredName: undefined,
|
|
@@ -2177,6 +2202,7 @@ ${defineGetters}`
|
|
|
2177
2202
|
const ref = {
|
|
2178
2203
|
type: "reference",
|
|
2179
2204
|
runtimeCondition: info.runtimeCondition,
|
|
2205
|
+
nonDeferAccess: info.nonDeferAccess,
|
|
2180
2206
|
target: item
|
|
2181
2207
|
};
|
|
2182
2208
|
return ref;
|
|
@@ -35,10 +35,28 @@ class AsyncModuleRuntimeModule extends HelperRuntimeModule {
|
|
|
35
35
|
}hasSymbol ? Symbol("webpack exports") : "${RuntimeGlobals.exports}";`,
|
|
36
36
|
'var webpackError = hasSymbol ? Symbol("webpack error") : "__webpack_error__";',
|
|
37
37
|
defer
|
|
38
|
-
?
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
38
|
+
? Template.asString([
|
|
39
|
+
`var webpackDone = ${RuntimeGlobals.asyncModuleDoneSymbol} = hasSymbol ? Symbol("webpack done") : "__webpack_done__";`,
|
|
40
|
+
`var webpackDefer = ${RuntimeGlobals.deferredModuleAsyncTransitiveDependenciesSymbol} = hasSymbol ? Symbol("webpack defer") : "__webpack_defer__";`,
|
|
41
|
+
`${RuntimeGlobals.deferredModuleAsyncTransitiveDependencies} = ${runtimeTemplate.basicFunction(
|
|
42
|
+
"asyncDeps",
|
|
43
|
+
[
|
|
44
|
+
Template.indent([
|
|
45
|
+
"var hasUnresolvedAsyncSubgraph = asyncDeps.some((id) => {",
|
|
46
|
+
Template.indent([
|
|
47
|
+
"var cache = __webpack_module_cache__[id];",
|
|
48
|
+
"return !cache || cache[webpackDone] === false;"
|
|
49
|
+
]),
|
|
50
|
+
"});",
|
|
51
|
+
"if (hasUnresolvedAsyncSubgraph) {",
|
|
52
|
+
Template.indent([
|
|
53
|
+
"return ({ then(onFulfilled, onRejected) { return Promise.all(asyncDeps.map(__webpack_require__)).then(onFulfilled, onRejected) } })"
|
|
54
|
+
]),
|
|
55
|
+
"}"
|
|
56
|
+
])
|
|
57
|
+
]
|
|
58
|
+
)}`
|
|
59
|
+
])
|
|
42
60
|
: "",
|
|
43
61
|
`var resolveQueue = ${runtimeTemplate.basicFunction("queue", [
|
|
44
62
|
"if(queue && queue.d < 1) {",
|
|
@@ -63,25 +81,17 @@ class AsyncModuleRuntimeModule extends HelperRuntimeModule {
|
|
|
63
81
|
? Template.asString([
|
|
64
82
|
"if(!dep[webpackQueues] && dep[webpackDefer]) {",
|
|
65
83
|
Template.indent([
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
"id",
|
|
69
|
-
[
|
|
70
|
-
"var cache = __webpack_module_cache__[id];",
|
|
71
|
-
"return !cache || cache[webpackDone] === false;"
|
|
72
|
-
]
|
|
73
|
-
)});`,
|
|
74
|
-
"if (hasUnresolvedAsyncSubgraph) {",
|
|
84
|
+
`var asyncDeps = ${RuntimeGlobals.deferredModuleAsyncTransitiveDependencies}(dep[webpackDefer]);`,
|
|
85
|
+
"if (asyncDeps) {",
|
|
75
86
|
Template.indent([
|
|
76
87
|
"var d = dep;",
|
|
77
88
|
"dep = {",
|
|
78
89
|
Template.indent([
|
|
79
|
-
"then(
|
|
90
|
+
"then(onFulfilled, onRejected) {",
|
|
80
91
|
Template.indent([
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
)});`
|
|
92
|
+
`asyncDeps.then(${runtimeTemplate.returningFunction(
|
|
93
|
+
"onFulfilled(d)"
|
|
94
|
+
)}, onRejected);`
|
|
85
95
|
]),
|
|
86
96
|
"}"
|
|
87
97
|
]),
|
|
@@ -23,7 +23,8 @@ class AutoPublicPathRuntimeModule extends RuntimeModule {
|
|
|
23
23
|
*/
|
|
24
24
|
generate() {
|
|
25
25
|
const compilation = /** @type {Compilation} */ (this.compilation);
|
|
26
|
-
const { scriptType, importMetaName, path } =
|
|
26
|
+
const { scriptType, importMetaName, path, environment } =
|
|
27
|
+
compilation.outputOptions;
|
|
27
28
|
const chunkName = compilation.getPath(
|
|
28
29
|
JavascriptModulesPlugin.getChunkFilenameTemplate(
|
|
29
30
|
/** @type {Chunk} */
|
|
@@ -41,13 +42,17 @@ class AutoPublicPathRuntimeModule extends RuntimeModule {
|
|
|
41
42
|
false
|
|
42
43
|
);
|
|
43
44
|
|
|
45
|
+
const global = environment.globalThis
|
|
46
|
+
? "globalThis"
|
|
47
|
+
: RuntimeGlobals.global;
|
|
48
|
+
|
|
44
49
|
return Template.asString([
|
|
45
50
|
"var scriptUrl;",
|
|
46
51
|
scriptType === "module"
|
|
47
52
|
? `if (typeof ${importMetaName}.url === "string") scriptUrl = ${importMetaName}.url`
|
|
48
53
|
: Template.asString([
|
|
49
|
-
`if (${
|
|
50
|
-
`var document = ${
|
|
54
|
+
`if (${global}.importScripts) scriptUrl = ${global}.location + "";`,
|
|
55
|
+
`var document = ${global}.document;`,
|
|
51
56
|
"if (!scriptUrl && document) {",
|
|
52
57
|
Template.indent([
|
|
53
58
|
// Technically we could use `document.currentScript instanceof window.HTMLScriptElement`,
|