webpack 5.104.1 → 5.105.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/bin/webpack.js +6 -3
- package/lib/APIPlugin.js +85 -15
- package/lib/AbstractMethodError.js +1 -0
- package/lib/AsyncDependenciesBlock.js +13 -1
- package/lib/AsyncDependencyToInitialChunkError.js +1 -0
- package/lib/AutomaticPrefetchPlugin.js +1 -1
- package/lib/BannerPlugin.js +2 -0
- package/lib/CacheFacade.js +2 -2
- package/lib/CaseSensitiveModulesWarning.js +1 -0
- package/lib/Chunk.js +8 -4
- package/lib/ChunkGraph.js +30 -9
- package/lib/ChunkGroup.js +6 -3
- package/lib/ChunkRenderError.js +2 -0
- package/lib/CleanPlugin.js +4 -1
- package/lib/CodeGenerationError.js +7 -1
- package/lib/CodeGenerationResults.js +10 -3
- package/lib/CommentCompilationWarning.js +2 -1
- package/lib/Compilation.js +280 -236
- package/lib/Compiler.js +3 -2
- package/lib/ConcatenationScope.js +2 -1
- package/lib/ConcurrentCompilationError.js +3 -3
- package/lib/ContextModule.js +248 -111
- package/lib/ContextModuleFactory.js +14 -2
- package/lib/DefinePlugin.js +3 -1
- package/lib/DelegatedModule.js +6 -0
- package/lib/DelegatedModuleFactoryPlugin.js +2 -0
- package/lib/Dependency.js +6 -1
- package/lib/DependencyTemplates.js +3 -2
- package/lib/DllModule.js +2 -0
- package/lib/DllReferencePlugin.js +1 -0
- package/lib/DotenvPlugin.js +11 -5
- package/lib/DynamicEntryPlugin.js +1 -0
- package/lib/EnvironmentNotSupportAsyncWarning.js +1 -0
- package/lib/EvalSourceMapDevToolPlugin.js +17 -13
- package/lib/ExportsInfo.js +8 -4
- package/lib/ExternalModule.js +16 -0
- package/lib/FalseIIFEUmdWarning.js +1 -0
- package/lib/FileSystemInfo.js +49 -25
- package/lib/FlagDependencyExportsPlugin.js +8 -1
- package/lib/FlagDependencyUsagePlugin.js +9 -7
- package/lib/HarmonyLinkingError.js +1 -0
- package/lib/HookWebpackError.js +2 -0
- package/lib/HotModuleReplacementPlugin.js +16 -2
- package/lib/InitFragment.js +1 -0
- package/lib/InvalidDependenciesModuleWarning.js +1 -0
- package/lib/LibManifestPlugin.js +1 -0
- package/lib/ManifestPlugin.js +4 -1
- package/lib/Module.js +7 -4
- package/lib/ModuleBuildError.js +3 -1
- package/lib/ModuleDependencyError.js +1 -0
- package/lib/ModuleDependencyWarning.js +1 -0
- package/lib/ModuleError.js +2 -1
- package/lib/ModuleFilenameHelpers.js +2 -1
- package/lib/ModuleGraph.js +3 -0
- package/lib/ModuleGraphConnection.js +10 -1
- package/lib/ModuleHashingError.js +2 -0
- package/lib/ModuleInfoHeaderPlugin.js +6 -1
- package/lib/ModuleNotFoundError.js +1 -0
- package/lib/ModuleParseError.js +5 -1
- package/lib/ModuleProfile.js +1 -1
- package/lib/ModuleRestoreError.js +2 -0
- package/lib/ModuleSourceTypeConstants.js +1 -11
- package/lib/ModuleStoreError.js +2 -0
- package/lib/ModuleWarning.js +3 -1
- package/lib/MultiCompiler.js +11 -7
- package/lib/MultiWatching.js +2 -2
- package/lib/NoModeWarning.js +1 -0
- package/lib/NodeStuffInWebError.js +1 -0
- package/lib/NormalModule.js +26 -5
- package/lib/NormalModuleFactory.js +20 -4
- package/lib/OptionsApply.js +3 -1
- package/lib/ProgressPlugin.js +4 -0
- package/lib/RawModule.js +2 -0
- package/lib/RuntimeModule.js +10 -0
- package/lib/RuntimePlugin.js +7 -9
- package/lib/RuntimeTemplate.js +14 -7
- package/lib/SourceMapDevToolPlugin.js +30 -23
- package/lib/Template.js +10 -5
- package/lib/TemplatedPathPlugin.js +4 -2
- package/lib/UnhandledSchemeError.js +1 -0
- package/lib/UnsupportedFeatureWarning.js +1 -0
- package/lib/WarnDeprecatedOptionPlugin.js +1 -0
- package/lib/WatchIgnorePlugin.js +1 -1
- package/lib/Watching.js +5 -0
- package/lib/WebpackError.js +4 -0
- package/lib/WebpackOptionsApply.js +60 -40
- package/lib/asset/AssetBytesGenerator.js +1 -0
- package/lib/asset/AssetGenerator.js +9 -3
- package/lib/asset/AssetModulesPlugin.js +33 -2
- package/lib/asset/AssetSourceGenerator.js +1 -0
- package/lib/asset/RawDataUrlModule.js +4 -0
- package/lib/async-modules/AwaitDependenciesInitFragment.js +4 -1
- package/lib/buildChunkGraph.js +31 -2
- package/lib/cache/MemoryWithGcCachePlugin.js +1 -0
- package/lib/cache/PackFileCacheStrategy.js +41 -8
- package/lib/cache/getLazyHashedEtag.js +13 -4
- package/lib/cache/mergeEtags.js +3 -1
- package/lib/cli.js +3 -1
- package/lib/config/defaults.js +65 -44
- package/lib/config/normalization.js +96 -0
- package/lib/container/ContainerEntryModule.js +4 -0
- package/lib/container/FallbackModule.js +2 -0
- package/lib/container/HoistContainerReferencesPlugin.js +6 -0
- package/lib/container/RemoteModule.js +19 -0
- package/lib/css/CssGenerator.js +31 -4
- package/lib/css/CssModulesPlugin.js +26 -30
- package/lib/css/CssParser.js +12 -9
- package/lib/debug/ProfilingPlugin.js +1 -0
- package/lib/dependencies/AMDDefineDependency.js +3 -1
- package/lib/dependencies/AMDDefineDependencyParserPlugin.js +6 -0
- package/lib/dependencies/AMDPlugin.js +1 -1
- package/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js +7 -1
- package/lib/dependencies/CachedConstDependency.js +1 -0
- package/lib/dependencies/CommonJsDependencyHelpers.js +2 -0
- package/lib/dependencies/CommonJsExportRequireDependency.js +1 -0
- package/lib/dependencies/CommonJsFullRequireDependency.js +2 -0
- package/lib/dependencies/CommonJsImportsParserPlugin.js +3 -0
- package/lib/dependencies/CommonJsRequireContextDependency.js +2 -2
- package/lib/dependencies/CommonJsSelfReferenceDependency.js +1 -0
- package/lib/dependencies/ConstDependency.js +1 -0
- package/lib/dependencies/ContextDependencyHelpers.js +11 -4
- package/lib/dependencies/ContextElementDependency.js +1 -0
- package/lib/dependencies/CriticalDependencyWarning.js +1 -0
- package/lib/dependencies/CssIcssExportDependency.js +5 -4
- package/lib/dependencies/CssIcssSymbolDependency.js +1 -0
- package/lib/dependencies/CssUrlDependency.js +2 -3
- package/lib/dependencies/ExternalModuleInitFragment.js +4 -1
- package/lib/dependencies/ExternalModuleInitFragmentDependency.js +0 -9
- package/lib/dependencies/HarmonyAcceptDependency.js +3 -0
- package/lib/dependencies/HarmonyEvaluatedImportSpecifierDependency.js +1 -0
- package/lib/dependencies/HarmonyExportExpressionDependency.js +4 -0
- package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +8 -1
- package/lib/dependencies/HarmonyExportInitFragment.js +17 -3
- package/lib/dependencies/HarmonyExportSpecifierDependency.js +4 -0
- package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +266 -5
- package/lib/dependencies/HarmonyImportSpecifierDependency.js +22 -3
- package/lib/dependencies/ImportDependency.js +1 -0
- package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +1 -0
- package/lib/dependencies/ImportMetaPlugin.js +53 -11
- package/lib/dependencies/ImportParserPlugin.js +7 -12
- package/lib/dependencies/LoaderPlugin.js +3 -0
- package/lib/dependencies/ModuleDecoratorDependency.js +1 -0
- package/lib/dependencies/ModuleDependency.js +1 -0
- package/lib/dependencies/ModuleInitFragmentDependency.js +87 -0
- package/lib/dependencies/ProvidedDependency.js +1 -0
- package/lib/dependencies/RequireContextPlugin.js +1 -0
- package/lib/dependencies/RequireEnsureDependenciesBlockParserPlugin.js +7 -2
- package/lib/dependencies/RuntimeRequirementsDependency.js +1 -0
- package/lib/dependencies/WorkerDependency.js +9 -3
- package/lib/dependencies/WorkerPlugin.js +1 -0
- package/lib/dependencies/getFunctionExpression.js +3 -1
- package/lib/errors/BuildCycleError.js +4 -1
- package/lib/esm/ModuleChunkFormatPlugin.js +6 -4
- package/lib/esm/ModuleChunkLoadingPlugin.js +1 -0
- package/lib/esm/ModuleChunkLoadingRuntimeModule.js +1 -0
- package/lib/hmr/LazyCompilationPlugin.js +5 -0
- package/lib/hmr/lazyCompilationBackend.js +3 -2
- package/lib/ids/ChunkModuleIdRangePlugin.js +2 -0
- package/lib/ids/IdHelpers.js +10 -8
- package/lib/ids/OccurrenceModuleIdsPlugin.js +15 -7
- package/lib/ids/SyncModuleIdsPlugin.js +5 -1
- package/lib/javascript/BasicEvaluatedExpression.js +1 -0
- package/lib/javascript/EnableChunkLoadingPlugin.js +5 -2
- package/lib/javascript/JavascriptModulesPlugin.js +29 -8
- package/lib/javascript/JavascriptParser.js +47 -14
- package/lib/json/JsonParser.js +6 -0
- package/lib/library/AbstractLibraryPlugin.js +4 -1
- package/lib/library/AmdLibraryPlugin.js +2 -1
- package/lib/library/AssignLibraryPlugin.js +6 -2
- package/lib/library/EnableLibraryPlugin.js +1 -0
- package/lib/library/ExportPropertyLibraryPlugin.js +1 -1
- package/lib/library/JsonpLibraryPlugin.js +1 -1
- package/lib/library/ModuleLibraryPlugin.js +130 -13
- package/lib/library/SystemLibraryPlugin.js +4 -1
- package/lib/library/UmdLibraryPlugin.js +4 -3
- package/lib/logging/createConsoleLogger.js +3 -0
- package/lib/logging/truncateArgs.js +1 -1
- package/lib/node/CommonJsChunkLoadingPlugin.js +1 -0
- package/lib/node/NodeTargetPlugin.js +1 -0
- package/lib/node/NodeWatchFileSystem.js +3 -0
- package/lib/node/nodeConsole.js +18 -1
- package/lib/optimize/AggressiveMergingPlugin.js +2 -1
- package/lib/optimize/AggressiveSplittingPlugin.js +10 -6
- package/lib/optimize/ConcatenatedModule.js +33 -19
- package/lib/optimize/FlagIncludedChunksPlugin.js +11 -1
- package/lib/optimize/InnerGraph.js +5 -3
- package/lib/optimize/InnerGraphPlugin.js +25 -25
- package/lib/optimize/MangleExportsPlugin.js +14 -2
- package/lib/optimize/MergeDuplicateChunksPlugin.js +3 -0
- package/lib/optimize/MinChunkSizePlugin.js +5 -2
- package/lib/optimize/ModuleConcatenationPlugin.js +19 -4
- package/lib/optimize/RealContentHashPlugin.js +35 -27
- package/lib/optimize/RemoveParentModulesPlugin.js +12 -3
- package/lib/optimize/SideEffectsFlagPlugin.js +3 -0
- package/lib/optimize/SplitChunksPlugin.js +14 -3
- package/lib/performance/AssetsOverSizeLimitWarning.js +6 -2
- package/lib/performance/EntrypointsOverSizeLimitWarning.js +6 -2
- package/lib/performance/NoAsyncChunksWarning.js +1 -0
- package/lib/rules/BasicEffectRulePlugin.js +2 -0
- package/lib/rules/BasicMatcherRulePlugin.js +3 -0
- package/lib/rules/ObjectMatcherRulePlugin.js +5 -1
- package/lib/rules/RuleSetCompiler.js +2 -0
- package/lib/runtime/AsyncModuleRuntimeModule.js +1 -0
- package/lib/runtime/ChunkNameRuntimeModule.js +1 -0
- package/lib/runtime/CompatRuntimeModule.js +1 -0
- package/lib/runtime/EnsureChunkRuntimeModule.js +1 -0
- package/lib/runtime/GetChunkFilenameRuntimeModule.js +4 -0
- package/lib/runtime/GetMainFilenameRuntimeModule.js +2 -0
- package/lib/runtime/GetTrustedTypesPolicyRuntimeModule.js +1 -0
- package/lib/runtime/LoadScriptRuntimeModule.js +2 -0
- package/lib/runtime/MakeDeferredNamespaceObjectRuntime.js +15 -32
- package/lib/runtime/PublicPathRuntimeModule.js +1 -0
- package/lib/runtime/StartupChunkDependenciesPlugin.js +2 -0
- package/lib/runtime/StartupChunkDependenciesRuntimeModule.js +1 -0
- package/lib/runtime/StartupEntrypointRuntimeModule.js +1 -0
- package/lib/schemes/HttpUriPlugin.js +27 -7
- package/lib/schemes/VirtualUrlPlugin.js +7 -2
- package/lib/serialization/BinaryMiddleware.js +4 -0
- package/lib/serialization/FileMiddleware.js +9 -4
- package/lib/serialization/ObjectMiddleware.js +34 -11
- package/lib/serialization/PlainObjectSerializer.js +2 -0
- package/lib/sharing/ConsumeSharedModule.js +60 -0
- package/lib/sharing/ConsumeSharedPlugin.js +5 -4
- package/lib/sharing/ProvideSharedModule.js +4 -0
- package/lib/sharing/ProvideSharedPlugin.js +24 -25
- package/lib/sharing/resolveMatchedConfigs.js +2 -2
- package/lib/sharing/utils.js +8 -6
- package/lib/stats/DefaultStatsFactoryPlugin.js +14 -12
- package/lib/stats/DefaultStatsPrinterPlugin.js +6 -5
- package/lib/stats/StatsFactory.js +2 -2
- package/lib/url/URLParserPlugin.js +4 -3
- package/lib/util/AppendOnlyStackedSet.js +57 -0
- package/lib/util/Hash.js +1 -0
- package/lib/util/IterableHelpers.js +1 -0
- package/lib/util/LazyBucketSortedSet.js +1 -0
- package/lib/util/LazySet.js +1 -0
- package/lib/util/ParallelismFactorCalculator.js +1 -0
- package/lib/util/SortableSet.js +1 -0
- package/lib/util/StringXor.js +1 -0
- package/lib/util/binarySearchBounds.js +15 -8
- package/lib/util/chainedImports.js +1 -1
- package/lib/util/cleverMerge.js +6 -1
- package/lib/util/comparators.js +21 -1
- package/lib/util/compileBooleanMatcher.js +3 -3
- package/lib/util/concatenate.js +3 -2
- package/lib/util/conventions.js +3 -2
- package/lib/util/deterministicGrouping.js +13 -1
- package/lib/util/extractSourceMap.js +12 -13
- package/lib/util/fs.js +15 -19
- package/lib/util/hash/BatchedHash.js +3 -0
- package/lib/util/hash/BulkUpdateHash.js +7 -1
- package/lib/util/hash/hash-digest.js +1 -0
- package/lib/util/hash/wasm-hash.js +16 -1
- package/lib/util/identifier.js +7 -2
- package/lib/util/magicComment.js +1 -1
- package/lib/util/propertyName.js +1 -1
- package/lib/util/registerExternalSerializer.js +1 -0
- package/lib/util/runtime.js +15 -1
- package/lib/util/semver.js +1 -0
- package/lib/util/serialization.js +2 -2
- package/lib/wasm/EnableWasmLoadingPlugin.js +1 -0
- package/lib/wasm-async/AsyncWasmLoadingRuntimeModule.js +11 -3
- package/lib/wasm-async/AsyncWebAssemblyGenerator.js +1 -0
- package/lib/wasm-async/AsyncWebAssemblyModulesPlugin.js +3 -2
- package/lib/wasm-sync/UnsupportedWebAssemblyFeatureError.js +5 -1
- package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +3 -0
- package/lib/wasm-sync/WebAssemblyInInitialChunkError.js +2 -0
- package/lib/wasm-sync/WebAssemblyJavascriptGenerator.js +7 -3
- package/lib/wasm-sync/WebAssemblyModulesPlugin.js +2 -2
- package/lib/wasm-sync/WebAssemblyParser.js +3 -1
- package/lib/web/FetchCompileWasmPlugin.js +1 -0
- package/lib/web/JsonpChunkLoadingPlugin.js +1 -0
- package/lib/web/JsonpChunkLoadingRuntimeModule.js +1 -0
- package/lib/webpack.js +13 -3
- package/lib/webworker/ImportScriptsChunkLoadingPlugin.js +1 -0
- package/package.json +20 -28
- package/schemas/WebpackOptions.check.js +1 -1
- package/schemas/WebpackOptions.json +71 -5
- package/types.d.ts +339 -93
|
@@ -20,6 +20,12 @@ const createHash = require("../util/createHash");
|
|
|
20
20
|
/** @typedef {import("../Compiler")} Compiler */
|
|
21
21
|
/** @typedef {typeof import("../util/Hash")} Hash */
|
|
22
22
|
|
|
23
|
+
/**
|
|
24
|
+
* @template T
|
|
25
|
+
* @typedef {import("../util/comparators").Comparator<T>} Comparator
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
/** @type {Hashes} */
|
|
23
29
|
const EMPTY_SET = new Set();
|
|
24
30
|
|
|
25
31
|
/**
|
|
@@ -47,6 +53,7 @@ const mapAndDeduplicateBuffers = (input, fn) => {
|
|
|
47
53
|
// Buffer.equals compares size first so this should be efficient enough
|
|
48
54
|
// If it becomes a performance problem we can use a map and group by size
|
|
49
55
|
// instead of looping over all assets.
|
|
56
|
+
/** @type {Buffer[]} */
|
|
50
57
|
const result = [];
|
|
51
58
|
outer: for (const value of input) {
|
|
52
59
|
const buf = fn(value);
|
|
@@ -65,6 +72,7 @@ const mapAndDeduplicateBuffers = (input, fn) => {
|
|
|
65
72
|
*/
|
|
66
73
|
const quoteMeta = (str) => str.replace(/[-[\]\\/{}()*+?.^$|]/g, "\\$&");
|
|
67
74
|
|
|
75
|
+
/** @type {WeakMap<Source, CachedSource>} */
|
|
68
76
|
const cachedSourceMap = new WeakMap();
|
|
69
77
|
|
|
70
78
|
/**
|
|
@@ -82,8 +90,6 @@ const toCachedSource = (source) => {
|
|
|
82
90
|
return newSource;
|
|
83
91
|
};
|
|
84
92
|
|
|
85
|
-
/** @typedef {Set<string>} OwnHashes */
|
|
86
|
-
/** @typedef {Set<string>} ReferencedHashes */
|
|
87
93
|
/** @typedef {Set<string>} Hashes */
|
|
88
94
|
|
|
89
95
|
/**
|
|
@@ -94,10 +100,10 @@ const toCachedSource = (source) => {
|
|
|
94
100
|
* @property {RawSource | undefined} newSource
|
|
95
101
|
* @property {RawSource | undefined} newSourceWithoutOwn
|
|
96
102
|
* @property {string} content
|
|
97
|
-
* @property {
|
|
103
|
+
* @property {Hashes | undefined} ownHashes
|
|
98
104
|
* @property {Promise<void> | undefined} contentComputePromise
|
|
99
105
|
* @property {Promise<void> | undefined} contentComputeWithoutOwnPromise
|
|
100
|
-
* @property {
|
|
106
|
+
* @property {Hashes | undefined} referencedHashes
|
|
101
107
|
* @property {Hashes} hashes
|
|
102
108
|
*/
|
|
103
109
|
|
|
@@ -220,7 +226,9 @@ class RealContentHashPlugin {
|
|
|
220
226
|
);
|
|
221
227
|
[asset.referencedHashes, asset.ownHashes] =
|
|
222
228
|
await cacheAnalyse.providePromise(name, etag, () => {
|
|
229
|
+
/** @type {Hashes} */
|
|
223
230
|
const referencedHashes = new Set();
|
|
231
|
+
/** @type {Hashes} */
|
|
224
232
|
const ownHashes = new Set();
|
|
225
233
|
const inContent = content.match(hashRegExp);
|
|
226
234
|
if (inContent) {
|
|
@@ -238,15 +246,13 @@ class RealContentHashPlugin {
|
|
|
238
246
|
);
|
|
239
247
|
/**
|
|
240
248
|
* @param {string} hash the hash
|
|
241
|
-
* @returns {undefined |
|
|
249
|
+
* @returns {undefined | Hashes} the referenced hashes
|
|
242
250
|
*/
|
|
243
251
|
const getDependencies = (hash) => {
|
|
244
252
|
const assets = hashToAssets.get(hash);
|
|
245
253
|
if (!assets) {
|
|
246
254
|
const referencingAssets = assetsWithInfo.filter((asset) =>
|
|
247
|
-
/** @type {
|
|
248
|
-
hash
|
|
249
|
-
)
|
|
255
|
+
/** @type {Hashes} */ (asset.referencedHashes).has(hash)
|
|
250
256
|
);
|
|
251
257
|
const err = new WebpackError(`RealContentHashPlugin
|
|
252
258
|
Some kind of unexpected caching problem occurred.
|
|
@@ -264,16 +270,15 @@ ${referencingAssets
|
|
|
264
270
|
compilation.errors.push(err);
|
|
265
271
|
return;
|
|
266
272
|
}
|
|
273
|
+
/** @type {Hashes} */
|
|
267
274
|
const hashes = new Set();
|
|
268
275
|
for (const { referencedHashes, ownHashes } of assets) {
|
|
269
|
-
if (!(/** @type {
|
|
270
|
-
for (const hash of /** @type {
|
|
276
|
+
if (!(/** @type {Hashes} */ (ownHashes).has(hash))) {
|
|
277
|
+
for (const hash of /** @type {Hashes} */ (ownHashes)) {
|
|
271
278
|
hashes.add(hash);
|
|
272
279
|
}
|
|
273
280
|
}
|
|
274
|
-
for (const hash of /** @type {
|
|
275
|
-
referencedHashes
|
|
276
|
-
)) {
|
|
281
|
+
for (const hash of /** @type {Hashes} */ (referencedHashes)) {
|
|
277
282
|
hashes.add(hash);
|
|
278
283
|
}
|
|
279
284
|
}
|
|
@@ -290,7 +295,7 @@ ${referencingAssets
|
|
|
290
295
|
(a) => a.name
|
|
291
296
|
)})`;
|
|
292
297
|
};
|
|
293
|
-
/** @type {
|
|
298
|
+
/** @type {Hashes} */
|
|
294
299
|
const hashesInOrder = new Set();
|
|
295
300
|
for (const hash of hashToAssets.keys()) {
|
|
296
301
|
/**
|
|
@@ -329,7 +334,7 @@ ${referencingAssets
|
|
|
329
334
|
cacheGenerate.mergeEtags(
|
|
330
335
|
cacheGenerate.getLazyHashedEtag(asset.source),
|
|
331
336
|
Array.from(
|
|
332
|
-
/** @type {
|
|
337
|
+
/** @type {Hashes} */ (asset.referencedHashes),
|
|
333
338
|
(hash) => hashToNewHash.get(hash)
|
|
334
339
|
).join("|")
|
|
335
340
|
);
|
|
@@ -341,10 +346,10 @@ ${referencingAssets
|
|
|
341
346
|
if (asset.contentComputePromise) return asset.contentComputePromise;
|
|
342
347
|
return (asset.contentComputePromise = (async () => {
|
|
343
348
|
if (
|
|
344
|
-
/** @type {
|
|
345
|
-
[
|
|
346
|
-
|
|
347
|
-
|
|
349
|
+
/** @type {Hashes} */ (asset.ownHashes).size > 0 ||
|
|
350
|
+
[.../** @type {Hashes} */ (asset.referencedHashes)].some(
|
|
351
|
+
(hash) => hashToNewHash.get(hash) !== hash
|
|
352
|
+
)
|
|
348
353
|
) {
|
|
349
354
|
const identifier = asset.name;
|
|
350
355
|
const etag = getEtag(asset);
|
|
@@ -372,10 +377,10 @@ ${referencingAssets
|
|
|
372
377
|
}
|
|
373
378
|
return (asset.contentComputeWithoutOwnPromise = (async () => {
|
|
374
379
|
if (
|
|
375
|
-
/** @type {
|
|
376
|
-
[
|
|
377
|
-
|
|
378
|
-
|
|
380
|
+
/** @type {Hashes} */ (asset.ownHashes).size > 0 ||
|
|
381
|
+
[.../** @type {Hashes} */ (asset.referencedHashes)].some(
|
|
382
|
+
(hash) => hashToNewHash.get(hash) !== hash
|
|
383
|
+
)
|
|
379
384
|
) {
|
|
380
385
|
const identifier = `${asset.name}|without-own`;
|
|
381
386
|
const etag = getEtag(asset);
|
|
@@ -387,7 +392,7 @@ ${referencingAssets
|
|
|
387
392
|
hashRegExp,
|
|
388
393
|
(hash) => {
|
|
389
394
|
if (
|
|
390
|
-
/** @type {
|
|
395
|
+
/** @type {Hashes} */
|
|
391
396
|
(asset.ownHashes).has(hash)
|
|
392
397
|
) {
|
|
393
398
|
return "";
|
|
@@ -401,6 +406,7 @@ ${referencingAssets
|
|
|
401
406
|
}
|
|
402
407
|
})());
|
|
403
408
|
};
|
|
409
|
+
/** @type {Comparator<AssetInfoForRealContentHash>} */
|
|
404
410
|
const comparator = compareSelect((a) => a.name, compareStrings);
|
|
405
411
|
for (const oldHash of hashesInOrder) {
|
|
406
412
|
const assets =
|
|
@@ -409,13 +415,13 @@ ${referencingAssets
|
|
|
409
415
|
assets.sort(comparator);
|
|
410
416
|
await Promise.all(
|
|
411
417
|
assets.map((asset) =>
|
|
412
|
-
/** @type {
|
|
418
|
+
/** @type {Hashes} */ (asset.ownHashes).has(oldHash)
|
|
413
419
|
? computeNewContentWithoutOwn(asset)
|
|
414
420
|
: computeNewContent(asset)
|
|
415
421
|
)
|
|
416
422
|
);
|
|
417
423
|
const assetsContent = mapAndDeduplicateBuffers(assets, (asset) => {
|
|
418
|
-
if (/** @type {
|
|
424
|
+
if (/** @type {Hashes} */ (asset.ownHashes).has(oldHash)) {
|
|
419
425
|
return asset.newSourceWithoutOwn
|
|
420
426
|
? asset.newSourceWithoutOwn.buffer()
|
|
421
427
|
: asset.source.buffer();
|
|
@@ -447,7 +453,9 @@ ${referencingAssets
|
|
|
447
453
|
);
|
|
448
454
|
|
|
449
455
|
const infoUpdate = {};
|
|
450
|
-
const hash =
|
|
456
|
+
const hash =
|
|
457
|
+
/** @type {Exclude<AssetInfo["contenthash"], undefined>} */
|
|
458
|
+
(asset.info.contenthash);
|
|
451
459
|
infoUpdate.contenthash = Array.isArray(hash)
|
|
452
460
|
? hash.map(
|
|
453
461
|
(hash) => /** @type {string} */ (hashToNewHash.get(hash))
|
|
@@ -33,7 +33,7 @@ const THIRTY_TWO_BIGINT = BigInt(32);
|
|
|
33
33
|
* Parses the module mask and returns the modules represented by it
|
|
34
34
|
* @param {bigint} mask the module mask
|
|
35
35
|
* @param {Module[]} ordinalModules the modules in the order they were added to the mask (LSB is index 0)
|
|
36
|
-
* @returns {Generator<Module>} the modules represented by the mask
|
|
36
|
+
* @returns {Generator<Module, undefined, undefined>} the modules represented by the mask
|
|
37
37
|
*/
|
|
38
38
|
function* getModulesFromMask(mask, ordinalModules) {
|
|
39
39
|
let offset = 31;
|
|
@@ -74,10 +74,13 @@ class RemoveParentModulesPlugin {
|
|
|
74
74
|
*/
|
|
75
75
|
const handler = (chunks, chunkGroups) => {
|
|
76
76
|
const chunkGraph = compilation.chunkGraph;
|
|
77
|
+
/** @type {Set<ChunkGroup>} */
|
|
77
78
|
const queue = new Set();
|
|
79
|
+
/** @type {WeakMap<ChunkGroup, bigint | undefined>} */
|
|
78
80
|
const availableModulesMap = new WeakMap();
|
|
79
81
|
|
|
80
82
|
let nextModuleMask = ONE_BIGINT;
|
|
83
|
+
/** @type {WeakMap<Module, bigint>} */
|
|
81
84
|
const maskByModule = new WeakMap();
|
|
82
85
|
/** @type {Module[]} */
|
|
83
86
|
const ordinalModules = [];
|
|
@@ -99,6 +102,7 @@ class RemoveParentModulesPlugin {
|
|
|
99
102
|
};
|
|
100
103
|
|
|
101
104
|
// Initialize masks by chunk and by chunk group for quicker comparisons
|
|
105
|
+
/** @type {WeakMap<Chunk, bigint>} */
|
|
102
106
|
const chunkMasks = new WeakMap();
|
|
103
107
|
for (const chunk of chunks) {
|
|
104
108
|
let mask = ZERO_BIGINT;
|
|
@@ -109,6 +113,7 @@ class RemoveParentModulesPlugin {
|
|
|
109
113
|
chunkMasks.set(chunk, mask);
|
|
110
114
|
}
|
|
111
115
|
|
|
116
|
+
/** @type {WeakMap<ChunkGroup, bigint>} */
|
|
112
117
|
const chunkGroupMasks = new WeakMap();
|
|
113
118
|
for (const chunkGroup of chunkGroups) {
|
|
114
119
|
let mask = ZERO_BIGINT;
|
|
@@ -143,7 +148,8 @@ class RemoveParentModulesPlugin {
|
|
|
143
148
|
const availableModulesInParent = availableModulesMap.get(parent);
|
|
144
149
|
if (availableModulesInParent !== undefined) {
|
|
145
150
|
const parentMask =
|
|
146
|
-
availableModulesInParent |
|
|
151
|
+
availableModulesInParent |
|
|
152
|
+
/** @type {bigint} */ (chunkGroupMasks.get(parent));
|
|
147
153
|
// If we know the available modules in parent: process these
|
|
148
154
|
if (availableModulesMask === undefined) {
|
|
149
155
|
// if we have not own info yet: create new entry
|
|
@@ -181,7 +187,10 @@ class RemoveParentModulesPlugin {
|
|
|
181
187
|
);
|
|
182
188
|
if (availableModulesSets.includes(undefined)) continue; // No info about this chunk group
|
|
183
189
|
|
|
184
|
-
const availableModulesMask = intersectMasks(
|
|
190
|
+
const availableModulesMask = intersectMasks(
|
|
191
|
+
/** @type {bigint[]} */
|
|
192
|
+
(availableModulesSets)
|
|
193
|
+
);
|
|
185
194
|
const toRemoveMask = chunkMask & availableModulesMask;
|
|
186
195
|
if (toRemoveMask !== ZERO_BIGINT) {
|
|
187
196
|
for (const module of getModulesFromMask(
|
|
@@ -68,6 +68,7 @@ class SideEffectsFlagPlugin {
|
|
|
68
68
|
* @param {boolean} analyseSource analyse source code for side effects
|
|
69
69
|
*/
|
|
70
70
|
constructor(analyseSource = true) {
|
|
71
|
+
/** @type {boolean} */
|
|
71
72
|
this._analyseSource = analyseSource;
|
|
72
73
|
}
|
|
73
74
|
|
|
@@ -277,6 +278,7 @@ class SideEffectsFlagPlugin {
|
|
|
277
278
|
|
|
278
279
|
logger.time("update dependencies");
|
|
279
280
|
|
|
281
|
+
/** @type {Set<Module>} */
|
|
280
282
|
const optimizedModules = new Set();
|
|
281
283
|
|
|
282
284
|
/**
|
|
@@ -291,6 +293,7 @@ class SideEffectsFlagPlugin {
|
|
|
291
293
|
module
|
|
292
294
|
)) {
|
|
293
295
|
const dep = connection.dependency;
|
|
296
|
+
/** @type {boolean} */
|
|
294
297
|
let isReexport;
|
|
295
298
|
if (
|
|
296
299
|
(isReexport =
|
|
@@ -36,6 +36,7 @@ const MinMaxSizeWarning = require("./MinMaxSizeWarning");
|
|
|
36
36
|
/** @typedef {import("../TemplatedPathPlugin").TemplatePath} TemplatePath */
|
|
37
37
|
/** @typedef {import("../util/deterministicGrouping").GroupedItems<Module>} DeterministicGroupingGroupedItemsForModule */
|
|
38
38
|
/** @typedef {import("../util/deterministicGrouping").Options<Module>} DeterministicGroupingOptionsForModule */
|
|
39
|
+
/** @typedef {import("../util/deterministicGrouping").Sizes} Sizes */
|
|
39
40
|
|
|
40
41
|
/**
|
|
41
42
|
* @callback ChunkFilterFn
|
|
@@ -220,9 +221,10 @@ const getRequests = (chunk) => {
|
|
|
220
221
|
* @returns {T} result
|
|
221
222
|
*/
|
|
222
223
|
const mapObject = (obj, fn) => {
|
|
224
|
+
/** @type {T} */
|
|
223
225
|
const newObj = Object.create(null);
|
|
224
226
|
for (const key of Object.keys(obj)) {
|
|
225
|
-
newObj[key] = fn(
|
|
227
|
+
newObj[/** @type {keyof T} */ (key)] = fn(
|
|
226
228
|
obj[/** @type {keyof T} */ (key)],
|
|
227
229
|
/** @type {keyof T} */
|
|
228
230
|
(key)
|
|
@@ -478,6 +480,7 @@ const normalizeCacheGroups = (cacheGroups, defaultSizeTypes) => {
|
|
|
478
480
|
}
|
|
479
481
|
});
|
|
480
482
|
} else if (typeof option === "function") {
|
|
483
|
+
/** @type {WeakMap<OptimizationSplitChunksCacheGroup, CacheGroupSource>} */
|
|
481
484
|
const cache = new WeakMap();
|
|
482
485
|
handlers.push((module, context, results) => {
|
|
483
486
|
const result = option(module);
|
|
@@ -868,7 +871,7 @@ module.exports = class SplitChunksPlugin {
|
|
|
868
871
|
index <<= ONE;
|
|
869
872
|
}
|
|
870
873
|
/**
|
|
871
|
-
* @param {Iterable<Chunk>} chunks list of chunks
|
|
874
|
+
* @param {Iterable<Chunk, undefined, undefined>} chunks list of chunks
|
|
872
875
|
* @returns {bigint | Chunk} key of the chunks
|
|
873
876
|
*/
|
|
874
877
|
const getKey = (chunks) => {
|
|
@@ -921,6 +924,7 @@ module.exports = class SplitChunksPlugin {
|
|
|
921
924
|
*/
|
|
922
925
|
const groupChunksByExports = (module) => {
|
|
923
926
|
const exportsInfo = moduleGraph.getExportsInfo(module);
|
|
927
|
+
/** @type {Map<string, Chunk[]>} */
|
|
924
928
|
const groupedByUsedExports = new Map();
|
|
925
929
|
for (const chunk of chunkGraph.getModuleChunksIterable(module)) {
|
|
926
930
|
const key = exportsInfo.getUsageKey(chunk.runtime);
|
|
@@ -1082,7 +1086,8 @@ module.exports = class SplitChunksPlugin {
|
|
|
1082
1086
|
* @property {bigint | Chunk} key a key of the list
|
|
1083
1087
|
*/
|
|
1084
1088
|
|
|
1085
|
-
/** @
|
|
1089
|
+
/** @typedef {WeakMap<ChunkFilterFn, SelectedChunksResult>} ChunkMap */
|
|
1090
|
+
/** @type {WeakMap<ChunkSet | Chunk, ChunkMap>} */
|
|
1086
1091
|
const selectedChunksCacheByChunksSet = new WeakMap();
|
|
1087
1092
|
|
|
1088
1093
|
/**
|
|
@@ -1095,6 +1100,7 @@ module.exports = class SplitChunksPlugin {
|
|
|
1095
1100
|
const getSelectedChunks = (chunks, chunkFilter) => {
|
|
1096
1101
|
let entry = selectedChunksCacheByChunksSet.get(chunks);
|
|
1097
1102
|
if (entry === undefined) {
|
|
1103
|
+
/** @type {ChunkMap} */
|
|
1098
1104
|
entry = new WeakMap();
|
|
1099
1105
|
selectedChunksCacheByChunksSet.set(chunks, entry);
|
|
1100
1106
|
}
|
|
@@ -1392,7 +1398,9 @@ module.exports = class SplitChunksPlugin {
|
|
|
1392
1398
|
|
|
1393
1399
|
while (chunksInfoMap.size > 0) {
|
|
1394
1400
|
// Find best matching entry
|
|
1401
|
+
/** @type {undefined | string} */
|
|
1395
1402
|
let bestEntryKey;
|
|
1403
|
+
/** @type {undefined | ChunksInfoItem} */
|
|
1396
1404
|
let bestEntry;
|
|
1397
1405
|
for (const pair of chunksInfoMap) {
|
|
1398
1406
|
const key = pair[0];
|
|
@@ -1471,6 +1479,7 @@ module.exports = class SplitChunksPlugin {
|
|
|
1471
1479
|
item.cacheGroup._conditionalEnforce &&
|
|
1472
1480
|
checkMinSize(item.sizes, item.cacheGroup.enforceSizeThreshold);
|
|
1473
1481
|
|
|
1482
|
+
/** @type {Set<Chunk>} */
|
|
1474
1483
|
const usedChunks = new Set(item.chunks);
|
|
1475
1484
|
|
|
1476
1485
|
// Check if maxRequests condition can be fulfilled
|
|
@@ -1533,6 +1542,7 @@ module.exports = class SplitChunksPlugin {
|
|
|
1533
1542
|
usedChunks.size === 1
|
|
1534
1543
|
) {
|
|
1535
1544
|
const [chunk] = usedChunks;
|
|
1545
|
+
/** @type {SplitChunksSizes} */
|
|
1536
1546
|
const chunkSizes = Object.create(null);
|
|
1537
1547
|
for (const module of chunkGraph.getChunkModulesIterable(chunk)) {
|
|
1538
1548
|
if (!item.modules.has(module)) {
|
|
@@ -1763,6 +1773,7 @@ module.exports = class SplitChunksPlugin {
|
|
|
1763
1773
|
return key;
|
|
1764
1774
|
},
|
|
1765
1775
|
getSize(module) {
|
|
1776
|
+
/** @type {Sizes} */
|
|
1766
1777
|
const size = Object.create(null);
|
|
1767
1778
|
for (const key of module.getSourceTypes()) {
|
|
1768
1779
|
size[key] = module.size(key);
|
|
@@ -10,7 +10,7 @@ const WebpackError = require("../WebpackError");
|
|
|
10
10
|
|
|
11
11
|
/** @typedef {import("./SizeLimitsPlugin").AssetDetails} AssetDetails */
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
class AssetsOverSizeLimitWarning extends WebpackError {
|
|
14
14
|
/**
|
|
15
15
|
* @param {AssetDetails[]} assetsOverSizeLimit the assets
|
|
16
16
|
* @param {number} assetLimit the size limit
|
|
@@ -26,7 +26,11 @@ module.exports = class AssetsOverSizeLimitWarning extends WebpackError {
|
|
|
26
26
|
This can impact web performance.
|
|
27
27
|
Assets: ${assetLists}`);
|
|
28
28
|
|
|
29
|
+
/** @type {string} */
|
|
29
30
|
this.name = "AssetsOverSizeLimitWarning";
|
|
30
31
|
this.assets = assetsOverSizeLimit;
|
|
31
32
|
}
|
|
32
|
-
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** @type {typeof AssetsOverSizeLimitWarning} */
|
|
36
|
+
module.exports = AssetsOverSizeLimitWarning;
|
|
@@ -10,7 +10,7 @@ const WebpackError = require("../WebpackError");
|
|
|
10
10
|
|
|
11
11
|
/** @typedef {import("./SizeLimitsPlugin").EntrypointDetails} EntrypointDetails */
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
class EntrypointsOverSizeLimitWarning extends WebpackError {
|
|
14
14
|
/**
|
|
15
15
|
* @param {EntrypointDetails[]} entrypoints the entrypoints
|
|
16
16
|
* @param {number} entrypointLimit the size limit
|
|
@@ -29,7 +29,11 @@ module.exports = class EntrypointsOverSizeLimitWarning extends WebpackError {
|
|
|
29
29
|
)}). This can impact web performance.
|
|
30
30
|
Entrypoints:${entrypointList}\n`);
|
|
31
31
|
|
|
32
|
+
/** @type {string} */
|
|
32
33
|
this.name = "EntrypointsOverSizeLimitWarning";
|
|
33
34
|
this.entrypoints = entrypoints;
|
|
34
35
|
}
|
|
35
|
-
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/** @type {typeof EntrypointsOverSizeLimitWarning} */
|
|
39
|
+
module.exports = EntrypointsOverSizeLimitWarning;
|
|
@@ -24,7 +24,9 @@ class BasicEffectRulePlugin {
|
|
|
24
24
|
* @param {string=} effectType the effect type
|
|
25
25
|
*/
|
|
26
26
|
constructor(ruleProperty, effectType) {
|
|
27
|
+
/** @type {BasicEffectRuleKeys} */
|
|
27
28
|
this.ruleProperty = ruleProperty;
|
|
29
|
+
/** @type {string | BasicEffectRuleKeys} */
|
|
28
30
|
this.effectType = effectType || ruleProperty;
|
|
29
31
|
}
|
|
30
32
|
|
|
@@ -27,8 +27,11 @@ class BasicMatcherRulePlugin {
|
|
|
27
27
|
* @param {boolean=} invert if true, inverts the condition
|
|
28
28
|
*/
|
|
29
29
|
constructor(ruleProperty, dataProperty, invert) {
|
|
30
|
+
/** @type {BasicMatcherRuleKeys} */
|
|
30
31
|
this.ruleProperty = ruleProperty;
|
|
32
|
+
/** @type {string | BasicMatcherRuleKeys} */
|
|
31
33
|
this.dataProperty = dataProperty || ruleProperty;
|
|
34
|
+
/** @type {boolean} */
|
|
32
35
|
this.invert = invert || false;
|
|
33
36
|
}
|
|
34
37
|
|
|
@@ -18,18 +18,22 @@
|
|
|
18
18
|
*/
|
|
19
19
|
|
|
20
20
|
/** @typedef {KeysOfTypes<RuleSetRule, { [k: string]: RuleSetConditionOrConditions }>} ObjectMatcherRuleKeys */
|
|
21
|
+
/** @typedef {keyof EffectData} DataProperty */
|
|
21
22
|
|
|
22
23
|
const PLUGIN_NAME = "ObjectMatcherRulePlugin";
|
|
23
24
|
|
|
24
25
|
class ObjectMatcherRulePlugin {
|
|
25
26
|
/**
|
|
26
27
|
* @param {ObjectMatcherRuleKeys} ruleProperty the rule property
|
|
27
|
-
* @param {
|
|
28
|
+
* @param {DataProperty=} dataProperty the data property
|
|
28
29
|
* @param {RuleConditionFunction=} additionalConditionFunction need to check
|
|
29
30
|
*/
|
|
30
31
|
constructor(ruleProperty, dataProperty, additionalConditionFunction) {
|
|
32
|
+
/** @type {ObjectMatcherRuleKeys} */
|
|
31
33
|
this.ruleProperty = ruleProperty;
|
|
34
|
+
/** @type {DataProperty | ObjectMatcherRuleKeys} */
|
|
32
35
|
this.dataProperty = dataProperty || ruleProperty;
|
|
36
|
+
/** @type {RuleConditionFunction | undefined} */
|
|
33
37
|
this.additionalConditionFunction = additionalConditionFunction;
|
|
34
38
|
}
|
|
35
39
|
|
|
@@ -116,6 +116,7 @@ class RuleSetCompiler {
|
|
|
116
116
|
* @returns {RuleSet} compiled RuleSet
|
|
117
117
|
*/
|
|
118
118
|
compile(ruleSet) {
|
|
119
|
+
/** @type {References} */
|
|
119
120
|
const refs = new Map();
|
|
120
121
|
const rules = this.compileRules("ruleSet", ruleSet, refs);
|
|
121
122
|
|
|
@@ -327,6 +328,7 @@ class RuleSetCompiler {
|
|
|
327
328
|
);
|
|
328
329
|
}
|
|
329
330
|
|
|
331
|
+
/** @type {Condition[]} */
|
|
330
332
|
const conditions = [];
|
|
331
333
|
for (const key of Object.keys(condition)) {
|
|
332
334
|
const value = condition[key];
|
|
@@ -26,10 +26,14 @@ class GetChunkFilenameRuntimeModule extends RuntimeModule {
|
|
|
26
26
|
*/
|
|
27
27
|
constructor(contentType, name, global, getFilenameForChunk, allChunks) {
|
|
28
28
|
super(`get ${name} chunk filename`);
|
|
29
|
+
/** @type {string} */
|
|
29
30
|
this.contentType = contentType;
|
|
31
|
+
/** @type {string} */
|
|
30
32
|
this.global = global;
|
|
31
33
|
this.getFilenameForChunk = getFilenameForChunk;
|
|
34
|
+
/** @type {boolean} */
|
|
32
35
|
this.allChunks = allChunks;
|
|
36
|
+
/** @type {boolean} */
|
|
33
37
|
this.dependentHash = true;
|
|
34
38
|
}
|
|
35
39
|
|
|
@@ -47,7 +47,9 @@ class LoadScriptRuntimeModule extends HelperRuntimeModule {
|
|
|
47
47
|
*/
|
|
48
48
|
constructor(withCreateScriptUrl, withFetchPriority) {
|
|
49
49
|
super("load script");
|
|
50
|
+
/** @type {boolean | undefined} */
|
|
50
51
|
this._withCreateScriptUrl = withCreateScriptUrl;
|
|
52
|
+
/** @type {boolean | undefined} */
|
|
51
53
|
this._withFetchPriority = withFetchPriority;
|
|
52
54
|
}
|
|
53
55
|
|