webpack 5.91.0 → 5.92.1
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/bin/webpack.js +1 -2
- package/lib/APIPlugin.js +6 -2
- package/lib/Cache.js +1 -1
- package/lib/Chunk.js +7 -4
- package/lib/ChunkGraph.js +20 -7
- package/lib/ChunkGroup.js +9 -3
- package/lib/CleanPlugin.js +1 -1
- package/lib/Compilation.js +33 -27
- package/lib/Compiler.js +28 -8
- package/lib/ConcatenationScope.js +3 -3
- package/lib/ContextModule.js +95 -43
- package/lib/DefinePlugin.js +14 -4
- package/lib/Dependency.js +8 -8
- package/lib/DependencyTemplate.js +10 -5
- package/lib/DllReferencePlugin.js +1 -1
- package/lib/EvalDevToolModulePlugin.js +11 -0
- package/lib/ExportsInfo.js +22 -4
- package/lib/ExternalModule.js +49 -18
- package/lib/FileSystemInfo.js +68 -41
- package/lib/FlagDependencyExportsPlugin.js +21 -7
- package/lib/Generator.js +2 -3
- package/lib/HotModuleReplacementPlugin.js +108 -45
- package/lib/IgnorePlugin.js +4 -1
- package/lib/LibManifestPlugin.js +2 -2
- package/lib/Module.js +11 -12
- package/lib/ModuleFactory.js +3 -3
- package/lib/ModuleFilenameHelpers.js +29 -16
- package/lib/ModuleGraph.js +5 -5
- package/lib/MultiCompiler.js +36 -1
- package/lib/NormalModule.js +10 -12
- package/lib/NormalModuleFactory.js +17 -8
- package/lib/Parser.js +1 -1
- package/lib/PlatformPlugin.js +39 -0
- package/lib/ProgressPlugin.js +1 -1
- package/lib/RecordIdsPlugin.js +4 -4
- package/lib/ResolverFactory.js +3 -3
- package/lib/RuntimeTemplate.js +22 -18
- package/lib/Stats.js +1 -1
- package/lib/Template.js +5 -5
- package/lib/TemplatedPathPlugin.js +16 -1
- package/lib/asset/AssetGenerator.js +15 -0
- package/lib/buildChunkGraph.js +3 -3
- package/lib/cache/MemoryWithGcCachePlugin.js +1 -1
- package/lib/cache/PackFileCacheStrategy.js +2 -2
- package/lib/cache/ResolverCachePlugin.js +8 -8
- package/lib/cache/getLazyHashedEtag.js +1 -1
- package/lib/cli.js +5 -5
- package/lib/config/browserslistTargetHandler.js +7 -1
- package/lib/config/defaults.js +85 -34
- package/lib/config/target.js +18 -11
- package/lib/container/ContainerEntryModule.js +1 -1
- package/lib/css/CssExportsGenerator.js +43 -17
- package/lib/css/CssGenerator.js +22 -12
- package/lib/css/CssLoadingRuntimeModule.js +8 -5
- package/lib/css/CssModulesPlugin.js +197 -100
- package/lib/css/CssParser.js +24 -15
- package/lib/css/walkCssTokens.js +1 -1
- package/lib/debug/ProfilingPlugin.js +1 -1
- package/lib/dependencies/ContextElementDependency.js +2 -2
- package/lib/dependencies/CssExportDependency.js +2 -2
- package/lib/dependencies/CssLocalIdentifierDependency.js +9 -2
- package/lib/dependencies/CssUrlDependency.js +5 -4
- package/lib/dependencies/ExportsInfoDependency.js +1 -1
- package/lib/dependencies/ExternalModuleDependency.js +4 -2
- package/lib/dependencies/HarmonyEvaluatedImportSpecifierDependency.js +2 -2
- package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +2 -2
- package/lib/dependencies/HarmonyImportDependency.js +2 -2
- package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +41 -18
- package/lib/dependencies/HarmonyImportSideEffectDependency.js +2 -2
- package/lib/dependencies/HarmonyImportSpecifierDependency.js +43 -32
- package/lib/dependencies/ImportDependency.js +2 -2
- package/lib/dependencies/ImportEagerDependency.js +2 -2
- package/lib/dependencies/ImportMetaPlugin.js +1 -1
- package/lib/dependencies/ImportParserPlugin.js +3 -1
- package/lib/dependencies/ImportWeakDependency.js +2 -2
- package/lib/dependencies/LoaderPlugin.js +2 -2
- package/lib/dependencies/ModuleDependency.js +2 -2
- package/lib/dependencies/PureExpressionDependency.js +63 -49
- package/lib/dependencies/WorkerDependency.js +1 -1
- package/lib/esm/ModuleChunkLoadingRuntimeModule.js +90 -2
- package/lib/hmr/LazyCompilationPlugin.js +2 -2
- package/lib/ids/ChunkModuleIdRangePlugin.js +1 -1
- package/lib/ids/DeterministicChunkIdsPlugin.js +1 -1
- package/lib/ids/DeterministicModuleIdsPlugin.js +1 -1
- package/lib/ids/IdHelpers.js +6 -6
- package/lib/ids/NamedChunkIdsPlugin.js +1 -1
- package/lib/ids/NamedModuleIdsPlugin.js +1 -1
- package/lib/ids/SyncModuleIdsPlugin.js +2 -2
- package/lib/index.js +11 -0
- package/lib/javascript/CommonJsChunkFormatPlugin.js +1 -1
- package/lib/javascript/JavascriptGenerator.js +0 -1
- package/lib/javascript/JavascriptModulesPlugin.js +174 -17
- package/lib/javascript/JavascriptParser.js +37 -16
- package/lib/library/AbstractLibraryPlugin.js +2 -2
- package/lib/library/AmdLibraryPlugin.js +2 -2
- package/lib/library/AssignLibraryPlugin.js +3 -3
- package/lib/library/ExportPropertyLibraryPlugin.js +2 -2
- package/lib/library/JsonpLibraryPlugin.js +2 -2
- package/lib/library/ModuleLibraryPlugin.js +2 -2
- package/lib/library/SystemLibraryPlugin.js +2 -2
- package/lib/library/UmdLibraryPlugin.js +33 -12
- package/lib/logging/createConsoleLogger.js +2 -2
- package/lib/node/CommonJsChunkLoadingPlugin.js +2 -1
- package/lib/node/NodeEnvironmentPlugin.js +1 -1
- package/lib/node/NodeTemplatePlugin.js +1 -1
- package/lib/node/ReadFileCompileWasmPlugin.js +1 -1
- package/lib/node/nodeConsole.js +1 -1
- package/lib/optimize/AggressiveMergingPlugin.js +1 -1
- package/lib/optimize/ConcatenatedModule.js +11 -76
- package/lib/optimize/InnerGraph.js +1 -1
- package/lib/optimize/LimitChunkCountPlugin.js +1 -2
- package/lib/optimize/ModuleConcatenationPlugin.js +1 -1
- package/lib/optimize/RealContentHashPlugin.js +3 -3
- package/lib/optimize/SideEffectsFlagPlugin.js +2 -2
- package/lib/optimize/SplitChunksPlugin.js +8 -8
- package/lib/performance/SizeLimitsPlugin.js +2 -2
- package/lib/rules/ObjectMatcherRulePlugin.js +11 -1
- package/lib/rules/RuleSetCompiler.js +9 -7
- package/lib/runtime/LoadScriptRuntimeModule.js +1 -1
- package/lib/runtime/StartupChunkDependenciesPlugin.js +1 -1
- package/lib/schemes/HttpUriPlugin.js +1 -1
- package/lib/serialization/BinaryMiddleware.js +4 -4
- package/lib/serialization/FileMiddleware.js +3 -3
- package/lib/serialization/NullPrototypeObjectSerializer.js +2 -2
- package/lib/serialization/ObjectMiddleware.js +6 -5
- package/lib/serialization/PlainObjectSerializer.js +2 -2
- package/lib/serialization/SerializerMiddleware.js +2 -2
- package/lib/serialization/SingleItemMiddleware.js +2 -2
- package/lib/serialization/types.js +1 -1
- package/lib/sharing/ConsumeSharedModule.js +1 -1
- package/lib/sharing/ProvideSharedPlugin.js +1 -1
- package/lib/sharing/resolveMatchedConfigs.js +1 -1
- package/lib/stats/DefaultStatsFactoryPlugin.js +20 -20
- package/lib/stats/DefaultStatsPrinterPlugin.js +1 -1
- package/lib/stats/StatsFactory.js +2 -2
- package/lib/stats/StatsPrinter.js +6 -6
- package/lib/util/ArrayQueue.js +14 -21
- package/lib/util/AsyncQueue.js +1 -1
- package/lib/util/Queue.js +8 -2
- package/lib/util/SortableSet.js +16 -4
- package/lib/util/TupleQueue.js +8 -2
- package/lib/util/WeakTupleMap.js +3 -3
- package/lib/util/binarySearchBounds.js +1 -1
- package/lib/util/cleverMerge.js +2 -2
- package/lib/util/comparators.js +4 -2
- package/lib/util/conventions.js +1 -1
- package/lib/util/createHash.js +3 -5
- package/lib/util/deprecation.js +3 -3
- package/lib/util/deterministicGrouping.js +2 -2
- package/lib/util/findGraphRoots.js +1 -1
- package/lib/util/fs.js +15 -15
- package/lib/util/identifier.js +5 -5
- package/lib/util/mergeScope.js +79 -0
- package/lib/util/runtime.js +2 -17
- package/lib/util/semver.js +3 -0
- package/lib/util/smartGrouping.js +3 -3
- package/lib/wasm-async/AsyncWasmLoadingRuntimeModule.js +4 -2
- package/lib/wasm-async/AsyncWebAssemblyGenerator.js +1 -1
- package/lib/wasm-async/AsyncWebAssemblyModulesPlugin.js +3 -3
- package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +1 -1
- package/lib/wasm-sync/WebAssemblyGenerator.js +17 -17
- package/lib/wasm-sync/WebAssemblyModulesPlugin.js +1 -1
- package/lib/wasm-sync/WebAssemblyUtils.js +2 -1
- package/lib/web/FetchCompileWasmPlugin.js +1 -1
- package/lib/web/JsonpChunkLoadingRuntimeModule.js +1 -1
- package/lib/webpack.js +12 -3
- package/package.json +20 -18
- package/schemas/WebpackOptions.check.js +1 -1
- package/schemas/WebpackOptions.json +30 -2
- 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 +213 -81
@@ -42,19 +42,28 @@ const {
|
|
42
42
|
WEBPACK_MODULE_TYPE_RUNTIME
|
43
43
|
} = require("./ModuleTypeConstants");
|
44
44
|
|
45
|
+
/** @typedef {import("estree").CallExpression} CallExpression */
|
46
|
+
/** @typedef {import("estree").Expression} Expression */
|
45
47
|
/** @typedef {import("./Chunk")} Chunk */
|
48
|
+
/** @typedef {import("./Chunk").ChunkId} ChunkId */
|
46
49
|
/** @typedef {import("./Compilation").AssetInfo} AssetInfo */
|
47
50
|
/** @typedef {import("./Compiler")} Compiler */
|
51
|
+
/** @typedef {import("./Dependency").DependencyLocation} DependencyLocation */
|
48
52
|
/** @typedef {import("./Module")} Module */
|
53
|
+
/** @typedef {import("./Module").BuildInfo} BuildInfo */
|
49
54
|
/** @typedef {import("./RuntimeModule")} RuntimeModule */
|
55
|
+
/** @typedef {import("./javascript/BasicEvaluatedExpression")} BasicEvaluatedExpression */
|
56
|
+
/** @typedef {import("./javascript/JavascriptParserHelpers").Range} Range */
|
50
57
|
/** @typedef {import("./util/runtime").RuntimeSpec} RuntimeSpec */
|
51
58
|
|
52
59
|
/**
|
53
|
-
* @typedef {
|
60
|
+
* @typedef {object} HMRJavascriptParserHooks
|
54
61
|
* @property {SyncBailHook<[TODO, string[]], void>} hotAcceptCallback
|
55
62
|
* @property {SyncBailHook<[TODO, string[]], void>} hotAcceptWithoutCallback
|
56
63
|
*/
|
57
64
|
|
65
|
+
/** @typedef {Map<string, { updatedChunkIds: Set<ChunkId>, removedChunkIds: Set<ChunkId>, removedModules: Set<Module>, filename: string, assetInfo: AssetInfo }>} HotUpdateMainContentByRuntime */
|
66
|
+
|
58
67
|
/** @type {WeakMap<JavascriptParser, HMRJavascriptParserHooks>} */
|
59
68
|
const parserHooksMap = new WeakMap();
|
60
69
|
|
@@ -82,6 +91,9 @@ class HotModuleReplacementPlugin {
|
|
82
91
|
return hooks;
|
83
92
|
}
|
84
93
|
|
94
|
+
/**
|
95
|
+
* @param {object=} options options
|
96
|
+
*/
|
85
97
|
constructor(options) {
|
86
98
|
this.options = options || {};
|
87
99
|
}
|
@@ -97,6 +109,11 @@ class HotModuleReplacementPlugin {
|
|
97
109
|
compiler.options.output.strictModuleErrorHandling = true;
|
98
110
|
const runtimeRequirements = [RuntimeGlobals.module];
|
99
111
|
|
112
|
+
/**
|
113
|
+
* @param {JavascriptParser} parser the parser
|
114
|
+
* @param {typeof ModuleHotAcceptDependency} ParamDependency dependency
|
115
|
+
* @returns {(expr: CallExpression) => boolean | undefined} callback
|
116
|
+
*/
|
100
117
|
const createAcceptHandler = (parser, ParamDependency) => {
|
101
118
|
const { hotAcceptCallback, hotAcceptWithoutCallback } =
|
102
119
|
HotModuleReplacementPlugin.getParserHooks(parser);
|
@@ -105,27 +122,38 @@ class HotModuleReplacementPlugin {
|
|
105
122
|
const module = parser.state.module;
|
106
123
|
const dep = new ConstDependency(
|
107
124
|
`${module.moduleArgument}.hot.accept`,
|
108
|
-
expr.callee.range,
|
125
|
+
/** @type {Range} */ (expr.callee.range),
|
109
126
|
runtimeRequirements
|
110
127
|
);
|
111
|
-
dep.loc = expr.loc;
|
128
|
+
dep.loc = /** @type {DependencyLocation} */ (expr.loc);
|
112
129
|
module.addPresentationalDependency(dep);
|
113
|
-
|
130
|
+
/** @type {BuildInfo} */
|
131
|
+
(module.buildInfo).moduleConcatenationBailout =
|
132
|
+
"Hot Module Replacement";
|
114
133
|
if (expr.arguments.length >= 1) {
|
115
134
|
const arg = parser.evaluateExpression(expr.arguments[0]);
|
135
|
+
/** @type {BasicEvaluatedExpression[]} */
|
116
136
|
let params = [];
|
117
|
-
let requests = [];
|
118
137
|
if (arg.isString()) {
|
119
138
|
params = [arg];
|
120
139
|
} else if (arg.isArray()) {
|
121
|
-
params =
|
140
|
+
params =
|
141
|
+
/** @type {BasicEvaluatedExpression[]} */
|
142
|
+
(arg.items).filter(param => param.isString());
|
122
143
|
}
|
144
|
+
/** @type {string[]} */
|
145
|
+
let requests = [];
|
123
146
|
if (params.length > 0) {
|
124
147
|
params.forEach((param, idx) => {
|
125
|
-
const request = param.string;
|
126
|
-
const dep = new ParamDependency(
|
148
|
+
const request = /** @type {string} */ (param.string);
|
149
|
+
const dep = new ParamDependency(
|
150
|
+
request,
|
151
|
+
/** @type {Range} */ (param.range)
|
152
|
+
);
|
127
153
|
dep.optional = true;
|
128
|
-
dep.loc = Object.create(
|
154
|
+
dep.loc = Object.create(
|
155
|
+
/** @type {DependencyLocation} */ (expr.loc)
|
156
|
+
);
|
129
157
|
dep.loc.index = idx;
|
130
158
|
module.addDependency(dep);
|
131
159
|
requests.push(request);
|
@@ -147,28 +175,40 @@ class HotModuleReplacementPlugin {
|
|
147
175
|
};
|
148
176
|
};
|
149
177
|
|
178
|
+
/**
|
179
|
+
* @param {JavascriptParser} parser the parser
|
180
|
+
* @param {typeof ModuleHotDeclineDependency} ParamDependency dependency
|
181
|
+
* @returns {(expr: CallExpression) => boolean | undefined} callback
|
182
|
+
*/
|
150
183
|
const createDeclineHandler = (parser, ParamDependency) => expr => {
|
151
184
|
const module = parser.state.module;
|
152
185
|
const dep = new ConstDependency(
|
153
186
|
`${module.moduleArgument}.hot.decline`,
|
154
|
-
expr.callee.range,
|
187
|
+
/** @type {Range} */ (expr.callee.range),
|
155
188
|
runtimeRequirements
|
156
189
|
);
|
157
|
-
dep.loc = expr.loc;
|
190
|
+
dep.loc = /** @type {DependencyLocation} */ (expr.loc);
|
158
191
|
module.addPresentationalDependency(dep);
|
159
|
-
|
192
|
+
/** @type {BuildInfo} */
|
193
|
+
(module.buildInfo).moduleConcatenationBailout = "Hot Module Replacement";
|
160
194
|
if (expr.arguments.length === 1) {
|
161
195
|
const arg = parser.evaluateExpression(expr.arguments[0]);
|
196
|
+
/** @type {BasicEvaluatedExpression[]} */
|
162
197
|
let params = [];
|
163
198
|
if (arg.isString()) {
|
164
199
|
params = [arg];
|
165
200
|
} else if (arg.isArray()) {
|
166
|
-
params =
|
201
|
+
params =
|
202
|
+
/** @type {BasicEvaluatedExpression[]} */
|
203
|
+
(arg.items).filter(param => param.isString());
|
167
204
|
}
|
168
205
|
params.forEach((param, idx) => {
|
169
|
-
const dep = new ParamDependency(
|
206
|
+
const dep = new ParamDependency(
|
207
|
+
/** @type {string} */ (param.string),
|
208
|
+
/** @type {Range} */ (param.range)
|
209
|
+
);
|
170
210
|
dep.optional = true;
|
171
|
-
dep.loc = Object.create(expr.loc);
|
211
|
+
dep.loc = Object.create(/** @type {DependencyLocation} */ (expr.loc));
|
172
212
|
dep.loc.index = idx;
|
173
213
|
module.addDependency(dep);
|
174
214
|
});
|
@@ -176,16 +216,21 @@ class HotModuleReplacementPlugin {
|
|
176
216
|
return true;
|
177
217
|
};
|
178
218
|
|
219
|
+
/**
|
220
|
+
* @param {JavascriptParser} parser the parser
|
221
|
+
* @returns {(expr: Expression) => boolean | undefined} callback
|
222
|
+
*/
|
179
223
|
const createHMRExpressionHandler = parser => expr => {
|
180
224
|
const module = parser.state.module;
|
181
225
|
const dep = new ConstDependency(
|
182
226
|
`${module.moduleArgument}.hot`,
|
183
|
-
expr.range,
|
227
|
+
/** @type {Range} */ (expr.range),
|
184
228
|
runtimeRequirements
|
185
229
|
);
|
186
|
-
dep.loc = expr.loc;
|
230
|
+
dep.loc = /** @type {DependencyLocation} */ (expr.loc);
|
187
231
|
module.addPresentationalDependency(dep);
|
188
|
-
|
232
|
+
/** @type {BuildInfo} */
|
233
|
+
(module.buildInfo).moduleConcatenationBailout = "Hot Module Replacement";
|
189
234
|
return true;
|
190
235
|
};
|
191
236
|
|
@@ -303,7 +348,9 @@ class HotModuleReplacementPlugin {
|
|
303
348
|
//#endregion
|
304
349
|
|
305
350
|
let hotIndex = 0;
|
351
|
+
/** @type {Record<string, string>} */
|
306
352
|
const fullHashChunkModuleHashes = {};
|
353
|
+
/** @type {Record<string, string>} */
|
307
354
|
const chunkModuleHashes = {};
|
308
355
|
|
309
356
|
compilation.hooks.record.tap(PLUGIN_NAME, (compilation, records) => {
|
@@ -316,18 +363,20 @@ class HotModuleReplacementPlugin {
|
|
316
363
|
records.chunkHashes = {};
|
317
364
|
records.chunkRuntime = {};
|
318
365
|
for (const chunk of compilation.chunks) {
|
319
|
-
|
320
|
-
records.
|
366
|
+
const chunkId = /** @type {ChunkId} */ (chunk.id);
|
367
|
+
records.chunkHashes[chunkId] = chunk.hash;
|
368
|
+
records.chunkRuntime[chunkId] = getRuntimeKey(chunk.runtime);
|
321
369
|
}
|
322
370
|
records.chunkModuleIds = {};
|
323
371
|
for (const chunk of compilation.chunks) {
|
324
|
-
records.chunkModuleIds[chunk.id] =
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
372
|
+
records.chunkModuleIds[/** @type {ChunkId} */ (chunk.id)] =
|
373
|
+
Array.from(
|
374
|
+
chunkGraph.getOrderedChunkModulesIterable(
|
375
|
+
chunk,
|
376
|
+
compareModulesById(chunkGraph)
|
377
|
+
),
|
378
|
+
m => chunkGraph.getModuleId(m)
|
379
|
+
);
|
331
380
|
}
|
332
381
|
});
|
333
382
|
/** @type {TupleSet<[Module, Chunk]>} */
|
@@ -340,6 +389,10 @@ class HotModuleReplacementPlugin {
|
|
340
389
|
const chunkGraph = compilation.chunkGraph;
|
341
390
|
const records = compilation.records;
|
342
391
|
for (const chunk of compilation.chunks) {
|
392
|
+
/**
|
393
|
+
* @param {Module} module module
|
394
|
+
* @returns {string} module hash
|
395
|
+
*/
|
343
396
|
const getModuleHash = module => {
|
344
397
|
if (
|
345
398
|
compilation.codeGenerationResults.has(module, chunk.runtime)
|
@@ -454,7 +507,7 @@ class HotModuleReplacementPlugin {
|
|
454
507
|
chunkModuleHashes[key] = hash;
|
455
508
|
}
|
456
509
|
|
457
|
-
/** @type {
|
510
|
+
/** @type {HotUpdateMainContentByRuntime} */
|
458
511
|
const hotUpdateMainContentByRuntime = new Map();
|
459
512
|
let allOldRuntime;
|
460
513
|
for (const key of Object.keys(records.chunkRuntime)) {
|
@@ -470,13 +523,16 @@ class HotModuleReplacementPlugin {
|
|
470
523
|
runtime
|
471
524
|
}
|
472
525
|
);
|
473
|
-
hotUpdateMainContentByRuntime.set(
|
474
|
-
|
475
|
-
|
476
|
-
|
477
|
-
|
478
|
-
|
479
|
-
|
526
|
+
hotUpdateMainContentByRuntime.set(
|
527
|
+
/** @type {string} */ (runtime),
|
528
|
+
{
|
529
|
+
updatedChunkIds: new Set(),
|
530
|
+
removedChunkIds: new Set(),
|
531
|
+
removedModules: new Set(),
|
532
|
+
filename,
|
533
|
+
assetInfo
|
534
|
+
}
|
535
|
+
);
|
480
536
|
});
|
481
537
|
if (hotUpdateMainContentByRuntime.size === 0) return;
|
482
538
|
|
@@ -506,6 +562,7 @@ class HotModuleReplacementPlugin {
|
|
506
562
|
}
|
507
563
|
}
|
508
564
|
|
565
|
+
/** @type {ChunkId | null} */
|
509
566
|
let chunkId;
|
510
567
|
let newModules;
|
511
568
|
let newRuntimeModules;
|
@@ -554,9 +611,10 @@ class HotModuleReplacementPlugin {
|
|
554
611
|
if (removedFromRuntime) {
|
555
612
|
// chunk was removed from some runtimes
|
556
613
|
forEachRuntime(removedFromRuntime, runtime => {
|
557
|
-
hotUpdateMainContentByRuntime
|
558
|
-
|
559
|
-
|
614
|
+
const item = hotUpdateMainContentByRuntime.get(
|
615
|
+
/** @type {string} */ (runtime)
|
616
|
+
);
|
617
|
+
item.removedChunkIds.add(/** @type {ChunkId} */ (chunkId));
|
560
618
|
});
|
561
619
|
// dispose modules from the chunk in these runtimes
|
562
620
|
// where they are no longer in this runtime
|
@@ -597,12 +655,16 @@ class HotModuleReplacementPlugin {
|
|
597
655
|
if (typeof moduleRuntime === "string") {
|
598
656
|
if (moduleRuntime === runtime) return;
|
599
657
|
} else if (moduleRuntime !== undefined) {
|
600
|
-
if (
|
658
|
+
if (
|
659
|
+
moduleRuntime.has(/** @type {string} */ (runtime))
|
660
|
+
)
|
661
|
+
return;
|
601
662
|
}
|
602
663
|
}
|
603
|
-
hotUpdateMainContentByRuntime
|
604
|
-
|
605
|
-
|
664
|
+
const item = hotUpdateMainContentByRuntime.get(
|
665
|
+
/** @type {string} */ (runtime)
|
666
|
+
);
|
667
|
+
item.removedModules.add(module);
|
606
668
|
});
|
607
669
|
}
|
608
670
|
}
|
@@ -676,9 +738,10 @@ class HotModuleReplacementPlugin {
|
|
676
738
|
}
|
677
739
|
}
|
678
740
|
forEachRuntime(newRuntime, runtime => {
|
679
|
-
hotUpdateMainContentByRuntime
|
680
|
-
|
681
|
-
|
741
|
+
const item = hotUpdateMainContentByRuntime.get(
|
742
|
+
/** @type {string} */ (runtime)
|
743
|
+
);
|
744
|
+
item.updatedChunkIds.add(/** @type {ChunkId} */ (chunkId));
|
682
745
|
});
|
683
746
|
}
|
684
747
|
}
|
package/lib/IgnorePlugin.js
CHANGED
package/lib/LibManifestPlugin.js
CHANGED
@@ -16,14 +16,14 @@ const { dirname, mkdirp } = require("./util/fs");
|
|
16
16
|
/** @typedef {import("./Module").BuildMeta} BuildMeta */
|
17
17
|
|
18
18
|
/**
|
19
|
-
* @typedef {
|
19
|
+
* @typedef {object} ManifestModuleData
|
20
20
|
* @property {string | number} id
|
21
21
|
* @property {BuildMeta} buildMeta
|
22
22
|
* @property {boolean | string[] | undefined} exports
|
23
23
|
*/
|
24
24
|
|
25
25
|
/**
|
26
|
-
* @typedef {
|
26
|
+
* @typedef {object} LibManifestPluginOptions
|
27
27
|
* @property {string=} context Context of requests in the manifest file (defaults to the webpack context).
|
28
28
|
* @property {boolean=} entryOnly If true, only entry points will be exposed (default: true).
|
29
29
|
* @property {boolean=} format If true, manifest json file (output) will be formatted.
|
package/lib/Module.js
CHANGED
@@ -45,7 +45,7 @@ const makeSerializable = require("./util/makeSerializable");
|
|
45
45
|
/** @typedef {import("./util/runtime").RuntimeSpec} RuntimeSpec */
|
46
46
|
|
47
47
|
/**
|
48
|
-
* @typedef {
|
48
|
+
* @typedef {object} SourceContext
|
49
49
|
* @property {DependencyTemplates} dependencyTemplates the dependency templates
|
50
50
|
* @property {RuntimeTemplate} runtimeTemplate the runtime template
|
51
51
|
* @property {ModuleGraph} moduleGraph the module graph
|
@@ -56,13 +56,12 @@ const makeSerializable = require("./util/makeSerializable");
|
|
56
56
|
|
57
57
|
// TODO webpack 6: compilation will be required in CodeGenerationContext
|
58
58
|
/**
|
59
|
-
* @typedef {
|
59
|
+
* @typedef {object} CodeGenerationContext
|
60
60
|
* @property {DependencyTemplates} dependencyTemplates the dependency templates
|
61
61
|
* @property {RuntimeTemplate} runtimeTemplate the runtime template
|
62
62
|
* @property {ModuleGraph} moduleGraph the module graph
|
63
63
|
* @property {ChunkGraph} chunkGraph the chunk graph
|
64
|
-
* @property {RuntimeSpec} runtime the
|
65
|
-
* @property {RuntimeSpec[]} [runtimes] the runtimes code should be generated for
|
64
|
+
* @property {RuntimeSpec} runtime the runtimes code should be generated for
|
66
65
|
* @property {ConcatenationScope=} concatenationScope when in concatenated module, information about other concatenated modules
|
67
66
|
* @property {CodeGenerationResults | undefined} codeGenerationResults code generation results of other modules (need to have a codeGenerationDependency to use that)
|
68
67
|
* @property {Compilation=} compilation the compilation
|
@@ -70,7 +69,7 @@ const makeSerializable = require("./util/makeSerializable");
|
|
70
69
|
*/
|
71
70
|
|
72
71
|
/**
|
73
|
-
* @typedef {
|
72
|
+
* @typedef {object} ConcatenationBailoutReasonContext
|
74
73
|
* @property {ModuleGraph} moduleGraph the module graph
|
75
74
|
* @property {ChunkGraph} chunkGraph the chunk graph
|
76
75
|
*/
|
@@ -79,7 +78,7 @@ const makeSerializable = require("./util/makeSerializable");
|
|
79
78
|
/** @typedef {ReadonlySet<string>} ReadOnlyRuntimeRequirements */
|
80
79
|
|
81
80
|
/**
|
82
|
-
* @typedef {
|
81
|
+
* @typedef {object} CodeGenerationResult
|
83
82
|
* @property {Map<string, Source>} sources the resulting sources for all source types
|
84
83
|
* @property {Map<string, any>=} data the resulting data for all source types
|
85
84
|
* @property {ReadOnlyRuntimeRequirements} runtimeRequirements the runtime requirements
|
@@ -87,13 +86,13 @@ const makeSerializable = require("./util/makeSerializable");
|
|
87
86
|
*/
|
88
87
|
|
89
88
|
/**
|
90
|
-
* @typedef {
|
89
|
+
* @typedef {object} LibIdentOptions
|
91
90
|
* @property {string} context absolute context path to which lib ident is relative to
|
92
|
-
* @property {
|
91
|
+
* @property {object=} associatedObjectForCache object for caching
|
93
92
|
*/
|
94
93
|
|
95
94
|
/**
|
96
|
-
* @typedef {
|
95
|
+
* @typedef {object} KnownBuildMeta
|
97
96
|
* @property {string=} moduleArgument
|
98
97
|
* @property {string=} exportsArgument
|
99
98
|
* @property {boolean=} strict
|
@@ -106,7 +105,7 @@ const makeSerializable = require("./util/makeSerializable");
|
|
106
105
|
*/
|
107
106
|
|
108
107
|
/**
|
109
|
-
* @typedef {
|
108
|
+
* @typedef {object} KnownBuildInfo
|
110
109
|
* @property {boolean=} cacheable
|
111
110
|
* @property {boolean=} parsed
|
112
111
|
* @property {LazySet<string>=} fileDependencies
|
@@ -121,7 +120,7 @@ const makeSerializable = require("./util/makeSerializable");
|
|
121
120
|
*/
|
122
121
|
|
123
122
|
/**
|
124
|
-
* @typedef {
|
123
|
+
* @typedef {object} NeedBuildContext
|
125
124
|
* @property {Compilation} compilation
|
126
125
|
* @property {FileSystemInfo} fileSystemInfo
|
127
126
|
* @property {Map<string, string | Set<string>>} valueCacheVersions
|
@@ -131,7 +130,7 @@ const makeSerializable = require("./util/makeSerializable");
|
|
131
130
|
/** @typedef {KnownBuildInfo & Record<string, any>} BuildInfo */
|
132
131
|
|
133
132
|
/**
|
134
|
-
* @typedef {
|
133
|
+
* @typedef {object} FactoryMeta
|
135
134
|
* @property {boolean=} sideEffectFree
|
136
135
|
*/
|
137
136
|
|
package/lib/ModuleFactory.js
CHANGED
@@ -10,7 +10,7 @@
|
|
10
10
|
/** @typedef {import("./Module")} Module */
|
11
11
|
|
12
12
|
/**
|
13
|
-
* @typedef {
|
13
|
+
* @typedef {object} ModuleFactoryResult
|
14
14
|
* @property {Module=} module the created module or unset if no module was created
|
15
15
|
* @property {Set<string>=} fileDependencies
|
16
16
|
* @property {Set<string>=} contextDependencies
|
@@ -19,14 +19,14 @@
|
|
19
19
|
*/
|
20
20
|
|
21
21
|
/**
|
22
|
-
* @typedef {
|
22
|
+
* @typedef {object} ModuleFactoryCreateDataContextInfo
|
23
23
|
* @property {string} issuer
|
24
24
|
* @property {string | null=} issuerLayer
|
25
25
|
* @property {string} compiler
|
26
26
|
*/
|
27
27
|
|
28
28
|
/**
|
29
|
-
* @typedef {
|
29
|
+
* @typedef {object} ModuleFactoryCreateData
|
30
30
|
* @property {ModuleFactoryCreateDataContextInfo} contextInfo
|
31
31
|
* @property {ResolveOptions=} resolveOptions
|
32
32
|
* @property {string} context
|
@@ -46,11 +46,13 @@ ModuleFilenameHelpers.REGEXP_HASH = /\[hash\]/gi;
|
|
46
46
|
ModuleFilenameHelpers.NAMESPACE = "[namespace]";
|
47
47
|
ModuleFilenameHelpers.REGEXP_NAMESPACE = /\[namespace\]/gi;
|
48
48
|
|
49
|
+
/** @typedef {() => string} ReturnStringCallback */
|
50
|
+
|
49
51
|
/**
|
50
52
|
* Returns a function that returns the part of the string after the token
|
51
|
-
* @param {
|
53
|
+
* @param {ReturnStringCallback} strFn the function to get the string
|
52
54
|
* @param {string} token the token to search for
|
53
|
-
* @returns {
|
55
|
+
* @returns {ReturnStringCallback} a function that returns the part of the string after the token
|
54
56
|
*/
|
55
57
|
const getAfter = (strFn, token) => {
|
56
58
|
return () => {
|
@@ -62,9 +64,9 @@ const getAfter = (strFn, token) => {
|
|
62
64
|
|
63
65
|
/**
|
64
66
|
* Returns a function that returns the part of the string before the token
|
65
|
-
* @param {
|
67
|
+
* @param {ReturnStringCallback} strFn the function to get the string
|
66
68
|
* @param {string} token the token to search for
|
67
|
-
* @returns {
|
69
|
+
* @returns {ReturnStringCallback} a function that returns the part of the string before the token
|
68
70
|
*/
|
69
71
|
const getBefore = (strFn, token) => {
|
70
72
|
return () => {
|
@@ -76,11 +78,11 @@ const getBefore = (strFn, token) => {
|
|
76
78
|
|
77
79
|
/**
|
78
80
|
* Returns a function that returns a hash of the string
|
79
|
-
* @param {
|
80
|
-
* @param {string | Hash} hashFunction the hash function to use
|
81
|
-
* @returns {
|
81
|
+
* @param {ReturnStringCallback} strFn the function to get the string
|
82
|
+
* @param {string | Hash=} hashFunction the hash function to use
|
83
|
+
* @returns {ReturnStringCallback} a function that returns the hash of the string
|
82
84
|
*/
|
83
|
-
const getHash = (strFn, hashFunction) => {
|
85
|
+
const getHash = (strFn, hashFunction = "md4") => {
|
84
86
|
return () => {
|
85
87
|
const hash = createHash(hashFunction);
|
86
88
|
hash.update(strFn());
|
@@ -116,7 +118,7 @@ const asRegExp = test => {
|
|
116
118
|
* Returns a lazy object. The object is lazy in the sense that the properties are
|
117
119
|
* only evaluated when they are accessed. This is only obtained by setting a function as the value for each key.
|
118
120
|
* @param {Record<string, () => T>} obj the object to convert to a lazy access object
|
119
|
-
* @returns {
|
121
|
+
* @returns {object} the lazy access object
|
120
122
|
*/
|
121
123
|
const lazyObject = obj => {
|
122
124
|
const newObj = {};
|
@@ -144,10 +146,10 @@ const SQUARE_BRACKET_TAG_REGEXP = /\[\\*([\w-]+)\\*\]/gi;
|
|
144
146
|
*
|
145
147
|
* @param {Module | string} module the module
|
146
148
|
* @param {TODO} options options
|
147
|
-
* @param {
|
149
|
+
* @param {object} contextInfo context info
|
148
150
|
* @param {RequestShortener} contextInfo.requestShortener requestShortener
|
149
151
|
* @param {ChunkGraph} contextInfo.chunkGraph chunk graph
|
150
|
-
* @param {string | Hash} contextInfo.hashFunction the hash function to use
|
152
|
+
* @param {string | Hash=} contextInfo.hashFunction the hash function to use
|
151
153
|
* @returns {string} the filename
|
152
154
|
*/
|
153
155
|
ModuleFilenameHelpers.createFilename = (
|
@@ -167,11 +169,16 @@ ModuleFilenameHelpers.createFilename = (
|
|
167
169
|
|
168
170
|
let absoluteResourcePath;
|
169
171
|
let hash;
|
172
|
+
/** @type {ReturnStringCallback} */
|
170
173
|
let identifier;
|
174
|
+
/** @type {ReturnStringCallback} */
|
171
175
|
let moduleId;
|
176
|
+
/** @type {ReturnStringCallback} */
|
172
177
|
let shortIdentifier;
|
173
178
|
if (typeof module === "string") {
|
174
|
-
shortIdentifier =
|
179
|
+
shortIdentifier =
|
180
|
+
/** @type {ReturnStringCallback} */
|
181
|
+
(memoize(() => requestShortener.shorten(module)));
|
175
182
|
identifier = shortIdentifier;
|
176
183
|
moduleId = () => "";
|
177
184
|
absoluteResourcePath = () => module.split("!").pop();
|
@@ -180,15 +187,21 @@ ModuleFilenameHelpers.createFilename = (
|
|
180
187
|
shortIdentifier = memoize(() =>
|
181
188
|
module.readableIdentifier(requestShortener)
|
182
189
|
);
|
183
|
-
identifier =
|
184
|
-
|
190
|
+
identifier =
|
191
|
+
/** @type {ReturnStringCallback} */
|
192
|
+
(memoize(() => requestShortener.shorten(module.identifier())));
|
193
|
+
moduleId =
|
194
|
+
/** @type {ReturnStringCallback} */
|
195
|
+
(() => chunkGraph.getModuleId(module));
|
185
196
|
absoluteResourcePath = () =>
|
186
197
|
module instanceof NormalModule
|
187
198
|
? module.resource
|
188
199
|
: module.identifier().split("!").pop();
|
189
200
|
hash = getHash(identifier, hashFunction);
|
190
201
|
}
|
191
|
-
const resource =
|
202
|
+
const resource =
|
203
|
+
/** @type {ReturnStringCallback} */
|
204
|
+
(memoize(() => shortIdentifier().split("!").pop()));
|
192
205
|
|
193
206
|
const loaders = getBefore(shortIdentifier, "!");
|
194
207
|
const allLoaders = getBefore(identifier, "!");
|
@@ -249,7 +262,7 @@ ModuleFilenameHelpers.createFilename = (
|
|
249
262
|
]);
|
250
263
|
|
251
264
|
// TODO webpack 6: consider removing weird double placeholders
|
252
|
-
return opts.moduleFilenameTemplate
|
265
|
+
return /** @type {string} */ (opts.moduleFilenameTemplate)
|
253
266
|
.replace(ModuleFilenameHelpers.REGEXP_ALL_LOADERS_RESOURCE, "[identifier]")
|
254
267
|
.replace(
|
255
268
|
ModuleFilenameHelpers.REGEXP_LOADERS_RESOURCE,
|
package/lib/ModuleGraph.js
CHANGED
@@ -132,7 +132,7 @@ class ModuleGraph {
|
|
132
132
|
*/
|
133
133
|
this._moduleMap = new Map();
|
134
134
|
/**
|
135
|
-
* @type {WeakMap<any,
|
135
|
+
* @type {WeakMap<any, object>}
|
136
136
|
* @private
|
137
137
|
*/
|
138
138
|
this._metaMap = new WeakMap();
|
@@ -757,20 +757,20 @@ class ModuleGraph {
|
|
757
757
|
|
758
758
|
/**
|
759
759
|
* @param {any} thing any thing
|
760
|
-
* @returns {
|
760
|
+
* @returns {object} metadata
|
761
761
|
*/
|
762
762
|
getMeta(thing) {
|
763
763
|
let meta = this._metaMap.get(thing);
|
764
764
|
if (meta === undefined) {
|
765
765
|
meta = Object.create(null);
|
766
|
-
this._metaMap.set(thing, /** @type {
|
766
|
+
this._metaMap.set(thing, /** @type {object} */ (meta));
|
767
767
|
}
|
768
|
-
return /** @type {
|
768
|
+
return /** @type {object} */ (meta);
|
769
769
|
}
|
770
770
|
|
771
771
|
/**
|
772
772
|
* @param {any} thing any thing
|
773
|
-
* @returns {
|
773
|
+
* @returns {object | undefined} metadata
|
774
774
|
*/
|
775
775
|
getMetaIfExisting(thing) {
|
776
776
|
return this._metaMap.get(thing);
|
package/lib/MultiCompiler.js
CHANGED
@@ -11,6 +11,7 @@ const { SyncHook, MultiHook } = require("tapable");
|
|
11
11
|
const ConcurrentCompilationError = require("./ConcurrentCompilationError");
|
12
12
|
const MultiStats = require("./MultiStats");
|
13
13
|
const MultiWatching = require("./MultiWatching");
|
14
|
+
const WebpackError = require("./WebpackError");
|
14
15
|
const ArrayQueue = require("./util/ArrayQueue");
|
15
16
|
|
16
17
|
/** @template T @typedef {import("tapable").AsyncSeriesHook<T>} AsyncSeriesHook<T> */
|
@@ -39,7 +40,7 @@ const ArrayQueue = require("./util/ArrayQueue");
|
|
39
40
|
*/
|
40
41
|
|
41
42
|
/**
|
42
|
-
* @typedef {
|
43
|
+
* @typedef {object} MultiCompilerOptions
|
43
44
|
* @property {number=} parallelism how many Compilers are allows to run at the same time in parallel
|
44
45
|
*/
|
45
46
|
|
@@ -109,6 +110,40 @@ module.exports = class MultiCompiler {
|
|
109
110
|
}
|
110
111
|
});
|
111
112
|
}
|
113
|
+
this._validateCompilersOptions();
|
114
|
+
}
|
115
|
+
|
116
|
+
_validateCompilersOptions() {
|
117
|
+
if (this.compilers.length < 2) return;
|
118
|
+
/**
|
119
|
+
* @param {Compiler} compiler compiler
|
120
|
+
* @param {WebpackError} warning warning
|
121
|
+
*/
|
122
|
+
const addWarning = (compiler, warning) => {
|
123
|
+
compiler.hooks.thisCompilation.tap("MultiCompiler", compilation => {
|
124
|
+
compilation.warnings.push(warning);
|
125
|
+
});
|
126
|
+
};
|
127
|
+
const cacheNames = new Set();
|
128
|
+
for (const compiler of this.compilers) {
|
129
|
+
if (compiler.options.cache && "name" in compiler.options.cache) {
|
130
|
+
const name = compiler.options.cache.name;
|
131
|
+
if (cacheNames.has(name)) {
|
132
|
+
addWarning(
|
133
|
+
compiler,
|
134
|
+
new WebpackError(
|
135
|
+
`${
|
136
|
+
compiler.name
|
137
|
+
? `Compiler with name "${compiler.name}" doesn't use unique cache name. `
|
138
|
+
: ""
|
139
|
+
}Please set unique "cache.name" option. Name "${name}" already used.`
|
140
|
+
)
|
141
|
+
);
|
142
|
+
} else {
|
143
|
+
cacheNames.add(name);
|
144
|
+
}
|
145
|
+
}
|
146
|
+
}
|
112
147
|
}
|
113
148
|
|
114
149
|
get options() {
|