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
@@ -14,7 +14,8 @@ const {
14
14
  JAVASCRIPT_MODULE_TYPE_ESM,
15
15
  JAVASCRIPT_MODULE_TYPE_DYNAMIC,
16
16
  WEBASSEMBLY_MODULE_TYPE_SYNC,
17
- ASSET_MODULE_TYPE
17
+ ASSET_MODULE_TYPE,
18
+ CSS_MODULE_TYPE
18
19
  } = require("../ModuleTypeConstants");
19
20
  const Template = require("../Template");
20
21
  const { cleverMerge } = require("../util/cleverMerge");
@@ -25,30 +26,39 @@ const {
25
26
  } = require("./target");
26
27
 
27
28
  /** @typedef {import("../../declarations/WebpackOptions").CacheOptionsNormalized} CacheOptions */
29
+ /** @typedef {import("../../declarations/WebpackOptions").Context} Context */
28
30
  /** @typedef {import("../../declarations/WebpackOptions").CssExperimentOptions} CssExperimentOptions */
29
31
  /** @typedef {import("../../declarations/WebpackOptions").EntryDescription} EntryDescription */
30
32
  /** @typedef {import("../../declarations/WebpackOptions").EntryNormalized} Entry */
33
+ /** @typedef {import("../../declarations/WebpackOptions").EntryStaticNormalized} EntryStaticNormalized */
34
+ /** @typedef {import("../../declarations/WebpackOptions").Environment} Environment */
31
35
  /** @typedef {import("../../declarations/WebpackOptions").Experiments} Experiments */
32
36
  /** @typedef {import("../../declarations/WebpackOptions").ExperimentsNormalized} ExperimentsNormalized */
33
37
  /** @typedef {import("../../declarations/WebpackOptions").ExternalsPresets} ExternalsPresets */
34
38
  /** @typedef {import("../../declarations/WebpackOptions").ExternalsType} ExternalsType */
39
+ /** @typedef {import("../../declarations/WebpackOptions").FileCacheOptions} FileCacheOptions */
35
40
  /** @typedef {import("../../declarations/WebpackOptions").InfrastructureLogging} InfrastructureLogging */
36
41
  /** @typedef {import("../../declarations/WebpackOptions").JavascriptParserOptions} JavascriptParserOptions */
37
42
  /** @typedef {import("../../declarations/WebpackOptions").Library} Library */
38
43
  /** @typedef {import("../../declarations/WebpackOptions").LibraryName} LibraryName */
39
44
  /** @typedef {import("../../declarations/WebpackOptions").LibraryOptions} LibraryOptions */
45
+ /** @typedef {import("../../declarations/WebpackOptions").LibraryType} LibraryType */
40
46
  /** @typedef {import("../../declarations/WebpackOptions").Loader} Loader */
41
47
  /** @typedef {import("../../declarations/WebpackOptions").Mode} Mode */
42
48
  /** @typedef {import("../../declarations/WebpackOptions").ModuleOptionsNormalized} ModuleOptions */
43
49
  /** @typedef {import("../../declarations/WebpackOptions").Node} WebpackNode */
44
50
  /** @typedef {import("../../declarations/WebpackOptions").Optimization} Optimization */
51
+ /** @typedef {import("../../declarations/WebpackOptions").OptimizationSplitChunksOptions} OptimizationSplitChunksOptions */
45
52
  /** @typedef {import("../../declarations/WebpackOptions").OutputNormalized} Output */
53
+ /** @typedef {import("../../declarations/WebpackOptions").ParserOptionsByModuleTypeKnown} ParserOptionsByModuleTypeKnown */
46
54
  /** @typedef {import("../../declarations/WebpackOptions").Performance} Performance */
47
55
  /** @typedef {import("../../declarations/WebpackOptions").ResolveOptions} ResolveOptions */
48
56
  /** @typedef {import("../../declarations/WebpackOptions").RuleSetRules} RuleSetRules */
49
57
  /** @typedef {import("../../declarations/WebpackOptions").SnapshotOptions} SnapshotOptions */
50
58
  /** @typedef {import("../../declarations/WebpackOptions").Target} Target */
51
59
  /** @typedef {import("../../declarations/WebpackOptions").WebpackOptionsNormalized} WebpackOptions */
60
+ /** @typedef {import("../Compiler")} Compiler */
61
+ /** @typedef {import("../Module")} Module */
52
62
  /** @typedef {import("./target").TargetProperties} TargetProperties */
53
63
 
54
64
  const NODE_MODULES_REGEXP = /[\\/]node_modules[\\/]/i;
@@ -100,7 +110,7 @@ const A = (obj, prop, factory) => {
100
110
  if (value === undefined) {
101
111
  obj[prop] = factory();
102
112
  } else if (Array.isArray(value)) {
103
- /** @type {any[]} */
113
+ /** @type {any[] | undefined} */
104
114
  let newArray = undefined;
105
115
  for (let i = 0; i < value.length; i++) {
106
116
  const item = value[i];
@@ -138,7 +148,7 @@ const applyWebpackOptionsBaseDefaults = options => {
138
148
  const applyWebpackOptionsDefaults = options => {
139
149
  F(options, "context", () => process.cwd());
140
150
  F(options, "target", () => {
141
- return getDefaultTarget(options.context);
151
+ return getDefaultTarget(/** @type {string} */ (options.context));
142
152
  });
143
153
 
144
154
  const { mode, name, target } = options;
@@ -147,8 +157,11 @@ const applyWebpackOptionsDefaults = options => {
147
157
  target === false
148
158
  ? /** @type {false} */ (false)
149
159
  : typeof target === "string"
150
- ? getTargetProperties(target, options.context)
151
- : getTargetsProperties(target, options.context);
160
+ ? getTargetProperties(target, /** @type {Context} */ (options.context))
161
+ : getTargetsProperties(
162
+ /** @type {string[]} */ (target),
163
+ /** @type {Context} */ (options.context)
164
+ );
152
165
 
153
166
  const development = mode === "development";
154
167
  const production = mode === "production" || !mode;
@@ -176,7 +189,9 @@ const applyWebpackOptionsDefaults = options => {
176
189
  targetProperties
177
190
  });
178
191
 
179
- const futureDefaults = options.experiments.futureDefaults;
192
+ const futureDefaults =
193
+ /** @type {NonNullable<ExperimentsNormalized["futureDefaults"]>} */
194
+ (options.experiments.futureDefaults);
180
195
 
181
196
  F(options, "cache", () =>
182
197
  development ? { type: /** @type {"memory"} */ ("memory") } : false
@@ -196,22 +211,30 @@ const applyWebpackOptionsDefaults = options => {
196
211
 
197
212
  applyModuleDefaults(options.module, {
198
213
  cache,
199
- syncWebAssembly: options.experiments.syncWebAssembly,
200
- asyncWebAssembly: options.experiments.asyncWebAssembly,
201
- css: options.experiments.css,
214
+ syncWebAssembly:
215
+ /** @type {NonNullable<ExperimentsNormalized["syncWebAssembly"]>} */
216
+ (options.experiments.syncWebAssembly),
217
+ asyncWebAssembly:
218
+ /** @type {NonNullable<ExperimentsNormalized["asyncWebAssembly"]>} */
219
+ (options.experiments.asyncWebAssembly),
220
+ css:
221
+ /** @type {NonNullable<ExperimentsNormalized["css"]>} */
222
+ (options.experiments.css),
202
223
  futureDefaults,
203
224
  isNode: targetProperties && targetProperties.node === true
204
225
  });
205
226
 
206
227
  applyOutputDefaults(options.output, {
207
- context: options.context,
228
+ context: /** @type {Context} */ (options.context),
208
229
  targetProperties,
209
230
  isAffectedByBrowserslist:
210
231
  target === undefined ||
211
232
  (typeof target === "string" && target.startsWith("browserslist")) ||
212
233
  (Array.isArray(target) &&
213
234
  target.some(target => target.startsWith("browserslist"))),
214
- outputModule: options.experiments.outputModule,
235
+ outputModule:
236
+ /** @type {NonNullable<ExperimentsNormalized["outputModule"]>} */
237
+ (options.experiments.outputModule),
215
238
  development,
216
239
  entry: options.entry,
217
240
  module: options.module,
@@ -223,7 +246,10 @@ const applyWebpackOptionsDefaults = options => {
223
246
  buildHttp: !!options.experiments.buildHttp
224
247
  });
225
248
 
226
- applyLoaderDefaults(options.loader, { targetProperties });
249
+ applyLoaderDefaults(
250
+ /** @type {NonNullable<WebpackOptions["loader"]>} */ (options.loader),
251
+ { targetProperties, environment: options.output.environment }
252
+ );
227
253
 
228
254
  F(options, "externalsType", () => {
229
255
  const validExternalTypes = require("../../schemas/WebpackOptions.json")
@@ -237,7 +263,9 @@ const applyWebpackOptionsDefaults = options => {
237
263
  });
238
264
 
239
265
  applyNodeDefaults(options.node, {
240
- futureDefaults: options.experiments.futureDefaults,
266
+ futureDefaults:
267
+ /** @type {NonNullable<WebpackOptions["experiments"]["futureDefaults"]>} */
268
+ (options.experiments.futureDefaults),
241
269
  targetProperties
242
270
  });
243
271
 
@@ -248,23 +276,29 @@ const applyWebpackOptionsDefaults = options => {
248
276
  ? {}
249
277
  : false
250
278
  );
251
- applyPerformanceDefaults(options.performance, {
252
- production
253
- });
279
+ applyPerformanceDefaults(
280
+ /** @type {NonNullable<WebpackOptions["performance"]>} */
281
+ (options.performance),
282
+ {
283
+ production
284
+ }
285
+ );
254
286
 
255
287
  applyOptimizationDefaults(options.optimization, {
256
288
  development,
257
289
  production,
258
- css: options.experiments.css,
290
+ css:
291
+ /** @type {NonNullable<ExperimentsNormalized["css"]>} */
292
+ (options.experiments.css),
259
293
  records: !!(options.recordsInputPath || options.recordsOutputPath)
260
294
  });
261
295
 
262
296
  options.resolve = cleverMerge(
263
297
  getResolveDefaults({
264
298
  cache,
265
- context: options.context,
299
+ context: /** @type {Context} */ (options.context),
266
300
  targetProperties,
267
- mode: options.mode
301
+ mode: /** @type {Mode} */ (options.mode)
268
302
  }),
269
303
  options.resolve
270
304
  );
@@ -323,9 +357,9 @@ const applyExperimentsDefaults = (
323
357
  * @param {CacheOptions} cache options
324
358
  * @param {Object} options options
325
359
  * @param {string} options.name name
326
- * @param {string} options.mode mode
360
+ * @param {Mode} options.mode mode
327
361
  * @param {boolean} options.development is development mode
328
- * @param {boolean} options.cacheUnaffected the cacheUnaffected experiment is enabled
362
+ * @param {Experiments["cacheUnaffected"]} options.cacheUnaffected the cacheUnaffected experiment is enabled
329
363
  * @returns {void}
330
364
  */
331
365
  const applyCacheDefaults = (
@@ -339,6 +373,7 @@ const applyCacheDefaults = (
339
373
  D(cache, "version", "");
340
374
  F(cache, "cacheDirectory", () => {
341
375
  const cwd = process.cwd();
376
+ /** @type {string | undefined} */
342
377
  let dir = cwd;
343
378
  for (;;) {
344
379
  try {
@@ -363,7 +398,11 @@ const applyCacheDefaults = (
363
398
  }
364
399
  });
365
400
  F(cache, "cacheLocation", () =>
366
- path.resolve(cache.cacheDirectory, cache.name)
401
+ path.resolve(
402
+ /** @type {NonNullable<FileCacheOptions["cacheDirectory"]>} */
403
+ (cache.cacheDirectory),
404
+ /** @type {NonNullable<FileCacheOptions["name"]>} */ (cache.name)
405
+ )
367
406
  );
368
407
  D(cache, "hashAlgorithm", "md4");
369
408
  D(cache, "store", "pack");
@@ -376,9 +415,13 @@ const applyCacheDefaults = (
376
415
  D(cache, "maxAge", 1000 * 60 * 60 * 24 * 60); // 1 month
377
416
  D(cache, "allowCollectingMemory", development);
378
417
  D(cache, "memoryCacheUnaffected", development && cacheUnaffected);
379
- D(cache.buildDependencies, "defaultWebpack", [
380
- path.resolve(__dirname, "..") + path.sep
381
- ]);
418
+ D(cache, "readonly", false);
419
+ D(
420
+ /** @type {NonNullable<FileCacheOptions["buildDependencies"]>} */
421
+ (cache.buildDependencies),
422
+ "defaultWebpack",
423
+ [path.resolve(__dirname, "..") + path.sep]
424
+ );
382
425
  break;
383
426
  case "memory":
384
427
  D(cache, "maxGenerations", Infinity);
@@ -510,25 +553,53 @@ const applyModuleDefaults = (
510
553
  { cache, syncWebAssembly, asyncWebAssembly, css, futureDefaults, isNode }
511
554
  ) => {
512
555
  if (cache) {
513
- D(module, "unsafeCache", module => {
514
- const name = module.nameForCondition();
515
- return name && NODE_MODULES_REGEXP.test(name);
516
- });
556
+ D(
557
+ module,
558
+ "unsafeCache",
559
+ /**
560
+ * @param {Module} module module
561
+ * @returns {boolean | null | string} true, if we want to cache the module
562
+ */
563
+ module => {
564
+ const name = module.nameForCondition();
565
+ return name && NODE_MODULES_REGEXP.test(name);
566
+ }
567
+ );
517
568
  } else {
518
569
  D(module, "unsafeCache", false);
519
570
  }
520
571
 
521
572
  F(module.parser, ASSET_MODULE_TYPE, () => ({}));
522
- F(module.parser.asset, "dataUrlCondition", () => ({}));
523
- if (typeof module.parser.asset.dataUrlCondition === "object") {
524
- D(module.parser.asset.dataUrlCondition, "maxSize", 8096);
573
+ F(
574
+ /** @type {NonNullable<ParserOptionsByModuleTypeKnown["asset"]>} */
575
+ (module.parser.asset),
576
+ "dataUrlCondition",
577
+ () => ({})
578
+ );
579
+ if (
580
+ typeof (
581
+ /** @type {NonNullable<ParserOptionsByModuleTypeKnown["asset"]>} */
582
+ (module.parser.asset).dataUrlCondition
583
+ ) === "object"
584
+ ) {
585
+ D(
586
+ /** @type {NonNullable<ParserOptionsByModuleTypeKnown["asset"]>} */
587
+ (module.parser.asset).dataUrlCondition,
588
+ "maxSize",
589
+ 8096
590
+ );
525
591
  }
526
592
 
527
593
  F(module.parser, "javascript", () => ({}));
528
- applyJavascriptParserOptionsDefaults(module.parser.javascript, {
529
- futureDefaults,
530
- isNode
531
- });
594
+
595
+ applyJavascriptParserOptionsDefaults(
596
+ /** @type {NonNullable<ParserOptionsByModuleTypeKnown["javascript"]>} */
597
+ (module.parser.javascript),
598
+ {
599
+ futureDefaults,
600
+ isNode
601
+ }
602
+ );
532
603
 
533
604
  A(module, "defaultRules", () => {
534
605
  const esm = {
@@ -634,7 +705,7 @@ const applyModuleDefaults = (
634
705
  }
635
706
  if (css) {
636
707
  const cssRule = {
637
- type: "css",
708
+ type: CSS_MODULE_TYPE,
638
709
  resolve: {
639
710
  fullySpecified: true,
640
711
  preferRelative: true
@@ -726,7 +797,7 @@ const applyOutputDefaults = (
726
797
  !Array.isArray(library) &&
727
798
  "type" in library
728
799
  ? library.name
729
- : /** @type {LibraryName=} */ (library);
800
+ : /** @type {LibraryName} */ (library);
730
801
  if (Array.isArray(libraryName)) {
731
802
  return libraryName.join(".");
732
803
  } else if (typeof libraryName === "object") {
@@ -753,8 +824,11 @@ const applyOutputDefaults = (
753
824
  const packageInfo = JSON.parse(fs.readFileSync(pkgPath, "utf-8"));
754
825
  return packageInfo.name || "";
755
826
  } catch (e) {
756
- if (e.code !== "ENOENT") {
757
- e.message += `\nwhile determining default 'output.uniqueName' from 'name' in ${pkgPath}`;
827
+ if (/** @type {Error & { code: string }} */ (e).code !== "ENOENT") {
828
+ /** @type {Error & { code: string }} */
829
+ (
830
+ e
831
+ ).message += `\nwhile determining default 'output.uniqueName' from 'name' in ${pkgPath}`;
758
832
  throw e;
759
833
  }
760
834
  return "";
@@ -767,7 +841,9 @@ const applyOutputDefaults = (
767
841
  D(output, "importFunctionName", "import");
768
842
  D(output, "importMetaName", "import.meta");
769
843
  F(output, "chunkFilename", () => {
770
- const filename = output.filename;
844
+ const filename =
845
+ /** @type {NonNullable<Output["chunkFilename"]>} */
846
+ (output.filename);
771
847
  if (typeof filename !== "function") {
772
848
  const hasName = filename.includes("[name]");
773
849
  const hasId = filename.includes("[id]");
@@ -781,14 +857,18 @@ const applyOutputDefaults = (
781
857
  return output.module ? "[id].mjs" : "[id].js";
782
858
  });
783
859
  F(output, "cssFilename", () => {
784
- const filename = output.filename;
860
+ const filename =
861
+ /** @type {NonNullable<Output["cssFilename"]>} */
862
+ (output.filename);
785
863
  if (typeof filename !== "function") {
786
864
  return filename.replace(/\.[mc]?js(\?|$)/, ".css$1");
787
865
  }
788
866
  return "[id].css";
789
867
  });
790
868
  F(output, "cssChunkFilename", () => {
791
- const chunkFilename = output.chunkFilename;
869
+ const chunkFilename =
870
+ /** @type {NonNullable<Output["cssChunkFilename"]>} */
871
+ (output.chunkFilename);
792
872
  if (typeof chunkFilename !== "function") {
793
873
  return chunkFilename.replace(/\.[mc]?js(\?|$)/, ".css$1");
794
874
  }
@@ -800,12 +880,18 @@ const applyOutputDefaults = (
800
880
  D(output, "charset", true);
801
881
  F(output, "hotUpdateGlobal", () =>
802
882
  Template.toIdentifier(
803
- "webpackHotUpdate" + Template.toIdentifier(output.uniqueName)
883
+ "webpackHotUpdate" +
884
+ Template.toIdentifier(
885
+ /** @type {NonNullable<Output["uniqueName"]>} */ (output.uniqueName)
886
+ )
804
887
  )
805
888
  );
806
889
  F(output, "chunkLoadingGlobal", () =>
807
890
  Template.toIdentifier(
808
- "webpackChunk" + Template.toIdentifier(output.uniqueName)
891
+ "webpackChunk" +
892
+ Template.toIdentifier(
893
+ /** @type {NonNullable<Output["uniqueName"]>} */ (output.uniqueName)
894
+ )
809
895
  )
810
896
  );
811
897
  F(output, "globalObject", () => {
@@ -938,26 +1024,80 @@ const applyOutputDefaults = (
938
1024
  D(output, "hashDigestLength", futureDefaults ? 16 : 20);
939
1025
  D(output, "strictModuleExceptionHandling", false);
940
1026
 
1027
+ const environment = /** @type {Environment} */ (output.environment);
1028
+ /**
1029
+ * @param {boolean | undefined} v value
1030
+ * @returns {boolean} true, when v is truthy or undefined
1031
+ */
941
1032
  const optimistic = v => v || v === undefined;
1033
+ /**
1034
+ * @param {boolean | undefined} v value
1035
+ * @param {boolean | undefined} c condition
1036
+ * @returns {boolean | undefined} true, when v is truthy or undefined, or c is truthy
1037
+ */
942
1038
  const conditionallyOptimistic = (v, c) => (v === undefined && c) || v;
1039
+
1040
+ F(
1041
+ environment,
1042
+ "globalThis",
1043
+ () => /** @type {boolean | undefined} */ (tp && tp.globalThis)
1044
+ );
1045
+ F(
1046
+ environment,
1047
+ "bigIntLiteral",
1048
+ () => /** @type {boolean | undefined} */ (tp && tp.bigIntLiteral)
1049
+ );
943
1050
  F(
944
- output.environment,
1051
+ environment,
1052
+ "const",
1053
+ () => tp && optimistic(/** @type {boolean | undefined} */ (tp.const))
1054
+ );
1055
+ F(
1056
+ environment,
945
1057
  "arrowFunction",
946
- () => tp && optimistic(tp.arrowFunction)
1058
+ () =>
1059
+ tp && optimistic(/** @type {boolean | undefined} */ (tp.arrowFunction))
1060
+ );
1061
+ F(
1062
+ environment,
1063
+ "forOf",
1064
+ () => tp && optimistic(/** @type {boolean | undefined} */ (tp.forOf))
947
1065
  );
948
- F(output.environment, "const", () => tp && optimistic(tp.const));
949
1066
  F(
950
- output.environment,
1067
+ environment,
951
1068
  "destructuring",
952
- () => tp && optimistic(tp.destructuring)
1069
+ () =>
1070
+ tp && optimistic(/** @type {boolean | undefined} */ (tp.destructuring))
953
1071
  );
954
- F(output.environment, "forOf", () => tp && optimistic(tp.forOf));
955
- F(output.environment, "bigIntLiteral", () => tp && tp.bigIntLiteral);
956
- F(output.environment, "dynamicImport", () =>
957
- conditionallyOptimistic(tp && tp.dynamicImport, output.module)
1072
+ F(
1073
+ environment,
1074
+ "optionalChaining",
1075
+ () =>
1076
+ tp && optimistic(/** @type {boolean | undefined} */ (tp.optionalChaining))
1077
+ );
1078
+ F(
1079
+ environment,
1080
+ "templateLiteral",
1081
+ () =>
1082
+ tp && optimistic(/** @type {boolean | undefined} */ (tp.templateLiteral))
958
1083
  );
959
- F(output.environment, "module", () =>
960
- conditionallyOptimistic(tp && tp.module, output.module)
1084
+ F(environment, "dynamicImport", () =>
1085
+ conditionallyOptimistic(
1086
+ /** @type {boolean | undefined} */ (tp && tp.dynamicImport),
1087
+ output.module
1088
+ )
1089
+ );
1090
+ F(environment, "dynamicImportInWorker", () =>
1091
+ conditionallyOptimistic(
1092
+ /** @type {boolean | undefined} */ (tp && tp.dynamicImportInWorker),
1093
+ output.module
1094
+ )
1095
+ );
1096
+ F(environment, "module", () =>
1097
+ conditionallyOptimistic(
1098
+ /** @type {boolean | undefined} */ (tp && tp.module),
1099
+ output.module
1100
+ )
961
1101
  );
962
1102
 
963
1103
  const { trustedTypes } = output;
@@ -966,7 +1106,8 @@ const applyOutputDefaults = (
966
1106
  trustedTypes,
967
1107
  "policyName",
968
1108
  () =>
969
- output.uniqueName.replace(/[^a-zA-Z0-9\-#=_/@.%]+/g, "_") || "webpack"
1109
+ /** @type {NonNullable<Output["uniqueName"]>} */
1110
+ (output.uniqueName).replace(/[^a-zA-Z0-9\-#=_/@.%]+/g, "_") || "webpack"
970
1111
  );
971
1112
  D(trustedTypes, "onPolicyCreationFailure", "stop");
972
1113
  }
@@ -977,10 +1118,11 @@ const applyOutputDefaults = (
977
1118
  */
978
1119
  const forEachEntry = fn => {
979
1120
  for (const name of Object.keys(entry)) {
980
- fn(entry[name]);
1121
+ fn(/** @type {{[k: string] : EntryDescription}} */ (entry)[name]);
981
1122
  }
982
1123
  };
983
1124
  A(output, "enabledLibraryTypes", () => {
1125
+ /** @type {LibraryType[]} */
984
1126
  const enabledLibraryTypes = [];
985
1127
  if (output.library) {
986
1128
  enabledLibraryTypes.push(output.library.type);
@@ -1040,35 +1182,56 @@ const applyExternalsPresetsDefaults = (
1040
1182
  D(
1041
1183
  externalsPresets,
1042
1184
  "web",
1043
- !buildHttp && targetProperties && targetProperties.web
1185
+ /** @type {boolean | undefined} */
1186
+ (!buildHttp && targetProperties && targetProperties.web)
1187
+ );
1188
+ D(
1189
+ externalsPresets,
1190
+ "node",
1191
+ /** @type {boolean | undefined} */
1192
+ (targetProperties && targetProperties.node)
1193
+ );
1194
+ D(
1195
+ externalsPresets,
1196
+ "nwjs",
1197
+ /** @type {boolean | undefined} */
1198
+ (targetProperties && targetProperties.nwjs)
1044
1199
  );
1045
- D(externalsPresets, "node", targetProperties && targetProperties.node);
1046
- D(externalsPresets, "nwjs", targetProperties && targetProperties.nwjs);
1047
1200
  D(
1048
1201
  externalsPresets,
1049
1202
  "electron",
1050
- targetProperties && targetProperties.electron
1203
+ /** @type {boolean | undefined} */
1204
+ (targetProperties && targetProperties.electron)
1051
1205
  );
1052
1206
  D(
1053
1207
  externalsPresets,
1054
1208
  "electronMain",
1055
- targetProperties &&
1056
- targetProperties.electron &&
1057
- targetProperties.electronMain
1209
+ /** @type {boolean | undefined} */
1210
+ (
1211
+ targetProperties &&
1212
+ targetProperties.electron &&
1213
+ targetProperties.electronMain
1214
+ )
1058
1215
  );
1059
1216
  D(
1060
1217
  externalsPresets,
1061
1218
  "electronPreload",
1062
- targetProperties &&
1063
- targetProperties.electron &&
1064
- targetProperties.electronPreload
1219
+ /** @type {boolean | undefined} */
1220
+ (
1221
+ targetProperties &&
1222
+ targetProperties.electron &&
1223
+ targetProperties.electronPreload
1224
+ )
1065
1225
  );
1066
1226
  D(
1067
1227
  externalsPresets,
1068
1228
  "electronRenderer",
1069
- targetProperties &&
1070
- targetProperties.electron &&
1071
- targetProperties.electronRenderer
1229
+ /** @type {boolean | undefined} */
1230
+ (
1231
+ targetProperties &&
1232
+ targetProperties.electron &&
1233
+ targetProperties.electronRenderer
1234
+ )
1072
1235
  );
1073
1236
  };
1074
1237
 
@@ -1076,9 +1239,10 @@ const applyExternalsPresetsDefaults = (
1076
1239
  * @param {Loader} loader options
1077
1240
  * @param {Object} options options
1078
1241
  * @param {TargetProperties | false} options.targetProperties target properties
1242
+ * @param {Environment} options.environment environment
1079
1243
  * @returns {void}
1080
1244
  */
1081
- const applyLoaderDefaults = (loader, { targetProperties }) => {
1245
+ const applyLoaderDefaults = (loader, { targetProperties, environment }) => {
1082
1246
  F(loader, "target", () => {
1083
1247
  if (targetProperties) {
1084
1248
  if (targetProperties.electron) {
@@ -1092,6 +1256,7 @@ const applyLoaderDefaults = (loader, { targetProperties }) => {
1092
1256
  if (targetProperties.web) return "web";
1093
1257
  }
1094
1258
  });
1259
+ D(loader, "environment", environment);
1095
1260
  };
1096
1261
 
1097
1262
  /**
@@ -1209,7 +1374,9 @@ const applyOptimizationDefaults = (
1209
1374
  F(splitChunks, "maxAsyncRequests", () => (production ? 30 : Infinity));
1210
1375
  F(splitChunks, "maxInitialRequests", () => (production ? 30 : Infinity));
1211
1376
  D(splitChunks, "automaticNameDelimiter", "-");
1212
- const { cacheGroups } = splitChunks;
1377
+ const cacheGroups =
1378
+ /** @type {NonNullable<OptimizationSplitChunksOptions["cacheGroups"]>} */
1379
+ (splitChunks.cacheGroups);
1213
1380
  F(cacheGroups, "default", () => ({
1214
1381
  idHint: "",
1215
1382
  reuseExistingChunk: true,