webpack 5.56.1 → 5.57.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/lib/AsyncDependenciesBlock.js +3 -2
- package/lib/Chunk.js +4 -6
- package/lib/ChunkGraph.js +1 -2
- package/lib/Compilation.js +157 -52
- package/lib/Compiler.js +1 -1
- package/lib/DependencyTemplates.js +1 -2
- package/lib/DllModule.js +1 -2
- package/lib/ExportsInfo.js +5 -4
- package/lib/ExternalModule.js +8 -3
- package/lib/FlagDependencyUsagePlugin.js +6 -1
- package/lib/ModuleGraph.js +49 -8
- package/lib/WebpackOptionsApply.js +2 -2
- package/lib/javascript/ArrayPushCallbackChunkFormatPlugin.js +3 -5
- package/lib/optimize/MangleExportsPlugin.js +5 -0
- package/lib/util/StringXor.js +28 -22
- package/package.json +1 -1
- package/types.d.ts +13 -5
@@ -66,9 +66,10 @@ class AsyncDependenciesBlock extends DependenciesBlock {
|
|
66
66
|
if (this._stringifiedGroupOptions === undefined) {
|
67
67
|
this._stringifiedGroupOptions = JSON.stringify(this.groupOptions);
|
68
68
|
}
|
69
|
-
hash.update(this._stringifiedGroupOptions);
|
70
69
|
const chunkGroup = chunkGraph.getBlockChunkGroup(this);
|
71
|
-
hash.update(
|
70
|
+
hash.update(
|
71
|
+
`${this._stringifiedGroupOptions}${chunkGroup ? chunkGroup.id : ""}`
|
72
|
+
);
|
72
73
|
super.updateHash(hash, context);
|
73
74
|
}
|
74
75
|
|
package/lib/Chunk.js
CHANGED
@@ -539,9 +539,9 @@ class Chunk {
|
|
539
539
|
* @returns {void}
|
540
540
|
*/
|
541
541
|
updateHash(hash, chunkGraph) {
|
542
|
-
hash.update(
|
543
|
-
|
544
|
-
|
542
|
+
hash.update(
|
543
|
+
`${this.id} ${this.ids ? this.ids.join() : ""} ${this.name || ""} `
|
544
|
+
);
|
545
545
|
const xor = new StringXor();
|
546
546
|
for (const m of chunkGraph.getChunkModulesIterable(this)) {
|
547
547
|
xor.add(chunkGraph.getModuleHash(m, this.runtime));
|
@@ -550,9 +550,7 @@ class Chunk {
|
|
550
550
|
const entryModules =
|
551
551
|
chunkGraph.getChunkEntryModulesWithChunkGroupIterable(this);
|
552
552
|
for (const [m, chunkGroup] of entryModules) {
|
553
|
-
hash.update(
|
554
|
-
hash.update(`${chunkGraph.getModuleId(m)}`);
|
555
|
-
hash.update(chunkGroup.id);
|
553
|
+
hash.update(`entry${chunkGraph.getModuleId(m)}${chunkGroup.id}`);
|
556
554
|
}
|
557
555
|
}
|
558
556
|
|
package/lib/ChunkGraph.js
CHANGED
@@ -1499,8 +1499,7 @@ Caller might not support runtime-dependent code generation (opt-out via optimiza
|
|
1499
1499
|
}
|
1500
1500
|
const graphHash = cgm.graphHashes.provide(runtime, () => {
|
1501
1501
|
const hash = createHash(this._hashFunction);
|
1502
|
-
hash.update(`${cgm.id}`);
|
1503
|
-
hash.update(`${this.moduleGraph.isAsync(module)}`);
|
1502
|
+
hash.update(`${cgm.id}${this.moduleGraph.isAsync(module)}`);
|
1504
1503
|
this.moduleGraph.getExportsInfo(module).updateHash(hash, runtime);
|
1505
1504
|
return BigInt(`0x${/** @type {string} */ (hash.digest("hex"))}`);
|
1506
1505
|
});
|
package/lib/Compilation.js
CHANGED
@@ -917,8 +917,10 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
|
|
917
917
|
};
|
918
918
|
defineRemovedModuleTemplates(this.moduleTemplates);
|
919
919
|
|
920
|
-
/** @type {
|
920
|
+
/** @type {Map<Module, WeakTupleMap<any, any>> | undefined} */
|
921
921
|
this.moduleMemCaches = undefined;
|
922
|
+
/** @type {Map<Module, WeakTupleMap<any, any>> | undefined} */
|
923
|
+
this.moduleMemCaches2 = undefined;
|
922
924
|
this.moduleGraph = new ModuleGraph();
|
923
925
|
/** @type {ChunkGraph} */
|
924
926
|
this.chunkGraph = undefined;
|
@@ -2169,7 +2171,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
|
|
2169
2171
|
const moduleMemCacheCache = this.compiler.moduleMemCaches;
|
2170
2172
|
if (!moduleMemCacheCache) return;
|
2171
2173
|
if (!this.moduleMemCaches) {
|
2172
|
-
this.moduleMemCaches = new
|
2174
|
+
this.moduleMemCaches = new Map();
|
2173
2175
|
this.moduleGraph.setModuleMemCaches(this.moduleMemCaches);
|
2174
2176
|
}
|
2175
2177
|
const { moduleGraph, moduleMemCaches } = this;
|
@@ -2179,7 +2181,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
|
|
2179
2181
|
let statChanged = 0;
|
2180
2182
|
let statUnchanged = 0;
|
2181
2183
|
let statReferencesChanged = 0;
|
2182
|
-
let
|
2184
|
+
let statWithoutBuild = 0;
|
2183
2185
|
|
2184
2186
|
const computeReferences = module => {
|
2185
2187
|
/** @type {WeakMap<Dependency, Module>} */
|
@@ -2211,48 +2213,63 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
|
|
2211
2213
|
return true;
|
2212
2214
|
};
|
2213
2215
|
|
2214
|
-
|
2215
|
-
|
2216
|
-
if (
|
2217
|
-
const
|
2218
|
-
if (
|
2219
|
-
|
2220
|
-
|
2221
|
-
|
2222
|
-
|
2223
|
-
|
2224
|
-
|
2225
|
-
|
2226
|
-
|
2227
|
-
|
2228
|
-
|
2229
|
-
|
2230
|
-
|
2231
|
-
|
2232
|
-
|
2233
|
-
|
2234
|
-
|
2235
|
-
|
2236
|
-
|
2237
|
-
|
2238
|
-
|
2239
|
-
|
2240
|
-
|
2241
|
-
moduleMemCaches.set(module, memCache);
|
2242
|
-
affectedModules.add(module);
|
2243
|
-
cachedMemCache.references = computeReferences(module);
|
2244
|
-
cachedMemCache.memCache = memCache;
|
2245
|
-
statReferencesChanged++;
|
2216
|
+
const modulesWithoutCache = new Set(modules);
|
2217
|
+
for (const [module, cachedMemCache] of moduleMemCacheCache) {
|
2218
|
+
if (modulesWithoutCache.has(module)) {
|
2219
|
+
const buildInfo = module.buildInfo;
|
2220
|
+
if (buildInfo) {
|
2221
|
+
if (cachedMemCache.buildInfo !== buildInfo) {
|
2222
|
+
// use a new one
|
2223
|
+
const memCache = new WeakTupleMap();
|
2224
|
+
moduleMemCaches.set(module, memCache);
|
2225
|
+
affectedModules.add(module);
|
2226
|
+
cachedMemCache.buildInfo = buildInfo;
|
2227
|
+
cachedMemCache.references = computeReferences(module);
|
2228
|
+
cachedMemCache.memCache = memCache;
|
2229
|
+
statChanged++;
|
2230
|
+
} else if (!compareReferences(module, cachedMemCache.references)) {
|
2231
|
+
// use a new one
|
2232
|
+
const memCache = new WeakTupleMap();
|
2233
|
+
moduleMemCaches.set(module, memCache);
|
2234
|
+
affectedModules.add(module);
|
2235
|
+
cachedMemCache.references = computeReferences(module);
|
2236
|
+
cachedMemCache.memCache = memCache;
|
2237
|
+
statReferencesChanged++;
|
2238
|
+
} else {
|
2239
|
+
// keep the old mem cache
|
2240
|
+
moduleMemCaches.set(module, cachedMemCache.memCache);
|
2241
|
+
statUnchanged++;
|
2242
|
+
}
|
2246
2243
|
} else {
|
2247
|
-
|
2248
|
-
|
2249
|
-
|
2244
|
+
infectedModules.add(module);
|
2245
|
+
moduleMemCacheCache.delete(module);
|
2246
|
+
statWithoutBuild++;
|
2250
2247
|
}
|
2248
|
+
modulesWithoutCache.delete(module);
|
2249
|
+
} else {
|
2250
|
+
moduleMemCacheCache.delete(module);
|
2251
|
+
}
|
2252
|
+
}
|
2253
|
+
|
2254
|
+
for (const module of modulesWithoutCache) {
|
2255
|
+
const buildInfo = module.buildInfo && module.buildInfo.buildInfo;
|
2256
|
+
if (buildInfo) {
|
2257
|
+
// create a new entry
|
2258
|
+
const memCache = new WeakTupleMap();
|
2259
|
+
moduleMemCacheCache.set(module, {
|
2260
|
+
buildInfo,
|
2261
|
+
references: computeReferences(module),
|
2262
|
+
memCache
|
2263
|
+
});
|
2264
|
+
moduleMemCaches.set(module, memCache);
|
2265
|
+
affectedModules.add(module);
|
2266
|
+
statNew++;
|
2251
2267
|
} else {
|
2252
2268
|
infectedModules.add(module);
|
2253
|
-
|
2269
|
+
statWithoutBuild++;
|
2254
2270
|
}
|
2255
2271
|
}
|
2272
|
+
|
2256
2273
|
const reduceAffectType = connections => {
|
2257
2274
|
let affected = false;
|
2258
2275
|
for (const { dependency } of connections) {
|
@@ -2313,10 +2330,103 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
|
|
2313
2330
|
infectedModules.size
|
2314
2331
|
} infected of ${
|
2315
2332
|
this.modules.size
|
2316
|
-
}) modules flagged as affected (${statNew} new modules, ${statChanged} changed, ${statReferencesChanged} references changed, ${statUnchanged} unchanged, ${
|
2333
|
+
}) modules flagged as affected (${statNew} new modules, ${statChanged} changed, ${statReferencesChanged} references changed, ${statUnchanged} unchanged, ${statWithoutBuild} were not built)`
|
2317
2334
|
);
|
2318
2335
|
}
|
2319
2336
|
|
2337
|
+
_updateAffectedModulesWithIds() {
|
2338
|
+
const { moduleMemCaches } = this;
|
2339
|
+
if (!moduleMemCaches) return;
|
2340
|
+
const moduleMemCaches2 = (this.moduleMemCaches2 = new Map());
|
2341
|
+
const { moduleGraph, chunkGraph } = this;
|
2342
|
+
const key = "memCache2";
|
2343
|
+
/**
|
2344
|
+
* @param {Module} module module
|
2345
|
+
* @returns {{ modules?: Map<Module, string | number | undefined>, blocks?: (string | number)[] }} references
|
2346
|
+
*/
|
2347
|
+
const computeReferences = module => {
|
2348
|
+
/** @type {Map<Module, string | number | undefined>} */
|
2349
|
+
let modules = undefined;
|
2350
|
+
/** @type {(string | number)[] | undefined} */
|
2351
|
+
let blocks = undefined;
|
2352
|
+
const outgoing = moduleGraph.getOutgoingConnectionsByModule(module);
|
2353
|
+
if (outgoing !== undefined) {
|
2354
|
+
for (const m of outgoing.keys()) {
|
2355
|
+
if (!m) continue;
|
2356
|
+
if (modules === undefined) modules = new Map();
|
2357
|
+
modules.set(m, chunkGraph.getModuleId(module));
|
2358
|
+
}
|
2359
|
+
}
|
2360
|
+
if (module.blocks.length > 0) {
|
2361
|
+
blocks = [];
|
2362
|
+
const queue = Array.from(module.blocks);
|
2363
|
+
for (const block of queue) {
|
2364
|
+
const chunkGroup = chunkGraph.getBlockChunkGroup(block);
|
2365
|
+
if (chunkGroup) {
|
2366
|
+
for (const chunk of chunkGroup.chunks) {
|
2367
|
+
blocks.push(chunk.id);
|
2368
|
+
}
|
2369
|
+
} else {
|
2370
|
+
blocks.push(null);
|
2371
|
+
}
|
2372
|
+
queue.push.apply(queue, block.blocks);
|
2373
|
+
}
|
2374
|
+
}
|
2375
|
+
return { modules, blocks };
|
2376
|
+
};
|
2377
|
+
/**
|
2378
|
+
* @param {Module} module module
|
2379
|
+
* @param {Object} references references
|
2380
|
+
* @param {Map<Module, string | number>=} references.modules modules
|
2381
|
+
* @param {(string | number)[]=} references.blocks blocks
|
2382
|
+
* @returns {boolean} ok?
|
2383
|
+
*/
|
2384
|
+
const compareReferences = (module, { modules, blocks }) => {
|
2385
|
+
if (modules !== undefined) {
|
2386
|
+
for (const [module, id] of modules) {
|
2387
|
+
if (chunkGraph.getModuleId(module) !== id) return false;
|
2388
|
+
}
|
2389
|
+
}
|
2390
|
+
if (blocks !== undefined) {
|
2391
|
+
const queue = Array.from(module.blocks);
|
2392
|
+
let i = 0;
|
2393
|
+
for (const block of queue) {
|
2394
|
+
const chunkGroup = chunkGraph.getBlockChunkGroup(block);
|
2395
|
+
if (chunkGroup) {
|
2396
|
+
for (const chunk of chunkGroup.chunks) {
|
2397
|
+
if (i >= blocks.length || blocks[i++] !== chunk.id) return false;
|
2398
|
+
}
|
2399
|
+
} else {
|
2400
|
+
if (i >= blocks.length || blocks[i++] !== null) return false;
|
2401
|
+
}
|
2402
|
+
queue.push.apply(queue, block.blocks);
|
2403
|
+
}
|
2404
|
+
if (i !== blocks.length) return false;
|
2405
|
+
}
|
2406
|
+
return true;
|
2407
|
+
};
|
2408
|
+
|
2409
|
+
for (const [module, memCache] of moduleMemCaches) {
|
2410
|
+
/** @type {{ references: { modules?: Map<Module, string | number | undefined>, blocks?: (string | number)[]}, memCache: WeakTupleMap<any[], any> }} */
|
2411
|
+
const cache = memCache.get(key);
|
2412
|
+
if (cache === undefined) {
|
2413
|
+
const memCache2 = new WeakTupleMap();
|
2414
|
+
memCache.set(key, {
|
2415
|
+
references: computeReferences(module),
|
2416
|
+
memCache: memCache2
|
2417
|
+
});
|
2418
|
+
moduleMemCaches2.set(module, memCache2);
|
2419
|
+
} else if (!compareReferences(module, cache.references)) {
|
2420
|
+
const memCache = new WeakTupleMap();
|
2421
|
+
cache.references = computeReferences(module);
|
2422
|
+
cache.memCache = memCache;
|
2423
|
+
moduleMemCaches2.set(module, memCache);
|
2424
|
+
} else {
|
2425
|
+
moduleMemCaches2.set(module, cache.memCache);
|
2426
|
+
}
|
2427
|
+
}
|
2428
|
+
}
|
2429
|
+
|
2320
2430
|
finish(callback) {
|
2321
2431
|
this.factorizeQueue.clear();
|
2322
2432
|
if (this.profile) {
|
@@ -2561,6 +2671,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
|
|
2561
2671
|
this.assetsInfo.clear();
|
2562
2672
|
this.moduleGraph.removeAllModuleAttributes();
|
2563
2673
|
this.moduleGraph.unfreeze();
|
2674
|
+
this.moduleMemCaches2 = undefined;
|
2564
2675
|
}
|
2565
2676
|
|
2566
2677
|
/**
|
@@ -2778,6 +2889,8 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
|
|
2778
2889
|
|
2779
2890
|
this.assignRuntimeIds();
|
2780
2891
|
|
2892
|
+
this._updateAffectedModulesWithIds();
|
2893
|
+
|
2781
2894
|
this.sortItemsWithChunkIds();
|
2782
2895
|
|
2783
2896
|
if (shouldRecord) {
|
@@ -3121,18 +3234,14 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
|
|
3121
3234
|
chunkGraphEntries = this._getChunkGraphEntries()
|
3122
3235
|
} = {}) {
|
3123
3236
|
const context = { chunkGraph, codeGenerationResults };
|
3124
|
-
const {
|
3237
|
+
const { moduleMemCaches2 } = this;
|
3125
3238
|
this.logger.time("runtime requirements.modules");
|
3126
3239
|
const additionalModuleRuntimeRequirements =
|
3127
3240
|
this.hooks.additionalModuleRuntimeRequirements;
|
3128
3241
|
const runtimeRequirementInModule = this.hooks.runtimeRequirementInModule;
|
3129
3242
|
for (const module of modules) {
|
3130
3243
|
if (chunkGraph.getNumberOfModuleChunks(module) > 0) {
|
3131
|
-
const memCache =
|
3132
|
-
moduleMemCaches &&
|
3133
|
-
// modules with async blocks depend on the chunk graph and can't be cached that way
|
3134
|
-
module.blocks.length === 0 &&
|
3135
|
-
moduleMemCaches.get(module);
|
3244
|
+
const memCache = moduleMemCaches2 && moduleMemCaches2.get(module);
|
3136
3245
|
for (const runtime of chunkGraph.getModuleRuntimes(module)) {
|
3137
3246
|
if (memCache) {
|
3138
3247
|
const cached = memCache.get(
|
@@ -3589,14 +3698,10 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
|
|
3589
3698
|
createModuleHashes() {
|
3590
3699
|
let statModulesHashed = 0;
|
3591
3700
|
let statModulesFromCache = 0;
|
3592
|
-
const { chunkGraph, runtimeTemplate,
|
3701
|
+
const { chunkGraph, runtimeTemplate, moduleMemCaches2 } = this;
|
3593
3702
|
const { hashFunction, hashDigest, hashDigestLength } = this.outputOptions;
|
3594
3703
|
for (const module of this.modules) {
|
3595
|
-
const memCache =
|
3596
|
-
moduleMemCaches &&
|
3597
|
-
// modules with async blocks depend on the chunk graph and can't be cached that way
|
3598
|
-
module.blocks.length === 0 &&
|
3599
|
-
moduleMemCaches.get(module);
|
3704
|
+
const memCache = moduleMemCaches2 && moduleMemCaches2.get(module);
|
3600
3705
|
for (const runtime of chunkGraph.getModuleRuntimes(module)) {
|
3601
3706
|
if (memCache) {
|
3602
3707
|
const digest = memCache.get(`moduleHash-${getRuntimeKey(runtime)}`);
|
package/lib/Compiler.js
CHANGED
@@ -249,7 +249,7 @@ class Compiler {
|
|
249
249
|
|
250
250
|
this.cache = new Cache();
|
251
251
|
|
252
|
-
/** @type {
|
252
|
+
/** @type {Map<Module, { buildInfo: object, references: WeakMap<Dependency, Module>, memCache: WeakTupleMap }> | undefined} */
|
253
253
|
this.moduleMemCaches = undefined;
|
254
254
|
|
255
255
|
this.compilerPath = "";
|
@@ -48,8 +48,7 @@ class DependencyTemplates {
|
|
48
48
|
*/
|
49
49
|
updateHash(part) {
|
50
50
|
const hash = createHash(this._hashFunction);
|
51
|
-
hash.update(this._hash);
|
52
|
-
hash.update(part);
|
51
|
+
hash.update(`${this._hash}${part}`);
|
53
52
|
this._hash = /** @type {string} */ (hash.digest("hex"));
|
54
53
|
}
|
55
54
|
|
package/lib/DllModule.js
CHANGED
@@ -117,8 +117,7 @@ class DllModule extends Module {
|
|
117
117
|
* @returns {void}
|
118
118
|
*/
|
119
119
|
updateHash(hash, context) {
|
120
|
-
hash.update(
|
121
|
-
hash.update(this.name || "");
|
120
|
+
hash.update(`dll module${this.name || ""}`);
|
122
121
|
super.updateHash(hash, context);
|
123
122
|
}
|
124
123
|
|
package/lib/ExportsInfo.js
CHANGED
@@ -1412,10 +1412,11 @@ class ExportInfo {
|
|
1412
1412
|
}
|
1413
1413
|
|
1414
1414
|
_updateHash(hash, runtime, alreadyVisitedExportsInfo) {
|
1415
|
-
hash.update(
|
1416
|
-
|
1417
|
-
|
1418
|
-
|
1415
|
+
hash.update(
|
1416
|
+
`${this._usedName || this.name}${this.getUsed(runtime)}${this.provided}${
|
1417
|
+
this.terminalBinding
|
1418
|
+
}`
|
1419
|
+
);
|
1419
1420
|
if (this.exportsInfo && !alreadyVisitedExportsInfo.has(this.exportsInfo)) {
|
1420
1421
|
this.exportsInfo._updateHash(hash, runtime, alreadyVisitedExportsInfo);
|
1421
1422
|
}
|
package/lib/ExternalModule.js
CHANGED
@@ -32,6 +32,7 @@ const { register } = require("./util/serialization");
|
|
32
32
|
/** @typedef {import("./Module").ConcatenationBailoutReasonContext} ConcatenationBailoutReasonContext */
|
33
33
|
/** @typedef {import("./Module").LibIdentOptions} LibIdentOptions */
|
34
34
|
/** @typedef {import("./Module").NeedBuildContext} NeedBuildContext */
|
35
|
+
/** @typedef {import("./NormalModuleFactory")} NormalModuleFactory */
|
35
36
|
/** @typedef {import("./RequestShortener")} RequestShortener */
|
36
37
|
/** @typedef {import("./ResolverFactory").ResolverWithOptions} ResolverWithOptions */
|
37
38
|
/** @typedef {import("./RuntimeTemplate")} RuntimeTemplate */
|
@@ -497,6 +498,10 @@ class ExternalModule extends Module {
|
|
497
498
|
callback();
|
498
499
|
}
|
499
500
|
|
501
|
+
restoreFromUnsafeCache(unsafeCacheData, normalModuleFactory) {
|
502
|
+
this._restoreFromUnsafeCache(unsafeCacheData, normalModuleFactory);
|
503
|
+
}
|
504
|
+
|
500
505
|
/**
|
501
506
|
* @param {ConcatenationBailoutReasonContext} context context
|
502
507
|
* @returns {string | undefined} reason why this module can't be concatenated, undefined when it can be concatenated
|
@@ -679,10 +684,10 @@ class ExternalModule extends Module {
|
|
679
684
|
*/
|
680
685
|
updateHash(hash, context) {
|
681
686
|
const { chunkGraph } = context;
|
682
|
-
hash.update(this.externalType);
|
683
|
-
hash.update(JSON.stringify(this.request));
|
684
687
|
hash.update(
|
685
|
-
JSON.stringify(
|
688
|
+
`${this.externalType}${JSON.stringify(this.request)}${this.isOptional(
|
689
|
+
chunkGraph.moduleGraph
|
690
|
+
)}`
|
686
691
|
);
|
687
692
|
super.updateHash(hash, context);
|
688
693
|
}
|
@@ -46,10 +46,15 @@ class FlagDependencyUsagePlugin {
|
|
46
46
|
stage: STAGE_DEFAULT
|
47
47
|
},
|
48
48
|
modules => {
|
49
|
+
if (compilation.moduleMemCaches) {
|
50
|
+
throw new Error(
|
51
|
+
"optimization.usedExports can't be used with cacheUnaffected as export usage is a global effect"
|
52
|
+
);
|
53
|
+
}
|
54
|
+
|
49
55
|
const logger = compilation.getLogger(
|
50
56
|
"webpack.FlagDependencyUsagePlugin"
|
51
57
|
);
|
52
|
-
|
53
58
|
/** @type {Map<ExportsInfo, Module>} */
|
54
59
|
const exportInfoToModuleMap = new Map();
|
55
60
|
|
package/lib/ModuleGraph.js
CHANGED
@@ -29,7 +29,7 @@ const EMPTY_SET = new Set();
|
|
29
29
|
|
30
30
|
/**
|
31
31
|
* @param {SortableSet<ModuleGraphConnection>} set input
|
32
|
-
* @returns {readonly Map<Module, readonly ModuleGraphConnection[]>} mapped by origin module
|
32
|
+
* @returns {readonly Map<Module | undefined, readonly ModuleGraphConnection[]>} mapped by origin module
|
33
33
|
*/
|
34
34
|
const getConnectionsByOriginModule = set => {
|
35
35
|
const map = new Map();
|
@@ -57,11 +57,41 @@ const getConnectionsByOriginModule = set => {
|
|
57
57
|
return map;
|
58
58
|
};
|
59
59
|
|
60
|
+
/**
|
61
|
+
* @param {SortableSet<ModuleGraphConnection>} set input
|
62
|
+
* @returns {readonly Map<Module | undefined, readonly ModuleGraphConnection[]>} mapped by module
|
63
|
+
*/
|
64
|
+
const getConnectionsByModule = set => {
|
65
|
+
const map = new Map();
|
66
|
+
/** @type {Module | 0} */
|
67
|
+
let lastModule = 0;
|
68
|
+
/** @type {ModuleGraphConnection[]} */
|
69
|
+
let lastList = undefined;
|
70
|
+
for (const connection of set) {
|
71
|
+
const { module } = connection;
|
72
|
+
if (lastModule === module) {
|
73
|
+
lastList.push(connection);
|
74
|
+
} else {
|
75
|
+
lastModule = module;
|
76
|
+
const list = map.get(module);
|
77
|
+
if (list !== undefined) {
|
78
|
+
lastList = list;
|
79
|
+
list.push(connection);
|
80
|
+
} else {
|
81
|
+
const list = [connection];
|
82
|
+
lastList = list;
|
83
|
+
map.set(module, list);
|
84
|
+
}
|
85
|
+
}
|
86
|
+
}
|
87
|
+
return map;
|
88
|
+
};
|
89
|
+
|
60
90
|
class ModuleGraphModule {
|
61
91
|
constructor() {
|
62
92
|
/** @type {SortableSet<ModuleGraphConnection>} */
|
63
93
|
this.incomingConnections = new SortableSet();
|
64
|
-
/** @type {
|
94
|
+
/** @type {SortableSet<ModuleGraphConnection> | undefined} */
|
65
95
|
this.outgoingConnections = undefined;
|
66
96
|
/** @type {Module | null} */
|
67
97
|
this.issuer = undefined;
|
@@ -104,7 +134,7 @@ class ModuleGraph {
|
|
104
134
|
/** @type {WeakTupleMap<any[], any>} */
|
105
135
|
this._cache = undefined;
|
106
136
|
|
107
|
-
/** @type {
|
137
|
+
/** @type {Map<Module, WeakTupleMap<any, any>>} */
|
108
138
|
this._moduleMemCaches = undefined;
|
109
139
|
}
|
110
140
|
|
@@ -180,7 +210,7 @@ class ModuleGraph {
|
|
180
210
|
}
|
181
211
|
mgm._unassignedConnections.push(connection);
|
182
212
|
if (mgm.outgoingConnections === undefined) {
|
183
|
-
mgm.outgoingConnections = new
|
213
|
+
mgm.outgoingConnections = new SortableSet();
|
184
214
|
}
|
185
215
|
mgm.outgoingConnections.add(connection);
|
186
216
|
} else {
|
@@ -282,7 +312,7 @@ class ModuleGraph {
|
|
282
312
|
const oldConnections = oldMgm.outgoingConnections;
|
283
313
|
if (oldConnections !== undefined) {
|
284
314
|
if (newMgm.outgoingConnections === undefined) {
|
285
|
-
newMgm.outgoingConnections = new
|
315
|
+
newMgm.outgoingConnections = new SortableSet();
|
286
316
|
}
|
287
317
|
const newConnections = newMgm.outgoingConnections;
|
288
318
|
for (const connection of oldConnections) {
|
@@ -319,7 +349,7 @@ class ModuleGraph {
|
|
319
349
|
const oldConnections = oldMgm.outgoingConnections;
|
320
350
|
if (oldConnections !== undefined) {
|
321
351
|
if (newMgm.outgoingConnections === undefined) {
|
322
|
-
newMgm.outgoingConnections = new
|
352
|
+
newMgm.outgoingConnections = new SortableSet();
|
323
353
|
}
|
324
354
|
const newConnections = newMgm.outgoingConnections;
|
325
355
|
for (const connection of oldConnections) {
|
@@ -434,13 +464,24 @@ class ModuleGraph {
|
|
434
464
|
|
435
465
|
/**
|
436
466
|
* @param {Module} module the module
|
437
|
-
* @returns {readonly Map<Module, readonly ModuleGraphConnection[]>} reasons why a module is included, in a map by source module
|
467
|
+
* @returns {readonly Map<Module | undefined, readonly ModuleGraphConnection[]>} reasons why a module is included, in a map by source module
|
438
468
|
*/
|
439
469
|
getIncomingConnectionsByOriginModule(module) {
|
440
470
|
const connections = this._getModuleGraphModule(module).incomingConnections;
|
441
471
|
return connections.getFromUnorderedCache(getConnectionsByOriginModule);
|
442
472
|
}
|
443
473
|
|
474
|
+
/**
|
475
|
+
* @param {Module} module the module
|
476
|
+
* @returns {readonly Map<Module | undefined, readonly ModuleGraphConnection[]> | undefined} connections to modules, in a map by module
|
477
|
+
*/
|
478
|
+
getOutgoingConnectionsByModule(module) {
|
479
|
+
const connections = this._getModuleGraphModule(module).outgoingConnections;
|
480
|
+
return connections === undefined
|
481
|
+
? undefined
|
482
|
+
: connections.getFromUnorderedCache(getConnectionsByModule);
|
483
|
+
}
|
484
|
+
|
444
485
|
/**
|
445
486
|
* @param {Module} module the module
|
446
487
|
* @returns {ModuleProfile | null} the module profile
|
@@ -728,7 +769,7 @@ class ModuleGraph {
|
|
728
769
|
}
|
729
770
|
|
730
771
|
/**
|
731
|
-
* @param {
|
772
|
+
* @param {Map<Module, WeakTupleMap<any, any>>} moduleMemCaches mem caches for modules for better caching
|
732
773
|
*/
|
733
774
|
setModuleMemCaches(moduleMemCaches) {
|
734
775
|
this._moduleMemCaches = moduleMemCaches;
|
@@ -550,7 +550,7 @@ class WebpackOptionsApply extends OptionsApply {
|
|
550
550
|
"'cache.cacheUnaffected: true' is only allowed when 'experiments.cacheUnaffected' is enabled"
|
551
551
|
);
|
552
552
|
}
|
553
|
-
compiler.moduleMemCaches = new
|
553
|
+
compiler.moduleMemCaches = new Map();
|
554
554
|
}
|
555
555
|
break;
|
556
556
|
}
|
@@ -577,7 +577,7 @@ class WebpackOptionsApply extends OptionsApply {
|
|
577
577
|
"'cache.memoryCacheUnaffected: true' is only allowed when 'experiments.cacheUnaffected' is enabled"
|
578
578
|
);
|
579
579
|
}
|
580
|
-
compiler.moduleMemCaches = new
|
580
|
+
compiler.moduleMemCaches = new Map();
|
581
581
|
}
|
582
582
|
switch (cacheOptions.store) {
|
583
583
|
case "pack": {
|
@@ -137,11 +137,9 @@ class ArrayPushCallbackChunkFormatPlugin {
|
|
137
137
|
"ArrayPushCallbackChunkFormatPlugin",
|
138
138
|
(chunk, hash, { chunkGraph, runtimeTemplate }) => {
|
139
139
|
if (chunk.hasRuntime()) return;
|
140
|
-
hash.update(
|
141
|
-
|
142
|
-
|
143
|
-
hash.update(`${runtimeTemplate.outputOptions.hotUpdateGlobal}`);
|
144
|
-
hash.update(`${runtimeTemplate.outputOptions.globalObject}`);
|
140
|
+
hash.update(
|
141
|
+
`ArrayPushCallbackChunkFormatPlugin1${runtimeTemplate.outputOptions.chunkLoadingGlobal}${runtimeTemplate.outputOptions.hotUpdateGlobal}${runtimeTemplate.outputOptions.globalObject}`
|
142
|
+
);
|
145
143
|
const entries = Array.from(
|
146
144
|
chunkGraph.getChunkEntryModulesWithChunkGroupIterable(chunk)
|
147
145
|
);
|
@@ -157,6 +157,11 @@ class MangleExportsPlugin {
|
|
157
157
|
compilation.hooks.optimizeCodeGeneration.tap(
|
158
158
|
"MangleExportsPlugin",
|
159
159
|
modules => {
|
160
|
+
if (compilation.moduleMemCaches) {
|
161
|
+
throw new Error(
|
162
|
+
"optimization.mangleExports can't be used with cacheUnaffected as export mangling is a global effect"
|
163
|
+
);
|
164
|
+
}
|
160
165
|
for (const module of modules) {
|
161
166
|
const isNamespace =
|
162
167
|
module.buildMeta && module.buildMeta.exportsType === "namespace";
|
package/lib/util/StringXor.js
CHANGED
@@ -8,41 +8,47 @@
|
|
8
8
|
class StringXor {
|
9
9
|
constructor() {
|
10
10
|
this._value = undefined;
|
11
|
-
this._buffer = undefined;
|
12
11
|
}
|
13
12
|
|
13
|
+
/**
|
14
|
+
* @param {string} str string
|
15
|
+
* @returns {void}
|
16
|
+
*/
|
14
17
|
add(str) {
|
15
|
-
|
16
|
-
|
17
|
-
if (
|
18
|
-
|
19
|
-
|
18
|
+
const len = str.length;
|
19
|
+
const value = this._value;
|
20
|
+
if (value === undefined) {
|
21
|
+
const newValue = (this._value = Buffer.allocUnsafe(len));
|
22
|
+
for (let i = 0; i < len; i++) {
|
23
|
+
newValue[i] = str.charCodeAt(i);
|
24
|
+
}
|
20
25
|
return;
|
21
|
-
}
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
26
|
+
}
|
27
|
+
const valueLen = value.length;
|
28
|
+
if (valueLen < len) {
|
29
|
+
const newValue = (this._value = Buffer.allocUnsafe(len));
|
30
|
+
let i;
|
31
|
+
for (i = 0; i < valueLen; i++) {
|
32
|
+
newValue[i] = value[i] ^ str.charCodeAt(i);
|
33
|
+
}
|
34
|
+
for (; i < len; i++) {
|
35
|
+
newValue[i] = str.charCodeAt(i);
|
29
36
|
}
|
30
37
|
} else {
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
const len = buf.length;
|
35
|
-
for (let i = 0; i < len; i++) {
|
36
|
-
value[i] = value[i] ^ buf[i];
|
38
|
+
for (let i = 0; i < len; i++) {
|
39
|
+
value[i] = value[i] ^ str.charCodeAt(i);
|
40
|
+
}
|
37
41
|
}
|
38
42
|
}
|
39
43
|
|
40
44
|
toString() {
|
41
|
-
|
45
|
+
const value = this._value;
|
46
|
+
return value === undefined ? "" : value.toString("latin1");
|
42
47
|
}
|
43
48
|
|
44
49
|
updateHash(hash) {
|
45
|
-
|
50
|
+
const value = this._value;
|
51
|
+
if (value !== undefined) hash.update(value);
|
46
52
|
}
|
47
53
|
}
|
48
54
|
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "webpack",
|
3
|
-
"version": "5.
|
3
|
+
"version": "5.57.0",
|
4
4
|
"author": "Tobias Koppers @sokra",
|
5
5
|
"description": "Packs CommonJs/AMD modules for the browser. Allows to split your codebase into multiple bundles, which can be loaded on demand. Support loaders to preprocess files, i.e. json, jsx, es7, css, less, ... and your custom stuff.",
|
6
6
|
"license": "MIT",
|
package/types.d.ts
CHANGED
@@ -1460,7 +1460,8 @@ declare class Compilation {
|
|
1460
1460
|
chunkTemplate: ChunkTemplate;
|
1461
1461
|
runtimeTemplate: RuntimeTemplate;
|
1462
1462
|
moduleTemplates: { javascript: ModuleTemplate };
|
1463
|
-
moduleMemCaches?:
|
1463
|
+
moduleMemCaches?: Map<Module, WeakTupleMap<any, any>>;
|
1464
|
+
moduleMemCaches2?: Map<Module, WeakTupleMap<any, any>>;
|
1464
1465
|
moduleGraph: ModuleGraph;
|
1465
1466
|
chunkGraph: ChunkGraph;
|
1466
1467
|
codeGenerationResults: CodeGenerationResults;
|
@@ -1907,10 +1908,10 @@ declare class Compiler {
|
|
1907
1908
|
context: string;
|
1908
1909
|
requestShortener: RequestShortener;
|
1909
1910
|
cache: Cache;
|
1910
|
-
moduleMemCaches?:
|
1911
|
+
moduleMemCaches?: Map<
|
1911
1912
|
Module,
|
1912
1913
|
{
|
1913
|
-
|
1914
|
+
buildInfo: object;
|
1914
1915
|
references: WeakMap<Dependency, Module>;
|
1915
1916
|
memCache: WeakTupleMap<any, any>;
|
1916
1917
|
}
|
@@ -3741,6 +3742,10 @@ declare class ExternalModule extends Module {
|
|
3741
3742
|
request: string | string[] | Record<string, string | string[]>;
|
3742
3743
|
externalType: string;
|
3743
3744
|
userRequest: string;
|
3745
|
+
restoreFromUnsafeCache(
|
3746
|
+
unsafeCacheData?: any,
|
3747
|
+
normalModuleFactory?: any
|
3748
|
+
): void;
|
3744
3749
|
}
|
3745
3750
|
declare interface ExternalModuleInfo {
|
3746
3751
|
index: number;
|
@@ -6699,7 +6704,10 @@ declare class ModuleGraph {
|
|
6699
6704
|
getOutgoingConnections(module: Module): Iterable<ModuleGraphConnection>;
|
6700
6705
|
getIncomingConnectionsByOriginModule(
|
6701
6706
|
module: Module
|
6702
|
-
): Map<Module, ReadonlyArray<ModuleGraphConnection>>;
|
6707
|
+
): Map<undefined | Module, ReadonlyArray<ModuleGraphConnection>>;
|
6708
|
+
getOutgoingConnectionsByModule(
|
6709
|
+
module: Module
|
6710
|
+
): undefined | Map<undefined | Module, ReadonlyArray<ModuleGraphConnection>>;
|
6703
6711
|
getProfile(module: Module): null | ModuleProfile;
|
6704
6712
|
setProfile(module: Module, profile: null | ModuleProfile): void;
|
6705
6713
|
getIssuer(module: Module): null | Module;
|
@@ -6740,7 +6748,7 @@ declare class ModuleGraph {
|
|
6740
6748
|
...args: T
|
6741
6749
|
): V;
|
6742
6750
|
setModuleMemCaches(
|
6743
|
-
moduleMemCaches:
|
6751
|
+
moduleMemCaches: Map<Module, WeakTupleMap<any, any>>
|
6744
6752
|
): void;
|
6745
6753
|
dependencyCacheProvide(dependency: Dependency, ...args: any[]): any;
|
6746
6754
|
static getModuleGraphForModule(
|