webpack 5.103.0 → 5.104.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.
Files changed (177) hide show
  1. package/hot/dev-server.js +18 -3
  2. package/hot/emitter-event-target.js +7 -0
  3. package/hot/lazy-compilation-node.js +45 -29
  4. package/hot/lazy-compilation-universal.js +18 -0
  5. package/hot/lazy-compilation-web.js +15 -5
  6. package/hot/load-http.js +7 -0
  7. package/hot/only-dev-server.js +19 -4
  8. package/lib/APIPlugin.js +6 -0
  9. package/lib/Chunk.js +1 -1
  10. package/lib/ChunkGraph.js +9 -7
  11. package/lib/ChunkGroup.js +8 -5
  12. package/lib/CleanPlugin.js +6 -3
  13. package/lib/CodeGenerationResults.js +2 -1
  14. package/lib/CompatibilityPlugin.js +3 -0
  15. package/lib/Compilation.js +33 -19
  16. package/lib/Compiler.js +3 -3
  17. package/lib/ContextModule.js +6 -3
  18. package/lib/ContextModuleFactory.js +6 -4
  19. package/lib/DefinePlugin.js +34 -3
  20. package/lib/DelegatedModule.js +7 -4
  21. package/lib/DllModule.js +6 -3
  22. package/lib/DotenvPlugin.js +11 -6
  23. package/lib/ExportsInfo.js +5 -5
  24. package/lib/ExternalModule.js +8 -7
  25. package/lib/ExternalModuleFactoryPlugin.js +1 -1
  26. package/lib/FileSystemInfo.js +1 -1
  27. package/lib/Generator.js +10 -7
  28. package/lib/HookWebpackError.js +33 -4
  29. package/lib/HotModuleReplacementPlugin.js +22 -0
  30. package/lib/ManifestPlugin.js +1 -1
  31. package/lib/Module.js +24 -15
  32. package/lib/ModuleBuildError.js +1 -1
  33. package/lib/ModuleError.js +1 -1
  34. package/lib/ModuleFilenameHelpers.js +1 -1
  35. package/lib/ModuleGraph.js +27 -12
  36. package/lib/ModuleGraphConnection.js +2 -2
  37. package/lib/ModuleSourceTypeConstants.js +189 -0
  38. package/lib/ModuleTypeConstants.js +1 -4
  39. package/lib/ModuleWarning.js +1 -1
  40. package/lib/NodeStuffPlugin.js +52 -42
  41. package/lib/NormalModule.js +6 -4
  42. package/lib/NormalModuleFactory.js +7 -10
  43. package/lib/Parser.js +1 -1
  44. package/lib/RawModule.js +7 -4
  45. package/lib/RuntimeModule.js +1 -1
  46. package/lib/RuntimeTemplate.js +5 -1
  47. package/lib/SizeFormatHelpers.js +1 -1
  48. package/lib/SourceMapDevToolPlugin.js +6 -1
  49. package/lib/Template.js +17 -6
  50. package/lib/TemplatedPathPlugin.js +5 -6
  51. package/lib/WebpackError.js +0 -1
  52. package/lib/WebpackOptionsApply.js +37 -9
  53. package/lib/asset/AssetBytesGenerator.js +15 -11
  54. package/lib/asset/AssetGenerator.js +30 -24
  55. package/lib/asset/AssetSourceGenerator.js +15 -11
  56. package/lib/asset/RawDataUrlModule.js +6 -3
  57. package/lib/buildChunkGraph.js +4 -2
  58. package/lib/cache/PackFileCacheStrategy.js +6 -5
  59. package/lib/cli.js +2 -43
  60. package/lib/config/browserslistTargetHandler.js +19 -0
  61. package/lib/config/defaults.js +128 -43
  62. package/lib/config/normalization.js +2 -2
  63. package/lib/config/target.js +5 -0
  64. package/lib/container/ContainerEntryModule.js +6 -3
  65. package/lib/container/FallbackModule.js +6 -3
  66. package/lib/container/RemoteModule.js +1 -3
  67. package/lib/css/CssGenerator.js +26 -24
  68. package/lib/css/CssLoadingRuntimeModule.js +12 -4
  69. package/lib/css/CssModulesPlugin.js +29 -74
  70. package/lib/css/CssParser.js +828 -341
  71. package/lib/css/walkCssTokens.js +33 -13
  72. package/lib/dependencies/CachedConstDependency.js +24 -10
  73. package/lib/dependencies/CommonJsRequireContextDependency.js +1 -1
  74. package/lib/dependencies/ContextDependencyHelpers.js +2 -2
  75. package/lib/dependencies/ContextDependencyTemplateAsRequireCall.js +3 -1
  76. package/lib/dependencies/CssIcssExportDependency.js +242 -104
  77. package/lib/dependencies/CssIcssImportDependency.js +61 -4
  78. package/lib/dependencies/CssIcssSymbolDependency.js +2 -6
  79. package/lib/dependencies/CssImportDependency.js +2 -1
  80. package/lib/dependencies/CssUrlDependency.js +3 -2
  81. package/lib/dependencies/DynamicExports.js +7 -7
  82. package/lib/dependencies/ExternalModuleDependency.js +7 -4
  83. package/lib/dependencies/ExternalModuleInitFragment.js +2 -1
  84. package/lib/dependencies/ExternalModuleInitFragmentDependency.js +2 -1
  85. package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +3 -2
  86. package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +6 -4
  87. package/lib/dependencies/HarmonyExports.js +4 -4
  88. package/lib/dependencies/HarmonyImportDependency.js +8 -3
  89. package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +1 -1
  90. package/lib/dependencies/ImportMetaPlugin.js +57 -0
  91. package/lib/dependencies/ImportParserPlugin.js +2 -2
  92. package/lib/dependencies/LocalModulesHelpers.js +3 -3
  93. package/lib/dependencies/WorkerPlugin.js +2 -2
  94. package/lib/dependencies/getFunctionExpression.js +1 -1
  95. package/lib/esm/ModuleChunkFormatPlugin.js +5 -4
  96. package/lib/hmr/HotModuleReplacement.runtime.js +2 -1
  97. package/lib/hmr/LazyCompilationPlugin.js +4 -3
  98. package/lib/ids/IdHelpers.js +16 -7
  99. package/lib/javascript/ChunkHelpers.js +1 -1
  100. package/lib/javascript/JavascriptGenerator.js +4 -3
  101. package/lib/javascript/JavascriptModulesPlugin.js +57 -24
  102. package/lib/javascript/JavascriptParser.js +19 -6
  103. package/lib/json/JsonGenerator.js +5 -4
  104. package/lib/json/JsonParser.js +2 -1
  105. package/lib/library/AbstractLibraryPlugin.js +1 -1
  106. package/lib/library/AmdLibraryPlugin.js +4 -1
  107. package/lib/library/ExportPropertyLibraryPlugin.js +4 -1
  108. package/lib/library/ModuleLibraryPlugin.js +41 -13
  109. package/lib/library/SystemLibraryPlugin.js +4 -1
  110. package/lib/library/UmdLibraryPlugin.js +1 -1
  111. package/lib/logging/Logger.js +5 -4
  112. package/lib/logging/createConsoleLogger.js +2 -2
  113. package/lib/optimize/ConcatenatedModule.js +47 -32
  114. package/lib/optimize/ModuleConcatenationPlugin.js +5 -4
  115. package/lib/optimize/SideEffectsFlagPlugin.js +3 -2
  116. package/lib/optimize/SplitChunksPlugin.js +60 -46
  117. package/lib/rules/RuleSetCompiler.js +1 -1
  118. package/lib/runtime/GetChunkFilenameRuntimeModule.js +3 -2
  119. package/lib/schemes/HttpUriPlugin.js +97 -10
  120. package/lib/serialization/AggregateErrorSerializer.js +1 -2
  121. package/lib/serialization/ObjectMiddleware.js +0 -2
  122. package/lib/serialization/SingleItemMiddleware.js +1 -1
  123. package/lib/sharing/ConsumeSharedModule.js +1 -1
  124. package/lib/sharing/ConsumeSharedPlugin.js +5 -3
  125. package/lib/sharing/ProvideSharedModule.js +1 -1
  126. package/lib/sharing/resolveMatchedConfigs.js +15 -9
  127. package/lib/sharing/utils.js +1 -1
  128. package/lib/stats/DefaultStatsFactoryPlugin.js +8 -5
  129. package/lib/stats/DefaultStatsPresetPlugin.js +1 -1
  130. package/lib/stats/DefaultStatsPrinterPlugin.js +1 -1
  131. package/lib/util/StringXor.js +1 -1
  132. package/lib/util/URLAbsoluteSpecifier.js +2 -2
  133. package/lib/util/binarySearchBounds.js +2 -2
  134. package/lib/util/comparators.js +53 -76
  135. package/lib/util/compileBooleanMatcher.js +78 -6
  136. package/lib/util/createHash.js +20 -199
  137. package/lib/util/deprecation.js +1 -1
  138. package/lib/util/deterministicGrouping.js +6 -3
  139. package/lib/util/fs.js +75 -75
  140. package/lib/util/hash/BatchedHash.js +10 -9
  141. package/lib/util/hash/BulkUpdateHash.js +138 -0
  142. package/lib/util/hash/DebugHash.js +75 -0
  143. package/lib/util/hash/hash-digest.js +216 -0
  144. package/lib/util/identifier.js +82 -17
  145. package/lib/util/internalSerializables.js +2 -6
  146. package/lib/util/runtime.js +3 -3
  147. package/lib/util/source.js +2 -2
  148. package/lib/wasm-async/AsyncWebAssemblyGenerator.js +3 -2
  149. package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +3 -2
  150. package/lib/wasm-sync/WebAssemblyGenerator.js +9 -6
  151. package/lib/wasm-sync/WebAssemblyJavascriptGenerator.js +3 -2
  152. package/lib/wasm-sync/WebAssemblyModulesPlugin.js +6 -2
  153. package/lib/webpack.js +1 -1
  154. package/package.json +30 -25
  155. package/schemas/WebpackOptions.check.js +1 -1
  156. package/schemas/WebpackOptions.json +59 -82
  157. package/schemas/plugins/css/CssModuleGeneratorOptions.check.js +1 -1
  158. package/schemas/plugins/css/CssModuleParserOptions.check.js +1 -1
  159. package/types.d.ts +225 -158
  160. package/lib/ModuleSourceTypesConstants.js +0 -117
  161. package/lib/dependencies/CssIcssFromIdentifierDependency.js +0 -124
  162. package/lib/dependencies/CssIcssGlobalIdentifierDependency.js +0 -48
  163. package/lib/dependencies/CssIcssLocalIdentifierDependency.js +0 -61
  164. package/lib/dependencies/CssIcssSelfLocalIdentifierDependency.js +0 -190
  165. package/lib/util/jsonParseEvenBetterErrors.js +0 -10
  166. package/schemas/plugins/css/CssAutoGeneratorOptions.check.d.ts +0 -7
  167. package/schemas/plugins/css/CssAutoGeneratorOptions.check.js +0 -6
  168. package/schemas/plugins/css/CssAutoGeneratorOptions.json +0 -3
  169. package/schemas/plugins/css/CssAutoParserOptions.check.d.ts +0 -7
  170. package/schemas/plugins/css/CssAutoParserOptions.check.js +0 -6
  171. package/schemas/plugins/css/CssAutoParserOptions.json +0 -3
  172. package/schemas/plugins/css/CssGlobalGeneratorOptions.check.d.ts +0 -7
  173. package/schemas/plugins/css/CssGlobalGeneratorOptions.check.js +0 -6
  174. package/schemas/plugins/css/CssGlobalGeneratorOptions.json +0 -3
  175. package/schemas/plugins/css/CssGlobalParserOptions.check.d.ts +0 -7
  176. package/schemas/plugins/css/CssGlobalParserOptions.check.js +0 -6
  177. package/schemas/plugins/css/CssGlobalParserOptions.json +0 -3
package/hot/dev-server.js CHANGED
@@ -61,14 +61,29 @@ if (module.hot) {
61
61
  }
62
62
  });
63
63
  };
64
+ /** @type {EventTarget | NodeJS.EventEmitter} */
64
65
  var hotEmitter = require("./emitter");
65
- hotEmitter.on("webpackHotUpdate", function (currentHash) {
66
- lastHash = currentHash;
66
+ /**
67
+ * @param {CustomEvent<{ currentHash: string }>} event event or hash
68
+ */
69
+ var handler = function (event) {
70
+ lastHash = typeof event === "string" ? event : event.detail.currentHash;
67
71
  if (!upToDate() && module.hot.status() === "idle") {
68
72
  log("info", "[HMR] Checking for updates on the server...");
69
73
  check();
70
74
  }
71
- });
75
+ };
76
+
77
+ if (typeof EventTarget !== "undefined" && hotEmitter instanceof EventTarget) {
78
+ hotEmitter.addEventListener(
79
+ "webpackHotUpdate",
80
+ /** @type {EventListener} */
81
+ (handler)
82
+ );
83
+ } else {
84
+ hotEmitter.on("webpackHotUpdate", handler);
85
+ }
86
+
72
87
  log("info", "[HMR] Waiting for update signal from WDS...");
73
88
  } else {
74
89
  throw new Error("[HMR] Hot Module Replacement is disabled.");
@@ -0,0 +1,7 @@
1
+ if (typeof EventTarget !== "function") {
2
+ throw new Error(
3
+ "Environment doesn't support lazy compilation (requires EventTarget)"
4
+ );
5
+ }
6
+
7
+ module.exports = new EventTarget();
@@ -1,7 +1,7 @@
1
- /* global __resourceQuery */
2
-
3
1
  "use strict";
4
2
 
3
+ /* global __resourceQuery */
4
+
5
5
  var urlBase = decodeURIComponent(__resourceQuery.slice(1));
6
6
 
7
7
  /**
@@ -10,29 +10,6 @@ var urlBase = decodeURIComponent(__resourceQuery.slice(1));
10
10
  */
11
11
  exports.keepAlive = function (options) {
12
12
  var data = options.data;
13
- var onError = options.onError;
14
- var active = options.active;
15
- var module = options.module;
16
- /** @type {import("http").IncomingMessage} */
17
- var response;
18
- var request = (
19
- urlBase.startsWith("https") ? require("https") : require("http")
20
- ).request(
21
- urlBase + data,
22
- {
23
- agent: false,
24
- headers: { accept: "text/event-stream" }
25
- },
26
- function (res) {
27
- response = res;
28
- response.on("error", errorHandler);
29
- if (!active && !module.hot) {
30
- console.log(
31
- "Hot Module Replacement is not enabled. Waiting for process restart..."
32
- );
33
- }
34
- }
35
- );
36
13
 
37
14
  /**
38
15
  * @param {Error} err error
@@ -40,11 +17,50 @@ exports.keepAlive = function (options) {
40
17
  function errorHandler(err) {
41
18
  err.message =
42
19
  "Problem communicating active modules to the server: " + err.message;
43
- onError(err);
20
+ options.onError(err);
44
21
  }
45
- request.on("error", errorHandler);
46
- request.end();
22
+
23
+ /** @type {Promise<import("http") | import("https")>} */
24
+ var mod = require("./load-http")(urlBase.startsWith("https"));
25
+
26
+ /** @type {import("http").ClientRequest} */
27
+ var request;
28
+ /** @type {import("http").IncomingMessage} */
29
+ var response;
30
+
31
+ mod.then(function (client) {
32
+ request = client.request(
33
+ urlBase + data,
34
+ {
35
+ agent: false,
36
+ headers: { accept: "text/event-stream" }
37
+ },
38
+ function (res) {
39
+ response = res;
40
+ response.on("error", errorHandler);
41
+
42
+ if (!options.active && !options.module.hot) {
43
+ console.log(
44
+ "Hot Module Replacement is not enabled. Waiting for process restart..."
45
+ );
46
+ }
47
+ }
48
+ );
49
+
50
+ request.on("error", errorHandler);
51
+ request.end();
52
+ });
53
+
47
54
  return function () {
48
- response.destroy();
55
+ if (response) {
56
+ response.destroy();
57
+ }
49
58
  };
50
59
  };
60
+
61
+ /**
62
+ * @param {string} value new url value
63
+ */
64
+ exports.setUrl = function (value) {
65
+ urlBase = value;
66
+ };
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+
3
+ /* global __resourceQuery */
4
+
5
+ var isNodeLikeEnv =
6
+ typeof global !== "undefined" && typeof global.process !== "undefined";
7
+
8
+ var handler = isNodeLikeEnv
9
+ ? require("./lazy-compilation-node")
10
+ : require("./lazy-compilation-web");
11
+
12
+ handler.setUrl(decodeURIComponent(__resourceQuery.slice(1)));
13
+
14
+ /**
15
+ * @param {{ data: string, onError: (err: Error) => void, active: boolean, module: module }} options options
16
+ * @returns {() => void} function to destroy response
17
+ */
18
+ module.exports = handler;
@@ -1,7 +1,7 @@
1
- /* global __resourceQuery */
2
-
3
1
  "use strict";
4
2
 
3
+ /* global __resourceQuery */
4
+
5
5
  if (typeof EventSource !== "function") {
6
6
  throw new Error(
7
7
  "Environment doesn't support lazy compilation (requires EventSource)"
@@ -54,15 +54,18 @@ var updateEventSource = function updateEventSource() {
54
54
  exports.keepAlive = function (options) {
55
55
  var data = options.data;
56
56
  var onError = options.onError;
57
- var active = options.active;
58
- var module = options.module;
57
+
59
58
  errorHandlers.add(onError);
59
+
60
60
  var value = activeKeys.get(data) || 0;
61
+
61
62
  activeKeys.set(data, value + 1);
63
+
62
64
  if (value === 0) {
63
65
  updateEventSource();
64
66
  }
65
- if (!active && !module.hot) {
67
+
68
+ if (!options.active && !options.module.hot) {
66
69
  console.log(
67
70
  "Hot Module Replacement is not enabled. Waiting for process restart..."
68
71
  );
@@ -81,3 +84,10 @@ exports.keepAlive = function (options) {
81
84
  }, 1000);
82
85
  };
83
86
  };
87
+
88
+ /**
89
+ * @param {string} value new url value
90
+ */
91
+ exports.setUrl = function (value) {
92
+ urlBase = value;
93
+ };
@@ -0,0 +1,7 @@
1
+ /**
2
+ * @param {boolean} isHTTPS true when need https module, otherwise false
3
+ * @returns {Promise<import("http") | import("https")>}
4
+ */
5
+ module.exports = function (isHTTPS) {
6
+ return isHTTPS ? import("https") : import("http");
7
+ };
@@ -4,7 +4,7 @@
4
4
  */
5
5
  /* globals __webpack_hash__ */
6
6
  if (module.hot) {
7
- /** @type {undefined|string} */
7
+ /** @type {undefined | string} */
8
8
  var lastHash;
9
9
  var upToDate = function upToDate() {
10
10
  return /** @type {string} */ (lastHash).indexOf(__webpack_hash__) >= 0;
@@ -79,9 +79,13 @@ if (module.hot) {
79
79
  }
80
80
  });
81
81
  };
82
+ /** @type {EventTarget | NodeJS.EventEmitter} */
82
83
  var hotEmitter = require("./emitter");
83
- hotEmitter.on("webpackHotUpdate", function (currentHash) {
84
- lastHash = currentHash;
84
+ /**
85
+ * @param {CustomEvent<{ currentHash: string }>} event event or hash
86
+ */
87
+ var handler = function (event) {
88
+ lastHash = typeof event === "string" ? event : event.detail.currentHash;
85
89
  if (!upToDate()) {
86
90
  var status = module.hot.status();
87
91
  if (status === "idle") {
@@ -96,7 +100,18 @@ if (module.hot) {
96
100
  );
97
101
  }
98
102
  }
99
- });
103
+ };
104
+
105
+ if (typeof EventTarget !== "undefined" && hotEmitter instanceof EventTarget) {
106
+ hotEmitter.addEventListener(
107
+ "webpackHotUpdate",
108
+ /** @type {EventListener} */
109
+ (handler)
110
+ );
111
+ } else {
112
+ hotEmitter.on("webpackHotUpdate", handler);
113
+ }
114
+
100
115
  log("info", "[HMR] Waiting for update signal from WDS...");
101
116
  } else {
102
117
  throw new Error("[HMR] Hot Module Replacement is disabled.");
package/lib/APIPlugin.js CHANGED
@@ -42,6 +42,12 @@ function getReplacements() {
42
42
  type: "function",
43
43
  assign: false
44
44
  },
45
+ __webpack_global__: {
46
+ expr: RuntimeGlobals.require,
47
+ req: [RuntimeGlobals.require],
48
+ type: "function",
49
+ assign: false
50
+ },
45
51
  __webpack_public_path__: {
46
52
  expr: RuntimeGlobals.publicPath,
47
53
  req: [RuntimeGlobals.publicPath],
package/lib/Chunk.js CHANGED
@@ -207,7 +207,7 @@ class Chunk {
207
207
 
208
208
  /**
209
209
  * @param {Chunk} otherChunk the chunk to compare with
210
- * @returns {-1|0|1} the comparison result
210
+ * @returns {-1 | 0 | 1} the comparison result
211
211
  */
212
212
  compareTo(otherChunk) {
213
213
  const chunkGraph = ChunkGraph.getChunkGraphForChunk(
package/lib/ChunkGraph.js CHANGED
@@ -35,8 +35,9 @@ const {
35
35
  /** @typedef {import("./Chunk").Entrypoints} Entrypoints */
36
36
  /** @typedef {import("./Chunk").ChunkId} ChunkId */
37
37
  /** @typedef {import("./ChunkGroup")} ChunkGroup */
38
- /** @typedef {import("./Generator").SourceTypes} SourceTypes */
39
38
  /** @typedef {import("./Module")} Module */
39
+ /** @typedef {import("./Module").SourceType} SourceType */
40
+ /** @typedef {import("./Module").SourceTypes} SourceTypes */
40
41
  /** @typedef {import("./Module").ReadOnlyRuntimeRequirements} ReadOnlyRuntimeRequirements */
41
42
  /** @typedef {import("./Module").RuntimeRequirements} RuntimeRequirements */
42
43
  /** @typedef {import("./ModuleGraph")} ModuleGraph */
@@ -97,7 +98,7 @@ const getModuleRuntimes = (chunks) => {
97
98
  * @returns {(set: SortableSet<Module>) => Map<string, SortableSet<Module>>} modules by source type
98
99
  */
99
100
  const modulesBySourceType = (sourceTypesByModule) => (set) => {
100
- /** @type {Map<string, SortableSet<Module>>} */
101
+ /** @type {Map<SourceType, SortableSet<Module>>} */
101
102
  const map = new Map();
102
103
  for (const module of set) {
103
104
  const sourceTypes =
@@ -220,7 +221,7 @@ class ChunkGraphModule {
220
221
  }
221
222
  }
222
223
 
223
- /** @typedef {WeakMap<Module, Set<string>>} SourceTypesByModule */
224
+ /** @typedef {WeakMap<Module, SourceTypes>} SourceTypesByModule */
224
225
  /** @typedef {Map<Module, Entrypoint>} EntryModules */
225
226
 
226
227
  class ChunkGraphChunk {
@@ -631,7 +632,7 @@ class ChunkGraph {
631
632
  /**
632
633
  * @param {Chunk} chunk chunk
633
634
  * @param {Module} module chunk module
634
- * @param {Set<string>} sourceTypes source types
635
+ * @param {SourceTypes} sourceTypes source types
635
636
  */
636
637
  setChunkModuleSourceTypes(chunk, module, sourceTypes) {
637
638
  const cgc = this._getChunkGraphChunk(chunk);
@@ -668,10 +669,11 @@ class ChunkGraph {
668
669
 
669
670
  /**
670
671
  * @param {Module} module module
671
- * @returns {Set<string> | undefined} source types
672
+ * @returns {SourceTypes | undefined} source types
672
673
  */
673
674
  _getOverwrittenModuleSourceTypes(module) {
674
675
  let newSet = false;
676
+ /** @type {Set<SourceType> | undefined} */
675
677
  let sourceTypes;
676
678
  for (const chunk of this.getModuleChunksIterable(module)) {
677
679
  const cgc = this._getChunkGraphChunk(chunk);
@@ -679,7 +681,7 @@ class ChunkGraph {
679
681
  const st = cgc.sourceTypesByModule.get(module);
680
682
  if (st === undefined) return;
681
683
  if (!sourceTypes) {
682
- sourceTypes = st;
684
+ sourceTypes = /** @type {Set<SourceType>} */ (st);
683
685
  } else if (!newSet) {
684
686
  for (const type of st) {
685
687
  if (!newSet) {
@@ -871,7 +873,7 @@ class ChunkGraph {
871
873
  /**
872
874
  * @param {Chunk} chunkA first chunk
873
875
  * @param {Chunk} chunkB second chunk
874
- * @returns {-1|0|1} this is a comparator function like sort and returns -1, 0, or 1 based on sort order
876
+ * @returns {-1 | 0 | 1} this is a comparator function like sort and returns -1, 0, or 1 based on sort order
875
877
  */
876
878
  compareChunks(chunkA, chunkB) {
877
879
  const cgcA = this._getChunkGraphChunk(chunkA);
package/lib/ChunkGroup.js CHANGED
@@ -45,7 +45,7 @@ const getArray = (set) => [...set];
45
45
  * A convenience method used to sort chunks based on their id's
46
46
  * @param {ChunkGroup} a first sorting comparator
47
47
  * @param {ChunkGroup} b second sorting comparator
48
- * @returns {1|0|-1} a sorting index to determine order
48
+ * @returns {1 | 0 | -1} a sorting index to determine order
49
49
  */
50
50
  const sortById = (a, b) => {
51
51
  if (a.id < b.id) return -1;
@@ -56,7 +56,7 @@ const sortById = (a, b) => {
56
56
  /**
57
57
  * @param {OriginRecord} a the first comparator in sort
58
58
  * @param {OriginRecord} b the second comparator in sort
59
- * @returns {1|-1|0} returns sorting order as index
59
+ * @returns {1 | -1| 0} returns sorting order as index
60
60
  */
61
61
  const sortOrigin = (a, b) => {
62
62
  const aIdent = a.module ? a.module.identifier() : "";
@@ -91,16 +91,19 @@ class ChunkGroup {
91
91
  this.chunks = [];
92
92
  /** @type {OriginRecord[]} */
93
93
  this.origins = [];
94
+
95
+ /** @typedef {Map<Module, number>} OrderIndices */
96
+
94
97
  /** Indices in top-down order */
95
98
  /**
96
99
  * @private
97
- * @type {Map<Module, number>}
100
+ * @type {OrderIndices}
98
101
  */
99
102
  this._modulePreOrderIndices = new Map();
100
103
  /** Indices in bottom-up order */
101
104
  /**
102
105
  * @private
103
- * @type {Map<Module, number>}
106
+ * @type {OrderIndices}
104
107
  */
105
108
  this._modulePostOrderIndices = new Map();
106
109
  /** @type {number | undefined} */
@@ -485,7 +488,7 @@ class ChunkGroup {
485
488
  * Sorting values are based off of number of chunks in ChunkGroup.
486
489
  * @param {ChunkGraph} chunkGraph the chunk graph
487
490
  * @param {ChunkGroup} otherGroup the chunkGroup to compare this against
488
- * @returns {-1|0|1} sort position for comparison
491
+ * @returns {-1 | 0 | 1} sort position for comparison
489
492
  */
490
493
  compareTo(chunkGraph, otherGroup) {
491
494
  if (this.chunks.length > otherGroup.chunks.length) return -1;
@@ -63,8 +63,10 @@ const mergeAssets = (as1, as2) => {
63
63
  }
64
64
  };
65
65
 
66
+ /** @typedef {Map<string, number>} CurrentAssets */
67
+
66
68
  /**
67
- * @param {Map<string, number>} assets current assets
69
+ * @param {CurrentAssets} assets current assets
68
70
  * @returns {Set<string>} Set of directory paths
69
71
  */
70
72
  function getDirectories(assets) {
@@ -92,12 +94,13 @@ function getDirectories(assets) {
92
94
  /**
93
95
  * @param {OutputFileSystem} fs filesystem
94
96
  * @param {string} outputPath output path
95
- * @param {Map<string, number>} currentAssets filename of the current assets (must not start with .. or ., must only use / as path separator)
97
+ * @param {CurrentAssets} currentAssets filename of the current assets (must not start with .. or ., must only use / as path separator)
96
98
  * @param {(err?: Error | null, set?: Diff) => void} callback returns the filenames of the assets that shouldn't be there
97
99
  * @returns {void}
98
100
  */
99
101
  const getDiffToFs = (fs, outputPath, currentAssets, callback) => {
100
102
  const directories = getDirectories(currentAssets);
103
+ /** @type {Diff} */
101
104
  const diff = new Set();
102
105
  asyncLib.forEachLimit(
103
106
  directories,
@@ -388,7 +391,7 @@ class CleanPlugin {
388
391
  // We assume that no external modification happens while the compiler is active
389
392
  // So we can store the old assets and only diff to them to avoid fs access on
390
393
  // incremental builds
391
- /** @type {undefined|Assets} */
394
+ /** @type {undefined | Assets} */
392
395
  let oldAssets;
393
396
 
394
397
  compiler.hooks.emit.tapAsync(
@@ -13,6 +13,7 @@ const { RuntimeSpecMap, runtimeToString } = require("./util/runtime");
13
13
 
14
14
  /** @typedef {import("webpack-sources").Source} Source */
15
15
  /** @typedef {import("./Module")} Module */
16
+ /** @typedef {import("./Module").SourceType} SourceType */
16
17
  /** @typedef {import("./Module").CodeGenerationResult} CodeGenerationResult */
17
18
  /** @typedef {import("./Module").CodeGenerationResultData} CodeGenerationResultData */
18
19
  /** @typedef {import("./Module").ReadOnlyRuntimeRequirements} ReadOnlyRuntimeRequirements */
@@ -96,7 +97,7 @@ Caller might not support runtime-dependent code generation (opt-out via optimiza
96
97
  /**
97
98
  * @param {Module} module the module
98
99
  * @param {RuntimeSpec} runtime runtime(s)
99
- * @param {string} sourceType the source type
100
+ * @param {SourceType} sourceType the source type
100
101
  * @returns {Source} a source
101
102
  */
102
103
  getSource(module, runtime, sourceType) {
@@ -147,6 +147,9 @@ class CompatibilityPlugin {
147
147
  range: /** @type {Range} */ (pattern.range)
148
148
  }
149
149
  });
150
+ if (!parser.scope.topLevelScope) {
151
+ return true;
152
+ }
150
153
  });
151
154
  parser.hooks.pattern
152
155
  .for(RuntimeGlobals.exports)
@@ -84,7 +84,6 @@ const processAsyncTree = require("./util/processAsyncTree");
84
84
  const { getRuntimeKey } = require("./util/runtime");
85
85
  const { isSourceEqual } = require("./util/source");
86
86
 
87
- /** @template T @typedef {import("tapable").AsArray<T>} AsArray<T> */
88
87
  /** @typedef {import("webpack-sources").Source} Source */
89
88
  /** @typedef {import("../declarations/WebpackOptions").OutputNormalized} OutputOptions */
90
89
  /** @typedef {import("../declarations/WebpackOptions").HashFunction} HashFunction */
@@ -135,6 +134,11 @@ const { isSourceEqual } = require("./util/source");
135
134
  /** @typedef {import("./TemplatedPathPlugin").TemplatePath} TemplatePath */
136
135
  /** @typedef {import("./util/Hash")} Hash */
137
136
 
137
+ /**
138
+ * @template T
139
+ * @typedef {import("tapable").AsArray<T>} AsArray<T>
140
+ */
141
+
138
142
  /**
139
143
  * @template T
140
144
  * @typedef {import("./util/deprecation").FakeHook<T>} FakeHook<T>
@@ -200,9 +204,9 @@ const { isSourceEqual } = require("./util/source");
200
204
  * @property {string | number} id
201
205
  * @property {string=} name
202
206
  * @property {string} hash
203
- * @property {((length: number) => string)=} hashWithLength
207
+ * @property {HashWithLengthFunction=} hashWithLength
204
208
  * @property {(Record<string, string>)=} contentHash
205
- * @property {(Record<string, (length: number) => string>)=} contentHashWithLength
209
+ * @property {(Record<string, HashWithLengthFunction>)=} contentHashWithLength
206
210
  */
207
211
 
208
212
  /**
@@ -224,17 +228,19 @@ const { isSourceEqual } = require("./util/source");
224
228
  * @property {EntryOptions=} entryOptions
225
229
  */
226
230
 
231
+ /** @typedef {LazySet<string>} FileSystemDependencies */
232
+
227
233
  /** @typedef {EXPECTED_ANY} ExecuteModuleExports */
228
234
 
229
235
  /**
230
236
  * @typedef {object} ExecuteModuleResult
231
237
  * @property {ExecuteModuleExports} exports
232
238
  * @property {boolean} cacheable
233
- * @property {Map<string, { source: Source, info: AssetInfo | undefined }>} assets
234
- * @property {LazySet<string>} fileDependencies
235
- * @property {LazySet<string>} contextDependencies
236
- * @property {LazySet<string>} missingDependencies
237
- * @property {LazySet<string>} buildDependencies
239
+ * @property {ExecuteModuleAssets} assets
240
+ * @property {FileSystemDependencies} fileDependencies
241
+ * @property {FileSystemDependencies} contextDependencies
242
+ * @property {FileSystemDependencies} missingDependencies
243
+ * @property {FileSystemDependencies} buildDependencies
238
244
  */
239
245
 
240
246
  /**
@@ -261,9 +267,11 @@ const { isSourceEqual } = require("./util/source");
261
267
  * @property {WebpackRequire} require require function
262
268
  */
263
269
 
270
+ /** @typedef {Map<string, { source: Source, info: AssetInfo | undefined }>} ExecuteModuleAssets */
271
+
264
272
  /**
265
273
  * @typedef {object} ExecuteModuleContext
266
- * @property {Map<string, { source: Source, info: AssetInfo | undefined }>} assets
274
+ * @property {ExecuteModuleAssets} assets
267
275
  * @property {Chunk} chunk
268
276
  * @property {ChunkGraph} chunkGraph
269
277
  * @property {WebpackRequire=} __webpack_require__
@@ -312,18 +320,22 @@ const { isSourceEqual } = require("./util/source");
312
320
  * @property {AssetInfo} info info about the asset
313
321
  */
314
322
 
323
+ /** @typedef {(length: number) => string} HashWithLengthFunction */
324
+
315
325
  /**
316
326
  * @typedef {object} ModulePathData
317
327
  * @property {string | number} id
318
328
  * @property {string} hash
319
- * @property {((length: number) => string)=} hashWithLength
329
+ * @property {HashWithLengthFunction=} hashWithLength
320
330
  */
321
331
 
332
+ /** @typedef {(id: string | number) => string | number} PrepareIdFunction */
333
+
322
334
  /**
323
335
  * @typedef {object} PathData
324
336
  * @property {ChunkGraph=} chunkGraph
325
337
  * @property {string=} hash
326
- * @property {((length: number) => string)=} hashWithLength
338
+ * @property {HashWithLengthFunction=} hashWithLength
327
339
  * @property {(Chunk | ChunkPathData)=} chunk
328
340
  * @property {(Module | ModulePathData)=} module
329
341
  * @property {RuntimeSpec=} runtime
@@ -332,9 +344,10 @@ const { isSourceEqual } = require("./util/source");
332
344
  * @property {string=} query
333
345
  * @property {string=} contentHashType
334
346
  * @property {string=} contentHash
335
- * @property {((length: number) => string)=} contentHashWithLength
347
+ * @property {HashWithLengthFunction=} contentHashWithLength
336
348
  * @property {boolean=} noChunkHash
337
349
  * @property {string=} url
350
+ * @property {PrepareIdFunction=} prepareId
338
351
  */
339
352
 
340
353
  /** @typedef {"module" | "chunk" | "root-of-chunk" | "nested"} ExcludeModulesType */
@@ -697,8 +710,8 @@ class Compilation {
697
710
  ) => `Can't automatically convert plugin using Compilation.hooks.${name} to Compilation.hooks.processAssets because ${reason}.
698
711
  BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a single Compilation.hooks.processAssets hook.`;
699
712
  /**
700
- * @param {string | (import("tapable").TapOptions & { name: string; } & ProcessAssetsAdditionalOptions)} options hook options
701
- * @returns {import("tapable").TapOptions & { name: string; } & ProcessAssetsAdditionalOptions} modified options
713
+ * @param {string | (import("tapable").TapOptions & { name: string } & ProcessAssetsAdditionalOptions)} options hook options
714
+ * @returns {import("tapable").TapOptions & { name: string } & ProcessAssetsAdditionalOptions} modified options
702
715
  */
703
716
  const getOptions = (options) => {
704
717
  if (typeof options === "string") options = { name: options };
@@ -1218,20 +1231,20 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
1218
1231
  this.emittedAssets = new Set();
1219
1232
  /** @type {Set<string>} */
1220
1233
  this.comparedForEmitAssets = new Set();
1221
- /** @type {LazySet<string>} */
1234
+ /** @type {FileSystemDependencies} */
1222
1235
  this.fileDependencies = new LazySet();
1223
- /** @type {LazySet<string>} */
1236
+ /** @type {FileSystemDependencies} */
1224
1237
  this.contextDependencies = new LazySet();
1225
- /** @type {LazySet<string>} */
1238
+ /** @type {FileSystemDependencies} */
1226
1239
  this.missingDependencies = new LazySet();
1227
- /** @type {LazySet<string>} */
1240
+ /** @type {FileSystemDependencies} */
1228
1241
  this.buildDependencies = new LazySet();
1229
1242
  // TODO webpack 6 remove
1230
1243
  this.compilationDependencies = {
1231
1244
  add: util.deprecate(
1232
1245
  /**
1233
1246
  * @param {string} item item
1234
- * @returns {LazySet<string>} file dependencies
1247
+ * @returns {FileSystemDependencies} file dependencies
1235
1248
  */
1236
1249
  (item) => this.fileDependencies.add(item),
1237
1250
  "Compilation.compilationDependencies is deprecated (used Compilation.fileDependencies instead)",
@@ -3744,6 +3757,7 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
3744
3757
  dependencyTemplates,
3745
3758
  runtimeTemplate,
3746
3759
  runtime,
3760
+ runtimes,
3747
3761
  codeGenerationResults: results,
3748
3762
  compilation: this
3749
3763
  });
package/lib/Compiler.js CHANGED
@@ -719,9 +719,9 @@ class Compiler {
719
719
  ({ name: file, source, info }, callback) => {
720
720
  let targetFile = file;
721
721
  let immutable = info.immutable;
722
- const queryStringIdx = targetFile.indexOf("?");
723
- if (queryStringIdx >= 0) {
724
- targetFile = targetFile.slice(0, queryStringIdx);
722
+ const queryOrHashStringIdx = targetFile.search(/[?#]/);
723
+ if (queryOrHashStringIdx >= 0) {
724
+ targetFile = targetFile.slice(0, queryOrHashStringIdx);
725
725
  // We may remove the hash, which is in the query string
726
726
  // So we recheck if the file is immutable
727
727
  // This doesn't cover all cases, but immutable is only a performance optimization anyway
@@ -9,7 +9,10 @@ const { OriginalSource, RawSource } = require("webpack-sources");
9
9
  const AsyncDependenciesBlock = require("./AsyncDependenciesBlock");
10
10
  const { makeWebpackError } = require("./HookWebpackError");
11
11
  const Module = require("./Module");
12
- const { JS_TYPES } = require("./ModuleSourceTypesConstants");
12
+ const {
13
+ JAVASCRIPT_TYPE,
14
+ JAVASCRIPT_TYPES
15
+ } = require("./ModuleSourceTypeConstants");
13
16
  const { JAVASCRIPT_MODULE_TYPE_DYNAMIC } = require("./ModuleTypeConstants");
14
17
  const RuntimeGlobals = require("./RuntimeGlobals");
15
18
  const Template = require("./Template");
@@ -162,7 +165,7 @@ class ContextModule extends Module {
162
165
  * @returns {SourceTypes} types available (do not mutate)
163
166
  */
164
167
  getSourceTypes() {
165
- return JS_TYPES;
168
+ return JAVASCRIPT_TYPES;
166
169
  }
167
170
 
168
171
  /**
@@ -1184,7 +1187,7 @@ module.exports = webpackEmptyAsyncContext;`;
1184
1187
  const { chunkGraph, compilation } = context;
1185
1188
  const sources = new Map();
1186
1189
  sources.set(
1187
- "javascript",
1190
+ JAVASCRIPT_TYPE,
1188
1191
  this.getSource(
1189
1192
  this.getSourceString(this.options.mode, context),
1190
1193
  compilation