webpack 5.98.0 → 5.99.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.
- package/README.md +7 -3
- package/lib/AsyncDependenciesBlock.js +3 -1
- package/lib/BannerPlugin.js +1 -1
- package/lib/Cache.js +9 -7
- package/lib/CacheFacade.js +5 -5
- package/lib/Chunk.js +2 -2
- package/lib/ChunkGraph.js +21 -16
- package/lib/ChunkTemplate.js +6 -6
- package/lib/CleanPlugin.js +10 -10
- package/lib/CodeGenerationResults.js +4 -3
- package/lib/CompatibilityPlugin.js +4 -1
- package/lib/Compilation.js +326 -152
- package/lib/Compiler.js +13 -18
- package/lib/ConditionalInitFragment.js +1 -1
- package/lib/ConstPlugin.js +5 -3
- package/lib/ContextModule.js +4 -2
- package/lib/ContextModuleFactory.js +3 -3
- package/lib/ContextReplacementPlugin.js +43 -16
- package/lib/DefinePlugin.js +25 -24
- package/lib/DelegatedModule.js +4 -2
- package/lib/DelegatedModuleFactoryPlugin.js +2 -1
- package/lib/Dependency.js +19 -13
- package/lib/DependencyTemplates.js +4 -3
- package/lib/DllModule.js +4 -2
- package/lib/DllModuleFactory.js +2 -2
- package/lib/DllReferencePlugin.js +2 -1
- package/lib/DynamicEntryPlugin.js +1 -1
- package/lib/EnvironmentPlugin.js +4 -2
- package/lib/ExportsInfo.js +72 -40
- package/lib/ExternalModule.js +14 -5
- package/lib/ExternalModuleFactoryPlugin.js +24 -12
- package/lib/FileSystemInfo.js +129 -94
- package/lib/FlagDependencyExportsPlugin.js +6 -4
- package/lib/FlagDependencyUsagePlugin.js +1 -1
- package/lib/Generator.js +29 -1
- package/lib/HookWebpackError.js +2 -2
- package/lib/HotModuleReplacementPlugin.js +3 -9
- package/lib/IgnoreErrorModuleFactory.js +2 -2
- package/lib/IgnorePlugin.js +0 -5
- package/lib/InitFragment.js +1 -1
- package/lib/LoaderOptionsPlugin.js +8 -5
- package/lib/MainTemplate.js +7 -7
- package/lib/Module.js +40 -17
- package/lib/ModuleBuildError.js +3 -1
- package/lib/ModuleDependencyError.js +4 -3
- package/lib/ModuleDependencyWarning.js +4 -3
- package/lib/ModuleFactory.js +9 -3
- package/lib/ModuleFilenameHelpers.js +13 -13
- package/lib/ModuleGraph.js +20 -14
- package/lib/ModuleGraphConnection.js +7 -13
- package/lib/ModuleNotFoundError.js +1 -1
- package/lib/ModuleParseError.js +2 -1
- package/lib/ModuleSourceTypesConstants.js +11 -0
- package/lib/ModuleTemplate.js +5 -5
- package/lib/ModuleTypeConstants.js +15 -0
- package/lib/MultiCompiler.js +4 -4
- package/lib/MultiStats.js +1 -1
- package/lib/NormalModule.js +101 -54
- package/lib/NormalModuleFactory.js +38 -33
- package/lib/NormalModuleReplacementPlugin.js +3 -2
- package/lib/NullFactory.js +2 -2
- package/lib/Parser.js +4 -3
- package/lib/ProgressPlugin.js +1 -2
- package/lib/RawModule.js +4 -2
- package/lib/RecordIdsPlugin.js +6 -2
- package/lib/RequestShortener.js +3 -1
- package/lib/ResolverFactory.js +12 -9
- package/lib/RuntimeModule.js +4 -2
- package/lib/RuntimeTemplate.js +2 -1
- package/lib/SelfModuleFactory.js +2 -2
- package/lib/SourceMapDevToolPlugin.js +0 -8
- package/lib/Template.js +6 -5
- package/lib/TemplatedPathPlugin.js +15 -12
- package/lib/WebpackOptionsApply.js +1 -1
- package/lib/asset/AssetGenerator.js +237 -170
- package/lib/asset/AssetModulesPlugin.js +50 -8
- package/lib/asset/AssetSourceGenerator.js +18 -0
- package/lib/asset/RawDataUrlModule.js +4 -2
- package/lib/buildChunkGraph.js +14 -4
- package/lib/cache/MemoryWithGcCachePlugin.js +6 -2
- package/lib/cache/PackFileCacheStrategy.js +137 -121
- package/lib/cache/ResolverCachePlugin.js +15 -7
- package/lib/cache/getLazyHashedEtag.js +4 -3
- package/lib/cli.js +23 -15
- package/lib/config/defaults.js +93 -26
- package/lib/config/normalization.js +14 -13
- package/lib/config/target.js +8 -8
- package/lib/container/ContainerEntryModule.js +4 -2
- package/lib/container/ContainerEntryModuleFactory.js +2 -2
- package/lib/container/FallbackModule.js +4 -2
- package/lib/container/FallbackModuleFactory.js +2 -2
- package/lib/container/RemoteModule.js +4 -2
- package/lib/container/options.js +5 -5
- package/lib/css/CssGenerator.js +71 -9
- package/lib/css/CssModulesPlugin.js +30 -5
- package/lib/css/CssParser.js +37 -17
- package/lib/css/walkCssTokens.js +17 -17
- package/lib/debug/ProfilingPlugin.js +98 -38
- package/lib/dependencies/AMDDefineDependencyParserPlugin.js +10 -4
- package/lib/dependencies/AMDPlugin.js +5 -2
- package/lib/dependencies/AMDRequireArrayDependency.js +4 -3
- package/lib/dependencies/AMDRequireContextDependency.js +2 -1
- package/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js +15 -7
- package/lib/dependencies/AMDRuntimeModules.js +3 -1
- package/lib/dependencies/CommonJsExportRequireDependency.js +4 -5
- package/lib/dependencies/CommonJsExportsParserPlugin.js +3 -3
- package/lib/dependencies/CommonJsImportsParserPlugin.js +8 -7
- package/lib/dependencies/CommonJsRequireContextDependency.js +2 -1
- package/lib/dependencies/ContextDependencyHelpers.js +13 -6
- package/lib/dependencies/CssIcssExportDependency.js +15 -12
- package/lib/dependencies/CssIcssImportDependency.js +4 -1
- package/lib/dependencies/CssLocalIdentifierDependency.js +17 -14
- package/lib/dependencies/ExportsInfoDependency.js +6 -1
- package/lib/dependencies/HarmonyEvaluatedImportSpecifierDependency.js +5 -5
- package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +22 -15
- package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +23 -8
- package/lib/dependencies/HarmonyExportSpecifierDependency.js +2 -2
- package/lib/dependencies/HarmonyImportDependency.js +8 -6
- package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +19 -14
- package/lib/dependencies/HarmonyImportSpecifierDependency.js +5 -5
- package/lib/dependencies/ImportContextDependency.js +2 -1
- package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +8 -4
- package/lib/dependencies/JsonExportsDependency.js +24 -8
- package/lib/dependencies/LoaderPlugin.js +4 -14
- package/lib/dependencies/RequireContextDependency.js +2 -1
- package/lib/dependencies/RequireContextDependencyParserPlugin.js +6 -3
- package/lib/dependencies/RequireEnsureDependenciesBlock.js +3 -2
- package/lib/dependencies/RequireEnsureDependenciesBlockParserPlugin.js +11 -5
- package/lib/dependencies/RequireResolveContextDependency.js +1 -1
- package/lib/dependencies/WebAssemblyExportImportedDependency.js +1 -1
- package/lib/dependencies/WorkerDependency.js +6 -3
- package/lib/dependencies/WorkerPlugin.js +100 -41
- package/lib/esm/ModuleChunkFormatPlugin.js +5 -0
- package/lib/hmr/HotModuleReplacement.runtime.js +1 -0
- package/lib/hmr/JavascriptHotModuleReplacement.runtime.js +1 -0
- package/lib/hmr/LazyCompilationPlugin.js +32 -24
- package/lib/hmr/lazyCompilationBackend.js +1 -1
- package/lib/ids/DeterministicModuleIdsPlugin.js +1 -1
- package/lib/ids/HashedModuleIdsPlugin.js +2 -1
- package/lib/ids/IdHelpers.js +15 -14
- package/lib/ids/SyncModuleIdsPlugin.js +9 -5
- package/lib/index.js +5 -5
- package/lib/javascript/BasicEvaluatedExpression.js +6 -6
- package/lib/javascript/JavascriptGenerator.js +11 -1
- package/lib/javascript/JavascriptModulesPlugin.js +51 -31
- package/lib/javascript/JavascriptParser.js +272 -188
- package/lib/javascript/JavascriptParserHelpers.js +10 -9
- package/lib/javascript/StartupHelpers.js +4 -1
- package/lib/json/JsonData.js +4 -4
- package/lib/json/JsonGenerator.js +54 -22
- package/lib/json/JsonModulesPlugin.js +16 -2
- package/lib/json/JsonParser.js +8 -4
- package/lib/library/AbstractLibraryPlugin.js +7 -3
- package/lib/library/AssignLibraryPlugin.js +29 -1
- package/lib/library/EnableLibraryPlugin.js +7 -10
- package/lib/library/ExportPropertyLibraryPlugin.js +4 -1
- package/lib/library/ModuleLibraryPlugin.js +121 -15
- package/lib/logging/Logger.js +2 -2
- package/lib/logging/createConsoleLogger.js +4 -4
- package/lib/node/NodeEnvironmentPlugin.js +6 -2
- package/lib/node/ReadFileCompileAsyncWasmPlugin.js +1 -2
- package/lib/node/ReadFileCompileWasmPlugin.js +1 -2
- package/lib/node/nodeConsole.js +3 -1
- package/lib/optimize/AggressiveSplittingPlugin.js +1 -1
- package/lib/optimize/ConcatenatedModule.js +19 -12
- package/lib/optimize/InnerGraph.js +3 -2
- package/lib/optimize/InnerGraphPlugin.js +13 -7
- package/lib/optimize/LimitChunkCountPlugin.js +20 -0
- package/lib/optimize/ModuleConcatenationPlugin.js +10 -7
- package/lib/optimize/RealContentHashPlugin.js +8 -4
- package/lib/optimize/SideEffectsFlagPlugin.js +4 -2
- package/lib/optimize/SplitChunksPlugin.js +87 -65
- package/lib/rules/BasicEffectRulePlugin.js +9 -1
- package/lib/rules/BasicMatcherRulePlugin.js +15 -4
- package/lib/rules/ObjectMatcherRulePlugin.js +12 -3
- package/lib/rules/RuleSetCompiler.js +25 -14
- package/lib/rules/UseEffectRulePlugin.js +47 -17
- package/lib/runtime/GetChunkFilenameRuntimeModule.js +6 -6
- package/lib/schemes/HttpUriPlugin.js +38 -17
- package/lib/serialization/BinaryMiddleware.js +52 -19
- package/lib/serialization/FileMiddleware.js +78 -48
- package/lib/serialization/ObjectMiddleware.js +78 -29
- package/lib/serialization/PlainObjectSerializer.js +1 -1
- package/lib/serialization/Serializer.js +15 -10
- package/lib/serialization/SerializerMiddleware.js +80 -41
- package/lib/serialization/SingleItemMiddleware.js +10 -7
- package/lib/serialization/types.js +1 -1
- package/lib/sharing/ConsumeSharedModule.js +4 -2
- package/lib/sharing/ProvideSharedModule.js +4 -2
- package/lib/sharing/ProvideSharedModuleFactory.js +5 -3
- package/lib/sharing/utils.js +2 -2
- package/lib/stats/DefaultStatsFactoryPlugin.js +80 -78
- package/lib/stats/DefaultStatsPresetPlugin.js +43 -23
- package/lib/stats/DefaultStatsPrinterPlugin.js +85 -43
- package/lib/stats/StatsFactory.js +11 -11
- package/lib/stats/StatsPrinter.js +7 -7
- package/lib/util/ArrayHelpers.js +2 -4
- package/lib/util/ArrayQueue.js +1 -1
- package/lib/util/AsyncQueue.js +4 -4
- package/lib/util/IterableHelpers.js +1 -1
- package/lib/util/LazyBucketSortedSet.js +41 -23
- package/lib/util/LazySet.js +3 -2
- package/lib/util/MapHelpers.js +1 -1
- package/lib/util/ParallelismFactorCalculator.js +1 -1
- package/lib/util/Semaphore.js +3 -3
- package/lib/util/SetHelpers.js +1 -1
- package/lib/util/SortableSet.js +9 -7
- package/lib/util/TupleQueue.js +9 -8
- package/lib/util/TupleSet.js +2 -2
- package/lib/util/WeakTupleMap.js +12 -11
- package/lib/util/binarySearchBounds.js +2 -1
- package/lib/util/cleverMerge.js +84 -54
- package/lib/util/comparators.js +22 -21
- package/lib/util/compileBooleanMatcher.js +3 -3
- package/lib/util/concatenate.js +6 -4
- package/lib/util/create-schema-validation.js +4 -4
- package/lib/util/createHash.js +2 -2
- package/lib/util/deprecation.js +35 -33
- package/lib/util/deterministicGrouping.js +6 -6
- package/lib/util/findGraphRoots.js +1 -1
- package/lib/util/fs.js +39 -39
- package/lib/util/hash/wasm-hash.js +2 -2
- package/lib/util/identifier.js +15 -18
- package/lib/util/makeSerializable.js +1 -1
- package/lib/util/memoize.js +4 -1
- package/lib/util/objectToMap.js +3 -2
- package/lib/util/processAsyncTree.js +2 -2
- package/lib/util/propertyName.js +0 -1
- package/lib/util/registerExternalSerializer.js +15 -18
- package/lib/util/removeBOM.js +25 -0
- package/lib/util/runtime.js +34 -27
- package/lib/util/serialization.js +5 -16
- package/lib/util/smartGrouping.js +3 -3
- package/lib/wasm-async/AsyncWasmLoadingRuntimeModule.js +3 -3
- package/lib/wasm-async/AsyncWebAssemblyGenerator.js +11 -0
- package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +10 -0
- package/lib/wasm-async/UniversalCompileAsyncWasmPlugin.js +4 -0
- package/lib/wasm-sync/WebAssemblyGenerator.js +28 -12
- package/lib/wasm-sync/WebAssemblyJavascriptGenerator.js +10 -0
- package/lib/wasm-sync/WebAssemblyParser.js +9 -4
- package/lib/webworker/ImportScriptsChunkLoadingPlugin.js +3 -0
- package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +30 -25
- package/package.json +19 -17
- package/schemas/WebpackOptions.check.js +1 -1
- package/schemas/WebpackOptions.json +48 -13
- package/schemas/plugins/JsonModulesPluginGenerator.check.d.ts +7 -0
- package/schemas/plugins/JsonModulesPluginGenerator.check.js +6 -0
- package/schemas/plugins/JsonModulesPluginGenerator.json +11 -0
- package/schemas/plugins/SourceMapDevToolPlugin.json +2 -2
- package/types.d.ts +918 -615
- package/lib/library/ModernModuleLibraryPlugin.js +0 -144
package/lib/Compilation.js
CHANGED
@@ -107,12 +107,16 @@ const { isSourceEqual } = require("./util/source");
|
|
107
107
|
/** @typedef {import("./Module").BuildInfo} BuildInfo */
|
108
108
|
/** @typedef {import("./Module").ValueCacheVersions} ValueCacheVersions */
|
109
109
|
/** @typedef {import("./NormalModule").NormalModuleCompilationHooks} NormalModuleCompilationHooks */
|
110
|
+
/** @typedef {import("./Module").FactoryMeta} FactoryMeta */
|
110
111
|
/** @typedef {import("./Module").CodeGenerationResult} CodeGenerationResult */
|
111
112
|
/** @typedef {import("./ModuleFactory")} ModuleFactory */
|
113
|
+
/** @typedef {import("../declarations/WebpackOptions").ResolveOptions} ResolveOptions */
|
112
114
|
/** @typedef {import("./ChunkGraph").ModuleId} ModuleId */
|
113
115
|
/** @typedef {import("./ModuleGraphConnection")} ModuleGraphConnection */
|
114
116
|
/** @typedef {import("./ModuleFactory").ModuleFactoryCreateDataContextInfo} ModuleFactoryCreateDataContextInfo */
|
115
117
|
/** @typedef {import("./ModuleFactory").ModuleFactoryResult} ModuleFactoryResult */
|
118
|
+
/** @typedef {import("./NormalModule").ParserOptions} ParserOptions */
|
119
|
+
/** @typedef {import("./NormalModule").GeneratorOptions} GeneratorOptions */
|
116
120
|
/** @typedef {import("./RequestShortener")} RequestShortener */
|
117
121
|
/** @typedef {import("./RuntimeModule")} RuntimeModule */
|
118
122
|
/** @typedef {import("./Template").RenderManifestEntry} RenderManifestEntry */
|
@@ -170,7 +174,7 @@ const { isSourceEqual } = require("./util/source");
|
|
170
174
|
* @returns {any}
|
171
175
|
*/
|
172
176
|
|
173
|
-
/** @typedef {new (...args:
|
177
|
+
/** @typedef {new (...args: EXPECTED_ANY[]) => Dependency} DepConstructor */
|
174
178
|
|
175
179
|
/** @typedef {Record<string, Source>} CompilationAssets */
|
176
180
|
|
@@ -189,10 +193,10 @@ const { isSourceEqual } = require("./util/source");
|
|
189
193
|
|
190
194
|
/**
|
191
195
|
* @typedef {object} ChunkPathData
|
192
|
-
* @property {string|number} id
|
196
|
+
* @property {string | number} id
|
193
197
|
* @property {string=} name
|
194
198
|
* @property {string} hash
|
195
|
-
* @property {
|
199
|
+
* @property {((length: number) => string)=} hashWithLength
|
196
200
|
* @property {(Record<string, string>)=} contentHash
|
197
201
|
* @property {(Record<string, (length: number) => string>)=} contentHashWithLength
|
198
202
|
*/
|
@@ -216,11 +220,13 @@ const { isSourceEqual } = require("./util/source");
|
|
216
220
|
* @property {EntryOptions=} entryOptions
|
217
221
|
*/
|
218
222
|
|
223
|
+
/** @typedef {EXPECTED_ANY} ExecuteModuleExports */
|
224
|
+
|
219
225
|
/**
|
220
226
|
* @typedef {object} ExecuteModuleResult
|
221
|
-
* @property {
|
227
|
+
* @property {ExecuteModuleExports} exports
|
222
228
|
* @property {boolean} cacheable
|
223
|
-
* @property {Map<string, { source: Source, info: AssetInfo }>} assets
|
229
|
+
* @property {Map<string, { source: Source, info: AssetInfo | undefined }>} assets
|
224
230
|
* @property {LazySet<string>} fileDependencies
|
225
231
|
* @property {LazySet<string>} contextDependencies
|
226
232
|
* @property {LazySet<string>} missingDependencies
|
@@ -228,22 +234,36 @@ const { isSourceEqual } = require("./util/source");
|
|
228
234
|
*/
|
229
235
|
|
230
236
|
/**
|
231
|
-
* @typedef {
|
232
|
-
*
|
233
|
-
*
|
237
|
+
* @typedef {object} ExecuteModuleObject
|
238
|
+
* @property {string} [id] module id
|
239
|
+
* @property {ExecuteModuleExports} exports exports
|
240
|
+
* @property {boolean} loaded is loaded
|
241
|
+
* @property {Error} [error] error
|
242
|
+
*/
|
243
|
+
|
244
|
+
/**
|
234
245
|
* @typedef {object} ExecuteModuleArgument
|
235
246
|
* @property {Module} module
|
236
|
-
* @property {
|
247
|
+
* @property {ExecuteModuleObject=} moduleObject
|
237
248
|
* @property {any} preparedInfo
|
238
249
|
* @property {CodeGenerationResult} codeGenerationResult
|
239
250
|
*/
|
240
251
|
|
252
|
+
/** @typedef {((id: string) => ExecuteModuleExports) & { i?: ((options: ExecuteOptions) => void)[], c?: Record<string, ExecuteModuleObject> }} WebpackRequire */
|
253
|
+
|
254
|
+
/**
|
255
|
+
* @typedef {object} ExecuteOptions
|
256
|
+
* @property {string} [id] module id
|
257
|
+
* @property {ExecuteModuleObject} module module
|
258
|
+
* @property {WebpackRequire} require require function
|
259
|
+
*/
|
260
|
+
|
241
261
|
/**
|
242
262
|
* @typedef {object} ExecuteModuleContext
|
243
|
-
* @property {Map<string, { source: Source, info: AssetInfo }>} assets
|
263
|
+
* @property {Map<string, { source: Source, info: AssetInfo | undefined }>} assets
|
244
264
|
* @property {Chunk} chunk
|
245
265
|
* @property {ChunkGraph} chunkGraph
|
246
|
-
* @property {
|
266
|
+
* @property {WebpackRequire=} __webpack_require__
|
247
267
|
*/
|
248
268
|
|
249
269
|
/**
|
@@ -256,7 +276,7 @@ const { isSourceEqual } = require("./util/source");
|
|
256
276
|
/**
|
257
277
|
* @typedef {object} LogEntry
|
258
278
|
* @property {string} type
|
259
|
-
* @property {
|
279
|
+
* @property {EXPECTED_ANY[]=} args
|
260
280
|
* @property {number} time
|
261
281
|
* @property {string[]=} trace
|
262
282
|
*/
|
@@ -277,7 +297,7 @@ const { isSourceEqual } = require("./util/source");
|
|
277
297
|
* @property {Record<string, string | string[]>=} related object of pointers to other assets, keyed by type of relation (only points from parent to child)
|
278
298
|
*/
|
279
299
|
|
280
|
-
/** @typedef {KnownAssetInfo & Record<string,
|
300
|
+
/** @typedef {KnownAssetInfo & Record<string, EXPECTED_ANY>} AssetInfo */
|
281
301
|
|
282
302
|
/** @typedef {{ path: string, info: AssetInfo }} InterpolatedPathAndAssetInfo */
|
283
303
|
|
@@ -290,25 +310,25 @@ const { isSourceEqual } = require("./util/source");
|
|
290
310
|
|
291
311
|
/**
|
292
312
|
* @typedef {object} ModulePathData
|
293
|
-
* @property {string|number} id
|
313
|
+
* @property {string | number} id
|
294
314
|
* @property {string} hash
|
295
|
-
* @property {
|
315
|
+
* @property {((length: number) => string)=} hashWithLength
|
296
316
|
*/
|
297
317
|
|
298
318
|
/**
|
299
319
|
* @typedef {object} PathData
|
300
320
|
* @property {ChunkGraph=} chunkGraph
|
301
321
|
* @property {string=} hash
|
302
|
-
* @property {
|
303
|
-
* @property {(Chunk|ChunkPathData)=} chunk
|
304
|
-
* @property {(Module|ModulePathData)=} module
|
322
|
+
* @property {((length: number) => string)=} hashWithLength
|
323
|
+
* @property {(Chunk | ChunkPathData)=} chunk
|
324
|
+
* @property {(Module | ModulePathData)=} module
|
305
325
|
* @property {RuntimeSpec=} runtime
|
306
326
|
* @property {string=} filename
|
307
327
|
* @property {string=} basename
|
308
328
|
* @property {string=} query
|
309
329
|
* @property {string=} contentHashType
|
310
330
|
* @property {string=} contentHash
|
311
|
-
* @property {
|
331
|
+
* @property {((length: number) => string)=} contentHashWithLength
|
312
332
|
* @property {boolean=} noChunkHash
|
313
333
|
* @property {string=} url
|
314
334
|
*/
|
@@ -317,11 +337,11 @@ const { isSourceEqual } = require("./util/source");
|
|
317
337
|
* @typedef {object} KnownNormalizedStatsOptions
|
318
338
|
* @property {string} context
|
319
339
|
* @property {RequestShortener} requestShortener
|
320
|
-
* @property {string} chunksSort
|
321
|
-
* @property {string} modulesSort
|
322
|
-
* @property {string} chunkModulesSort
|
323
|
-
* @property {string} nestedModulesSort
|
324
|
-
* @property {string} assetsSort
|
340
|
+
* @property {string | false} chunksSort
|
341
|
+
* @property {string | false} modulesSort
|
342
|
+
* @property {string | false} chunkModulesSort
|
343
|
+
* @property {string | false} nestedModulesSort
|
344
|
+
* @property {string | false} assetsSort
|
325
345
|
* @property {boolean} ids
|
326
346
|
* @property {boolean} cachedAssets
|
327
347
|
* @property {boolean} groupAssetsByEmitStatus
|
@@ -349,27 +369,31 @@ const { isSourceEqual } = require("./util/source");
|
|
349
369
|
* @property {number} modulesSpace
|
350
370
|
* @property {number} chunkModulesSpace
|
351
371
|
* @property {number} nestedModulesSpace
|
352
|
-
* @property {false|"none"|"error"|"warn"|"info"|"log"|"verbose"} logging
|
372
|
+
* @property {false | "none" | "error" | "warn" | "info" | "log" | "verbose"} logging
|
353
373
|
* @property {((value: string) => boolean)[]} loggingDebug
|
354
374
|
* @property {boolean} loggingTrace
|
355
|
-
* @property {
|
375
|
+
* @property {TODO} _env
|
356
376
|
*/
|
357
377
|
|
358
|
-
/** @typedef {KnownNormalizedStatsOptions & Omit<StatsOptions, keyof KnownNormalizedStatsOptions> & Record<string,
|
378
|
+
/** @typedef {KnownNormalizedStatsOptions & Omit<StatsOptions, keyof KnownNormalizedStatsOptions> & Record<string, EXPECTED_ANY>} NormalizedStatsOptions */
|
359
379
|
|
360
380
|
/**
|
361
381
|
* @typedef {object} KnownCreateStatsOptionsContext
|
362
382
|
* @property {boolean=} forToString
|
363
383
|
*/
|
364
384
|
|
365
|
-
/** @typedef {Record<string,
|
385
|
+
/** @typedef {KnownCreateStatsOptionsContext & Record<string, EXPECTED_ANY>} CreateStatsOptionsContext */
|
386
|
+
|
387
|
+
/** @typedef {{ module: Module, hash: string, runtime: RuntimeSpec, runtimes: RuntimeSpec[]}} CodeGenerationJob */
|
366
388
|
|
367
|
-
/** @typedef {
|
389
|
+
/** @typedef {CodeGenerationJob[]} CodeGenerationJobs */
|
368
390
|
|
369
391
|
/** @typedef {{javascript: ModuleTemplate}} ModuleTemplates */
|
370
392
|
|
371
393
|
/** @typedef {Set<Module>} NotCodeGeneratedModules */
|
372
394
|
|
395
|
+
/** @typedef {Record<string, TODO>} Records */
|
396
|
+
|
373
397
|
/** @type {AssetInfo} */
|
374
398
|
const EMPTY_ASSET_INFO = Object.freeze({});
|
375
399
|
|
@@ -433,12 +457,28 @@ const byLocation = compareSelect(err => err.loc, compareLocations);
|
|
433
457
|
|
434
458
|
const compareErrors = concatComparators(byModule, byLocation, byMessage);
|
435
459
|
|
436
|
-
/**
|
460
|
+
/**
|
461
|
+
* @typedef {object} KnownUnsafeCacheData
|
462
|
+
* @property {FactoryMeta} [factoryMeta] factory meta
|
463
|
+
* @property {ResolveOptions} [resolveOptions] resolve options
|
464
|
+
* @property {ParserOptions} [parserOptions]
|
465
|
+
* @property {GeneratorOptions} [generatorOptions]
|
466
|
+
*/
|
467
|
+
|
468
|
+
/** @typedef {KnownUnsafeCacheData & Record<string, EXPECTED_ANY>} UnsafeCacheData */
|
469
|
+
|
470
|
+
/**
|
471
|
+
* @typedef {Module & { restoreFromUnsafeCache?: (unsafeCacheData: UnsafeCacheData, moduleFactory: ModuleFactory, compilationParams: CompilationParams) => void }} ModuleWithRestoreFromUnsafeCache
|
472
|
+
*/
|
473
|
+
|
474
|
+
/** @type {WeakMap<Dependency, ModuleWithRestoreFromUnsafeCache | null>} */
|
437
475
|
const unsafeCacheDependencies = new WeakMap();
|
438
476
|
|
439
|
-
/** @type {WeakMap<
|
477
|
+
/** @type {WeakMap<ModuleWithRestoreFromUnsafeCache, UnsafeCacheData>} */
|
440
478
|
const unsafeCacheData = new WeakMap();
|
441
479
|
|
480
|
+
/** @typedef {Map<Module, WeakTupleMap<any, any>>} ModuleMemCaches */
|
481
|
+
|
442
482
|
class Compilation {
|
443
483
|
/**
|
444
484
|
* Creates an instance of Compilation.
|
@@ -449,7 +489,7 @@ class Compilation {
|
|
449
489
|
this._backCompat = compiler._backCompat;
|
450
490
|
|
451
491
|
const getNormalModuleLoader = () => deprecatedNormalModuleLoaderHook(this);
|
452
|
-
/** @typedef {{ additionalAssets?: true |
|
492
|
+
/** @typedef {{ additionalAssets?: true | TODO }} ProcessAssetsAdditionalOptions */
|
453
493
|
/** @type {AsyncSeriesHook<[CompilationAssets], ProcessAssetsAdditionalOptions>} */
|
454
494
|
const processAssetsHook = new AsyncSeriesHook(["assets"]);
|
455
495
|
|
@@ -480,23 +520,34 @@ class Compilation {
|
|
480
520
|
const { fn, additionalAssets, ...remainingTap } = tap;
|
481
521
|
const additionalAssetsFn =
|
482
522
|
additionalAssets === true ? fn : additionalAssets;
|
523
|
+
/** @typedef {WeakSet<CompilationAssets>} ProcessedAssets */
|
524
|
+
|
525
|
+
/** @type {ProcessedAssets | undefined} */
|
483
526
|
const processedAssets = additionalAssetsFn ? new WeakSet() : undefined;
|
484
527
|
switch (type) {
|
485
528
|
case "sync":
|
486
529
|
if (additionalAssetsFn) {
|
487
530
|
this.hooks.processAdditionalAssets.tap(name, assets => {
|
488
|
-
if (
|
531
|
+
if (
|
532
|
+
/** @type {ProcessedAssets} */
|
533
|
+
(processedAssets).has(this.assets)
|
534
|
+
)
|
489
535
|
additionalAssetsFn(assets);
|
490
536
|
});
|
491
537
|
}
|
492
538
|
return {
|
493
539
|
...remainingTap,
|
494
540
|
type: "async",
|
541
|
+
/**
|
542
|
+
* @param {CompilationAssets} assets assets
|
543
|
+
* @param {(err?: Error | null, result?: void) => void} callback callback
|
544
|
+
* @returns {void}
|
545
|
+
*/
|
495
546
|
fn: (assets, callback) => {
|
496
547
|
try {
|
497
548
|
fn(assets);
|
498
549
|
} catch (err) {
|
499
|
-
return callback(err);
|
550
|
+
return callback(/** @type {Error} */ (err));
|
500
551
|
}
|
501
552
|
if (processedAssets !== undefined)
|
502
553
|
processedAssets.add(this.assets);
|
@@ -516,7 +567,10 @@ class Compilation {
|
|
516
567
|
this.hooks.processAdditionalAssets.tapAsync(
|
517
568
|
name,
|
518
569
|
(assets, callback) => {
|
519
|
-
if (
|
570
|
+
if (
|
571
|
+
/** @type {ProcessedAssets} */
|
572
|
+
(processedAssets).has(this.assets)
|
573
|
+
)
|
520
574
|
return additionalAssetsFn(assets, callback);
|
521
575
|
callback();
|
522
576
|
}
|
@@ -524,33 +578,52 @@ class Compilation {
|
|
524
578
|
}
|
525
579
|
return {
|
526
580
|
...remainingTap,
|
581
|
+
/**
|
582
|
+
* @param {CompilationAssets} assets assets
|
583
|
+
* @param {(err?: Error | null, result?: void) => void} callback callback
|
584
|
+
* @returns {void}
|
585
|
+
*/
|
527
586
|
fn: (assets, callback) => {
|
528
|
-
fn(
|
529
|
-
|
530
|
-
|
531
|
-
|
532
|
-
|
533
|
-
|
534
|
-
|
535
|
-
|
536
|
-
|
537
|
-
|
538
|
-
|
587
|
+
fn(
|
588
|
+
assets,
|
589
|
+
/**
|
590
|
+
* @param {Error} err err
|
591
|
+
* @returns {void}
|
592
|
+
*/
|
593
|
+
err => {
|
594
|
+
if (err) return callback(err);
|
595
|
+
if (processedAssets !== undefined)
|
596
|
+
processedAssets.add(this.assets);
|
597
|
+
const newAssets = popNewAssets(assets);
|
598
|
+
if (newAssets !== undefined) {
|
599
|
+
this.hooks.processAdditionalAssets.callAsync(
|
600
|
+
newAssets,
|
601
|
+
callback
|
602
|
+
);
|
603
|
+
return;
|
604
|
+
}
|
605
|
+
callback();
|
539
606
|
}
|
540
|
-
|
541
|
-
});
|
607
|
+
);
|
542
608
|
}
|
543
609
|
};
|
544
610
|
case "promise":
|
545
611
|
if (additionalAssetsFn) {
|
546
612
|
this.hooks.processAdditionalAssets.tapPromise(name, assets => {
|
547
|
-
if (
|
613
|
+
if (
|
614
|
+
/** @type {ProcessedAssets} */
|
615
|
+
(processedAssets).has(this.assets)
|
616
|
+
)
|
548
617
|
return additionalAssetsFn(assets);
|
549
618
|
return Promise.resolve();
|
550
619
|
});
|
551
620
|
}
|
552
621
|
return {
|
553
622
|
...remainingTap,
|
623
|
+
/**
|
624
|
+
* @param {CompilationAssets} assets assets
|
625
|
+
* @returns {Promise<CompilationAssets>} result
|
626
|
+
*/
|
554
627
|
fn: assets => {
|
555
628
|
const p = fn(assets);
|
556
629
|
if (!p || !p.then) return p;
|
@@ -577,9 +650,9 @@ class Compilation {
|
|
577
650
|
* @template T
|
578
651
|
* @param {string} name name of the hook
|
579
652
|
* @param {number} stage new stage
|
580
|
-
* @param {
|
653
|
+
* @param {() => AsArray<T>} getArgs get old hook function args
|
581
654
|
* @param {string=} code deprecation code (not deprecated when unset)
|
582
|
-
* @returns {FakeHook<Pick<AsyncSeriesHook<T>, "tap" | "tapAsync" | "tapPromise" | "name">>} fake hook which redirects
|
655
|
+
* @returns {FakeHook<Pick<AsyncSeriesHook<T>, "tap" | "tapAsync" | "tapPromise" | "name">> | undefined} fake hook which redirects
|
583
656
|
*/
|
584
657
|
const createProcessAssetsHook = (name, stage, getArgs, code) => {
|
585
658
|
if (!this._backCompat && code) return;
|
@@ -590,6 +663,10 @@ class Compilation {
|
|
590
663
|
const errorMessage =
|
591
664
|
reason => `Can't automatically convert plugin using Compilation.hooks.${name} to Compilation.hooks.processAssets because ${reason}.
|
592
665
|
BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a single Compilation.hooks.processAssets hook.`;
|
666
|
+
/**
|
667
|
+
* @param {string | (import("tapable").TapOptions & { name: string; } & ProcessAssetsAdditionalOptions)} options hook options
|
668
|
+
* @returns {import("tapable").TapOptions & { name: string; } & ProcessAssetsAdditionalOptions} modified options
|
669
|
+
*/
|
593
670
|
const getOptions = options => {
|
594
671
|
if (typeof options === "string") options = { name: options };
|
595
672
|
if (options.stage) {
|
@@ -740,7 +817,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
|
|
740
817
|
/** @type {SyncHook<[RuntimeModule, Chunk]>} */
|
741
818
|
runtimeModule: new SyncHook(["module", "chunk"]),
|
742
819
|
|
743
|
-
/** @type {SyncHook<[Iterable<Module>,
|
820
|
+
/** @type {SyncHook<[Iterable<Module>, Records]>} */
|
744
821
|
reviveModules: new SyncHook(["modules", "records"]),
|
745
822
|
/** @type {SyncHook<[Iterable<Module>]>} */
|
746
823
|
beforeModuleIds: new SyncHook(["modules"]),
|
@@ -751,7 +828,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
|
|
751
828
|
/** @type {SyncHook<[Iterable<Module>]>} */
|
752
829
|
afterOptimizeModuleIds: new SyncHook(["modules"]),
|
753
830
|
|
754
|
-
/** @type {SyncHook<[Iterable<Chunk>,
|
831
|
+
/** @type {SyncHook<[Iterable<Chunk>, Records]>} */
|
755
832
|
reviveChunks: new SyncHook(["chunks", "records"]),
|
756
833
|
/** @type {SyncHook<[Iterable<Chunk>]>} */
|
757
834
|
beforeChunkIds: new SyncHook(["chunks"]),
|
@@ -762,9 +839,9 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
|
|
762
839
|
/** @type {SyncHook<[Iterable<Chunk>]>} */
|
763
840
|
afterOptimizeChunkIds: new SyncHook(["chunks"]),
|
764
841
|
|
765
|
-
/** @type {SyncHook<[Iterable<Module>,
|
842
|
+
/** @type {SyncHook<[Iterable<Module>, Records]>} */
|
766
843
|
recordModules: new SyncHook(["modules", "records"]),
|
767
|
-
/** @type {SyncHook<[Iterable<Chunk>,
|
844
|
+
/** @type {SyncHook<[Iterable<Chunk>, Records]>} */
|
768
845
|
recordChunks: new SyncHook(["chunks", "records"]),
|
769
846
|
|
770
847
|
/** @type {SyncHook<[Iterable<Module>]>} */
|
@@ -791,9 +868,9 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
|
|
791
868
|
contentHash: new SyncHook(["chunk"]),
|
792
869
|
/** @type {SyncHook<[]>} */
|
793
870
|
afterHash: new SyncHook([]),
|
794
|
-
/** @type {SyncHook<[
|
871
|
+
/** @type {SyncHook<[Records]>} */
|
795
872
|
recordHash: new SyncHook(["records"]),
|
796
|
-
/** @type {SyncHook<[Compilation,
|
873
|
+
/** @type {SyncHook<[Compilation, Records]>} */
|
797
874
|
record: new SyncHook(["compilation", "records"]),
|
798
875
|
|
799
876
|
/** @type {SyncHook<[]>} */
|
@@ -804,36 +881,52 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
|
|
804
881
|
beforeChunkAssets: new SyncHook([]),
|
805
882
|
// TODO webpack 6 remove
|
806
883
|
/** @deprecated */
|
807
|
-
additionalChunkAssets:
|
808
|
-
"
|
809
|
-
|
810
|
-
|
811
|
-
|
812
|
-
|
884
|
+
additionalChunkAssets:
|
885
|
+
/** @type {FakeHook<Pick<AsyncSeriesHook<[Set<Chunk>]>, "tap" | "tapAsync" | "tapPromise" | "name">>} */
|
886
|
+
(
|
887
|
+
createProcessAssetsHook(
|
888
|
+
"additionalChunkAssets",
|
889
|
+
Compilation.PROCESS_ASSETS_STAGE_ADDITIONAL,
|
890
|
+
() => [this.chunks],
|
891
|
+
"DEP_WEBPACK_COMPILATION_ADDITIONAL_CHUNK_ASSETS"
|
892
|
+
)
|
893
|
+
),
|
813
894
|
|
814
895
|
// TODO webpack 6 deprecate
|
815
896
|
/** @deprecated */
|
816
|
-
additionalAssets:
|
817
|
-
"
|
818
|
-
|
819
|
-
|
820
|
-
|
897
|
+
additionalAssets:
|
898
|
+
/** @type {FakeHook<Pick<AsyncSeriesHook<[]>, "tap" | "tapAsync" | "tapPromise" | "name">>} */
|
899
|
+
(
|
900
|
+
createProcessAssetsHook(
|
901
|
+
"additionalAssets",
|
902
|
+
Compilation.PROCESS_ASSETS_STAGE_ADDITIONAL,
|
903
|
+
() => []
|
904
|
+
)
|
905
|
+
),
|
821
906
|
// TODO webpack 6 remove
|
822
907
|
/** @deprecated */
|
823
|
-
optimizeChunkAssets:
|
824
|
-
"
|
825
|
-
|
826
|
-
|
827
|
-
|
828
|
-
|
908
|
+
optimizeChunkAssets:
|
909
|
+
/** @type {FakeHook<Pick<AsyncSeriesHook<[Set<Chunk>]>, "tap" | "tapAsync" | "tapPromise" | "name">>} */
|
910
|
+
(
|
911
|
+
createProcessAssetsHook(
|
912
|
+
"optimizeChunkAssets",
|
913
|
+
Compilation.PROCESS_ASSETS_STAGE_OPTIMIZE,
|
914
|
+
() => [this.chunks],
|
915
|
+
"DEP_WEBPACK_COMPILATION_OPTIMIZE_CHUNK_ASSETS"
|
916
|
+
)
|
917
|
+
),
|
829
918
|
// TODO webpack 6 remove
|
830
919
|
/** @deprecated */
|
831
|
-
afterOptimizeChunkAssets:
|
832
|
-
"
|
833
|
-
|
834
|
-
|
835
|
-
|
836
|
-
|
920
|
+
afterOptimizeChunkAssets:
|
921
|
+
/** @type {FakeHook<Pick<AsyncSeriesHook<[Set<Chunk>]>, "tap" | "tapAsync" | "tapPromise" | "name">>} */
|
922
|
+
(
|
923
|
+
createProcessAssetsHook(
|
924
|
+
"afterOptimizeChunkAssets",
|
925
|
+
Compilation.PROCESS_ASSETS_STAGE_OPTIMIZE + 1,
|
926
|
+
() => [this.chunks],
|
927
|
+
"DEP_WEBPACK_COMPILATION_AFTER_OPTIMIZE_CHUNK_ASSETS"
|
928
|
+
)
|
929
|
+
),
|
837
930
|
// TODO webpack 6 deprecate
|
838
931
|
/** @deprecated */
|
839
932
|
optimizeAssets: processAssetsHook,
|
@@ -864,7 +957,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
|
|
864
957
|
/** @type {SyncHook<[Chunk, string]>} */
|
865
958
|
chunkAsset: new SyncHook(["chunk", "filename"]),
|
866
959
|
|
867
|
-
/** @type {SyncWaterfallHook<[string,
|
960
|
+
/** @type {SyncWaterfallHook<[string, PathData, AssetInfo | undefined]>} */
|
868
961
|
assetPath: new SyncWaterfallHook(["path", "options", "assetInfo"]),
|
869
962
|
|
870
963
|
/** @type {SyncBailHook<[], boolean | void>} */
|
@@ -956,15 +1049,15 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
|
|
956
1049
|
};
|
957
1050
|
defineRemovedModuleTemplates(this.moduleTemplates);
|
958
1051
|
|
959
|
-
/** @type {
|
1052
|
+
/** @type {ModuleMemCaches | undefined} */
|
960
1053
|
this.moduleMemCaches = undefined;
|
961
|
-
/** @type {
|
1054
|
+
/** @type {ModuleMemCaches | undefined} */
|
962
1055
|
this.moduleMemCaches2 = undefined;
|
963
1056
|
this.moduleGraph = new ModuleGraph();
|
964
1057
|
/** @type {ChunkGraph} */
|
965
|
-
this.chunkGraph = undefined;
|
1058
|
+
this.chunkGraph = /** @type {TODO} */ (undefined);
|
966
1059
|
/** @type {CodeGenerationResults} */
|
967
|
-
this.codeGenerationResults = undefined;
|
1060
|
+
this.codeGenerationResults = /** @type {TODO} */ (undefined);
|
968
1061
|
|
969
1062
|
/** @type {AsyncQueue<Module, Module, Module>} */
|
970
1063
|
this.processDependenciesQueue = new AsyncQueue({
|
@@ -1039,6 +1132,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
|
|
1039
1132
|
* @type {Map<string, Module>}
|
1040
1133
|
*/
|
1041
1134
|
this._modules = new Map();
|
1135
|
+
/** @type {Records | null} */
|
1042
1136
|
this.records = null;
|
1043
1137
|
/** @type {string[]} */
|
1044
1138
|
this.additionalChunkAssets = [];
|
@@ -1064,15 +1158,15 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
|
|
1064
1158
|
);
|
1065
1159
|
/** @type {Record<string, number>} */
|
1066
1160
|
this.childrenCounters = {};
|
1067
|
-
/** @type {Set<number|string>} */
|
1161
|
+
/** @type {Set<number|string> | null} */
|
1068
1162
|
this.usedChunkIds = null;
|
1069
|
-
/** @type {Set<number>} */
|
1163
|
+
/** @type {Set<number> | null} */
|
1070
1164
|
this.usedModuleIds = null;
|
1071
1165
|
/** @type {boolean} */
|
1072
1166
|
this.needAdditionalPass = false;
|
1073
|
-
/** @type {Set<
|
1167
|
+
/** @type {Set<ModuleWithRestoreFromUnsafeCache>} */
|
1074
1168
|
this._restoredUnsafeCacheModuleEntries = new Set();
|
1075
|
-
/** @type {Map<string,
|
1169
|
+
/** @type {Map<string, ModuleWithRestoreFromUnsafeCache>} */
|
1076
1170
|
this._restoredUnsafeCacheEntries = new Map();
|
1077
1171
|
/** @type {WeakSet<Module>} */
|
1078
1172
|
this.builtModules = new WeakSet();
|
@@ -1182,7 +1276,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
|
|
1182
1276
|
}
|
1183
1277
|
|
1184
1278
|
/**
|
1185
|
-
* @param {string | (
|
1279
|
+
* @param {string | (() => string)} name name of the logger, or function called once to get the logger name
|
1186
1280
|
* @returns {Logger} a logger with that name
|
1187
1281
|
*/
|
1188
1282
|
getLogger(name) {
|
@@ -1220,6 +1314,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
|
|
1220
1314
|
args,
|
1221
1315
|
trace
|
1222
1316
|
};
|
1317
|
+
/* eslint-disable no-console */
|
1223
1318
|
if (this.hooks.log.call(name, logEntry) === undefined) {
|
1224
1319
|
if (
|
1225
1320
|
logEntry.type === LogType.profileEnd &&
|
@@ -1248,6 +1343,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
|
|
1248
1343
|
}`
|
1249
1344
|
);
|
1250
1345
|
}
|
1346
|
+
/* eslint-enable no-console */
|
1251
1347
|
}
|
1252
1348
|
},
|
1253
1349
|
childName => {
|
@@ -1668,6 +1764,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
|
|
1668
1764
|
return;
|
1669
1765
|
}
|
1670
1766
|
} catch (err) {
|
1767
|
+
// eslint-disable-next-line no-console
|
1671
1768
|
console.error(err);
|
1672
1769
|
}
|
1673
1770
|
}
|
@@ -1909,7 +2006,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
|
|
1909
2006
|
}
|
1910
2007
|
|
1911
2008
|
const module =
|
1912
|
-
/** @type {
|
2009
|
+
/** @type {ModuleWithRestoreFromUnsafeCache} */
|
1913
2010
|
(_module);
|
1914
2011
|
|
1915
2012
|
if (
|
@@ -1920,7 +2017,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
|
|
1920
2017
|
this._unsafeCachePredicate(module)
|
1921
2018
|
) {
|
1922
2019
|
const unsafeCacheableModule =
|
1923
|
-
/** @type {
|
2020
|
+
/** @type {ModuleWithRestoreFromUnsafeCache} */
|
1924
2021
|
(module);
|
1925
2022
|
for (let i = 0; i < dependencies.length; i++) {
|
1926
2023
|
const dependency = dependencies[i];
|
@@ -1976,7 +2073,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
|
|
1976
2073
|
|
1977
2074
|
/**
|
1978
2075
|
* @private
|
1979
|
-
* @param {Module} originModule original module
|
2076
|
+
* @param {Module | null} originModule original module
|
1980
2077
|
* @param {Module} module module
|
1981
2078
|
* @param {boolean} recursive true if make it recursive, otherwise false
|
1982
2079
|
* @param {boolean} checkCycle true if need to check cycle, otherwise false
|
@@ -1993,14 +2090,20 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
|
|
1993
2090
|
// Check for cycles when build is trigger inside another build
|
1994
2091
|
/** @type {Set<Module> | undefined} */
|
1995
2092
|
let creatingModuleDuringBuildSet;
|
1996
|
-
if (
|
2093
|
+
if (
|
2094
|
+
checkCycle &&
|
2095
|
+
this.buildQueue.isProcessing(/** @type {Module} */ (originModule))
|
2096
|
+
) {
|
1997
2097
|
// Track build dependency
|
1998
|
-
creatingModuleDuringBuildSet =
|
1999
|
-
|
2098
|
+
creatingModuleDuringBuildSet = this.creatingModuleDuringBuild.get(
|
2099
|
+
/** @type {Module} */
|
2100
|
+
(originModule)
|
2101
|
+
);
|
2000
2102
|
if (creatingModuleDuringBuildSet === undefined) {
|
2001
2103
|
creatingModuleDuringBuildSet = new Set();
|
2002
2104
|
this.creatingModuleDuringBuild.set(
|
2003
|
-
|
2105
|
+
/** @type {Module} */
|
2106
|
+
(originModule),
|
2004
2107
|
creatingModuleDuringBuildSet
|
2005
2108
|
);
|
2006
2109
|
}
|
@@ -2082,15 +2185,19 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
|
|
2082
2185
|
factory.create(
|
2083
2186
|
{
|
2084
2187
|
contextInfo: {
|
2085
|
-
issuer: originModule
|
2188
|
+
issuer: originModule
|
2189
|
+
? /** @type {string} */ (originModule.nameForCondition())
|
2190
|
+
: "",
|
2086
2191
|
issuerLayer: originModule ? originModule.layer : null,
|
2087
|
-
compiler: this.compiler.name,
|
2192
|
+
compiler: /** @type {string} */ (this.compiler.name),
|
2088
2193
|
...contextInfo
|
2089
2194
|
},
|
2090
2195
|
resolveOptions: originModule ? originModule.resolveOptions : undefined,
|
2091
2196
|
context:
|
2092
2197
|
context ||
|
2093
|
-
(originModule
|
2198
|
+
(originModule
|
2199
|
+
? /** @type {string} */ (originModule.context)
|
2200
|
+
: /** @type {string} */ (this.compiler.context)),
|
2094
2201
|
dependencies
|
2095
2202
|
},
|
2096
2203
|
(err, result) => {
|
@@ -2260,12 +2367,14 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
|
|
2260
2367
|
};
|
2261
2368
|
entryData[target].push(entry);
|
2262
2369
|
this.entries.set(
|
2263
|
-
/** @type {NonNullable<EntryOptions["name"]>} */
|
2370
|
+
/** @type {NonNullable<EntryOptions["name"]>} */
|
2371
|
+
(name),
|
2264
2372
|
entryData
|
2265
2373
|
);
|
2266
2374
|
} else {
|
2267
2375
|
entryData[target].push(entry);
|
2268
|
-
for (const
|
2376
|
+
for (const _key of Object.keys(options)) {
|
2377
|
+
const key = /** @type {keyof EntryOptions} */ (_key);
|
2269
2378
|
if (options[key] === undefined) continue;
|
2270
2379
|
if (entryData.options[key] === options[key]) continue;
|
2271
2380
|
if (
|
@@ -2276,7 +2385,10 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
|
|
2276
2385
|
continue;
|
2277
2386
|
}
|
2278
2387
|
if (entryData.options[key] === undefined) {
|
2279
|
-
|
2388
|
+
/** @type {TODO} */
|
2389
|
+
(entryData.options)[key] =
|
2390
|
+
/** @type {NonNullable<EntryOptions[keyof EntryOptions]>} */
|
2391
|
+
(options[key]);
|
2280
2392
|
} else {
|
2281
2393
|
return callback(
|
2282
2394
|
new WebpackError(
|
@@ -2302,7 +2414,12 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
|
|
2302
2414
|
this.hooks.failedEntry.call(entry, options, err);
|
2303
2415
|
return callback(err);
|
2304
2416
|
}
|
2305
|
-
this.hooks.succeedEntry.call(
|
2417
|
+
this.hooks.succeedEntry.call(
|
2418
|
+
entry,
|
2419
|
+
options,
|
2420
|
+
/** @type {Module} */
|
2421
|
+
(module)
|
2422
|
+
);
|
2306
2423
|
return callback(null, module);
|
2307
2424
|
}
|
2308
2425
|
);
|
@@ -2981,7 +3098,12 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
|
|
2981
3098
|
|
2982
3099
|
const entryModules = new Set();
|
2983
3100
|
for (const dep of [...this.globalEntry.dependencies, ...dependencies]) {
|
2984
|
-
entrypoint.addOrigin(
|
3101
|
+
entrypoint.addOrigin(
|
3102
|
+
null,
|
3103
|
+
{ name },
|
3104
|
+
/** @type {Dependency & { request: string }} */
|
3105
|
+
(dep).request
|
3106
|
+
);
|
2985
3107
|
|
2986
3108
|
const module = this.moduleGraph.getModule(dep);
|
2987
3109
|
if (module) {
|
@@ -3136,13 +3258,21 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
|
|
3136
3258
|
|
3137
3259
|
const shouldRecord = this.hooks.shouldRecord.call() !== false;
|
3138
3260
|
|
3139
|
-
this.hooks.reviveModules.call(
|
3261
|
+
this.hooks.reviveModules.call(
|
3262
|
+
this.modules,
|
3263
|
+
/** @type {Records} */
|
3264
|
+
(this.records)
|
3265
|
+
);
|
3140
3266
|
this.hooks.beforeModuleIds.call(this.modules);
|
3141
3267
|
this.hooks.moduleIds.call(this.modules);
|
3142
3268
|
this.hooks.optimizeModuleIds.call(this.modules);
|
3143
3269
|
this.hooks.afterOptimizeModuleIds.call(this.modules);
|
3144
3270
|
|
3145
|
-
this.hooks.reviveChunks.call(
|
3271
|
+
this.hooks.reviveChunks.call(
|
3272
|
+
this.chunks,
|
3273
|
+
/** @type {Records} */
|
3274
|
+
(this.records)
|
3275
|
+
);
|
3146
3276
|
this.hooks.beforeChunkIds.call(this.chunks);
|
3147
3277
|
this.hooks.chunkIds.call(this.chunks);
|
3148
3278
|
this.hooks.optimizeChunkIds.call(this.chunks);
|
@@ -3157,8 +3287,16 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
|
|
3157
3287
|
this.sortItemsWithChunkIds();
|
3158
3288
|
|
3159
3289
|
if (shouldRecord) {
|
3160
|
-
this.hooks.recordModules.call(
|
3161
|
-
|
3290
|
+
this.hooks.recordModules.call(
|
3291
|
+
this.modules,
|
3292
|
+
/** @type {Records} */
|
3293
|
+
(this.records)
|
3294
|
+
);
|
3295
|
+
this.hooks.recordChunks.call(
|
3296
|
+
this.chunks,
|
3297
|
+
/** @type {Records} */
|
3298
|
+
(this.records)
|
3299
|
+
);
|
3162
3300
|
}
|
3163
3301
|
|
3164
3302
|
this.hooks.optimizeCodeGeneration.call(this.modules);
|
@@ -3198,7 +3336,10 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
|
|
3198
3336
|
|
3199
3337
|
if (shouldRecord) {
|
3200
3338
|
this.logger.time("record hash");
|
3201
|
-
this.hooks.recordHash.call(
|
3339
|
+
this.hooks.recordHash.call(
|
3340
|
+
/** @type {Records} */
|
3341
|
+
(this.records)
|
3342
|
+
);
|
3202
3343
|
this.logger.timeEnd("record hash");
|
3203
3344
|
}
|
3204
3345
|
|
@@ -3219,22 +3360,28 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
|
|
3219
3360
|
}
|
3220
3361
|
this.hooks.afterProcessAssets.call(this.assets);
|
3221
3362
|
this.logger.timeEnd("process assets");
|
3222
|
-
this.assets =
|
3223
|
-
|
3224
|
-
|
3225
|
-
|
3226
|
-
|
3227
|
-
|
3228
|
-
|
3363
|
+
this.assets =
|
3364
|
+
/** @type {CompilationAssets} */
|
3365
|
+
(
|
3366
|
+
this._backCompat
|
3367
|
+
? soonFrozenObjectDeprecation(
|
3368
|
+
this.assets,
|
3369
|
+
"Compilation.assets",
|
3370
|
+
"DEP_WEBPACK_COMPILATION_ASSETS",
|
3371
|
+
`BREAKING CHANGE: No more changes should happen to Compilation.assets after sealing the Compilation.
|
3229
3372
|
Do changes to assets earlier, e. g. in Compilation.hooks.processAssets.
|
3230
3373
|
Make sure to select an appropriate stage from Compilation.PROCESS_ASSETS_STAGE_*.`
|
3231
|
-
|
3232
|
-
|
3233
|
-
|
3374
|
+
)
|
3375
|
+
: Object.freeze(this.assets)
|
3376
|
+
);
|
3234
3377
|
|
3235
3378
|
this.summarizeDependencies();
|
3236
3379
|
if (shouldRecord) {
|
3237
|
-
this.hooks.record.call(
|
3380
|
+
this.hooks.record.call(
|
3381
|
+
this,
|
3382
|
+
/** @type {Records} */
|
3383
|
+
(this.records)
|
3384
|
+
);
|
3238
3385
|
}
|
3239
3386
|
|
3240
3387
|
if (this.hooks.needAdditionalSeal.call()) {
|
@@ -3471,7 +3618,7 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
|
|
3471
3618
|
* @param {RuntimeTemplate} runtimeTemplate runtimeTemplate
|
3472
3619
|
* @param {WebpackError[]} errors errors
|
3473
3620
|
* @param {CodeGenerationResults} results results
|
3474
|
-
* @param {
|
3621
|
+
* @param {(err?: WebpackError | null, result?: boolean) => void} callback callback
|
3475
3622
|
*/
|
3476
3623
|
_codeGenerationModule(
|
3477
3624
|
module,
|
@@ -3752,7 +3899,6 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
|
|
3752
3899
|
groupOptions = { name: groupOptions };
|
3753
3900
|
}
|
3754
3901
|
const name = groupOptions.name;
|
3755
|
-
|
3756
3902
|
if (name) {
|
3757
3903
|
const chunkGroup = this.namedChunkGroups.get(name);
|
3758
3904
|
if (chunkGroup !== undefined) {
|
@@ -3761,7 +3907,8 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
|
|
3761
3907
|
module,
|
3762
3908
|
/** @type {DependencyLocation} */
|
3763
3909
|
(loc),
|
3764
|
-
|
3910
|
+
/** @type {string} */
|
3911
|
+
(request)
|
3765
3912
|
);
|
3766
3913
|
}
|
3767
3914
|
return chunkGroup;
|
@@ -3773,7 +3920,8 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
|
|
3773
3920
|
module,
|
3774
3921
|
/** @type {DependencyLocation} */
|
3775
3922
|
(loc),
|
3776
|
-
|
3923
|
+
/** @type {string} */
|
3924
|
+
(request)
|
3777
3925
|
);
|
3778
3926
|
const chunk = this.addChunk(name);
|
3779
3927
|
|
@@ -3832,7 +3980,7 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
|
|
3832
3980
|
/**
|
3833
3981
|
* This method first looks to see if a name is provided for a new chunk,
|
3834
3982
|
* and first looks to see if any named chunks already exist and reuse that chunk instead.
|
3835
|
-
* @param {string=} name optional chunk name to be provided
|
3983
|
+
* @param {(string | null)=} name optional chunk name to be provided
|
3836
3984
|
* @returns {Chunk} create a chunk (invoked during seal event)
|
3837
3985
|
*/
|
3838
3986
|
addChunk(name) {
|
@@ -4317,9 +4465,9 @@ This prevents using hashes of each other and should be avoided.`);
|
|
4317
4465
|
this.logger.timeEnd("hashing: sort chunks");
|
4318
4466
|
|
4319
4467
|
const fullHashChunks = new Set();
|
4320
|
-
/** @type {
|
4468
|
+
/** @type {CodeGenerationJobs} */
|
4321
4469
|
const codeGenerationJobs = [];
|
4322
|
-
/** @type {Map<string, Map<Module,
|
4470
|
+
/** @type {Map<string, Map<Module, CodeGenerationJob>>} */
|
4323
4471
|
const codeGenerationJobsMap = new Map();
|
4324
4472
|
/** @type {WebpackError[]} */
|
4325
4473
|
const errors = [];
|
@@ -4436,7 +4584,11 @@ This prevents using hashes of each other and should be avoided.`);
|
|
4436
4584
|
moduleHashDigest,
|
4437
4585
|
moduleHashDigest.slice(0, hashDigestLength)
|
4438
4586
|
);
|
4439
|
-
|
4587
|
+
/** @type {CodeGenerationJob} */
|
4588
|
+
(
|
4589
|
+
/** @type {Map<Module, CodeGenerationJob>} */
|
4590
|
+
(codeGenerationJobsMap.get(oldHash)).get(module)
|
4591
|
+
).hash = moduleHashDigest;
|
4440
4592
|
}
|
4441
4593
|
const chunkHash = createHash(/** @type {Algorithm} */ (hashFunction));
|
4442
4594
|
chunkHash.update(chunk.hash);
|
@@ -4486,7 +4638,7 @@ This prevents using hashes of each other and should be avoided.`);
|
|
4486
4638
|
/**
|
4487
4639
|
* @private
|
4488
4640
|
* @param {string} file file name
|
4489
|
-
* @param {AssetInfo} newInfo new asset information
|
4641
|
+
* @param {AssetInfo=} newInfo new asset information
|
4490
4642
|
* @param {AssetInfo=} oldInfo old asset information
|
4491
4643
|
*/
|
4492
4644
|
_setAssetInfo(file, newInfo, oldInfo = this.assetsInfo.get(file)) {
|
@@ -4552,8 +4704,8 @@ This prevents using hashes of each other and should be avoided.`);
|
|
4552
4704
|
|
4553
4705
|
/**
|
4554
4706
|
* @param {string} file file name
|
4555
|
-
* @param {Source |
|
4556
|
-
* @param {(AssetInfo |
|
4707
|
+
* @param {Source | ((source: Source) => Source)} newSourceOrFunction new asset source or function converting old to new
|
4708
|
+
* @param {(AssetInfo | ((assetInfo?: AssetInfo) => AssetInfo | undefined)) | undefined} assetInfoUpdateOrFunction new asset info or function converting old to new
|
4557
4709
|
*/
|
4558
4710
|
updateAsset(
|
4559
4711
|
file,
|
@@ -4796,7 +4948,7 @@ This prevents using hashes of each other and should be avoided.`);
|
|
4796
4948
|
manifest,
|
4797
4949
|
(fileManifest, callback) => {
|
4798
4950
|
const ident = fileManifest.identifier;
|
4799
|
-
const usedHash = fileManifest.hash;
|
4951
|
+
const usedHash = /** @type {string} */ (fileManifest.hash);
|
4800
4952
|
|
4801
4953
|
const assetCacheItem = this._assetsCache.getItemCache(
|
4802
4954
|
ident,
|
@@ -5242,12 +5394,15 @@ This prevents using hashes of each other and should be avoided.`);
|
|
5242
5394
|
err => {
|
5243
5395
|
if (err) return callback(err);
|
5244
5396
|
|
5397
|
+
/** @type {ExecuteModuleExports | undefined} */
|
5245
5398
|
let exports;
|
5246
5399
|
try {
|
5247
5400
|
const {
|
5248
5401
|
strictModuleErrorHandling,
|
5249
5402
|
strictModuleExceptionHandling
|
5250
5403
|
} = this.outputOptions;
|
5404
|
+
|
5405
|
+
/** @type {WebpackRequire} */
|
5251
5406
|
const __webpack_require__ = id => {
|
5252
5407
|
const cached = moduleCache[id];
|
5253
5408
|
if (cached !== undefined) {
|
@@ -5255,29 +5410,39 @@ This prevents using hashes of each other and should be avoided.`);
|
|
5255
5410
|
return cached.exports;
|
5256
5411
|
}
|
5257
5412
|
const moduleArgument = moduleArgumentsById.get(id);
|
5258
|
-
return __webpack_require_module__(
|
5413
|
+
return __webpack_require_module__(
|
5414
|
+
/** @type {ExecuteModuleArgument} */
|
5415
|
+
(moduleArgument),
|
5416
|
+
id
|
5417
|
+
);
|
5259
5418
|
};
|
5260
5419
|
const interceptModuleExecution = (__webpack_require__[
|
5261
|
-
|
5262
|
-
|
5263
|
-
|
5420
|
+
/** @type {"i"} */
|
5421
|
+
(
|
5422
|
+
RuntimeGlobals.interceptModuleExecution.replace(
|
5423
|
+
`${RuntimeGlobals.require}.`,
|
5424
|
+
""
|
5425
|
+
)
|
5264
5426
|
)
|
5265
|
-
] = []);
|
5427
|
+
] = /** @type {NonNullable<WebpackRequire["i"]>} */ ([]));
|
5266
5428
|
const moduleCache = (__webpack_require__[
|
5267
|
-
|
5268
|
-
|
5269
|
-
|
5429
|
+
/** @type {"c"} */ (
|
5430
|
+
RuntimeGlobals.moduleCache.replace(
|
5431
|
+
`${RuntimeGlobals.require}.`,
|
5432
|
+
""
|
5433
|
+
)
|
5270
5434
|
)
|
5271
|
-
] = {});
|
5435
|
+
] = /** @type {NonNullable<WebpackRequire["c"]>} */ ({}));
|
5272
5436
|
|
5273
5437
|
context.__webpack_require__ = __webpack_require__;
|
5274
5438
|
|
5275
5439
|
/**
|
5276
5440
|
* @param {ExecuteModuleArgument} moduleArgument the module argument
|
5277
5441
|
* @param {string=} id id
|
5278
|
-
* @returns {
|
5442
|
+
* @returns {ExecuteModuleExports} exports
|
5279
5443
|
*/
|
5280
5444
|
const __webpack_require_module__ = (moduleArgument, id) => {
|
5445
|
+
/** @type {ExecuteOptions} */
|
5281
5446
|
const execOptions = {
|
5282
5447
|
id,
|
5283
5448
|
module: {
|
@@ -5312,9 +5477,14 @@ This prevents using hashes of each other and should be avoided.`);
|
|
5312
5477
|
if (strictModuleExceptionHandling) {
|
5313
5478
|
if (id) delete moduleCache[id];
|
5314
5479
|
} else if (strictModuleErrorHandling) {
|
5315
|
-
moduleObject.error =
|
5480
|
+
moduleObject.error = /** @type {WebpackError} */ (
|
5481
|
+
execErr
|
5482
|
+
);
|
5483
|
+
}
|
5484
|
+
if (!(/** @type {WebpackError} */ (execErr).module)) {
|
5485
|
+
/** @type {WebpackError} */
|
5486
|
+
(execErr).module = module;
|
5316
5487
|
}
|
5317
|
-
if (!execErr.module) execErr.module = module;
|
5318
5488
|
throw execErr;
|
5319
5489
|
}
|
5320
5490
|
};
|
@@ -5329,13 +5499,17 @@ This prevents using hashes of each other and should be avoided.`);
|
|
5329
5499
|
}
|
5330
5500
|
exports = __webpack_require__(module.identifier());
|
5331
5501
|
} catch (execErr) {
|
5502
|
+
const { message, stack, module } =
|
5503
|
+
/** @type {WebpackError} */
|
5504
|
+
(execErr);
|
5332
5505
|
const err = new WebpackError(
|
5333
|
-
`Execution of module code from module graph (${
|
5334
|
-
|
5335
|
-
|
5506
|
+
`Execution of module code from module graph (${
|
5507
|
+
/** @type {Module} */
|
5508
|
+
(module).readableIdentifier(this.requestShortener)
|
5509
|
+
}) failed: ${message}`
|
5336
5510
|
);
|
5337
|
-
err.stack =
|
5338
|
-
err.module =
|
5511
|
+
err.stack = stack;
|
5512
|
+
err.module = module;
|
5339
5513
|
return callback(err);
|
5340
5514
|
}
|
5341
5515
|
|
@@ -5422,7 +5596,7 @@ Compilation.prototype.factorizeModule = /**
|
|
5422
5596
|
(options: FactorizeModuleOptions & { factoryResult: true }, callback: ModuleFactoryResultCallback): void;
|
5423
5597
|
}} */ (
|
5424
5598
|
function (options, callback) {
|
5425
|
-
this.factorizeQueue.add(options, callback);
|
5599
|
+
this.factorizeQueue.add(options, /** @type {TODO} */ (callback));
|
5426
5600
|
}
|
5427
5601
|
);
|
5428
5602
|
/* eslint-enable jsdoc/require-asterisk-prefix */
|
@@ -5459,7 +5633,7 @@ Object.defineProperty(compilationPrototype, "cache", {
|
|
5459
5633
|
),
|
5460
5634
|
set: util.deprecate(
|
5461
5635
|
/**
|
5462
|
-
* @param {
|
5636
|
+
* @param {EXPECTED_ANY} v value
|
5463
5637
|
*/
|
5464
5638
|
v => {},
|
5465
5639
|
"Compilation.cache was removed in favor of Compilation.getCache()",
|