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
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);
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":