webpack 5.103.0 → 5.104.1
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/hot/dev-server.js +18 -3
- package/hot/emitter-event-target.js +7 -0
- package/hot/lazy-compilation-node.js +45 -29
- package/hot/lazy-compilation-universal.js +18 -0
- package/hot/lazy-compilation-web.js +15 -5
- package/hot/load-http.js +7 -0
- package/hot/only-dev-server.js +19 -4
- package/lib/APIPlugin.js +6 -0
- package/lib/Chunk.js +1 -1
- package/lib/ChunkGraph.js +9 -7
- package/lib/ChunkGroup.js +8 -5
- package/lib/CleanPlugin.js +6 -3
- package/lib/CodeGenerationResults.js +2 -1
- package/lib/CompatibilityPlugin.js +3 -0
- package/lib/Compilation.js +33 -19
- package/lib/Compiler.js +3 -3
- package/lib/ContextModule.js +6 -3
- package/lib/ContextModuleFactory.js +6 -4
- package/lib/DefinePlugin.js +34 -3
- package/lib/DelegatedModule.js +7 -4
- package/lib/DllModule.js +6 -3
- package/lib/DotenvPlugin.js +11 -6
- package/lib/ExportsInfo.js +5 -5
- package/lib/ExternalModule.js +8 -7
- package/lib/ExternalModuleFactoryPlugin.js +1 -1
- package/lib/FileSystemInfo.js +1 -1
- package/lib/Generator.js +10 -7
- package/lib/HookWebpackError.js +33 -4
- package/lib/HotModuleReplacementPlugin.js +22 -0
- package/lib/ManifestPlugin.js +1 -1
- package/lib/Module.js +24 -15
- package/lib/ModuleBuildError.js +1 -1
- package/lib/ModuleError.js +1 -1
- package/lib/ModuleFilenameHelpers.js +1 -1
- package/lib/ModuleGraph.js +27 -12
- package/lib/ModuleGraphConnection.js +2 -2
- package/lib/ModuleSourceTypeConstants.js +189 -0
- package/lib/ModuleTypeConstants.js +1 -4
- package/lib/ModuleWarning.js +1 -1
- package/lib/NodeStuffPlugin.js +52 -42
- package/lib/NormalModule.js +6 -4
- package/lib/NormalModuleFactory.js +7 -10
- package/lib/Parser.js +1 -1
- package/lib/RawModule.js +7 -4
- package/lib/RuntimeModule.js +1 -1
- package/lib/RuntimeTemplate.js +5 -1
- package/lib/SizeFormatHelpers.js +1 -1
- package/lib/SourceMapDevToolPlugin.js +6 -1
- package/lib/Template.js +17 -6
- package/lib/TemplatedPathPlugin.js +5 -6
- package/lib/WebpackError.js +0 -1
- package/lib/WebpackOptionsApply.js +37 -9
- package/lib/asset/AssetBytesGenerator.js +15 -11
- package/lib/asset/AssetGenerator.js +30 -24
- package/lib/asset/AssetSourceGenerator.js +15 -11
- package/lib/asset/RawDataUrlModule.js +6 -3
- package/lib/buildChunkGraph.js +4 -2
- package/lib/cache/PackFileCacheStrategy.js +6 -5
- package/lib/cli.js +2 -43
- package/lib/config/browserslistTargetHandler.js +19 -0
- package/lib/config/defaults.js +128 -43
- package/lib/config/normalization.js +2 -2
- package/lib/config/target.js +5 -0
- package/lib/container/ContainerEntryModule.js +6 -3
- package/lib/container/FallbackModule.js +6 -3
- package/lib/container/RemoteModule.js +1 -3
- package/lib/css/CssGenerator.js +26 -24
- package/lib/css/CssLoadingRuntimeModule.js +12 -4
- package/lib/css/CssModulesPlugin.js +29 -74
- package/lib/css/CssParser.js +828 -341
- package/lib/css/walkCssTokens.js +33 -13
- package/lib/dependencies/CachedConstDependency.js +24 -10
- package/lib/dependencies/CommonJsRequireContextDependency.js +1 -1
- package/lib/dependencies/ContextDependencyHelpers.js +2 -2
- package/lib/dependencies/ContextDependencyTemplateAsRequireCall.js +3 -1
- package/lib/dependencies/CssIcssExportDependency.js +242 -104
- package/lib/dependencies/CssIcssImportDependency.js +61 -4
- package/lib/dependencies/CssIcssSymbolDependency.js +2 -6
- package/lib/dependencies/CssImportDependency.js +2 -1
- package/lib/dependencies/CssUrlDependency.js +3 -2
- package/lib/dependencies/DynamicExports.js +7 -7
- package/lib/dependencies/ExternalModuleDependency.js +7 -4
- package/lib/dependencies/ExternalModuleInitFragment.js +2 -1
- package/lib/dependencies/ExternalModuleInitFragmentDependency.js +2 -1
- package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +3 -2
- package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +6 -4
- package/lib/dependencies/HarmonyExports.js +4 -4
- package/lib/dependencies/HarmonyImportDependency.js +8 -3
- package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +1 -1
- package/lib/dependencies/ImportMetaPlugin.js +57 -0
- package/lib/dependencies/ImportParserPlugin.js +2 -2
- package/lib/dependencies/LocalModulesHelpers.js +3 -3
- package/lib/dependencies/WorkerPlugin.js +2 -2
- package/lib/dependencies/getFunctionExpression.js +1 -1
- package/lib/esm/ModuleChunkFormatPlugin.js +5 -4
- package/lib/hmr/HotModuleReplacement.runtime.js +2 -1
- package/lib/hmr/LazyCompilationPlugin.js +4 -3
- package/lib/ids/IdHelpers.js +16 -7
- package/lib/javascript/ChunkHelpers.js +1 -1
- package/lib/javascript/JavascriptGenerator.js +4 -3
- package/lib/javascript/JavascriptModulesPlugin.js +57 -24
- package/lib/javascript/JavascriptParser.js +19 -6
- package/lib/json/JsonGenerator.js +5 -4
- package/lib/json/JsonParser.js +2 -1
- package/lib/library/AbstractLibraryPlugin.js +1 -1
- package/lib/library/AmdLibraryPlugin.js +4 -1
- package/lib/library/ExportPropertyLibraryPlugin.js +4 -1
- package/lib/library/ModuleLibraryPlugin.js +41 -13
- package/lib/library/SystemLibraryPlugin.js +4 -1
- package/lib/library/UmdLibraryPlugin.js +1 -1
- package/lib/logging/Logger.js +5 -4
- package/lib/logging/createConsoleLogger.js +2 -2
- package/lib/optimize/ConcatenatedModule.js +47 -32
- package/lib/optimize/ModuleConcatenationPlugin.js +5 -4
- package/lib/optimize/SideEffectsFlagPlugin.js +3 -2
- package/lib/optimize/SplitChunksPlugin.js +60 -46
- package/lib/rules/RuleSetCompiler.js +1 -1
- package/lib/runtime/GetChunkFilenameRuntimeModule.js +3 -2
- package/lib/schemes/HttpUriPlugin.js +97 -10
- package/lib/serialization/AggregateErrorSerializer.js +1 -2
- package/lib/serialization/ObjectMiddleware.js +0 -2
- package/lib/serialization/SingleItemMiddleware.js +1 -1
- package/lib/sharing/ConsumeSharedModule.js +1 -1
- package/lib/sharing/ConsumeSharedPlugin.js +5 -3
- package/lib/sharing/ProvideSharedModule.js +1 -1
- package/lib/sharing/resolveMatchedConfigs.js +15 -9
- package/lib/sharing/utils.js +1 -1
- package/lib/stats/DefaultStatsFactoryPlugin.js +8 -5
- package/lib/stats/DefaultStatsPresetPlugin.js +1 -1
- package/lib/stats/DefaultStatsPrinterPlugin.js +1 -1
- package/lib/util/StringXor.js +1 -1
- package/lib/util/URLAbsoluteSpecifier.js +2 -2
- package/lib/util/binarySearchBounds.js +2 -2
- package/lib/util/comparators.js +53 -76
- package/lib/util/compileBooleanMatcher.js +78 -6
- package/lib/util/createHash.js +20 -199
- package/lib/util/deprecation.js +1 -1
- package/lib/util/deterministicGrouping.js +6 -3
- package/lib/util/fs.js +75 -75
- package/lib/util/hash/BatchedHash.js +10 -9
- package/lib/util/hash/BulkUpdateHash.js +138 -0
- package/lib/util/hash/DebugHash.js +75 -0
- package/lib/util/hash/hash-digest.js +216 -0
- package/lib/util/identifier.js +82 -17
- package/lib/util/internalSerializables.js +2 -6
- package/lib/util/runtime.js +3 -3
- package/lib/util/source.js +2 -2
- package/lib/wasm-async/AsyncWebAssemblyGenerator.js +3 -2
- package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +3 -2
- package/lib/wasm-sync/WebAssemblyGenerator.js +9 -6
- package/lib/wasm-sync/WebAssemblyJavascriptGenerator.js +3 -2
- package/lib/wasm-sync/WebAssemblyModulesPlugin.js +6 -2
- package/lib/webpack.js +1 -1
- package/package.json +30 -25
- package/schemas/WebpackOptions.check.js +1 -1
- package/schemas/WebpackOptions.json +59 -82
- package/schemas/plugins/css/CssModuleGeneratorOptions.check.js +1 -1
- package/schemas/plugins/css/CssModuleParserOptions.check.js +1 -1
- package/types.d.ts +225 -158
- package/lib/ModuleSourceTypesConstants.js +0 -117
- package/lib/dependencies/CssIcssFromIdentifierDependency.js +0 -124
- package/lib/dependencies/CssIcssGlobalIdentifierDependency.js +0 -48
- package/lib/dependencies/CssIcssLocalIdentifierDependency.js +0 -61
- package/lib/dependencies/CssIcssSelfLocalIdentifierDependency.js +0 -190
- package/lib/util/jsonParseEvenBetterErrors.js +0 -10
- package/schemas/plugins/css/CssAutoGeneratorOptions.check.d.ts +0 -7
- package/schemas/plugins/css/CssAutoGeneratorOptions.check.js +0 -6
- package/schemas/plugins/css/CssAutoGeneratorOptions.json +0 -3
- package/schemas/plugins/css/CssAutoParserOptions.check.d.ts +0 -7
- package/schemas/plugins/css/CssAutoParserOptions.check.js +0 -6
- package/schemas/plugins/css/CssAutoParserOptions.json +0 -3
- package/schemas/plugins/css/CssGlobalGeneratorOptions.check.d.ts +0 -7
- package/schemas/plugins/css/CssGlobalGeneratorOptions.check.js +0 -6
- package/schemas/plugins/css/CssGlobalGeneratorOptions.json +0 -3
- package/schemas/plugins/css/CssGlobalParserOptions.check.d.ts +0 -7
- package/schemas/plugins/css/CssGlobalParserOptions.check.js +0 -6
- package/schemas/plugins/css/CssGlobalParserOptions.json +0 -3
|
@@ -16,7 +16,10 @@ const {
|
|
|
16
16
|
const ConcatenationScope = require("../ConcatenationScope");
|
|
17
17
|
const { UsageState } = require("../ExportsInfo");
|
|
18
18
|
const Module = require("../Module");
|
|
19
|
-
const {
|
|
19
|
+
const {
|
|
20
|
+
JAVASCRIPT_TYPE,
|
|
21
|
+
JAVASCRIPT_TYPES
|
|
22
|
+
} = require("../ModuleSourceTypeConstants");
|
|
20
23
|
const { JAVASCRIPT_MODULE_TYPE_ESM } = require("../ModuleTypeConstants");
|
|
21
24
|
const RuntimeGlobals = require("../RuntimeGlobals");
|
|
22
25
|
const Template = require("../Template");
|
|
@@ -132,8 +135,10 @@ if (!ReferencerClass.prototype.PropertyDefinition) {
|
|
|
132
135
|
* @property {ExportName} exportName
|
|
133
136
|
*/
|
|
134
137
|
|
|
135
|
-
/** @typedef {ConcatenatedModuleInfo | ExternalModuleInfo
|
|
136
|
-
/** @typedef {ConcatenatedModuleInfo | ExternalModuleInfo | ReferenceToModuleInfo
|
|
138
|
+
/** @typedef {ConcatenatedModuleInfo | ExternalModuleInfo} ModuleInfo */
|
|
139
|
+
/** @typedef {ConcatenatedModuleInfo | ExternalModuleInfo | ReferenceToModuleInfo} ModuleInfoOrReference */
|
|
140
|
+
|
|
141
|
+
/** @typedef {Map<string, string>} ExportMap */
|
|
137
142
|
|
|
138
143
|
/**
|
|
139
144
|
* @typedef {object} ConcatenatedModuleInfo
|
|
@@ -148,8 +153,8 @@ if (!ReferencerClass.prototype.PropertyDefinition) {
|
|
|
148
153
|
* @property {Scope | undefined} globalScope
|
|
149
154
|
* @property {Scope | undefined} moduleScope
|
|
150
155
|
* @property {Map<string, string>} internalNames
|
|
151
|
-
* @property {
|
|
152
|
-
* @property {
|
|
156
|
+
* @property {ExportMap | undefined} exportMap
|
|
157
|
+
* @property {ExportMap | undefined} rawExportMap
|
|
153
158
|
* @property {string=} namespaceExportSymbol
|
|
154
159
|
* @property {string | undefined} namespaceObjectName
|
|
155
160
|
* @property {ConcatenationScope | undefined} concatenationScope
|
|
@@ -192,7 +197,7 @@ if (!ReferencerClass.prototype.PropertyDefinition) {
|
|
|
192
197
|
/**
|
|
193
198
|
* @template T
|
|
194
199
|
* @param {string} property property
|
|
195
|
-
* @param {
|
|
200
|
+
* @param {(a: T[keyof T], b: T[keyof T]) => 0 | 1 | -1} comparator comparator
|
|
196
201
|
* @returns {Comparator<T>} comparator
|
|
197
202
|
*/
|
|
198
203
|
|
|
@@ -684,7 +689,7 @@ const getFinalName = (
|
|
|
684
689
|
|
|
685
690
|
/**
|
|
686
691
|
* @typedef {object} ConcatenateModuleHooks
|
|
687
|
-
* @property {SyncBailHook<[ConcatenatedModule], boolean>} onDemandExportsGeneration
|
|
692
|
+
* @property {SyncBailHook<[ConcatenatedModule, RuntimeSpec[], string, Record<string, string>], boolean>} onDemandExportsGeneration
|
|
688
693
|
* @property {SyncBailHook<[Partial<ConcatenatedModuleInfo>, ConcatenatedModuleInfo], boolean | void>} concatenatedModuleInfo
|
|
689
694
|
*/
|
|
690
695
|
|
|
@@ -734,7 +739,12 @@ class ConcatenatedModule extends Module {
|
|
|
734
739
|
let hooks = compilationHooksMap.get(compilation);
|
|
735
740
|
if (hooks === undefined) {
|
|
736
741
|
hooks = {
|
|
737
|
-
onDemandExportsGeneration: new SyncBailHook([
|
|
742
|
+
onDemandExportsGeneration: new SyncBailHook([
|
|
743
|
+
"module",
|
|
744
|
+
"runtimes",
|
|
745
|
+
"exportsFinalName",
|
|
746
|
+
"exportsSource"
|
|
747
|
+
]),
|
|
738
748
|
concatenatedModuleInfo: new SyncBailHook([
|
|
739
749
|
"updatedInfo",
|
|
740
750
|
"concatenatedModuleInfo"
|
|
@@ -784,7 +794,7 @@ class ConcatenatedModule extends Module {
|
|
|
784
794
|
* @returns {SourceTypes} types available (do not mutate)
|
|
785
795
|
*/
|
|
786
796
|
getSourceTypes() {
|
|
787
|
-
return
|
|
797
|
+
return JAVASCRIPT_TYPES;
|
|
788
798
|
}
|
|
789
799
|
|
|
790
800
|
get modules() {
|
|
@@ -1254,6 +1264,7 @@ class ConcatenatedModule extends Module {
|
|
|
1254
1264
|
moduleGraph,
|
|
1255
1265
|
chunkGraph,
|
|
1256
1266
|
runtime: generationRuntime,
|
|
1267
|
+
runtimes,
|
|
1257
1268
|
codeGenerationResults
|
|
1258
1269
|
}) {
|
|
1259
1270
|
const { concatenatedModuleInfo } = ConcatenatedModule.getCompilationHooks(
|
|
@@ -1289,6 +1300,7 @@ class ConcatenatedModule extends Module {
|
|
|
1289
1300
|
moduleGraph,
|
|
1290
1301
|
chunkGraph,
|
|
1291
1302
|
runtime,
|
|
1303
|
+
runtimes,
|
|
1292
1304
|
/** @type {CodeGenerationResults} */
|
|
1293
1305
|
(codeGenerationResults),
|
|
1294
1306
|
allUsedNames
|
|
@@ -1407,7 +1419,7 @@ class ConcatenatedModule extends Module {
|
|
|
1407
1419
|
* @param {string} name the name to find a new name for
|
|
1408
1420
|
* @param {ConcatenatedModuleInfo} info the info of the module
|
|
1409
1421
|
* @param {Reference[]} references the references to the name
|
|
1410
|
-
* @returns {string|undefined} the new name or undefined if the name is not found
|
|
1422
|
+
* @returns {string | undefined} the new name or undefined if the name is not found
|
|
1411
1423
|
*/
|
|
1412
1424
|
const _findNewName = (name, info, references) => {
|
|
1413
1425
|
const { usedNames, alreadyCheckedScopes } = getUsedNamesInScopeInfo(
|
|
@@ -1441,7 +1453,7 @@ class ConcatenatedModule extends Module {
|
|
|
1441
1453
|
* @param {string} name the name to find a new name for
|
|
1442
1454
|
* @param {ConcatenatedModuleInfo} info the info of the module
|
|
1443
1455
|
* @param {Reference[]} references the references to the name
|
|
1444
|
-
* @returns {string|undefined} the new name or undefined if the name is not found
|
|
1456
|
+
* @returns {string | undefined} the new name or undefined if the name is not found
|
|
1445
1457
|
*/
|
|
1446
1458
|
const _findNewNameForSpecifier = (name, info, references) => {
|
|
1447
1459
|
const { usedNames: moduleUsedNames, alreadyCheckedScopes } =
|
|
@@ -1772,9 +1784,6 @@ class ConcatenatedModule extends Module {
|
|
|
1772
1784
|
);
|
|
1773
1785
|
}
|
|
1774
1786
|
|
|
1775
|
-
const { onDemandExportsGeneration } =
|
|
1776
|
-
ConcatenatedModule.getCompilationHooks(this.compilation);
|
|
1777
|
-
|
|
1778
1787
|
runtimeRequirements.add(RuntimeGlobals.exports);
|
|
1779
1788
|
runtimeRequirements.add(RuntimeGlobals.definePropertyGetters);
|
|
1780
1789
|
|
|
@@ -1788,21 +1797,24 @@ class ConcatenatedModule extends Module {
|
|
|
1788
1797
|
);
|
|
1789
1798
|
}
|
|
1790
1799
|
|
|
1791
|
-
|
|
1792
|
-
|
|
1793
|
-
|
|
1794
|
-
|
|
1795
|
-
|
|
1796
|
-
|
|
1797
|
-
|
|
1798
|
-
|
|
1799
|
-
|
|
1800
|
-
|
|
1801
|
-
|
|
1802
|
-
|
|
1803
|
-
|
|
1804
|
-
|
|
1805
|
-
|
|
1800
|
+
const exportsSource =
|
|
1801
|
+
"\n// EXPORTS\n" +
|
|
1802
|
+
`${RuntimeGlobals.definePropertyGetters}(${this.exportsArgument}, {${definitions.join(
|
|
1803
|
+
","
|
|
1804
|
+
)}\n});\n`;
|
|
1805
|
+
|
|
1806
|
+
const { onDemandExportsGeneration } =
|
|
1807
|
+
ConcatenatedModule.getCompilationHooks(this.compilation);
|
|
1808
|
+
|
|
1809
|
+
if (
|
|
1810
|
+
!onDemandExportsGeneration.call(
|
|
1811
|
+
this,
|
|
1812
|
+
runtimes,
|
|
1813
|
+
exportsSource,
|
|
1814
|
+
exportsFinalName
|
|
1815
|
+
)
|
|
1816
|
+
) {
|
|
1817
|
+
result.add(exportsSource);
|
|
1806
1818
|
}
|
|
1807
1819
|
}
|
|
1808
1820
|
|
|
@@ -2008,7 +2020,7 @@ ${defineGetters}`
|
|
|
2008
2020
|
|
|
2009
2021
|
/** @type {CodeGenerationResult} */
|
|
2010
2022
|
const resultEntry = {
|
|
2011
|
-
sources: new Map([[
|
|
2023
|
+
sources: new Map([[JAVASCRIPT_TYPE, new CachedSource(result)]]),
|
|
2012
2024
|
data,
|
|
2013
2025
|
runtimeRequirements
|
|
2014
2026
|
};
|
|
@@ -2024,6 +2036,7 @@ ${defineGetters}`
|
|
|
2024
2036
|
* @param {ModuleGraph} moduleGraph moduleGraph
|
|
2025
2037
|
* @param {ChunkGraph} chunkGraph chunkGraph
|
|
2026
2038
|
* @param {RuntimeSpec} runtime runtime
|
|
2039
|
+
* @param {RuntimeSpec[]} runtimes runtimes
|
|
2027
2040
|
* @param {CodeGenerationResults} codeGenerationResults codeGenerationResults
|
|
2028
2041
|
* @param {Set<string>} usedNames used names
|
|
2029
2042
|
*/
|
|
@@ -2035,6 +2048,7 @@ ${defineGetters}`
|
|
|
2035
2048
|
moduleGraph,
|
|
2036
2049
|
chunkGraph,
|
|
2037
2050
|
runtime,
|
|
2051
|
+
runtimes,
|
|
2038
2052
|
codeGenerationResults,
|
|
2039
2053
|
usedNames
|
|
2040
2054
|
) {
|
|
@@ -2055,13 +2069,14 @@ ${defineGetters}`
|
|
|
2055
2069
|
moduleGraph,
|
|
2056
2070
|
chunkGraph,
|
|
2057
2071
|
runtime,
|
|
2072
|
+
runtimes,
|
|
2058
2073
|
concatenationScope,
|
|
2059
2074
|
codeGenerationResults,
|
|
2060
|
-
sourceTypes:
|
|
2075
|
+
sourceTypes: JAVASCRIPT_TYPES
|
|
2061
2076
|
});
|
|
2062
2077
|
const source =
|
|
2063
2078
|
/** @type {Source} */
|
|
2064
|
-
(codeGenResult.sources.get(
|
|
2079
|
+
(codeGenResult.sources.get(JAVASCRIPT_TYPE));
|
|
2065
2080
|
const data = codeGenResult.data;
|
|
2066
2081
|
const chunkInitFragments = data && data.get("chunkInitFragments");
|
|
2067
2082
|
const code = source.source().toString();
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
const asyncLib = require("neo-async");
|
|
9
9
|
const ChunkGraph = require("../ChunkGraph");
|
|
10
10
|
const ModuleGraph = require("../ModuleGraph");
|
|
11
|
-
const {
|
|
11
|
+
const { JAVASCRIPT_TYPE } = require("../ModuleSourceTypeConstants");
|
|
12
12
|
const { STAGE_DEFAULT } = require("../OptimizationStages");
|
|
13
13
|
const HarmonyImportDependency = require("../dependencies/HarmonyImportDependency");
|
|
14
14
|
const { compareModulesByIdentifier } = require("../util/comparators");
|
|
@@ -460,7 +460,7 @@ class ModuleConcatenationPlugin {
|
|
|
460
460
|
chunkGraph.disconnectChunkAndModule(chunk, m);
|
|
461
461
|
} else {
|
|
462
462
|
const newSourceTypes = new Set(sourceTypes);
|
|
463
|
-
newSourceTypes.delete(
|
|
463
|
+
newSourceTypes.delete(JAVASCRIPT_TYPE);
|
|
464
464
|
chunkGraph.setChunkModuleSourceTypes(
|
|
465
465
|
chunk,
|
|
466
466
|
m,
|
|
@@ -865,6 +865,7 @@ class ModuleConcatenationPlugin {
|
|
|
865
865
|
}
|
|
866
866
|
|
|
867
867
|
/** @typedef {Module | ((requestShortener: RequestShortener) => string)} Problem */
|
|
868
|
+
/** @typedef {Map<Module, Problem>} Warnings */
|
|
868
869
|
|
|
869
870
|
class ConcatConfiguration {
|
|
870
871
|
/**
|
|
@@ -877,7 +878,7 @@ class ConcatConfiguration {
|
|
|
877
878
|
/** @type {Set<Module>} */
|
|
878
879
|
this.modules = new Set();
|
|
879
880
|
this.modules.add(rootModule);
|
|
880
|
-
/** @type {
|
|
881
|
+
/** @type {Warnings} */
|
|
881
882
|
this.warnings = new Map();
|
|
882
883
|
}
|
|
883
884
|
|
|
@@ -909,7 +910,7 @@ class ConcatConfiguration {
|
|
|
909
910
|
}
|
|
910
911
|
|
|
911
912
|
/**
|
|
912
|
-
* @returns {
|
|
913
|
+
* @returns {Warnings} warnings
|
|
913
914
|
*/
|
|
914
915
|
getWarningsSorted() {
|
|
915
916
|
return new Map(
|
|
@@ -45,7 +45,7 @@ const globToRegexpCache = new WeakMap();
|
|
|
45
45
|
|
|
46
46
|
/**
|
|
47
47
|
* @param {string} glob the pattern
|
|
48
|
-
* @param {
|
|
48
|
+
* @param {CacheItem} cache the glob to RegExp cache
|
|
49
49
|
* @returns {RegExp} a regular expression
|
|
50
50
|
*/
|
|
51
51
|
const globToRegexp = (glob, cache) => {
|
|
@@ -381,6 +381,7 @@ class SideEffectsFlagPlugin {
|
|
|
381
381
|
for (const module of modules) {
|
|
382
382
|
optimizeIncomingConnections(module);
|
|
383
383
|
}
|
|
384
|
+
moduleGraph.finishUpdateParent();
|
|
384
385
|
logger.timeEnd("update dependencies");
|
|
385
386
|
}
|
|
386
387
|
);
|
|
@@ -391,7 +392,7 @@ class SideEffectsFlagPlugin {
|
|
|
391
392
|
/**
|
|
392
393
|
* @param {string} moduleName the module name
|
|
393
394
|
* @param {SideEffectsFlagValue} flagValue the flag value
|
|
394
|
-
* @param {
|
|
395
|
+
* @param {CacheItem} cache cache for glob to regexp
|
|
395
396
|
* @returns {boolean | undefined} true, when the module has side effects, undefined or false when not
|
|
396
397
|
*/
|
|
397
398
|
static moduleHasSideEffects(moduleName, flagValue, cache) {
|
|
@@ -31,6 +31,7 @@ const MinMaxSizeWarning = require("./MinMaxSizeWarning");
|
|
|
31
31
|
/** @typedef {import("../ChunkGroup")} ChunkGroup */
|
|
32
32
|
/** @typedef {import("../Compiler")} Compiler */
|
|
33
33
|
/** @typedef {import("../Module")} Module */
|
|
34
|
+
/** @typedef {import("../Module").SourceType} SourceType */
|
|
34
35
|
/** @typedef {import("../ModuleGraph")} ModuleGraph */
|
|
35
36
|
/** @typedef {import("../TemplatedPathPlugin").TemplatePath} TemplatePath */
|
|
36
37
|
/** @typedef {import("../util/deterministicGrouping").GroupedItems<Module>} DeterministicGroupingGroupedItemsForModule */
|
|
@@ -42,22 +43,26 @@ const MinMaxSizeWarning = require("./MinMaxSizeWarning");
|
|
|
42
43
|
* @returns {boolean | undefined}
|
|
43
44
|
*/
|
|
44
45
|
|
|
46
|
+
/** @typedef {number} Priority */
|
|
47
|
+
/** @typedef {number} Size */
|
|
48
|
+
/** @typedef {number} CountOfChunk */
|
|
49
|
+
/** @typedef {number} CountOfRequest */
|
|
50
|
+
|
|
45
51
|
/**
|
|
46
52
|
* @callback CombineSizeFunction
|
|
47
|
-
* @param {
|
|
48
|
-
* @param {
|
|
49
|
-
* @returns {
|
|
53
|
+
* @param {Size} a
|
|
54
|
+
* @param {Size} b
|
|
55
|
+
* @returns {Size}
|
|
50
56
|
*/
|
|
51
57
|
|
|
52
|
-
/** @typedef {string} SourceType */
|
|
53
58
|
/** @typedef {SourceType[]} SourceTypes */
|
|
54
59
|
/** @typedef {SourceType[]} DefaultSizeTypes */
|
|
55
|
-
/** @typedef {Record<SourceType,
|
|
60
|
+
/** @typedef {Record<SourceType, Size>} SplitChunksSizes */
|
|
56
61
|
|
|
57
62
|
/**
|
|
58
63
|
* @typedef {object} CacheGroupSource
|
|
59
64
|
* @property {string} key
|
|
60
|
-
* @property {
|
|
65
|
+
* @property {Priority=} priority
|
|
61
66
|
* @property {GetNameFn=} getName
|
|
62
67
|
* @property {ChunkFilterFn=} chunksFilter
|
|
63
68
|
* @property {boolean=} enforce
|
|
@@ -67,9 +72,9 @@ const MinMaxSizeWarning = require("./MinMaxSizeWarning");
|
|
|
67
72
|
* @property {SplitChunksSizes} enforceSizeThreshold
|
|
68
73
|
* @property {SplitChunksSizes} maxAsyncSize
|
|
69
74
|
* @property {SplitChunksSizes} maxInitialSize
|
|
70
|
-
* @property {
|
|
71
|
-
* @property {
|
|
72
|
-
* @property {
|
|
75
|
+
* @property {CountOfChunk=} minChunks
|
|
76
|
+
* @property {CountOfRequest=} maxAsyncRequests
|
|
77
|
+
* @property {CountOfRequest=} maxInitialRequests
|
|
73
78
|
* @property {TemplatePath=} filename
|
|
74
79
|
* @property {string=} idHint
|
|
75
80
|
* @property {string=} automaticNameDelimiter
|
|
@@ -80,7 +85,7 @@ const MinMaxSizeWarning = require("./MinMaxSizeWarning");
|
|
|
80
85
|
/**
|
|
81
86
|
* @typedef {object} CacheGroup
|
|
82
87
|
* @property {string} key
|
|
83
|
-
* @property {
|
|
88
|
+
* @property {Priority} priority
|
|
84
89
|
* @property {GetNameFn=} getName
|
|
85
90
|
* @property {ChunkFilterFn} chunksFilter
|
|
86
91
|
* @property {SplitChunksSizes} minSize
|
|
@@ -89,9 +94,9 @@ const MinMaxSizeWarning = require("./MinMaxSizeWarning");
|
|
|
89
94
|
* @property {SplitChunksSizes} enforceSizeThreshold
|
|
90
95
|
* @property {SplitChunksSizes} maxAsyncSize
|
|
91
96
|
* @property {SplitChunksSizes} maxInitialSize
|
|
92
|
-
* @property {
|
|
93
|
-
* @property {
|
|
94
|
-
* @property {
|
|
97
|
+
* @property {CountOfChunk} minChunks
|
|
98
|
+
* @property {CountOfRequest} maxAsyncRequests
|
|
99
|
+
* @property {CountOfRequest} maxInitialRequests
|
|
95
100
|
* @property {TemplatePath=} filename
|
|
96
101
|
* @property {string} idHint
|
|
97
102
|
* @property {string} automaticNameDelimiter
|
|
@@ -143,9 +148,9 @@ const MinMaxSizeWarning = require("./MinMaxSizeWarning");
|
|
|
143
148
|
* @property {SplitChunksSizes} enforceSizeThreshold
|
|
144
149
|
* @property {SplitChunksSizes} maxInitialSize
|
|
145
150
|
* @property {SplitChunksSizes} maxAsyncSize
|
|
146
|
-
* @property {
|
|
147
|
-
* @property {
|
|
148
|
-
* @property {
|
|
151
|
+
* @property {CountOfChunk} minChunks
|
|
152
|
+
* @property {CountOfRequest} maxAsyncRequests
|
|
153
|
+
* @property {CountOfRequest} maxInitialRequests
|
|
149
154
|
* @property {boolean} hidePathInfo
|
|
150
155
|
* @property {TemplatePath=} filename
|
|
151
156
|
* @property {string} automaticNameDelimiter
|
|
@@ -155,15 +160,17 @@ const MinMaxSizeWarning = require("./MinMaxSizeWarning");
|
|
|
155
160
|
* @property {FallbackCacheGroup} fallbackCacheGroup
|
|
156
161
|
*/
|
|
157
162
|
|
|
163
|
+
/** @typedef {Set<Chunk>} ChunkSet */
|
|
164
|
+
|
|
158
165
|
/**
|
|
159
166
|
* @typedef {object} ChunksInfoItem
|
|
160
167
|
* @property {SortableSet<Module>} modules
|
|
161
168
|
* @property {CacheGroup} cacheGroup
|
|
162
169
|
* @property {number} cacheGroupIndex
|
|
163
170
|
* @property {string=} name
|
|
164
|
-
* @property {
|
|
165
|
-
* @property {
|
|
166
|
-
* @property {
|
|
171
|
+
* @property {SplitChunksSizes} sizes
|
|
172
|
+
* @property {ChunkSet} chunks
|
|
173
|
+
* @property {ChunkSet} reusableChunks
|
|
167
174
|
* @property {Set<bigint | Chunk>} chunksKeys
|
|
168
175
|
*/
|
|
169
176
|
|
|
@@ -195,7 +202,7 @@ const hashFilename = (name, outputOptions) => {
|
|
|
195
202
|
|
|
196
203
|
/**
|
|
197
204
|
* @param {Chunk} chunk the chunk
|
|
198
|
-
* @returns {
|
|
205
|
+
* @returns {CountOfRequest} the number of requests
|
|
199
206
|
*/
|
|
200
207
|
const getRequests = (chunk) => {
|
|
201
208
|
let requests = 0;
|
|
@@ -209,7 +216,7 @@ const getRequests = (chunk) => {
|
|
|
209
216
|
* @template {object} T
|
|
210
217
|
* @template {object} R
|
|
211
218
|
* @param {T} obj obj an object
|
|
212
|
-
* @param {
|
|
219
|
+
* @param {(obj: T[keyof T], key: keyof T) => T[keyof T]} fn fn
|
|
213
220
|
* @returns {T} result
|
|
214
221
|
*/
|
|
215
222
|
const mapObject = (obj, fn) => {
|
|
@@ -293,7 +300,7 @@ const ALL_CHUNK_FILTER = (_chunk) => true;
|
|
|
293
300
|
*/
|
|
294
301
|
const normalizeSizes = (value, defaultSizeTypes) => {
|
|
295
302
|
if (typeof value === "number") {
|
|
296
|
-
/** @type {
|
|
303
|
+
/** @type {SplitChunksSizes} */
|
|
297
304
|
const o = {};
|
|
298
305
|
for (const sizeType of defaultSizeTypes) o[sizeType] = value;
|
|
299
306
|
return o;
|
|
@@ -321,7 +328,7 @@ const mergeSizes = (...sizes) => {
|
|
|
321
328
|
* @returns {boolean} true, if there are sizes > 0
|
|
322
329
|
*/
|
|
323
330
|
const hasNonZeroSizes = (sizes) => {
|
|
324
|
-
for (const key of Object.keys(sizes)) {
|
|
331
|
+
for (const key of /** @type {SourceType[]} */ (Object.keys(sizes))) {
|
|
325
332
|
if (sizes[key] > 0) return true;
|
|
326
333
|
}
|
|
327
334
|
return false;
|
|
@@ -334,8 +341,8 @@ const hasNonZeroSizes = (sizes) => {
|
|
|
334
341
|
* @returns {SplitChunksSizes} the combine sizes
|
|
335
342
|
*/
|
|
336
343
|
const combineSizes = (a, b, combine) => {
|
|
337
|
-
const aKeys = new Set(Object.keys(a));
|
|
338
|
-
const bKeys = new Set(Object.keys(b));
|
|
344
|
+
const aKeys = /** @type {Set<SourceType>} */ (new Set(Object.keys(a)));
|
|
345
|
+
const bKeys = /** @type {Set<SourceType>} */ (new Set(Object.keys(b)));
|
|
339
346
|
/** @type {SplitChunksSizes} */
|
|
340
347
|
const result = {};
|
|
341
348
|
for (const key of aKeys) {
|
|
@@ -355,7 +362,7 @@ const combineSizes = (a, b, combine) => {
|
|
|
355
362
|
* @returns {boolean} true if there are sizes and all existing sizes are at least `minSize`
|
|
356
363
|
*/
|
|
357
364
|
const checkMinSize = (sizes, minSize) => {
|
|
358
|
-
for (const key of Object.keys(minSize)) {
|
|
365
|
+
for (const key of /** @type {SourceType[]} */ (Object.keys(minSize))) {
|
|
359
366
|
const size = sizes[key];
|
|
360
367
|
if (size === undefined || size === 0) continue;
|
|
361
368
|
if (size < minSize[key]) return false;
|
|
@@ -366,11 +373,13 @@ const checkMinSize = (sizes, minSize) => {
|
|
|
366
373
|
/**
|
|
367
374
|
* @param {SplitChunksSizes} sizes the sizes
|
|
368
375
|
* @param {SplitChunksSizes} minSizeReduction the min sizes
|
|
369
|
-
* @param {
|
|
376
|
+
* @param {CountOfChunk} chunkCount number of chunks
|
|
370
377
|
* @returns {boolean} true if there are sizes and all existing sizes are at least `minSizeReduction`
|
|
371
378
|
*/
|
|
372
379
|
const checkMinSizeReduction = (sizes, minSizeReduction, chunkCount) => {
|
|
373
|
-
for (const key of
|
|
380
|
+
for (const key of /** @type {SourceType[]} */ (
|
|
381
|
+
Object.keys(minSizeReduction)
|
|
382
|
+
)) {
|
|
374
383
|
const size = sizes[key];
|
|
375
384
|
if (size === undefined || size === 0) continue;
|
|
376
385
|
if (size * chunkCount < minSizeReduction[key]) return false;
|
|
@@ -384,8 +393,9 @@ const checkMinSizeReduction = (sizes, minSizeReduction, chunkCount) => {
|
|
|
384
393
|
* @returns {undefined | SourceTypes} list of size types that are below min size
|
|
385
394
|
*/
|
|
386
395
|
const getViolatingMinSizes = (sizes, minSize) => {
|
|
396
|
+
/** @type {SourceTypes | undefined} */
|
|
387
397
|
let list;
|
|
388
|
-
for (const key of Object.keys(minSize)) {
|
|
398
|
+
for (const key of /** @type {SourceType[]} */ (Object.keys(minSize))) {
|
|
389
399
|
const size = sizes[key];
|
|
390
400
|
if (size === undefined || size === 0) continue;
|
|
391
401
|
if (size < minSize[key]) {
|
|
@@ -398,11 +408,11 @@ const getViolatingMinSizes = (sizes, minSize) => {
|
|
|
398
408
|
|
|
399
409
|
/**
|
|
400
410
|
* @param {SplitChunksSizes} sizes the sizes
|
|
401
|
-
* @returns {
|
|
411
|
+
* @returns {Size} the total size
|
|
402
412
|
*/
|
|
403
413
|
const totalSize = (sizes) => {
|
|
404
414
|
let size = 0;
|
|
405
|
-
for (const key of Object.keys(sizes)) {
|
|
415
|
+
for (const key of /** @type {SourceType[]} */ (Object.keys(sizes))) {
|
|
406
416
|
size += sizes[key];
|
|
407
417
|
}
|
|
408
418
|
return size;
|
|
@@ -887,9 +897,9 @@ module.exports = class SplitChunksPlugin {
|
|
|
887
897
|
};
|
|
888
898
|
|
|
889
899
|
const getChunkSetsInGraph = memoize(() => {
|
|
890
|
-
/** @type {Map<bigint,
|
|
900
|
+
/** @type {Map<bigint, ChunkSet>} */
|
|
891
901
|
const chunkSetsInGraph = new Map();
|
|
892
|
-
/** @type {
|
|
902
|
+
/** @type {ChunkSet} */
|
|
893
903
|
const singleChunkSets = new Set();
|
|
894
904
|
for (const module of compilation.modules) {
|
|
895
905
|
const chunks = chunkGraph.getModuleChunksIterable(module);
|
|
@@ -927,10 +937,12 @@ module.exports = class SplitChunksPlugin {
|
|
|
927
937
|
/** @type {Map<Module, Iterable<Chunk[]>>} */
|
|
928
938
|
const groupedByExportsMap = new Map();
|
|
929
939
|
|
|
940
|
+
/** @typedef {Map<bigint | Chunk, ChunkSet>} ChunkSetsInGraph */
|
|
941
|
+
|
|
930
942
|
const getExportsChunkSetsInGraph = memoize(() => {
|
|
931
|
-
/** @type {
|
|
943
|
+
/** @type {ChunkSetsInGraph} */
|
|
932
944
|
const chunkSetsInGraph = new Map();
|
|
933
|
-
/** @type {
|
|
945
|
+
/** @type {ChunkSet} */
|
|
934
946
|
const singleChunkSets = new Set();
|
|
935
947
|
for (const module of compilation.modules) {
|
|
936
948
|
const groupedChunks = [...groupChunksByExports(module)];
|
|
@@ -949,13 +961,13 @@ module.exports = class SplitChunksPlugin {
|
|
|
949
961
|
return { chunkSetsInGraph, singleChunkSets };
|
|
950
962
|
});
|
|
951
963
|
|
|
952
|
-
/** @typedef {Map<
|
|
964
|
+
/** @typedef {Map<CountOfChunk, ChunkSet[]>} ChunkSetsByCount */
|
|
953
965
|
|
|
954
966
|
// group these set of chunks by count
|
|
955
967
|
// to allow to check less sets via isSubset
|
|
956
968
|
// (only smaller sets can be subset)
|
|
957
969
|
/**
|
|
958
|
-
* @param {IterableIterator<
|
|
970
|
+
* @param {IterableIterator<ChunkSet>} chunkSets set of sets of chunks
|
|
959
971
|
* @returns {ChunkSetsByCount} map of sets of chunks by count
|
|
960
972
|
*/
|
|
961
973
|
const groupChunkSetsByCount = (chunkSets) => {
|
|
@@ -983,13 +995,13 @@ module.exports = class SplitChunksPlugin {
|
|
|
983
995
|
)
|
|
984
996
|
);
|
|
985
997
|
|
|
986
|
-
/** @typedef {(
|
|
998
|
+
/** @typedef {(ChunkSet | Chunk)[]} Combinations */
|
|
987
999
|
|
|
988
1000
|
// Create a list of possible combinations
|
|
989
1001
|
/**
|
|
990
|
-
* @param {
|
|
991
|
-
* @param {
|
|
992
|
-
* @param {
|
|
1002
|
+
* @param {ChunkSetsInGraph} chunkSets chunk sets
|
|
1003
|
+
* @param {ChunkSet} singleChunkSets single chunks sets
|
|
1004
|
+
* @param {ChunkSetsByCount} chunkSetsByCount chunk sets by count
|
|
993
1005
|
* @returns {(key: bigint | Chunk) => Combinations} combinations
|
|
994
1006
|
*/
|
|
995
1007
|
const createGetCombinations = (
|
|
@@ -1009,7 +1021,7 @@ module.exports = class SplitChunksPlugin {
|
|
|
1009
1021
|
return result;
|
|
1010
1022
|
}
|
|
1011
1023
|
const chunksSet =
|
|
1012
|
-
/** @type {
|
|
1024
|
+
/** @type {ChunkSet} */
|
|
1013
1025
|
(chunkSets.get(key));
|
|
1014
1026
|
/** @type {Combinations} */
|
|
1015
1027
|
const array = [chunksSet];
|
|
@@ -1070,13 +1082,13 @@ module.exports = class SplitChunksPlugin {
|
|
|
1070
1082
|
* @property {bigint | Chunk} key a key of the list
|
|
1071
1083
|
*/
|
|
1072
1084
|
|
|
1073
|
-
/** @type {WeakMap<
|
|
1085
|
+
/** @type {WeakMap<ChunkSet | Chunk, WeakMap<ChunkFilterFn, SelectedChunksResult>>} */
|
|
1074
1086
|
const selectedChunksCacheByChunksSet = new WeakMap();
|
|
1075
1087
|
|
|
1076
1088
|
/**
|
|
1077
1089
|
* get list and key by applying the filter function to the list
|
|
1078
1090
|
* It is cached for performance reasons
|
|
1079
|
-
* @param {
|
|
1091
|
+
* @param {ChunkSet | Chunk} chunks list of chunks
|
|
1080
1092
|
* @param {ChunkFilterFn} chunkFilter filter function for chunks
|
|
1081
1093
|
* @returns {SelectedChunksResult} list and key
|
|
1082
1094
|
*/
|
|
@@ -1269,7 +1281,7 @@ module.exports = class SplitChunksPlugin {
|
|
|
1269
1281
|
const getCombsByUsedExports = memoize(() => {
|
|
1270
1282
|
// fill the groupedByExportsMap
|
|
1271
1283
|
getExportsChunkSetsInGraph();
|
|
1272
|
-
/** @type {Set<
|
|
1284
|
+
/** @type {Set<ChunkSet | Chunk>} */
|
|
1273
1285
|
const set = new Set();
|
|
1274
1286
|
const groupedByUsedExports =
|
|
1275
1287
|
/** @type {Iterable<Chunk[]>} */
|
|
@@ -1703,7 +1715,9 @@ module.exports = class SplitChunksPlugin {
|
|
|
1703
1715
|
if (Object.keys(maxSize).length === 0) {
|
|
1704
1716
|
continue;
|
|
1705
1717
|
}
|
|
1706
|
-
for (const key of
|
|
1718
|
+
for (const key of /** @type {SourceType[]} */ (
|
|
1719
|
+
Object.keys(maxSize)
|
|
1720
|
+
)) {
|
|
1707
1721
|
const maxSizeValue = maxSize[key];
|
|
1708
1722
|
const minSizeValue = minSize[key];
|
|
1709
1723
|
if (
|
|
@@ -82,7 +82,7 @@ const { SyncHook } = require("tapable");
|
|
|
82
82
|
/**
|
|
83
83
|
* @template T
|
|
84
84
|
* @template {T[keyof T]} V
|
|
85
|
-
* @typedef {({ [
|
|
85
|
+
* @typedef {({ [key in keyof Required<T>]: Required<T>[key] extends V ? key : never })[keyof T]} KeysOfTypes
|
|
86
86
|
*/
|
|
87
87
|
|
|
88
88
|
/** @typedef {Set<string>} UnhandledProperties */
|
|
@@ -13,6 +13,7 @@ const { first } = require("../util/SetHelpers");
|
|
|
13
13
|
/** @typedef {import("../Chunk").ChunkId} ChunkId */
|
|
14
14
|
/** @typedef {import("../ChunkGraph")} ChunkGraph */
|
|
15
15
|
/** @typedef {import("../Compilation")} Compilation */
|
|
16
|
+
/** @typedef {import("../Compilation").HashWithLengthFunction} HashWithLengthFunction */
|
|
16
17
|
/** @typedef {import("../TemplatedPathPlugin").TemplatePath} TemplatePath */
|
|
17
18
|
|
|
18
19
|
class GetChunkFilenameRuntimeModule extends RuntimeModule {
|
|
@@ -138,7 +139,7 @@ class GetChunkFilenameRuntimeModule extends RuntimeModule {
|
|
|
138
139
|
};
|
|
139
140
|
/**
|
|
140
141
|
* @param {string} value string
|
|
141
|
-
* @returns {
|
|
142
|
+
* @returns {HashWithLengthFunction} string to put in quotes with length
|
|
142
143
|
*/
|
|
143
144
|
const unquotedStringifyWithLength = (value) => (length) =>
|
|
144
145
|
unquotedStringify(`${value}`.slice(0, length));
|
|
@@ -230,7 +231,7 @@ class GetChunkFilenameRuntimeModule extends RuntimeModule {
|
|
|
230
231
|
|
|
231
232
|
/**
|
|
232
233
|
* @param {(chunk: Chunk) => string | number} fn function from chunk to value
|
|
233
|
-
* @returns {
|
|
234
|
+
* @returns {HashWithLengthFunction} function which generates code with static mapping of results of fn for including in quoted string for specific length
|
|
234
235
|
*/
|
|
235
236
|
const mapExprWithLength = (fn) => (length) =>
|
|
236
237
|
`" + ${createMap((c) => `${fn(c)}`.slice(0, length))} + "`;
|