webpack 5.83.1 → 5.85.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 (232) hide show
  1. package/README.md +2 -2
  2. package/lib/AsyncDependenciesBlock.js +2 -2
  3. package/lib/AutomaticPrefetchPlugin.js +1 -0
  4. package/lib/BannerPlugin.js +4 -0
  5. package/lib/CacheFacade.js +4 -0
  6. package/lib/ChunkGroup.js +5 -1
  7. package/lib/CleanPlugin.js +30 -7
  8. package/lib/CompatibilityPlugin.js +4 -3
  9. package/lib/Compilation.js +3 -3
  10. package/lib/Compiler.js +1 -1
  11. package/lib/ContextModule.js +3 -3
  12. package/lib/ContextModuleFactory.js +1 -1
  13. package/lib/DefinePlugin.js +11 -2
  14. package/lib/DllEntryPlugin.js +5 -0
  15. package/lib/DllModule.js +1 -1
  16. package/lib/DllModuleFactory.js +1 -1
  17. package/lib/EvalSourceMapDevToolPlugin.js +3 -1
  18. package/lib/HookWebpackError.js +1 -1
  19. package/lib/IgnoreErrorModuleFactory.js +1 -1
  20. package/lib/MainTemplate.js +2 -2
  21. package/lib/Module.js +21 -9
  22. package/lib/ModuleFactory.js +1 -1
  23. package/lib/ModuleTypeConstants.js +2 -1
  24. package/lib/NormalModuleFactory.js +1 -1
  25. package/lib/NormalModuleReplacementPlugin.js +4 -2
  26. package/lib/NullFactory.js +1 -1
  27. package/lib/PrefetchPlugin.js +4 -0
  28. package/lib/RecordIdsPlugin.js +4 -4
  29. package/lib/RuntimeModule.js +5 -5
  30. package/lib/RuntimePlugin.js +4 -0
  31. package/lib/RuntimeTemplate.js +7 -7
  32. package/lib/SelfModuleFactory.js +12 -0
  33. package/lib/SourceMapDevToolPlugin.js +9 -2
  34. package/lib/Template.js +3 -2
  35. package/lib/UseStrictPlugin.js +4 -0
  36. package/lib/WarnDeprecatedOptionPlugin.js +7 -0
  37. package/lib/WatchIgnorePlugin.js +4 -0
  38. package/lib/WebpackOptionsApply.js +2 -1
  39. package/lib/asset/AssetGenerator.js +7 -2
  40. package/lib/asset/AssetModulesPlugin.js +7 -1
  41. package/lib/asset/AssetParser.js +4 -1
  42. package/lib/asset/RawDataUrlModule.js +5 -3
  43. package/lib/async-modules/InferAsyncModulesPlugin.js +1 -1
  44. package/lib/cache/PackFileCacheStrategy.js +7 -1
  45. package/lib/config/browserslistTargetHandler.js +3 -3
  46. package/lib/config/defaults.js +240 -73
  47. package/lib/config/normalization.js +104 -71
  48. package/lib/config/target.js +37 -10
  49. package/lib/container/ContainerEntryModule.js +4 -0
  50. package/lib/container/ContainerEntryModuleFactory.js +1 -1
  51. package/lib/container/FallbackDependency.js +7 -0
  52. package/lib/container/FallbackItemDependency.js +3 -0
  53. package/lib/container/FallbackModule.js +5 -1
  54. package/lib/container/FallbackModuleFactory.js +1 -1
  55. package/lib/container/RemoteModule.js +4 -0
  56. package/lib/container/RemoteRuntimeModule.js +2 -1
  57. package/lib/container/RemoteToExternalDependency.js +3 -0
  58. package/lib/css/CssParser.js +168 -73
  59. package/lib/debug/ProfilingPlugin.js +11 -0
  60. package/lib/dependencies/AMDDefineDependency.js +12 -6
  61. package/lib/dependencies/AMDDefineDependencyParserPlugin.js +8 -2
  62. package/lib/dependencies/AMDPlugin.js +7 -0
  63. package/lib/dependencies/AMDRequireArrayDependency.js +5 -0
  64. package/lib/dependencies/AMDRequireContextDependency.js +6 -0
  65. package/lib/dependencies/AMDRequireDependenciesBlock.js +6 -0
  66. package/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js +8 -2
  67. package/lib/dependencies/AMDRequireDependency.js +8 -1
  68. package/lib/dependencies/AMDRequireItemDependency.js +6 -0
  69. package/lib/dependencies/CachedConstDependency.js +6 -0
  70. package/lib/dependencies/CommonJsExportRequireDependency.js +11 -0
  71. package/lib/dependencies/CommonJsExportsDependency.js +8 -0
  72. package/lib/dependencies/CommonJsExportsParserPlugin.js +2 -2
  73. package/lib/dependencies/CommonJsFullRequireDependency.js +2 -1
  74. package/lib/dependencies/CommonJsPlugin.js +28 -12
  75. package/lib/dependencies/CommonJsRequireContextDependency.js +8 -0
  76. package/lib/dependencies/CommonJsRequireDependency.js +7 -0
  77. package/lib/dependencies/CommonJsSelfReferenceDependency.js +8 -0
  78. package/lib/dependencies/ConstDependency.js +2 -1
  79. package/lib/dependencies/ContextDependencyHelpers.js +3 -3
  80. package/lib/dependencies/CreateScriptUrlDependency.js +2 -1
  81. package/lib/dependencies/CriticalDependencyWarning.js +3 -0
  82. package/lib/dependencies/CssImportDependency.js +2 -1
  83. package/lib/dependencies/CssLocalIdentifierDependency.js +2 -1
  84. package/lib/dependencies/CssSelfLocalIdentifierDependency.js +2 -1
  85. package/lib/dependencies/CssUrlDependency.js +12 -2
  86. package/lib/dependencies/DelegatedSourceDependency.js +3 -0
  87. package/lib/dependencies/ExportsInfoDependency.js +6 -0
  88. package/lib/dependencies/HarmonyAcceptDependency.js +2 -1
  89. package/lib/dependencies/HarmonyAcceptImportDependency.js +3 -0
  90. package/lib/dependencies/HarmonyDetectionParserPlugin.js +16 -0
  91. package/lib/dependencies/HarmonyEvaluatedImportSpecifierDependency.js +12 -1
  92. package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +3 -0
  93. package/lib/dependencies/HarmonyExportExpressionDependency.js +8 -0
  94. package/lib/dependencies/HarmonyExportHeaderDependency.js +5 -0
  95. package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +2 -1
  96. package/lib/dependencies/HarmonyExportSpecifierDependency.js +4 -0
  97. package/lib/dependencies/HarmonyExports.js +3 -1
  98. package/lib/dependencies/HarmonyImportDependency.js +2 -1
  99. package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +18 -5
  100. package/lib/dependencies/HarmonyImportSideEffectDependency.js +6 -0
  101. package/lib/dependencies/HarmonyImportSpecifierDependency.js +86 -6
  102. package/lib/dependencies/HarmonyModulesPlugin.js +12 -0
  103. package/lib/dependencies/ImportContextDependency.js +6 -0
  104. package/lib/dependencies/ImportDependency.js +2 -1
  105. package/lib/dependencies/ImportEagerDependency.js +2 -1
  106. package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +32 -13
  107. package/lib/dependencies/ImportMetaContextPlugin.js +7 -0
  108. package/lib/dependencies/ImportMetaHotAcceptDependency.js +6 -0
  109. package/lib/dependencies/ImportMetaHotDeclineDependency.js +6 -0
  110. package/lib/dependencies/ImportParserPlugin.js +5 -0
  111. package/lib/dependencies/ImportPlugin.js +7 -0
  112. package/lib/dependencies/ImportWeakDependency.js +2 -1
  113. package/lib/dependencies/LocalModule.js +16 -0
  114. package/lib/dependencies/LocalModuleDependency.js +7 -0
  115. package/lib/dependencies/LocalModulesHelpers.js +18 -0
  116. package/lib/dependencies/ModuleHotAcceptDependency.js +6 -0
  117. package/lib/dependencies/ModuleHotDeclineDependency.js +6 -0
  118. package/lib/dependencies/PrefetchDependency.js +3 -0
  119. package/lib/dependencies/ProvidedDependency.js +2 -1
  120. package/lib/dependencies/PureExpressionDependency.js +2 -1
  121. package/lib/dependencies/RequireContextDependency.js +6 -0
  122. package/lib/dependencies/RequireContextPlugin.js +7 -0
  123. package/lib/dependencies/RequireEnsureDependenciesBlock.js +4 -0
  124. package/lib/dependencies/RequireEnsureDependency.js +8 -2
  125. package/lib/dependencies/RequireEnsureItemDependency.js +3 -0
  126. package/lib/dependencies/RequireEnsurePlugin.js +14 -0
  127. package/lib/dependencies/RequireHeaderDependency.js +5 -1
  128. package/lib/dependencies/RequireIncludeDependency.js +5 -0
  129. package/lib/dependencies/RequireIncludeDependencyParserPlugin.js +3 -0
  130. package/lib/dependencies/RequireIncludePlugin.js +14 -0
  131. package/lib/dependencies/RequireResolveContextDependency.js +8 -0
  132. package/lib/dependencies/RequireResolveDependency.js +6 -0
  133. package/lib/dependencies/RequireResolveHeaderDependency.js +4 -0
  134. package/lib/dependencies/SystemPlugin.js +10 -1
  135. package/lib/dependencies/URLDependency.js +3 -2
  136. package/lib/dependencies/URLPlugin.js +7 -5
  137. package/lib/dependencies/UnsupportedDependency.js +5 -0
  138. package/lib/dependencies/WebAssemblyExportImportedDependency.js +6 -0
  139. package/lib/dependencies/WebpackIsIncludedDependency.js +5 -0
  140. package/lib/dependencies/WorkerDependency.js +2 -1
  141. package/lib/dependencies/WorkerPlugin.js +30 -3
  142. package/lib/dependencies/getFunctionExpression.js +7 -0
  143. package/lib/esm/ExportWebpackRequireRuntimeModule.js +2 -1
  144. package/lib/esm/ModuleChunkFormatPlugin.js +15 -7
  145. package/lib/esm/ModuleChunkLoadingPlugin.js +9 -0
  146. package/lib/esm/ModuleChunkLoadingRuntimeModule.js +14 -9
  147. package/lib/hmr/LazyCompilationPlugin.js +1 -1
  148. package/lib/ids/ChunkModuleIdRangePlugin.js +11 -0
  149. package/lib/ids/DeterministicChunkIdsPlugin.js +11 -2
  150. package/lib/ids/DeterministicModuleIdsPlugin.js +11 -7
  151. package/lib/ids/HashedModuleIdsPlugin.js +8 -1
  152. package/lib/ids/IdHelpers.js +6 -0
  153. package/lib/ids/NamedChunkIdsPlugin.js +13 -1
  154. package/lib/ids/NamedModuleIdsPlugin.js +14 -3
  155. package/lib/ids/OccurrenceChunkIdsPlugin.js +6 -2
  156. package/lib/ids/SyncModuleIdsPlugin.js +2 -2
  157. package/lib/javascript/ArrayPushCallbackChunkFormatPlugin.js +3 -3
  158. package/lib/javascript/BasicEvaluatedExpression.js +11 -1
  159. package/lib/javascript/ChunkHelpers.js +2 -2
  160. package/lib/javascript/CommonJsChunkFormatPlugin.js +1 -1
  161. package/lib/javascript/EnableChunkLoadingPlugin.js +4 -0
  162. package/lib/javascript/JavascriptModulesPlugin.js +36 -31
  163. package/lib/javascript/JavascriptParser.js +586 -192
  164. package/lib/javascript/StartupHelpers.js +2 -2
  165. package/lib/json/JsonGenerator.js +7 -5
  166. package/lib/json/JsonParser.js +1 -1
  167. package/lib/library/AbstractLibraryPlugin.js +4 -0
  168. package/lib/library/AssignLibraryPlugin.js +6 -4
  169. package/lib/library/ExportPropertyLibraryPlugin.js +4 -1
  170. package/lib/library/ModuleLibraryPlugin.js +6 -3
  171. package/lib/library/SystemLibraryPlugin.js +1 -0
  172. package/lib/library/UmdLibraryPlugin.js +4 -0
  173. package/lib/node/CommonJsChunkLoadingPlugin.js +17 -2
  174. package/lib/node/NodeTemplatePlugin.js +10 -2
  175. package/lib/node/NodeWatchFileSystem.js +1 -1
  176. package/lib/node/ReadFileChunkLoadingRuntimeModule.js +6 -3
  177. package/lib/node/ReadFileCompileAsyncWasmPlugin.js +8 -0
  178. package/lib/node/ReadFileCompileWasmPlugin.js +19 -2
  179. package/lib/node/RequireChunkLoadingRuntimeModule.js +6 -3
  180. package/lib/optimize/ConcatenatedModule.js +1 -1
  181. package/lib/optimize/InnerGraphPlugin.js +11 -4
  182. package/lib/runtime/AsyncModuleRuntimeModule.js +1 -1
  183. package/lib/runtime/AutoPublicPathRuntimeModule.js +5 -1
  184. package/lib/runtime/BaseUriRuntimeModule.js +5 -1
  185. package/lib/runtime/EnsureChunkRuntimeModule.js +3 -0
  186. package/lib/runtime/GetChunkFilenameRuntimeModule.js +35 -16
  187. package/lib/runtime/GetTrustedTypesPolicyRuntimeModule.js +1 -1
  188. package/lib/runtime/LoadScriptRuntimeModule.js +1 -1
  189. package/lib/runtime/PublicPathRuntimeModule.js +5 -0
  190. package/lib/runtime/StartupChunkDependenciesPlugin.js +15 -0
  191. package/lib/runtime/StartupChunkDependenciesRuntimeModule.js +4 -1
  192. package/lib/runtime/StartupEntrypointRuntimeModule.js +8 -5
  193. package/lib/serialization/ArraySerializer.js +22 -6
  194. package/lib/serialization/BinaryMiddleware.js +21 -0
  195. package/lib/serialization/DateObjectSerializer.js +15 -4
  196. package/lib/serialization/ErrorObjectSerializer.js +20 -8
  197. package/lib/serialization/FileMiddleware.js +17 -0
  198. package/lib/serialization/MapObjectSerializer.js +24 -8
  199. package/lib/serialization/NullPrototypeObjectSerializer.js +25 -8
  200. package/lib/serialization/ObjectMiddleware.js +23 -0
  201. package/lib/serialization/PlainObjectSerializer.js +23 -12
  202. package/lib/serialization/RegExpObjectSerializer.js +16 -5
  203. package/lib/serialization/SetObjectSerializer.js +21 -6
  204. package/lib/sharing/ProvideSharedModuleFactory.js +1 -1
  205. package/lib/sharing/ShareRuntimeModule.js +1 -1
  206. package/lib/util/createHash.js +1 -1
  207. package/lib/util/makeSerializable.js +7 -0
  208. package/lib/util/serialization.js +10 -0
  209. package/lib/wasm-async/AsyncWasmLoadingRuntimeModule.js +9 -0
  210. package/lib/wasm-async/AsyncWebAssemblyGenerator.js +9 -1
  211. package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +13 -3
  212. package/lib/wasm-async/AsyncWebAssemblyModulesPlugin.js +19 -2
  213. package/lib/wasm-async/AsyncWebAssemblyParser.js +3 -0
  214. package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +25 -1
  215. package/lib/wasm-sync/WasmFinalizeExportsPlugin.js +14 -5
  216. package/lib/wasm-sync/WebAssemblyGenerator.js +18 -5
  217. package/lib/wasm-sync/WebAssemblyJavascriptGenerator.js +1 -1
  218. package/lib/wasm-sync/WebAssemblyModulesPlugin.js +12 -1
  219. package/lib/wasm-sync/WebAssemblyParser.js +9 -2
  220. package/lib/wasm-sync/WebAssemblyUtils.js +1 -1
  221. package/lib/web/FetchCompileAsyncWasmPlugin.js +9 -0
  222. package/lib/web/FetchCompileWasmPlugin.js +19 -2
  223. package/lib/web/JsonpChunkLoadingPlugin.js +9 -0
  224. package/lib/web/JsonpChunkLoadingRuntimeModule.js +4 -1
  225. package/lib/webworker/ImportScriptsChunkLoadingPlugin.js +9 -0
  226. package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +6 -2
  227. package/package.json +3 -3
  228. package/schemas/WebpackOptions.check.js +1 -1
  229. package/schemas/WebpackOptions.json +12 -0
  230. package/schemas/plugins/SourceMapDevToolPlugin.check.js +1 -1
  231. package/schemas/plugins/SourceMapDevToolPlugin.json +4 -0
  232. package/types.d.ts +655 -290
package/README.md CHANGED
@@ -32,8 +32,8 @@
32
32
  <a href="https://github.com/webpack/webpack/graphs/contributors">
33
33
  <img src="https://img.shields.io/github/contributors/webpack/webpack.svg">
34
34
  </a>
35
- <a href="https://gitter.im/webpack/webpack">
36
- <img src="https://badges.gitter.im/webpack/webpack.svg">
35
+ <a href="https://github.com/webpack/webpack/discussions">
36
+ <img src="https://img.shields.io/github/discussions/webpack/webpack">
37
37
  </a>
38
38
  <a href="https://twitter.com/Webpack">
39
39
  <img src="https://img.shields.io/twitter/follow/Webpack?style=social">
@@ -39,14 +39,14 @@ class AsyncDependenciesBlock extends DependenciesBlock {
39
39
  }
40
40
 
41
41
  /**
42
- * @returns {string} The name of the chunk
42
+ * @returns {string | undefined} The name of the chunk
43
43
  */
44
44
  get chunkName() {
45
45
  return this.groupOptions.name;
46
46
  }
47
47
 
48
48
  /**
49
- * @param {string} value The new chunk name
49
+ * @param {string | undefined} value The new chunk name
50
50
  * @returns {void}
51
51
  */
52
52
  set chunkName(value) {
@@ -27,6 +27,7 @@ class AutomaticPrefetchPlugin {
27
27
  );
28
28
  }
29
29
  );
30
+ /** @type {{context: string, request: string}[] | null} */
30
31
  let lastModules = null;
31
32
  compiler.hooks.afterCompile.tap("AutomaticPrefetchPlugin", compilation => {
32
33
  lastModules = [];
@@ -24,6 +24,10 @@ const validate = createSchemaValidation(
24
24
  }
25
25
  );
26
26
 
27
+ /**
28
+ * @param {string} str string to wrap
29
+ * @returns {string} wrapped string
30
+ */
27
31
  const wrapComment = str => {
28
32
  if (!str.includes("\n")) {
29
33
  return Template.toComment(str);
@@ -55,6 +55,10 @@ class MultiItemCache {
55
55
  * @returns {Promise<T>} promise with the data
56
56
  */
57
57
  getPromise() {
58
+ /**
59
+ * @param {number} i index
60
+ * @returns {Promise<T>} promise with the data
61
+ */
58
62
  const next = i => {
59
63
  return this._items[i].getPromise().then(result => {
60
64
  if (result !== undefined) return result;
package/lib/ChunkGroup.js CHANGED
@@ -353,7 +353,7 @@ class ChunkGroup {
353
353
  }
354
354
 
355
355
  /**
356
- * @returns {Array} an array containing the blocks
356
+ * @returns {Array<AsyncDependenciesBlock>} an array containing the blocks
357
357
  */
358
358
  getBlocks() {
359
359
  return this._blocks.getFromCache(getArray);
@@ -363,6 +363,10 @@ class ChunkGroup {
363
363
  return this._blocks.size;
364
364
  }
365
365
 
366
+ /**
367
+ * @param {AsyncDependenciesBlock} block block
368
+ * @returns {boolean} true, if block exists
369
+ */
366
370
  hasBlock(block) {
367
371
  return this._blocks.has(block);
368
372
  }
@@ -78,7 +78,8 @@ const getDiffToFs = (fs, outputPath, currentAssets, callback) => {
78
78
  directories,
79
79
  10,
80
80
  (directory, callback) => {
81
- fs.readdir(join(fs, outputPath, directory), (err, entries) => {
81
+ /** @type {NonNullable<OutputFileSystem["readdir"]>} */
82
+ (fs.readdir)(join(fs, outputPath, directory), (err, entries) => {
82
83
  if (err) {
83
84
  if (err.code === "ENOENT") return callback();
84
85
  if (err.code === "ENOTDIR") {
@@ -128,7 +129,8 @@ const getDiffToOldAssets = (currentAssets, oldAssets) => {
128
129
  */
129
130
  const doStat = (fs, filename, callback) => {
130
131
  if ("lstat" in fs) {
131
- fs.lstat(filename, callback);
132
+ /** @type {NonNullable<OutputFileSystem["lstat"]>} */
133
+ (fs.lstat)(filename, callback);
132
134
  } else {
133
135
  fs.stat(filename, callback);
134
136
  }
@@ -145,6 +147,9 @@ const doStat = (fs, filename, callback) => {
145
147
  * @returns {void}
146
148
  */
147
149
  const applyDiff = (fs, outputPath, dry, logger, diff, isKept, callback) => {
150
+ /**
151
+ * @param {string} msg message
152
+ */
148
153
  const log = msg => {
149
154
  if (dry) {
150
155
  logger.info(msg);
@@ -165,6 +170,10 @@ const applyDiff = (fs, outputPath, dry, logger, diff, isKept, callback) => {
165
170
  jobs,
166
171
  10,
167
172
  ({ type, filename, parent }, push, callback) => {
173
+ /**
174
+ * @param {Error & { code?: string }} err error
175
+ * @returns {void}
176
+ */
168
177
  const handleError = err => {
169
178
  if (err.code === "ENOENT") {
170
179
  log(`${filename} was removed during cleaning by something else`);
@@ -195,7 +204,9 @@ const applyDiff = (fs, outputPath, dry, logger, diff, isKept, callback) => {
195
204
  });
196
205
  return callback();
197
206
  }
198
- fs.readdir(path, (err, entries) => {
207
+
208
+ /** @type {NonNullable<OutputFileSystem["readdir"]>} */
209
+ (fs.readdir)(path, (err, entries) => {
199
210
  if (err) return handleError(err);
200
211
  /** @type {Job} */
201
212
  const deleteJob = {
@@ -317,9 +328,17 @@ class CleanPlugin {
317
328
  typeof keep === "function"
318
329
  ? keep
319
330
  : typeof keep === "string"
320
- ? path => path.startsWith(keep)
331
+ ? /**
332
+ * @param {string} path path
333
+ * @returns {boolean} true, if the path should be kept
334
+ */
335
+ path => path.startsWith(keep)
321
336
  : typeof keep === "object" && keep.test
322
- ? path => keep.test(path)
337
+ ? /**
338
+ * @param {string} path path
339
+ * @returns {boolean} true, if the path should be kept
340
+ */
341
+ path => keep.test(path)
323
342
  : () => false;
324
343
 
325
344
  // We assume that no external modification happens while the compiler is active
@@ -371,6 +390,10 @@ class CleanPlugin {
371
390
 
372
391
  const outputPath = compilation.getPath(compiler.outputPath, {});
373
392
 
393
+ /**
394
+ * @param {string} path path
395
+ * @returns {boolean} true, if needs to be kept
396
+ */
374
397
  const isKept = path => {
375
398
  const result = hooks.keep.call(path);
376
399
  if (result !== undefined) return result;
@@ -378,7 +401,7 @@ class CleanPlugin {
378
401
  };
379
402
 
380
403
  /**
381
- * @param {Error=} err err
404
+ * @param {(Error | null)=} err err
382
405
  * @param {Set<string>=} diff diff
383
406
  */
384
407
  const diffCallback = (err, diff) => {
@@ -392,7 +415,7 @@ class CleanPlugin {
392
415
  outputPath,
393
416
  dry,
394
417
  logger,
395
- diff,
418
+ /** @type {Set<string>} */ (diff),
396
419
  isKept,
397
420
  (err, keptAssets) => {
398
421
  if (err) {
@@ -10,6 +10,7 @@ const {
10
10
  JAVASCRIPT_MODULE_TYPE_DYNAMIC,
11
11
  JAVASCRIPT_MODULE_TYPE_ESM
12
12
  } = require("./ModuleTypeConstants");
13
+ const RuntimeGlobals = require("./RuntimeGlobals");
13
14
  const ConstDependency = require("./dependencies/ConstDependency");
14
15
 
15
16
  /** @typedef {import("./Compiler")} Compiler */
@@ -79,7 +80,7 @@ class CompatibilityPlugin {
79
80
  if (
80
81
  statement.type === "FunctionDeclaration" &&
81
82
  statement.id &&
82
- statement.id.name === "__webpack_require__"
83
+ statement.id.name === RuntimeGlobals.require
83
84
  ) {
84
85
  const newName = `__nested_webpack_require_${statement.range[0]}__`;
85
86
  parser.tagVariable(
@@ -98,7 +99,7 @@ class CompatibilityPlugin {
98
99
  }
99
100
  });
100
101
  parser.hooks.pattern
101
- .for("__webpack_require__")
102
+ .for(RuntimeGlobals.require)
102
103
  .tap(PLUGIN_NAME, pattern => {
103
104
  const newName = `__nested_webpack_require_${pattern.range[0]}__`;
104
105
  parser.tagVariable(pattern.name, nestedWebpackIdentifierTag, {
@@ -112,7 +113,7 @@ class CompatibilityPlugin {
112
113
  return true;
113
114
  });
114
115
  parser.hooks.pattern
115
- .for("__webpack_exports__")
116
+ .for(RuntimeGlobals.exports)
116
117
  .tap(PLUGIN_NAME, pattern => {
117
118
  parser.tagVariable(pattern.name, nestedWebpackIdentifierTag, {
118
119
  name: "__nested_webpack_exports__",
@@ -681,7 +681,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
681
681
  optimizeChunkModules: new AsyncSeriesBailHook(["chunks", "modules"]),
682
682
  /** @type {SyncHook<[Iterable<Chunk>, Iterable<Module>]>} */
683
683
  afterOptimizeChunkModules: new SyncHook(["chunks", "modules"]),
684
- /** @type {SyncBailHook<[], boolean>} */
684
+ /** @type {SyncBailHook<[], boolean | undefined>} */
685
685
  shouldRecord: new SyncBailHook([]),
686
686
 
687
687
  /** @type {SyncHook<[Chunk, Set<string>, RuntimeRequirementsContext]>} */
@@ -5024,13 +5024,13 @@ This prevents using hashes of each other and should be avoided.`);
5024
5024
  };
5025
5025
  const interceptModuleExecution = (__webpack_require__[
5026
5026
  RuntimeGlobals.interceptModuleExecution.replace(
5027
- "__webpack_require__.",
5027
+ `${RuntimeGlobals.require}.`,
5028
5028
  ""
5029
5029
  )
5030
5030
  ] = []);
5031
5031
  const moduleCache = (__webpack_require__[
5032
5032
  RuntimeGlobals.moduleCache.replace(
5033
- "__webpack_require__.",
5033
+ `${RuntimeGlobals.require}.`,
5034
5034
  ""
5035
5035
  )
5036
5036
  ] = {});
package/lib/Compiler.js CHANGED
@@ -126,7 +126,7 @@ class Compiler {
126
126
  /** @type {SyncHook<[]>} */
127
127
  initialize: new SyncHook([]),
128
128
 
129
- /** @type {SyncBailHook<[Compilation], boolean>} */
129
+ /** @type {SyncBailHook<[Compilation], boolean | undefined>} */
130
130
  shouldEmit: new SyncBailHook(["compilation"]),
131
131
  /** @type {AsyncSeriesHook<[Stats]>} */
132
132
  done: new AsyncSeriesHook(["stats"]),
@@ -640,7 +640,7 @@ class ContextModule extends Module {
640
640
 
641
641
  getReturn(type, asyncModule) {
642
642
  if (type === 9) {
643
- return "__webpack_require__(id)";
643
+ return `${RuntimeGlobals.require}(id)`;
644
644
  }
645
645
  return `${RuntimeGlobals.createFakeNamespaceObject}(id, ${type}${
646
646
  asyncModule ? " | 16" : ""
@@ -799,7 +799,7 @@ module.exports = webpackAsyncContext;`;
799
799
  ? `${arrow ? "id =>" : "function(id)"} {
800
800
  ${this.getReturnModuleObjectSource(fakeMap)}
801
801
  }`
802
- : "__webpack_require__";
802
+ : RuntimeGlobals.require;
803
803
  return `var map = ${JSON.stringify(map, null, "\t")};
804
804
  ${this.getFakeMapInitStatement(fakeMap)}
805
805
 
@@ -850,7 +850,7 @@ module.exports = webpackAsyncContext;`;
850
850
  ? `${arrow ? "id =>" : "function(id)"} {
851
851
  ${this.getReturnModuleObjectSource(fakeMap, true)};
852
852
  }`
853
- : "__webpack_require__";
853
+ : RuntimeGlobals.require;
854
854
 
855
855
  return `var map = ${JSON.stringify(map, null, "\t")};
856
856
  ${this.getFakeMapInitStatement(fakeMap)}
@@ -80,7 +80,7 @@ module.exports = class ContextModuleFactory extends ModuleFactory {
80
80
 
81
81
  /**
82
82
  * @param {ModuleFactoryCreateData} data data object
83
- * @param {function(Error=, ModuleFactoryResult=): void} callback callback
83
+ * @param {function((Error | null)=, ModuleFactoryResult=): void} callback callback
84
84
  * @returns {void}
85
85
  */
86
86
  create(data, callback) {
@@ -463,7 +463,7 @@ class DefinePlugin {
463
463
  });
464
464
  parser.hooks.expression.for(key).tap(PLUGIN_NAME, expr => {
465
465
  addValueDependency(originalKey);
466
- const strCode = toCode(
466
+ let strCode = toCode(
467
467
  code,
468
468
  parser,
469
469
  compilation.valueCacheVersions,
@@ -473,6 +473,11 @@ class DefinePlugin {
473
473
  !parser.isAsiPosition(expr.range[0]),
474
474
  parser.destructuringAssignmentPropertiesFor(expr)
475
475
  );
476
+
477
+ if (parser.scope.inShorthand) {
478
+ strCode = parser.scope.inShorthand + ":" + strCode;
479
+ }
480
+
476
481
  if (WEBPACK_REQUIRE_FUNCTION_REGEXP.test(strCode)) {
477
482
  return toConstantDependency(parser, strCode, [
478
483
  RuntimeGlobals.require
@@ -564,7 +569,7 @@ class DefinePlugin {
564
569
  );
565
570
  parser.hooks.expression.for(key).tap(PLUGIN_NAME, expr => {
566
571
  addValueDependency(key);
567
- const strCode = stringifyObj(
572
+ let strCode = stringifyObj(
568
573
  obj,
569
574
  parser,
570
575
  compilation.valueCacheVersions,
@@ -575,6 +580,10 @@ class DefinePlugin {
575
580
  parser.destructuringAssignmentPropertiesFor(expr)
576
581
  );
577
582
 
583
+ if (parser.scope.inShorthand) {
584
+ strCode = parser.scope.inShorthand + ":" + strCode;
585
+ }
586
+
578
587
  if (WEBPACK_REQUIRE_FUNCTION_REGEXP.test(strCode)) {
579
588
  return toConstantDependency(parser, strCode, [
580
589
  RuntimeGlobals.require
@@ -10,6 +10,11 @@ const DllEntryDependency = require("./dependencies/DllEntryDependency");
10
10
  const EntryDependency = require("./dependencies/EntryDependency");
11
11
 
12
12
  class DllEntryPlugin {
13
+ /**
14
+ * @param {string} context context
15
+ * @param {string[]} entries entry names
16
+ * @param {TODO} options options
17
+ */
13
18
  constructor(context, entries, options) {
14
19
  this.context = context;
15
20
  this.entries = entries;
package/lib/DllModule.js CHANGED
@@ -89,7 +89,7 @@ class DllModule extends Module {
89
89
  const sources = new Map();
90
90
  sources.set(
91
91
  "javascript",
92
- new RawSource("module.exports = __webpack_require__;")
92
+ new RawSource(`module.exports = ${RuntimeGlobals.require};`)
93
93
  );
94
94
  return {
95
95
  sources,
@@ -19,7 +19,7 @@ class DllModuleFactory extends ModuleFactory {
19
19
  }
20
20
  /**
21
21
  * @param {ModuleFactoryCreateData} data data object
22
- * @param {function(Error=, ModuleFactoryResult=): void} callback callback
22
+ * @param {function((Error | null)=, ModuleFactoryResult=): void} callback callback
23
23
  * @returns {void}
24
24
  */
25
25
  create(data, callback) {
@@ -48,7 +48,9 @@ class EvalSourceMapDevToolPlugin {
48
48
  options = inputOptions;
49
49
  }
50
50
  this.sourceMapComment =
51
- options.append || "//# sourceURL=[module]\n//# sourceMappingURL=[url]";
51
+ options.append && typeof options.append !== "function"
52
+ ? options.append
53
+ : "//# sourceURL=[module]\n//# sourceMappingURL=[url]";
52
54
  this.moduleFilenameTemplate =
53
55
  options.moduleFilenameTemplate ||
54
56
  "webpack://[namespace]/[resource-path]?[hash]";
@@ -85,7 +85,7 @@ const tryRunOrWebpackError = (fn, hook) => {
85
85
  if (err instanceof WebpackError) {
86
86
  throw err;
87
87
  }
88
- throw new HookWebpackError(err, hook);
88
+ throw new HookWebpackError(/** @type {Error} */ (err), hook);
89
89
  }
90
90
  return r;
91
91
  };
@@ -26,7 +26,7 @@ class IgnoreErrorModuleFactory extends ModuleFactory {
26
26
 
27
27
  /**
28
28
  * @param {ModuleFactoryCreateData} data data object
29
- * @param {function(Error=, ModuleFactoryResult=): void} callback callback
29
+ * @param {function((Error | null)=, ModuleFactoryResult=): void} callback callback
30
30
  * @returns {void}
31
31
  */
32
32
  create(data, callback) {
@@ -306,8 +306,8 @@ class MainTemplate {
306
306
 
307
307
  Object.defineProperty(MainTemplate.prototype, "requireFn", {
308
308
  get: util.deprecate(
309
- () => "__webpack_require__",
310
- 'MainTemplate.requireFn is deprecated (use "__webpack_require__")',
309
+ () => RuntimeGlobals.require,
310
+ `MainTemplate.requireFn is deprecated (use "${RuntimeGlobals.require}")`,
311
311
  "DEP_WEBPACK_MAIN_TEMPLATE_REQUIRE_FN"
312
312
  )
313
313
  });
package/lib/Module.js CHANGED
@@ -131,13 +131,13 @@ const deprecatedNeedRebuild = util.deprecate(
131
131
  class Module extends DependenciesBlock {
132
132
  /**
133
133
  * @param {ModuleTypes | ""} type the module type, when deserializing the type is not known and is an empty string
134
- * @param {string=} context an optional context
135
- * @param {string=} layer an optional layer in which the module is
134
+ * @param {(string | null)=} context an optional context
135
+ * @param {(string | null)=} layer an optional layer in which the module is
136
136
  */
137
137
  constructor(type, context = null, layer = null) {
138
138
  super();
139
139
 
140
- /** @type {ModuleTypes | ""} */
140
+ /** @type {ModuleTypes} */
141
141
  this.type = type;
142
142
  /** @type {string | null} */
143
143
  this.context = context;
@@ -151,7 +151,7 @@ class Module extends DependenciesBlock {
151
151
  this.debugId = debugId++;
152
152
 
153
153
  // Info from Factory
154
- /** @type {ResolveOptions} */
154
+ /** @type {ResolveOptions | undefined} */
155
155
  this.resolveOptions = EMPTY_RESOLVE_OPTIONS;
156
156
  /** @type {object | undefined} */
157
157
  this.factoryMeta = undefined;
@@ -167,9 +167,9 @@ class Module extends DependenciesBlock {
167
167
  this._warnings = undefined;
168
168
  /** @type {WebpackError[] | undefined} */
169
169
  this._errors = undefined;
170
- /** @type {BuildMeta} */
170
+ /** @type {BuildMeta | undefined} */
171
171
  this.buildMeta = undefined;
172
- /** @type {Record<string, any>} */
172
+ /** @type {Record<string, any> | undefined} */
173
173
  this.buildInfo = undefined;
174
174
  /** @type {Dependency[] | undefined} */
175
175
  this.presentationalDependencies = undefined;
@@ -331,6 +331,10 @@ class Module extends DependenciesBlock {
331
331
  );
332
332
  }
333
333
 
334
+ /**
335
+ * @param {Chunk} chunk the chunk
336
+ * @returns {boolean} true, when the module was added
337
+ */
334
338
  addChunk(chunk) {
335
339
  const chunkGraph = ChunkGraph.getChunkGraphForModule(
336
340
  this,
@@ -342,6 +346,10 @@ class Module extends DependenciesBlock {
342
346
  return true;
343
347
  }
344
348
 
349
+ /**
350
+ * @param {Chunk} chunk the chunk
351
+ * @returns {void}
352
+ */
345
353
  removeChunk(chunk) {
346
354
  return ChunkGraph.getChunkGraphForModule(
347
355
  this,
@@ -350,6 +358,10 @@ class Module extends DependenciesBlock {
350
358
  ).disconnectChunkAndModule(chunk, this);
351
359
  }
352
360
 
361
+ /**
362
+ * @param {Chunk} chunk the chunk
363
+ * @returns {boolean} true, when the module is in the chunk
364
+ */
353
365
  isInChunk(chunk) {
354
366
  return ChunkGraph.getChunkGraphForModule(
355
367
  this,
@@ -435,7 +447,7 @@ class Module extends DependenciesBlock {
435
447
  case "namespace":
436
448
  return "namespace";
437
449
  case "default":
438
- switch (this.buildMeta.defaultObject) {
450
+ switch (/** @type {BuildMeta} */ (this.buildMeta).defaultObject) {
439
451
  case "redirect":
440
452
  return "default-with-named";
441
453
  case "redirect-warn":
@@ -447,7 +459,7 @@ class Module extends DependenciesBlock {
447
459
  if (strict) return "default-with-named";
448
460
  // Try to figure out value of __esModule by following reexports
449
461
  const handleDefault = () => {
450
- switch (this.buildMeta.defaultObject) {
462
+ switch (/** @type {BuildMeta} */ (this.buildMeta).defaultObject) {
451
463
  case "redirect":
452
464
  case "redirect-warn":
453
465
  return "default-with-named";
@@ -664,7 +676,7 @@ class Module extends DependenciesBlock {
664
676
  ] of moduleGraph.getIncomingConnectionsByOriginModule(this)) {
665
677
  if (!connections.some(c => c.isTargetActive(chunk.runtime))) continue;
666
678
  for (const originChunk of chunkGraph.getModuleChunksIterable(
667
- fromModule
679
+ /** @type {Module} */ (fromModule)
668
680
  )) {
669
681
  // return true if module this is not reachable from originChunk when ignoring chunk
670
682
  if (!this.isAccessibleInChunk(chunkGraph, originChunk, chunk))
@@ -38,7 +38,7 @@ class ModuleFactory {
38
38
  /**
39
39
  * @abstract
40
40
  * @param {ModuleFactoryCreateData} data data object
41
- * @param {function(Error=, ModuleFactoryResult=): void} callback callback
41
+ * @param {function((Error | null)=, ModuleFactoryResult=): void} callback callback
42
42
  * @returns {void}
43
43
  */
44
44
  create(data, callback) {
@@ -135,7 +135,8 @@ const WEBPACK_MODULE_TYPE_LAZY_COMPILATION_PROXY = "lazy-compilation-proxy";
135
135
  /** @typedef {"css" | "css/global" | "css/module"} CSSModuleTypes */
136
136
  /** @typedef {"asset" | "asset/inline" | "asset/resource" | "asset/source" | "asset/raw-data-url"} AssetModuleTypes */
137
137
  /** @typedef {"runtime" | "fallback-module" | "remote-module" | "provide-module" | "consume-shared-module" | "lazy-compilation-proxy"} WebpackModuleTypes */
138
- /** @typedef {JavaScriptModuleTypes | JSONModuleType | WebAssemblyModuleTypes | CSSModuleTypes | AssetModuleTypes | WebpackModuleTypes} ModuleTypes */
138
+ /** @typedef {string} UnknownModuleTypes */
139
+ /** @typedef {JavaScriptModuleTypes | JSONModuleType | WebAssemblyModuleTypes | CSSModuleTypes | AssetModuleTypes | WebpackModuleTypes | UnknownModuleTypes} ModuleTypes */
139
140
 
140
141
  exports.ASSET_MODULE_TYPE = ASSET_MODULE_TYPE;
141
142
  exports.ASSET_MODULE_TYPE_RAW_DATA_URL = ASSET_MODULE_TYPE_RAW_DATA_URL;
@@ -753,7 +753,7 @@ class NormalModuleFactory extends ModuleFactory {
753
753
 
754
754
  /**
755
755
  * @param {ModuleFactoryCreateData} data data object
756
- * @param {function(Error=, ModuleFactoryResult=): void} callback callback
756
+ * @param {function((Error | null)=, ModuleFactoryResult=): void} callback callback
757
757
  * @returns {void}
758
758
  */
759
759
  create(data, callback) {
@@ -43,7 +43,9 @@ class NormalModuleReplacementPlugin {
43
43
  });
44
44
  nmf.hooks.afterResolve.tap("NormalModuleReplacementPlugin", result => {
45
45
  const createData = result.createData;
46
- if (resourceRegExp.test(createData.resource)) {
46
+ if (
47
+ resourceRegExp.test(/** @type {string} */ (createData.resource))
48
+ ) {
47
49
  if (typeof newResource === "function") {
48
50
  newResource(result);
49
51
  } else {
@@ -56,7 +58,7 @@ class NormalModuleReplacementPlugin {
56
58
  } else {
57
59
  createData.resource = join(
58
60
  fs,
59
- dirname(fs, createData.resource),
61
+ dirname(fs, /** @type {string} */ (createData.resource)),
60
62
  newResource
61
63
  );
62
64
  }
@@ -13,7 +13,7 @@ const ModuleFactory = require("./ModuleFactory");
13
13
  class NullFactory extends ModuleFactory {
14
14
  /**
15
15
  * @param {ModuleFactoryCreateData} data data object
16
- * @param {function(Error=, ModuleFactoryResult=): void} callback callback
16
+ * @param {function((Error | null)=, ModuleFactoryResult=): void} callback callback
17
17
  * @returns {void}
18
18
  */
19
19
  create(data, callback) {
@@ -10,6 +10,10 @@ const PrefetchDependency = require("./dependencies/PrefetchDependency");
10
10
  /** @typedef {import("./Compiler")} Compiler */
11
11
 
12
12
  class PrefetchPlugin {
13
+ /**
14
+ * @param {string} context context or request if context is not set
15
+ * @param {string} [request] request
16
+ */
13
17
  constructor(context, request) {
14
18
  if (request) {
15
19
  this.context = context;
@@ -69,7 +69,7 @@ class RecordIdsPlugin {
69
69
  compilation.hooks.recordModules.tap(
70
70
  "RecordIdsPlugin",
71
71
  /**
72
- * @param {Module[]} modules the modules array
72
+ * @param {Iterable<Module>} modules the modules array
73
73
  * @param {Records} records the records object
74
74
  * @returns {void}
75
75
  */
@@ -92,7 +92,7 @@ class RecordIdsPlugin {
92
92
  compilation.hooks.reviveModules.tap(
93
93
  "RecordIdsPlugin",
94
94
  /**
95
- * @param {Module[]} modules the modules array
95
+ * @param {Iterable<Module>} modules the modules array
96
96
  * @param {Records} records the records object
97
97
  * @returns {void}
98
98
  */
@@ -166,7 +166,7 @@ class RecordIdsPlugin {
166
166
  compilation.hooks.recordChunks.tap(
167
167
  "RecordIdsPlugin",
168
168
  /**
169
- * @param {Chunk[]} chunks the chunks array
169
+ * @param {Iterable<Chunk>} chunks the chunks array
170
170
  * @param {Records} records the records object
171
171
  * @returns {void}
172
172
  */
@@ -192,7 +192,7 @@ class RecordIdsPlugin {
192
192
  compilation.hooks.reviveChunks.tap(
193
193
  "RecordIdsPlugin",
194
194
  /**
195
- * @param {Chunk[]} chunks the chunks array
195
+ * @param {Iterable<Chunk>} chunks the chunks array
196
196
  * @param {Records} records the records object
197
197
  * @returns {void}
198
198
  */
@@ -38,15 +38,15 @@ class RuntimeModule extends Module {
38
38
  this.stage = stage;
39
39
  this.buildMeta = {};
40
40
  this.buildInfo = {};
41
- /** @type {Compilation} */
41
+ /** @type {Compilation | undefined} */
42
42
  this.compilation = undefined;
43
- /** @type {Chunk} */
43
+ /** @type {Chunk | undefined} */
44
44
  this.chunk = undefined;
45
- /** @type {ChunkGraph} */
45
+ /** @type {ChunkGraph | undefined} */
46
46
  this.chunkGraph = undefined;
47
47
  this.fullHash = false;
48
48
  this.dependentHash = false;
49
- /** @type {string} */
49
+ /** @type {string | undefined} */
50
50
  this._cachedGeneratedCode = undefined;
51
51
  }
52
52
 
@@ -117,7 +117,7 @@ class RuntimeModule extends Module {
117
117
  hash.update(this.getGeneratedCode());
118
118
  }
119
119
  } catch (err) {
120
- hash.update(err.message);
120
+ hash.update(/** @type {Error} */ (err).message);
121
121
  }
122
122
  super.updateHash(hash, context);
123
123
  }
@@ -99,6 +99,10 @@ class RuntimePlugin {
99
99
  apply(compiler) {
100
100
  compiler.hooks.compilation.tap("RuntimePlugin", compilation => {
101
101
  const globalChunkLoading = compilation.outputOptions.chunkLoading;
102
+ /**
103
+ * @param {Chunk} chunk chunk
104
+ * @returns {boolean} true, when chunk loading is disabled for the chunk
105
+ */
102
106
  const isChunkLoadingDisabledForChunk = chunk => {
103
107
  const options = chunk.getEntryOptions();
104
108
  const chunkLoading =