webpack 5.51.1 → 5.51.2

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/bin/webpack.js CHANGED
File without changes
package/lib/ChunkGraph.js CHANGED
@@ -205,6 +205,8 @@ class ChunkGraphChunk {
205
205
  this.runtimeModules = new SortableSet();
206
206
  /** @type {Set<RuntimeModule> | undefined} */
207
207
  this.fullHashModules = undefined;
208
+ /** @type {Set<RuntimeModule> | undefined} */
209
+ this.dependentHashModules = undefined;
208
210
  /** @type {Set<string> | undefined} */
209
211
  this.runtimeRequirements = undefined;
210
212
  /** @type {Set<string>} */
@@ -389,6 +391,20 @@ class ChunkGraph {
389
391
  }
390
392
  }
391
393
 
394
+ /**
395
+ * @param {Chunk} chunk the chunk
396
+ * @param {Iterable<RuntimeModule>} modules the modules that require a full hash
397
+ * @returns {void}
398
+ */
399
+ attachDependentHashModules(chunk, modules) {
400
+ const cgc = this._getChunkGraphChunk(chunk);
401
+ if (cgc.dependentHashModules === undefined)
402
+ cgc.dependentHashModules = new Set();
403
+ for (const module of modules) {
404
+ cgc.dependentHashModules.add(module);
405
+ }
406
+ }
407
+
392
408
  /**
393
409
  * @param {Module} oldModule the replaced module
394
410
  * @param {Module} newModule the replacing module
@@ -444,6 +460,17 @@ class ChunkGraph {
444
460
  cgc.fullHashModules.delete(/** @type {RuntimeModule} */ (oldModule));
445
461
  cgc.fullHashModules.add(/** @type {RuntimeModule} */ (newModule));
446
462
  }
463
+ if (
464
+ cgc.dependentHashModules !== undefined &&
465
+ cgc.dependentHashModules.has(/** @type {RuntimeModule} */ (oldModule))
466
+ ) {
467
+ cgc.dependentHashModules.delete(
468
+ /** @type {RuntimeModule} */ (oldModule)
469
+ );
470
+ cgc.dependentHashModules.add(
471
+ /** @type {RuntimeModule} */ (newModule)
472
+ );
473
+ }
447
474
  }
448
475
  oldCgm.runtimeInChunks = undefined;
449
476
  }
@@ -529,13 +556,22 @@ class ChunkGraph {
529
556
 
530
557
  /**
531
558
  * @param {Chunk} chunk the chunk
532
- * @returns {number} the number of module which are contained in this chunk
559
+ * @returns {number} the number of modules which are contained in this chunk
533
560
  */
534
561
  getNumberOfChunkModules(chunk) {
535
562
  const cgc = this._getChunkGraphChunk(chunk);
536
563
  return cgc.modules.size;
537
564
  }
538
565
 
566
+ /**
567
+ * @param {Chunk} chunk the chunk
568
+ * @returns {number} the number of full hash modules which are contained in this chunk
569
+ */
570
+ getNumberOfChunkFullHashModules(chunk) {
571
+ const cgc = this._getChunkGraphChunk(chunk);
572
+ return cgc.fullHashModules === undefined ? 0 : cgc.fullHashModules.size;
573
+ }
574
+
539
575
  /**
540
576
  * @param {Chunk} chunk the chunk
541
577
  * @returns {Iterable<Module>} return the modules for this chunk
@@ -900,6 +936,23 @@ class ChunkGraph {
900
936
  ChunkGraph.clearChunkGraphForChunk(chunkB);
901
937
  }
902
938
 
939
+ /**
940
+ * @param {Chunk} chunk the chunk to upgrade
941
+ * @returns {void}
942
+ */
943
+ upgradeDependentToFullHashModules(chunk) {
944
+ const cgc = this._getChunkGraphChunk(chunk);
945
+ if (cgc.dependentHashModules === undefined) return;
946
+ if (cgc.fullHashModules === undefined) {
947
+ cgc.fullHashModules = cgc.dependentHashModules;
948
+ } else {
949
+ for (const m of cgc.dependentHashModules) {
950
+ cgc.fullHashModules.add(m);
951
+ }
952
+ cgc.dependentHashModules = undefined;
953
+ }
954
+ }
955
+
903
956
  /**
904
957
  * @param {Module} module the checked module
905
958
  * @param {Chunk} chunk the checked chunk
@@ -952,6 +1005,18 @@ class ChunkGraph {
952
1005
  cgc.fullHashModules.add(module);
953
1006
  }
954
1007
 
1008
+ /**
1009
+ * @param {Chunk} chunk the new chunk
1010
+ * @param {RuntimeModule} module the module that require a full hash
1011
+ * @returns {void}
1012
+ */
1013
+ addDependentHashModuleToChunk(chunk, module) {
1014
+ const cgc = this._getChunkGraphChunk(chunk);
1015
+ if (cgc.dependentHashModules === undefined)
1016
+ cgc.dependentHashModules = new Set();
1017
+ cgc.dependentHashModules.add(module);
1018
+ }
1019
+
955
1020
  /**
956
1021
  * @param {Chunk} chunk the new chunk
957
1022
  * @param {Module} module the entry module
@@ -1128,6 +1193,15 @@ class ChunkGraph {
1128
1193
  return cgc.fullHashModules;
1129
1194
  }
1130
1195
 
1196
+ /**
1197
+ * @param {Chunk} chunk the chunk
1198
+ * @returns {Iterable<RuntimeModule> | undefined} iterable of modules (do not modify)
1199
+ */
1200
+ getChunkDependentHashModulesIterable(chunk) {
1201
+ const cgc = this._getChunkGraphChunk(chunk);
1202
+ return cgc.dependentHashModules;
1203
+ }
1204
+
1131
1205
  /** @typedef {[Module, Entrypoint | undefined]} EntryModuleWithChunkGroup */
1132
1206
 
1133
1207
  /**
@@ -2879,6 +2879,8 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
2879
2879
  chunkGraph.connectChunkAndRuntimeModule(chunk, module);
2880
2880
  if (module.fullHash) {
2881
2881
  chunkGraph.addFullHashModuleToChunk(chunk, module);
2882
+ } else if (module.dependentHash) {
2883
+ chunkGraph.addDependentHashModuleToChunk(chunk, module);
2882
2884
  }
2883
2885
 
2884
2886
  // attach runtime module
@@ -3344,8 +3346,13 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
3344
3346
  if (remaining > 0) {
3345
3347
  const readyChunks = [];
3346
3348
  for (const chunk of runtimeChunks) {
3349
+ const hasFullHashModules =
3350
+ chunkGraph.getNumberOfChunkFullHashModules(chunk) !== 0;
3347
3351
  const info = runtimeChunksMap.get(chunk);
3348
3352
  for (const otherInfo of info.referencedBy) {
3353
+ if (hasFullHashModules) {
3354
+ chunkGraph.upgradeDependentToFullHashModules(otherInfo.chunk);
3355
+ }
3349
3356
  remaining--;
3350
3357
  if (--otherInfo.remaining === 0) {
3351
3358
  readyChunks.push(otherInfo.chunk);
package/lib/Compiler.js CHANGED
@@ -1130,6 +1130,13 @@ ${other}`);
1130
1130
  * @returns {void}
1131
1131
  */
1132
1132
  close(callback) {
1133
+ if (this.watching) {
1134
+ // When there is still an active watching, close this first
1135
+ this.watching.close(err => {
1136
+ this.close(callback);
1137
+ });
1138
+ return;
1139
+ }
1133
1140
  this.hooks.shutdown.callAsync(err => {
1134
1141
  if (err) return callback(err);
1135
1142
  // Get rid of reference to last compilation to avoid leaking memory
@@ -1161,9 +1161,10 @@ class FileSystemInfo {
1161
1161
  if (cache !== undefined) {
1162
1162
  const resolved = getResolvedTimestamp(cache);
1163
1163
  if (resolved !== undefined) return callback(null, resolved);
1164
- this._resolveContextTimestamp(cache, callback);
1164
+ return this._resolveContextTimestamp(cache, callback);
1165
1165
  }
1166
1166
  this.contextTimestampQueue.add(path, (err, entry) => {
1167
+ if (err) return callback(err);
1167
1168
  const resolved = getResolvedTimestamp(entry);
1168
1169
  if (resolved !== undefined) return callback(null, resolved);
1169
1170
  this._resolveContextTimestamp(entry, callback);
@@ -1178,9 +1179,7 @@ class FileSystemInfo {
1178
1179
  _getUnresolvedContextTimestamp(path, callback) {
1179
1180
  const cache = this._contextTimestamps.get(path);
1180
1181
  if (cache !== undefined) return callback(null, cache);
1181
- this.contextTimestampQueue.add(path, (err, entry) => {
1182
- return callback(null, entry);
1183
- });
1182
+ this.contextTimestampQueue.add(path, callback);
1184
1183
  }
1185
1184
 
1186
1185
  /**
@@ -1204,9 +1203,10 @@ class FileSystemInfo {
1204
1203
  if (cache !== undefined) {
1205
1204
  const resolved = getResolvedHash(cache);
1206
1205
  if (resolved !== undefined) return callback(null, resolved);
1207
- this._resolveContextHash(cache, callback);
1206
+ return this._resolveContextHash(cache, callback);
1208
1207
  }
1209
1208
  this.contextHashQueue.add(path, (err, entry) => {
1209
+ if (err) return callback(err);
1210
1210
  const resolved = getResolvedHash(entry);
1211
1211
  if (resolved !== undefined) return callback(null, resolved);
1212
1212
  this._resolveContextHash(entry, callback);
@@ -1221,9 +1221,7 @@ class FileSystemInfo {
1221
1221
  _getUnresolvedContextHash(path, callback) {
1222
1222
  const cache = this._contextHashes.get(path);
1223
1223
  if (cache !== undefined) return callback(null, cache);
1224
- this.contextHashQueue.add(path, (err, entry) => {
1225
- return callback(null, entry);
1226
- });
1224
+ this.contextHashQueue.add(path, callback);
1227
1225
  }
1228
1226
 
1229
1227
  /**
@@ -1236,9 +1234,10 @@ class FileSystemInfo {
1236
1234
  if (cache !== undefined) {
1237
1235
  const resolved = getResolvedTimestamp(cache);
1238
1236
  if (resolved !== undefined) return callback(null, resolved);
1239
- this._resolveContextTsh(cache, callback);
1237
+ return this._resolveContextTsh(cache, callback);
1240
1238
  }
1241
1239
  this.contextTshQueue.add(path, (err, entry) => {
1240
+ if (err) return callback(err);
1242
1241
  const resolved = getResolvedTimestamp(entry);
1243
1242
  if (resolved !== undefined) return callback(null, resolved);
1244
1243
  this._resolveContextTsh(entry, callback);
@@ -1253,9 +1252,7 @@ class FileSystemInfo {
1253
1252
  _getUnresolvedContextTsh(path, callback) {
1254
1253
  const cache = this._contextTshs.get(path);
1255
1254
  if (cache !== undefined) return callback(null, cache);
1256
- this.contextTshQueue.add(path, (err, entry) => {
1257
- return callback(null, entry);
1258
- });
1255
+ this.contextTshQueue.add(path, callback);
1259
1256
  }
1260
1257
 
1261
1258
  _createBuildDependenciesResolvers() {
@@ -495,6 +495,7 @@ class HotModuleReplacementPlugin {
495
495
  let newModules;
496
496
  let newRuntimeModules;
497
497
  let newFullHashModules;
498
+ let newDependentHashModules;
498
499
  let newRuntime;
499
500
  let removedFromRuntime;
500
501
  const currentChunk = find(
@@ -521,6 +522,13 @@ class HotModuleReplacementPlugin {
521
522
  Array.from(fullHashModules).filter(module =>
522
523
  updatedModules.has(module, currentChunk)
523
524
  );
525
+ const dependentHashModules =
526
+ chunkGraph.getChunkDependentHashModulesIterable(currentChunk);
527
+ newDependentHashModules =
528
+ dependentHashModules &&
529
+ Array.from(dependentHashModules).filter(module =>
530
+ updatedModules.has(module, currentChunk)
531
+ );
524
532
  removedFromRuntime = subtractRuntime(oldRuntime, newRuntime);
525
533
  } else {
526
534
  // chunk has completely removed
@@ -607,6 +615,12 @@ class HotModuleReplacementPlugin {
607
615
  newFullHashModules
608
616
  );
609
617
  }
618
+ if (newDependentHashModules) {
619
+ chunkGraph.attachDependentHashModules(
620
+ hotUpdateChunk,
621
+ newDependentHashModules
622
+ );
623
+ }
610
624
  const renderManifest = compilation.getRenderManifest({
611
625
  chunk: hotUpdateChunk,
612
626
  hash: records.hash,
@@ -44,6 +44,7 @@ class RuntimeModule extends Module {
44
44
  /** @type {ChunkGraph} */
45
45
  this.chunkGraph = undefined;
46
46
  this.fullHash = false;
47
+ this.dependentHash = false;
47
48
  /** @type {string} */
48
49
  this._cachedGeneratedCode = undefined;
49
50
  }
@@ -107,7 +108,7 @@ class RuntimeModule extends Module {
107
108
  hash.update(this.name);
108
109
  hash.update(`${this.stage}`);
109
110
  try {
110
- if (this.fullHash) {
111
+ if (this.fullHash || this.dependentHash) {
111
112
  // Do not use getGeneratedCode here, because i. e. compilation hash might be not
112
113
  // ready at this point. We will cache it later instead.
113
114
  hash.update(this.generate());
package/lib/Watching.js CHANGED
@@ -419,26 +419,24 @@ class Watching {
419
419
  this.compiler.fileTimestamps = undefined;
420
420
  this.compiler.contextTimestamps = undefined;
421
421
  this.compiler.fsStartTime = undefined;
422
- const shutdown = () => {
423
- this.compiler.cache.shutdown(err => {
424
- this.compiler.hooks.watchClose.call();
425
- const closeCallbacks = this._closeCallbacks;
426
- this._closeCallbacks = undefined;
427
- for (const cb of closeCallbacks) cb(err);
428
- });
422
+ const shutdown = err => {
423
+ this.compiler.hooks.watchClose.call();
424
+ const closeCallbacks = this._closeCallbacks;
425
+ this._closeCallbacks = undefined;
426
+ for (const cb of closeCallbacks) cb(err);
429
427
  };
430
428
  if (compilation) {
431
429
  const logger = compilation.getLogger("webpack.Watching");
432
430
  logger.time("storeBuildDependencies");
433
431
  this.compiler.cache.storeBuildDependencies(
434
432
  compilation.buildDependencies,
435
- err => {
433
+ err2 => {
436
434
  logger.timeEnd("storeBuildDependencies");
437
- shutdown();
435
+ shutdown(err || err2);
438
436
  }
439
437
  );
440
438
  } else {
441
- shutdown();
439
+ shutdown(err);
442
440
  }
443
441
  };
444
442
 
@@ -1039,7 +1039,9 @@ HarmonyExportImportedSpecifierDependency.Template = class HarmonyExportImportedS
1039
1039
  ids,
1040
1040
  runtimeRequirements
1041
1041
  ),
1042
- InitFragment.STAGE_HARMONY_IMPORTS,
1042
+ moduleGraph.isAsync(importedModule)
1043
+ ? InitFragment.STAGE_ASYNC_HARMONY_IMPORTS
1044
+ : InitFragment.STAGE_HARMONY_IMPORTS,
1043
1045
  dep.sourceOrder
1044
1046
  )
1045
1047
  );
@@ -1100,7 +1102,9 @@ HarmonyExportImportedSpecifierDependency.Template = class HarmonyExportImportedS
1100
1102
  initFragments.push(
1101
1103
  new InitFragment(
1102
1104
  `${content}\n/* harmony reexport (unknown) */ ${RuntimeGlobals.definePropertyGetters}(${exportsName}, __WEBPACK_REEXPORT_OBJECT__);\n`,
1103
- InitFragment.STAGE_HARMONY_IMPORTS,
1105
+ moduleGraph.isAsync(importedModule)
1106
+ ? InitFragment.STAGE_ASYNC_HARMONY_IMPORTS
1107
+ : InitFragment.STAGE_HARMONY_IMPORTS,
1104
1108
  dep.sourceOrder
1105
1109
  )
1106
1110
  );
@@ -1073,7 +1073,7 @@ module.exports = class SplitChunksPlugin {
1073
1073
  "SplitChunksPlugin\n" +
1074
1074
  `Cache group "${cacheGroup.key}" conflicts with existing chunk.\n` +
1075
1075
  `Both have the same name "${name}" and existing chunk is not a parent of the selected modules.\n` +
1076
- "Use a different name for the cache group or make sure that the existing chunk is a parent (e. g. via dependsOn).\n" +
1076
+ "Use a different name for the cache group or make sure that the existing chunk is a parent (e. g. via dependOn).\n" +
1077
1077
  'HINT: You can omit "name" to automatically create a name.\n' +
1078
1078
  "BREAKING CHANGE: webpack < 5 used to allow to use an entrypoint as splitChunk. " +
1079
1079
  "This is no longer allowed when the entrypoint is not a parent of the selected modules.\n" +
@@ -30,6 +30,7 @@ class GetChunkFilenameRuntimeModule extends RuntimeModule {
30
30
  this.global = global;
31
31
  this.getFilenameForChunk = getFilenameForChunk;
32
32
  this.allChunks = allChunks;
33
+ this.dependentHash = true;
33
34
  }
34
35
 
35
36
  /**
@@ -6,6 +6,59 @@
6
6
  "use strict";
7
7
 
8
8
  const SAFE_IDENTIFIER = /^[_a-zA-Z$][_a-zA-Z$0-9]*$/;
9
+ const RESERVED_IDENTIFER = new Set([
10
+ "break",
11
+ "case",
12
+ "catch",
13
+ "class",
14
+ "const",
15
+ "continue",
16
+ "debugger",
17
+ "default",
18
+ "delete",
19
+ "do",
20
+ "else",
21
+ "export",
22
+ "extends",
23
+ "finally",
24
+ "for",
25
+ "function",
26
+ "if",
27
+ "import",
28
+ "in",
29
+ "instanceof",
30
+ "new",
31
+ "return",
32
+ "super",
33
+ "switch",
34
+ "this",
35
+ "throw",
36
+ "try",
37
+ "typeof",
38
+ "var",
39
+ "void",
40
+ "while",
41
+ "with",
42
+ "enum",
43
+ // strict mode
44
+ "implements",
45
+ "interface",
46
+ "let",
47
+ "package",
48
+ "private",
49
+ "protected",
50
+ "public",
51
+ "static",
52
+ "yield",
53
+ "yield",
54
+ // module code
55
+ "await",
56
+ // skip future reserved keywords defined under ES1 till ES3
57
+ // additional
58
+ "null",
59
+ "true",
60
+ "false"
61
+ ]);
9
62
 
10
63
  const propertyAccess = (properties, start = 0) => {
11
64
  let str = "";
@@ -13,7 +66,7 @@ const propertyAccess = (properties, start = 0) => {
13
66
  const p = properties[i];
14
67
  if (`${+p}` === p) {
15
68
  str += `[${p}]`;
16
- } else if (SAFE_IDENTIFIER.test(p)) {
69
+ } else if (SAFE_IDENTIFIER.test(p) && !RESERVED_IDENTIFER.has(p)) {
17
70
  str += `.${p}`;
18
71
  } else {
19
72
  str += `[${JSON.stringify(p)}]`;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "webpack",
3
- "version": "5.51.1",
3
+ "version": "5.51.2",
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",
@@ -65,6 +65,7 @@
65
65
  "is-ci": "^3.0.0",
66
66
  "istanbul": "^0.4.5",
67
67
  "jest": "^27.0.6",
68
+ "jest-cli": "^27.0.6",
68
69
  "jest-circus": "^27.0.6",
69
70
  "jest-diff": "^27.0.2",
70
71
  "jest-junit": "^12.0.0",
package/types.d.ts CHANGED
@@ -767,6 +767,10 @@ declare class ChunkGraph {
767
767
  attachModules(chunk: Chunk, modules: Iterable<Module>): void;
768
768
  attachRuntimeModules(chunk: Chunk, modules: Iterable<RuntimeModule>): void;
769
769
  attachFullHashModules(chunk: Chunk, modules: Iterable<RuntimeModule>): void;
770
+ attachDependentHashModules(
771
+ chunk: Chunk,
772
+ modules: Iterable<RuntimeModule>
773
+ ): void;
770
774
  replaceModule(oldModule: Module, newModule: Module): void;
771
775
  isModuleInChunk(module: Module, chunk: Chunk): boolean;
772
776
  isModuleInChunkGroup(module: Module, chunkGroup: ChunkGroup): boolean;
@@ -780,6 +784,7 @@ declare class ChunkGraph {
780
784
  getNumberOfModuleChunks(module: Module): number;
781
785
  getModuleRuntimes(module: Module): RuntimeSpecSet;
782
786
  getNumberOfChunkModules(chunk: Chunk): number;
787
+ getNumberOfChunkFullHashModules(chunk: Chunk): number;
783
788
  getChunkModulesIterable(chunk: Chunk): Iterable<Module>;
784
789
  getChunkModulesIterableBySourceType(
785
790
  chunk: Chunk,
@@ -831,6 +836,7 @@ declare class ChunkGraph {
831
836
  ): number;
832
837
  canChunksBeIntegrated(chunkA: Chunk, chunkB: Chunk): boolean;
833
838
  integrateChunks(chunkA: Chunk, chunkB: Chunk): void;
839
+ upgradeDependentToFullHashModules(chunk: Chunk): void;
834
840
  isEntryModuleInChunk(module: Module, chunk: Chunk): boolean;
835
841
  connectChunkAndEntryModule(
836
842
  chunk: Chunk,
@@ -839,6 +845,7 @@ declare class ChunkGraph {
839
845
  ): void;
840
846
  connectChunkAndRuntimeModule(chunk: Chunk, module: RuntimeModule): void;
841
847
  addFullHashModuleToChunk(chunk: Chunk, module: RuntimeModule): void;
848
+ addDependentHashModuleToChunk(chunk: Chunk, module: RuntimeModule): void;
842
849
  disconnectChunkAndEntryModule(chunk: Chunk, module: Module): void;
843
850
  disconnectChunkAndRuntimeModule(chunk: Chunk, module: RuntimeModule): void;
844
851
  disconnectEntryModule(module: Module): void;
@@ -856,6 +863,9 @@ declare class ChunkGraph {
856
863
  getChunkFullHashModulesSet(
857
864
  chunk: Chunk
858
865
  ): undefined | ReadonlySet<RuntimeModule>;
866
+ getChunkDependentHashModulesIterable(
867
+ chunk: Chunk
868
+ ): undefined | Iterable<RuntimeModule>;
859
869
  getChunkEntryModulesWithChunkGroupIterable(
860
870
  chunk: Chunk
861
871
  ): Iterable<[Module, undefined | Entrypoint]>;
@@ -9779,6 +9789,7 @@ declare class RuntimeModule extends Module {
9779
9789
  chunk: Chunk;
9780
9790
  chunkGraph: ChunkGraph;
9781
9791
  fullHash: boolean;
9792
+ dependentHash: boolean;
9782
9793
  attach(compilation: Compilation, chunk: Chunk, chunkGraph?: ChunkGraph): void;
9783
9794
  generate(): string;
9784
9795
  getGeneratedCode(): string;