webpack 5.90.2 → 5.91.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 -5
- package/bin/webpack.js +5 -1
- package/lib/APIPlugin.js +8 -4
- package/lib/AutomaticPrefetchPlugin.js +1 -1
- package/lib/BannerPlugin.js +3 -1
- package/lib/Cache.js +7 -1
- package/lib/CacheFacade.js +3 -3
- package/lib/ChunkGraph.js +32 -18
- package/lib/ChunkGroup.js +14 -14
- package/lib/CleanPlugin.js +7 -5
- package/lib/Compilation.js +263 -94
- package/lib/Compiler.js +199 -83
- package/lib/ConditionalInitFragment.js +4 -5
- package/lib/ContextModule.js +4 -1
- package/lib/ContextModuleFactory.js +4 -2
- package/lib/ContextReplacementPlugin.js +3 -2
- package/lib/CssModule.js +0 -3
- package/lib/DefinePlugin.js +4 -2
- package/lib/DelegatedModule.js +2 -1
- package/lib/Dependency.js +4 -2
- package/lib/DependencyTemplate.js +7 -2
- package/lib/DllModule.js +3 -1
- package/lib/DllReferencePlugin.js +6 -2
- package/lib/EntryOptionPlugin.js +4 -1
- package/lib/EntryPlugin.js +6 -1
- package/lib/Entrypoint.js +1 -1
- package/lib/ExportsInfo.js +1 -4
- package/lib/ExternalModule.js +120 -25
- package/lib/ExternalModuleFactoryPlugin.js +37 -2
- package/lib/FileSystemInfo.js +1 -1
- package/lib/Generator.js +2 -1
- package/lib/HookWebpackError.js +2 -2
- package/lib/InitFragment.js +5 -3
- package/lib/LibManifestPlugin.js +15 -7
- package/lib/Module.js +54 -5
- package/lib/ModuleFilenameHelpers.js +1 -1
- package/lib/ModuleGraph.js +56 -27
- package/lib/ModuleGraphConnection.js +2 -1
- package/lib/MultiCompiler.js +61 -17
- package/lib/NodeStuffPlugin.js +14 -3
- package/lib/NormalModule.js +239 -86
- package/lib/NormalModuleFactory.js +163 -32
- package/lib/NormalModuleReplacementPlugin.js +5 -1
- package/lib/ProvidePlugin.js +3 -1
- package/lib/RawModule.js +4 -2
- package/lib/ResolverFactory.js +5 -1
- package/lib/RuntimeModule.js +6 -5
- package/lib/RuntimePlugin.js +1 -0
- package/lib/RuntimeTemplate.js +102 -34
- package/lib/SourceMapDevToolPlugin.js +4 -1
- package/lib/Stats.js +12 -5
- package/lib/TemplatedPathPlugin.js +32 -6
- package/lib/Watching.js +67 -60
- package/lib/WebpackError.js +6 -6
- package/lib/WebpackOptionsApply.js +18 -5
- package/lib/asset/RawDataUrlModule.js +5 -2
- package/lib/async-modules/AwaitDependenciesInitFragment.js +2 -2
- package/lib/buildChunkGraph.js +220 -392
- package/lib/cache/IdleFileCachePlugin.js +8 -3
- package/lib/cache/MemoryCachePlugin.js +1 -1
- package/lib/cache/MemoryWithGcCachePlugin.js +6 -2
- package/lib/cache/PackFileCacheStrategy.js +49 -16
- package/lib/cache/ResolverCachePlugin.js +14 -6
- package/lib/cache/getLazyHashedEtag.js +1 -1
- package/lib/config/defaults.js +24 -1
- package/lib/config/normalization.js +3 -1
- package/lib/container/ContainerEntryDependency.js +2 -1
- package/lib/container/ContainerEntryModule.js +5 -2
- package/lib/container/ContainerPlugin.js +14 -10
- package/lib/container/FallbackModule.js +3 -2
- package/lib/container/RemoteModule.js +2 -1
- package/lib/container/RemoteRuntimeModule.js +12 -3
- package/lib/css/CssExportsGenerator.js +34 -17
- package/lib/css/CssGenerator.js +20 -2
- package/lib/css/CssLoadingRuntimeModule.js +212 -96
- package/lib/css/CssModulesPlugin.js +47 -13
- package/lib/debug/ProfilingPlugin.js +27 -2
- package/lib/dependencies/AMDDefineDependencyParserPlugin.js +9 -5
- package/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js +4 -1
- package/lib/dependencies/CommonJsDependencyHelpers.js +2 -1
- package/lib/dependencies/CommonJsExportRequireDependency.js +33 -18
- package/lib/dependencies/CommonJsExportsDependency.js +13 -5
- package/lib/dependencies/CommonJsExportsParserPlugin.js +20 -15
- package/lib/dependencies/CommonJsImportsParserPlugin.js +1 -2
- package/lib/dependencies/ContextDependencyHelpers.js +49 -29
- package/lib/dependencies/ContextElementDependency.js +8 -1
- package/lib/dependencies/CssLocalIdentifierDependency.js +63 -8
- package/lib/dependencies/CssUrlDependency.js +5 -3
- package/lib/dependencies/ExportsInfoDependency.js +4 -3
- package/lib/dependencies/ExternalModuleInitFragment.js +5 -3
- package/lib/dependencies/HarmonyEvaluatedImportSpecifierDependency.js +4 -4
- package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +43 -23
- package/lib/dependencies/HarmonyExportHeaderDependency.js +1 -1
- package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +73 -32
- package/lib/dependencies/HarmonyExportInitFragment.js +10 -2
- package/lib/dependencies/HarmonyImportDependency.js +28 -12
- package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +44 -16
- package/lib/dependencies/HarmonyImportSideEffectDependency.js +7 -6
- package/lib/dependencies/HarmonyImportSpecifierDependency.js +21 -10
- package/lib/dependencies/ImportDependency.js +9 -2
- package/lib/dependencies/ImportEagerDependency.js +4 -2
- package/lib/dependencies/ImportMetaContextDependency.js +7 -0
- package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +25 -14
- package/lib/dependencies/ImportParserPlugin.js +12 -4
- package/lib/dependencies/ImportWeakDependency.js +4 -2
- package/lib/dependencies/LoaderDependency.js +2 -1
- package/lib/dependencies/LoaderImportDependency.js +2 -1
- package/lib/dependencies/ModuleDependency.js +4 -5
- package/lib/dependencies/PureExpressionDependency.js +4 -1
- package/lib/dependencies/RequireContextPlugin.js +1 -1
- package/lib/dependencies/RequireEnsureDependenciesBlockParserPlugin.js +26 -14
- package/lib/dependencies/RequireEnsureDependency.js +1 -1
- package/lib/dependencies/URLDependency.js +7 -4
- package/lib/dependencies/WorkerDependency.js +1 -1
- package/lib/dependencies/WorkerPlugin.js +6 -5
- package/lib/dependencies/getFunctionExpression.js +3 -1
- package/lib/esm/ModuleChunkLoadingRuntimeModule.js +2 -1
- package/lib/hmr/LazyCompilationPlugin.js +2 -1
- package/lib/javascript/BasicEvaluatedExpression.js +2 -2
- package/lib/javascript/ChunkHelpers.js +2 -2
- package/lib/javascript/JavascriptParser.js +169 -57
- package/lib/javascript/JavascriptParserHelpers.js +1 -1
- package/lib/javascript/StartupHelpers.js +22 -5
- package/lib/logging/Logger.js +27 -2
- package/lib/logging/createConsoleLogger.js +11 -7
- package/lib/node/NodeEnvironmentPlugin.js +13 -7
- package/lib/node/NodeWatchFileSystem.js +37 -26
- package/lib/node/ReadFileChunkLoadingRuntimeModule.js +2 -1
- package/lib/node/RequireChunkLoadingRuntimeModule.js +2 -1
- package/lib/node/nodeConsole.js +24 -1
- package/lib/optimize/AggressiveSplittingPlugin.js +1 -0
- package/lib/optimize/ConcatenatedModule.js +140 -55
- package/lib/optimize/EnsureChunkConditionsPlugin.js +1 -1
- package/lib/optimize/InnerGraph.js +7 -2
- package/lib/optimize/InnerGraphPlugin.js +36 -13
- package/lib/optimize/ModuleConcatenationPlugin.js +12 -2
- package/lib/optimize/RemoveParentModulesPlugin.js +1 -0
- package/lib/optimize/RuntimeChunkPlugin.js +6 -1
- package/lib/optimize/SideEffectsFlagPlugin.js +46 -15
- package/lib/optimize/SplitChunksPlugin.js +2 -2
- package/lib/performance/SizeLimitsPlugin.js +11 -0
- package/lib/rules/ObjectMatcherRulePlugin.js +4 -0
- package/lib/runtime/EnsureChunkRuntimeModule.js +2 -1
- package/lib/runtime/GetTrustedTypesPolicyRuntimeModule.js +2 -1
- package/lib/serialization/FileMiddleware.js +1 -0
- package/lib/serialization/ObjectMiddleware.js +2 -0
- package/lib/serialization/Serializer.js +19 -0
- package/lib/sharing/ConsumeSharedModule.js +3 -2
- package/lib/sharing/ConsumeSharedPlugin.js +17 -3
- package/lib/sharing/ConsumeSharedRuntimeModule.js +9 -2
- package/lib/sharing/ProvideSharedModule.js +2 -1
- package/lib/sharing/ProvideSharedPlugin.js +12 -5
- package/lib/sharing/resolveMatchedConfigs.js +2 -2
- package/lib/sharing/utils.js +13 -6
- package/lib/util/StackedCacheMap.js +26 -0
- package/lib/util/WeakTupleMap.js +57 -13
- package/lib/util/cleverMerge.js +24 -11
- package/lib/util/comparators.js +34 -14
- package/lib/util/conventions.js +129 -0
- package/lib/util/fs.js +379 -65
- package/lib/util/hash/BatchedHash.js +3 -0
- package/lib/util/hash/xxhash64.js +2 -2
- package/lib/util/memoize.js +2 -0
- package/lib/util/runtime.js +1 -1
- package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +4 -2
- package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +15 -6
- package/lib/wasm-sync/WebAssemblyGenerator.js +27 -6
- package/lib/wasm-sync/WebAssemblyJavascriptGenerator.js +2 -1
- package/lib/wasm-sync/WebAssemblyParser.js +7 -4
- package/lib/web/JsonpChunkLoadingRuntimeModule.js +2 -1
- package/lib/webpack.js +11 -5
- package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +2 -1
- package/package.json +25 -26
- package/schemas/WebpackOptions.check.js +1 -1
- package/schemas/WebpackOptions.json +69 -8
- package/schemas/plugins/BannerPlugin.check.js +1 -1
- package/schemas/plugins/BannerPlugin.json +5 -1
- package/schemas/plugins/css/CssAutoGeneratorOptions.check.js +1 -1
- package/schemas/plugins/css/CssGeneratorOptions.check.js +1 -1
- package/schemas/plugins/css/CssGlobalGeneratorOptions.check.js +1 -1
- package/schemas/plugins/css/CssModuleGeneratorOptions.check.js +1 -1
- package/types.d.ts +1772 -673
package/lib/MultiCompiler.js
CHANGED
@@ -19,6 +19,7 @@ const ArrayQueue = require("./util/ArrayQueue");
|
|
19
19
|
/** @typedef {import("./Compiler")} Compiler */
|
20
20
|
/** @typedef {import("./Stats")} Stats */
|
21
21
|
/** @typedef {import("./Watching")} Watching */
|
22
|
+
/** @typedef {import("./logging/Logger").Logger} Logger */
|
22
23
|
/** @typedef {import("./util/fs").InputFileSystem} InputFileSystem */
|
23
24
|
/** @typedef {import("./util/fs").IntermediateFileSystem} IntermediateFileSystem */
|
24
25
|
/** @typedef {import("./util/fs").OutputFileSystem} OutputFileSystem */
|
@@ -27,7 +28,7 @@ const ArrayQueue = require("./util/ArrayQueue");
|
|
27
28
|
/**
|
28
29
|
* @template T
|
29
30
|
* @callback Callback
|
30
|
-
* @param {
|
31
|
+
* @param {Error | null} err
|
31
32
|
* @param {T=} result
|
32
33
|
*/
|
33
34
|
|
@@ -49,9 +50,11 @@ module.exports = class MultiCompiler {
|
|
49
50
|
*/
|
50
51
|
constructor(compilers, options) {
|
51
52
|
if (!Array.isArray(compilers)) {
|
53
|
+
/** @type {Compiler[]} */
|
52
54
|
compilers = Object.keys(compilers).map(name => {
|
53
|
-
|
54
|
-
|
55
|
+
/** @type {Record<string, Compiler>} */
|
56
|
+
(compilers)[name].name = name;
|
57
|
+
return /** @type {Record<string, Compiler>} */ (compilers)[name];
|
55
58
|
});
|
56
59
|
}
|
57
60
|
|
@@ -80,7 +83,7 @@ module.exports = class MultiCompiler {
|
|
80
83
|
this.dependencies = new WeakMap();
|
81
84
|
this.running = false;
|
82
85
|
|
83
|
-
/** @type {Stats[]} */
|
86
|
+
/** @type {(Stats | null)[]} */
|
84
87
|
const compilerStats = this.compilers.map(() => null);
|
85
88
|
let doneCompilers = 0;
|
86
89
|
for (let index = 0; index < this.compilers.length; index++) {
|
@@ -94,7 +97,9 @@ module.exports = class MultiCompiler {
|
|
94
97
|
}
|
95
98
|
compilerStats[compilerIndex] = stats;
|
96
99
|
if (doneCompilers === this.compilers.length) {
|
97
|
-
this.hooks.done.call(
|
100
|
+
this.hooks.done.call(
|
101
|
+
new MultiStats(/** @type {Stats[]} */ (compilerStats))
|
102
|
+
);
|
98
103
|
}
|
99
104
|
});
|
100
105
|
compiler.hooks.invalid.tap("MultiCompiler", () => {
|
@@ -180,6 +185,10 @@ module.exports = class MultiCompiler {
|
|
180
185
|
}
|
181
186
|
}
|
182
187
|
|
188
|
+
/**
|
189
|
+
* @param {string | (function(): string)} name name of the logger, or function called once to get the logger name
|
190
|
+
* @returns {Logger} a logger with that name
|
191
|
+
*/
|
183
192
|
getInfrastructureLogger(name) {
|
184
193
|
return this.compilers[0].getInfrastructureLogger(name);
|
185
194
|
}
|
@@ -202,6 +211,10 @@ module.exports = class MultiCompiler {
|
|
202
211
|
const edges = new Set();
|
203
212
|
/** @type {string[]} */
|
204
213
|
const missing = [];
|
214
|
+
/**
|
215
|
+
* @param {Compiler} compiler compiler
|
216
|
+
* @returns {boolean} target was found
|
217
|
+
*/
|
205
218
|
const targetFound = compiler => {
|
206
219
|
for (const edge of edges) {
|
207
220
|
if (edge.target === compiler) {
|
@@ -210,10 +223,19 @@ module.exports = class MultiCompiler {
|
|
210
223
|
}
|
211
224
|
return false;
|
212
225
|
};
|
226
|
+
/**
|
227
|
+
* @param {{source: Compiler, target: Compiler}} e1 edge 1
|
228
|
+
* @param {{source: Compiler, target: Compiler}} e2 edge 2
|
229
|
+
* @returns {number} result
|
230
|
+
*/
|
213
231
|
const sortEdges = (e1, e2) => {
|
214
232
|
return (
|
215
|
-
|
216
|
-
e1.
|
233
|
+
/** @type {string} */
|
234
|
+
(e1.source.name).localeCompare(
|
235
|
+
/** @type {string} */ (e2.source.name)
|
236
|
+
) ||
|
237
|
+
/** @type {string} */
|
238
|
+
(e1.target.name).localeCompare(/** @type {string} */ (e2.target.name))
|
217
239
|
);
|
218
240
|
};
|
219
241
|
for (const source of this.compilers) {
|
@@ -274,7 +296,14 @@ module.exports = class MultiCompiler {
|
|
274
296
|
runWithDependencies(compilers, fn, callback) {
|
275
297
|
const fulfilledNames = new Set();
|
276
298
|
let remainingCompilers = compilers;
|
299
|
+
/**
|
300
|
+
* @param {string} d dependency
|
301
|
+
* @returns {boolean} when dependency was fulfilled
|
302
|
+
*/
|
277
303
|
const isDependencyFulfilled = d => fulfilledNames.has(d);
|
304
|
+
/**
|
305
|
+
* @returns {Compiler[]} compilers
|
306
|
+
*/
|
278
307
|
const getReadyCompilers = () => {
|
279
308
|
let readyCompilers = [];
|
280
309
|
let list = remainingCompilers;
|
@@ -291,8 +320,12 @@ module.exports = class MultiCompiler {
|
|
291
320
|
}
|
292
321
|
return readyCompilers;
|
293
322
|
};
|
323
|
+
/**
|
324
|
+
* @param {Callback<MultiStats>} callback callback
|
325
|
+
* @returns {void}
|
326
|
+
*/
|
294
327
|
const runCompilers = callback => {
|
295
|
-
if (remainingCompilers.length === 0) return callback();
|
328
|
+
if (remainingCompilers.length === 0) return callback(null);
|
296
329
|
asyncLib.map(
|
297
330
|
getReadyCompilers(),
|
298
331
|
(compiler, callback) => {
|
@@ -302,7 +335,9 @@ module.exports = class MultiCompiler {
|
|
302
335
|
runCompilers(callback);
|
303
336
|
});
|
304
337
|
},
|
305
|
-
|
338
|
+
(err, results) => {
|
339
|
+
callback(err, /** @type {TODO} */ (results));
|
340
|
+
}
|
306
341
|
);
|
307
342
|
};
|
308
343
|
runCompilers(callback);
|
@@ -316,7 +351,7 @@ module.exports = class MultiCompiler {
|
|
316
351
|
* @returns {SetupResult[]} result of setup
|
317
352
|
*/
|
318
353
|
_runGraph(setup, run, callback) {
|
319
|
-
/** @typedef {{ compiler: Compiler, setupResult: SetupResult, result: Stats, state: "pending" | "blocked" | "queued" | "starting" | "running" | "running-outdated" | "done", children: Node[], parents: Node[] }} Node */
|
354
|
+
/** @typedef {{ compiler: Compiler, setupResult: undefined | SetupResult, result: undefined | Stats, state: "pending" | "blocked" | "queued" | "starting" | "running" | "running-outdated" | "done", children: Node[], parents: Node[] }} Node */
|
320
355
|
|
321
356
|
// State transitions for nodes:
|
322
357
|
// -> blocked (initial)
|
@@ -341,12 +376,14 @@ module.exports = class MultiCompiler {
|
|
341
376
|
}));
|
342
377
|
/** @type {Map<string, Node>} */
|
343
378
|
const compilerToNode = new Map();
|
344
|
-
for (const node of nodes)
|
379
|
+
for (const node of nodes) {
|
380
|
+
compilerToNode.set(/** @type {string} */ (node.compiler.name), node);
|
381
|
+
}
|
345
382
|
for (const node of nodes) {
|
346
383
|
const dependencies = this.dependencies.get(node.compiler);
|
347
384
|
if (!dependencies) continue;
|
348
385
|
for (const dep of dependencies) {
|
349
|
-
const parent = compilerToNode.get(dep);
|
386
|
+
const parent = /** @type {Node} */ (compilerToNode.get(dep));
|
350
387
|
node.parents.push(parent);
|
351
388
|
parent.children.push(node);
|
352
389
|
}
|
@@ -361,10 +398,10 @@ module.exports = class MultiCompiler {
|
|
361
398
|
}
|
362
399
|
let errored = false;
|
363
400
|
let running = 0;
|
364
|
-
const parallelism = this._options.parallelism;
|
401
|
+
const parallelism = /** @type {number} */ (this._options.parallelism);
|
365
402
|
/**
|
366
403
|
* @param {Node} node node
|
367
|
-
* @param {Error=} err error
|
404
|
+
* @param {(Error | null)=} err error
|
368
405
|
* @param {Stats=} stats result
|
369
406
|
* @returns {void}
|
370
407
|
*/
|
@@ -440,6 +477,7 @@ module.exports = class MultiCompiler {
|
|
440
477
|
}
|
441
478
|
};
|
442
479
|
|
480
|
+
/** @type {SetupResult[]} */
|
443
481
|
const setupResults = [];
|
444
482
|
nodes.forEach((node, i) => {
|
445
483
|
setupResults.push(
|
@@ -461,7 +499,7 @@ module.exports = class MultiCompiler {
|
|
461
499
|
};
|
462
500
|
const processQueueWorker = () => {
|
463
501
|
while (running < parallelism && queue.length > 0 && !errored) {
|
464
|
-
const node = queue.dequeue();
|
502
|
+
const node = /** @type {Node} */ (queue.dequeue());
|
465
503
|
if (
|
466
504
|
node.state === "queued" ||
|
467
505
|
(node.state === "blocked" &&
|
@@ -469,7 +507,11 @@ module.exports = class MultiCompiler {
|
|
469
507
|
) {
|
470
508
|
running++;
|
471
509
|
node.state = "starting";
|
472
|
-
run(
|
510
|
+
run(
|
511
|
+
node.compiler,
|
512
|
+
/** @type {SetupResult} */ (node.setupResult),
|
513
|
+
nodeDone.bind(null, node)
|
514
|
+
);
|
473
515
|
node.state = "running";
|
474
516
|
}
|
475
517
|
}
|
@@ -576,7 +618,9 @@ module.exports = class MultiCompiler {
|
|
576
618
|
(compiler, callback) => {
|
577
619
|
compiler.close(callback);
|
578
620
|
},
|
579
|
-
|
621
|
+
error => {
|
622
|
+
callback(error);
|
623
|
+
}
|
580
624
|
);
|
581
625
|
}
|
582
626
|
};
|
package/lib/NodeStuffPlugin.js
CHANGED
@@ -32,6 +32,7 @@ const { parseResource } = require("./util/identifier");
|
|
32
32
|
/** @typedef {import("./RuntimeTemplate")} RuntimeTemplate */
|
33
33
|
/** @typedef {import("./javascript/JavascriptParser")} JavascriptParser */
|
34
34
|
/** @typedef {import("./javascript/JavascriptParser").Range} Range */
|
35
|
+
/** @typedef {import("./util/fs").InputFileSystem} InputFileSystem */
|
35
36
|
|
36
37
|
const PLUGIN_NAME = "NodeStuffPlugin";
|
37
38
|
|
@@ -193,7 +194,11 @@ class NodeStuffPlugin {
|
|
193
194
|
break;
|
194
195
|
case true:
|
195
196
|
setModuleConstant("__filename", module =>
|
196
|
-
relative(
|
197
|
+
relative(
|
198
|
+
/** @type {InputFileSystem} */ (compiler.inputFileSystem),
|
199
|
+
context,
|
200
|
+
module.resource
|
201
|
+
)
|
197
202
|
);
|
198
203
|
break;
|
199
204
|
}
|
@@ -227,7 +232,11 @@ class NodeStuffPlugin {
|
|
227
232
|
break;
|
228
233
|
case true:
|
229
234
|
setModuleConstant("__dirname", module =>
|
230
|
-
relative(
|
235
|
+
relative(
|
236
|
+
/** @type {InputFileSystem} */ (compiler.inputFileSystem),
|
237
|
+
context,
|
238
|
+
/** @type {string} */ (module.context)
|
239
|
+
)
|
231
240
|
);
|
232
241
|
break;
|
233
242
|
}
|
@@ -236,7 +245,9 @@ class NodeStuffPlugin {
|
|
236
245
|
.for("__dirname")
|
237
246
|
.tap(PLUGIN_NAME, expr => {
|
238
247
|
if (!parser.state.module) return;
|
239
|
-
return evaluateToString(
|
248
|
+
return evaluateToString(
|
249
|
+
/** @type {string} */ (parser.state.module.context)
|
250
|
+
)(expr);
|
240
251
|
});
|
241
252
|
}
|
242
253
|
parser.hooks.expression
|