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.

Files changed (64) 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/DefinePlugin.js +13 -8
  8. package/lib/Dependency.js +11 -0
  9. package/lib/DependencyTemplates.js +8 -2
  10. package/lib/EvalDevToolModulePlugin.js +2 -1
  11. package/lib/EvalSourceMapDevToolPlugin.js +2 -1
  12. package/lib/ExternalModule.js +18 -9
  13. package/lib/FileSystemInfo.js +101 -170
  14. package/lib/FlagDependencyExportsPlugin.js +25 -16
  15. package/lib/JavascriptMetaInfoPlugin.js +6 -1
  16. package/lib/ModuleFactory.js +1 -0
  17. package/lib/ModuleFilenameHelpers.js +21 -7
  18. package/lib/ModuleGraph.js +90 -21
  19. package/lib/NormalModuleFactory.js +8 -43
  20. package/lib/SourceMapDevToolPlugin.js +7 -3
  21. package/lib/WebpackOptionsApply.js +19 -1
  22. package/lib/cache/PackFileCacheStrategy.js +2 -1
  23. package/lib/cache/getLazyHashedEtag.js +35 -8
  24. package/lib/config/defaults.js +18 -7
  25. package/lib/dependencies/CachedConstDependency.js +4 -3
  26. package/lib/dependencies/CommonJsExportRequireDependency.js +19 -9
  27. package/lib/dependencies/CommonJsFullRequireDependency.js +11 -9
  28. package/lib/dependencies/ConstDependency.js +12 -4
  29. package/lib/dependencies/ContextDependency.js +8 -0
  30. package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +179 -163
  31. package/lib/dependencies/HarmonyImportDependency.js +4 -1
  32. package/lib/dependencies/JsonExportsDependency.js +7 -1
  33. package/lib/dependencies/ModuleDecoratorDependency.js +5 -2
  34. package/lib/dependencies/ModuleDependency.js +8 -0
  35. package/lib/dependencies/NullDependency.js +8 -4
  36. package/lib/dependencies/ProvidedDependency.js +6 -2
  37. package/lib/dependencies/PureExpressionDependency.js +5 -1
  38. package/lib/dependencies/RuntimeRequirementsDependency.js +5 -1
  39. package/lib/dependencies/WebAssemblyExportImportedDependency.js +9 -0
  40. package/lib/ids/IdHelpers.js +21 -8
  41. package/lib/ids/NamedChunkIdsPlugin.js +3 -0
  42. package/lib/ids/NamedModuleIdsPlugin.js +3 -1
  43. package/lib/index.js +6 -0
  44. package/lib/javascript/BasicEvaluatedExpression.js +3 -0
  45. package/lib/javascript/JavascriptParser.js +22 -4
  46. package/lib/javascript/JavascriptParserHelpers.js +0 -2
  47. package/lib/optimize/ConcatenatedModule.js +25 -4
  48. package/lib/optimize/InnerGraph.js +22 -2
  49. package/lib/optimize/ModuleConcatenationPlugin.js +2 -1
  50. package/lib/schemes/HttpUriPlugin.js +1 -2
  51. package/lib/serialization/BinaryMiddleware.js +11 -2
  52. package/lib/serialization/FileMiddleware.js +24 -7
  53. package/lib/serialization/ObjectMiddleware.js +19 -8
  54. package/lib/util/WeakTupleMap.js +95 -92
  55. package/lib/util/createHash.js +10 -0
  56. package/lib/util/hash/BatchedHash.js +65 -0
  57. package/lib/util/hash/xxhash64.js +154 -0
  58. package/lib/util/serialization.js +4 -4
  59. package/package.json +10 -6
  60. package/schemas/WebpackOptions.check.js +1 -1
  61. package/schemas/WebpackOptions.json +12 -0
  62. package/schemas/plugins/HashedModuleIdsPlugin.check.js +1 -1
  63. package/schemas/plugins/HashedModuleIdsPlugin.json +20 -2
  64. package/types.d.ts +205 -20
package/lib/Compiler.js CHANGED
@@ -40,8 +40,10 @@ const { isSourceEqual } = require("./util/source");
40
40
  /** @typedef {import("../declarations/WebpackOptions").WebpackOptionsNormalized} WebpackOptions */
41
41
  /** @typedef {import("../declarations/WebpackOptions").WebpackPluginInstance} WebpackPluginInstance */
42
42
  /** @typedef {import("./Chunk")} Chunk */
43
+ /** @typedef {import("./Dependency")} Dependency */
43
44
  /** @typedef {import("./FileSystemInfo").FileSystemInfoEntry} FileSystemInfoEntry */
44
45
  /** @typedef {import("./Module")} Module */
46
+ /** @typedef {import("./util/WeakTupleMap")} WeakTupleMap */
45
47
  /** @typedef {import("./util/fs").InputFileSystem} InputFileSystem */
46
48
  /** @typedef {import("./util/fs").IntermediateFileSystem} IntermediateFileSystem */
47
49
  /** @typedef {import("./util/fs").OutputFileSystem} OutputFileSystem */
@@ -247,6 +249,9 @@ class Compiler {
247
249
 
248
250
  this.cache = new Cache();
249
251
 
252
+ /** @type {WeakMap<Module, { hash: string, references: WeakMap<Dependency, Module>, memCache: WeakTupleMap }> | undefined} */
253
+ this.moduleMemCaches = undefined;
254
+
250
255
  this.compilerPath = "";
251
256
 
252
257
  /** @type {boolean} */
@@ -276,7 +281,11 @@ class Compiler {
276
281
  * @returns {CacheFacade} the cache facade instance
277
282
  */
278
283
  getCache(name) {
279
- return new CacheFacade(this.cache, `${this.compilerPath}${name}`);
284
+ return new CacheFacade(
285
+ this.cache,
286
+ `${this.compilerPath}${name}`,
287
+ this.options.output.hashFunction
288
+ );
280
289
  }
281
290
 
282
291
  /**
@@ -1027,9 +1036,9 @@ ${other}`);
1027
1036
  return !!this.parentCompilation;
1028
1037
  }
1029
1038
 
1030
- createCompilation() {
1039
+ createCompilation(params) {
1031
1040
  this._cleanupLastCompilation();
1032
- return (this._lastCompilation = new Compilation(this));
1041
+ return (this._lastCompilation = new Compilation(this, params));
1033
1042
  }
1034
1043
 
1035
1044
  /**
@@ -1037,7 +1046,7 @@ ${other}`);
1037
1046
  * @returns {Compilation} the created compilation
1038
1047
  */
1039
1048
  newCompilation(params) {
1040
- const compilation = this.createCompilation();
1049
+ const compilation = this.createCompilation(params);
1041
1050
  compilation.name = this.name;
1042
1051
  compilation.records = this.records;
1043
1052
  this.hooks.thisCompilation.call(compilation, params);
@@ -13,7 +13,7 @@ const {
13
13
  evaluateToString,
14
14
  toConstantDependency
15
15
  } = require("./javascript/JavascriptParserHelpers");
16
- const { provide } = require("./util/MapHelpers");
16
+ const createHash = require("./util/createHash");
17
17
 
18
18
  /** @typedef {import("estree").Expression} Expression */
19
19
  /** @typedef {import("./Compiler")} Compiler */
@@ -286,12 +286,11 @@ class DefinePlugin {
286
286
  );
287
287
  const { runtimeTemplate } = compilation;
288
288
 
289
- const mainValue = /** @type {Set<string>} */ (
290
- provide(
291
- compilation.valueCacheVersions,
292
- VALUE_DEP_MAIN,
293
- () => new Set()
294
- )
289
+ const mainHash = createHash(compilation.outputOptions.hashFunction);
290
+ mainHash.update(
291
+ /** @type {string} */ (
292
+ compilation.valueCacheVersions.get(VALUE_DEP_MAIN)
293
+ ) || ""
295
294
  );
296
295
 
297
296
  /**
@@ -300,6 +299,7 @@ class DefinePlugin {
300
299
  * @returns {void}
301
300
  */
302
301
  const handler = parser => {
302
+ const mainValue = compilation.valueCacheVersions.get(VALUE_DEP_MAIN);
303
303
  parser.hooks.program.tap("DefinePlugin", () => {
304
304
  const { buildInfo } = parser.state.module;
305
305
  if (!buildInfo.valueDependencies)
@@ -565,7 +565,7 @@ class DefinePlugin {
565
565
  const code = definitions[key];
566
566
  const version = toCacheVersion(code);
567
567
  const name = VALUE_DEP_PREFIX + prefix + key;
568
- mainValue.add(name);
568
+ mainHash.update("|" + prefix + key);
569
569
  const oldVersion = compilation.valueCacheVersions.get(name);
570
570
  if (oldVersion === undefined) {
571
571
  compilation.valueCacheVersions.set(name, version);
@@ -589,6 +589,11 @@ class DefinePlugin {
589
589
  };
590
590
 
591
591
  walkDefinitionsForValues(definitions, "");
592
+
593
+ compilation.valueCacheVersions.set(
594
+ VALUE_DEP_MAIN,
595
+ /** @type {string} */ (mainHash.digest("hex").slice(0, 8))
596
+ );
592
597
  }
593
598
  );
594
599
  }
package/lib/Dependency.js CHANGED
@@ -78,6 +78,8 @@ const memoize = require("./util/memoize");
78
78
  * @property {boolean=} canMangle when false, referenced export can not be mangled, defaults to true
79
79
  */
80
80
 
81
+ const TRANSITIVE = Symbol("transitive");
82
+
81
83
  const getIgnoredModule = memoize(() => {
82
84
  const RawModule = require("./RawModule");
83
85
  return new RawModule("/* (ignored) */", `ignored`, `(ignored)`);
@@ -175,6 +177,13 @@ class Dependency {
175
177
  return null;
176
178
  }
177
179
 
180
+ /**
181
+ * @returns {boolean | TRANSITIVE} true, when changes to the referenced module could affect the referencing module; TRANSITIVE, when changes to the referenced module could affect referencing modules of the referencing module
182
+ */
183
+ couldAffectReferencingModule() {
184
+ return TRANSITIVE;
185
+ }
186
+
178
187
  /**
179
188
  * Returns the referenced module and export
180
189
  * @deprecated
@@ -322,4 +331,6 @@ Object.defineProperty(Dependency.prototype, "disconnect", {
322
331
  }
323
332
  });
324
333
 
334
+ Dependency.TRANSITIVE = TRANSITIVE;
335
+
325
336
  module.exports = Dependency;
@@ -9,14 +9,20 @@ const createHash = require("./util/createHash");
9
9
 
10
10
  /** @typedef {import("./Dependency")} Dependency */
11
11
  /** @typedef {import("./DependencyTemplate")} DependencyTemplate */
12
+ /** @typedef {typeof import("./util/Hash")} Hash */
13
+
12
14
  /** @typedef {new (...args: any[]) => Dependency} DependencyConstructor */
13
15
 
14
16
  class DependencyTemplates {
15
- constructor() {
17
+ /**
18
+ * @param {string | Hash} hashFunction the hash function to use
19
+ */
20
+ constructor(hashFunction = "md4") {
16
21
  /** @type {Map<Function, DependencyTemplate>} */
17
22
  this._map = new Map();
18
23
  /** @type {string} */
19
24
  this._hash = "31d6cfe0d16ae931b73c59d7e0c089c0";
25
+ this._hashFunction = hashFunction;
20
26
  }
21
27
 
22
28
  /**
@@ -41,7 +47,7 @@ class DependencyTemplates {
41
47
  * @returns {void}
42
48
  */
43
49
  updateHash(part) {
44
- const hash = createHash("md4");
50
+ const hash = createHash(this._hashFunction);
45
51
  hash.update(this._hash);
46
52
  hash.update(part);
47
53
  this._hash = /** @type {string} */ (hash.digest("hex"));
@@ -61,7 +61,8 @@ class EvalDevToolModulePlugin {
61
61
  },
62
62
  {
63
63
  requestShortener: runtimeTemplate.requestShortener,
64
- chunkGraph
64
+ chunkGraph,
65
+ hashFunction: compilation.outputOptions.hashFunction
65
66
  }
66
67
  );
67
68
  const footer =
@@ -138,7 +138,8 @@ class EvalSourceMapDevToolPlugin {
138
138
  },
139
139
  {
140
140
  requestShortener: runtimeTemplate.requestShortener,
141
- chunkGraph
141
+ chunkGraph,
142
+ hashFunction: compilation.outputOptions.hashFunction
142
143
  }
143
144
  );
144
145
  });
@@ -38,6 +38,7 @@ const { register } = require("./util/serialization");
38
38
  /** @typedef {import("./WebpackError")} WebpackError */
39
39
  /** @typedef {import("./javascript/JavascriptModulesPlugin").ChunkRenderContext} ChunkRenderContext */
40
40
  /** @typedef {import("./util/Hash")} Hash */
41
+ /** @typedef {typeof import("./util/Hash")} HashConstructor */
41
42
  /** @typedef {import("./util/fs").InputFileSystem} InputFileSystem */
42
43
  /** @typedef {import("./util/runtime").RuntimeSpec} RuntimeSpec */
43
44
 
@@ -160,11 +161,16 @@ const getSourceForImportExternal = (moduleAndSpecifiers, runtimeTemplate) => {
160
161
  };
161
162
 
162
163
  class ModuleExternalInitFragment extends InitFragment {
163
- constructor(request, ident) {
164
+ /**
165
+ * @param {string} request import source
166
+ * @param {string=} ident recomputed ident
167
+ * @param {string | HashConstructor=} hashFunction the hash function to use
168
+ */
169
+ constructor(request, ident, hashFunction = "md4") {
164
170
  if (ident === undefined) {
165
171
  ident = Template.toIdentifier(request);
166
172
  if (ident !== request) {
167
- ident += `_${createHash("md4")
173
+ ident += `_${createHash(hashFunction)
168
174
  .update(request)
169
175
  .digest("hex")
170
176
  .slice(0, 8)}`;
@@ -230,21 +236,25 @@ const generateModuleRemapping = (input, exportsInfo, runtime) => {
230
236
  };
231
237
 
232
238
  /**
233
- * @param {string|number} id the module id
234
239
  * @param {string|string[]} moduleAndSpecifiers the module request
235
240
  * @param {ExportsInfo} exportsInfo exports info of this module
236
241
  * @param {RuntimeSpec} runtime the runtime
242
+ * @param {string | HashConstructor=} hashFunction the hash function to use
237
243
  * @returns {SourceData} the generated source
238
244
  */
239
245
  const getSourceForModuleExternal = (
240
- id,
241
246
  moduleAndSpecifiers,
242
247
  exportsInfo,
243
- runtime
248
+ runtime,
249
+ hashFunction
244
250
  ) => {
245
251
  if (!Array.isArray(moduleAndSpecifiers))
246
252
  moduleAndSpecifiers = [moduleAndSpecifiers];
247
- const initFragment = new ModuleExternalInitFragment(moduleAndSpecifiers[0]);
253
+ const initFragment = new ModuleExternalInitFragment(
254
+ moduleAndSpecifiers[0],
255
+ undefined,
256
+ hashFunction
257
+ );
248
258
  const baseAccess = `${initFragment.getNamespaceIdentifier()}${propertyAccess(
249
259
  moduleAndSpecifiers,
250
260
  1
@@ -566,12 +576,11 @@ class ExternalModule extends Module {
566
576
  "The target environment doesn't support EcmaScriptModule syntax so it's not possible to use external type 'module'"
567
577
  );
568
578
  }
569
- const id = chunkGraph.getModuleId(this);
570
579
  return getSourceForModuleExternal(
571
- id !== null ? id : this.identifier(),
572
580
  request,
573
581
  moduleGraph.getExportsInfo(this),
574
- runtime
582
+ runtime,
583
+ runtimeTemplate.outputOptions.hashFunction
575
584
  );
576
585
  }
577
586
  case "var":