webpack 5.86.0 → 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/CaseSensitiveModulesWarning.js +3 -1
- package/lib/ChunkGroup.js +1 -0
- package/lib/Compiler.js +3 -1
- package/lib/ConcatenationScope.js +2 -2
- package/lib/ConditionalInitFragment.js +11 -1
- package/lib/ConstPlugin.js +57 -29
- package/lib/FlagEntryExportAsUsedPlugin.js +4 -0
- 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/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 +1 -1
- package/lib/WebpackOptionsDefaulter.js +10 -3
- package/lib/config/defaults.js +31 -2
- package/lib/css/CssModulesPlugin.js +5 -2
- 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/ids/SyncModuleIdsPlugin.js +1 -0
- package/lib/javascript/BasicEvaluatedExpression.js +23 -15
- package/lib/javascript/CommonJsChunkFormatPlugin.js +6 -2
- package/lib/javascript/JavascriptParser.js +118 -58
- package/lib/javascript/JavascriptParserHelpers.js +37 -15
- 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/ObjectMiddleware.js +6 -3
- 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 +39 -5
- package/schemas/plugins/css/CssGeneratorOptions.json +1 -1
- package/schemas/plugins/css/CssParserOptions.json +1 -1
- package/types.d.ts +433 -184
package/README.md
CHANGED
@@ -232,6 +232,7 @@ or are automatically applied via regex from your webpack configuration.
|
|
232
232
|
| <a href="https://github.com/webpack-contrib/polymer-webpack-loader"><img width="48" height="48" src="https://worldvectorlogo.com/logos/polymer.svg"></a> | ![polymer-npm] | ![polymer-size] | Process HTML & CSS with preprocessor of choice and `require()` Web Components like first-class modules |
|
233
233
|
| <a href="https://github.com/TheLarkInn/angular2-template-loader"><img width="48" height="48" src="https://worldvectorlogo.com/logos/angular-icon-1.svg"></a> | ![angular-npm] | ![angular-size] | Loads and compiles Angular 2 Components |
|
234
234
|
| <a href="https://github.com/riot/webpack-loader"><img width="48" height="48" src="https://worldvectorlogo.com/logos/riot.svg"></a> | ![riot-npm] | ![riot-size] | Riot official webpack loader |
|
235
|
+
| <a href="https://github.com/sveltejs/svelte-loader"><img width="48" height="48" src="https://worldvectorlogo.com/logos/svelte-1.svg"></a> | ![svelte-npm] | ![svelte-size] | Official Svelte loader |
|
235
236
|
|
236
237
|
[vue-npm]: https://img.shields.io/npm/v/vue-loader.svg
|
237
238
|
[vue-size]: https://packagephobia.com/badge?p=vue-loader
|
@@ -241,6 +242,8 @@ or are automatically applied via regex from your webpack configuration.
|
|
241
242
|
[angular-size]: https://packagephobia.com/badge?p=angular2-template-loader
|
242
243
|
[riot-npm]: https://img.shields.io/npm/v/riot-tag-loader.svg
|
243
244
|
[riot-size]: https://packagephobia.com/badge?p=riot-tag-loader
|
245
|
+
[svelte-npm]: https://img.shields.io/npm/v/svelte-loader.svg
|
246
|
+
[svelte-size]: https://packagephobia.com/badge?p=svelte-loader
|
244
247
|
|
245
248
|
### Performance
|
246
249
|
|
@@ -714,5 +717,5 @@ src="https://static.monei.net/monei-logo.svg" height="30" alt="MONEI"></a>
|
|
714
717
|
[builds2-url]: https://dev.azure.com/webpack/webpack/_build/latest?definitionId=3
|
715
718
|
[licenses-url]: https://app.fossa.io/projects/git%2Bhttps%3A%2F%2Fgithub.com%2Fwebpack%2Fwebpack?ref=badge_shield
|
716
719
|
[licenses]: https://app.fossa.io/api/projects/git%2Bhttps%3A%2F%2Fgithub.com%2Fwebpack%2Fwebpack.svg?type=shield
|
717
|
-
[cover]: https://
|
718
|
-
[cover-url]: https://
|
720
|
+
[cover]: https://codecov.io/gh/webpack/webpack/branch/master/graph/badge.svg?token=mDP3mQJNnn
|
721
|
+
[cover-url]: https://codecov.io/gh/webpack/webpack
|
@@ -42,7 +42,9 @@ const createModulesListMessage = (modules, moduleGraph) => {
|
|
42
42
|
|
43
43
|
if (validReasons.length > 0) {
|
44
44
|
message += `\n Used by ${validReasons.length} module(s), i. e.`;
|
45
|
-
message += `\n ${
|
45
|
+
message += `\n ${
|
46
|
+
/** @type {Module[]} */ (validReasons)[0].identifier()
|
47
|
+
}`;
|
46
48
|
}
|
47
49
|
return message;
|
48
50
|
})
|
package/lib/ChunkGroup.js
CHANGED
@@ -28,6 +28,7 @@ const {
|
|
28
28
|
* @typedef {Object} RawChunkGroupOptions
|
29
29
|
* @property {number=} preloadOrder
|
30
30
|
* @property {number=} prefetchOrder
|
31
|
+
* @property {("low" | "high" | "auto")=} fetchPriority
|
31
32
|
*/
|
32
33
|
|
33
34
|
/** @typedef {RawChunkGroupOptions & { name?: string }} ChunkGroupOptions */
|
package/lib/Compiler.js
CHANGED
@@ -1073,7 +1073,9 @@ ${other}`);
|
|
1073
1073
|
childCompiler.root = this.root;
|
1074
1074
|
if (Array.isArray(plugins)) {
|
1075
1075
|
for (const plugin of plugins) {
|
1076
|
-
plugin
|
1076
|
+
if (plugin) {
|
1077
|
+
plugin.apply(childCompiler);
|
1078
|
+
}
|
1077
1079
|
}
|
1078
1080
|
}
|
1079
1081
|
for (const name in this.hooks) {
|
@@ -108,7 +108,7 @@ class ConcatenationScope {
|
|
108
108
|
module,
|
109
109
|
{ ids = undefined, call = false, directImport = false, asiSafe = false }
|
110
110
|
) {
|
111
|
-
const info = this._modulesMap.get(module);
|
111
|
+
const info = /** @type {ModuleInfo} */ (this._modulesMap.get(module));
|
112
112
|
const callFlag = call ? "_call" : "";
|
113
113
|
const directImportFlag = directImport ? "_directImport" : "";
|
114
114
|
const asiSafeFlag = asiSafe
|
@@ -133,7 +133,7 @@ class ConcatenationScope {
|
|
133
133
|
|
134
134
|
/**
|
135
135
|
* @param {string} name the identifier
|
136
|
-
* @returns {ModuleReferenceOptions & { index: number }} parsed options and index
|
136
|
+
* @returns {ModuleReferenceOptions & { index: number } | null} parsed options and index
|
137
137
|
*/
|
138
138
|
static matchModuleReference(name) {
|
139
139
|
const match = MODULE_REFERENCE_REGEXP.exec(name);
|
@@ -14,6 +14,11 @@ const { mergeRuntime } = require("./util/runtime");
|
|
14
14
|
/** @typedef {import("./Generator").GenerateContext} GenerateContext */
|
15
15
|
/** @typedef {import("./util/runtime").RuntimeSpec} RuntimeSpec */
|
16
16
|
|
17
|
+
/**
|
18
|
+
* @param {string} condition condition
|
19
|
+
* @param {string | Source} source source
|
20
|
+
* @returns {string | Source} wrapped source
|
21
|
+
*/
|
17
22
|
const wrapInCondition = (condition, source) => {
|
18
23
|
if (typeof source === "string") {
|
19
24
|
return Template.asString([
|
@@ -33,13 +38,14 @@ const wrapInCondition = (condition, source) => {
|
|
33
38
|
|
34
39
|
/**
|
35
40
|
* @typedef {GenerateContext} Context
|
41
|
+
* @extends {InitFragment<Context>}
|
36
42
|
*/
|
37
43
|
class ConditionalInitFragment extends InitFragment {
|
38
44
|
/**
|
39
45
|
* @param {string|Source} content the source code that will be included as initialization code
|
40
46
|
* @param {number} stage category of initialization code (contribute to order)
|
41
47
|
* @param {number} position position in the category (contribute to order)
|
42
|
-
* @param {string} key unique key to avoid emitting the same initialization code twice
|
48
|
+
* @param {string | undefined} key unique key to avoid emitting the same initialization code twice
|
43
49
|
* @param {RuntimeSpec | boolean} runtimeCondition in which runtime this fragment should be executed
|
44
50
|
* @param {string|Source=} endContent the source code that will be included at the end of the module
|
45
51
|
*/
|
@@ -89,6 +95,10 @@ class ConditionalInitFragment extends InitFragment {
|
|
89
95
|
return wrapInCondition(expr, this.endContent);
|
90
96
|
}
|
91
97
|
|
98
|
+
/**
|
99
|
+
* @param {ConditionalInitFragment} other fragment to merge with
|
100
|
+
* @returns {ConditionalInitFragment} merged fragment
|
101
|
+
*/
|
92
102
|
merge(other) {
|
93
103
|
if (this.runtimeCondition === true) return this;
|
94
104
|
if (other.runtimeCondition === true) return other;
|
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
|
});
|
@@ -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;
|
@@ -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
|
/**
|
@@ -15,10 +15,16 @@ const JavascriptModulesPlugin = require("./javascript/JavascriptModulesPlugin");
|
|
15
15
|
/** @typedef {import("./ExportsInfo")} ExportsInfo */
|
16
16
|
/** @typedef {import("./ExportsInfo").ExportInfo} ExportInfo */
|
17
17
|
/** @typedef {import("./Module")} Module */
|
18
|
+
/** @typedef {import("./Module").BuildMeta} BuildMeta */
|
18
19
|
/** @typedef {import("./ModuleGraph")} ModuleGraph */
|
19
20
|
/** @typedef {import("./ModuleTemplate")} ModuleTemplate */
|
20
21
|
/** @typedef {import("./RequestShortener")} RequestShortener */
|
21
22
|
|
23
|
+
/**
|
24
|
+
* @template T
|
25
|
+
* @param {Iterable<T>} iterable iterable
|
26
|
+
* @returns {string} joined with comma
|
27
|
+
*/
|
22
28
|
const joinIterableWithComma = iterable => {
|
23
29
|
// This is more performant than Array.from().join(", ")
|
24
30
|
// as it doesn't create an array
|
@@ -139,7 +145,7 @@ const printExportsInfoToSource = (
|
|
139
145
|
}
|
140
146
|
};
|
141
147
|
|
142
|
-
/** @type {WeakMap<RequestShortener, WeakMap<Module, { header: RawSource, full: WeakMap<Source, CachedSource> }>>} */
|
148
|
+
/** @type {WeakMap<RequestShortener, WeakMap<Module, { header: RawSource | undefined, full: WeakMap<Source, CachedSource> }>>} */
|
143
149
|
const caches = new WeakMap();
|
144
150
|
|
145
151
|
class ModuleInfoHeaderPlugin {
|
@@ -197,7 +203,8 @@ class ModuleInfoHeaderPlugin {
|
|
197
203
|
}
|
198
204
|
source.add(header);
|
199
205
|
if (verbose) {
|
200
|
-
const exportsType = module.buildMeta
|
206
|
+
const exportsType = /** @type {BuildMeta} */ (module.buildMeta)
|
207
|
+
.exportsType;
|
201
208
|
source.add(
|
202
209
|
Template.toComment(
|
203
210
|
exportsType
|
@@ -43,7 +43,7 @@ const previouslyPolyfilledBuiltinModules = {
|
|
43
43
|
|
44
44
|
class ModuleNotFoundError extends WebpackError {
|
45
45
|
/**
|
46
|
-
* @param {Module} module module tied to dependency
|
46
|
+
* @param {Module | null} module module tied to dependency
|
47
47
|
* @param {Error&any} err error thrown
|
48
48
|
* @param {DependencyLocation} loc location of dependency
|
49
49
|
*/
|
@@ -54,7 +54,10 @@ class ModuleNotFoundError extends WebpackError {
|
|
54
54
|
const match = err.message.match(/Can't resolve '([^']+)'/);
|
55
55
|
if (match) {
|
56
56
|
const request = match[1];
|
57
|
-
const alias =
|
57
|
+
const alias =
|
58
|
+
previouslyPolyfilledBuiltinModules[
|
59
|
+
/** @type {keyof previouslyPolyfilledBuiltinModules} */ (request)
|
60
|
+
];
|
58
61
|
if (alias) {
|
59
62
|
const pathIndex = alias.indexOf("/");
|
60
63
|
const dependency = pathIndex > 0 ? alias.slice(0, pathIndex) : alias;
|