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
@@ -429,7 +429,7 @@ class RuntimeTemplate {
429
429
  );
430
430
  }
431
431
  runtimeRequirements.add(RuntimeGlobals.require);
432
- return `__webpack_require__(${this.moduleId({
432
+ return `${RuntimeGlobals.require}(${this.moduleId({
433
433
  module,
434
434
  chunkGraph,
435
435
  request,
@@ -625,7 +625,7 @@ class RuntimeTemplate {
625
625
  )})`;
626
626
  } else {
627
627
  runtimeRequirements.add(RuntimeGlobals.require);
628
- appending = `.then(__webpack_require__.bind(__webpack_require__, ${comment}${idExpr}))`;
628
+ appending = `.then(${RuntimeGlobals.require}.bind(${RuntimeGlobals.require}, ${comment}${idExpr}))`;
629
629
  }
630
630
  break;
631
631
  case "dynamic":
@@ -651,7 +651,7 @@ class RuntimeTemplate {
651
651
  )})`;
652
652
  } else {
653
653
  runtimeRequirements.add(RuntimeGlobals.require);
654
- appending = `.then(__webpack_require__.bind(__webpack_require__, ${comment}${idExpr}))`;
654
+ appending = `.then(${RuntimeGlobals.require}.bind(${RuntimeGlobals.require}, ${comment}${idExpr}))`;
655
655
  }
656
656
  appending += `.then(${this.returningFunction(
657
657
  `${RuntimeGlobals.createFakeNamespaceObject}(m, ${fakeType})`,
@@ -666,7 +666,7 @@ class RuntimeTemplate {
666
666
  `${header}return ${returnExpression};`
667
667
  )})`;
668
668
  } else {
669
- appending = `.then(${RuntimeGlobals.createFakeNamespaceObject}.bind(__webpack_require__, ${comment}${idExpr}, ${fakeType}))`;
669
+ appending = `.then(${RuntimeGlobals.createFakeNamespaceObject}.bind(${RuntimeGlobals.require}, ${comment}${idExpr}, ${fakeType}))`;
670
670
  }
671
671
  }
672
672
  break;
@@ -773,7 +773,7 @@ class RuntimeTemplate {
773
773
  originModule.buildMeta.strictHarmonyModule
774
774
  );
775
775
  runtimeRequirements.add(RuntimeGlobals.require);
776
- const importContent = `/* harmony import */ ${optDeclaration}${importVar} = __webpack_require__(${moduleId});\n`;
776
+ const importContent = `/* harmony import */ ${optDeclaration}${importVar} = ${RuntimeGlobals.require}(${moduleId});\n`;
777
777
 
778
778
  if (exportsType === "dynamic") {
779
779
  runtimeRequirements.add(RuntimeGlobals.compatGetDefaultExport);
@@ -794,10 +794,10 @@ class RuntimeTemplate {
794
794
  * @param {Module} options.originModule the origin module
795
795
  * @param {boolean|undefined} options.asiSafe true, if location is safe for ASI, a bracket can be emitted
796
796
  * @param {boolean} options.isCall true, if expression will be called
797
- * @param {boolean} options.callContext when false, call context will not be preserved
797
+ * @param {boolean | null} options.callContext when false, call context will not be preserved
798
798
  * @param {boolean} options.defaultInterop when true and accessing the default exports, interop code will be generated
799
799
  * @param {string} options.importVar the identifier name of the import variable
800
- * @param {InitFragment[]} options.initFragments init fragments will be added here
800
+ * @param {InitFragment<TODO>[]} options.initFragments init fragments will be added here
801
801
  * @param {RuntimeSpec} options.runtime runtime for which this code will be generated
802
802
  * @param {Set<string>} options.runtimeRequirements if set, will be filled with runtime requirements
803
803
  * @returns {string} expression
@@ -5,11 +5,23 @@
5
5
 
6
6
  "use strict";
7
7
 
8
+ /** @typedef {import("./ModuleFactory").ModuleFactoryCreateData} ModuleFactoryCreateData */
9
+ /** @typedef {import("./ModuleFactory").ModuleFactoryResult} ModuleFactoryResult */
10
+ /** @typedef {import("./ModuleGraph")} ModuleGraph */
11
+
8
12
  class SelfModuleFactory {
13
+ /**
14
+ * @param {ModuleGraph} moduleGraph module graph
15
+ */
9
16
  constructor(moduleGraph) {
10
17
  this.moduleGraph = moduleGraph;
11
18
  }
12
19
 
20
+ /**
21
+ * @param {ModuleFactoryCreateData} data data object
22
+ * @param {function((Error | null)=, ModuleFactoryResult=): void} callback callback
23
+ * @returns {void}
24
+ */
13
25
  create(data, callback) {
14
26
  const module = this.moduleGraph.getParentModule(data.dependencies[0]);
15
27
  callback(null, {
@@ -23,6 +23,7 @@ const { makePathsAbsolute } = require("./util/identifier");
23
23
  /** @typedef {import("./CacheFacade").ItemCacheFacade} ItemCacheFacade */
24
24
  /** @typedef {import("./Chunk")} Chunk */
25
25
  /** @typedef {import("./Compilation").AssetInfo} AssetInfo */
26
+ /** @typedef {import("./Compilation").PathData} PathData */
26
27
  /** @typedef {import("./Compiler")} Compiler */
27
28
  /** @typedef {import("./Module")} Module */
28
29
  /** @typedef {import("./NormalModule").SourceMap} SourceMap */
@@ -139,7 +140,7 @@ class SourceMapDevToolPlugin {
139
140
 
140
141
  /** @type {string | false} */
141
142
  this.sourceMapFilename = options.filename;
142
- /** @type {string | false} */
143
+ /** @type {string | false | (function(PathData, AssetInfo=): string)}} */
143
144
  this.sourceMappingURLComment =
144
145
  options.append === false
145
146
  ? false
@@ -447,13 +448,14 @@ class SourceMapDevToolPlugin {
447
448
  );
448
449
  }
449
450
 
450
- /** @type {string | false} */
451
+ /** @type {string | false | (function(PathData, AssetInfo=): string)} */
451
452
  let currentSourceMappingURLComment = sourceMappingURLComment;
452
453
  let cssExtensionDetected =
453
454
  CSS_EXTENSION_DETECT_REGEXP.test(file);
454
455
  resetRegexpState(CSS_EXTENSION_DETECT_REGEXP);
455
456
  if (
456
457
  currentSourceMappingURLComment !== false &&
458
+ typeof currentSourceMappingURLComment !== "function" &&
457
459
  cssExtensionDetected
458
460
  ) {
459
461
  currentSourceMappingURLComment =
@@ -534,6 +536,11 @@ class SourceMapDevToolPlugin {
534
536
  "SourceMapDevToolPlugin: append can't be false when no filename is provided"
535
537
  );
536
538
  }
539
+ if (typeof currentSourceMappingURLComment === "function") {
540
+ throw new Error(
541
+ "SourceMapDevToolPlugin: append can't be a function when no filename is provided"
542
+ );
543
+ }
537
544
  /**
538
545
  * Add source map as data url to asset
539
546
  */
package/lib/Template.js CHANGED
@@ -7,6 +7,7 @@
7
7
 
8
8
  const { ConcatSource, PrefixSource } = require("webpack-sources");
9
9
  const { WEBPACK_MODULE_TYPE_RUNTIME } = require("./ModuleTypeConstants");
10
+ const RuntimeGlobals = require("./RuntimeGlobals");
10
11
 
11
12
  /** @typedef {import("webpack-sources").Source} Source */
12
13
  /** @typedef {import("../declarations/WebpackOptions").Output} OutputOptions */
@@ -289,7 +290,7 @@ class Template {
289
290
  * @param {Module[]} modules modules to render (should be ordered by identifier)
290
291
  * @param {function(Module): Source} renderModule function to render a module
291
292
  * @param {string=} prefix applying prefix strings
292
- * @returns {Source} rendered chunk modules in a Source object
293
+ * @returns {Source | null} rendered chunk modules in a Source object or null if no modules
293
294
  */
294
295
  static renderChunkModules(renderContext, modules, renderModule, prefix = "") {
295
296
  const { chunkGraph } = renderContext;
@@ -405,7 +406,7 @@ class Template {
405
406
  return new PrefixSource(
406
407
  "/******/ ",
407
408
  new ConcatSource(
408
- "function(__webpack_require__) { // webpackRuntimeModules\n",
409
+ `function(${RuntimeGlobals.require}) { // webpackRuntimeModules\n`,
409
410
  this.renderRuntimeModules(runtimeModules, renderContext),
410
411
  "}\n"
411
412
  )
@@ -13,6 +13,7 @@ const {
13
13
  const ConstDependency = require("./dependencies/ConstDependency");
14
14
 
15
15
  /** @typedef {import("./Compiler")} Compiler */
16
+ /** @typedef {import("./javascript/JavascriptParser")} JavascriptParser */
16
17
 
17
18
  const PLUGIN_NAME = "UseStrictPlugin";
18
19
 
@@ -26,6 +27,9 @@ class UseStrictPlugin {
26
27
  compiler.hooks.compilation.tap(
27
28
  PLUGIN_NAME,
28
29
  (compilation, { normalModuleFactory }) => {
30
+ /**
31
+ * @param {JavascriptParser} parser the parser
32
+ */
29
33
  const handler = parser => {
30
34
  parser.hooks.program.tap(PLUGIN_NAME, ast => {
31
35
  const firstNode = ast.body[0];
@@ -40,6 +40,13 @@ class WarnDeprecatedOptionPlugin {
40
40
  }
41
41
 
42
42
  class DeprecatedOptionWarning extends WebpackError {
43
+ /**
44
+ * Create an instance deprecated option warning
45
+ *
46
+ * @param {string} option the target option
47
+ * @param {string | number} value the deprecated option value
48
+ * @param {string} suggestion the suggestion replacement
49
+ */
43
50
  constructor(option, value, suggestion) {
44
51
  super();
45
52
 
@@ -36,6 +36,10 @@ class IgnoringWatchFileSystem {
36
36
  watch(files, dirs, missing, startTime, options, callback, callbackUndelayed) {
37
37
  files = Array.from(files);
38
38
  dirs = Array.from(dirs);
39
+ /**
40
+ * @param {string} path path to check
41
+ * @returns {boolean} true, if path is ignored
42
+ */
39
43
  const ignored = path =>
40
44
  this.paths.some(p =>
41
45
  p instanceof RegExp ? p.test(path) : path.indexOf(p) === 0
@@ -657,7 +657,8 @@ class WebpackOptionsApply extends OptionsApply {
657
657
  maxAge: cacheOptions.maxAge,
658
658
  profile: cacheOptions.profile,
659
659
  allowCollectingMemory: cacheOptions.allowCollectingMemory,
660
- compression: cacheOptions.compression
660
+ compression: cacheOptions.compression,
661
+ readonly: cacheOptions.readonly
661
662
  }),
662
663
  cacheOptions.idleTimeout,
663
664
  cacheOptions.idleTimeoutForInitialStore,
@@ -107,6 +107,11 @@ const encodeDataUri = (encoding, source) => {
107
107
  return encodedContent;
108
108
  };
109
109
 
110
+ /**
111
+ * @param {string} encoding encoding
112
+ * @param {string} content content
113
+ * @returns {Buffer} decoded content
114
+ */
110
115
  const decodeDataUriContent = (encoding, content) => {
111
116
  const isBase64 = encoding === "base64";
112
117
 
@@ -230,10 +235,10 @@ class AssetGenerator extends Generator {
230
235
  ) {
231
236
  switch (type) {
232
237
  case ASSET_MODULE_TYPE:
233
- return module.originalSource();
238
+ return /** @type {Source} */ (module.originalSource());
234
239
  default: {
235
240
  let content;
236
- const originalSource = module.originalSource();
241
+ const originalSource = /** @type {Source} */ (module.originalSource());
237
242
  if (module.buildInfo.dataUrl) {
238
243
  let encodedSource;
239
244
  if (typeof this.dataUrlOptions === "function") {
@@ -21,6 +21,10 @@ const memoize = require("../util/memoize");
21
21
  /** @typedef {import("../Compiler")} Compiler */
22
22
  /** @typedef {import("../Module")} Module */
23
23
 
24
+ /**
25
+ * @param {string} name name of definitions
26
+ * @returns {TODO} definition
27
+ */
24
28
  const getSchema = name => {
25
29
  const { definitions } = require("../../schemas/WebpackOptions.json");
26
30
  return {
@@ -204,7 +208,9 @@ class AssetModulesPlugin {
204
208
  codeGenResult.data.get("fullContentHash")
205
209
  });
206
210
  } catch (e) {
207
- e.message += `\nduring rendering of asset ${module.identifier()}`;
211
+ /** @type {Error} */ (
212
+ e
213
+ ).message += `\nduring rendering of asset ${module.identifier()}`;
208
214
  throw e;
209
215
  }
210
216
  }
@@ -7,6 +7,7 @@
7
7
 
8
8
  const Parser = require("../Parser");
9
9
 
10
+ /** @typedef {import("../../declarations/WebpackOptions").AssetParserDataUrlOptions} AssetParserDataUrlOptions */
10
11
  /** @typedef {import("../../declarations/WebpackOptions").AssetParserOptions} AssetParserOptions */
11
12
  /** @typedef {import("../Parser").ParserState} ParserState */
12
13
  /** @typedef {import("../Parser").PreparsedAst} PreparsedAst */
@@ -45,7 +46,9 @@ class AssetParser extends Parser {
45
46
  typeof this.dataUrlCondition === "object"
46
47
  ) {
47
48
  state.module.buildInfo.dataUrl =
48
- Buffer.byteLength(source) <= this.dataUrlCondition.maxSize;
49
+ Buffer.byteLength(source) <=
50
+ /** @type {NonNullable<AssetParserDataUrlOptions["maxSize"]>} */
51
+ (this.dataUrlCondition.maxSize);
49
52
  } else {
50
53
  throw new Error("Unexpected dataUrlCondition type");
51
54
  }
@@ -60,7 +60,8 @@ class RawDataUrlModule extends Module {
60
60
  * @returns {number} the estimated size of the module (must be non-zero)
61
61
  */
62
62
  size(type) {
63
- if (this.url === undefined) this.url = this.urlBuffer.toString();
63
+ if (this.url === undefined)
64
+ this.url = /** @type {Buffer} */ (this.urlBuffer).toString();
64
65
  return Math.max(1, this.url.length);
65
66
  }
66
67
 
@@ -102,7 +103,8 @@ class RawDataUrlModule extends Module {
102
103
  * @returns {CodeGenerationResult} result
103
104
  */
104
105
  codeGeneration(context) {
105
- if (this.url === undefined) this.url = this.urlBuffer.toString();
106
+ if (this.url === undefined)
107
+ this.url = /** @type {Buffer} */ (this.urlBuffer).toString();
106
108
  const sources = new Map();
107
109
  sources.set(
108
110
  "javascript",
@@ -121,7 +123,7 @@ class RawDataUrlModule extends Module {
121
123
  * @returns {void}
122
124
  */
123
125
  updateHash(hash, context) {
124
- hash.update(this.urlBuffer);
126
+ hash.update(/** @type {Buffer} */ (this.urlBuffer));
125
127
  super.updateHash(hash, context);
126
128
  }
127
129
 
@@ -42,7 +42,7 @@ class InferAsyncModulesPlugin {
42
42
  c.isTargetActive(undefined)
43
43
  )
44
44
  ) {
45
- queue.add(originModule);
45
+ queue.add(/** @type {Module} */ (originModule));
46
46
  }
47
47
  }
48
48
  }
@@ -981,6 +981,7 @@ class PackFileCacheStrategy {
981
981
  * @param {boolean} options.profile track and log detailed timing information for individual cache items
982
982
  * @param {boolean} options.allowCollectingMemory allow to collect unused memory created during deserialization
983
983
  * @param {false | "gzip" | "brotli"} options.compression compression used
984
+ * @param {boolean} options.readonly disable storing cache into filesystem
984
985
  */
985
986
  constructor({
986
987
  compiler,
@@ -993,7 +994,8 @@ class PackFileCacheStrategy {
993
994
  maxAge,
994
995
  profile,
995
996
  allowCollectingMemory,
996
- compression
997
+ compression,
998
+ readonly
997
999
  }) {
998
1000
  this.fileSerializer = createFileSerializer(
999
1001
  fs,
@@ -1012,6 +1014,7 @@ class PackFileCacheStrategy {
1012
1014
  this.logger = logger;
1013
1015
  this.maxAge = maxAge;
1014
1016
  this.profile = profile;
1017
+ this.readonly = readonly;
1015
1018
  this.allowCollectingMemory = allowCollectingMemory;
1016
1019
  this.compression = compression;
1017
1020
  this._extension =
@@ -1213,6 +1216,8 @@ class PackFileCacheStrategy {
1213
1216
  * @returns {Promise<void>} promise
1214
1217
  */
1215
1218
  store(identifier, etag, data) {
1219
+ if (this.readonly) return Promise.resolve();
1220
+
1216
1221
  return this._getPack().then(pack => {
1217
1222
  pack.set(identifier, etag === null ? null : etag.toString(), data);
1218
1223
  });
@@ -1239,6 +1244,7 @@ class PackFileCacheStrategy {
1239
1244
  }
1240
1245
 
1241
1246
  storeBuildDependencies(dependencies) {
1247
+ if (this.readonly) return;
1242
1248
  this.newBuildDependencies.addAll(dependencies);
1243
1249
  }
1244
1250
 
@@ -23,7 +23,7 @@ const inputRx = /^(?:((?:[A-Z]:)?[/\\].*?))?(?::(.+?))?$/i;
23
23
  */
24
24
 
25
25
  /**
26
- * @param {string} input input string
26
+ * @param {string | null | undefined} input input string
27
27
  * @param {string} context the context directory
28
28
  * @returns {BrowserslistHandlerConfig} config
29
29
  */
@@ -47,7 +47,7 @@ const parse = (input, context) => {
47
47
  };
48
48
 
49
49
  /**
50
- * @param {string} input input string
50
+ * @param {string | null | undefined} input input string
51
51
  * @param {string} context the context directory
52
52
  * @returns {string[] | undefined} selected browsers
53
53
  */
@@ -66,7 +66,7 @@ const load = (input, context) => {
66
66
  })
67
67
  : browserslist.loadConfig({ path: context, env });
68
68
 
69
- if (!config) return null;
69
+ if (!config) return;
70
70
  return browserslist(config);
71
71
  };
72
72