webpack 5.17.0 → 5.18.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/Module.js CHANGED
@@ -67,6 +67,7 @@ const makeSerializable = require("./util/makeSerializable");
67
67
  * @property {Map<string, Source>} sources the resulting sources for all source types
68
68
  * @property {Map<string, any>=} data the resulting data for all source types
69
69
  * @property {ReadonlySet<string>} runtimeRequirements the runtime requirements
70
+ * @property {string=} hash a hash of the code generation result (will be automatically calculated from sources and runtimeRequirements if not provided)
70
71
  */
71
72
 
72
73
  /**
@@ -703,9 +704,7 @@ class Module extends DependenciesBlock {
703
704
  }
704
705
  ) {
705
706
  const { chunkGraph, runtime } = context;
706
- hash.update(`${chunkGraph.getModuleId(this)}`);
707
- const exportsInfo = chunkGraph.moduleGraph.getExportsInfo(this);
708
- exportsInfo.updateHash(hash, runtime);
707
+ hash.update(chunkGraph.getModuleGraphHash(this, runtime));
709
708
  if (this.presentationalDependencies !== undefined) {
710
709
  for (const dep of this.presentationalDependencies) {
711
710
  dep.updateHash(hash, context);
package/lib/Template.js CHANGED
@@ -349,34 +349,43 @@ class Template {
349
349
 
350
350
  /**
351
351
  * @param {RuntimeModule[]} runtimeModules array of runtime modules in order
352
- * @param {RenderContext} renderContext render context
352
+ * @param {RenderContext & { codeGenerationResults?: CodeGenerationResults }} renderContext render context
353
353
  * @returns {Source} rendered runtime modules in a Source object
354
354
  */
355
355
  static renderRuntimeModules(runtimeModules, renderContext) {
356
356
  const source = new ConcatSource();
357
357
  for (const module of runtimeModules) {
358
- const codeGenResult = module.codeGeneration({
359
- chunkGraph: renderContext.chunkGraph,
360
- dependencyTemplates: renderContext.dependencyTemplates,
361
- moduleGraph: renderContext.moduleGraph,
362
- runtimeTemplate: renderContext.runtimeTemplate,
363
- runtime: renderContext.chunk.runtime
364
- });
365
- if (codeGenResult) {
366
- const moduleSource = codeGenResult.sources.get("runtime");
367
- if (moduleSource) {
368
- source.add(Template.toNormalComment(module.identifier()) + "\n");
369
- if (!module.shouldIsolate()) {
370
- source.add(moduleSource);
371
- } else if (renderContext.runtimeTemplate.supportsArrowFunction()) {
372
- source.add("(() => {\n");
373
- source.add(new PrefixSource("\t", moduleSource));
374
- source.add("\n})();\n\n");
375
- } else {
376
- source.add("!function() {\n");
377
- source.add(new PrefixSource("\t", moduleSource));
378
- source.add("\n}();\n\n");
379
- }
358
+ const codeGenerationResults = renderContext.codeGenerationResults;
359
+ let runtimeSource;
360
+ if (codeGenerationResults) {
361
+ runtimeSource = codeGenerationResults.getSource(
362
+ module,
363
+ renderContext.chunk.runtime,
364
+ "runtime"
365
+ );
366
+ } else {
367
+ const codeGenResult = module.codeGeneration({
368
+ chunkGraph: renderContext.chunkGraph,
369
+ dependencyTemplates: renderContext.dependencyTemplates,
370
+ moduleGraph: renderContext.moduleGraph,
371
+ runtimeTemplate: renderContext.runtimeTemplate,
372
+ runtime: renderContext.chunk.runtime
373
+ });
374
+ if (!codeGenResult) continue;
375
+ runtimeSource = codeGenResult.sources.get("runtime");
376
+ }
377
+ if (runtimeSource) {
378
+ source.add(Template.toNormalComment(module.identifier()) + "\n");
379
+ if (!module.shouldIsolate()) {
380
+ source.add(runtimeSource);
381
+ } else if (renderContext.runtimeTemplate.supportsArrowFunction()) {
382
+ source.add("(() => {\n");
383
+ source.add(new PrefixSource("\t", runtimeSource));
384
+ source.add("\n})();\n\n");
385
+ } else {
386
+ source.add("!function() {\n");
387
+ source.add(new PrefixSource("\t", runtimeSource));
388
+ source.add("\n}();\n\n");
380
389
  }
381
390
  }
382
391
  }
@@ -83,26 +83,6 @@ class ExportsInfoDependency extends NullDependency {
83
83
  this.property = property;
84
84
  }
85
85
 
86
- /**
87
- * Update the hash
88
- * @param {Hash} hash hash to be updated
89
- * @param {UpdateHashContext} context context
90
- * @returns {void}
91
- */
92
- updateHash(hash, context) {
93
- const { chunkGraph, runtime } = context;
94
- const { moduleGraph } = chunkGraph;
95
- const module = moduleGraph.getParentModule(this);
96
- const value = getProperty(
97
- moduleGraph,
98
- module,
99
- this.exportName,
100
- this.property,
101
- runtime
102
- );
103
- hash.update(value === undefined ? "undefined" : JSON.stringify(value));
104
- }
105
-
106
86
  serialize(context) {
107
87
  const { write } = context;
108
88
  write(this.range);
@@ -680,35 +680,6 @@ class HarmonyExportImportedSpecifierDependency extends HarmonyImportDependency {
680
680
  return errors;
681
681
  }
682
682
 
683
- /**
684
- * Update the hash
685
- * @param {Hash} hash hash to be updated
686
- * @param {UpdateHashContext} context context
687
- * @returns {void}
688
- */
689
- updateHash(hash, context) {
690
- const { chunkGraph, runtime } = context;
691
- super.updateHash(hash, context);
692
-
693
- const mode = this.getMode(chunkGraph.moduleGraph, runtime);
694
-
695
- hash.update(mode.type);
696
- if (mode.items) {
697
- for (const item of mode.items) {
698
- hash.update(item.name);
699
- hash.update(item.ids.join());
700
- if (item.checked) hash.update("checked");
701
- }
702
- }
703
- if (mode.ignored) {
704
- hash.update("ignored");
705
- for (const k of mode.ignored) {
706
- hash.update(k);
707
- }
708
- }
709
- hash.update(mode.name || "");
710
- }
711
-
712
683
  serialize(context) {
713
684
  const { write } = context;
714
685
 
@@ -196,47 +196,6 @@ class HarmonyImportDependency extends ModuleDependency {
196
196
  }
197
197
  }
198
198
 
199
- /**
200
- * Update the hash
201
- * @param {Hash} hash hash to be updated
202
- * @param {UpdateHashContext} context context
203
- * @returns {void}
204
- */
205
- updateHash(hash, context) {
206
- const { chunkGraph, runtime, runtimeTemplate } = context;
207
- const { moduleGraph } = chunkGraph;
208
- super.updateHash(hash, context);
209
- hash.update(`${this.sourceOrder}`);
210
- const connection = moduleGraph.getConnection(this);
211
- if (connection) {
212
- const importedModule = connection.module;
213
- if (importedModule) {
214
- const parentModule = moduleGraph.getParentModule(this);
215
- hash.update(
216
- importedModule.getExportsType(
217
- moduleGraph,
218
- parentModule.buildMeta && parentModule.buildMeta.strictHarmonyModule
219
- )
220
- );
221
- if (moduleGraph.isAsync(importedModule)) hash.update("async");
222
- }
223
- if (runtimeTemplate) {
224
- const runtimeRequirements = new Set();
225
- hash.update(
226
- runtimeTemplate.runtimeConditionExpression({
227
- chunkGraph,
228
- runtimeCondition: filterRuntime(runtime, runtime => {
229
- return connection.isTargetActive(runtime);
230
- }),
231
- runtime,
232
- runtimeRequirements
233
- })
234
- );
235
- for (const rr of runtimeRequirements) hash.update(rr);
236
- }
237
- }
238
- }
239
-
240
199
  serialize(context) {
241
200
  const { write } = context;
242
201
  write(this.sourceOrder);
@@ -181,25 +181,6 @@ class HarmonyImportSpecifierDependency extends HarmonyImportDependency {
181
181
  return 0;
182
182
  }
183
183
 
184
- /**
185
- * Update the hash
186
- * @param {Hash} hash hash to be updated
187
- * @param {UpdateHashContext} context context
188
- * @returns {void}
189
- */
190
- updateHash(hash, context) {
191
- const { chunkGraph, runtime } = context;
192
- super.updateHash(hash, context);
193
- const moduleGraph = chunkGraph.moduleGraph;
194
- const importedModule = moduleGraph.getModule(this);
195
- const ids = this.getIds(moduleGraph);
196
- hash.update(ids.join());
197
- if (importedModule) {
198
- const exportsInfo = moduleGraph.getExportsInfo(importedModule);
199
- hash.update(`${exportsInfo.getUsedName(ids, runtime)}`);
200
- }
201
- }
202
-
203
184
  serialize(context) {
204
185
  const { write } = context;
205
186
  write(this.ids);
@@ -73,7 +73,6 @@ class JsonExportsDependency extends NullDependency {
73
73
  */
74
74
  updateHash(hash, context) {
75
75
  hash.update(this.exports ? JSON.stringify(this.exports) : "undefined");
76
- super.updateHash(hash, context);
77
76
  }
78
77
 
79
78
  serialize(context) {
@@ -69,7 +69,6 @@ class ModuleDecoratorDependency extends NullDependency {
69
69
  * @returns {void}
70
70
  */
71
71
  updateHash(hash, context) {
72
- super.updateHash(hash, context);
73
72
  hash.update(this.decorator);
74
73
  hash.update(`${this.allowExportsAccess}`);
75
74
  }
@@ -20,14 +20,6 @@ class NullDependency extends Dependency {
20
20
  return "null";
21
21
  }
22
22
 
23
- /**
24
- * Update the hash
25
- * @param {Hash} hash hash to be updated
26
- * @param {UpdateHashContext} context context
27
- * @returns {void}
28
- */
29
- updateHash(hash, context) {}
30
-
31
23
  serialize({ write }) {
32
24
  write(this.loc);
33
25
  }
@@ -51,7 +51,6 @@ class ProvidedDependency extends ModuleDependency {
51
51
  * @returns {void}
52
52
  */
53
53
  updateHash(hash, context) {
54
- super.updateHash(hash, context);
55
54
  hash.update(this.identifier);
56
55
  hash.update(this.path ? this.path.join(",") : "null");
57
56
  }
@@ -43,18 +43,6 @@ class StaticExportsDependency extends NullDependency {
43
43
  };
44
44
  }
45
45
 
46
- /**
47
- * Update the hash
48
- * @param {Hash} hash hash to be updated
49
- * @param {UpdateHashContext} context context
50
- * @returns {void}
51
- */
52
- updateHash(hash, context) {
53
- hash.update(JSON.stringify(this.exports));
54
- if (this.canMangle) hash.update("canMangle");
55
- super.updateHash(hash, context);
56
- }
57
-
58
46
  serialize(context) {
59
47
  const { write } = context;
60
48
  write(this.exports);
@@ -1650,18 +1650,6 @@ ${defineGetters}`
1650
1650
  }
1651
1651
  }
1652
1652
 
1653
- /**
1654
- * @param {ChunkGraph} chunkGraph the chunk graph
1655
- * @param {DependencyTemplates} dependencyTemplates dependency templates
1656
- * @param {RuntimeSpec} runtime the runtime
1657
- * @returns {string} hash
1658
- */
1659
- _getHashDigest(chunkGraph, dependencyTemplates, runtime) {
1660
- const hash = chunkGraph.getModuleHash(this, runtime);
1661
- const dtHash = dependencyTemplates.getHash();
1662
- return `${hash}-${dtHash}`;
1663
- }
1664
-
1665
1653
  /**
1666
1654
  * @param {ModuleGraph} moduleGraph the module graph
1667
1655
  * @param {RuntimeSpec} runtime the runtime
@@ -48,6 +48,7 @@ const NAMED_PRESETS = {
48
48
  runtimeModules: true,
49
49
  exclude: false,
50
50
  modulesSpace: Infinity,
51
+ chunkModulesSpace: Infinity,
51
52
  assetsSpace: Infinity,
52
53
  children: true
53
54
  },
@@ -0,0 +1,22 @@
1
+ /*
2
+ MIT License http://www.opensource.org/licenses/mit-license.php
3
+ Author Tobias Koppers @sokra
4
+ */
5
+
6
+ "use strict";
7
+
8
+ /**
9
+ * @template K
10
+ * @template V
11
+ * @param {Map<K, V>} map a map
12
+ * @param {K} key the key
13
+ * @param {function(): V} computer compute value
14
+ * @returns {V} value
15
+ */
16
+ exports.provide = (map, key, computer) => {
17
+ const value = map.get(key);
18
+ if (value !== undefined) return value;
19
+ const newValue = computer();
20
+ map.set(key, newValue);
21
+ return newValue;
22
+ };
@@ -7,9 +7,11 @@
7
7
 
8
8
  const Hash = require("./Hash");
9
9
 
10
- const BULK_SIZE = 1000;
10
+ const BULK_SIZE = 2000;
11
11
 
12
- const digestCache = new Map();
12
+ // We are using an object instead of a Map as this will stay static during the runtime
13
+ // so access to it can be optimized by v8
14
+ const digestCaches = {};
13
15
 
14
16
  class BulkUpdateDecorator extends Hash {
15
17
  /**
@@ -64,11 +66,15 @@ class BulkUpdateDecorator extends Hash {
64
66
  * @returns {string|Buffer} digest
65
67
  */
66
68
  digest(encoding) {
67
- let cacheKey;
69
+ let digestCache;
68
70
  if (this.hash === undefined) {
69
71
  // short data for hash, we can use caching
70
- cacheKey = `${this.hashKey}-${encoding}-${this.buffer}`;
71
- const cacheEntry = digestCache.get(cacheKey);
72
+ const cacheKey = `${this.hashKey}-${encoding}`;
73
+ digestCache = digestCaches[cacheKey];
74
+ if (digestCache === undefined) {
75
+ digestCache = digestCaches[cacheKey] = new Map();
76
+ }
77
+ const cacheEntry = digestCache.get(this.buffer);
72
78
  if (cacheEntry !== undefined) return cacheEntry;
73
79
  this.hash = this.hashFactory();
74
80
  }
@@ -78,8 +84,8 @@ class BulkUpdateDecorator extends Hash {
78
84
  const digestResult = this.hash.digest(encoding);
79
85
  const result =
80
86
  typeof digestResult === "string" ? digestResult : digestResult.toString();
81
- if (cacheKey !== undefined) {
82
- digestCache.set(cacheKey, result);
87
+ if (digestCache !== undefined) {
88
+ digestCache.set(this.buffer, result);
83
89
  }
84
90
  return result;
85
91
  }
@@ -54,14 +54,16 @@ exports.getEntryRuntime = (compilation, name, options) => {
54
54
  /**
55
55
  * @param {RuntimeSpec} runtime runtime
56
56
  * @param {function(string): void} fn functor
57
+ * @param {boolean} deterministicOrder enforce a deterministic order
57
58
  * @returns {void}
58
59
  */
59
- exports.forEachRuntime = (runtime, fn) => {
60
+ exports.forEachRuntime = (runtime, fn, deterministicOrder = false) => {
60
61
  if (runtime === undefined) {
61
62
  fn(undefined);
62
63
  } else if (typeof runtime === "string") {
63
64
  fn(runtime);
64
65
  } else {
66
+ if (deterministicOrder) runtime.sort();
65
67
  for (const r of runtime) {
66
68
  fn(r);
67
69
  }
@@ -448,6 +450,15 @@ class RuntimeSpecMap {
448
450
  this._map.set(getRuntimeKey(runtime), value);
449
451
  }
450
452
 
453
+ provide(runtime, computer) {
454
+ const key = getRuntimeKey(runtime);
455
+ const value = this._map.get(key);
456
+ if (value !== undefined) return value;
457
+ const newValue = computer();
458
+ this._map.set(key, newValue);
459
+ return newValue;
460
+ }
461
+
451
462
  delete(runtime) {
452
463
  this._map.delete(getRuntimeKey(runtime));
453
464
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "webpack",
3
- "version": "5.17.0",
3
+ "version": "5.18.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
@@ -799,6 +799,9 @@ declare class ChunkGraph {
799
799
  getChunkFullHashModulesIterable(
800
800
  chunk: Chunk
801
801
  ): undefined | Iterable<RuntimeModule>;
802
+ getChunkFullHashModulesSet(
803
+ chunk: Chunk
804
+ ): undefined | ReadonlySet<RuntimeModule>;
802
805
  getChunkEntryModulesWithChunkGroupIterable(
803
806
  chunk: Chunk
804
807
  ): Iterable<[Module, undefined | Entrypoint]>;
@@ -833,6 +836,11 @@ declare class ChunkGraph {
833
836
  runtime: RuntimeSpec
834
837
  ): ReadonlySet<string>;
835
838
  getChunkRuntimeRequirements(chunk: Chunk): ReadonlySet<string>;
839
+ getModuleGraphHash(
840
+ module?: any,
841
+ runtime?: any,
842
+ withConnections?: boolean
843
+ ): any;
836
844
  getTreeRuntimeRequirements(chunk: Chunk): ReadonlySet<string>;
837
845
  static getChunkGraphForModule(
838
846
  module: Module,
@@ -1063,16 +1071,24 @@ declare interface CodeGenerationResult {
1063
1071
  * the runtime requirements
1064
1072
  */
1065
1073
  runtimeRequirements: ReadonlySet<string>;
1074
+
1075
+ /**
1076
+ * a hash of the code generation result (will be automatically calculated from sources and runtimeRequirements if not provided)
1077
+ */
1078
+ hash?: string;
1066
1079
  }
1067
1080
  declare abstract class CodeGenerationResults {
1068
1081
  map: Map<Module, RuntimeSpecMap<CodeGenerationResult>>;
1082
+ hashes: Map<Module, RuntimeSpecMap<string>>;
1069
1083
  get(module: Module, runtime: RuntimeSpec): CodeGenerationResult;
1084
+ has(module: Module, runtime: RuntimeSpec): boolean;
1070
1085
  getSource(module: Module, runtime: RuntimeSpec, sourceType: string): Source;
1071
1086
  getRuntimeRequirements(
1072
1087
  module: Module,
1073
1088
  runtime: RuntimeSpec
1074
1089
  ): ReadonlySet<string>;
1075
1090
  getData(module: Module, runtime: RuntimeSpec, key: string): any;
1091
+ getHash(module: Module, runtime: RuntimeSpec): any;
1076
1092
  add(module: Module, runtime: RuntimeSpec, result: CodeGenerationResult): void;
1077
1093
  }
1078
1094
  type CodeValue =
@@ -1437,7 +1453,12 @@ declare class Compilation {
1437
1453
  sortItemsWithChunkIds(): void;
1438
1454
  summarizeDependencies(): void;
1439
1455
  createModuleHashes(): void;
1440
- createHash(): void;
1456
+ createHash(): {
1457
+ module: Module;
1458
+ hash: string;
1459
+ runtime: RuntimeSpec;
1460
+ runtimes: RuntimeSpec[];
1461
+ }[];
1441
1462
  fullHash?: string;
1442
1463
  hash?: string;
1443
1464
  emitAsset(file: string, source: Source, assetInfo?: AssetInfo): void;
@@ -8728,6 +8749,7 @@ declare abstract class RuntimeSpecMap<T> {
8728
8749
  get(runtime: RuntimeSpec): T;
8729
8750
  has(runtime: RuntimeSpec): boolean;
8730
8751
  set(runtime?: any, value?: any): void;
8752
+ provide(runtime?: any, computer?: any): any;
8731
8753
  delete(runtime?: any): void;
8732
8754
  update(runtime?: any, fn?: any): void;
8733
8755
  keys(): RuntimeSpec[];
@@ -10117,7 +10139,9 @@ declare class Template {
10117
10139
  ): Source;
10118
10140
  static renderRuntimeModules(
10119
10141
  runtimeModules: RuntimeModule[],
10120
- renderContext: RenderContextModuleTemplate
10142
+ renderContext: RenderContextModuleTemplate & {
10143
+ codeGenerationResults?: CodeGenerationResults;
10144
+ }
10121
10145
  ): Source;
10122
10146
  static renderChunkRuntimeModules(
10123
10147
  runtimeModules: RuntimeModule[],