webpack 5.52.1 → 5.55.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of webpack might be problematic. Click here for more details.

Files changed (69) hide show
  1. package/lib/AsyncDependenciesBlock.js +9 -2
  2. package/lib/CacheFacade.js +10 -3
  3. package/lib/ChunkGraph.js +19 -8
  4. package/lib/CodeGenerationResults.js +7 -2
  5. package/lib/Compilation.js +586 -143
  6. package/lib/Compiler.js +13 -4
  7. package/lib/Dependency.js +11 -0
  8. package/lib/DependencyTemplates.js +8 -2
  9. package/lib/EvalDevToolModulePlugin.js +2 -1
  10. package/lib/EvalSourceMapDevToolPlugin.js +2 -1
  11. package/lib/ExternalModule.js +18 -9
  12. package/lib/FileSystemInfo.js +101 -170
  13. package/lib/FlagDependencyExportsPlugin.js +25 -16
  14. package/lib/JavascriptMetaInfoPlugin.js +6 -1
  15. package/lib/ModuleFactory.js +1 -0
  16. package/lib/ModuleFilenameHelpers.js +21 -7
  17. package/lib/ModuleGraph.js +90 -21
  18. package/lib/NodeStuffInWebError.js +34 -0
  19. package/lib/NodeStuffPlugin.js +59 -16
  20. package/lib/NormalModuleFactory.js +8 -43
  21. package/lib/SourceMapDevToolPlugin.js +7 -3
  22. package/lib/WebpackOptionsApply.js +19 -1
  23. package/lib/cache/PackFileCacheStrategy.js +11 -1
  24. package/lib/cache/getLazyHashedEtag.js +35 -8
  25. package/lib/config/defaults.js +32 -12
  26. package/lib/dependencies/CachedConstDependency.js +4 -3
  27. package/lib/dependencies/CommonJsExportRequireDependency.js +19 -9
  28. package/lib/dependencies/CommonJsFullRequireDependency.js +11 -9
  29. package/lib/dependencies/ConstDependency.js +12 -4
  30. package/lib/dependencies/ContextDependency.js +8 -0
  31. package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +179 -163
  32. package/lib/dependencies/HarmonyImportDependency.js +4 -1
  33. package/lib/dependencies/JsonExportsDependency.js +7 -1
  34. package/lib/dependencies/ModuleDecoratorDependency.js +5 -2
  35. package/lib/dependencies/ModuleDependency.js +8 -0
  36. package/lib/dependencies/NullDependency.js +8 -4
  37. package/lib/dependencies/ProvidedDependency.js +6 -2
  38. package/lib/dependencies/PureExpressionDependency.js +5 -1
  39. package/lib/dependencies/RuntimeRequirementsDependency.js +5 -1
  40. package/lib/dependencies/WebAssemblyExportImportedDependency.js +9 -0
  41. package/lib/ids/IdHelpers.js +21 -8
  42. package/lib/ids/NamedChunkIdsPlugin.js +3 -0
  43. package/lib/ids/NamedModuleIdsPlugin.js +3 -1
  44. package/lib/index.js +6 -0
  45. package/lib/javascript/BasicEvaluatedExpression.js +3 -0
  46. package/lib/javascript/JavascriptParser.js +22 -4
  47. package/lib/javascript/JavascriptParserHelpers.js +0 -2
  48. package/lib/node/NodeTargetPlugin.js +1 -0
  49. package/lib/optimize/ConcatenatedModule.js +25 -4
  50. package/lib/optimize/InnerGraph.js +22 -2
  51. package/lib/optimize/ModuleConcatenationPlugin.js +2 -1
  52. package/lib/schemes/HttpUriPlugin.js +1 -2
  53. package/lib/serialization/BinaryMiddleware.js +11 -2
  54. package/lib/serialization/FileMiddleware.js +24 -7
  55. package/lib/serialization/ObjectMiddleware.js +19 -8
  56. package/lib/util/WeakTupleMap.js +95 -92
  57. package/lib/util/createHash.js +10 -0
  58. package/lib/util/hash/BatchedHash.js +65 -0
  59. package/lib/util/hash/xxhash64.js +154 -0
  60. package/lib/util/internalSerializables.js +1 -0
  61. package/lib/util/serialization.js +4 -4
  62. package/package.json +11 -7
  63. package/schemas/WebpackOptions.check.js +1 -1
  64. package/schemas/WebpackOptions.json +19 -3
  65. package/schemas/plugins/HashedModuleIdsPlugin.check.js +1 -1
  66. package/schemas/plugins/HashedModuleIdsPlugin.json +20 -2
  67. package/schemas/plugins/IgnorePlugin.check.js +1 -1
  68. package/schemas/plugins/IgnorePlugin.json +4 -2
  69. package/types.d.ts +215 -25
@@ -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("md4");
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
 
@@ -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 {Map<Dependency, ModuleGraphConnection>} */
88
- this._dependencyMap = new Map();
89
+ /** @type {WeakMap<Dependency, ModuleGraphConnection>} */
90
+ this._dependencyMap = new WeakMap();
89
91
  /** @type {Map<Module, ModuleGraphModule>} */
90
92
  this._moduleMap = new Map();
91
- /** @type {Map<Module, Set<ModuleGraphConnection>>} */
92
- this._originMap = new Map();
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
- const mgm = this._getModuleGraphModule(originModule);
175
- if (mgm.outgoingConnections === undefined) {
176
- mgm.outgoingConnections = new Set();
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._dependencyMap.get(dependency);
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._dependencyMap.get(dependency);
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.delete(dependency);
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._dependencyMap.get(dependency);
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._dependencyMap.get(dependency);
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
- return connection;
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._dependencyMap.get(dependency);
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._dependencyMap.get(dependency);
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._dependencyMap.get(dependency);
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
- freeze() {
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
@@ -0,0 +1,34 @@
1
+ /*
2
+ MIT License http://www.opensource.org/licenses/mit-license.php
3
+ Author Ivan Kopeykin @vankop
4
+ */
5
+
6
+ "use strict";
7
+
8
+ const WebpackError = require("./WebpackError");
9
+ const makeSerializable = require("./util/makeSerializable");
10
+
11
+ /** @typedef {import("./Dependency").DependencyLocation} DependencyLocation */
12
+
13
+ class NodeStuffInWebError extends WebpackError {
14
+ /**
15
+ * @param {DependencyLocation} loc loc
16
+ * @param {string} expression expression
17
+ * @param {string} description description
18
+ */
19
+ constructor(loc, expression, description) {
20
+ super(
21
+ `${JSON.stringify(
22
+ expression
23
+ )} has been used, it will be undefined in next major version.
24
+ ${description}`
25
+ );
26
+
27
+ this.name = "NodeStuffInWebError";
28
+ this.loc = loc;
29
+ }
30
+ }
31
+
32
+ makeSerializable(NodeStuffInWebError, "webpack/lib/NodeStuffInWebError");
33
+
34
+ module.exports = NodeStuffInWebError;
@@ -5,6 +5,7 @@
5
5
 
6
6
  "use strict";
7
7
 
8
+ const NodeStuffInWebError = require("./NodeStuffInWebError");
8
9
  const RuntimeGlobals = require("./RuntimeGlobals");
9
10
  const CachedConstDependency = require("./dependencies/CachedConstDependency");
10
11
  const ConstDependency = require("./dependencies/ConstDependency");
@@ -44,7 +45,8 @@ class NodeStuffPlugin {
44
45
  localOptions = { ...localOptions, ...parserOptions.node };
45
46
  }
46
47
 
47
- if (localOptions.global) {
48
+ if (localOptions.global !== false) {
49
+ const withWarning = localOptions.global === "warn";
48
50
  parser.hooks.expression
49
51
  .for("global")
50
52
  .tap("NodeStuffPlugin", expr => {
@@ -55,10 +57,21 @@ class NodeStuffPlugin {
55
57
  );
56
58
  dep.loc = expr.loc;
57
59
  parser.state.module.addPresentationalDependency(dep);
60
+
61
+ // TODO webpack 6 remove
62
+ if (withWarning) {
63
+ parser.state.module.addWarning(
64
+ new NodeStuffInWebError(
65
+ dep.loc,
66
+ "global",
67
+ "The global namespace object is Node.js feature and doesn't present in browser."
68
+ )
69
+ );
70
+ }
58
71
  });
59
72
  }
60
73
 
61
- const setModuleConstant = (expressionName, fn) => {
74
+ const setModuleConstant = (expressionName, fn, warning) => {
62
75
  parser.hooks.expression
63
76
  .for(expressionName)
64
77
  .tap("NodeStuffPlugin", expr => {
@@ -69,22 +82,41 @@ class NodeStuffPlugin {
69
82
  );
70
83
  dep.loc = expr.loc;
71
84
  parser.state.module.addPresentationalDependency(dep);
85
+
86
+ // TODO webpack 6 remove
87
+ if (warning) {
88
+ parser.state.module.addWarning(
89
+ new NodeStuffInWebError(dep.loc, expressionName, warning)
90
+ );
91
+ }
92
+
72
93
  return true;
73
94
  });
74
95
  };
75
96
 
76
- const setConstant = (expressionName, value) =>
77
- setModuleConstant(expressionName, () => value);
97
+ const setConstant = (expressionName, value, warning) =>
98
+ setModuleConstant(expressionName, () => value, warning);
78
99
 
79
100
  const context = compiler.context;
80
101
  if (localOptions.__filename) {
81
- if (localOptions.__filename === "mock") {
82
- setConstant("__filename", "/index.js");
83
- } else if (localOptions.__filename === true) {
84
- setModuleConstant("__filename", module =>
85
- relative(compiler.inputFileSystem, context, module.resource)
86
- );
102
+ switch (localOptions.__filename) {
103
+ case "mock":
104
+ setConstant("__filename", "/index.js");
105
+ break;
106
+ case "warn-mock":
107
+ setConstant(
108
+ "__filename",
109
+ "/index.js",
110
+ "The __filename is Node.js feature and doesn't present in browser."
111
+ );
112
+ break;
113
+ case true:
114
+ setModuleConstant("__filename", module =>
115
+ relative(compiler.inputFileSystem, context, module.resource)
116
+ );
117
+ break;
87
118
  }
119
+
88
120
  parser.hooks.evaluateIdentifier
89
121
  .for("__filename")
90
122
  .tap("NodeStuffPlugin", expr => {
@@ -94,13 +126,24 @@ class NodeStuffPlugin {
94
126
  });
95
127
  }
96
128
  if (localOptions.__dirname) {
97
- if (localOptions.__dirname === "mock") {
98
- setConstant("__dirname", "/");
99
- } else if (localOptions.__dirname === true) {
100
- setModuleConstant("__dirname", module =>
101
- relative(compiler.inputFileSystem, context, module.context)
102
- );
129
+ switch (localOptions.__dirname) {
130
+ case "mock":
131
+ setConstant("__dirname", "/");
132
+ break;
133
+ case "warn-mock":
134
+ setConstant(
135
+ "__dirname",
136
+ "/",
137
+ "The __dirname is Node.js feature and doesn't present in browser."
138
+ );
139
+ break;
140
+ case true:
141
+ setModuleConstant("__dirname", module =>
142
+ relative(compiler.inputFileSystem, context, module.context)
143
+ );
144
+ break;
103
145
  }
146
+
104
147
  parser.hooks.evaluateIdentifier
105
148
  .for("__dirname")
106
149
  .tap("NodeStuffPlugin", expr => {
@@ -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("md4").update(sourceMapString).digest("hex")
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().apply(compiler);
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");
@@ -118,6 +118,14 @@ class Pack {
118
118
  this.requests.push(undefined);
119
119
  this.requestsTimeout = undefined;
120
120
  }, MAX_TIME_IN_FRESH_PACK);
121
+ if (this.requestsTimeout.unref) this.requestsTimeout.unref();
122
+ }
123
+ }
124
+
125
+ stopCapturingRequests() {
126
+ if (this.requestsTimeout !== undefined) {
127
+ clearTimeout(this.requestsTimeout);
128
+ this.requestsTimeout = undefined;
121
129
  }
122
130
  }
123
131
 
@@ -987,7 +995,8 @@ class PackFileCacheStrategy {
987
995
  this.fileSystemInfo = new FileSystemInfo(fs, {
988
996
  managedPaths: snapshot.managedPaths,
989
997
  immutablePaths: snapshot.immutablePaths,
990
- logger: logger.getChildLogger("webpack.FileSystemInfo")
998
+ logger: logger.getChildLogger("webpack.FileSystemInfo"),
999
+ hashFunction: compiler.options.output.hashFunction
991
1000
  });
992
1001
  this.compiler = compiler;
993
1002
  this.context = context;
@@ -1232,6 +1241,7 @@ class PackFileCacheStrategy {
1232
1241
  const reportProgress = ProgressPlugin.getReporter(this.compiler);
1233
1242
  return (this.storePromise = packPromise
1234
1243
  .then(pack => {
1244
+ pack.stopCapturingRequests();
1235
1245
  if (!pack.invalid) return;
1236
1246
  this.packPromise = undefined;
1237
1247
  this.logger.log(`Storing pack...`);