webpack 5.90.3 → 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 +262 -93
- package/lib/Compiler.js +199 -83
- package/lib/ConditionalInitFragment.js +4 -5
- package/lib/ContextModule.js +2 -0
- package/lib/ContextModuleFactory.js +4 -2
- package/lib/ContextReplacementPlugin.js +3 -2
- package/lib/DefinePlugin.js +4 -2
- package/lib/Dependency.js +4 -2
- package/lib/DependencyTemplate.js +7 -2
- package/lib/DllModule.js +1 -0
- 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 +118 -24
- 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 +30 -2
- package/lib/ModuleFilenameHelpers.js +1 -1
- package/lib/ModuleGraph.js +56 -27
- package/lib/ModuleGraphConnection.js +2 -1
- package/lib/MultiCompiler.js +26 -8
- package/lib/NodeStuffPlugin.js +14 -3
- package/lib/NormalModule.js +3 -1
- package/lib/NormalModuleFactory.js +1 -1
- package/lib/NormalModuleReplacementPlugin.js +5 -1
- package/lib/ProvidePlugin.js +3 -1
- package/lib/RawModule.js +2 -1
- package/lib/ResolverFactory.js +3 -1
- package/lib/RuntimeModule.js +4 -4
- package/lib/RuntimePlugin.js +1 -0
- package/lib/RuntimeTemplate.js +102 -34
- package/lib/SourceMapDevToolPlugin.js +4 -1
- package/lib/Stats.js +10 -3
- 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 +3 -1
- package/lib/async-modules/AwaitDependenciesInitFragment.js +2 -2
- package/lib/buildChunkGraph.js +117 -64
- 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 +3 -1
- package/lib/container/ContainerPlugin.js +14 -10
- package/lib/container/FallbackModule.js +1 -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 +6 -5
- 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/WorkerPlugin.js +2 -1
- package/lib/dependencies/getFunctionExpression.js +3 -1
- package/lib/esm/ModuleChunkLoadingRuntimeModule.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 +138 -54
- 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 +1 -1
- package/lib/sharing/ConsumeSharedPlugin.js +17 -3
- package/lib/sharing/ConsumeSharedRuntimeModule.js +9 -2
- 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/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/WebAssemblyParser.js +7 -4
- package/lib/web/JsonpChunkLoadingRuntimeModule.js +2 -1
- package/lib/webpack.js +7 -3
- 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 +1668 -613
package/lib/buildChunkGraph.js
CHANGED
@@ -58,6 +58,16 @@ const { getEntryRuntime, mergeRuntime } = require("./util/runtime");
|
|
58
58
|
* @property {ChunkGroup} chunkGroup referenced chunk group
|
59
59
|
*/
|
60
60
|
|
61
|
+
/** @typedef {(Module | ConnectionState | ModuleGraphConnection)[]} BlockModulesInTuples */
|
62
|
+
/** @typedef {(Module | ConnectionState | ModuleGraphConnection[])[]} BlockModulesInFlattenTuples */
|
63
|
+
/** @typedef {Map<DependenciesBlock, BlockModulesInFlattenTuples>} BlockModulesMap */
|
64
|
+
/** @typedef {Map<Chunk, bigint>} MaskByChunk */
|
65
|
+
/** @typedef {Set<DependenciesBlock>} BlocksWithNestedBlocks */
|
66
|
+
/** @typedef {Map<AsyncDependenciesBlock, BlockChunkGroupConnection[]>} BlockConnections */
|
67
|
+
/** @typedef {Map<ChunkGroup, ChunkGroupInfo>} ChunkGroupInfoMap */
|
68
|
+
/** @typedef {Set<ChunkGroup>} AllCreatedChunkGroups */
|
69
|
+
/** @typedef {Map<Entrypoint, Module[]>} InputEntrypointsAndModules */
|
70
|
+
|
61
71
|
const ZERO_BIGINT = BigInt(0);
|
62
72
|
const ONE_BIGINT = BigInt(1);
|
63
73
|
|
@@ -88,15 +98,26 @@ const getActiveStateOfConnections = (connections, runtime) => {
|
|
88
98
|
return merged;
|
89
99
|
};
|
90
100
|
|
101
|
+
/**
|
102
|
+
* @param {Module} module module
|
103
|
+
* @param {ModuleGraph} moduleGraph module graph
|
104
|
+
* @param {RuntimeSpec} runtime runtime
|
105
|
+
* @param {BlockModulesMap} blockModulesMap block modules map
|
106
|
+
*/
|
91
107
|
const extractBlockModules = (module, moduleGraph, runtime, blockModulesMap) => {
|
108
|
+
/** @type {DependenciesBlock | undefined} */
|
92
109
|
let blockCache;
|
110
|
+
/** @type {BlockModulesInTuples | undefined} */
|
93
111
|
let modules;
|
94
112
|
|
113
|
+
/** @type {BlockModulesInTuples[]} */
|
95
114
|
const arrays = [];
|
96
115
|
|
116
|
+
/** @type {DependenciesBlock[]} */
|
97
117
|
const queue = [module];
|
98
118
|
while (queue.length > 0) {
|
99
|
-
const block = queue.pop();
|
119
|
+
const block = /** @type {DependenciesBlock} */ (queue.pop());
|
120
|
+
/** @type {Module[]} */
|
100
121
|
const arr = [];
|
101
122
|
arrays.push(arr);
|
102
123
|
blockModulesMap.set(block, arr);
|
@@ -120,17 +141,26 @@ const extractBlockModules = (module, moduleGraph, runtime, blockModulesMap) => {
|
|
120
141
|
|
121
142
|
// deprecated fallback
|
122
143
|
if (index < 0) {
|
123
|
-
index = block.dependencies.indexOf(d);
|
144
|
+
index = /** @type {DependenciesBlock} */ (block).dependencies.indexOf(d);
|
124
145
|
}
|
125
146
|
|
126
147
|
if (blockCache !== block) {
|
127
|
-
modules =
|
148
|
+
modules =
|
149
|
+
/** @type {BlockModulesInTuples} */
|
150
|
+
(
|
151
|
+
blockModulesMap.get(
|
152
|
+
(blockCache = /** @type {DependenciesBlock} */ (block))
|
153
|
+
)
|
154
|
+
);
|
128
155
|
}
|
129
156
|
|
130
157
|
const i = index * 3;
|
131
|
-
|
132
|
-
modules[i
|
133
|
-
|
158
|
+
/** @type {BlockModulesInTuples} */
|
159
|
+
(modules)[i] = m;
|
160
|
+
/** @type {BlockModulesInTuples} */
|
161
|
+
(modules)[i + 1] = connection.getActiveState(runtime);
|
162
|
+
/** @type {BlockModulesInTuples} */
|
163
|
+
(modules)[i + 2] = connection;
|
134
164
|
}
|
135
165
|
|
136
166
|
for (const modules of arrays) {
|
@@ -140,14 +170,15 @@ const extractBlockModules = (module, moduleGraph, runtime, blockModulesMap) => {
|
|
140
170
|
outer: for (let j = 0; j < modules.length; j += 3) {
|
141
171
|
const m = modules[j];
|
142
172
|
if (m === undefined) continue;
|
143
|
-
const state = modules[j + 1];
|
144
|
-
const connection = modules[j + 2];
|
173
|
+
const state = /** @type {ConnectionState} */ (modules[j + 1]);
|
174
|
+
const connection = /** @type {ModuleGraphConnection} */ (modules[j + 2]);
|
145
175
|
if (indexMap === undefined) {
|
146
176
|
let i = 0;
|
147
177
|
for (; i < length; i += 3) {
|
148
178
|
if (modules[i] === m) {
|
149
|
-
const merged = modules[i + 1];
|
150
|
-
|
179
|
+
const merged = /** @type {ConnectionState} */ (modules[i + 1]);
|
180
|
+
/** @type {ModuleGraphConnection[]} */
|
181
|
+
(/** @type {unknown} */ (modules[i + 2])).push(connection);
|
151
182
|
if (merged === true) continue outer;
|
152
183
|
modules[i + 1] = ModuleGraphConnection.addConnectionStates(
|
153
184
|
merged,
|
@@ -160,7 +191,8 @@ const extractBlockModules = (module, moduleGraph, runtime, blockModulesMap) => {
|
|
160
191
|
length++;
|
161
192
|
modules[length] = state;
|
162
193
|
length++;
|
163
|
-
|
194
|
+
/** @type {ModuleGraphConnection[]} */
|
195
|
+
(/** @type {unknown} */ (modules[length])) = [connection];
|
164
196
|
length++;
|
165
197
|
if (length > 30) {
|
166
198
|
// To avoid worse case performance, we will use an index map for
|
@@ -174,8 +206,9 @@ const extractBlockModules = (module, moduleGraph, runtime, blockModulesMap) => {
|
|
174
206
|
} else {
|
175
207
|
const idx = indexMap.get(m);
|
176
208
|
if (idx !== undefined) {
|
177
|
-
const merged = modules[idx];
|
178
|
-
|
209
|
+
const merged = /** @type {ConnectionState} */ (modules[idx]);
|
210
|
+
/** @type {ModuleGraphConnection[]} */
|
211
|
+
(/** @type {unknown} */ (modules[idx + 1])).push(connection);
|
179
212
|
if (merged === true) continue outer;
|
180
213
|
modules[idx] = ModuleGraphConnection.addConnectionStates(
|
181
214
|
merged,
|
@@ -187,7 +220,11 @@ const extractBlockModules = (module, moduleGraph, runtime, blockModulesMap) => {
|
|
187
220
|
modules[length] = state;
|
188
221
|
indexMap.set(m, length);
|
189
222
|
length++;
|
190
|
-
|
223
|
+
/** @type {ModuleGraphConnection[]} */
|
224
|
+
(
|
225
|
+
/** @type {unknown} */
|
226
|
+
(modules[length])
|
227
|
+
) = [connection];
|
191
228
|
length++;
|
192
229
|
}
|
193
230
|
}
|
@@ -200,12 +237,12 @@ const extractBlockModules = (module, moduleGraph, runtime, blockModulesMap) => {
|
|
200
237
|
*
|
201
238
|
* @param {Logger} logger a logger
|
202
239
|
* @param {Compilation} compilation the compilation
|
203
|
-
* @param {
|
204
|
-
* @param {
|
205
|
-
* @param {
|
206
|
-
* @param {
|
207
|
-
* @param {
|
208
|
-
* @param {
|
240
|
+
* @param {InputEntrypointsAndModules} inputEntrypointsAndModules chunk groups which are processed with the modules
|
241
|
+
* @param {ChunkGroupInfoMap} chunkGroupInfoMap mapping from chunk group to available modules
|
242
|
+
* @param {BlockConnections} blockConnections connection for blocks
|
243
|
+
* @param {BlocksWithNestedBlocks} blocksWithNestedBlocks flag for blocks that have nested blocks
|
244
|
+
* @param {AllCreatedChunkGroups} allCreatedChunkGroups filled with all chunk groups that are created here
|
245
|
+
* @param {MaskByChunk} maskByChunk module content mask by chunk
|
209
246
|
*/
|
210
247
|
const visitModules = (
|
211
248
|
logger,
|
@@ -221,9 +258,7 @@ const visitModules = (
|
|
221
258
|
|
222
259
|
const blockModulesRuntimeMap = new Map();
|
223
260
|
|
224
|
-
/** @type {
|
225
|
-
let blockModulesMapRuntime = false;
|
226
|
-
/** @type {Map<DependenciesBlock, (Module | ConnectionState)[]>} */
|
261
|
+
/** @type {BlockModulesMap | undefined} */
|
227
262
|
let blockModulesMap;
|
228
263
|
|
229
264
|
/** @type {Map<Module, number>} */
|
@@ -254,15 +289,13 @@ const visitModules = (
|
|
254
289
|
*
|
255
290
|
* @param {DependenciesBlock} block block
|
256
291
|
* @param {RuntimeSpec} runtime runtime
|
257
|
-
* @returns {
|
292
|
+
* @returns {BlockModulesInFlattenTuples} block modules in flatten tuples
|
258
293
|
*/
|
259
294
|
const getBlockModules = (block, runtime) => {
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
blockModulesRuntimeMap.set(runtime, blockModulesMap);
|
265
|
-
}
|
295
|
+
blockModulesMap = blockModulesRuntimeMap.get(runtime);
|
296
|
+
if (blockModulesMap === undefined) {
|
297
|
+
blockModulesMap = new Map();
|
298
|
+
blockModulesRuntimeMap.set(runtime, blockModulesMap);
|
266
299
|
}
|
267
300
|
let blockModules = blockModulesMap.get(block);
|
268
301
|
if (blockModules !== undefined) return blockModules;
|
@@ -286,9 +319,11 @@ const visitModules = (
|
|
286
319
|
} else {
|
287
320
|
logger.time("visitModules: prepare");
|
288
321
|
extractBlockModules(module, moduleGraph, runtime, blockModulesMap);
|
289
|
-
blockModules =
|
322
|
+
blockModules =
|
323
|
+
/** @type {BlockModulesInFlattenTuples} */
|
324
|
+
(blockModulesMap.get(block));
|
290
325
|
logger.timeAggregate("visitModules: prepare");
|
291
|
-
return
|
326
|
+
return blockModules;
|
292
327
|
}
|
293
328
|
};
|
294
329
|
|
@@ -451,6 +486,7 @@ const visitModules = (
|
|
451
486
|
const iteratorBlock = b => {
|
452
487
|
// 1. We create a chunk group with single chunk in it for this Block
|
453
488
|
// but only once (blockChunkGroups map)
|
489
|
+
/** @type {ChunkGroupInfo | undefined} */
|
454
490
|
let cgi = blockChunkGroups.get(b);
|
455
491
|
/** @type {ChunkGroup | undefined} */
|
456
492
|
let c;
|
@@ -465,8 +501,8 @@ const visitModules = (
|
|
465
501
|
entrypoint = compilation.addAsyncEntrypoint(
|
466
502
|
entryOptions,
|
467
503
|
module,
|
468
|
-
b.loc,
|
469
|
-
b.request
|
504
|
+
/** @type {DependencyLocation} */ (b.loc),
|
505
|
+
/** @type {string} */ (b.request)
|
470
506
|
);
|
471
507
|
maskByChunk.set(entrypoint.chunks[0], ZERO_BIGINT);
|
472
508
|
entrypoint.index = nextChunkGroupIndex++;
|
@@ -500,7 +536,11 @@ const visitModules = (
|
|
500
536
|
} else {
|
501
537
|
entrypoint = /** @type {Entrypoint} */ (cgi.chunkGroup);
|
502
538
|
// TODO merge entryOptions
|
503
|
-
entrypoint.addOrigin(
|
539
|
+
entrypoint.addOrigin(
|
540
|
+
module,
|
541
|
+
/** @type {DependencyLocation} */ (b.loc),
|
542
|
+
/** @type {string} */ (b.request)
|
543
|
+
);
|
504
544
|
chunkGraph.connectBlockAndChunkGroup(b, entrypoint);
|
505
545
|
}
|
506
546
|
|
@@ -524,13 +564,13 @@ const visitModules = (
|
|
524
564
|
chunkGroupInfo
|
525
565
|
});
|
526
566
|
} else {
|
527
|
-
cgi = chunkName
|
567
|
+
cgi = chunkName ? namedChunkGroups.get(chunkName) : undefined;
|
528
568
|
if (!cgi) {
|
529
569
|
c = compilation.addChunkInGroup(
|
530
570
|
b.groupOptions || b.chunkName,
|
531
571
|
module,
|
532
|
-
b.loc,
|
533
|
-
b.request
|
572
|
+
/** @type {DependencyLocation} */ (b.loc),
|
573
|
+
/** @type {string} */ (b.request)
|
534
574
|
);
|
535
575
|
maskByChunk.set(c.chunks[0], ZERO_BIGINT);
|
536
576
|
c.index = nextChunkGroupIndex++;
|
@@ -561,19 +601,23 @@ const visitModules = (
|
|
561
601
|
new AsyncDependencyToInitialChunkError(
|
562
602
|
/** @type {string} */ (chunkName),
|
563
603
|
module,
|
564
|
-
b.loc
|
604
|
+
/** @type {DependencyLocation} */ (b.loc)
|
565
605
|
)
|
566
606
|
);
|
567
607
|
c = chunkGroup;
|
568
608
|
} else {
|
569
609
|
c.addOptions(b.groupOptions);
|
570
610
|
}
|
571
|
-
c.addOrigin(
|
611
|
+
c.addOrigin(
|
612
|
+
module,
|
613
|
+
/** @type {DependencyLocation} */ (b.loc),
|
614
|
+
/** @type {string} */ (b.request)
|
615
|
+
);
|
572
616
|
}
|
573
617
|
blockConnections.set(b, []);
|
574
618
|
}
|
575
619
|
blockChunkGroups.set(b, /** @type {ChunkGroupInfo} */ (cgi));
|
576
|
-
blockByChunkGroups.set(cgi, b);
|
620
|
+
blockByChunkGroups.set(/** @type {ChunkGroupInfo} */ (cgi), b);
|
577
621
|
} else if (entryOptions) {
|
578
622
|
entrypoint = /** @type {Entrypoint} */ (cgi.chunkGroup);
|
579
623
|
} else {
|
@@ -583,7 +627,8 @@ const visitModules = (
|
|
583
627
|
if (c !== undefined) {
|
584
628
|
// 2. We store the connection for the block
|
585
629
|
// to connect it later if needed
|
586
|
-
|
630
|
+
/** @type {BlockChunkGroupConnection[]} */
|
631
|
+
(blockConnections.get(b)).push({
|
587
632
|
originChunkGroupInfo: chunkGroupInfo,
|
588
633
|
chunkGroup: c
|
589
634
|
});
|
@@ -622,7 +667,9 @@ const visitModules = (
|
|
622
667
|
const blockModules = getBlockModules(block, chunkGroupInfo.runtime);
|
623
668
|
|
624
669
|
if (blockModules !== undefined) {
|
625
|
-
const
|
670
|
+
const minAvailableModules =
|
671
|
+
/** @type {bigint} */
|
672
|
+
(chunkGroupInfo.minAvailableModules);
|
626
673
|
// Buffer items because order need to be reversed to get indices correct
|
627
674
|
// Traverse all referenced modules
|
628
675
|
for (let i = 0, len = blockModules.length; i < len; i += 3) {
|
@@ -770,7 +817,7 @@ const visitModules = (
|
|
770
817
|
// We connect Module and Chunk
|
771
818
|
chunkGraph.connectChunkAndModule(chunk, module);
|
772
819
|
const moduleOrdinal = getModuleOrdinal(module);
|
773
|
-
let chunkMask = maskByChunk.get(chunk);
|
820
|
+
let chunkMask = /** @type {bigint} */ (maskByChunk.get(chunk));
|
774
821
|
chunkMask |= ONE_BIGINT << BigInt(moduleOrdinal);
|
775
822
|
maskByChunk.set(chunk, chunkMask);
|
776
823
|
}
|
@@ -837,11 +884,13 @@ const visitModules = (
|
|
837
884
|
if (chunkGroupInfo.resultingAvailableModules !== undefined)
|
838
885
|
return chunkGroupInfo.resultingAvailableModules;
|
839
886
|
|
840
|
-
let resultingAvailableModules =
|
887
|
+
let resultingAvailableModules = /** @type {bigint} */ (
|
888
|
+
chunkGroupInfo.minAvailableModules
|
889
|
+
);
|
841
890
|
|
842
891
|
// add the modules from the chunk group to the set
|
843
892
|
for (const chunk of chunkGroupInfo.chunkGroup.chunks) {
|
844
|
-
const mask = maskByChunk.get(chunk);
|
893
|
+
const mask = /** @type {bigint} */ (maskByChunk.get(chunk));
|
845
894
|
resultingAvailableModules |= mask;
|
846
895
|
}
|
847
896
|
|
@@ -986,7 +1035,8 @@ const visitModules = (
|
|
986
1035
|
const ordinal = getModuleOrdinal(module);
|
987
1036
|
info.skippedModuleConnections.delete(entry);
|
988
1037
|
if (isOrdinalSetInMask(minAvailableModules, ordinal)) {
|
989
|
-
|
1038
|
+
/** @type {NonNullable<ChunkGroupInfo["skippedItems"]>} */
|
1039
|
+
(info.skippedItems).add(module);
|
990
1040
|
continue;
|
991
1041
|
}
|
992
1042
|
}
|
@@ -1079,13 +1129,11 @@ const visitModules = (
|
|
1079
1129
|
let preOrderIndex = 0;
|
1080
1130
|
let postOrderIndex = 0;
|
1081
1131
|
|
1132
|
+
/**
|
1133
|
+
* @param {DependenciesBlock} current current
|
1134
|
+
* @param {BlocksWithNestedBlocks} visited visited dependencies blocks
|
1135
|
+
*/
|
1082
1136
|
const process = (current, visited) => {
|
1083
|
-
if (visited.has(current)) {
|
1084
|
-
return;
|
1085
|
-
}
|
1086
|
-
|
1087
|
-
visited.add(current);
|
1088
|
-
|
1089
1137
|
const blockModules = getBlockModules(current, runtime);
|
1090
1138
|
if (blockModules === undefined) {
|
1091
1139
|
return;
|
@@ -1099,6 +1147,11 @@ const visitModules = (
|
|
1099
1147
|
continue;
|
1100
1148
|
}
|
1101
1149
|
const refModule = /** @type {Module} */ (blockModules[i]);
|
1150
|
+
if (visited.has(refModule)) {
|
1151
|
+
continue;
|
1152
|
+
}
|
1153
|
+
|
1154
|
+
visited.add(refModule);
|
1102
1155
|
|
1103
1156
|
if (refModule) {
|
1104
1157
|
chunkGroup.setModulePreOrderIndex(refModule, preOrderIndex++);
|
@@ -1128,9 +1181,9 @@ const visitModules = (
|
|
1128
1181
|
/**
|
1129
1182
|
*
|
1130
1183
|
* @param {Compilation} compilation the compilation
|
1131
|
-
* @param {
|
1132
|
-
* @param {
|
1133
|
-
* @param {
|
1184
|
+
* @param {BlocksWithNestedBlocks} blocksWithNestedBlocks flag for blocks that have nested blocks
|
1185
|
+
* @param {BlockConnections} blockConnections connection for blocks
|
1186
|
+
* @param {MaskByChunk} maskByChunk mapping from chunk to module mask
|
1134
1187
|
*/
|
1135
1188
|
const connectChunkGroups = (
|
1136
1189
|
compilation,
|
@@ -1149,7 +1202,7 @@ const connectChunkGroups = (
|
|
1149
1202
|
*/
|
1150
1203
|
const areModulesAvailable = (chunkGroup, availableModules) => {
|
1151
1204
|
for (const chunk of chunkGroup.chunks) {
|
1152
|
-
const chunkMask = maskByChunk.get(chunk);
|
1205
|
+
const chunkMask = /** @type {bigint} */ (maskByChunk.get(chunk));
|
1153
1206
|
if ((chunkMask & availableModules) !== chunkMask) return false;
|
1154
1207
|
}
|
1155
1208
|
return true;
|
@@ -1169,7 +1222,7 @@ const connectChunkGroups = (
|
|
1169
1222
|
connections.every(({ chunkGroup, originChunkGroupInfo }) =>
|
1170
1223
|
areModulesAvailable(
|
1171
1224
|
chunkGroup,
|
1172
|
-
originChunkGroupInfo.resultingAvailableModules
|
1225
|
+
/** @type {bigint} */ (originChunkGroupInfo.resultingAvailableModules)
|
1173
1226
|
)
|
1174
1227
|
)
|
1175
1228
|
) {
|
@@ -1215,7 +1268,7 @@ const cleanupUnconnectedGroups = (compilation, allCreatedChunkGroups) => {
|
|
1215
1268
|
/**
|
1216
1269
|
* This method creates the Chunk graph from the Module graph
|
1217
1270
|
* @param {Compilation} compilation the compilation
|
1218
|
-
* @param {
|
1271
|
+
* @param {InputEntrypointsAndModules} inputEntrypointsAndModules chunk groups which are processed with the modules
|
1219
1272
|
* @returns {void}
|
1220
1273
|
*/
|
1221
1274
|
const buildChunkGraph = (compilation, inputEntrypointsAndModules) => {
|
@@ -1223,19 +1276,19 @@ const buildChunkGraph = (compilation, inputEntrypointsAndModules) => {
|
|
1223
1276
|
|
1224
1277
|
// SHARED STATE
|
1225
1278
|
|
1226
|
-
/** @type {
|
1279
|
+
/** @type {BlockConnections} */
|
1227
1280
|
const blockConnections = new Map();
|
1228
1281
|
|
1229
|
-
/** @type {
|
1282
|
+
/** @type {AllCreatedChunkGroups} */
|
1230
1283
|
const allCreatedChunkGroups = new Set();
|
1231
1284
|
|
1232
|
-
/** @type {
|
1285
|
+
/** @type {ChunkGroupInfoMap} */
|
1233
1286
|
const chunkGroupInfoMap = new Map();
|
1234
1287
|
|
1235
|
-
/** @type {
|
1288
|
+
/** @type {BlocksWithNestedBlocks} */
|
1236
1289
|
const blocksWithNestedBlocks = new Set();
|
1237
1290
|
|
1238
|
-
/** @type {
|
1291
|
+
/** @type {MaskByChunk} */
|
1239
1292
|
const maskByChunk = new Map();
|
1240
1293
|
|
1241
1294
|
// PART ONE
|
@@ -9,12 +9,13 @@ const Cache = require("../Cache");
|
|
9
9
|
const ProgressPlugin = require("../ProgressPlugin");
|
10
10
|
|
11
11
|
/** @typedef {import("../Compiler")} Compiler */
|
12
|
+
/** @typedef {import("./PackFileCacheStrategy")} PackFileCacheStrategy */
|
12
13
|
|
13
14
|
const BUILD_DEPENDENCIES_KEY = Symbol();
|
14
15
|
|
15
16
|
class IdleFileCachePlugin {
|
16
17
|
/**
|
17
|
-
* @param {
|
18
|
+
* @param {PackFileCacheStrategy} strategy cache strategy
|
18
19
|
* @param {number} idleTimeout timeout
|
19
20
|
* @param {number} idleTimeoutForInitialStore initial timeout
|
20
21
|
* @param {number} idleTimeoutAfterLargeChanges timeout after changes
|
@@ -93,7 +94,9 @@ class IdleFileCachePlugin {
|
|
93
94
|
{ name: "IdleFileCachePlugin", stage: Cache.STAGE_DISK },
|
94
95
|
dependencies => {
|
95
96
|
pendingIdleTasks.set(BUILD_DEPENDENCIES_KEY, () =>
|
96
|
-
|
97
|
+
Promise.resolve().then(() =>
|
98
|
+
strategy.storeBuildDependencies(dependencies)
|
99
|
+
)
|
97
100
|
);
|
98
101
|
}
|
99
102
|
);
|
@@ -227,7 +230,9 @@ class IdleFileCachePlugin {
|
|
227
230
|
compiler.hooks.done.tap("IdleFileCachePlugin", stats => {
|
228
231
|
// 10% build overhead is ignored, as it's not cacheable
|
229
232
|
timeSpendInBuild *= 0.9;
|
230
|
-
timeSpendInBuild +=
|
233
|
+
timeSpendInBuild +=
|
234
|
+
/** @type {number} */ (stats.endTime) -
|
235
|
+
/** @type {number} */ (stats.startTime);
|
231
236
|
});
|
232
237
|
}
|
233
238
|
}
|
@@ -19,7 +19,7 @@ class MemoryCachePlugin {
|
|
19
19
|
* @returns {void}
|
20
20
|
*/
|
21
21
|
apply(compiler) {
|
22
|
-
/** @type {Map<string, { etag: Etag | null, data: any }>} */
|
22
|
+
/** @type {Map<string, { etag: Etag | null, data: any } | null>} */
|
23
23
|
const cache = new Map();
|
24
24
|
compiler.cache.hooks.store.tap(
|
25
25
|
{ name: "MemoryCachePlugin", stage: Cache.STAGE_MEMORY },
|
@@ -13,6 +13,10 @@ const Cache = require("../Cache");
|
|
13
13
|
/** @typedef {import("../Module")} Module */
|
14
14
|
|
15
15
|
class MemoryWithGcCachePlugin {
|
16
|
+
/**
|
17
|
+
* @param {Object} options Options
|
18
|
+
* @param {number} options.maxGenerations max generations
|
19
|
+
*/
|
16
20
|
constructor({ maxGenerations }) {
|
17
21
|
this._maxGenerations = maxGenerations;
|
18
22
|
}
|
@@ -23,9 +27,9 @@ class MemoryWithGcCachePlugin {
|
|
23
27
|
*/
|
24
28
|
apply(compiler) {
|
25
29
|
const maxGenerations = this._maxGenerations;
|
26
|
-
/** @type {Map<string, { etag: Etag | null, data: any }>} */
|
30
|
+
/** @type {Map<string, { etag: Etag | null, data: any } | undefined | null>} */
|
27
31
|
const cache = new Map();
|
28
|
-
/** @type {Map<string, { entry: { etag: Etag | null, data: any }, until: number }>} */
|
32
|
+
/** @type {Map<string, { entry: { etag: Etag | null, data: any } | null, until: number }>} */
|
29
33
|
const oldCache = new Map();
|
30
34
|
let generation = 0;
|
31
35
|
let cachePosition = 0;
|
@@ -28,13 +28,16 @@ const {
|
|
28
28
|
/** @typedef {import("../util/fs").IntermediateFileSystem} IntermediateFileSystem */
|
29
29
|
|
30
30
|
/** @typedef {Map<string, string | false>} ResolveResults */
|
31
|
+
/** @typedef {Set<string>} Items */
|
32
|
+
/** @typedef {Set<string>} BuildDependencies */
|
33
|
+
/** @typedef {Map<string, PackItemInfo>} ItemInfo */
|
31
34
|
|
32
35
|
class PackContainer {
|
33
36
|
/**
|
34
37
|
* @param {Object} data stored data
|
35
38
|
* @param {string} version version identifier
|
36
39
|
* @param {Snapshot} buildSnapshot snapshot of all build dependencies
|
37
|
-
* @param {
|
40
|
+
* @param {BuildDependencies} buildDependencies list of all unresolved build dependencies captured
|
38
41
|
* @param {ResolveResults} resolveResults result of the resolved build dependencies
|
39
42
|
* @param {Snapshot} resolveBuildDependenciesSnapshot snapshot of the dependencies of the build dependencies resolving
|
40
43
|
*/
|
@@ -54,13 +57,17 @@ class PackContainer {
|
|
54
57
|
this.resolveBuildDependenciesSnapshot = resolveBuildDependenciesSnapshot;
|
55
58
|
}
|
56
59
|
|
60
|
+
/**
|
61
|
+
* @param {ObjectSerializerContext} context context
|
62
|
+
*/
|
57
63
|
serialize({ write, writeLazy }) {
|
58
64
|
write(this.version);
|
59
65
|
write(this.buildSnapshot);
|
60
66
|
write(this.buildDependencies);
|
61
67
|
write(this.resolveResults);
|
62
68
|
write(this.resolveBuildDependenciesSnapshot);
|
63
|
-
writeLazy
|
69
|
+
/** @type {NonNullable<ObjectSerializerContext["writeLazy"]>} */
|
70
|
+
(writeLazy)(this.data);
|
64
71
|
}
|
65
72
|
|
66
73
|
/**
|
@@ -104,13 +111,17 @@ class PackItemInfo {
|
|
104
111
|
}
|
105
112
|
|
106
113
|
class Pack {
|
114
|
+
/**
|
115
|
+
* @param {Logger} logger a logger
|
116
|
+
* @param {number} maxAge max age of cache items
|
117
|
+
*/
|
107
118
|
constructor(logger, maxAge) {
|
108
|
-
/** @type {
|
119
|
+
/** @type {ItemInfo} */
|
109
120
|
this.itemInfo = new Map();
|
110
121
|
/** @type {(string | undefined)[]} */
|
111
122
|
this.requests = [];
|
112
123
|
this.requestsTimeout = undefined;
|
113
|
-
/** @type {
|
124
|
+
/** @type {ItemInfo} */
|
114
125
|
this.freshContent = new Map();
|
115
126
|
/** @type {(undefined | PackContent)[]} */
|
116
127
|
this.content = [];
|
@@ -224,12 +235,18 @@ class Pack {
|
|
224
235
|
return i;
|
225
236
|
}
|
226
237
|
|
238
|
+
/**
|
239
|
+
* @private
|
240
|
+
* @param {Items} items items
|
241
|
+
* @param {Items} usedItems used items
|
242
|
+
* @param {number} newLoc new location
|
243
|
+
*/
|
227
244
|
_gcAndUpdateLocation(items, usedItems, newLoc) {
|
228
245
|
let count = 0;
|
229
246
|
let lastGC;
|
230
247
|
const now = Date.now();
|
231
248
|
for (const identifier of items) {
|
232
|
-
const info = this.itemInfo.get(identifier);
|
249
|
+
const info = /** @type {PackItemInfo} */ (this.itemInfo.get(identifier));
|
233
250
|
if (now - info.lastAccess > this.maxAge) {
|
234
251
|
this.itemInfo.delete(identifier);
|
235
252
|
items.delete(identifier);
|
@@ -263,7 +280,7 @@ class Pack {
|
|
263
280
|
const loc = this._findLocation();
|
264
281
|
this.content[loc] = null; // reserve
|
265
282
|
const pack = {
|
266
|
-
/** @type {
|
283
|
+
/** @type {Items} */
|
267
284
|
items: new Set(),
|
268
285
|
/** @type {Map<string, any>} */
|
269
286
|
map: new Map(),
|
@@ -372,9 +389,9 @@ class Pack {
|
|
372
389
|
}
|
373
390
|
|
374
391
|
// 4. Determine merged items
|
375
|
-
/** @type {
|
392
|
+
/** @type {Items} */
|
376
393
|
const mergedItems = new Set();
|
377
|
-
/** @type {
|
394
|
+
/** @type {Items} */
|
378
395
|
const mergedUsedItems = new Set();
|
379
396
|
/** @type {(function(Map<string, any>): Promise<void>)[]} */
|
380
397
|
const addToMergedMap = [];
|
@@ -544,6 +561,9 @@ class Pack {
|
|
544
561
|
}
|
545
562
|
}
|
546
563
|
|
564
|
+
/**
|
565
|
+
* @param {ObjectSerializerContext} context context
|
566
|
+
*/
|
547
567
|
serialize({ write, writeSeparate }) {
|
548
568
|
this._persistFreshContent();
|
549
569
|
this._optimizeSmallContent();
|
@@ -571,6 +591,9 @@ class Pack {
|
|
571
591
|
write(null); // null as marker of the end of items
|
572
592
|
}
|
573
593
|
|
594
|
+
/**
|
595
|
+
* @param {ObjectDeserializerContext & { logger: Logger }} context context
|
596
|
+
*/
|
574
597
|
deserialize({ read, logger }) {
|
575
598
|
this.logger = logger;
|
576
599
|
{
|
@@ -629,6 +652,9 @@ class PackContentItems {
|
|
629
652
|
this.map = map;
|
630
653
|
}
|
631
654
|
|
655
|
+
/**
|
656
|
+
* @param {ObjectSerializerContext & { snapshot: TODO, rollback: TODO, logger: Logger, profile: boolean | undefined }} context context
|
657
|
+
*/
|
632
658
|
serialize({ write, snapshot, rollback, logger, profile }) {
|
633
659
|
if (profile) {
|
634
660
|
write(false);
|
@@ -695,6 +721,9 @@ class PackContentItems {
|
|
695
721
|
}
|
696
722
|
}
|
697
723
|
|
724
|
+
/**
|
725
|
+
* @param {ObjectDeserializerContext & { logger: Logger, profile: boolean | undefined }} context context
|
726
|
+
*/
|
698
727
|
deserialize({ read, logger, profile }) {
|
699
728
|
if (read()) {
|
700
729
|
this.map = read();
|
@@ -760,17 +789,17 @@ class PackContent {
|
|
760
789
|
*/
|
761
790
|
|
762
791
|
/**
|
763
|
-
* @param {
|
764
|
-
* @param {
|
792
|
+
* @param {Items} items keys
|
793
|
+
* @param {Items} usedItems used keys
|
765
794
|
* @param {PackContentItems | function(): Promise<PackContentItems>} dataOrFn sync or async content
|
766
795
|
* @param {Logger=} logger logger for logging
|
767
796
|
* @param {string=} lazyName name of dataOrFn for logging
|
768
797
|
*/
|
769
798
|
constructor(items, usedItems, dataOrFn, logger, lazyName) {
|
770
799
|
this.items = items;
|
771
|
-
/** @type {function(): Promise<PackContentItems> | PackContentItems} */
|
800
|
+
/** @type {(function(): Promise<PackContentItems> | PackContentItems) | undefined} */
|
772
801
|
this.lazy = typeof dataOrFn === "function" ? dataOrFn : undefined;
|
773
|
-
/** @type {Map<string, any>} */
|
802
|
+
/** @type {Map<string, any> | undefined} */
|
774
803
|
this.content = typeof dataOrFn === "function" ? undefined : dataOrFn.map;
|
775
804
|
this.outdated = false;
|
776
805
|
this.used = usedItems;
|
@@ -778,6 +807,10 @@ class PackContent {
|
|
778
807
|
this.lazyName = lazyName;
|
779
808
|
}
|
780
809
|
|
810
|
+
/**
|
811
|
+
* @param {string} identifier identifier
|
812
|
+
* @returns {string | Promise<string>} result
|
813
|
+
*/
|
781
814
|
get(identifier) {
|
782
815
|
this.used.add(identifier);
|
783
816
|
if (this.content) {
|
@@ -1049,7 +1082,7 @@ class PackFileCacheStrategy {
|
|
1049
1082
|
? ".pack.gz"
|
1050
1083
|
: ".pack";
|
1051
1084
|
this.snapshot = snapshot;
|
1052
|
-
/** @type {
|
1085
|
+
/** @type {BuildDependencies} */
|
1053
1086
|
this.buildDependencies = new Set();
|
1054
1087
|
/** @type {LazySet<string>} */
|
1055
1088
|
this.newBuildDependencies = new LazySet();
|
@@ -1081,9 +1114,9 @@ class PackFileCacheStrategy {
|
|
1081
1114
|
const { logger, profile, cacheLocation, version } = this;
|
1082
1115
|
/** @type {Snapshot} */
|
1083
1116
|
let buildSnapshot;
|
1084
|
-
/** @type {
|
1117
|
+
/** @type {BuildDependencies} */
|
1085
1118
|
let buildDependencies;
|
1086
|
-
/** @type {
|
1119
|
+
/** @type {BuildDependencies} */
|
1087
1120
|
let newBuildDependencies;
|
1088
1121
|
/** @type {Snapshot} */
|
1089
1122
|
let resolveBuildDependenciesSnapshot;
|
@@ -1272,7 +1305,7 @@ class PackFileCacheStrategy {
|
|
1272
1305
|
}
|
1273
1306
|
|
1274
1307
|
/**
|
1275
|
-
* @param {LazySet<string>} dependencies dependencies to store
|
1308
|
+
* @param {LazySet<string> | Iterable<string>} dependencies dependencies to store
|
1276
1309
|
*/
|
1277
1310
|
storeBuildDependencies(dependencies) {
|
1278
1311
|
if (this.readonly) return;
|