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
@@ -17,7 +17,9 @@ const {
17
17
  } = require("../javascript/JavascriptModulesPlugin");
18
18
  const { updateHashForEntryStartup } = require("../javascript/StartupHelpers");
19
19
 
20
+ /** @typedef {import("../Chunk")} Chunk */
20
21
  /** @typedef {import("../Compiler")} Compiler */
22
+ /** @typedef {import("../Entrypoint")} Entrypoint */
21
23
 
22
24
  class ModuleChunkFormatPlugin {
23
25
  /**
@@ -73,7 +75,9 @@ class ModuleChunkFormatPlugin {
73
75
  chunkGraph.getChunkEntryModulesWithChunkGroupIterable(chunk)
74
76
  );
75
77
  if (entries.length > 0) {
76
- const runtimeChunk = entries[0][1].getRuntimeChunk();
78
+ const runtimeChunk =
79
+ /** @type {Entrypoint[][]} */
80
+ (entries)[0][1].getRuntimeChunk();
77
81
  const currentOutputName = compilation
78
82
  .getPath(
79
83
  getChunkFilenameTemplate(chunk, compilation.outputOptions),
@@ -87,6 +91,10 @@ class ModuleChunkFormatPlugin {
87
91
  // remove filename, we only need the directory
88
92
  currentOutputName.pop();
89
93
 
94
+ /**
95
+ * @param {Chunk} chunk the chunk
96
+ * @returns {string} the relative path
97
+ */
90
98
  const getRelativePath = chunk => {
91
99
  const baseOutputName = currentOutputName.slice();
92
100
  const chunkOutputName = compilation
@@ -123,15 +131,15 @@ class ModuleChunkFormatPlugin {
123
131
  entrySource.add(source);
124
132
  entrySource.add(";\n\n// load runtime\n");
125
133
  entrySource.add(
126
- `import __webpack_require__ from ${JSON.stringify(
127
- getRelativePath(runtimeChunk)
134
+ `import ${RuntimeGlobals.require} from ${JSON.stringify(
135
+ getRelativePath(/** @type {Chunk} */ (runtimeChunk))
128
136
  )};\n`
129
137
  );
130
138
 
131
139
  const startupSource = new ConcatSource();
132
140
  startupSource.add(
133
141
  `var __webpack_exec__ = ${runtimeTemplate.returningFunction(
134
- `__webpack_require__(${RuntimeGlobals.entryModuleId} = moduleId)`,
142
+ `${RuntimeGlobals.require}(${RuntimeGlobals.entryModuleId} = moduleId)`,
135
143
  "moduleId"
136
144
  )}\n`
137
145
  );
@@ -143,8 +151,8 @@ class ModuleChunkFormatPlugin {
143
151
  const final = i + 1 === entries.length;
144
152
  const moduleId = chunkGraph.getModuleId(module);
145
153
  const chunks = getAllChunks(
146
- entrypoint,
147
- runtimeChunk,
154
+ /** @type {Entrypoint} */ (entrypoint),
155
+ /** @type {Chunk} */ (runtimeChunk),
148
156
  undefined
149
157
  );
150
158
  for (const chunk of chunks) {
@@ -166,7 +174,7 @@ class ModuleChunkFormatPlugin {
166
174
  }
167
175
  startupSource.add(
168
176
  `${
169
- final ? "var __webpack_exports__ = " : ""
177
+ final ? `var ${RuntimeGlobals.exports} = ` : ""
170
178
  }__webpack_exec__(${JSON.stringify(moduleId)});\n`
171
179
  );
172
180
  }
@@ -9,6 +9,7 @@ const RuntimeGlobals = require("../RuntimeGlobals");
9
9
  const ExportWebpackRequireRuntimeModule = require("./ExportWebpackRequireRuntimeModule");
10
10
  const ModuleChunkLoadingRuntimeModule = require("./ModuleChunkLoadingRuntimeModule");
11
11
 
12
+ /** @typedef {import("../Chunk")} Chunk */
12
13
  /** @typedef {import("../Compiler")} Compiler */
13
14
 
14
15
  class ModuleChunkLoadingPlugin {
@@ -22,6 +23,10 @@ class ModuleChunkLoadingPlugin {
22
23
  "ModuleChunkLoadingPlugin",
23
24
  compilation => {
24
25
  const globalChunkLoading = compilation.outputOptions.chunkLoading;
26
+ /**
27
+ * @param {Chunk} chunk chunk to check
28
+ * @returns {boolean} true, when the plugin is enabled for the chunk
29
+ */
25
30
  const isEnabledForChunk = chunk => {
26
31
  const options = chunk.getEntryOptions();
27
32
  const chunkLoading =
@@ -31,6 +36,10 @@ class ModuleChunkLoadingPlugin {
31
36
  return chunkLoading === "import";
32
37
  };
33
38
  const onceForChunkSet = new WeakSet();
39
+ /**
40
+ * @param {Chunk} chunk chunk to check
41
+ * @param {Set<string>} set runtime requirements
42
+ */
34
43
  const handler = (chunk, set) => {
35
44
  if (onceForChunkSet.has(chunk)) return;
36
45
  onceForChunkSet.add(chunk);
@@ -18,6 +18,7 @@ const compileBooleanMatcher = require("../util/compileBooleanMatcher");
18
18
  const { getUndoPath } = require("../util/identifier");
19
19
 
20
20
  /** @typedef {import("../Chunk")} Chunk */
21
+ /** @typedef {import("../ChunkGraph")} ChunkGraph */
21
22
 
22
23
  /**
23
24
  * @typedef {Object} JsonpCompilationPluginHooks
@@ -50,6 +51,9 @@ class ModuleChunkLoadingRuntimeModule extends RuntimeModule {
50
51
  return hooks;
51
52
  }
52
53
 
54
+ /**
55
+ * @param {ReadonlySet<string>} runtimeRequirements runtime requirements
56
+ */
53
57
  constructor(runtimeRequirements) {
54
58
  super("import chunk loading", RuntimeModule.STAGE_ATTACH);
55
59
  this._runtimeRequirements = runtimeRequirements;
@@ -66,11 +70,10 @@ class ModuleChunkLoadingRuntimeModule extends RuntimeModule {
66
70
  if (options && options.baseUri) {
67
71
  return `${RuntimeGlobals.baseURI} = ${JSON.stringify(options.baseUri)};`;
68
72
  }
73
+ const compilation = /** @type {Compilation} */ (this.compilation);
69
74
  const {
70
- compilation: {
71
- outputOptions: { importMetaName }
72
- }
73
- } = this;
75
+ outputOptions: { importMetaName }
76
+ } = compilation;
74
77
  return `${RuntimeGlobals.baseURI} = new URL(${JSON.stringify(
75
78
  rootOutputDir
76
79
  )}, ${importMetaName}.url);`;
@@ -80,7 +83,9 @@ class ModuleChunkLoadingRuntimeModule extends RuntimeModule {
80
83
  * @returns {string} runtime code
81
84
  */
82
85
  generate() {
83
- const { compilation, chunk, chunkGraph } = this;
86
+ const compilation = /** @type {Compilation} */ (this.compilation);
87
+ const chunkGraph = /** @type {ChunkGraph} */ (this.chunkGraph);
88
+ const chunk = /** @type {Chunk} */ (this.chunk);
84
89
  const {
85
90
  runtimeTemplate,
86
91
  outputOptions: { importFunctionName }
@@ -103,8 +108,8 @@ class ModuleChunkLoadingRuntimeModule extends RuntimeModule {
103
108
  const hasJsMatcher = compileBooleanMatcher(conditionMap);
104
109
  const initialChunkIds = getInitialChunkIds(chunk, chunkGraph, chunkHasJs);
105
110
 
106
- const outputName = this.compilation.getPath(
107
- getChunkFilenameTemplate(chunk, this.compilation.outputOptions),
111
+ const outputName = compilation.getPath(
112
+ getChunkFilenameTemplate(chunk, compilation.outputOptions),
108
113
  {
109
114
  chunk,
110
115
  contentHashType: "javascript"
@@ -112,7 +117,7 @@ class ModuleChunkLoadingRuntimeModule extends RuntimeModule {
112
117
  );
113
118
  const rootOutputDir = getUndoPath(
114
119
  outputName,
115
- this.compilation.outputOptions.path,
120
+ /** @type {string} */ (compilation.outputOptions.path),
116
121
  true
117
122
  );
118
123
 
@@ -156,7 +161,7 @@ class ModuleChunkLoadingRuntimeModule extends RuntimeModule {
156
161
  "}"
157
162
  ]),
158
163
  "}",
159
- "if(runtime) runtime(__webpack_require__);",
164
+ `if(runtime) runtime(${RuntimeGlobals.require});`,
160
165
  "for(;i < ids.length; i++) {",
161
166
  Template.indent([
162
167
  "chunkId = ids[i];",
@@ -303,7 +303,7 @@ class LazyCompilationDependencyFactory extends ModuleFactory {
303
303
 
304
304
  /**
305
305
  * @param {ModuleFactoryCreateData} data data object
306
- * @param {function(Error=, ModuleFactoryResult=): void} callback callback
306
+ * @param {function((Error | null)=, ModuleFactoryResult=): void} callback callback
307
307
  * @returns {void}
308
308
  */
309
309
  create(data, callback) {
@@ -13,7 +13,18 @@ const {
13
13
 
14
14
  /** @typedef {import("../Compiler")} Compiler */
15
15
 
16
+ /**
17
+ * @typedef {Object} ChunkModuleIdRangePluginOptions
18
+ * @property {string} name the chunk name
19
+ * @property {("index" | "index2" | "preOrderIndex" | "postOrderIndex")=} order order
20
+ * @property {number=} start start id
21
+ * @property {number=} end end id
22
+ */
23
+
16
24
  class ChunkModuleIdRangePlugin {
25
+ /**
26
+ * @param {ChunkModuleIdRangePluginOptions} options options object
27
+ */
17
28
  constructor(options) {
18
29
  this.options = options;
19
30
  }
@@ -15,9 +15,18 @@ const {
15
15
  /** @typedef {import("../Compiler")} Compiler */
16
16
  /** @typedef {import("../Module")} Module */
17
17
 
18
+ /**
19
+ * @typedef {Object} DeterministicChunkIdsPluginOptions
20
+ * @property {string=} context context for ids
21
+ * @property {number=} maxLength maximum length of ids
22
+ */
23
+
18
24
  class DeterministicChunkIdsPlugin {
19
- constructor(options) {
20
- this.options = options || {};
25
+ /**
26
+ * @param {DeterministicChunkIdsPluginOptions} [options] options
27
+ */
28
+ constructor(options = {}) {
29
+ this.options = options;
21
30
  }
22
31
 
23
32
  /**
@@ -17,15 +17,19 @@ const {
17
17
  /** @typedef {import("../Compiler")} Compiler */
18
18
  /** @typedef {import("../Module")} Module */
19
19
 
20
+ /**
21
+ * @typedef {Object} DeterministicModuleIdsPluginOptions
22
+ * @property {string=} context context relative to which module identifiers are computed
23
+ * @property {function(Module): boolean=} test selector function for modules
24
+ * @property {number=} maxLength maximum id length in digits (used as starting point)
25
+ * @property {number=} salt hash salt for ids
26
+ * @property {boolean=} fixedLength do not increase the maxLength to find an optimal id space size
27
+ * @property {boolean=} failOnConflict throw an error when id conflicts occur (instead of rehashing)
28
+ */
29
+
20
30
  class DeterministicModuleIdsPlugin {
21
31
  /**
22
- * @param {Object} options options
23
- * @param {string=} options.context context relative to which module identifiers are computed
24
- * @param {function(Module): boolean=} options.test selector function for modules
25
- * @param {number=} options.maxLength maximum id length in digits (used as starting point)
26
- * @param {number=} options.salt hash salt for ids
27
- * @param {boolean=} options.fixedLength do not increase the maxLength to find an optimal id space size
28
- * @param {boolean=} options.failOnConflict throw an error when id conflicts occur (instead of rehashing)
32
+ * @param {DeterministicModuleIdsPluginOptions} [options] options
29
33
  */
30
34
  constructor(options = {}) {
31
35
  this.options = options;
@@ -16,6 +16,7 @@ const {
16
16
  } = require("./IdHelpers");
17
17
 
18
18
  /** @typedef {import("../../declarations/plugins/HashedModuleIdsPlugin").HashedModuleIdsPluginOptions} HashedModuleIdsPluginOptions */
19
+ /** @typedef {import("../Compiler")} Compiler */
19
20
 
20
21
  const validate = createSchemaValidation(
21
22
  require("../../schemas/plugins/HashedModuleIdsPlugin.check.js"),
@@ -43,6 +44,11 @@ class HashedModuleIdsPlugin {
43
44
  };
44
45
  }
45
46
 
47
+ /**
48
+ * Apply the plugin
49
+ * @param {Compiler} compiler the compiler instance
50
+ * @returns {void}
51
+ */
46
52
  apply(compiler) {
47
53
  const options = this.options;
48
54
  compiler.hooks.compilation.tap("HashedModuleIdsPlugin", compilation => {
@@ -64,7 +70,8 @@ class HashedModuleIdsPlugin {
64
70
  hash.digest(options.hashDigest)
65
71
  );
66
72
  let len = options.hashDigestLength;
67
- while (usedIds.has(hashId.slice(0, len))) len++;
73
+ while (usedIds.has(hashId.slice(0, len)))
74
+ /** @type {number} */ (len)++;
68
75
  const moduleId = hashId.slice(0, len);
69
76
  chunkGraph.setModuleId(module, moduleId);
70
77
  usedIds.add(moduleId);
@@ -427,6 +427,9 @@ const assignAscendingModuleIds = (usedIds, modules, compilation) => {
427
427
  let nextId = 0;
428
428
  let assignId;
429
429
  if (usedIds.size > 0) {
430
+ /**
431
+ * @param {Module} module the module
432
+ */
430
433
  assignId = module => {
431
434
  if (chunkGraph.getModuleId(module) === null) {
432
435
  while (usedIds.has(nextId + "")) nextId++;
@@ -434,6 +437,9 @@ const assignAscendingModuleIds = (usedIds, modules, compilation) => {
434
437
  }
435
438
  };
436
439
  } else {
440
+ /**
441
+ * @param {Module} module the module
442
+ */
437
443
  assignId = module => {
438
444
  if (chunkGraph.getModuleId(module) === null) {
439
445
  chunkGraph.setModuleId(module, nextId++);
@@ -14,11 +14,21 @@ const {
14
14
  assignAscendingChunkIds
15
15
  } = require("./IdHelpers");
16
16
 
17
+ /** @typedef {import("../../declarations/WebpackOptions").OutputNormalized} Output */
17
18
  /** @typedef {import("../Chunk")} Chunk */
18
19
  /** @typedef {import("../Compiler")} Compiler */
19
20
  /** @typedef {import("../Module")} Module */
20
21
 
22
+ /**
23
+ * @typedef {Object} NamedChunkIdsPluginOptions
24
+ * @property {string} [context] context
25
+ * @property {string} [delimiter] delimiter
26
+ */
27
+
21
28
  class NamedChunkIdsPlugin {
29
+ /**
30
+ * @param {NamedChunkIdsPluginOptions=} options options
31
+ */
22
32
  constructor(options) {
23
33
  this.delimiter = (options && options.delimiter) || "-";
24
34
  this.context = options && options.context;
@@ -31,7 +41,9 @@ class NamedChunkIdsPlugin {
31
41
  */
32
42
  apply(compiler) {
33
43
  compiler.hooks.compilation.tap("NamedChunkIdsPlugin", compilation => {
34
- const { hashFunction } = compilation.outputOptions;
44
+ const hashFunction =
45
+ /** @type {NonNullable<Output["hashFunction"]>} */
46
+ (compilation.outputOptions.hashFunction);
35
47
  compilation.hooks.chunkIds.tap("NamedChunkIdsPlugin", chunks => {
36
48
  const chunkGraph = compilation.chunkGraph;
37
49
  const context = this.context ? this.context : compiler.context;
@@ -14,12 +14,21 @@ const {
14
14
  assignAscendingModuleIds
15
15
  } = require("./IdHelpers");
16
16
 
17
+ /** @typedef {import("../../declarations/WebpackOptions").OutputNormalized} Output */
17
18
  /** @typedef {import("../Compiler")} Compiler */
18
19
  /** @typedef {import("../Module")} Module */
19
20
 
21
+ /**
22
+ * @typedef {Object} NamedModuleIdsPluginOptions
23
+ * @property {string} [context] context
24
+ */
25
+
20
26
  class NamedModuleIdsPlugin {
21
- constructor(options) {
22
- this.options = options || {};
27
+ /**
28
+ * @param {NamedModuleIdsPluginOptions} [options] options
29
+ */
30
+ constructor(options = {}) {
31
+ this.options = options;
23
32
  }
24
33
 
25
34
  /**
@@ -30,7 +39,9 @@ class NamedModuleIdsPlugin {
30
39
  apply(compiler) {
31
40
  const { root } = compiler;
32
41
  compiler.hooks.compilation.tap("NamedModuleIdsPlugin", compilation => {
33
- const { hashFunction } = compilation.outputOptions;
42
+ const hashFunction =
43
+ /** @type {NonNullable<Output["hashFunction"]>} */
44
+ (compilation.outputOptions.hashFunction);
34
45
  compilation.hooks.moduleIds.tap("NamedModuleIdsPlugin", () => {
35
46
  const chunkGraph = compilation.chunkGraph;
36
47
  const context = this.options.context
@@ -60,8 +60,12 @@ class OccurrenceChunkIdsPlugin {
60
60
 
61
61
  const chunksInOccurrenceOrder = Array.from(chunks).sort((a, b) => {
62
62
  if (prioritiseInitial) {
63
- const aEntryOccurs = occursInInitialChunksMap.get(a);
64
- const bEntryOccurs = occursInInitialChunksMap.get(b);
63
+ const aEntryOccurs =
64
+ /** @type {number} */
65
+ (occursInInitialChunksMap.get(a));
66
+ const bEntryOccurs =
67
+ /** @type {number} */
68
+ (occursInInitialChunksMap.get(b));
65
69
  if (aEntryOccurs > bEntryOccurs) return -1;
66
70
  if (aEntryOccurs < bEntryOccurs) return 1;
67
71
  }
@@ -50,7 +50,7 @@ class SyncModuleIdsPlugin {
50
50
  }
51
51
  return callback();
52
52
  }
53
- const json = JSON.parse(buffer.toString());
53
+ const json = JSON.parse(/** @type {Buffer} */ (buffer).toString());
54
54
  data = new Map();
55
55
  for (const key of Object.keys(json)) {
56
56
  data.set(key, json[key]);
@@ -98,7 +98,7 @@ class SyncModuleIdsPlugin {
98
98
  err.module = module;
99
99
  compilation.errors.push(err);
100
100
  }
101
- chunkGraph.setModuleId(module, id);
101
+ chunkGraph.setModuleId(module, /** @type {string | number} */ (id));
102
102
  usedIds.add(idAsString);
103
103
  }
104
104
  });
@@ -84,8 +84,8 @@ class ArrayPushCallbackChunkFormatPlugin {
84
84
  if (runtimeModules.length > 0 || entries.length > 0) {
85
85
  const runtime = new ConcatSource(
86
86
  (runtimeTemplate.supportsArrowFunction()
87
- ? "__webpack_require__ =>"
88
- : "function(__webpack_require__)") +
87
+ ? `${RuntimeGlobals.require} =>`
88
+ : `function(${RuntimeGlobals.require})`) +
89
89
  " { // webpackRuntimeModules\n"
90
90
  );
91
91
  if (runtimeModules.length > 0) {
@@ -121,7 +121,7 @@ class ArrayPushCallbackChunkFormatPlugin {
121
121
  .getChunkRuntimeRequirements(chunk)
122
122
  .has(RuntimeGlobals.returnExportsFromRuntime)
123
123
  ) {
124
- runtime.add("return __webpack_exports__;\n");
124
+ runtime.add(`return ${RuntimeGlobals.exports};\n`);
125
125
  }
126
126
  }
127
127
  runtime.add("}\n");
@@ -70,6 +70,8 @@ class BasicEvaluatedExpression {
70
70
  this.getMembers = undefined;
71
71
  /** @type {() => boolean[]} */
72
72
  this.getMembersOptionals = undefined;
73
+ /** @type {() => number[]} */
74
+ this.getMemberRangeStarts = undefined;
73
75
  /** @type {EsTreeNode} */
74
76
  this.expression = undefined;
75
77
  }
@@ -384,14 +386,22 @@ class BasicEvaluatedExpression {
384
386
  * @param {string | VariableInfoInterface} rootInfo root info
385
387
  * @param {() => string[]} getMembers members
386
388
  * @param {() => boolean[]=} getMembersOptionals optional members
389
+ * @param {() => number[]=} getMemberRangeStarts range start of progressively increasing sub-expressions
387
390
  * @returns {this} this
388
391
  */
389
- setIdentifier(identifier, rootInfo, getMembers, getMembersOptionals) {
392
+ setIdentifier(
393
+ identifier,
394
+ rootInfo,
395
+ getMembers,
396
+ getMembersOptionals,
397
+ getMemberRangeStarts
398
+ ) {
390
399
  this.type = TypeIdentifier;
391
400
  this.identifier = identifier;
392
401
  this.rootInfo = rootInfo;
393
402
  this.getMembers = getMembers;
394
403
  this.getMembersOptionals = getMembersOptionals;
404
+ this.getMemberRangeStarts = getMemberRangeStarts;
395
405
  this.sideEffects = true;
396
406
  return this;
397
407
  }
@@ -11,8 +11,8 @@ const Entrypoint = require("../Entrypoint");
11
11
 
12
12
  /**
13
13
  * @param {Entrypoint} entrypoint a chunk group
14
- * @param {Chunk} excludedChunk1 current chunk which is excluded
15
- * @param {Chunk} excludedChunk2 runtime chunk which is excluded
14
+ * @param {Chunk=} excludedChunk1 current chunk which is excluded
15
+ * @param {Chunk=} excludedChunk2 runtime chunk which is excluded
16
16
  * @returns {Set<Chunk>} chunks
17
17
  */
18
18
  const getAllChunks = (entrypoint, excludedChunk1, excludedChunk2) => {
@@ -120,7 +120,7 @@ class CommonJsChunkFormatPlugin {
120
120
  entrySource.add(source);
121
121
  entrySource.add(";\n\n// load runtime\n");
122
122
  entrySource.add(
123
- `var __webpack_require__ = require(${JSON.stringify(
123
+ `var ${RuntimeGlobals.require} = require(${JSON.stringify(
124
124
  runtimePath
125
125
  )});\n`
126
126
  );
@@ -11,6 +11,10 @@
11
11
  /** @type {WeakMap<Compiler, Set<ChunkLoadingType>>} */
12
12
  const enabledTypes = new WeakMap();
13
13
 
14
+ /**
15
+ * @param {Compiler} compiler compiler
16
+ * @returns {Set<ChunkLoadingType>} enabled types
17
+ */
14
18
  const getEnabledTypes = compiler => {
15
19
  let set = enabledTypes.get(compiler);
16
20
  if (set === undefined) {