webpack 5.90.3 → 5.91.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.
- package/README.md +5 -5
- package/bin/webpack.js +5 -1
- package/lib/APIPlugin.js +8 -4
- package/lib/AutomaticPrefetchPlugin.js +1 -1
- package/lib/BannerPlugin.js +3 -1
- package/lib/Cache.js +7 -1
- package/lib/CacheFacade.js +3 -3
- package/lib/ChunkGraph.js +32 -18
- package/lib/ChunkGroup.js +14 -14
- package/lib/CleanPlugin.js +7 -5
- package/lib/Compilation.js +262 -93
- package/lib/Compiler.js +199 -83
- package/lib/ConditionalInitFragment.js +4 -5
- package/lib/ContextModule.js +2 -0
- package/lib/ContextModuleFactory.js +4 -2
- package/lib/ContextReplacementPlugin.js +3 -2
- package/lib/DefinePlugin.js +4 -2
- package/lib/Dependency.js +4 -2
- package/lib/DependencyTemplate.js +7 -2
- package/lib/DllModule.js +1 -0
- package/lib/DllReferencePlugin.js +6 -2
- package/lib/EntryOptionPlugin.js +4 -1
- package/lib/EntryPlugin.js +6 -1
- package/lib/Entrypoint.js +1 -1
- package/lib/ExportsInfo.js +1 -4
- package/lib/ExternalModule.js +118 -24
- package/lib/ExternalModuleFactoryPlugin.js +37 -2
- package/lib/FileSystemInfo.js +1 -1
- package/lib/Generator.js +2 -1
- package/lib/HookWebpackError.js +2 -2
- package/lib/InitFragment.js +5 -3
- package/lib/LibManifestPlugin.js +15 -7
- package/lib/Module.js +30 -2
- package/lib/ModuleFilenameHelpers.js +1 -1
- package/lib/ModuleGraph.js +56 -27
- package/lib/ModuleGraphConnection.js +2 -1
- package/lib/MultiCompiler.js +26 -8
- package/lib/NodeStuffPlugin.js +14 -3
- package/lib/NormalModule.js +3 -1
- package/lib/NormalModuleFactory.js +1 -1
- package/lib/NormalModuleReplacementPlugin.js +5 -1
- package/lib/ProvidePlugin.js +3 -1
- package/lib/RawModule.js +2 -1
- package/lib/ResolverFactory.js +3 -1
- package/lib/RuntimeModule.js +4 -4
- package/lib/RuntimePlugin.js +1 -0
- package/lib/RuntimeTemplate.js +102 -34
- package/lib/SourceMapDevToolPlugin.js +4 -1
- package/lib/Stats.js +10 -3
- package/lib/TemplatedPathPlugin.js +32 -6
- package/lib/Watching.js +67 -60
- package/lib/WebpackError.js +6 -6
- package/lib/WebpackOptionsApply.js +18 -5
- package/lib/asset/RawDataUrlModule.js +3 -1
- package/lib/async-modules/AwaitDependenciesInitFragment.js +2 -2
- package/lib/buildChunkGraph.js +117 -64
- package/lib/cache/IdleFileCachePlugin.js +8 -3
- package/lib/cache/MemoryCachePlugin.js +1 -1
- package/lib/cache/MemoryWithGcCachePlugin.js +6 -2
- package/lib/cache/PackFileCacheStrategy.js +49 -16
- package/lib/cache/ResolverCachePlugin.js +14 -6
- package/lib/cache/getLazyHashedEtag.js +1 -1
- package/lib/config/defaults.js +24 -1
- package/lib/config/normalization.js +3 -1
- package/lib/container/ContainerEntryDependency.js +2 -1
- package/lib/container/ContainerEntryModule.js +3 -1
- package/lib/container/ContainerPlugin.js +14 -10
- package/lib/container/FallbackModule.js +1 -1
- package/lib/container/RemoteRuntimeModule.js +12 -3
- package/lib/css/CssExportsGenerator.js +34 -17
- package/lib/css/CssGenerator.js +20 -2
- package/lib/css/CssLoadingRuntimeModule.js +212 -96
- package/lib/css/CssModulesPlugin.js +47 -13
- package/lib/debug/ProfilingPlugin.js +27 -2
- package/lib/dependencies/AMDDefineDependencyParserPlugin.js +9 -5
- package/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js +4 -1
- package/lib/dependencies/CommonJsDependencyHelpers.js +2 -1
- package/lib/dependencies/CommonJsExportRequireDependency.js +33 -18
- package/lib/dependencies/CommonJsExportsDependency.js +13 -5
- package/lib/dependencies/CommonJsExportsParserPlugin.js +20 -15
- package/lib/dependencies/CommonJsImportsParserPlugin.js +1 -2
- package/lib/dependencies/ContextDependencyHelpers.js +49 -29
- package/lib/dependencies/ContextElementDependency.js +8 -1
- package/lib/dependencies/CssLocalIdentifierDependency.js +63 -8
- package/lib/dependencies/CssUrlDependency.js +5 -3
- package/lib/dependencies/ExportsInfoDependency.js +4 -3
- package/lib/dependencies/ExternalModuleInitFragment.js +5 -3
- package/lib/dependencies/HarmonyEvaluatedImportSpecifierDependency.js +4 -4
- package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +43 -23
- package/lib/dependencies/HarmonyExportHeaderDependency.js +1 -1
- package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +73 -32
- package/lib/dependencies/HarmonyExportInitFragment.js +10 -2
- package/lib/dependencies/HarmonyImportDependency.js +28 -12
- package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +44 -16
- package/lib/dependencies/HarmonyImportSideEffectDependency.js +7 -6
- package/lib/dependencies/HarmonyImportSpecifierDependency.js +6 -5
- package/lib/dependencies/ImportDependency.js +9 -2
- package/lib/dependencies/ImportEagerDependency.js +4 -2
- package/lib/dependencies/ImportMetaContextDependency.js +7 -0
- package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +25 -14
- package/lib/dependencies/ImportParserPlugin.js +12 -4
- package/lib/dependencies/ImportWeakDependency.js +4 -2
- package/lib/dependencies/LoaderDependency.js +2 -1
- package/lib/dependencies/LoaderImportDependency.js +2 -1
- package/lib/dependencies/ModuleDependency.js +4 -5
- package/lib/dependencies/PureExpressionDependency.js +4 -1
- package/lib/dependencies/RequireContextPlugin.js +1 -1
- package/lib/dependencies/RequireEnsureDependenciesBlockParserPlugin.js +26 -14
- package/lib/dependencies/RequireEnsureDependency.js +1 -1
- package/lib/dependencies/URLDependency.js +7 -4
- package/lib/dependencies/WorkerPlugin.js +2 -1
- package/lib/dependencies/getFunctionExpression.js +3 -1
- package/lib/esm/ModuleChunkLoadingRuntimeModule.js +2 -1
- package/lib/javascript/BasicEvaluatedExpression.js +2 -2
- package/lib/javascript/ChunkHelpers.js +2 -2
- package/lib/javascript/JavascriptParser.js +169 -57
- package/lib/javascript/JavascriptParserHelpers.js +1 -1
- package/lib/javascript/StartupHelpers.js +22 -5
- package/lib/logging/Logger.js +27 -2
- package/lib/logging/createConsoleLogger.js +11 -7
- package/lib/node/NodeEnvironmentPlugin.js +13 -7
- package/lib/node/NodeWatchFileSystem.js +37 -26
- package/lib/node/ReadFileChunkLoadingRuntimeModule.js +2 -1
- package/lib/node/RequireChunkLoadingRuntimeModule.js +2 -1
- package/lib/node/nodeConsole.js +24 -1
- package/lib/optimize/AggressiveSplittingPlugin.js +1 -0
- package/lib/optimize/ConcatenatedModule.js +138 -54
- package/lib/optimize/EnsureChunkConditionsPlugin.js +1 -1
- package/lib/optimize/InnerGraph.js +7 -2
- package/lib/optimize/InnerGraphPlugin.js +36 -13
- package/lib/optimize/ModuleConcatenationPlugin.js +12 -2
- package/lib/optimize/RemoveParentModulesPlugin.js +1 -0
- package/lib/optimize/RuntimeChunkPlugin.js +6 -1
- package/lib/optimize/SideEffectsFlagPlugin.js +46 -15
- package/lib/optimize/SplitChunksPlugin.js +2 -2
- package/lib/performance/SizeLimitsPlugin.js +11 -0
- package/lib/rules/ObjectMatcherRulePlugin.js +4 -0
- package/lib/runtime/EnsureChunkRuntimeModule.js +2 -1
- package/lib/runtime/GetTrustedTypesPolicyRuntimeModule.js +2 -1
- package/lib/serialization/FileMiddleware.js +1 -0
- package/lib/serialization/ObjectMiddleware.js +2 -0
- package/lib/serialization/Serializer.js +19 -0
- package/lib/sharing/ConsumeSharedModule.js +1 -1
- package/lib/sharing/ConsumeSharedPlugin.js +17 -3
- package/lib/sharing/ConsumeSharedRuntimeModule.js +9 -2
- package/lib/sharing/ProvideSharedPlugin.js +12 -5
- package/lib/sharing/resolveMatchedConfigs.js +2 -2
- package/lib/sharing/utils.js +13 -6
- package/lib/util/StackedCacheMap.js +26 -0
- package/lib/util/WeakTupleMap.js +57 -13
- package/lib/util/cleverMerge.js +24 -11
- package/lib/util/comparators.js +34 -14
- package/lib/util/conventions.js +129 -0
- package/lib/util/fs.js +379 -65
- package/lib/util/hash/BatchedHash.js +3 -0
- package/lib/util/hash/xxhash64.js +2 -2
- package/lib/util/runtime.js +1 -1
- package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +4 -2
- package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +15 -6
- package/lib/wasm-sync/WebAssemblyGenerator.js +27 -6
- package/lib/wasm-sync/WebAssemblyParser.js +7 -4
- package/lib/web/JsonpChunkLoadingRuntimeModule.js +2 -1
- package/lib/webpack.js +7 -3
- package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +2 -1
- package/package.json +25 -26
- package/schemas/WebpackOptions.check.js +1 -1
- package/schemas/WebpackOptions.json +69 -8
- package/schemas/plugins/BannerPlugin.check.js +1 -1
- package/schemas/plugins/BannerPlugin.json +5 -1
- package/schemas/plugins/css/CssAutoGeneratorOptions.check.js +1 -1
- package/schemas/plugins/css/CssGeneratorOptions.check.js +1 -1
- package/schemas/plugins/css/CssGlobalGeneratorOptions.check.js +1 -1
- package/schemas/plugins/css/CssModuleGeneratorOptions.check.js +1 -1
- package/types.d.ts +1668 -613
package/README.md
CHANGED
@@ -315,7 +315,7 @@ a question to [StackOverflow with the webpack tag](https://stackoverflow.com/tag
|
|
315
315
|
|
316
316
|
If you are twitter savvy you can tweet #webpack with your question and someone should be able to reach out and help also.
|
317
317
|
|
318
|
-
If you have discovered a 🐜 or have a feature suggestion, feel free to create an issue on
|
318
|
+
If you have discovered a 🐜 or have a feature suggestion, feel free to create an issue on GitHub.
|
319
319
|
|
320
320
|
### License
|
321
321
|
|
@@ -405,7 +405,7 @@ src="https://static.monei.net/monei-logo.svg" height="30" alt="MONEI"></a>
|
|
405
405
|
|
406
406
|
<h2 align="center">Gold Sponsors</h2>
|
407
407
|
|
408
|
-
[Become a gold sponsor](https://opencollective.com/webpack#sponsor) and get your logo on our README on
|
408
|
+
[Become a gold sponsor](https://opencollective.com/webpack#sponsor) and get your logo on our README on GitHub with a link to your site.
|
409
409
|
|
410
410
|
<div align="center">
|
411
411
|
|
@@ -444,7 +444,7 @@ src="https://static.monei.net/monei-logo.svg" height="30" alt="MONEI"></a>
|
|
444
444
|
|
445
445
|
<h2 align="center">Silver Sponsors</h2>
|
446
446
|
|
447
|
-
[Become a silver sponsor](https://opencollective.com/webpack#sponsor) and get your logo on our README on
|
447
|
+
[Become a silver sponsor](https://opencollective.com/webpack#sponsor) and get your logo on our README on GitHub with a link to your site.
|
448
448
|
|
449
449
|
<div align="center">
|
450
450
|
|
@@ -483,7 +483,7 @@ src="https://static.monei.net/monei-logo.svg" height="30" alt="MONEI"></a>
|
|
483
483
|
|
484
484
|
<h2 align="center">Bronze Sponsors</h2>
|
485
485
|
|
486
|
-
[Become a bronze sponsor](https://opencollective.com/webpack#sponsor) and get your logo on our README on
|
486
|
+
[Become a bronze sponsor](https://opencollective.com/webpack#sponsor) and get your logo on our README on GitHub with a link to your site.
|
487
487
|
|
488
488
|
<div align="center">
|
489
489
|
|
@@ -593,7 +593,7 @@ src="https://static.monei.net/monei-logo.svg" height="30" alt="MONEI"></a>
|
|
593
593
|
|
594
594
|
<h2 align="center">Backers</h2>
|
595
595
|
|
596
|
-
[Become a backer](https://opencollective.com/webpack#backer) and get your image on our README on
|
596
|
+
[Become a backer](https://opencollective.com/webpack#backer) and get your image on our README on GitHub with a link to your site.
|
597
597
|
|
598
598
|
<a href="https://opencollective.com/webpack/backer/0/website?requireActive=false" target="_blank"><img src="https://opencollective.com/webpack/backer/0/avatar.svg?requireActive=false"></a>
|
599
599
|
<a href="https://opencollective.com/webpack/backer/1/website?requireActive=false" target="_blank"><img src="https://opencollective.com/webpack/backer/1/avatar.svg?requireActive=false"></a>
|
package/bin/webpack.js
CHANGED
@@ -119,6 +119,7 @@ if (!cli.installed) {
|
|
119
119
|
|
120
120
|
console.error(notify);
|
121
121
|
|
122
|
+
/** @type {string | undefined} */
|
122
123
|
let packageManager;
|
123
124
|
|
124
125
|
if (fs.existsSync(path.resolve(process.cwd(), "yarn.lock"))) {
|
@@ -171,7 +172,10 @@ if (!cli.installed) {
|
|
171
172
|
}')...`
|
172
173
|
);
|
173
174
|
|
174
|
-
runCommand(
|
175
|
+
runCommand(
|
176
|
+
/** @type {string} */ (packageManager),
|
177
|
+
installOptions.concat(cli.package)
|
178
|
+
)
|
175
179
|
.then(() => {
|
176
180
|
runCli(cli);
|
177
181
|
})
|
package/lib/APIPlugin.js
CHANGED
@@ -25,6 +25,7 @@ const GetFullHashRuntimeModule = require("./runtime/GetFullHashRuntimeModule");
|
|
25
25
|
|
26
26
|
/** @typedef {import("./Compiler")} Compiler */
|
27
27
|
/** @typedef {import("./Dependency").DependencyLocation} DependencyLocation */
|
28
|
+
/** @typedef {import("./Module").BuildInfo} BuildInfo */
|
28
29
|
/** @typedef {import("./javascript/JavascriptParser")} JavascriptParser */
|
29
30
|
/** @typedef {import("./javascript/JavascriptParser").Range} Range */
|
30
31
|
|
@@ -187,7 +188,7 @@ class APIPlugin {
|
|
187
188
|
hooks.renderModuleContent.tap(
|
188
189
|
PLUGIN_NAME,
|
189
190
|
(source, module, renderContext) => {
|
190
|
-
if (module.buildInfo.needCreateRequire) {
|
191
|
+
if (/** @type {BuildInfo} */ (module.buildInfo).needCreateRequire) {
|
191
192
|
const chunkInitFragments = [
|
192
193
|
new InitFragment(
|
193
194
|
'import { createRequire as __WEBPACK_EXTERNAL_createRequire } from "module";\n',
|
@@ -214,7 +215,8 @@ class APIPlugin {
|
|
214
215
|
const dep = toConstantDependency(parser, info.expr, info.req);
|
215
216
|
|
216
217
|
if (key === "__non_webpack_require__" && this.options.module) {
|
217
|
-
|
218
|
+
/** @type {BuildInfo} */
|
219
|
+
(parser.state.module.buildInfo).needCreateRequire = true;
|
218
220
|
}
|
219
221
|
|
220
222
|
return dep(expression);
|
@@ -267,7 +269,8 @@ class APIPlugin {
|
|
267
269
|
parser.hooks.expression
|
268
270
|
.for("__webpack_module__.id")
|
269
271
|
.tap(PLUGIN_NAME, expr => {
|
270
|
-
|
272
|
+
/** @type {BuildInfo} */
|
273
|
+
(parser.state.module.buildInfo).moduleConcatenationBailout =
|
271
274
|
"__webpack_module__.id";
|
272
275
|
const dep = new ConstDependency(
|
273
276
|
parser.state.module.moduleArgument + ".id",
|
@@ -282,7 +285,8 @@ class APIPlugin {
|
|
282
285
|
parser.hooks.expression
|
283
286
|
.for("__webpack_module__")
|
284
287
|
.tap(PLUGIN_NAME, expr => {
|
285
|
-
|
288
|
+
/** @type {BuildInfo} */
|
289
|
+
(parser.state.module.buildInfo).moduleConcatenationBailout =
|
286
290
|
"__webpack_module__";
|
287
291
|
const dep = new ConstDependency(
|
288
292
|
parser.state.module.moduleArgument,
|
@@ -27,7 +27,7 @@ class AutomaticPrefetchPlugin {
|
|
27
27
|
);
|
28
28
|
}
|
29
29
|
);
|
30
|
-
/** @type {{context: string, request: string}[] | null} */
|
30
|
+
/** @type {{context: string | null, request: string}[] | null} */
|
31
31
|
let lastModules = null;
|
32
32
|
compiler.hooks.afterCompile.tap("AutomaticPrefetchPlugin", compilation => {
|
33
33
|
lastModules = [];
|
package/lib/BannerPlugin.js
CHANGED
@@ -83,12 +83,14 @@ class BannerPlugin {
|
|
83
83
|
options
|
84
84
|
);
|
85
85
|
const cache = new WeakMap();
|
86
|
+
const stage =
|
87
|
+
this.options.stage || Compilation.PROCESS_ASSETS_STAGE_ADDITIONS;
|
86
88
|
|
87
89
|
compiler.hooks.compilation.tap("BannerPlugin", compilation => {
|
88
90
|
compilation.hooks.processAssets.tap(
|
89
91
|
{
|
90
92
|
name: "BannerPlugin",
|
91
|
-
stage
|
93
|
+
stage
|
92
94
|
},
|
93
95
|
() => {
|
94
96
|
for (const chunk of compilation.chunks) {
|
package/lib/Cache.js
CHANGED
@@ -21,7 +21,7 @@ const {
|
|
21
21
|
/**
|
22
22
|
* @template T
|
23
23
|
* @callback CallbackCache
|
24
|
-
* @param {
|
24
|
+
* @param {WebpackError | null} err
|
25
25
|
* @param {T=} result
|
26
26
|
* @returns {void}
|
27
27
|
*/
|
@@ -33,6 +33,11 @@ const {
|
|
33
33
|
* @returns {void}
|
34
34
|
*/
|
35
35
|
|
36
|
+
/**
|
37
|
+
* @param {number} times times
|
38
|
+
* @param {function(Error=): void} callback callback
|
39
|
+
* @returns {function(Error=): void} callback
|
40
|
+
*/
|
36
41
|
const needCalls = (times, callback) => {
|
37
42
|
return err => {
|
38
43
|
if (--times === 0) {
|
@@ -71,6 +76,7 @@ class Cache {
|
|
71
76
|
* @returns {void}
|
72
77
|
*/
|
73
78
|
get(identifier, etag, callback) {
|
79
|
+
/** @type {GotHandler[]} */
|
74
80
|
const gotHandlers = [];
|
75
81
|
this.hooks.get.callAsync(identifier, etag, gotHandlers, (err, result) => {
|
76
82
|
if (err) {
|
package/lib/CacheFacade.js
CHANGED
@@ -19,8 +19,8 @@ const mergeEtags = require("./cache/mergeEtags");
|
|
19
19
|
/**
|
20
20
|
* @template T
|
21
21
|
* @callback CallbackCache
|
22
|
-
* @param {(
|
23
|
-
* @param {T=} result
|
22
|
+
* @param {(Error | null)=} err
|
23
|
+
* @param {(T | null)=} result
|
24
24
|
* @returns {void}
|
25
25
|
*/
|
26
26
|
|
@@ -196,7 +196,7 @@ class CacheFacade {
|
|
196
196
|
/**
|
197
197
|
* @param {Cache} cache the root cache
|
198
198
|
* @param {string} name the child cache name
|
199
|
-
* @param {string | HashConstructor} hashFunction the hash function to use
|
199
|
+
* @param {(string | HashConstructor)=} hashFunction the hash function to use
|
200
200
|
*/
|
201
201
|
constructor(cache, name, hashFunction) {
|
202
202
|
this._cache = cache;
|
package/lib/ChunkGraph.js
CHANGED
@@ -33,6 +33,7 @@ const {
|
|
33
33
|
/** @typedef {import("./ChunkGroup")} ChunkGroup */
|
34
34
|
/** @typedef {import("./Module")} Module */
|
35
35
|
/** @typedef {import("./ModuleGraph")} ModuleGraph */
|
36
|
+
/** @typedef {import("./ModuleGraphConnection").ConnectionState} ConnectionState */
|
36
37
|
/** @typedef {import("./RuntimeModule")} RuntimeModule */
|
37
38
|
/** @typedef {typeof import("./util/Hash")} Hash */
|
38
39
|
/** @typedef {import("./util/runtime").RuntimeSpec} RuntimeSpec */
|
@@ -55,6 +56,10 @@ const compareModuleIterables = compareIterables(compareModulesByIdentifier);
|
|
55
56
|
*/
|
56
57
|
|
57
58
|
class ModuleHashInfo {
|
59
|
+
/**
|
60
|
+
* @param {string} hash hash
|
61
|
+
* @param {string} renderedHash rendered hash
|
62
|
+
*/
|
58
63
|
constructor(hash, renderedHash) {
|
59
64
|
this.hash = hash;
|
60
65
|
this.renderedHash = renderedHash;
|
@@ -180,13 +185,16 @@ const isAvailableChunk = (a, b) => {
|
|
180
185
|
return true;
|
181
186
|
};
|
182
187
|
|
188
|
+
/** @typedef {Set<Chunk>} EntryInChunks */
|
189
|
+
/** @typedef {Set<Chunk>} RuntimeInChunks */
|
190
|
+
|
183
191
|
class ChunkGraphModule {
|
184
192
|
constructor() {
|
185
193
|
/** @type {SortableSet<Chunk>} */
|
186
194
|
this.chunks = new SortableSet();
|
187
|
-
/** @type {
|
195
|
+
/** @type {EntryInChunks | undefined} */
|
188
196
|
this.entryInChunks = undefined;
|
189
|
-
/** @type {
|
197
|
+
/** @type {RuntimeInChunks | undefined} */
|
190
198
|
this.runtimeInChunks = undefined;
|
191
199
|
/** @type {RuntimeSpecMap<ModuleHashInfo> | undefined} */
|
192
200
|
this.hashes = undefined;
|
@@ -194,9 +202,9 @@ class ChunkGraphModule {
|
|
194
202
|
this.id = null;
|
195
203
|
/** @type {RuntimeSpecMap<Set<string>> | undefined} */
|
196
204
|
this.runtimeRequirements = undefined;
|
197
|
-
/** @type {RuntimeSpecMap<string>} */
|
205
|
+
/** @type {RuntimeSpecMap<string> | undefined} */
|
198
206
|
this.graphHashes = undefined;
|
199
|
-
/** @type {RuntimeSpecMap<string>} */
|
207
|
+
/** @type {RuntimeSpecMap<string> | undefined} */
|
200
208
|
this.graphHashesWithConnections = undefined;
|
201
209
|
}
|
202
210
|
}
|
@@ -284,6 +292,9 @@ class ChunkGraph {
|
|
284
292
|
findGraphRoots(set, module => {
|
285
293
|
/** @type {Set<Module>} */
|
286
294
|
const set = new Set();
|
295
|
+
/**
|
296
|
+
* @param {Module} module module
|
297
|
+
*/
|
287
298
|
const addDependencies = module => {
|
288
299
|
for (const connection of moduleGraph.getOutgoingConnections(module)) {
|
289
300
|
if (!connection.module) continue;
|
@@ -417,7 +428,7 @@ class ChunkGraph {
|
|
417
428
|
}
|
418
429
|
for (const chunk of oldCgm.entryInChunks) {
|
419
430
|
const cgc = this._getChunkGraphChunk(chunk);
|
420
|
-
const old = cgc.entryModules.get(oldModule);
|
431
|
+
const old = /** @type {Entrypoint} */ (cgc.entryModules.get(oldModule));
|
421
432
|
/** @type {Map<Module, Entrypoint>} */
|
422
433
|
const newEntryModules = new Map();
|
423
434
|
for (const [m, cg] of cgc.entryModules) {
|
@@ -716,7 +727,7 @@ class ChunkGraph {
|
|
716
727
|
for (const asyncChunk of includeAllChunks
|
717
728
|
? chunk.getAllReferencedChunks()
|
718
729
|
: chunk.getAllAsyncChunks()) {
|
719
|
-
/** @type {(string|number)[]} */
|
730
|
+
/** @type {(string | number)[] | undefined} */
|
720
731
|
let array;
|
721
732
|
for (const module of this.getOrderedChunkModulesIterable(
|
722
733
|
asyncChunk,
|
@@ -755,7 +766,7 @@ class ChunkGraph {
|
|
755
766
|
for (const asyncChunk of includeAllChunks
|
756
767
|
? chunk.getAllReferencedChunks()
|
757
768
|
: chunk.getAllAsyncChunks()) {
|
758
|
-
/** @type {Record<string|number, string>} */
|
769
|
+
/** @type {Record<string|number, string> | undefined} */
|
759
770
|
let idToHashMap;
|
760
771
|
for (const module of this.getOrderedChunkModulesIterable(
|
761
772
|
asyncChunk,
|
@@ -1115,7 +1126,7 @@ class ChunkGraph {
|
|
1115
1126
|
*/
|
1116
1127
|
disconnectEntryModule(module) {
|
1117
1128
|
const cgm = this._getChunkGraphModule(module);
|
1118
|
-
for (const chunk of cgm.entryInChunks) {
|
1129
|
+
for (const chunk of /** @type {EntryInChunks} */ (cgm.entryInChunks)) {
|
1119
1130
|
const cgc = this._getChunkGraphChunk(chunk);
|
1120
1131
|
cgc.entryModules.delete(module);
|
1121
1132
|
}
|
@@ -1223,14 +1234,7 @@ class ChunkGraph {
|
|
1223
1234
|
const array = Array.from(cgc.runtimeModules);
|
1224
1235
|
array.sort(
|
1225
1236
|
concatComparators(
|
1226
|
-
compareSelect(
|
1227
|
-
/**
|
1228
|
-
* @param {RuntimeModule} r runtime module
|
1229
|
-
* @returns {number=} stage
|
1230
|
-
*/
|
1231
|
-
r => r.stage,
|
1232
|
-
compareIds
|
1233
|
-
),
|
1237
|
+
compareSelect(r => /** @type {RuntimeModule} */ (r).stage, compareIds),
|
1234
1238
|
compareModulesByIdentifier
|
1235
1239
|
)
|
1236
1240
|
);
|
@@ -1275,7 +1279,7 @@ class ChunkGraph {
|
|
1275
1279
|
|
1276
1280
|
/**
|
1277
1281
|
* @param {AsyncDependenciesBlock} depBlock the async block
|
1278
|
-
* @returns {ChunkGroup} the chunk group
|
1282
|
+
* @returns {ChunkGroup | undefined} the chunk group
|
1279
1283
|
*/
|
1280
1284
|
getBlockChunkGroup(depBlock) {
|
1281
1285
|
return this._blockChunkGroups.get(depBlock);
|
@@ -1364,7 +1368,7 @@ class ChunkGraph {
|
|
1364
1368
|
Caller might not support runtime-dependent code generation (opt-out via optimization.usedExports: "global").`
|
1365
1369
|
);
|
1366
1370
|
}
|
1367
|
-
return first(hashInfoItems);
|
1371
|
+
return /** @type {T} */ (first(hashInfoItems));
|
1368
1372
|
} else {
|
1369
1373
|
const hashInfo = hashes.get(runtime);
|
1370
1374
|
if (!hashInfo) {
|
@@ -1576,6 +1580,10 @@ Caller might not support runtime-dependent code generation (opt-out via optimiza
|
|
1576
1580
|
if (cgm.graphHashesWithConnections === undefined) {
|
1577
1581
|
cgm.graphHashesWithConnections = new RuntimeSpecMap();
|
1578
1582
|
}
|
1583
|
+
/**
|
1584
|
+
* @param {ConnectionState} state state
|
1585
|
+
* @returns {"F" | "T" | "O"} result
|
1586
|
+
*/
|
1579
1587
|
const activeStateToString = state => {
|
1580
1588
|
if (state === false) return "F";
|
1581
1589
|
if (state === true) return "T";
|
@@ -1646,6 +1654,9 @@ Caller might not support runtime-dependent code generation (opt-out via optimiza
|
|
1646
1654
|
? Array.from(connectedModules).sort(([a], [b]) => (a < b ? -1 : 1))
|
1647
1655
|
: connectedModules;
|
1648
1656
|
const hash = createHash(this._hashFunction);
|
1657
|
+
/**
|
1658
|
+
* @param {Module} module module
|
1659
|
+
*/
|
1649
1660
|
const addModuleToHash = module => {
|
1650
1661
|
hash.update(
|
1651
1662
|
this._getModuleGraphHashBigInt(
|
@@ -1655,6 +1666,9 @@ Caller might not support runtime-dependent code generation (opt-out via optimiza
|
|
1655
1666
|
).toString(16)
|
1656
1667
|
);
|
1657
1668
|
};
|
1669
|
+
/**
|
1670
|
+
* @param {Set<Module>} modules modules
|
1671
|
+
*/
|
1658
1672
|
const addModulesToHash = modules => {
|
1659
1673
|
let xor = ZERO_BIG_INT;
|
1660
1674
|
for (const m of modules) {
|
package/lib/ChunkGroup.js
CHANGED
@@ -70,7 +70,7 @@ const sortOrigin = (a, b) => {
|
|
70
70
|
class ChunkGroup {
|
71
71
|
/**
|
72
72
|
* Creates an instance of ChunkGroup.
|
73
|
-
* @param {string|ChunkGroupOptions=} options chunk group options passed to chunkGroup
|
73
|
+
* @param {string | ChunkGroupOptions=} options chunk group options passed to chunkGroup
|
74
74
|
*/
|
75
75
|
constructor(options) {
|
76
76
|
if (typeof options === "string") {
|
@@ -80,7 +80,7 @@ class ChunkGroup {
|
|
80
80
|
}
|
81
81
|
/** @type {number} */
|
82
82
|
this.groupDebugId = debugId++;
|
83
|
-
this.options = options;
|
83
|
+
this.options = /** @type {ChunkGroupOptions} */ (options);
|
84
84
|
/** @type {SortableSet<ChunkGroup>} */
|
85
85
|
this._children = new SortableSet(undefined, sortById);
|
86
86
|
/** @type {SortableSet<ChunkGroup>} */
|
@@ -108,18 +108,18 @@ class ChunkGroup {
|
|
108
108
|
* @returns {void}
|
109
109
|
*/
|
110
110
|
addOptions(options) {
|
111
|
-
for (const
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
this.options[key] =
|
116
|
-
|
117
|
-
} else if (
|
118
|
-
this.options[/** @type {keyof ChunkGroupOptions} */ (key)] !==
|
119
|
-
options[/** @type {keyof ChunkGroupOptions} */ (key)]
|
120
|
-
) {
|
111
|
+
for (const _key of Object.keys(options)) {
|
112
|
+
const key = /** @type {keyof ChunkGroupOptions} */ (_key);
|
113
|
+
if (this.options[key] === undefined) {
|
114
|
+
/** @type {TODO} */
|
115
|
+
(this.options)[key] = options[key];
|
116
|
+
} else if (this.options[key] !== options[key]) {
|
121
117
|
if (key.endsWith("Order")) {
|
122
|
-
|
118
|
+
/** @type {TODO} */
|
119
|
+
(this.options)[key] = Math.max(
|
120
|
+
/** @type {number} */ (this.options[key]),
|
121
|
+
/** @type {number} */ (options[key])
|
122
|
+
);
|
123
123
|
} else {
|
124
124
|
throw new Error(
|
125
125
|
`ChunkGroup.addOptions: No option merge strategy for ${key}`
|
@@ -219,7 +219,7 @@ class ChunkGroup {
|
|
219
219
|
/**
|
220
220
|
* @param {Chunk} oldChunk chunk to be replaced
|
221
221
|
* @param {Chunk} newChunk New chunk that will be replaced with
|
222
|
-
* @returns {boolean} returns true if the replacement was successful
|
222
|
+
* @returns {boolean | undefined} returns true if the replacement was successful
|
223
223
|
*/
|
224
224
|
replaceChunk(oldChunk, newChunk) {
|
225
225
|
const oldIdx = this.chunks.indexOf(oldChunk);
|
package/lib/CleanPlugin.js
CHANGED
@@ -15,6 +15,7 @@ const processAsyncTree = require("./util/processAsyncTree");
|
|
15
15
|
/** @typedef {import("../declarations/WebpackOptions").CleanOptions} CleanOptions */
|
16
16
|
/** @typedef {import("./Compiler")} Compiler */
|
17
17
|
/** @typedef {import("./logging/Logger").Logger} Logger */
|
18
|
+
/** @typedef {import("./util/fs").IStats} IStats */
|
18
19
|
/** @typedef {import("./util/fs").OutputFileSystem} OutputFileSystem */
|
19
20
|
/** @typedef {import("./util/fs").StatsCallback} StatsCallback */
|
20
21
|
|
@@ -88,8 +89,8 @@ const getDiffToFs = (fs, outputPath, currentAssets, callback) => {
|
|
88
89
|
}
|
89
90
|
return callback(err);
|
90
91
|
}
|
91
|
-
for (const entry of entries) {
|
92
|
-
const file =
|
92
|
+
for (const entry of /** @type {string[]} */ (entries)) {
|
93
|
+
const file = entry;
|
93
94
|
const filename = directory ? `${directory}/${file}` : file;
|
94
95
|
if (!directories.has(filename) && !currentAssets.has(filename)) {
|
95
96
|
diff.add(filename);
|
@@ -196,7 +197,7 @@ const applyDiff = (fs, outputPath, dry, logger, diff, isKept, callback) => {
|
|
196
197
|
}
|
197
198
|
doStat(fs, path, (err, stats) => {
|
198
199
|
if (err) return handleError(err);
|
199
|
-
if (!stats.isDirectory()) {
|
200
|
+
if (!(/** @type {IStats} */ (stats).isDirectory())) {
|
200
201
|
push({
|
201
202
|
type: "unlink",
|
202
203
|
filename,
|
@@ -206,7 +207,7 @@ const applyDiff = (fs, outputPath, dry, logger, diff, isKept, callback) => {
|
|
206
207
|
}
|
207
208
|
|
208
209
|
/** @type {NonNullable<OutputFileSystem["readdir"]>} */
|
209
|
-
(fs.readdir)(path, (err,
|
210
|
+
(fs.readdir)(path, (err, _entries) => {
|
210
211
|
if (err) return handleError(err);
|
211
212
|
/** @type {Job} */
|
212
213
|
const deleteJob = {
|
@@ -214,6 +215,7 @@ const applyDiff = (fs, outputPath, dry, logger, diff, isKept, callback) => {
|
|
214
215
|
filename,
|
215
216
|
parent
|
216
217
|
};
|
218
|
+
const entries = /** @type {string[]} */ (_entries);
|
217
219
|
if (entries.length === 0) {
|
218
220
|
push(deleteJob);
|
219
221
|
} else {
|
@@ -355,7 +357,7 @@ class CleanPlugin {
|
|
355
357
|
(compilation, callback) => {
|
356
358
|
const hooks = CleanPlugin.getCompilationHooks(compilation);
|
357
359
|
const logger = compilation.getLogger("webpack.CleanPlugin");
|
358
|
-
const fs = compiler.outputFileSystem;
|
360
|
+
const fs = /** @type {OutputFileSystem} */ (compiler.outputFileSystem);
|
359
361
|
|
360
362
|
if (!fs.readdir) {
|
361
363
|
return callback(
|