webpack 5.85.1 → 5.87.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.
Potentially problematic release.
This version of webpack might be problematic. Click here for more details.
- package/README.md +5 -2
- package/lib/APIPlugin.js +150 -99
- package/lib/CaseSensitiveModulesWarning.js +3 -1
- package/lib/Chunk.js +35 -17
- package/lib/ChunkGroup.js +11 -6
- package/lib/Compiler.js +4 -3
- package/lib/ConcatenationScope.js +2 -2
- package/lib/ConditionalInitFragment.js +11 -1
- package/lib/ConstPlugin.js +57 -29
- package/lib/ContextModule.js +4 -2
- package/lib/ContextModuleFactory.js +1 -0
- package/lib/DependenciesBlock.js +1 -1
- package/lib/DllModule.js +6 -0
- package/lib/EvalSourceMapDevToolPlugin.js +2 -1
- package/lib/ExternalModule.js +15 -8
- package/lib/FlagEntryExportAsUsedPlugin.js +4 -0
- package/lib/Module.js +7 -1
- package/lib/ModuleDependencyError.js +4 -2
- package/lib/ModuleDependencyWarning.js +4 -2
- package/lib/ModuleGraph.js +31 -24
- package/lib/ModuleGraphConnection.js +19 -6
- package/lib/ModuleInfoHeaderPlugin.js +9 -2
- package/lib/ModuleNotFoundError.js +5 -2
- package/lib/ModuleStoreError.js +2 -1
- package/lib/ModuleTypeConstants.js +7 -0
- package/lib/MultiWatching.js +4 -0
- package/lib/ProgressPlugin.js +71 -15
- package/lib/RuntimeGlobals.js +5 -0
- package/lib/RuntimePlugin.js +2 -1
- package/lib/RuntimeTemplate.js +20 -2
- package/lib/WebpackError.js +6 -5
- package/lib/WebpackOptionsApply.js +4 -2
- package/lib/WebpackOptionsDefaulter.js +10 -3
- package/lib/config/defaults.js +31 -2
- package/lib/css/CssExportsGenerator.js +9 -0
- package/lib/css/CssGenerator.js +1 -1
- package/lib/css/CssLoadingRuntimeModule.js +13 -6
- package/lib/css/CssModulesPlugin.js +42 -14
- package/lib/css/CssParser.js +12 -0
- package/lib/dependencies/ConstDependency.js +2 -2
- package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +19 -0
- package/lib/dependencies/ImportParserPlugin.js +25 -1
- package/lib/dependencies/JsonExportsDependency.js +1 -1
- package/lib/ids/SyncModuleIdsPlugin.js +1 -0
- package/lib/javascript/BasicEvaluatedExpression.js +23 -15
- package/lib/javascript/CommonJsChunkFormatPlugin.js +6 -2
- package/lib/javascript/JavascriptModulesPlugin.js +1 -0
- package/lib/javascript/JavascriptParser.js +118 -58
- package/lib/javascript/JavascriptParserHelpers.js +37 -15
- package/lib/json/JsonData.js +2 -2
- package/lib/json/JsonParser.js +25 -12
- package/lib/node/ReadFileCompileAsyncWasmPlugin.js +2 -1
- package/lib/optimize/AggressiveMergingPlugin.js +8 -0
- package/lib/optimize/AggressiveSplittingPlugin.js +9 -2
- package/lib/optimize/EnsureChunkConditionsPlugin.js +3 -0
- package/lib/optimize/FlagIncludedChunksPlugin.js +11 -5
- package/lib/optimize/InnerGraph.js +4 -4
- package/lib/optimize/LimitChunkCountPlugin.js +29 -4
- package/lib/optimize/MangleExportsPlugin.js +1 -1
- package/lib/optimize/MinMaxSizeWarning.js +5 -0
- package/lib/optimize/ModuleConcatenationPlugin.js +59 -2
- package/lib/optimize/RealContentHashPlugin.js +80 -30
- package/lib/optimize/RemoveParentModulesPlugin.js +6 -0
- package/lib/optimize/RuntimeChunkPlugin.js +9 -1
- package/lib/optimize/SideEffectsFlagPlugin.js +10 -1
- package/lib/optimize/SplitChunksPlugin.js +71 -31
- package/lib/performance/SizeLimitsPlugin.js +7 -4
- package/lib/prefetch/ChunkPrefetchFunctionRuntimeModule.js +3 -1
- package/lib/prefetch/ChunkPrefetchPreloadPlugin.js +3 -1
- package/lib/prefetch/ChunkPrefetchStartupRuntimeModule.js +5 -2
- package/lib/prefetch/ChunkPrefetchTriggerRuntimeModule.js +3 -1
- package/lib/prefetch/ChunkPreloadTriggerRuntimeModule.js +3 -1
- package/lib/rules/BasicEffectRulePlugin.js +4 -0
- package/lib/rules/BasicMatcherRulePlugin.js +5 -0
- package/lib/rules/RuleSetCompiler.js +3 -3
- package/lib/rules/UseEffectRulePlugin.js +6 -4
- package/lib/runtime/AsyncModuleRuntimeModule.js +4 -1
- package/lib/runtime/AutoPublicPathRuntimeModule.js +3 -1
- package/lib/runtime/BaseUriRuntimeModule.js +2 -2
- package/lib/runtime/CompatGetDefaultExportRuntimeModule.js +4 -1
- package/lib/runtime/CompatRuntimeModule.js +6 -1
- package/lib/runtime/CreateFakeNamespaceObjectRuntimeModule.js +4 -1
- package/lib/runtime/CreateScriptRuntimeModule.js +3 -1
- package/lib/runtime/CreateScriptUrlRuntimeModule.js +3 -1
- package/lib/runtime/DefinePropertyGettersRuntimeModule.js +4 -1
- package/lib/runtime/EnsureChunkRuntimeModule.js +14 -3
- package/lib/runtime/GetChunkFilenameRuntimeModule.js +5 -9
- package/lib/runtime/GetFullHashRuntimeModule.js +3 -2
- package/lib/runtime/GetMainFilenameRuntimeModule.js +4 -1
- package/lib/runtime/GetTrustedTypesPolicyRuntimeModule.js +3 -1
- package/lib/runtime/HasOwnPropertyRuntimeModule.js +4 -1
- package/lib/runtime/LoadScriptRuntimeModule.js +63 -47
- package/lib/runtime/MakeNamespaceObjectRuntimeModule.js +4 -1
- package/lib/runtime/OnChunksLoadedRuntimeModule.js +3 -1
- package/lib/runtime/PublicPathRuntimeModule.js +3 -1
- package/lib/runtime/RelativeUrlRuntimeModule.js +4 -1
- package/lib/runtime/RuntimeIdRuntimeModule.js +5 -1
- package/lib/runtime/StartupChunkDependenciesRuntimeModule.js +8 -2
- package/lib/runtime/StartupEntrypointRuntimeModule.js +2 -1
- package/lib/serialization/BinaryMiddleware.js +143 -1
- package/lib/serialization/ErrorObjectSerializer.js +3 -0
- package/lib/serialization/ObjectMiddleware.js +9 -3
- package/lib/serialization/types.js +1 -1
- package/lib/sharing/ConsumeSharedFallbackDependency.js +3 -0
- package/lib/sharing/ConsumeSharedRuntimeModule.js +13 -4
- package/lib/sharing/ProvideSharedDependency.js +11 -0
- package/lib/sharing/ProvideSharedModule.js +4 -0
- package/lib/sharing/ProvideSharedPlugin.js +22 -21
- package/lib/sharing/ShareRuntimeModule.js +11 -4
- package/lib/sharing/resolveMatchedConfigs.js +1 -1
- package/lib/sharing/utils.js +32 -5
- package/lib/util/AsyncQueue.js +4 -2
- package/lib/util/ParallelismFactorCalculator.js +10 -0
- package/lib/util/Semaphore.js +1 -1
- package/lib/util/createHash.js +30 -9
- package/lib/util/deprecation.js +10 -3
- package/lib/util/deterministicGrouping.js +50 -11
- package/lib/util/findGraphRoots.js +4 -2
- package/lib/util/memoize.js +3 -3
- package/lib/util/processAsyncTree.js +7 -1
- package/lib/util/registerExternalSerializer.js +1 -1
- package/lib/util/runtime.js +14 -1
- package/lib/util/smartGrouping.js +1 -1
- package/lib/validateSchema.js +6 -2
- package/lib/wasm-async/AsyncWasmLoadingRuntimeModule.js +5 -1
- package/lib/wasm-async/AsyncWebAssemblyParser.js +7 -3
- package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +13 -6
- package/lib/wasm-sync/WasmFinalizeExportsPlugin.js +3 -1
- package/lib/wasm-sync/WebAssemblyGenerator.js +1 -0
- package/lib/wasm-sync/WebAssemblyParser.js +6 -2
- package/lib/web/JsonpChunkLoadingRuntimeModule.js +13 -3
- package/lib/webpack.js +11 -2
- package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +14 -15
- package/module.d.ts +1 -0
- package/package.json +4 -4
- package/schemas/WebpackOptions.check.js +1 -1
- package/schemas/WebpackOptions.json +51 -5
- package/schemas/plugins/css/CssGeneratorOptions.json +1 -1
- package/schemas/plugins/css/CssParserOptions.json +1 -1
- package/types.d.ts +476 -218
package/lib/ConstPlugin.js
CHANGED
@@ -15,9 +15,14 @@ const ConstDependency = require("./dependencies/ConstDependency");
|
|
15
15
|
const { evaluateToString } = require("./javascript/JavascriptParserHelpers");
|
16
16
|
const { parseResource } = require("./util/identifier");
|
17
17
|
|
18
|
-
/** @typedef {import("estree").Expression}
|
19
|
-
/** @typedef {import("estree").
|
18
|
+
/** @typedef {import("estree").Expression} Expression */
|
19
|
+
/** @typedef {import("estree").SourceLocation} SourceLocation */
|
20
|
+
/** @typedef {import("estree").Statement} Statement */
|
21
|
+
/** @typedef {import("estree").Super} Super */
|
20
22
|
/** @typedef {import("./Compiler")} Compiler */
|
23
|
+
/** @typedef {import("./javascript/BasicEvaluatedExpression")} BasicEvaluatedExpression */
|
24
|
+
/** @typedef {import("./javascript/JavascriptParser")} JavascriptParser */
|
25
|
+
/** @typedef {import("./javascript/JavascriptParser").Range} Range */
|
21
26
|
|
22
27
|
const collectDeclaration = (declarations, pattern) => {
|
23
28
|
const stack = [pattern];
|
@@ -136,6 +141,9 @@ class ConstPlugin {
|
|
136
141
|
new CachedConstDependency.Template()
|
137
142
|
);
|
138
143
|
|
144
|
+
/**
|
145
|
+
* @param {JavascriptParser} parser the parser
|
146
|
+
*/
|
139
147
|
const handler = parser => {
|
140
148
|
parser.hooks.statementIf.tap(PLUGIN_NAME, statement => {
|
141
149
|
if (parser.scope.isAsmJs) return;
|
@@ -143,8 +151,11 @@ class ConstPlugin {
|
|
143
151
|
const bool = param.asBool();
|
144
152
|
if (typeof bool === "boolean") {
|
145
153
|
if (!param.couldHaveSideEffects()) {
|
146
|
-
const dep = new ConstDependency(
|
147
|
-
|
154
|
+
const dep = new ConstDependency(
|
155
|
+
`${bool}`,
|
156
|
+
/** @type {Range} */ (param.range)
|
157
|
+
);
|
158
|
+
dep.loc = /** @type {SourceLocation} */ (statement.loc);
|
148
159
|
parser.state.module.addPresentationalDependency(dep);
|
149
160
|
} else {
|
150
161
|
parser.walkExpression(statement.test);
|
@@ -200,9 +211,9 @@ class ConstPlugin {
|
|
200
211
|
}
|
201
212
|
const dep = new ConstDependency(
|
202
213
|
replacement,
|
203
|
-
branchToRemove.range
|
214
|
+
/** @type {Range} */ (branchToRemove.range)
|
204
215
|
);
|
205
|
-
dep.loc = branchToRemove.loc;
|
216
|
+
dep.loc = /** @type {SourceLocation} */ (branchToRemove.loc);
|
206
217
|
parser.state.module.addPresentationalDependency(dep);
|
207
218
|
}
|
208
219
|
return bool;
|
@@ -216,8 +227,11 @@ class ConstPlugin {
|
|
216
227
|
const bool = param.asBool();
|
217
228
|
if (typeof bool === "boolean") {
|
218
229
|
if (!param.couldHaveSideEffects()) {
|
219
|
-
const dep = new ConstDependency(
|
220
|
-
|
230
|
+
const dep = new ConstDependency(
|
231
|
+
` ${bool}`,
|
232
|
+
/** @type {Range} */ (param.range)
|
233
|
+
);
|
234
|
+
dep.loc = /** @type {SourceLocation} */ (expression.loc);
|
221
235
|
parser.state.module.addPresentationalDependency(dep);
|
222
236
|
} else {
|
223
237
|
parser.walkExpression(expression.test);
|
@@ -236,8 +250,11 @@ class ConstPlugin {
|
|
236
250
|
const branchToRemove = bool
|
237
251
|
? expression.alternate
|
238
252
|
: expression.consequent;
|
239
|
-
const dep = new ConstDependency(
|
240
|
-
|
253
|
+
const dep = new ConstDependency(
|
254
|
+
"0",
|
255
|
+
/** @type {Range} */ (branchToRemove.range)
|
256
|
+
);
|
257
|
+
dep.loc = /** @type {SourceLocation} */ (branchToRemove.loc);
|
241
258
|
parser.state.module.addPresentationalDependency(dep);
|
242
259
|
return bool;
|
243
260
|
}
|
@@ -313,8 +330,11 @@ class ConstPlugin {
|
|
313
330
|
//
|
314
331
|
// returnfalse&&'foo'
|
315
332
|
//
|
316
|
-
const dep = new ConstDependency(
|
317
|
-
|
333
|
+
const dep = new ConstDependency(
|
334
|
+
` ${bool}`,
|
335
|
+
/** @type {Range} */ (param.range)
|
336
|
+
);
|
337
|
+
dep.loc = /** @type {SourceLocation} */ (expression.loc);
|
318
338
|
parser.state.module.addPresentationalDependency(dep);
|
319
339
|
} else {
|
320
340
|
parser.walkExpression(expression.left);
|
@@ -322,9 +342,9 @@ class ConstPlugin {
|
|
322
342
|
if (!keepRight) {
|
323
343
|
const dep = new ConstDependency(
|
324
344
|
"0",
|
325
|
-
expression.right.range
|
345
|
+
/** @type {Range} */ (expression.right.range)
|
326
346
|
);
|
327
|
-
dep.loc = expression.loc;
|
347
|
+
dep.loc = /** @type {SourceLocation} */ (expression.loc);
|
328
348
|
parser.state.module.addPresentationalDependency(dep);
|
329
349
|
}
|
330
350
|
return keepRight;
|
@@ -363,15 +383,18 @@ class ConstPlugin {
|
|
363
383
|
//
|
364
384
|
// returnnull??'foo'
|
365
385
|
//
|
366
|
-
const dep = new ConstDependency(
|
367
|
-
|
386
|
+
const dep = new ConstDependency(
|
387
|
+
" null",
|
388
|
+
/** @type {Range} */ (param.range)
|
389
|
+
);
|
390
|
+
dep.loc = /** @type {SourceLocation} */ (expression.loc);
|
368
391
|
parser.state.module.addPresentationalDependency(dep);
|
369
392
|
} else {
|
370
393
|
const dep = new ConstDependency(
|
371
394
|
"0",
|
372
|
-
expression.right.range
|
395
|
+
/** @type {Range} */ (expression.right.range)
|
373
396
|
);
|
374
|
-
dep.loc = expression.loc;
|
397
|
+
dep.loc = /** @type {SourceLocation} */ (expression.loc);
|
375
398
|
parser.state.module.addPresentationalDependency(dep);
|
376
399
|
parser.walkExpression(expression.left);
|
377
400
|
}
|
@@ -382,9 +405,9 @@ class ConstPlugin {
|
|
382
405
|
}
|
383
406
|
);
|
384
407
|
parser.hooks.optionalChaining.tap(PLUGIN_NAME, expr => {
|
385
|
-
/** @type {
|
408
|
+
/** @type {Expression[]} */
|
386
409
|
const optionalExpressionsStack = [];
|
387
|
-
/** @type {
|
410
|
+
/** @type {Expression | Super} */
|
388
411
|
let next = expr.expression;
|
389
412
|
|
390
413
|
while (
|
@@ -395,7 +418,7 @@ class ConstPlugin {
|
|
395
418
|
if (next.optional) {
|
396
419
|
// SuperNode can not be optional
|
397
420
|
optionalExpressionsStack.push(
|
398
|
-
/** @type {
|
421
|
+
/** @type {Expression} */ (next.object)
|
399
422
|
);
|
400
423
|
}
|
401
424
|
next = next.object;
|
@@ -403,7 +426,7 @@ class ConstPlugin {
|
|
403
426
|
if (next.optional) {
|
404
427
|
// SuperNode can not be optional
|
405
428
|
optionalExpressionsStack.push(
|
406
|
-
/** @type {
|
429
|
+
/** @type {Expression} */ (next.callee)
|
407
430
|
);
|
408
431
|
}
|
409
432
|
next = next.callee;
|
@@ -412,7 +435,9 @@ class ConstPlugin {
|
|
412
435
|
|
413
436
|
while (optionalExpressionsStack.length) {
|
414
437
|
const expression = optionalExpressionsStack.pop();
|
415
|
-
const evaluated = parser.evaluateExpression(
|
438
|
+
const evaluated = parser.evaluateExpression(
|
439
|
+
/** @type {Expression} */ (expression)
|
440
|
+
);
|
416
441
|
|
417
442
|
if (evaluated.asNullish()) {
|
418
443
|
// ------------------------------------------
|
@@ -427,8 +452,11 @@ class ConstPlugin {
|
|
427
452
|
//
|
428
453
|
// ------------------------------------------
|
429
454
|
//
|
430
|
-
const dep = new ConstDependency(
|
431
|
-
|
455
|
+
const dep = new ConstDependency(
|
456
|
+
" undefined",
|
457
|
+
/** @type {Range} */ (expr.range)
|
458
|
+
);
|
459
|
+
dep.loc = /** @type {SourceLocation} */ (expr.loc);
|
432
460
|
parser.state.module.addPresentationalDependency(dep);
|
433
461
|
return true;
|
434
462
|
}
|
@@ -452,10 +480,10 @@ class ConstPlugin {
|
|
452
480
|
JSON.stringify(
|
453
481
|
cachedParseResource(parser.state.module.resource).query
|
454
482
|
),
|
455
|
-
expr.range,
|
483
|
+
/** @type {Range} */ (expr.range),
|
456
484
|
"__resourceQuery"
|
457
485
|
);
|
458
|
-
dep.loc = expr.loc;
|
486
|
+
dep.loc = /** @type {SourceLocation} */ (expr.loc);
|
459
487
|
parser.state.module.addPresentationalDependency(dep);
|
460
488
|
return true;
|
461
489
|
});
|
@@ -478,10 +506,10 @@ class ConstPlugin {
|
|
478
506
|
JSON.stringify(
|
479
507
|
cachedParseResource(parser.state.module.resource).fragment
|
480
508
|
),
|
481
|
-
expr.range,
|
509
|
+
/** @type {Range} */ (expr.range),
|
482
510
|
"__resourceFragment"
|
483
511
|
);
|
484
|
-
dep.loc = expr.loc;
|
512
|
+
dep.loc = /** @type {SourceLocation} */ (expr.loc);
|
485
513
|
parser.state.module.addPresentationalDependency(dep);
|
486
514
|
return true;
|
487
515
|
});
|
package/lib/ContextModule.js
CHANGED
@@ -64,6 +64,7 @@ const makeSerializable = require("./util/makeSerializable");
|
|
64
64
|
* @property {string=} typePrefix
|
65
65
|
* @property {string=} category
|
66
66
|
* @property {string[][]=} referencedExports exports referenced from modules (won't be mangled)
|
67
|
+
* @property {string=} layer
|
67
68
|
*/
|
68
69
|
|
69
70
|
/**
|
@@ -107,8 +108,9 @@ class ContextModule extends Module {
|
|
107
108
|
const resourceQuery = (options && options.resourceQuery) || parsed.query;
|
108
109
|
const resourceFragment =
|
109
110
|
(options && options.resourceFragment) || parsed.fragment;
|
111
|
+
const layer = options && options.layer;
|
110
112
|
|
111
|
-
super(JAVASCRIPT_MODULE_TYPE_DYNAMIC, resource);
|
113
|
+
super(JAVASCRIPT_MODULE_TYPE_DYNAMIC, resource, layer);
|
112
114
|
/** @type {ContextModuleOptions} */
|
113
115
|
this.options = {
|
114
116
|
...options,
|
@@ -117,7 +119,7 @@ class ContextModule extends Module {
|
|
117
119
|
resourceFragment
|
118
120
|
};
|
119
121
|
} else {
|
120
|
-
super(JAVASCRIPT_MODULE_TYPE_DYNAMIC);
|
122
|
+
super(JAVASCRIPT_MODULE_TYPE_DYNAMIC, undefined, options.layer);
|
121
123
|
/** @type {ContextModuleOptions} */
|
122
124
|
this.options = {
|
123
125
|
...options,
|
package/lib/DependenciesBlock.js
CHANGED
package/lib/DllModule.js
CHANGED
@@ -15,6 +15,7 @@ const makeSerializable = require("./util/makeSerializable");
|
|
15
15
|
/** @typedef {import("../declarations/WebpackOptions").WebpackOptionsNormalized} WebpackOptions */
|
16
16
|
/** @typedef {import("./ChunkGraph")} ChunkGraph */
|
17
17
|
/** @typedef {import("./Compilation")} Compilation */
|
18
|
+
/** @typedef {import("./Dependency")} Dependency */
|
18
19
|
/** @typedef {import("./Dependency").UpdateHashContext} UpdateHashContext */
|
19
20
|
/** @typedef {import("./DependencyTemplates")} DependencyTemplates */
|
20
21
|
/** @typedef {import("./Module").CodeGenerationContext} CodeGenerationContext */
|
@@ -37,6 +38,11 @@ const RUNTIME_REQUIREMENTS = new Set([
|
|
37
38
|
]);
|
38
39
|
|
39
40
|
class DllModule extends Module {
|
41
|
+
/**
|
42
|
+
* @param {string} context context path
|
43
|
+
* @param {Dependency[]} dependencies dependencies
|
44
|
+
* @param {string} name name
|
45
|
+
*/
|
40
46
|
constructor(context, dependencies, name) {
|
41
47
|
super(JAVASCRIPT_MODULE_TYPE_DYNAMIC, context);
|
42
48
|
|
@@ -160,7 +160,8 @@ class EvalSourceMapDevToolPlugin {
|
|
160
160
|
}
|
161
161
|
sourceMap.sourceRoot = options.sourceRoot || "";
|
162
162
|
const moduleId = chunkGraph.getModuleId(m);
|
163
|
-
sourceMap.file =
|
163
|
+
sourceMap.file =
|
164
|
+
typeof moduleId === "number" ? `${moduleId}.js` : moduleId;
|
164
165
|
|
165
166
|
const footer =
|
166
167
|
this.sourceMapComment.replace(
|
package/lib/ExternalModule.js
CHANGED
@@ -104,9 +104,13 @@ const getSourceForCommonJsExternal = moduleAndSpecifiers => {
|
|
104
104
|
|
105
105
|
/**
|
106
106
|
* @param {string|string[]} moduleAndSpecifiers the module request
|
107
|
+
* @param {string} importMetaName import.meta name
|
107
108
|
* @returns {SourceData} the generated source
|
108
109
|
*/
|
109
|
-
const getSourceForCommonJsExternalInNodeModule =
|
110
|
+
const getSourceForCommonJsExternalInNodeModule = (
|
111
|
+
moduleAndSpecifiers,
|
112
|
+
importMetaName
|
113
|
+
) => {
|
110
114
|
const chunkInitFragments = [
|
111
115
|
new InitFragment(
|
112
116
|
'import { createRequire as __WEBPACK_EXTERNAL_createRequire } from "module";\n',
|
@@ -117,18 +121,18 @@ const getSourceForCommonJsExternalInNodeModule = moduleAndSpecifiers => {
|
|
117
121
|
];
|
118
122
|
if (!Array.isArray(moduleAndSpecifiers)) {
|
119
123
|
return {
|
120
|
-
|
124
|
+
chunkInitFragments,
|
125
|
+
expression: `__WEBPACK_EXTERNAL_createRequire(${importMetaName}.url)(${JSON.stringify(
|
121
126
|
moduleAndSpecifiers
|
122
|
-
)})
|
123
|
-
chunkInitFragments
|
127
|
+
)})`
|
124
128
|
};
|
125
129
|
}
|
126
130
|
const moduleName = moduleAndSpecifiers[0];
|
127
131
|
return {
|
128
|
-
|
132
|
+
chunkInitFragments,
|
133
|
+
expression: `__WEBPACK_EXTERNAL_createRequire(${importMetaName}.url)(${JSON.stringify(
|
129
134
|
moduleName
|
130
|
-
)})${propertyAccess(moduleAndSpecifiers, 1)}
|
131
|
-
chunkInitFragments
|
135
|
+
)})${propertyAccess(moduleAndSpecifiers, 1)}`
|
132
136
|
};
|
133
137
|
};
|
134
138
|
|
@@ -557,7 +561,10 @@ class ExternalModule extends Module {
|
|
557
561
|
return getSourceForCommonJsExternal(request);
|
558
562
|
case "node-commonjs":
|
559
563
|
return this.buildInfo.module
|
560
|
-
? getSourceForCommonJsExternalInNodeModule(
|
564
|
+
? getSourceForCommonJsExternalInNodeModule(
|
565
|
+
request,
|
566
|
+
runtimeTemplate.outputOptions.importMetaName
|
567
|
+
)
|
561
568
|
: getSourceForCommonJsExternal(request);
|
562
569
|
case "amd":
|
563
570
|
case "amd-require":
|
@@ -12,6 +12,10 @@ const { getEntryRuntime } = require("./util/runtime");
|
|
12
12
|
const PLUGIN_NAME = "FlagEntryExportAsUsedPlugin";
|
13
13
|
|
14
14
|
class FlagEntryExportAsUsedPlugin {
|
15
|
+
/**
|
16
|
+
* @param {boolean} nsObjectUsed true, if the ns object is used
|
17
|
+
* @param {string} explanation explanation for the reason
|
18
|
+
*/
|
15
19
|
constructor(nsObjectUsed, explanation) {
|
16
20
|
this.nsObjectUsed = nsObjectUsed;
|
17
21
|
this.explanation = explanation;
|
package/lib/Module.js
CHANGED
@@ -107,6 +107,7 @@ const makeSerializable = require("./util/makeSerializable");
|
|
107
107
|
*/
|
108
108
|
|
109
109
|
/** @typedef {KnownBuildMeta & Record<string, any>} BuildMeta */
|
110
|
+
/** @typedef {Record<string, any>} BuildInfo */
|
110
111
|
|
111
112
|
const EMPTY_RESOLVE_OPTIONS = {};
|
112
113
|
|
@@ -116,6 +117,11 @@ const DEFAULT_TYPES_UNKNOWN = new Set(["unknown"]);
|
|
116
117
|
const DEFAULT_TYPES_JS = new Set(["javascript"]);
|
117
118
|
|
118
119
|
const deprecatedNeedRebuild = util.deprecate(
|
120
|
+
/**
|
121
|
+
* @param {Module} module the module
|
122
|
+
* @param {NeedBuildContext} context context info
|
123
|
+
* @returns {boolean} true, when rebuild is needed
|
124
|
+
*/
|
119
125
|
(module, context) => {
|
120
126
|
return module.needRebuild(
|
121
127
|
context.fileSystemInfo.getDeprecatedFileTimestamps(),
|
@@ -169,7 +175,7 @@ class Module extends DependenciesBlock {
|
|
169
175
|
this._errors = undefined;
|
170
176
|
/** @type {BuildMeta | undefined} */
|
171
177
|
this.buildMeta = undefined;
|
172
|
-
/** @type {
|
178
|
+
/** @type {BuildInfo | undefined} */
|
173
179
|
this.buildInfo = undefined;
|
174
180
|
/** @type {Dependency[] | undefined} */
|
175
181
|
this.presentationalDependencies = undefined;
|
@@ -23,7 +23,7 @@ class ModuleDependencyError extends WebpackError {
|
|
23
23
|
this.name = "ModuleDependencyError";
|
24
24
|
this.details =
|
25
25
|
err && !(/** @type {any} */ (err).hideStack)
|
26
|
-
? err.stack.split("\n").slice(1).join("\n")
|
26
|
+
? /** @type {string} */ (err.stack).split("\n").slice(1).join("\n")
|
27
27
|
: undefined;
|
28
28
|
this.module = module;
|
29
29
|
this.loc = loc;
|
@@ -32,7 +32,9 @@ class ModuleDependencyError extends WebpackError {
|
|
32
32
|
|
33
33
|
if (err && /** @type {any} */ (err).hideStack) {
|
34
34
|
this.stack =
|
35
|
-
err.stack.split("\n").slice(1).join("\n") +
|
35
|
+
/** @type {string} */ (err.stack).split("\n").slice(1).join("\n") +
|
36
|
+
"\n\n" +
|
37
|
+
this.stack;
|
36
38
|
}
|
37
39
|
}
|
38
40
|
}
|
@@ -23,7 +23,7 @@ class ModuleDependencyWarning extends WebpackError {
|
|
23
23
|
this.name = "ModuleDependencyWarning";
|
24
24
|
this.details =
|
25
25
|
err && !(/** @type {any} */ (err).hideStack)
|
26
|
-
? err.stack.split("\n").slice(1).join("\n")
|
26
|
+
? /** @type {string} */ (err.stack).split("\n").slice(1).join("\n")
|
27
27
|
: undefined;
|
28
28
|
this.module = module;
|
29
29
|
this.loc = loc;
|
@@ -32,7 +32,9 @@ class ModuleDependencyWarning extends WebpackError {
|
|
32
32
|
|
33
33
|
if (err && /** @type {any} */ (err).hideStack) {
|
34
34
|
this.stack =
|
35
|
-
err.stack.split("\n").slice(1).join("\n") +
|
35
|
+
/** @type {string} */ (err.stack).split("\n").slice(1).join("\n") +
|
36
|
+
"\n\n" +
|
37
|
+
this.stack;
|
36
38
|
}
|
37
39
|
}
|
38
40
|
}
|
package/lib/ModuleGraph.js
CHANGED
@@ -35,14 +35,15 @@ const getConnectionsByOriginModule = set => {
|
|
35
35
|
const map = new Map();
|
36
36
|
/** @type {Module | 0} */
|
37
37
|
let lastModule = 0;
|
38
|
-
/** @type {ModuleGraphConnection[]} */
|
38
|
+
/** @type {ModuleGraphConnection[] | undefined} */
|
39
39
|
let lastList = undefined;
|
40
40
|
for (const connection of set) {
|
41
41
|
const { originModule } = connection;
|
42
42
|
if (lastModule === originModule) {
|
43
|
-
|
43
|
+
/** @type {ModuleGraphConnection[]} */
|
44
|
+
(lastList).push(connection);
|
44
45
|
} else {
|
45
|
-
lastModule = originModule;
|
46
|
+
lastModule = /** @type {Module} */ (originModule);
|
46
47
|
const list = map.get(originModule);
|
47
48
|
if (list !== undefined) {
|
48
49
|
lastList = list;
|
@@ -65,12 +66,13 @@ const getConnectionsByModule = set => {
|
|
65
66
|
const map = new Map();
|
66
67
|
/** @type {Module | 0} */
|
67
68
|
let lastModule = 0;
|
68
|
-
/** @type {ModuleGraphConnection[]} */
|
69
|
+
/** @type {ModuleGraphConnection[] | undefined} */
|
69
70
|
let lastList = undefined;
|
70
71
|
for (const connection of set) {
|
71
72
|
const { module } = connection;
|
72
73
|
if (lastModule === module) {
|
73
|
-
|
74
|
+
/** @type {ModuleGraphConnection[]} */
|
75
|
+
(lastList).push(connection);
|
74
76
|
} else {
|
75
77
|
lastModule = module;
|
76
78
|
const list = map.get(module);
|
@@ -99,13 +101,13 @@ class ModuleGraphModule {
|
|
99
101
|
this.optimizationBailout = [];
|
100
102
|
/** @type {ExportsInfo} */
|
101
103
|
this.exports = new ExportsInfo();
|
102
|
-
/** @type {number} */
|
104
|
+
/** @type {number | null} */
|
103
105
|
this.preOrderIndex = null;
|
104
|
-
/** @type {number} */
|
106
|
+
/** @type {number | null} */
|
105
107
|
this.postOrderIndex = null;
|
106
|
-
/** @type {number} */
|
108
|
+
/** @type {number | null} */
|
107
109
|
this.depth = null;
|
108
|
-
/** @type {ModuleProfile} */
|
110
|
+
/** @type {ModuleProfile | undefined | null} */
|
109
111
|
this.profile = undefined;
|
110
112
|
/** @type {boolean} */
|
111
113
|
this.async = false;
|
@@ -116,20 +118,20 @@ class ModuleGraphModule {
|
|
116
118
|
|
117
119
|
class ModuleGraph {
|
118
120
|
constructor() {
|
119
|
-
/** @type {WeakMap<Dependency, ModuleGraphConnection>} */
|
121
|
+
/** @type {WeakMap<Dependency, ModuleGraphConnection | null>} */
|
120
122
|
this._dependencyMap = new WeakMap();
|
121
123
|
/** @type {Map<Module, ModuleGraphModule>} */
|
122
124
|
this._moduleMap = new Map();
|
123
125
|
/** @type {WeakMap<any, Object>} */
|
124
126
|
this._metaMap = new WeakMap();
|
125
127
|
|
126
|
-
/** @type {WeakTupleMap<any[], any>} */
|
128
|
+
/** @type {WeakTupleMap<any[], any> | undefined} */
|
127
129
|
this._cache = undefined;
|
128
130
|
|
129
131
|
/** @type {Map<Module, WeakTupleMap<any, any>>} */
|
130
132
|
this._moduleMemCaches = undefined;
|
131
133
|
|
132
|
-
/** @type {string} */
|
134
|
+
/** @type {string | undefined} */
|
133
135
|
this._cacheStage = undefined;
|
134
136
|
}
|
135
137
|
|
@@ -221,7 +223,9 @@ class ModuleGraph {
|
|
221
223
|
* @returns {void}
|
222
224
|
*/
|
223
225
|
updateModule(dependency, module) {
|
224
|
-
const connection =
|
226
|
+
const connection =
|
227
|
+
/** @type {ModuleGraphConnection} */
|
228
|
+
(this.getConnection(dependency));
|
225
229
|
if (connection.module === module) return;
|
226
230
|
const newConnection = connection.clone();
|
227
231
|
newConnection.module = module;
|
@@ -375,7 +379,7 @@ class ModuleGraph {
|
|
375
379
|
|
376
380
|
/**
|
377
381
|
* @param {Dependency} dependency the dependency to look for a referenced module
|
378
|
-
* @returns {Module} the referenced module
|
382
|
+
* @returns {Module | null} the referenced module
|
379
383
|
*/
|
380
384
|
getResolvedModule(dependency) {
|
381
385
|
const connection = this.getConnection(dependency);
|
@@ -398,7 +402,10 @@ class ModuleGraph {
|
|
398
402
|
) {
|
399
403
|
let foundConnection;
|
400
404
|
for (const connection of mgm._unassignedConnections) {
|
401
|
-
this._dependencyMap.set(
|
405
|
+
this._dependencyMap.set(
|
406
|
+
/** @type {Dependency} */ (connection.dependency),
|
407
|
+
connection
|
408
|
+
);
|
402
409
|
if (connection.dependency === dependency)
|
403
410
|
foundConnection = connection;
|
404
411
|
}
|
@@ -416,7 +423,7 @@ class ModuleGraph {
|
|
416
423
|
|
417
424
|
/**
|
418
425
|
* @param {Dependency} dependency the dependency to look for a referenced module
|
419
|
-
* @returns {Module} the referenced module
|
426
|
+
* @returns {Module | null} the referenced module
|
420
427
|
*/
|
421
428
|
getModule(dependency) {
|
422
429
|
const connection = this.getConnection(dependency);
|
@@ -425,7 +432,7 @@ class ModuleGraph {
|
|
425
432
|
|
426
433
|
/**
|
427
434
|
* @param {Dependency} dependency the dependency to look for a referencing module
|
428
|
-
* @returns {Module} the referencing module
|
435
|
+
* @returns {Module | null} the referencing module
|
429
436
|
*/
|
430
437
|
getOrigin(dependency) {
|
431
438
|
const connection = this.getConnection(dependency);
|
@@ -434,7 +441,7 @@ class ModuleGraph {
|
|
434
441
|
|
435
442
|
/**
|
436
443
|
* @param {Dependency} dependency the dependency to look for a referencing module
|
437
|
-
* @returns {Module} the original referencing module
|
444
|
+
* @returns {Module | null} the original referencing module
|
438
445
|
*/
|
439
446
|
getResolvedOrigin(dependency) {
|
440
447
|
const connection = this.getConnection(dependency);
|
@@ -604,7 +611,7 @@ class ModuleGraph {
|
|
604
611
|
|
605
612
|
/**
|
606
613
|
* @param {Module} module the module
|
607
|
-
* @returns {number} the index of the module
|
614
|
+
* @returns {number | null} the index of the module
|
608
615
|
*/
|
609
616
|
getPreOrderIndex(module) {
|
610
617
|
const mgm = this._getModuleGraphModule(module);
|
@@ -613,7 +620,7 @@ class ModuleGraph {
|
|
613
620
|
|
614
621
|
/**
|
615
622
|
* @param {Module} module the module
|
616
|
-
* @returns {number} the index of the module
|
623
|
+
* @returns {number | null} the index of the module
|
617
624
|
*/
|
618
625
|
getPostOrderIndex(module) {
|
619
626
|
const mgm = this._getModuleGraphModule(module);
|
@@ -670,7 +677,7 @@ class ModuleGraph {
|
|
670
677
|
|
671
678
|
/**
|
672
679
|
* @param {Module} module the module
|
673
|
-
* @returns {number} the depth of the module
|
680
|
+
* @returns {number | null} the depth of the module
|
674
681
|
*/
|
675
682
|
getDepth(module) {
|
676
683
|
const mgm = this._getModuleGraphModule(module);
|
@@ -727,14 +734,14 @@ class ModuleGraph {
|
|
727
734
|
let meta = this._metaMap.get(thing);
|
728
735
|
if (meta === undefined) {
|
729
736
|
meta = Object.create(null);
|
730
|
-
this._metaMap.set(thing, meta);
|
737
|
+
this._metaMap.set(thing, /** @type {Object} */ (meta));
|
731
738
|
}
|
732
|
-
return meta;
|
739
|
+
return /** @type {Object} */ (meta);
|
733
740
|
}
|
734
741
|
|
735
742
|
/**
|
736
743
|
* @param {any} thing any thing
|
737
|
-
* @returns {Object} metadata
|
744
|
+
* @returns {Object | undefined} metadata
|
738
745
|
*/
|
739
746
|
getMetaIfExisting(thing) {
|
740
747
|
return this._metaMap.get(thing);
|
@@ -74,9 +74,9 @@ class ModuleGraphConnection {
|
|
74
74
|
this.weak = weak;
|
75
75
|
this.conditional = !!condition;
|
76
76
|
this._active = condition !== false;
|
77
|
-
/** @type {function(ModuleGraphConnection, RuntimeSpec): ConnectionState} */
|
77
|
+
/** @type {(function(ModuleGraphConnection, RuntimeSpec): ConnectionState) | undefined} */
|
78
78
|
this.condition = condition || undefined;
|
79
|
-
/** @type {Set<string>} */
|
79
|
+
/** @type {Set<string> | undefined} */
|
80
80
|
this.explanations = undefined;
|
81
81
|
if (explanation) {
|
82
82
|
this.explanations = new Set();
|
@@ -107,7 +107,9 @@ class ModuleGraphConnection {
|
|
107
107
|
*/
|
108
108
|
addCondition(condition) {
|
109
109
|
if (this.conditional) {
|
110
|
-
const old =
|
110
|
+
const old =
|
111
|
+
/** @type {(function(ModuleGraphConnection, RuntimeSpec): ConnectionState)} */
|
112
|
+
(this.condition);
|
111
113
|
this.condition = (c, r) =>
|
112
114
|
intersectConnectionStates(old(c, r), condition(c, r));
|
113
115
|
} else if (this._active) {
|
@@ -143,7 +145,12 @@ class ModuleGraphConnection {
|
|
143
145
|
*/
|
144
146
|
isActive(runtime) {
|
145
147
|
if (!this.conditional) return this._active;
|
146
|
-
|
148
|
+
|
149
|
+
return (
|
150
|
+
/** @type {(function(ModuleGraphConnection, RuntimeSpec): ConnectionState)} */ (
|
151
|
+
this.condition
|
152
|
+
)(this, runtime) !== false
|
153
|
+
);
|
147
154
|
}
|
148
155
|
|
149
156
|
/**
|
@@ -152,7 +159,11 @@ class ModuleGraphConnection {
|
|
152
159
|
*/
|
153
160
|
isTargetActive(runtime) {
|
154
161
|
if (!this.conditional) return this._active;
|
155
|
-
return
|
162
|
+
return (
|
163
|
+
/** @type {(function(ModuleGraphConnection, RuntimeSpec): ConnectionState)} */ (
|
164
|
+
this.condition
|
165
|
+
)(this, runtime) === true
|
166
|
+
);
|
156
167
|
}
|
157
168
|
|
158
169
|
/**
|
@@ -161,7 +172,9 @@ class ModuleGraphConnection {
|
|
161
172
|
*/
|
162
173
|
getActiveState(runtime) {
|
163
174
|
if (!this.conditional) return this._active;
|
164
|
-
return
|
175
|
+
return /** @type {(function(ModuleGraphConnection, RuntimeSpec): ConnectionState)} */ (
|
176
|
+
this.condition
|
177
|
+
)(this, runtime);
|
165
178
|
}
|
166
179
|
|
167
180
|
/**
|