webpack 5.53.0 → 5.56.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 +9 -2
- package/lib/CacheFacade.js +10 -3
- package/lib/ChunkGraph.js +19 -8
- package/lib/CodeGenerationResults.js +7 -2
- package/lib/Compilation.js +586 -143
- package/lib/Compiler.js +13 -4
- package/lib/DefinePlugin.js +13 -8
- package/lib/Dependency.js +11 -0
- package/lib/DependencyTemplates.js +8 -2
- package/lib/EvalDevToolModulePlugin.js +2 -1
- package/lib/EvalSourceMapDevToolPlugin.js +2 -1
- package/lib/ExternalModule.js +18 -9
- package/lib/FileSystemInfo.js +101 -170
- package/lib/FlagDependencyExportsPlugin.js +25 -16
- package/lib/JavascriptMetaInfoPlugin.js +6 -1
- package/lib/ModuleFactory.js +1 -0
- package/lib/ModuleFilenameHelpers.js +21 -7
- package/lib/ModuleGraph.js +90 -21
- package/lib/NormalModuleFactory.js +8 -43
- package/lib/SourceMapDevToolPlugin.js +7 -3
- package/lib/WebpackOptionsApply.js +19 -1
- package/lib/cache/PackFileCacheStrategy.js +2 -1
- package/lib/cache/getLazyHashedEtag.js +35 -8
- package/lib/config/defaults.js +18 -7
- package/lib/dependencies/CachedConstDependency.js +4 -3
- package/lib/dependencies/CommonJsExportRequireDependency.js +19 -9
- package/lib/dependencies/CommonJsFullRequireDependency.js +11 -9
- package/lib/dependencies/ConstDependency.js +12 -4
- package/lib/dependencies/ContextDependency.js +8 -0
- package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +179 -163
- package/lib/dependencies/HarmonyImportDependency.js +4 -1
- package/lib/dependencies/JsonExportsDependency.js +7 -1
- package/lib/dependencies/ModuleDecoratorDependency.js +5 -2
- package/lib/dependencies/ModuleDependency.js +8 -0
- package/lib/dependencies/NullDependency.js +8 -4
- package/lib/dependencies/ProvidedDependency.js +6 -2
- package/lib/dependencies/PureExpressionDependency.js +5 -1
- package/lib/dependencies/RuntimeRequirementsDependency.js +5 -1
- package/lib/dependencies/WebAssemblyExportImportedDependency.js +9 -0
- package/lib/ids/IdHelpers.js +21 -8
- package/lib/ids/NamedChunkIdsPlugin.js +3 -0
- package/lib/ids/NamedModuleIdsPlugin.js +3 -1
- package/lib/index.js +6 -0
- package/lib/javascript/BasicEvaluatedExpression.js +3 -0
- package/lib/javascript/JavascriptParser.js +22 -4
- package/lib/javascript/JavascriptParserHelpers.js +0 -2
- package/lib/optimize/ConcatenatedModule.js +25 -4
- package/lib/optimize/InnerGraph.js +22 -2
- package/lib/optimize/ModuleConcatenationPlugin.js +2 -1
- package/lib/schemes/HttpUriPlugin.js +1 -2
- package/lib/serialization/BinaryMiddleware.js +11 -2
- package/lib/serialization/FileMiddleware.js +24 -7
- package/lib/serialization/ObjectMiddleware.js +19 -8
- package/lib/util/WeakTupleMap.js +95 -92
- package/lib/util/createHash.js +10 -0
- package/lib/util/hash/BatchedHash.js +65 -0
- package/lib/util/hash/xxhash64.js +154 -0
- package/lib/util/serialization.js +4 -4
- package/package.json +10 -6
- package/schemas/WebpackOptions.check.js +1 -1
- package/schemas/WebpackOptions.json +12 -0
- package/schemas/plugins/HashedModuleIdsPlugin.check.js +1 -1
- package/schemas/plugins/HashedModuleIdsPlugin.json +20 -2
- package/types.d.ts +205 -20
@@ -8,6 +8,11 @@
|
|
8
8
|
const createHash = require("./util/createHash");
|
9
9
|
const memoize = require("./util/memoize");
|
10
10
|
|
11
|
+
/** @typedef {import("./ChunkGraph")} ChunkGraph */
|
12
|
+
/** @typedef {import("./Module")} Module */
|
13
|
+
/** @typedef {import("./RequestShortener")} RequestShortener */
|
14
|
+
/** @typedef {typeof import("./util/Hash")} Hash */
|
15
|
+
|
11
16
|
const ModuleFilenameHelpers = exports;
|
12
17
|
|
13
18
|
// TODO webpack 6: consider removing these
|
@@ -53,9 +58,9 @@ const getBefore = (strFn, token) => {
|
|
53
58
|
};
|
54
59
|
};
|
55
60
|
|
56
|
-
const getHash = strFn => {
|
61
|
+
const getHash = (strFn, hashFunction) => {
|
57
62
|
return () => {
|
58
|
-
const hash = createHash(
|
63
|
+
const hash = createHash(hashFunction);
|
59
64
|
hash.update(strFn());
|
60
65
|
const digest = /** @type {string} */ (hash.digest("hex"));
|
61
66
|
return digest.substr(0, 4);
|
@@ -91,10 +96,20 @@ const lazyObject = obj => {
|
|
91
96
|
|
92
97
|
const REGEXP = /\[\\*([\w-]+)\\*\]/gi;
|
93
98
|
|
99
|
+
/**
|
100
|
+
*
|
101
|
+
* @param {Module | string} module the module
|
102
|
+
* @param {TODO} options options
|
103
|
+
* @param {Object} contextInfo context info
|
104
|
+
* @param {RequestShortener} contextInfo.requestShortener requestShortener
|
105
|
+
* @param {ChunkGraph} contextInfo.chunkGraph chunk graph
|
106
|
+
* @param {string | Hash} contextInfo.hashFunction the hash function to use
|
107
|
+
* @returns {string} the filename
|
108
|
+
*/
|
94
109
|
ModuleFilenameHelpers.createFilename = (
|
95
|
-
module,
|
110
|
+
module = "",
|
96
111
|
options,
|
97
|
-
{ requestShortener, chunkGraph }
|
112
|
+
{ requestShortener, chunkGraph, hashFunction = "md4" }
|
98
113
|
) => {
|
99
114
|
const opts = {
|
100
115
|
namespace: "",
|
@@ -111,13 +126,12 @@ ModuleFilenameHelpers.createFilename = (
|
|
111
126
|
let identifier;
|
112
127
|
let moduleId;
|
113
128
|
let shortIdentifier;
|
114
|
-
if (module === undefined) module = "";
|
115
129
|
if (typeof module === "string") {
|
116
130
|
shortIdentifier = memoize(() => requestShortener.shorten(module));
|
117
131
|
identifier = shortIdentifier;
|
118
132
|
moduleId = () => "";
|
119
133
|
absoluteResourcePath = () => module.split("!").pop();
|
120
|
-
hash = getHash(identifier);
|
134
|
+
hash = getHash(identifier, hashFunction);
|
121
135
|
} else {
|
122
136
|
shortIdentifier = memoize(() =>
|
123
137
|
module.readableIdentifier(requestShortener)
|
@@ -125,7 +139,7 @@ ModuleFilenameHelpers.createFilename = (
|
|
125
139
|
identifier = memoize(() => requestShortener.shorten(module.identifier()));
|
126
140
|
moduleId = () => chunkGraph.getModuleId(module);
|
127
141
|
absoluteResourcePath = () => module.identifier().split("!").pop();
|
128
|
-
hash = getHash(identifier);
|
142
|
+
hash = getHash(identifier, hashFunction);
|
129
143
|
}
|
130
144
|
const resource = memoize(() => shortIdentifier().split("!").pop());
|
131
145
|
|
package/lib/ModuleGraph.js
CHANGED
@@ -79,19 +79,19 @@ class ModuleGraphModule {
|
|
79
79
|
this.profile = undefined;
|
80
80
|
/** @type {boolean} */
|
81
81
|
this.async = false;
|
82
|
+
/** @type {ModuleGraphConnection[]} */
|
83
|
+
this._unassignedConnections = undefined;
|
82
84
|
}
|
83
85
|
}
|
84
86
|
|
85
87
|
class ModuleGraph {
|
86
88
|
constructor() {
|
87
|
-
/** @type {
|
88
|
-
this._dependencyMap = new
|
89
|
+
/** @type {WeakMap<Dependency, ModuleGraphConnection>} */
|
90
|
+
this._dependencyMap = new WeakMap();
|
89
91
|
/** @type {Map<Module, ModuleGraphModule>} */
|
90
92
|
this._moduleMap = new Map();
|
91
|
-
/** @type {
|
92
|
-
this.
|
93
|
-
/** @type {Map<any, Object>} */
|
94
|
-
this._metaMap = new Map();
|
93
|
+
/** @type {WeakMap<any, Object>} */
|
94
|
+
this._metaMap = new WeakMap();
|
95
95
|
|
96
96
|
// Caching
|
97
97
|
this._cacheModuleGraphModuleKey1 = undefined;
|
@@ -103,6 +103,9 @@ class ModuleGraph {
|
|
103
103
|
|
104
104
|
/** @type {WeakTupleMap<any[], any>} */
|
105
105
|
this._cache = undefined;
|
106
|
+
|
107
|
+
/** @type {WeakMap<Module, WeakTupleMap<any, any>>} */
|
108
|
+
this._moduleMemCaches = undefined;
|
106
109
|
}
|
107
110
|
|
108
111
|
/**
|
@@ -168,14 +171,21 @@ class ModuleGraph {
|
|
168
171
|
dependency.weak,
|
169
172
|
dependency.getCondition(this)
|
170
173
|
);
|
171
|
-
this._dependencyMap.set(dependency, connection);
|
172
174
|
const connections = this._getModuleGraphModule(module).incomingConnections;
|
173
175
|
connections.add(connection);
|
174
|
-
|
175
|
-
|
176
|
-
mgm.
|
176
|
+
if (originModule) {
|
177
|
+
const mgm = this._getModuleGraphModule(originModule);
|
178
|
+
if (mgm._unassignedConnections === undefined) {
|
179
|
+
mgm._unassignedConnections = [];
|
180
|
+
}
|
181
|
+
mgm._unassignedConnections.push(connection);
|
182
|
+
if (mgm.outgoingConnections === undefined) {
|
183
|
+
mgm.outgoingConnections = new Set();
|
184
|
+
}
|
185
|
+
mgm.outgoingConnections.add(connection);
|
186
|
+
} else {
|
187
|
+
this._dependencyMap.set(dependency, connection);
|
177
188
|
}
|
178
|
-
mgm.outgoingConnections.add(connection);
|
179
189
|
}
|
180
190
|
|
181
191
|
/**
|
@@ -184,7 +194,7 @@ class ModuleGraph {
|
|
184
194
|
* @returns {void}
|
185
195
|
*/
|
186
196
|
updateModule(dependency, module) {
|
187
|
-
const connection = this.
|
197
|
+
const connection = this.getConnection(dependency);
|
188
198
|
if (connection.module === module) return;
|
189
199
|
const newConnection = connection.clone();
|
190
200
|
newConnection.module = module;
|
@@ -201,12 +211,12 @@ class ModuleGraph {
|
|
201
211
|
* @returns {void}
|
202
212
|
*/
|
203
213
|
removeConnection(dependency) {
|
204
|
-
const connection = this.
|
214
|
+
const connection = this.getConnection(dependency);
|
205
215
|
const targetMgm = this._getModuleGraphModule(connection.module);
|
206
216
|
targetMgm.incomingConnections.delete(connection);
|
207
217
|
const originMgm = this._getModuleGraphModule(connection.originModule);
|
208
218
|
originMgm.outgoingConnections.delete(connection);
|
209
|
-
this._dependencyMap.
|
219
|
+
this._dependencyMap.set(dependency, null);
|
210
220
|
}
|
211
221
|
|
212
222
|
/**
|
@@ -215,7 +225,7 @@ class ModuleGraph {
|
|
215
225
|
* @returns {void}
|
216
226
|
*/
|
217
227
|
addExplanation(dependency, explanation) {
|
218
|
-
const connection = this.
|
228
|
+
const connection = this.getConnection(dependency);
|
219
229
|
connection.addExplanation(explanation);
|
220
230
|
}
|
221
231
|
|
@@ -341,7 +351,7 @@ class ModuleGraph {
|
|
341
351
|
* @returns {Module} the referenced module
|
342
352
|
*/
|
343
353
|
getResolvedModule(dependency) {
|
344
|
-
const connection = this.
|
354
|
+
const connection = this.getConnection(dependency);
|
345
355
|
return connection !== undefined ? connection.resolvedModule : null;
|
346
356
|
}
|
347
357
|
|
@@ -351,7 +361,30 @@ class ModuleGraph {
|
|
351
361
|
*/
|
352
362
|
getConnection(dependency) {
|
353
363
|
const connection = this._dependencyMap.get(dependency);
|
354
|
-
|
364
|
+
if (connection === undefined) {
|
365
|
+
const module = this.getParentModule(dependency);
|
366
|
+
if (module !== undefined) {
|
367
|
+
const mgm = this._getModuleGraphModule(module);
|
368
|
+
if (
|
369
|
+
mgm._unassignedConnections &&
|
370
|
+
mgm._unassignedConnections.length !== 0
|
371
|
+
) {
|
372
|
+
let foundConnection;
|
373
|
+
for (const connection of mgm._unassignedConnections) {
|
374
|
+
this._dependencyMap.set(connection.dependency, connection);
|
375
|
+
if (connection.dependency === dependency)
|
376
|
+
foundConnection = connection;
|
377
|
+
}
|
378
|
+
mgm._unassignedConnections.length = 0;
|
379
|
+
if (foundConnection !== undefined) {
|
380
|
+
return foundConnection;
|
381
|
+
}
|
382
|
+
}
|
383
|
+
}
|
384
|
+
this._dependencyMap.set(dependency, null);
|
385
|
+
return undefined;
|
386
|
+
}
|
387
|
+
return connection === null ? undefined : connection;
|
355
388
|
}
|
356
389
|
|
357
390
|
/**
|
@@ -359,7 +392,7 @@ class ModuleGraph {
|
|
359
392
|
* @returns {Module} the referenced module
|
360
393
|
*/
|
361
394
|
getModule(dependency) {
|
362
|
-
const connection = this.
|
395
|
+
const connection = this.getConnection(dependency);
|
363
396
|
return connection !== undefined ? connection.module : null;
|
364
397
|
}
|
365
398
|
|
@@ -368,7 +401,7 @@ class ModuleGraph {
|
|
368
401
|
* @returns {Module} the referencing module
|
369
402
|
*/
|
370
403
|
getOrigin(dependency) {
|
371
|
-
const connection = this.
|
404
|
+
const connection = this.getConnection(dependency);
|
372
405
|
return connection !== undefined ? connection.originModule : null;
|
373
406
|
}
|
374
407
|
|
@@ -377,7 +410,7 @@ class ModuleGraph {
|
|
377
410
|
* @returns {Module} the original referencing module
|
378
411
|
*/
|
379
412
|
getResolvedOrigin(dependency) {
|
380
|
-
const connection = this.
|
413
|
+
const connection = this.getConnection(dependency);
|
381
414
|
return connection !== undefined ? connection.resolvedOriginModule : null;
|
382
415
|
}
|
383
416
|
|
@@ -669,12 +702,17 @@ class ModuleGraph {
|
|
669
702
|
return this._metaMap.get(thing);
|
670
703
|
}
|
671
704
|
|
672
|
-
|
705
|
+
/**
|
706
|
+
* @param {string=} cacheStage a persistent stage name for caching
|
707
|
+
*/
|
708
|
+
freeze(cacheStage) {
|
673
709
|
this._cache = new WeakTupleMap();
|
710
|
+
this._cacheStage = cacheStage;
|
674
711
|
}
|
675
712
|
|
676
713
|
unfreeze() {
|
677
714
|
this._cache = undefined;
|
715
|
+
this._cacheStage = undefined;
|
678
716
|
}
|
679
717
|
|
680
718
|
/**
|
@@ -689,6 +727,37 @@ class ModuleGraph {
|
|
689
727
|
return this._cache.provide(fn, ...args, () => fn(this, ...args));
|
690
728
|
}
|
691
729
|
|
730
|
+
/**
|
731
|
+
* @param {WeakMap<Module, WeakTupleMap<any, any>>} moduleMemCaches mem caches for modules for better caching
|
732
|
+
*/
|
733
|
+
setModuleMemCaches(moduleMemCaches) {
|
734
|
+
this._moduleMemCaches = moduleMemCaches;
|
735
|
+
}
|
736
|
+
|
737
|
+
/**
|
738
|
+
* @param {Dependency} dependency dependency
|
739
|
+
* @param {...any} args arguments, last argument is a function called with moduleGraph, dependency, ...args
|
740
|
+
* @returns {any} computed value or cached
|
741
|
+
*/
|
742
|
+
dependencyCacheProvide(dependency, ...args) {
|
743
|
+
/** @type {(moduleGraph: ModuleGraph, dependency: Dependency, ...args: any[]) => any} */
|
744
|
+
const fn = args.pop();
|
745
|
+
if (this._moduleMemCaches && this._cacheStage) {
|
746
|
+
const memCache = this._moduleMemCaches.get(
|
747
|
+
this.getParentModule(dependency)
|
748
|
+
);
|
749
|
+
if (memCache !== undefined) {
|
750
|
+
return memCache.provide(dependency, this._cacheStage, ...args, () =>
|
751
|
+
fn(this, dependency, ...args)
|
752
|
+
);
|
753
|
+
}
|
754
|
+
}
|
755
|
+
if (this._cache === undefined) return fn(this, dependency, ...args);
|
756
|
+
return this._cache.provide(dependency, ...args, () =>
|
757
|
+
fn(this, dependency, ...args)
|
758
|
+
);
|
759
|
+
}
|
760
|
+
|
692
761
|
// TODO remove in webpack 6
|
693
762
|
/**
|
694
763
|
* @param {Module} module the module
|
@@ -167,12 +167,6 @@ const deprecationChangedHookMessage = (name, hook) => {
|
|
167
167
|
);
|
168
168
|
};
|
169
169
|
|
170
|
-
/** @type {WeakMap<ModuleDependency, ModuleFactoryResult & { module: { restoreFromUnsafeCache: Function }}>} */
|
171
|
-
const unsafeCacheDependencies = new WeakMap();
|
172
|
-
|
173
|
-
/** @type {WeakMap<Module, object>} */
|
174
|
-
const unsafeCacheData = new WeakMap();
|
175
|
-
|
176
170
|
const ruleSetCompiler = new RuleSetCompiler([
|
177
171
|
new BasicMatcherRulePlugin("test", "resource"),
|
178
172
|
new BasicMatcherRulePlugin("scheme"),
|
@@ -256,11 +250,6 @@ class NormalModuleFactory extends ModuleFactory {
|
|
256
250
|
rules: options.rules
|
257
251
|
}
|
258
252
|
]);
|
259
|
-
this.unsafeCache = !!options.unsafeCache;
|
260
|
-
this.cachePredicate =
|
261
|
-
typeof options.unsafeCache === "function"
|
262
|
-
? options.unsafeCache
|
263
|
-
: () => true;
|
264
253
|
this.context = context || "";
|
265
254
|
this.fs = fs;
|
266
255
|
this._globalParserOptions = options.parser;
|
@@ -745,18 +734,6 @@ class NormalModuleFactory extends ModuleFactory {
|
|
745
734
|
*/
|
746
735
|
create(data, callback) {
|
747
736
|
const dependencies = /** @type {ModuleDependency[]} */ (data.dependencies);
|
748
|
-
if (this.unsafeCache) {
|
749
|
-
const cacheEntry = unsafeCacheDependencies.get(dependencies[0]);
|
750
|
-
if (cacheEntry) {
|
751
|
-
const { module } = cacheEntry;
|
752
|
-
if (!this._restoredUnsafeCacheEntries.has(module)) {
|
753
|
-
const data = unsafeCacheData.get(module);
|
754
|
-
module.restoreFromUnsafeCache(data, this);
|
755
|
-
this._restoredUnsafeCacheEntries.add(module);
|
756
|
-
}
|
757
|
-
return callback(null, cacheEntry);
|
758
|
-
}
|
759
|
-
}
|
760
737
|
const context = data.context || this.context;
|
761
738
|
const resolveOptions = data.resolveOptions || EMPTY_RESOLVE_OPTIONS;
|
762
739
|
const dependency = dependencies[0];
|
@@ -788,7 +765,8 @@ class NormalModuleFactory extends ModuleFactory {
|
|
788
765
|
return callback(err, {
|
789
766
|
fileDependencies,
|
790
767
|
missingDependencies,
|
791
|
-
contextDependencies
|
768
|
+
contextDependencies,
|
769
|
+
cacheable: false
|
792
770
|
});
|
793
771
|
}
|
794
772
|
|
@@ -797,7 +775,8 @@ class NormalModuleFactory extends ModuleFactory {
|
|
797
775
|
return callback(null, {
|
798
776
|
fileDependencies,
|
799
777
|
missingDependencies,
|
800
|
-
contextDependencies
|
778
|
+
contextDependencies,
|
779
|
+
cacheable: resolveData.cacheable
|
801
780
|
});
|
802
781
|
}
|
803
782
|
|
@@ -814,7 +793,8 @@ class NormalModuleFactory extends ModuleFactory {
|
|
814
793
|
return callback(err, {
|
815
794
|
fileDependencies,
|
816
795
|
missingDependencies,
|
817
|
-
contextDependencies
|
796
|
+
contextDependencies,
|
797
|
+
cacheable: false
|
818
798
|
});
|
819
799
|
}
|
820
800
|
|
@@ -822,25 +802,10 @@ class NormalModuleFactory extends ModuleFactory {
|
|
822
802
|
module,
|
823
803
|
fileDependencies,
|
824
804
|
missingDependencies,
|
825
|
-
contextDependencies
|
805
|
+
contextDependencies,
|
806
|
+
cacheable: resolveData.cacheable
|
826
807
|
};
|
827
808
|
|
828
|
-
if (
|
829
|
-
this.unsafeCache &&
|
830
|
-
resolveData.cacheable &&
|
831
|
-
module &&
|
832
|
-
module.restoreFromUnsafeCache &&
|
833
|
-
this.cachePredicate(module)
|
834
|
-
) {
|
835
|
-
for (const d of dependencies) {
|
836
|
-
unsafeCacheDependencies.set(d, factoryResult);
|
837
|
-
}
|
838
|
-
if (!unsafeCacheData.has(module)) {
|
839
|
-
unsafeCacheData.set(module, module.getUnsafeCacheData());
|
840
|
-
}
|
841
|
-
this._restoredUnsafeCacheEntries.add(module);
|
842
|
-
}
|
843
|
-
|
844
809
|
callback(null, factoryResult);
|
845
810
|
});
|
846
811
|
});
|
@@ -297,7 +297,8 @@ class SourceMapDevToolPlugin {
|
|
297
297
|
},
|
298
298
|
{
|
299
299
|
requestShortener,
|
300
|
-
chunkGraph
|
300
|
+
chunkGraph,
|
301
|
+
hashFunction: compilation.outputOptions.hashFunction
|
301
302
|
}
|
302
303
|
)
|
303
304
|
);
|
@@ -358,7 +359,8 @@ class SourceMapDevToolPlugin {
|
|
358
359
|
},
|
359
360
|
{
|
360
361
|
requestShortener,
|
361
|
-
chunkGraph
|
362
|
+
chunkGraph,
|
363
|
+
hashFunction: compilation.outputOptions.hashFunction
|
362
364
|
}
|
363
365
|
);
|
364
366
|
hasName = usedNamesSet.has(sourceName);
|
@@ -442,7 +444,9 @@ class SourceMapDevToolPlugin {
|
|
442
444
|
const sourceMapContentHash =
|
443
445
|
usesContentHash &&
|
444
446
|
/** @type {string} */ (
|
445
|
-
createHash(
|
447
|
+
createHash(compilation.outputOptions.hashFunction)
|
448
|
+
.update(sourceMapString)
|
449
|
+
.digest("hex")
|
446
450
|
);
|
447
451
|
const pathParams = {
|
448
452
|
chunk,
|
@@ -431,7 +431,9 @@ class WebpackOptionsApply extends OptionsApply {
|
|
431
431
|
"hashed",
|
432
432
|
"deterministic"
|
433
433
|
).apply(compiler);
|
434
|
-
new HashedModuleIdsPlugin(
|
434
|
+
new HashedModuleIdsPlugin({
|
435
|
+
hashFunction: options.output.hashFunction
|
436
|
+
}).apply(compiler);
|
435
437
|
break;
|
436
438
|
}
|
437
439
|
case "deterministic": {
|
@@ -542,6 +544,14 @@ class WebpackOptionsApply extends OptionsApply {
|
|
542
544
|
const MemoryCachePlugin = require("./cache/MemoryCachePlugin");
|
543
545
|
new MemoryCachePlugin().apply(compiler);
|
544
546
|
}
|
547
|
+
if (cacheOptions.cacheUnaffected) {
|
548
|
+
if (!options.experiments.cacheUnaffected) {
|
549
|
+
throw new Error(
|
550
|
+
"'cache.cacheUnaffected: true' is only allowed when 'experiments.cacheUnaffected' is enabled"
|
551
|
+
);
|
552
|
+
}
|
553
|
+
compiler.moduleMemCaches = new WeakMap();
|
554
|
+
}
|
545
555
|
break;
|
546
556
|
}
|
547
557
|
case "filesystem": {
|
@@ -561,6 +571,14 @@ class WebpackOptionsApply extends OptionsApply {
|
|
561
571
|
maxGenerations: cacheOptions.maxMemoryGenerations
|
562
572
|
}).apply(compiler);
|
563
573
|
}
|
574
|
+
if (cacheOptions.memoryCacheUnaffected) {
|
575
|
+
if (!options.experiments.cacheUnaffected) {
|
576
|
+
throw new Error(
|
577
|
+
"'cache.memoryCacheUnaffected: true' is only allowed when 'experiments.cacheUnaffected' is enabled"
|
578
|
+
);
|
579
|
+
}
|
580
|
+
compiler.moduleMemCaches = new WeakMap();
|
581
|
+
}
|
564
582
|
switch (cacheOptions.store) {
|
565
583
|
case "pack": {
|
566
584
|
const IdleFileCachePlugin = require("./cache/IdleFileCachePlugin");
|
@@ -995,7 +995,8 @@ class PackFileCacheStrategy {
|
|
995
995
|
this.fileSystemInfo = new FileSystemInfo(fs, {
|
996
996
|
managedPaths: snapshot.managedPaths,
|
997
997
|
immutablePaths: snapshot.immutablePaths,
|
998
|
-
logger: logger.getChildLogger("webpack.FileSystemInfo")
|
998
|
+
logger: logger.getChildLogger("webpack.FileSystemInfo"),
|
999
|
+
hashFunction: compiler.options.output.hashFunction
|
999
1000
|
});
|
1000
1001
|
this.compiler = compiler;
|
1001
1002
|
this.context = context;
|
@@ -8,6 +8,7 @@
|
|
8
8
|
const createHash = require("../util/createHash");
|
9
9
|
|
10
10
|
/** @typedef {import("../util/Hash")} Hash */
|
11
|
+
/** @typedef {typeof import("../util/Hash")} HashConstructor */
|
11
12
|
|
12
13
|
/**
|
13
14
|
* @typedef {Object} HashableObject
|
@@ -17,10 +18,12 @@ const createHash = require("../util/createHash");
|
|
17
18
|
class LazyHashedEtag {
|
18
19
|
/**
|
19
20
|
* @param {HashableObject} obj object with updateHash method
|
21
|
+
* @param {string | HashConstructor} hashFunction the hash function to use
|
20
22
|
*/
|
21
|
-
constructor(obj) {
|
23
|
+
constructor(obj, hashFunction = "md4") {
|
22
24
|
this._obj = obj;
|
23
25
|
this._hash = undefined;
|
26
|
+
this._hashFunction = hashFunction;
|
24
27
|
}
|
25
28
|
|
26
29
|
/**
|
@@ -28,7 +31,7 @@ class LazyHashedEtag {
|
|
28
31
|
*/
|
29
32
|
toString() {
|
30
33
|
if (this._hash === undefined) {
|
31
|
-
const hash = createHash(
|
34
|
+
const hash = createHash(this._hashFunction);
|
32
35
|
this._obj.updateHash(hash);
|
33
36
|
this._hash = /** @type {string} */ (hash.digest("base64"));
|
34
37
|
}
|
@@ -36,18 +39,42 @@ class LazyHashedEtag {
|
|
36
39
|
}
|
37
40
|
}
|
38
41
|
|
39
|
-
/** @type {WeakMap<HashableObject, LazyHashedEtag
|
40
|
-
const
|
42
|
+
/** @type {Map<string | HashConstructor, WeakMap<HashableObject, LazyHashedEtag>>} */
|
43
|
+
const mapStrings = new Map();
|
44
|
+
|
45
|
+
/** @type {WeakMap<HashConstructor, WeakMap<HashableObject, LazyHashedEtag>>} */
|
46
|
+
const mapObjects = new WeakMap();
|
41
47
|
|
42
48
|
/**
|
43
49
|
* @param {HashableObject} obj object with updateHash method
|
50
|
+
* @param {string | HashConstructor} hashFunction the hash function to use
|
44
51
|
* @returns {LazyHashedEtag} etag
|
45
52
|
*/
|
46
|
-
const getter = obj => {
|
47
|
-
|
53
|
+
const getter = (obj, hashFunction = "md4") => {
|
54
|
+
let innerMap;
|
55
|
+
if (typeof hashFunction === "string") {
|
56
|
+
innerMap = mapStrings.get(hashFunction);
|
57
|
+
if (innerMap === undefined) {
|
58
|
+
const newHash = new LazyHashedEtag(obj, hashFunction);
|
59
|
+
innerMap = new WeakMap();
|
60
|
+
innerMap.set(obj, newHash);
|
61
|
+
mapStrings.set(hashFunction, innerMap);
|
62
|
+
return newHash;
|
63
|
+
}
|
64
|
+
} else {
|
65
|
+
innerMap = mapObjects.get(hashFunction);
|
66
|
+
if (innerMap === undefined) {
|
67
|
+
const newHash = new LazyHashedEtag(obj, hashFunction);
|
68
|
+
innerMap = new WeakMap();
|
69
|
+
innerMap.set(obj, newHash);
|
70
|
+
mapObjects.set(hashFunction, innerMap);
|
71
|
+
return newHash;
|
72
|
+
}
|
73
|
+
}
|
74
|
+
const hash = innerMap.get(obj);
|
48
75
|
if (hash !== undefined) return hash;
|
49
|
-
const newHash = new LazyHashedEtag(obj);
|
50
|
-
|
76
|
+
const newHash = new LazyHashedEtag(obj, hashFunction);
|
77
|
+
innerMap.set(obj, newHash);
|
51
78
|
return newHash;
|
52
79
|
};
|
53
80
|
|
package/lib/config/defaults.js
CHANGED
@@ -159,20 +159,21 @@ const applyWebpackOptionsDefaults = options => {
|
|
159
159
|
D(options, "recordsInputPath", false);
|
160
160
|
D(options, "recordsOutputPath", false);
|
161
161
|
|
162
|
+
applyExperimentsDefaults(options.experiments, { production, development });
|
163
|
+
|
162
164
|
F(options, "cache", () =>
|
163
165
|
development ? { type: /** @type {"memory"} */ ("memory") } : false
|
164
166
|
);
|
165
167
|
applyCacheDefaults(options.cache, {
|
166
168
|
name: name || "default",
|
167
169
|
mode: mode || "production",
|
168
|
-
development
|
170
|
+
development,
|
171
|
+
cacheUnaffected: options.experiments.cacheUnaffected
|
169
172
|
});
|
170
173
|
const cache = !!options.cache;
|
171
174
|
|
172
175
|
applySnapshotDefaults(options.snapshot, { production });
|
173
176
|
|
174
|
-
applyExperimentsDefaults(options.experiments, { production, development });
|
175
|
-
|
176
177
|
applyModuleDefaults(options.module, {
|
177
178
|
cache,
|
178
179
|
syncWebAssembly: options.experiments.syncWebAssembly,
|
@@ -190,7 +191,8 @@ const applyWebpackOptionsDefaults = options => {
|
|
190
191
|
outputModule: options.experiments.outputModule,
|
191
192
|
development,
|
192
193
|
entry: options.entry,
|
193
|
-
module: options.module
|
194
|
+
module: options.module,
|
195
|
+
futureDefaults: options.experiments.futureDefaults
|
194
196
|
});
|
195
197
|
|
196
198
|
applyExternalsPresetsDefaults(options.externalsPresets, {
|
@@ -266,6 +268,7 @@ const applyExperimentsDefaults = (experiments, { production, development }) => {
|
|
266
268
|
D(experiments, "lazyCompilation", false);
|
267
269
|
D(experiments, "buildHttp", false);
|
268
270
|
D(experiments, "futureDefaults", false);
|
271
|
+
D(experiments, "cacheUnaffected", experiments.futureDefaults);
|
269
272
|
|
270
273
|
if (typeof experiments.buildHttp === "object") {
|
271
274
|
D(experiments.buildHttp, "frozen", production);
|
@@ -279,9 +282,13 @@ const applyExperimentsDefaults = (experiments, { production, development }) => {
|
|
279
282
|
* @param {string} options.name name
|
280
283
|
* @param {string} options.mode mode
|
281
284
|
* @param {boolean} options.development is development mode
|
285
|
+
* @param {boolean} options.cacheUnaffected the cacheUnaffected experiment is enabled
|
282
286
|
* @returns {void}
|
283
287
|
*/
|
284
|
-
const applyCacheDefaults = (
|
288
|
+
const applyCacheDefaults = (
|
289
|
+
cache,
|
290
|
+
{ name, mode, development, cacheUnaffected }
|
291
|
+
) => {
|
285
292
|
if (cache === false) return;
|
286
293
|
switch (cache.type) {
|
287
294
|
case "filesystem":
|
@@ -325,12 +332,14 @@ const applyCacheDefaults = (cache, { name, mode, development }) => {
|
|
325
332
|
D(cache, "maxMemoryGenerations", development ? 5 : Infinity);
|
326
333
|
D(cache, "maxAge", 1000 * 60 * 60 * 24 * 60); // 1 month
|
327
334
|
D(cache, "allowCollectingMemory", development);
|
335
|
+
D(cache, "memoryCacheUnaffected", development && cacheUnaffected);
|
328
336
|
D(cache.buildDependencies, "defaultWebpack", [
|
329
337
|
path.resolve(__dirname, "..") + path.sep
|
330
338
|
]);
|
331
339
|
break;
|
332
340
|
case "memory":
|
333
341
|
D(cache, "maxGenerations", Infinity);
|
342
|
+
D(cache, "cacheUnaffected", development && cacheUnaffected);
|
334
343
|
break;
|
335
344
|
}
|
336
345
|
};
|
@@ -580,6 +589,7 @@ const applyModuleDefaults = (
|
|
580
589
|
* @param {boolean} options.development is development mode
|
581
590
|
* @param {Entry} options.entry entry option
|
582
591
|
* @param {ModuleOptions} options.module module option
|
592
|
+
* @param {boolean} options.futureDefaults is future defaults enabled
|
583
593
|
* @returns {void}
|
584
594
|
*/
|
585
595
|
const applyOutputDefaults = (
|
@@ -591,7 +601,8 @@ const applyOutputDefaults = (
|
|
591
601
|
outputModule,
|
592
602
|
development,
|
593
603
|
entry,
|
594
|
-
module
|
604
|
+
module,
|
605
|
+
futureDefaults
|
595
606
|
}
|
596
607
|
) => {
|
597
608
|
/**
|
@@ -788,7 +799,7 @@ const applyOutputDefaults = (
|
|
788
799
|
: ""
|
789
800
|
);
|
790
801
|
D(output, "chunkLoadTimeout", 120000);
|
791
|
-
D(output, "hashFunction", "md4");
|
802
|
+
D(output, "hashFunction", futureDefaults ? "xxhash64" : "md4");
|
792
803
|
D(output, "hashDigest", "hex");
|
793
804
|
D(output, "hashDigestLength", 20);
|
794
805
|
D(output, "strictModuleExceptionHandling", false);
|
@@ -27,6 +27,7 @@ class CachedConstDependency extends NullDependency {
|
|
27
27
|
this.expression = expression;
|
28
28
|
this.range = range;
|
29
29
|
this.identifier = identifier;
|
30
|
+
this._hashUpdate = undefined;
|
30
31
|
}
|
31
32
|
|
32
33
|
/**
|
@@ -36,9 +37,9 @@ class CachedConstDependency extends NullDependency {
|
|
36
37
|
* @returns {void}
|
37
38
|
*/
|
38
39
|
updateHash(hash, context) {
|
39
|
-
|
40
|
-
|
41
|
-
hash.update(this.
|
40
|
+
if (this._hashUpdate === undefined)
|
41
|
+
this._hashUpdate = "" + this.identifier + this.range + this.expression;
|
42
|
+
hash.update(this._hashUpdate);
|
42
43
|
}
|
43
44
|
|
44
45
|
serialize(context) {
|