webpack 5.91.0 → 5.92.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 (174) hide show
  1. package/bin/webpack.js +1 -2
  2. package/lib/APIPlugin.js +6 -2
  3. package/lib/Cache.js +1 -1
  4. package/lib/Chunk.js +7 -4
  5. package/lib/ChunkGraph.js +20 -7
  6. package/lib/ChunkGroup.js +9 -3
  7. package/lib/CleanPlugin.js +1 -1
  8. package/lib/Compilation.js +33 -27
  9. package/lib/Compiler.js +28 -8
  10. package/lib/ConcatenationScope.js +3 -3
  11. package/lib/ContextModule.js +95 -43
  12. package/lib/DefinePlugin.js +14 -4
  13. package/lib/Dependency.js +8 -8
  14. package/lib/DependencyTemplate.js +10 -5
  15. package/lib/DllReferencePlugin.js +1 -1
  16. package/lib/EvalDevToolModulePlugin.js +11 -0
  17. package/lib/ExportsInfo.js +22 -4
  18. package/lib/ExternalModule.js +49 -18
  19. package/lib/FileSystemInfo.js +68 -41
  20. package/lib/FlagDependencyExportsPlugin.js +21 -7
  21. package/lib/Generator.js +2 -3
  22. package/lib/HotModuleReplacementPlugin.js +108 -45
  23. package/lib/IgnorePlugin.js +4 -1
  24. package/lib/LibManifestPlugin.js +2 -2
  25. package/lib/Module.js +11 -12
  26. package/lib/ModuleFactory.js +3 -3
  27. package/lib/ModuleFilenameHelpers.js +29 -16
  28. package/lib/ModuleGraph.js +5 -5
  29. package/lib/MultiCompiler.js +36 -1
  30. package/lib/NormalModule.js +10 -12
  31. package/lib/NormalModuleFactory.js +17 -8
  32. package/lib/Parser.js +1 -1
  33. package/lib/PlatformPlugin.js +39 -0
  34. package/lib/ProgressPlugin.js +1 -1
  35. package/lib/RecordIdsPlugin.js +4 -4
  36. package/lib/ResolverFactory.js +3 -3
  37. package/lib/RuntimeTemplate.js +22 -18
  38. package/lib/Stats.js +1 -1
  39. package/lib/Template.js +5 -5
  40. package/lib/TemplatedPathPlugin.js +16 -1
  41. package/lib/asset/AssetGenerator.js +15 -0
  42. package/lib/buildChunkGraph.js +3 -3
  43. package/lib/cache/MemoryWithGcCachePlugin.js +1 -1
  44. package/lib/cache/PackFileCacheStrategy.js +2 -2
  45. package/lib/cache/ResolverCachePlugin.js +8 -8
  46. package/lib/cache/getLazyHashedEtag.js +1 -1
  47. package/lib/cli.js +5 -5
  48. package/lib/config/browserslistTargetHandler.js +7 -1
  49. package/lib/config/defaults.js +85 -34
  50. package/lib/config/target.js +18 -11
  51. package/lib/container/ContainerEntryModule.js +1 -1
  52. package/lib/css/CssExportsGenerator.js +43 -17
  53. package/lib/css/CssGenerator.js +22 -12
  54. package/lib/css/CssLoadingRuntimeModule.js +8 -5
  55. package/lib/css/CssModulesPlugin.js +197 -100
  56. package/lib/css/CssParser.js +24 -15
  57. package/lib/css/walkCssTokens.js +1 -1
  58. package/lib/debug/ProfilingPlugin.js +1 -1
  59. package/lib/dependencies/ContextElementDependency.js +2 -2
  60. package/lib/dependencies/CssExportDependency.js +2 -2
  61. package/lib/dependencies/CssLocalIdentifierDependency.js +9 -2
  62. package/lib/dependencies/CssUrlDependency.js +5 -4
  63. package/lib/dependencies/ExportsInfoDependency.js +1 -1
  64. package/lib/dependencies/ExternalModuleDependency.js +4 -2
  65. package/lib/dependencies/HarmonyEvaluatedImportSpecifierDependency.js +2 -2
  66. package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +2 -2
  67. package/lib/dependencies/HarmonyImportDependency.js +2 -2
  68. package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +41 -18
  69. package/lib/dependencies/HarmonyImportSideEffectDependency.js +2 -2
  70. package/lib/dependencies/HarmonyImportSpecifierDependency.js +43 -32
  71. package/lib/dependencies/ImportDependency.js +2 -2
  72. package/lib/dependencies/ImportEagerDependency.js +2 -2
  73. package/lib/dependencies/ImportMetaPlugin.js +1 -1
  74. package/lib/dependencies/ImportParserPlugin.js +3 -1
  75. package/lib/dependencies/ImportWeakDependency.js +2 -2
  76. package/lib/dependencies/LoaderPlugin.js +2 -2
  77. package/lib/dependencies/ModuleDependency.js +2 -2
  78. package/lib/dependencies/PureExpressionDependency.js +63 -49
  79. package/lib/dependencies/WorkerDependency.js +1 -1
  80. package/lib/esm/ModuleChunkLoadingRuntimeModule.js +90 -2
  81. package/lib/hmr/LazyCompilationPlugin.js +2 -2
  82. package/lib/ids/ChunkModuleIdRangePlugin.js +1 -1
  83. package/lib/ids/DeterministicChunkIdsPlugin.js +1 -1
  84. package/lib/ids/DeterministicModuleIdsPlugin.js +1 -1
  85. package/lib/ids/IdHelpers.js +6 -6
  86. package/lib/ids/NamedChunkIdsPlugin.js +1 -1
  87. package/lib/ids/NamedModuleIdsPlugin.js +1 -1
  88. package/lib/ids/SyncModuleIdsPlugin.js +2 -2
  89. package/lib/index.js +11 -0
  90. package/lib/javascript/CommonJsChunkFormatPlugin.js +1 -1
  91. package/lib/javascript/JavascriptGenerator.js +0 -1
  92. package/lib/javascript/JavascriptModulesPlugin.js +174 -17
  93. package/lib/javascript/JavascriptParser.js +37 -16
  94. package/lib/library/AbstractLibraryPlugin.js +2 -2
  95. package/lib/library/AmdLibraryPlugin.js +2 -2
  96. package/lib/library/AssignLibraryPlugin.js +3 -3
  97. package/lib/library/ExportPropertyLibraryPlugin.js +2 -2
  98. package/lib/library/JsonpLibraryPlugin.js +2 -2
  99. package/lib/library/ModuleLibraryPlugin.js +2 -2
  100. package/lib/library/SystemLibraryPlugin.js +2 -2
  101. package/lib/library/UmdLibraryPlugin.js +33 -12
  102. package/lib/logging/createConsoleLogger.js +2 -2
  103. package/lib/node/CommonJsChunkLoadingPlugin.js +2 -1
  104. package/lib/node/NodeEnvironmentPlugin.js +1 -1
  105. package/lib/node/NodeTemplatePlugin.js +1 -1
  106. package/lib/node/ReadFileCompileWasmPlugin.js +1 -1
  107. package/lib/node/nodeConsole.js +1 -1
  108. package/lib/optimize/AggressiveMergingPlugin.js +1 -1
  109. package/lib/optimize/ConcatenatedModule.js +11 -76
  110. package/lib/optimize/InnerGraph.js +1 -1
  111. package/lib/optimize/LimitChunkCountPlugin.js +1 -2
  112. package/lib/optimize/ModuleConcatenationPlugin.js +1 -1
  113. package/lib/optimize/RealContentHashPlugin.js +3 -3
  114. package/lib/optimize/SideEffectsFlagPlugin.js +2 -2
  115. package/lib/optimize/SplitChunksPlugin.js +8 -8
  116. package/lib/performance/SizeLimitsPlugin.js +2 -2
  117. package/lib/rules/ObjectMatcherRulePlugin.js +11 -1
  118. package/lib/rules/RuleSetCompiler.js +9 -7
  119. package/lib/runtime/LoadScriptRuntimeModule.js +1 -1
  120. package/lib/runtime/StartupChunkDependenciesPlugin.js +1 -1
  121. package/lib/schemes/HttpUriPlugin.js +1 -1
  122. package/lib/serialization/BinaryMiddleware.js +4 -4
  123. package/lib/serialization/FileMiddleware.js +3 -3
  124. package/lib/serialization/NullPrototypeObjectSerializer.js +2 -2
  125. package/lib/serialization/ObjectMiddleware.js +6 -5
  126. package/lib/serialization/PlainObjectSerializer.js +2 -2
  127. package/lib/serialization/SerializerMiddleware.js +2 -2
  128. package/lib/serialization/SingleItemMiddleware.js +2 -2
  129. package/lib/serialization/types.js +1 -1
  130. package/lib/sharing/ConsumeSharedModule.js +1 -1
  131. package/lib/sharing/ProvideSharedPlugin.js +1 -1
  132. package/lib/sharing/resolveMatchedConfigs.js +1 -1
  133. package/lib/stats/DefaultStatsFactoryPlugin.js +20 -20
  134. package/lib/stats/DefaultStatsPrinterPlugin.js +1 -1
  135. package/lib/stats/StatsFactory.js +2 -2
  136. package/lib/stats/StatsPrinter.js +6 -6
  137. package/lib/util/ArrayQueue.js +14 -21
  138. package/lib/util/AsyncQueue.js +1 -1
  139. package/lib/util/Queue.js +8 -2
  140. package/lib/util/SortableSet.js +16 -4
  141. package/lib/util/TupleQueue.js +8 -2
  142. package/lib/util/WeakTupleMap.js +3 -3
  143. package/lib/util/binarySearchBounds.js +1 -1
  144. package/lib/util/cleverMerge.js +2 -2
  145. package/lib/util/comparators.js +4 -2
  146. package/lib/util/conventions.js +1 -1
  147. package/lib/util/createHash.js +3 -5
  148. package/lib/util/deprecation.js +3 -3
  149. package/lib/util/deterministicGrouping.js +2 -2
  150. package/lib/util/findGraphRoots.js +1 -1
  151. package/lib/util/fs.js +15 -15
  152. package/lib/util/identifier.js +5 -5
  153. package/lib/util/mergeScope.js +79 -0
  154. package/lib/util/runtime.js +2 -17
  155. package/lib/util/semver.js +3 -0
  156. package/lib/util/smartGrouping.js +3 -3
  157. package/lib/wasm-async/AsyncWasmLoadingRuntimeModule.js +4 -2
  158. package/lib/wasm-async/AsyncWebAssemblyGenerator.js +1 -1
  159. package/lib/wasm-async/AsyncWebAssemblyModulesPlugin.js +3 -3
  160. package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +1 -1
  161. package/lib/wasm-sync/WebAssemblyGenerator.js +17 -17
  162. package/lib/wasm-sync/WebAssemblyModulesPlugin.js +1 -1
  163. package/lib/wasm-sync/WebAssemblyUtils.js +2 -1
  164. package/lib/web/FetchCompileWasmPlugin.js +1 -1
  165. package/lib/web/JsonpChunkLoadingRuntimeModule.js +1 -1
  166. package/lib/webpack.js +12 -3
  167. package/package.json +20 -18
  168. package/schemas/WebpackOptions.check.js +1 -1
  169. package/schemas/WebpackOptions.json +30 -2
  170. package/schemas/plugins/css/CssAutoGeneratorOptions.check.js +1 -1
  171. package/schemas/plugins/css/CssGeneratorOptions.check.js +1 -1
  172. package/schemas/plugins/css/CssGlobalGeneratorOptions.check.js +1 -1
  173. package/schemas/plugins/css/CssModuleGeneratorOptions.check.js +1 -1
  174. package/types.d.ts +213 -81
package/bin/webpack.js CHANGED
@@ -79,7 +79,6 @@ const runCli = cli => {
79
79
  const pkg = require(pkgPath);
80
80
 
81
81
  if (pkg.type === "module" || /\.mjs/i.test(pkg.bin[cli.binName])) {
82
- // eslint-disable-next-line n/no-unsupported-features/es-syntax
83
82
  import(path.resolve(path.dirname(pkgPath), pkg.bin[cli.binName])).catch(
84
83
  error => {
85
84
  console.error(error);
@@ -92,7 +91,7 @@ const runCli = cli => {
92
91
  };
93
92
 
94
93
  /**
95
- * @typedef {Object} CliOption
94
+ * @typedef {object} CliOption
96
95
  * @property {string} name display name
97
96
  * @property {string} package npm package name
98
97
  * @property {string} binName name of the executable file
package/lib/APIPlugin.js CHANGED
@@ -133,7 +133,7 @@ function getReplacements(module, importMetaName) {
133
133
  const PLUGIN_NAME = "APIPlugin";
134
134
 
135
135
  /**
136
- * @typedef {Object} APIPluginOptions
136
+ * @typedef {object} APIPluginOptions
137
137
  * @property {boolean} [module] the output filename
138
138
  */
139
139
 
@@ -189,9 +189,13 @@ class APIPlugin {
189
189
  PLUGIN_NAME,
190
190
  (source, module, renderContext) => {
191
191
  if (/** @type {BuildInfo} */ (module.buildInfo).needCreateRequire) {
192
+ const needPrefix =
193
+ renderContext.runtimeTemplate.supportNodePrefixForCoreModules();
192
194
  const chunkInitFragments = [
193
195
  new InitFragment(
194
- 'import { createRequire as __WEBPACK_EXTERNAL_createRequire } from "module";\n',
196
+ `import { createRequire as __WEBPACK_EXTERNAL_createRequire } from "${
197
+ needPrefix ? "node:" : ""
198
+ }module";\n`,
195
199
  InitFragment.STAGE_HARMONY_IMPORTS,
196
200
  0,
197
201
  "external module node-commonjs"
package/lib/Cache.js CHANGED
@@ -14,7 +14,7 @@ const {
14
14
  /** @typedef {import("./WebpackError")} WebpackError */
15
15
 
16
16
  /**
17
- * @typedef {Object} Etag
17
+ * @typedef {object} Etag
18
18
  * @property {function(): string} toString
19
19
  */
20
20
 
package/lib/Chunk.js CHANGED
@@ -38,13 +38,13 @@ const { mergeRuntime } = require("./util/runtime");
38
38
  const ChunkFilesSet = createArrayToSetDeprecationSet("chunk.files");
39
39
 
40
40
  /**
41
- * @typedef {Object} WithId an object who has an id property *
41
+ * @typedef {object} WithId an object who has an id property *
42
42
  * @property {string | number} id the id of the object
43
43
  */
44
44
 
45
45
  /**
46
46
  * @deprecated
47
- * @typedef {Object} ChunkMaps
47
+ * @typedef {object} ChunkMaps
48
48
  * @property {Record<string|number, string>} hash
49
49
  * @property {Record<string|number, Record<string, string>>} contentHash
50
50
  * @property {Record<string|number, string>} name
@@ -52,7 +52,7 @@ const ChunkFilesSet = createArrayToSetDeprecationSet("chunk.files");
52
52
 
53
53
  /**
54
54
  * @deprecated
55
- * @typedef {Object} ChunkModuleMaps
55
+ * @typedef {object} ChunkModuleMaps
56
56
  * @property {Record<string|number, (string|number)[]>} id
57
57
  * @property {Record<string|number, string>} hash
58
58
  */
@@ -85,7 +85,10 @@ class Chunk {
85
85
  this.filenameTemplate = undefined;
86
86
  /** @type {(string | function(PathData, AssetInfo=): string) | undefined} */
87
87
  this.cssFilenameTemplate = undefined;
88
- /** @private @type {SortableSet<ChunkGroup>} */
88
+ /**
89
+ * @private
90
+ * @type {SortableSet<ChunkGroup>}
91
+ */
89
92
  this._groups = new SortableSet(undefined, compareChunkGroupsByIndex);
90
93
  /** @type {RuntimeSpec} */
91
94
  this.runtime = undefined;
package/lib/ChunkGraph.js CHANGED
@@ -50,7 +50,7 @@ const compareModuleIterables = compareIterables(compareModulesByIdentifier);
50
50
  /** @typedef {[Module, Entrypoint | undefined]} EntryModuleWithChunkGroup */
51
51
 
52
52
  /**
53
- * @typedef {Object} ChunkSizeOptions
53
+ * @typedef {object} ChunkSizeOptions
54
54
  * @property {number=} chunkOverhead constant overhead for a chunk
55
55
  * @property {number=} entryChunkMultiplicator multiplicator for initial chunks
56
56
  */
@@ -187,6 +187,7 @@ const isAvailableChunk = (a, b) => {
187
187
 
188
188
  /** @typedef {Set<Chunk>} EntryInChunks */
189
189
  /** @typedef {Set<Chunk>} RuntimeInChunks */
190
+ /** @typedef {string | number} ModuleId */
190
191
 
191
192
  class ChunkGraphModule {
192
193
  constructor() {
@@ -238,13 +239,25 @@ class ChunkGraph {
238
239
  * @param {string | Hash} hashFunction the hash function to use
239
240
  */
240
241
  constructor(moduleGraph, hashFunction = "md4") {
241
- /** @private @type {WeakMap<Module, ChunkGraphModule>} */
242
+ /**
243
+ * @private
244
+ * @type {WeakMap<Module, ChunkGraphModule>}
245
+ */
242
246
  this._modules = new WeakMap();
243
- /** @private @type {WeakMap<Chunk, ChunkGraphChunk>} */
247
+ /**
248
+ * @private
249
+ * @type {WeakMap<Chunk, ChunkGraphChunk>}
250
+ */
244
251
  this._chunks = new WeakMap();
245
- /** @private @type {WeakMap<AsyncDependenciesBlock, ChunkGroup>} */
252
+ /**
253
+ * @private
254
+ * @type {WeakMap<AsyncDependenciesBlock, ChunkGroup>}
255
+ */
246
256
  this._blockChunkGroups = new WeakMap();
247
- /** @private @type {Map<string, string | number>} */
257
+ /**
258
+ * @private
259
+ * @type {Map<string, string | number>}
260
+ */
248
261
  this._runtimeIds = new Map();
249
262
  /** @type {ModuleGraph} */
250
263
  this.moduleGraph = moduleGraph;
@@ -1309,7 +1322,7 @@ class ChunkGraph {
1309
1322
 
1310
1323
  /**
1311
1324
  * @param {Module} module the module
1312
- * @returns {string | number} the id of the module
1325
+ * @returns {ModuleId} the id of the module
1313
1326
  */
1314
1327
  getModuleId(module) {
1315
1328
  const cgm = this._getChunkGraphModule(module);
@@ -1318,7 +1331,7 @@ class ChunkGraph {
1318
1331
 
1319
1332
  /**
1320
1333
  * @param {Module} module the module
1321
- * @param {string | number} id the id of the module
1334
+ * @param {ModuleId} id the id of the module
1322
1335
  * @returns {void}
1323
1336
  */
1324
1337
  setModuleId(module, id) {
package/lib/ChunkGroup.js CHANGED
@@ -25,7 +25,7 @@ const {
25
25
  /** @typedef {{module: Module, loc: DependencyLocation, request: string}} OriginRecord */
26
26
 
27
27
  /**
28
- * @typedef {Object} RawChunkGroupOptions
28
+ * @typedef {object} RawChunkGroupOptions
29
29
  * @property {number=} preloadOrder
30
30
  * @property {number=} prefetchOrder
31
31
  * @property {("low" | "high" | "auto")=} fetchPriority
@@ -93,10 +93,16 @@ class ChunkGroup {
93
93
  /** @type {OriginRecord[]} */
94
94
  this.origins = [];
95
95
  /** Indices in top-down order */
96
- /** @private @type {Map<Module, number>} */
96
+ /**
97
+ * @private
98
+ * @type {Map<Module, number>}
99
+ */
97
100
  this._modulePreOrderIndices = new Map();
98
101
  /** Indices in bottom-up order */
99
- /** @private @type {Map<Module, number>} */
102
+ /**
103
+ * @private
104
+ * @type {Map<Module, number>}
105
+ */
100
106
  this._modulePostOrderIndices = new Map();
101
107
  /** @type {number | undefined} */
102
108
  this.index = undefined;
@@ -24,7 +24,7 @@ const processAsyncTree = require("./util/processAsyncTree");
24
24
  /** @typedef {function(IgnoreItem): void} AddToIgnoreCallback */
25
25
 
26
26
  /**
27
- * @typedef {Object} CleanPluginCompilationHooks
27
+ * @typedef {object} CleanPluginCompilationHooks
28
28
  * @property {SyncBailHook<[string], boolean>} keep when returning true the file/directory will be kept during cleaning, returning false will clean it and ignore the following plugins and config
29
29
  */
30
30
 
@@ -168,20 +168,20 @@ const { isSourceEqual } = require("./util/source");
168
168
  /** @typedef {Record<string, Source>} CompilationAssets */
169
169
 
170
170
  /**
171
- * @typedef {Object} AvailableModulesChunkGroupMapping
171
+ * @typedef {object} AvailableModulesChunkGroupMapping
172
172
  * @property {ChunkGroup} chunkGroup
173
173
  * @property {Set<Module>} availableModules
174
174
  * @property {boolean} needCopy
175
175
  */
176
176
 
177
177
  /**
178
- * @typedef {Object} DependenciesBlockLike
178
+ * @typedef {object} DependenciesBlockLike
179
179
  * @property {Dependency[]} dependencies
180
180
  * @property {AsyncDependenciesBlock[]} blocks
181
181
  */
182
182
 
183
183
  /**
184
- * @typedef {Object} ChunkPathData
184
+ * @typedef {object} ChunkPathData
185
185
  * @property {string|number} id
186
186
  * @property {string=} name
187
187
  * @property {string} hash
@@ -191,7 +191,7 @@ const { isSourceEqual } = require("./util/source");
191
191
  */
192
192
 
193
193
  /**
194
- * @typedef {Object} ChunkHashContext
194
+ * @typedef {object} ChunkHashContext
195
195
  * @property {CodeGenerationResults} codeGenerationResults results of code generation
196
196
  * @property {RuntimeTemplate} runtimeTemplate the runtime template
197
197
  * @property {ModuleGraph} moduleGraph the module graph
@@ -199,18 +199,18 @@ const { isSourceEqual } = require("./util/source");
199
199
  */
200
200
 
201
201
  /**
202
- * @typedef {Object} RuntimeRequirementsContext
202
+ * @typedef {object} RuntimeRequirementsContext
203
203
  * @property {ChunkGraph} chunkGraph the chunk graph
204
204
  * @property {CodeGenerationResults} codeGenerationResults the code generation results
205
205
  */
206
206
 
207
207
  /**
208
- * @typedef {Object} ExecuteModuleOptions
208
+ * @typedef {object} ExecuteModuleOptions
209
209
  * @property {EntryOptions=} entryOptions
210
210
  */
211
211
 
212
212
  /**
213
- * @typedef {Object} ExecuteModuleResult
213
+ * @typedef {object} ExecuteModuleResult
214
214
  * @property {any} exports
215
215
  * @property {boolean} cacheable
216
216
  * @property {Map<string, { source: Source, info: AssetInfo }>} assets
@@ -221,7 +221,7 @@ const { isSourceEqual } = require("./util/source");
221
221
  */
222
222
 
223
223
  /**
224
- * @typedef {Object} ExecuteModuleArgument
224
+ * @typedef {object} ExecuteModuleArgument
225
225
  * @property {Module} module
226
226
  * @property {{ id: string, exports: any, loaded: boolean }=} moduleObject
227
227
  * @property {any} preparedInfo
@@ -229,7 +229,7 @@ const { isSourceEqual } = require("./util/source");
229
229
  */
230
230
 
231
231
  /**
232
- * @typedef {Object} ExecuteModuleContext
232
+ * @typedef {object} ExecuteModuleContext
233
233
  * @property {Map<string, { source: Source, info: AssetInfo }>} assets
234
234
  * @property {Chunk} chunk
235
235
  * @property {ChunkGraph} chunkGraph
@@ -237,14 +237,14 @@ const { isSourceEqual } = require("./util/source");
237
237
  */
238
238
 
239
239
  /**
240
- * @typedef {Object} EntryData
240
+ * @typedef {object} EntryData
241
241
  * @property {Dependency[]} dependencies dependencies of the entrypoint that should be evaluated at startup
242
242
  * @property {Dependency[]} includeDependencies dependencies of the entrypoint that should be included but not evaluated
243
243
  * @property {EntryOptions} options options of the entrypoint
244
244
  */
245
245
 
246
246
  /**
247
- * @typedef {Object} LogEntry
247
+ * @typedef {object} LogEntry
248
248
  * @property {string} type
249
249
  * @property {any[]} args
250
250
  * @property {number} time
@@ -252,7 +252,7 @@ const { isSourceEqual } = require("./util/source");
252
252
  */
253
253
 
254
254
  /**
255
- * @typedef {Object} KnownAssetInfo
255
+ * @typedef {object} KnownAssetInfo
256
256
  * @property {boolean=} immutable true, if the asset can be long term cached forever (contains a hash)
257
257
  * @property {boolean=} minimized whether the asset is minimized
258
258
  * @property {string | string[]=} fullhash the value(s) of the full hash used for this asset
@@ -270,21 +270,21 @@ const { isSourceEqual } = require("./util/source");
270
270
  /** @typedef {KnownAssetInfo & Record<string, any>} AssetInfo */
271
271
 
272
272
  /**
273
- * @typedef {Object} Asset
273
+ * @typedef {object} Asset
274
274
  * @property {string} name the filename of the asset
275
275
  * @property {Source} source source of the asset
276
276
  * @property {AssetInfo} info info about the asset
277
277
  */
278
278
 
279
279
  /**
280
- * @typedef {Object} ModulePathData
280
+ * @typedef {object} ModulePathData
281
281
  * @property {string|number} id
282
282
  * @property {string} hash
283
283
  * @property {function(number): string=} hashWithLength
284
284
  */
285
285
 
286
286
  /**
287
- * @typedef {Object} PathData
287
+ * @typedef {object} PathData
288
288
  * @property {ChunkGraph=} chunkGraph
289
289
  * @property {string=} hash
290
290
  * @property {function(number): string=} hashWithLength
@@ -302,7 +302,7 @@ const { isSourceEqual } = require("./util/source");
302
302
  */
303
303
 
304
304
  /**
305
- * @typedef {Object} KnownNormalizedStatsOptions
305
+ * @typedef {object} KnownNormalizedStatsOptions
306
306
  * @property {string} context
307
307
  * @property {RequestShortener} requestShortener
308
308
  * @property {string} chunksSort
@@ -346,7 +346,7 @@ const { isSourceEqual } = require("./util/source");
346
346
  /** @typedef {KnownNormalizedStatsOptions & Omit<StatsOptions, keyof KnownNormalizedStatsOptions> & Record<string, any>} NormalizedStatsOptions */
347
347
 
348
348
  /**
349
- * @typedef {Object} KnownCreateStatsOptionsContext
349
+ * @typedef {object} KnownCreateStatsOptionsContext
350
350
  * @property {boolean=} forToString
351
351
  */
352
352
 
@@ -849,7 +849,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
849
849
  /** @type {SyncHook<[Chunk, string]>} */
850
850
  chunkAsset: new SyncHook(["chunk", "filename"]),
851
851
 
852
- /** @type {SyncWaterfallHook<[string, object, AssetInfo]>} */
852
+ /** @type {SyncWaterfallHook<[string, object, AssetInfo | undefined]>} */
853
853
  assetPath: new SyncWaterfallHook(["path", "options", "assetInfo"]),
854
854
 
855
855
  /** @type {SyncBailHook<[], boolean>} */
@@ -1019,7 +1019,10 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
1019
1019
  arrayToSetDeprecation(this.chunks, "Compilation.chunks");
1020
1020
  arrayToSetDeprecation(this.modules, "Compilation.modules");
1021
1021
  }
1022
- /** @private @type {Map<string, Module>} */
1022
+ /**
1023
+ * @private
1024
+ * @type {Map<string, Module>}
1025
+ */
1023
1026
  this._modules = new Map();
1024
1027
  this.records = null;
1025
1028
  /** @type {string[]} */
@@ -1061,7 +1064,10 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
1061
1064
  this.codeGeneratedModules = new WeakSet();
1062
1065
  /** @type {WeakSet<Module>} */
1063
1066
  this.buildTimeExecutedModules = new WeakSet();
1064
- /** @private @type {Map<Module, Callback[]>} */
1067
+ /**
1068
+ * @private
1069
+ * @type {Map<Module, Callback[]>}
1070
+ */
1065
1071
  this._rebuildingModules = new Map();
1066
1072
  /** @type {Set<string>} */
1067
1073
  this.emittedAssets = new Set();
@@ -1787,7 +1793,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
1787
1793
  }
1788
1794
 
1789
1795
  /**
1790
- * @typedef {Object} HandleModuleCreationOptions
1796
+ * @typedef {object} HandleModuleCreationOptions
1791
1797
  * @property {ModuleFactory} factory
1792
1798
  * @property {Dependency[]} dependencies
1793
1799
  * @property {Module | null} originModule
@@ -2122,7 +2128,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
2122
2128
  }
2123
2129
 
2124
2130
  /**
2125
- * @param {Object} options options
2131
+ * @param {object} options options
2126
2132
  * @param {string} options.context context string path
2127
2133
  * @param {Dependency} options.dependency dependency used to create Module chain
2128
2134
  * @param {Partial<ModuleFactoryCreateDataContextInfo>=} options.contextInfo additional context info for the root module
@@ -2561,7 +2567,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
2561
2567
  };
2562
2568
  /**
2563
2569
  * @param {Module} module module
2564
- * @param {Object} references references
2570
+ * @param {object} references references
2565
2571
  * @param {string | number} references.id id
2566
2572
  * @param {Map<Module, string | number | undefined>=} references.modules modules
2567
2573
  * @param {(string | number | null)[]=} references.blocks blocks
@@ -3466,7 +3472,6 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
3466
3472
  dependencyTemplates,
3467
3473
  runtimeTemplate,
3468
3474
  runtime,
3469
- runtimes,
3470
3475
  codeGenerationResults: results,
3471
3476
  compilation: this
3472
3477
  });
@@ -3510,7 +3515,7 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
3510
3515
  }
3511
3516
 
3512
3517
  /**
3513
- * @param {Object} options options
3518
+ * @param {object} options options
3514
3519
  * @param {ChunkGraph=} options.chunkGraph the chunk graph
3515
3520
  * @param {Iterable<Module>=} options.modules modules
3516
3521
  * @param {Iterable<Chunk>=} options.chunks chunks
@@ -5338,7 +5343,7 @@ This prevents using hashes of each other and should be avoided.`);
5338
5343
  }
5339
5344
 
5340
5345
  /**
5341
- * @typedef {Object} FactorizeModuleOptions
5346
+ * @typedef {object} FactorizeModuleOptions
5342
5347
  * @property {ModuleProfile} currentProfile
5343
5348
  * @property {ModuleFactory} factory
5344
5349
  * @property {Dependency[]} dependencies
@@ -5355,7 +5360,8 @@ This prevents using hashes of each other and should be avoided.`);
5355
5360
  */
5356
5361
 
5357
5362
  // Workaround for typescript as it doesn't support function overloading in jsdoc within a class
5358
- Compilation.prototype.factorizeModule = /** @type {{
5363
+ Compilation.prototype.factorizeModule = /**
5364
+ @type {{
5359
5365
  (options: FactorizeModuleOptions & { factoryResult?: false }, callback: ModuleCallback): void;
5360
5366
  (options: FactorizeModuleOptions & { factoryResult: true }, callback: ModuleFactoryResultCallback): void;
5361
5367
  }} */ (
package/lib/Compiler.js CHANGED
@@ -45,6 +45,7 @@ const { isSourceEqual } = require("./util/source");
45
45
  /** @typedef {import("./FileSystemInfo").FileSystemInfoEntry} FileSystemInfoEntry */
46
46
  /** @typedef {import("./Module")} Module */
47
47
  /** @typedef {import("./Module").BuildInfo} BuildInfo */
48
+ /** @typedef {import("./config/target").PlatformTargetProperties} PlatformTargetProperties */
48
49
  /** @typedef {import("./logging/createConsoleLogger").LoggingFunction} LoggingFunction */
49
50
  /** @typedef {import("./util/WeakTupleMap")} WeakTupleMap */
50
51
  /** @typedef {import("./util/fs").IStats} IStats */
@@ -54,7 +55,7 @@ const { isSourceEqual } = require("./util/source");
54
55
  /** @typedef {import("./util/fs").WatchFileSystem} WatchFileSystem */
55
56
 
56
57
  /**
57
- * @typedef {Object} CompilationParams
58
+ * @typedef {object} CompilationParams
58
59
  * @property {NormalModuleFactory} normalModuleFactory
59
60
  * @property {ContextModuleFactory} contextModuleFactory
60
61
  */
@@ -81,7 +82,7 @@ const { isSourceEqual } = require("./util/source");
81
82
  */
82
83
 
83
84
  /**
84
- * @typedef {Object} AssetEmittedInfo
85
+ * @typedef {object} AssetEmittedInfo
85
86
  * @property {Buffer} content
86
87
  * @property {Source} source
87
88
  * @property {Compilation} compilation
@@ -104,12 +105,12 @@ const isSorted = array => {
104
105
  };
105
106
 
106
107
  /**
107
- * @param {Object<string, any>} obj an object
108
+ * @param {{[key: string]: any}} obj an object
108
109
  * @param {string[]} keys the keys of the object
109
- * @returns {Object<string, any>} the object with properties sorted by property name
110
+ * @returns {{[key: string]: any}} the object with properties sorted by property name
110
111
  */
111
112
  const sortObject = (obj, keys) => {
112
- /** @type {Object<string, any>} */
113
+ /** @type {{[key: string]: any}} */
113
114
  const o = {};
114
115
  for (const k of keys.sort()) {
115
116
  o[k] = obj[k];
@@ -265,6 +266,16 @@ class Compiler {
265
266
  /** @type {LoggingFunction | undefined} */
266
267
  this.infrastructureLogger = undefined;
267
268
 
269
+ /** @type {Readonly<PlatformTargetProperties>} */
270
+ this.platform = {
271
+ web: null,
272
+ browser: null,
273
+ webworker: null,
274
+ node: null,
275
+ nwjs: null,
276
+ electron: null
277
+ };
278
+
268
279
  this.options = options;
269
280
 
270
281
  this.context = context;
@@ -294,11 +305,20 @@ class Compiler {
294
305
  /** @type {NormalModuleFactory | undefined} */
295
306
  this._lastNormalModuleFactory = undefined;
296
307
 
297
- /** @private @type {WeakMap<Source, CacheEntry>} */
308
+ /**
309
+ * @private
310
+ * @type {WeakMap<Source, CacheEntry>}
311
+ */
298
312
  this._assetEmittingSourceCache = new WeakMap();
299
- /** @private @type {Map<string, number>} */
313
+ /**
314
+ * @private
315
+ * @type {Map<string, number>}
316
+ */
300
317
  this._assetEmittingWrittenFiles = new Map();
301
- /** @private @type {Set<string>} */
318
+ /**
319
+ * @private
320
+ * @type {Set<string>}
321
+ */
302
322
  this._assetEmittingPreviousFiles = new Set();
303
323
  }
304
324
 
@@ -14,13 +14,13 @@ const DEFAULT_EXPORT = "__WEBPACK_DEFAULT_EXPORT__";
14
14
  const NAMESPACE_OBJECT_EXPORT = "__WEBPACK_NAMESPACE_OBJECT__";
15
15
 
16
16
  /**
17
- * @typedef {Object} ExternalModuleInfo
17
+ * @typedef {object} ExternalModuleInfo
18
18
  * @property {number} index
19
19
  * @property {Module} module
20
20
  */
21
21
 
22
22
  /**
23
- * @typedef {Object} ConcatenatedModuleInfo
23
+ * @typedef {object} ConcatenatedModuleInfo
24
24
  * @property {number} index
25
25
  * @property {Module} module
26
26
  * @property {Map<string, string>} exportMap mapping from export name to symbol
@@ -31,7 +31,7 @@ const NAMESPACE_OBJECT_EXPORT = "__WEBPACK_NAMESPACE_OBJECT__";
31
31
  /** @typedef {ConcatenatedModuleInfo | ExternalModuleInfo} ModuleInfo */
32
32
 
33
33
  /**
34
- * @typedef {Object} ModuleReferenceOptions
34
+ * @typedef {object} ModuleReferenceOptions
35
35
  * @property {string[]} ids the properties/exports of the module
36
36
  * @property {boolean} call true, when this referenced export is called
37
37
  * @property {boolean} directImport true, when this referenced export is directly imported (not via property access)