webpack 5.97.1 → 5.99.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +345 -392
- package/lib/AsyncDependenciesBlock.js +3 -1
- package/lib/BannerPlugin.js +1 -1
- package/lib/Cache.js +9 -7
- package/lib/CacheFacade.js +5 -5
- package/lib/Chunk.js +2 -2
- package/lib/ChunkGraph.js +21 -16
- package/lib/ChunkTemplate.js +6 -6
- package/lib/CleanPlugin.js +10 -10
- package/lib/CodeGenerationResults.js +4 -3
- package/lib/CompatibilityPlugin.js +4 -1
- package/lib/Compilation.js +343 -167
- package/lib/Compiler.js +13 -18
- package/lib/ConditionalInitFragment.js +1 -1
- package/lib/ConstPlugin.js +5 -3
- package/lib/ContextModule.js +4 -2
- package/lib/ContextModuleFactory.js +3 -3
- package/lib/ContextReplacementPlugin.js +43 -16
- package/lib/DefinePlugin.js +25 -24
- package/lib/DelegatedModule.js +4 -2
- package/lib/DelegatedModuleFactoryPlugin.js +2 -1
- package/lib/Dependency.js +19 -13
- package/lib/DependencyTemplates.js +4 -3
- package/lib/DllModule.js +4 -2
- package/lib/DllModuleFactory.js +2 -2
- package/lib/DllReferencePlugin.js +2 -1
- package/lib/DynamicEntryPlugin.js +1 -1
- package/lib/EnvironmentPlugin.js +4 -2
- package/lib/ExportsInfo.js +72 -40
- package/lib/ExternalModule.js +14 -5
- package/lib/ExternalModuleFactoryPlugin.js +24 -12
- package/lib/FileSystemInfo.js +129 -94
- package/lib/FlagDependencyExportsPlugin.js +6 -4
- package/lib/FlagDependencyUsagePlugin.js +1 -1
- package/lib/Generator.js +29 -1
- package/lib/HookWebpackError.js +2 -2
- package/lib/HotModuleReplacementPlugin.js +3 -9
- package/lib/IgnoreErrorModuleFactory.js +2 -2
- package/lib/IgnorePlugin.js +0 -5
- package/lib/InitFragment.js +1 -1
- package/lib/LoaderOptionsPlugin.js +8 -5
- package/lib/MainTemplate.js +7 -7
- package/lib/Module.js +44 -21
- package/lib/ModuleBuildError.js +3 -1
- package/lib/ModuleDependencyError.js +4 -3
- package/lib/ModuleDependencyWarning.js +4 -3
- package/lib/ModuleFactory.js +9 -3
- package/lib/ModuleFilenameHelpers.js +21 -39
- package/lib/ModuleGraph.js +20 -14
- package/lib/ModuleGraphConnection.js +7 -13
- package/lib/ModuleNotFoundError.js +1 -1
- package/lib/ModuleParseError.js +2 -1
- package/lib/ModuleSourceTypesConstants.js +11 -0
- package/lib/ModuleTemplate.js +5 -5
- package/lib/ModuleTypeConstants.js +15 -0
- package/lib/MultiCompiler.js +4 -4
- package/lib/MultiStats.js +1 -1
- package/lib/NormalModule.js +101 -54
- package/lib/NormalModuleFactory.js +38 -33
- package/lib/NormalModuleReplacementPlugin.js +3 -2
- package/lib/NullFactory.js +2 -2
- package/lib/Parser.js +4 -3
- package/lib/ProgressPlugin.js +1 -2
- package/lib/RawModule.js +4 -2
- package/lib/RecordIdsPlugin.js +6 -2
- package/lib/RequestShortener.js +3 -1
- package/lib/ResolverFactory.js +12 -9
- package/lib/RuntimeModule.js +4 -2
- package/lib/RuntimeTemplate.js +2 -1
- package/lib/SelfModuleFactory.js +2 -2
- package/lib/SourceMapDevToolPlugin.js +0 -8
- package/lib/Template.js +6 -5
- package/lib/TemplatedPathPlugin.js +15 -12
- package/lib/WebpackOptionsApply.js +1 -1
- package/lib/asset/AssetGenerator.js +237 -170
- package/lib/asset/AssetModulesPlugin.js +52 -10
- package/lib/asset/AssetSourceGenerator.js +18 -0
- package/lib/asset/RawDataUrlModule.js +4 -2
- package/lib/buildChunkGraph.js +14 -4
- package/lib/cache/MemoryWithGcCachePlugin.js +6 -2
- package/lib/cache/PackFileCacheStrategy.js +137 -121
- package/lib/cache/ResolverCachePlugin.js +15 -7
- package/lib/cache/getLazyHashedEtag.js +4 -3
- package/lib/cli.js +23 -15
- package/lib/config/defaults.js +104 -28
- package/lib/config/normalization.js +14 -13
- package/lib/config/target.js +8 -8
- package/lib/container/ContainerEntryModule.js +4 -2
- package/lib/container/ContainerEntryModuleFactory.js +2 -2
- package/lib/container/FallbackModule.js +4 -2
- package/lib/container/FallbackModuleFactory.js +2 -2
- package/lib/container/RemoteModule.js +4 -2
- package/lib/container/options.js +5 -5
- package/lib/css/CssGenerator.js +71 -9
- package/lib/css/CssLoadingRuntimeModule.js +5 -2
- package/lib/css/CssModulesPlugin.js +41 -9
- package/lib/css/CssParser.js +37 -17
- package/lib/css/walkCssTokens.js +17 -17
- package/lib/debug/ProfilingPlugin.js +98 -38
- package/lib/dependencies/AMDDefineDependencyParserPlugin.js +10 -4
- package/lib/dependencies/AMDPlugin.js +5 -2
- package/lib/dependencies/AMDRequireArrayDependency.js +4 -3
- package/lib/dependencies/AMDRequireContextDependency.js +2 -1
- package/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js +15 -7
- package/lib/dependencies/AMDRuntimeModules.js +3 -1
- package/lib/dependencies/CommonJsExportRequireDependency.js +4 -5
- package/lib/dependencies/CommonJsExportsParserPlugin.js +3 -3
- package/lib/dependencies/CommonJsImportsParserPlugin.js +38 -7
- package/lib/dependencies/CommonJsRequireContextDependency.js +2 -1
- package/lib/dependencies/ContextDependencyHelpers.js +13 -6
- package/lib/dependencies/CssIcssExportDependency.js +15 -12
- package/lib/dependencies/CssIcssImportDependency.js +4 -1
- package/lib/dependencies/CssLocalIdentifierDependency.js +18 -15
- package/lib/dependencies/ExportsInfoDependency.js +6 -1
- package/lib/dependencies/HarmonyEvaluatedImportSpecifierDependency.js +5 -5
- package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +22 -15
- package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +23 -8
- package/lib/dependencies/HarmonyExportSpecifierDependency.js +2 -2
- package/lib/dependencies/HarmonyImportDependency.js +8 -6
- package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +19 -14
- package/lib/dependencies/HarmonyImportSpecifierDependency.js +5 -5
- package/lib/dependencies/ImportContextDependency.js +2 -1
- package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +8 -4
- package/lib/dependencies/JsonExportsDependency.js +49 -27
- package/lib/dependencies/LoaderPlugin.js +4 -14
- package/lib/dependencies/RequireContextDependency.js +2 -1
- package/lib/dependencies/RequireContextDependencyParserPlugin.js +6 -3
- package/lib/dependencies/RequireEnsureDependenciesBlock.js +3 -2
- package/lib/dependencies/RequireEnsureDependenciesBlockParserPlugin.js +11 -5
- package/lib/dependencies/RequireResolveContextDependency.js +1 -1
- package/lib/dependencies/WebAssemblyExportImportedDependency.js +1 -1
- package/lib/dependencies/WorkerDependency.js +6 -3
- package/lib/dependencies/WorkerPlugin.js +100 -41
- package/lib/esm/ModuleChunkFormatPlugin.js +5 -0
- package/lib/esm/ModuleChunkLoadingRuntimeModule.js +3 -2
- package/lib/hmr/HotModuleReplacement.runtime.js +1 -0
- package/lib/hmr/JavascriptHotModuleReplacement.runtime.js +1 -0
- package/lib/hmr/LazyCompilationPlugin.js +32 -24
- package/lib/hmr/lazyCompilationBackend.js +1 -1
- package/lib/ids/DeterministicModuleIdsPlugin.js +1 -1
- package/lib/ids/HashedModuleIdsPlugin.js +2 -1
- package/lib/ids/IdHelpers.js +15 -14
- package/lib/ids/SyncModuleIdsPlugin.js +9 -5
- package/lib/index.js +5 -5
- package/lib/javascript/BasicEvaluatedExpression.js +6 -6
- package/lib/javascript/JavascriptGenerator.js +11 -1
- package/lib/javascript/JavascriptModulesPlugin.js +54 -34
- package/lib/javascript/JavascriptParser.js +272 -188
- package/lib/javascript/JavascriptParserHelpers.js +10 -9
- package/lib/javascript/StartupHelpers.js +4 -1
- package/lib/json/JsonData.js +4 -4
- package/lib/json/JsonGenerator.js +54 -22
- package/lib/json/JsonModulesPlugin.js +16 -3
- package/lib/json/JsonParser.js +10 -4
- package/lib/library/AbstractLibraryPlugin.js +7 -3
- package/lib/library/AssignLibraryPlugin.js +29 -1
- package/lib/library/EnableLibraryPlugin.js +7 -10
- package/lib/library/ExportPropertyLibraryPlugin.js +4 -1
- package/lib/library/ModuleLibraryPlugin.js +121 -15
- package/lib/logging/Logger.js +2 -2
- package/lib/logging/createConsoleLogger.js +4 -4
- package/lib/node/NodeEnvironmentPlugin.js +6 -2
- package/lib/node/ReadFileCompileAsyncWasmPlugin.js +1 -2
- package/lib/node/ReadFileCompileWasmPlugin.js +1 -2
- package/lib/node/nodeConsole.js +3 -1
- package/lib/optimize/AggressiveSplittingPlugin.js +1 -1
- package/lib/optimize/ConcatenatedModule.js +19 -12
- package/lib/optimize/InnerGraph.js +3 -2
- package/lib/optimize/InnerGraphPlugin.js +13 -7
- package/lib/optimize/LimitChunkCountPlugin.js +20 -0
- package/lib/optimize/ModuleConcatenationPlugin.js +10 -7
- package/lib/optimize/RealContentHashPlugin.js +8 -4
- package/lib/optimize/SideEffectsFlagPlugin.js +4 -2
- package/lib/optimize/SplitChunksPlugin.js +90 -65
- package/lib/rules/BasicEffectRulePlugin.js +9 -1
- package/lib/rules/BasicMatcherRulePlugin.js +15 -4
- package/lib/rules/ObjectMatcherRulePlugin.js +12 -3
- package/lib/rules/RuleSetCompiler.js +25 -14
- package/lib/rules/UseEffectRulePlugin.js +47 -17
- package/lib/runtime/AutoPublicPathRuntimeModule.js +1 -1
- package/lib/runtime/GetChunkFilenameRuntimeModule.js +6 -6
- package/lib/schemes/HttpUriPlugin.js +38 -17
- package/lib/serialization/BinaryMiddleware.js +52 -19
- package/lib/serialization/FileMiddleware.js +78 -48
- package/lib/serialization/ObjectMiddleware.js +78 -29
- package/lib/serialization/PlainObjectSerializer.js +1 -1
- package/lib/serialization/Serializer.js +15 -10
- package/lib/serialization/SerializerMiddleware.js +80 -41
- package/lib/serialization/SingleItemMiddleware.js +10 -7
- package/lib/serialization/types.js +1 -1
- package/lib/sharing/ConsumeSharedModule.js +4 -2
- package/lib/sharing/ProvideSharedModule.js +4 -2
- package/lib/sharing/ProvideSharedModuleFactory.js +5 -3
- package/lib/sharing/utils.js +2 -2
- package/lib/stats/DefaultStatsFactoryPlugin.js +81 -79
- package/lib/stats/DefaultStatsPresetPlugin.js +43 -23
- package/lib/stats/DefaultStatsPrinterPlugin.js +85 -43
- package/lib/stats/StatsFactory.js +11 -11
- package/lib/stats/StatsPrinter.js +7 -7
- package/lib/util/ArrayHelpers.js +2 -4
- package/lib/util/ArrayQueue.js +1 -1
- package/lib/util/AsyncQueue.js +4 -4
- package/lib/util/IterableHelpers.js +1 -1
- package/lib/util/LazyBucketSortedSet.js +41 -23
- package/lib/util/LazySet.js +3 -2
- package/lib/util/MapHelpers.js +1 -1
- package/lib/util/ParallelismFactorCalculator.js +1 -1
- package/lib/util/Semaphore.js +3 -3
- package/lib/util/SetHelpers.js +1 -1
- package/lib/util/SortableSet.js +9 -7
- package/lib/util/TupleQueue.js +9 -8
- package/lib/util/TupleSet.js +2 -2
- package/lib/util/WeakTupleMap.js +12 -11
- package/lib/util/binarySearchBounds.js +2 -1
- package/lib/util/cleverMerge.js +84 -54
- package/lib/util/comparators.js +22 -21
- package/lib/util/compileBooleanMatcher.js +3 -3
- package/lib/util/concatenate.js +6 -4
- package/lib/util/create-schema-validation.js +4 -4
- package/lib/util/createHash.js +2 -2
- package/lib/util/deprecation.js +35 -33
- package/lib/util/deterministicGrouping.js +6 -6
- package/lib/util/findGraphRoots.js +1 -1
- package/lib/util/fs.js +39 -39
- package/lib/util/hash/wasm-hash.js +2 -2
- package/lib/util/identifier.js +15 -18
- package/lib/util/makeSerializable.js +1 -1
- package/lib/util/memoize.js +4 -1
- package/lib/util/objectToMap.js +3 -2
- package/lib/util/processAsyncTree.js +2 -2
- package/lib/util/propertyName.js +0 -1
- package/lib/util/registerExternalSerializer.js +15 -18
- package/lib/util/removeBOM.js +25 -0
- package/lib/util/runtime.js +34 -27
- package/lib/util/semver.js +18 -8
- package/lib/util/serialization.js +5 -16
- package/lib/util/smartGrouping.js +3 -3
- package/lib/validateSchema.js +4 -7
- package/lib/wasm/EnableWasmLoadingPlugin.js +2 -2
- package/lib/wasm-async/AsyncWasmLoadingRuntimeModule.js +3 -3
- package/lib/wasm-async/AsyncWebAssemblyGenerator.js +11 -0
- package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +10 -0
- package/lib/wasm-async/AsyncWebAssemblyModulesPlugin.js +2 -2
- package/lib/wasm-async/UniversalCompileAsyncWasmPlugin.js +4 -0
- package/lib/wasm-sync/WebAssemblyGenerator.js +28 -12
- package/lib/wasm-sync/WebAssemblyJavascriptGenerator.js +10 -0
- package/lib/wasm-sync/WebAssemblyModulesPlugin.js +2 -2
- package/lib/wasm-sync/WebAssemblyParser.js +9 -4
- package/lib/web/JsonpChunkLoadingRuntimeModule.js +4 -2
- package/lib/webworker/ImportScriptsChunkLoadingPlugin.js +3 -0
- package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +30 -25
- package/package.json +27 -26
- package/schemas/WebpackOptions.check.js +1 -1
- package/schemas/WebpackOptions.json +48 -13
- package/schemas/plugins/JsonModulesPluginGenerator.check.d.ts +7 -0
- package/schemas/plugins/JsonModulesPluginGenerator.check.js +6 -0
- package/schemas/plugins/JsonModulesPluginGenerator.json +11 -0
- package/schemas/plugins/JsonModulesPluginParser.check.js +1 -1
- package/schemas/plugins/JsonModulesPluginParser.json +4 -0
- package/schemas/plugins/SourceMapDevToolPlugin.json +2 -2
- package/types.d.ts +888 -583
- package/lib/library/ModernModuleLibraryPlugin.js +0 -144
package/lib/util/cleverMerge.js
CHANGED
@@ -5,9 +5,9 @@
|
|
5
5
|
|
6
6
|
"use strict";
|
7
7
|
|
8
|
-
/** @type {WeakMap<
|
8
|
+
/** @type {WeakMap<EXPECTED_OBJECT, WeakMap<EXPECTED_OBJECT, EXPECTED_OBJECT>>} */
|
9
9
|
const mergeCache = new WeakMap();
|
10
|
-
/** @type {WeakMap<
|
10
|
+
/** @type {WeakMap<EXPECTED_OBJECT, Map<string, Map<string | number | boolean, EXPECTED_OBJECT>>>} */
|
11
11
|
const setPropertyCache = new WeakMap();
|
12
12
|
const DELETE = Symbol("DELETE");
|
13
13
|
const DYNAMIC_INFO = Symbol("cleverMerge dynamic info");
|
@@ -44,14 +44,14 @@ const cachedCleverMerge = (first, second) => {
|
|
44
44
|
if (prevMerge !== undefined) return prevMerge;
|
45
45
|
const newMerge = _cleverMerge(first, second, true);
|
46
46
|
innerCache.set(second, newMerge);
|
47
|
-
return
|
47
|
+
return newMerge;
|
48
48
|
};
|
49
49
|
|
50
50
|
/**
|
51
51
|
* @template T
|
52
52
|
* @param {Partial<T>} obj object
|
53
53
|
* @param {string} property property
|
54
|
-
* @param {string|number|boolean} value assignment value
|
54
|
+
* @param {string | number | boolean} value assignment value
|
55
55
|
* @returns {T} new object
|
56
56
|
*/
|
57
57
|
const cachedSetProperty = (obj, property, value) => {
|
@@ -82,38 +82,45 @@ const cachedSetProperty = (obj, property, value) => {
|
|
82
82
|
return /** @type {T} */ (result);
|
83
83
|
};
|
84
84
|
|
85
|
-
/**
|
85
|
+
/**
|
86
|
+
* @template V
|
87
|
+
* @typedef {Map<string, V | undefined>} ByValues
|
88
|
+
*/
|
86
89
|
|
87
90
|
/**
|
88
91
|
* @typedef {object} ObjectParsedPropertyEntry
|
89
92
|
* @property {any | undefined} base base value
|
90
93
|
* @property {string | undefined} byProperty the name of the selector property
|
91
|
-
* @property {ByValues} byValues value depending on selector property, merged with base
|
94
|
+
* @property {ByValues<any>} byValues value depending on selector property, merged with base
|
92
95
|
*/
|
93
96
|
|
97
|
+
/** @typedef {(function(...EXPECTED_ANY): object) & { [DYNAMIC_INFO]: [DynamicFunction, object] }} DynamicFunction */
|
98
|
+
|
94
99
|
/**
|
95
100
|
* @typedef {object} ParsedObject
|
96
101
|
* @property {Map<string, ObjectParsedPropertyEntry>} static static properties (key is property name)
|
97
|
-
* @property {{ byProperty: string, fn:
|
102
|
+
* @property {{ byProperty: string, fn: DynamicFunction } | undefined} dynamic dynamic part
|
98
103
|
*/
|
99
104
|
|
100
|
-
/** @type {WeakMap<
|
105
|
+
/** @type {WeakMap<EXPECTED_OBJECT, ParsedObject>} */
|
101
106
|
const parseCache = new WeakMap();
|
102
107
|
|
103
108
|
/**
|
104
|
-
* @
|
109
|
+
* @template {object} T
|
110
|
+
* @param {T} obj the object
|
105
111
|
* @returns {ParsedObject} parsed object
|
106
112
|
*/
|
107
113
|
const cachedParseObject = obj => {
|
108
|
-
const entry = parseCache.get(obj);
|
114
|
+
const entry = parseCache.get(/** @type {EXPECTED_OBJECT} */ (obj));
|
109
115
|
if (entry !== undefined) return entry;
|
110
116
|
const result = parseObject(obj);
|
111
|
-
parseCache.set(obj, result);
|
117
|
+
parseCache.set(/** @type {EXPECTED_OBJECT} */ (obj), result);
|
112
118
|
return result;
|
113
119
|
};
|
114
120
|
|
115
121
|
/**
|
116
122
|
* @template {object} T
|
123
|
+
* @template V
|
117
124
|
* @param {T} obj the object
|
118
125
|
* @returns {ParsedObject} parsed object
|
119
126
|
*/
|
@@ -138,7 +145,7 @@ const parseObject = obj => {
|
|
138
145
|
for (const key of Object.keys(obj)) {
|
139
146
|
if (key.startsWith("by")) {
|
140
147
|
const byProperty = /** @type {keyof T} */ (key);
|
141
|
-
const byObj = /** @type {
|
148
|
+
const byObj = /** @type {TODO} */ (obj[byProperty]);
|
142
149
|
if (typeof byObj === "object") {
|
143
150
|
for (const byValue of Object.keys(byObj)) {
|
144
151
|
const obj = byObj[/** @type {keyof (keyof T)} */ (byValue)];
|
@@ -152,7 +159,7 @@ const parseObject = obj => {
|
|
152
159
|
`${/** @type {string} */ (byProperty)} and ${entry.byProperty} for a single property is not supported`
|
153
160
|
);
|
154
161
|
}
|
155
|
-
/** @type {ByValues} */
|
162
|
+
/** @type {ByValues<V>} */
|
156
163
|
(entry.byValues).set(
|
157
164
|
byValue,
|
158
165
|
obj[/** @type {keyof (keyof T)} */ (key)]
|
@@ -160,9 +167,12 @@ const parseObject = obj => {
|
|
160
167
|
if (byValue === "default") {
|
161
168
|
for (const otherByValue of Object.keys(byObj)) {
|
162
169
|
if (
|
163
|
-
!(
|
170
|
+
!(
|
171
|
+
/** @type {ByValues<V>} */
|
172
|
+
(entry.byValues).has(otherByValue)
|
173
|
+
)
|
164
174
|
)
|
165
|
-
/** @type {ByValues} */
|
175
|
+
/** @type {ByValues<V>} */
|
166
176
|
(entry.byValues).set(otherByValue, undefined);
|
167
177
|
}
|
168
178
|
}
|
@@ -197,7 +207,7 @@ const parseObject = obj => {
|
|
197
207
|
/**
|
198
208
|
* @template {object} T
|
199
209
|
* @param {Map<string, ObjectParsedPropertyEntry>} info static properties (key is property name)
|
200
|
-
* @param {{ byProperty: string, fn:
|
210
|
+
* @param {{ byProperty: string, fn: (...args: EXPECTED_ANY[]) => T } | undefined} dynamicInfo dynamic part
|
201
211
|
* @returns {T} the object
|
202
212
|
*/
|
203
213
|
const serializeObject = (info, dynamicInfo) => {
|
@@ -205,7 +215,9 @@ const serializeObject = (info, dynamicInfo) => {
|
|
205
215
|
// Setup byProperty structure
|
206
216
|
for (const entry of info.values()) {
|
207
217
|
if (entry.byProperty !== undefined) {
|
208
|
-
const
|
218
|
+
const byProperty = /** @type {keyof T} */ (entry.byProperty);
|
219
|
+
const byObj = (obj[byProperty] =
|
220
|
+
obj[byProperty] || /** @type {TODO} */ ({}));
|
209
221
|
for (const byValue of entry.byValues.keys()) {
|
210
222
|
byObj[byValue] = byObj[byValue] || {};
|
211
223
|
}
|
@@ -217,7 +229,9 @@ const serializeObject = (info, dynamicInfo) => {
|
|
217
229
|
}
|
218
230
|
// Fill byProperty structure
|
219
231
|
if (entry.byProperty !== undefined) {
|
220
|
-
const
|
232
|
+
const byProperty = /** @type {keyof T} */ (entry.byProperty);
|
233
|
+
const byObj = (obj[byProperty] =
|
234
|
+
obj[byProperty] || /** @type {TODO} */ ({}));
|
221
235
|
for (const byValue of Object.keys(byObj)) {
|
222
236
|
const value = getFromByValues(entry.byValues, byValue);
|
223
237
|
if (value !== undefined) byObj[byValue][key] = value;
|
@@ -225,7 +239,8 @@ const serializeObject = (info, dynamicInfo) => {
|
|
225
239
|
}
|
226
240
|
}
|
227
241
|
if (dynamicInfo !== undefined) {
|
228
|
-
|
242
|
+
/** @type {TODO} */
|
243
|
+
(obj)[dynamicInfo.byProperty] = dynamicInfo.fn;
|
229
244
|
}
|
230
245
|
return obj;
|
231
246
|
};
|
@@ -237,7 +252,8 @@ const VALUE_TYPE_OBJECT = 3;
|
|
237
252
|
const VALUE_TYPE_DELETE = 4;
|
238
253
|
|
239
254
|
/**
|
240
|
-
* @
|
255
|
+
* @template T
|
256
|
+
* @param {T} value a single value
|
241
257
|
* @returns {VALUE_TYPE_UNDEFINED | VALUE_TYPE_ATOM | VALUE_TYPE_ARRAY_EXTEND | VALUE_TYPE_OBJECT | VALUE_TYPE_DELETE} value type
|
242
258
|
*/
|
243
259
|
const getValueType = value => {
|
@@ -278,11 +294,13 @@ const cleverMerge = (first, second) => {
|
|
278
294
|
};
|
279
295
|
|
280
296
|
/**
|
297
|
+
* @template {object} T
|
298
|
+
* @template {object} O
|
281
299
|
* Merges two objects. Objects are deeply clever merged.
|
282
|
-
* @param {
|
283
|
-
* @param {
|
300
|
+
* @param {T} first first
|
301
|
+
* @param {O} second second
|
284
302
|
* @param {boolean} internalCaching should parsing of objects and nested merges be cached
|
285
|
-
* @returns {
|
303
|
+
* @returns {T & O} merged object of first and second object
|
286
304
|
*/
|
287
305
|
const _cleverMerge = (first, second, internalCaching = false) => {
|
288
306
|
const firstObject = internalCaching
|
@@ -295,11 +313,16 @@ const _cleverMerge = (first, second, internalCaching = false) => {
|
|
295
313
|
let { byProperty, fn } = firstDynamicInfo;
|
296
314
|
const fnInfo = fn[DYNAMIC_INFO];
|
297
315
|
if (fnInfo) {
|
298
|
-
second =
|
299
|
-
|
300
|
-
|
316
|
+
second =
|
317
|
+
/** @type {TODO} */
|
318
|
+
(
|
319
|
+
internalCaching
|
320
|
+
? cachedCleverMerge(fnInfo[1], second)
|
321
|
+
: cleverMerge(fnInfo[1], second)
|
322
|
+
);
|
301
323
|
fn = fnInfo[0];
|
302
324
|
}
|
325
|
+
/** @type {DynamicFunction} */
|
303
326
|
const newFn = (...args) => {
|
304
327
|
const fnResult = fn(...args);
|
305
328
|
return internalCaching
|
@@ -307,7 +330,9 @@ const _cleverMerge = (first, second, internalCaching = false) => {
|
|
307
330
|
: cleverMerge(fnResult, second);
|
308
331
|
};
|
309
332
|
newFn[DYNAMIC_INFO] = [fn, second];
|
310
|
-
return
|
333
|
+
return /** @type {T & O} */ (
|
334
|
+
serializeObject(firstObject.static, { byProperty, fn: newFn })
|
335
|
+
);
|
311
336
|
}
|
312
337
|
|
313
338
|
// If the first part is static only, we merge the static parts and keep the dynamic part of the second argument
|
@@ -330,7 +355,7 @@ const _cleverMerge = (first, second, internalCaching = false) => {
|
|
330
355
|
resultInfo.set(key, secondEntry);
|
331
356
|
}
|
332
357
|
}
|
333
|
-
return serializeObject(resultInfo, secondDynamicInfo);
|
358
|
+
return /** @type {T & O} */ (serializeObject(resultInfo, secondDynamicInfo));
|
334
359
|
};
|
335
360
|
|
336
361
|
/**
|
@@ -446,9 +471,10 @@ const mergeEntries = (firstEntry, secondEntry, internalCaching) => {
|
|
446
471
|
};
|
447
472
|
|
448
473
|
/**
|
449
|
-
* @
|
474
|
+
* @template V
|
475
|
+
* @param {ByValues<V>} byValues all values
|
450
476
|
* @param {string} key value of the selector
|
451
|
-
* @returns {
|
477
|
+
* @returns {V | undefined} value
|
452
478
|
*/
|
453
479
|
const getFromByValues = (byValues, key) => {
|
454
480
|
if (key !== "default" && byValues.has(key)) {
|
@@ -458,10 +484,12 @@ const getFromByValues = (byValues, key) => {
|
|
458
484
|
};
|
459
485
|
|
460
486
|
/**
|
461
|
-
* @
|
462
|
-
* @
|
487
|
+
* @template A
|
488
|
+
* @template B
|
489
|
+
* @param {A | A[]} a value
|
490
|
+
* @param {B | B[]} b value
|
463
491
|
* @param {boolean} internalCaching should parsing of objects and nested merges be cached
|
464
|
-
* @returns {
|
492
|
+
* @returns {A & B | (A | B)[] | A | A[] | B | B[]} value
|
465
493
|
*/
|
466
494
|
const mergeSingleValue = (a, b, internalCaching) => {
|
467
495
|
const bType = getValueType(b);
|
@@ -490,12 +518,13 @@ const mergeSingleValue = (a, b, internalCaching) => {
|
|
490
518
|
case VALUE_TYPE_UNDEFINED:
|
491
519
|
return b;
|
492
520
|
case VALUE_TYPE_DELETE:
|
493
|
-
return /** @type {
|
521
|
+
return /** @type {B[]} */ (b).filter(item => item !== "...");
|
494
522
|
case VALUE_TYPE_ARRAY_EXTEND: {
|
523
|
+
/** @type {(A | B)[]} */
|
495
524
|
const newArray = [];
|
496
|
-
for (const item of b) {
|
525
|
+
for (const item of /** @type {B[]} */ (b)) {
|
497
526
|
if (item === "...") {
|
498
|
-
for (const item of a) {
|
527
|
+
for (const item of /** @type {A[]} */ (a)) {
|
499
528
|
newArray.push(item);
|
500
529
|
}
|
501
530
|
} else {
|
@@ -505,8 +534,8 @@ const mergeSingleValue = (a, b, internalCaching) => {
|
|
505
534
|
return newArray;
|
506
535
|
}
|
507
536
|
case VALUE_TYPE_OBJECT:
|
508
|
-
return /** @type {
|
509
|
-
item === "..." ? a : item
|
537
|
+
return /** @type {(A | B)[]} */ (b).map(item =>
|
538
|
+
item === "..." ? /** @type {A} */ (a) : item
|
510
539
|
);
|
511
540
|
default:
|
512
541
|
throw new Error("Not implemented");
|
@@ -524,14 +553,12 @@ const mergeSingleValue = (a, b, internalCaching) => {
|
|
524
553
|
*/
|
525
554
|
const removeOperations = (obj, keysToKeepOriginalValue = []) => {
|
526
555
|
const newObj = /** @type {T} */ ({});
|
527
|
-
for (const
|
528
|
-
const
|
556
|
+
for (const _key of Object.keys(obj)) {
|
557
|
+
const key = /** @type {keyof T} */ (_key);
|
558
|
+
const value = obj[key];
|
529
559
|
const type = getValueType(value);
|
530
|
-
if (
|
531
|
-
|
532
|
-
keysToKeepOriginalValue.includes(/** @type {keyof T} */ (key))
|
533
|
-
) {
|
534
|
-
newObj[/** @type {keyof T} */ (key)] = value;
|
560
|
+
if (type === VALUE_TYPE_OBJECT && keysToKeepOriginalValue.includes(key)) {
|
561
|
+
newObj[key] = value;
|
535
562
|
continue;
|
536
563
|
}
|
537
564
|
switch (type) {
|
@@ -539,25 +566,26 @@ const removeOperations = (obj, keysToKeepOriginalValue = []) => {
|
|
539
566
|
case VALUE_TYPE_DELETE:
|
540
567
|
break;
|
541
568
|
case VALUE_TYPE_OBJECT:
|
542
|
-
newObj[
|
569
|
+
newObj[key] =
|
543
570
|
/** @type {T[keyof T]} */
|
544
571
|
(
|
545
572
|
removeOperations(
|
546
|
-
/** @type {
|
573
|
+
/** @type {T} */
|
574
|
+
(value),
|
547
575
|
keysToKeepOriginalValue
|
548
576
|
)
|
549
577
|
);
|
550
578
|
break;
|
551
579
|
case VALUE_TYPE_ARRAY_EXTEND:
|
552
|
-
newObj[
|
580
|
+
newObj[key] =
|
553
581
|
/** @type {T[keyof T]} */
|
554
582
|
(
|
555
|
-
/** @type {
|
583
|
+
/** @type {EXPECTED_ANY[]} */
|
556
584
|
(value).filter(i => i !== "...")
|
557
585
|
);
|
558
586
|
break;
|
559
587
|
default:
|
560
|
-
newObj[
|
588
|
+
newObj[key] = value;
|
561
589
|
break;
|
562
590
|
}
|
563
591
|
}
|
@@ -566,10 +594,11 @@ const removeOperations = (obj, keysToKeepOriginalValue = []) => {
|
|
566
594
|
|
567
595
|
/**
|
568
596
|
* @template T
|
569
|
-
* @template {
|
597
|
+
* @template {keyof T} P
|
598
|
+
* @template V
|
570
599
|
* @param {T} obj the object
|
571
600
|
* @param {P} byProperty the by description
|
572
|
-
* @param
|
601
|
+
* @param {...V} values values
|
573
602
|
* @returns {Omit<T, P>} object with merged byProperty
|
574
603
|
*/
|
575
604
|
const resolveByProperty = (obj, byProperty, ...values) => {
|
@@ -579,10 +608,10 @@ const resolveByProperty = (obj, byProperty, ...values) => {
|
|
579
608
|
const { [byProperty]: _byValue, ..._remaining } = obj;
|
580
609
|
const remaining = /** @type {T} */ (_remaining);
|
581
610
|
const byValue =
|
582
|
-
/** @type {Record<string, T> |
|
611
|
+
/** @type {Record<string, T> | ((...args: V[]) => T)} */
|
583
612
|
(_byValue);
|
584
613
|
if (typeof byValue === "object") {
|
585
|
-
const key = values[0];
|
614
|
+
const key = /** @type {string} */ (values[0]);
|
586
615
|
if (key in byValue) {
|
587
616
|
return cachedCleverMerge(remaining, byValue[key]);
|
588
617
|
} else if ("default" in byValue) {
|
@@ -597,6 +626,7 @@ const resolveByProperty = (obj, byProperty, ...values) => {
|
|
597
626
|
resolveByProperty(result, byProperty, ...values)
|
598
627
|
);
|
599
628
|
}
|
629
|
+
return obj;
|
600
630
|
};
|
601
631
|
|
602
632
|
module.exports.cachedSetProperty = cachedSetProperty;
|
package/lib/util/comparators.js
CHANGED
@@ -18,29 +18,30 @@ const { compareRuntime } = require("./runtime");
|
|
18
18
|
|
19
19
|
/**
|
20
20
|
* @template T
|
21
|
-
* @typedef {
|
21
|
+
* @typedef {(a: T, b: T) => -1 | 0 | 1} Comparator
|
22
22
|
*/
|
23
23
|
/**
|
24
|
-
* @template TArg
|
24
|
+
* @template {object} TArg
|
25
25
|
* @template T
|
26
|
-
* @typedef {
|
26
|
+
* @typedef {(tArg: TArg, a: T, b: T) => -1 | 0 | 1} RawParameterizedComparator
|
27
27
|
*/
|
28
28
|
/**
|
29
|
-
* @template TArg
|
29
|
+
* @template {object} TArg
|
30
30
|
* @template T
|
31
|
-
* @typedef {
|
31
|
+
* @typedef {(tArg: TArg) => Comparator<T>} ParameterizedComparator
|
32
32
|
*/
|
33
33
|
|
34
34
|
/**
|
35
|
-
* @template
|
36
|
-
* @
|
37
|
-
* @
|
35
|
+
* @template {object} TArg
|
36
|
+
* @template {object} T
|
37
|
+
* @param {RawParameterizedComparator<TArg, T>} fn comparator with argument
|
38
|
+
* @returns {ParameterizedComparator<TArg, T>} comparator
|
38
39
|
*/
|
39
40
|
const createCachedParameterizedComparator = fn => {
|
40
|
-
/** @type {WeakMap<
|
41
|
+
/** @type {WeakMap<EXPECTED_OBJECT, Comparator<T>>} */
|
41
42
|
const map = new WeakMap();
|
42
43
|
return arg => {
|
43
|
-
const cachedResult = map.get(arg);
|
44
|
+
const cachedResult = map.get(/** @type {EXPECTED_OBJECT} */ (arg));
|
44
45
|
if (cachedResult !== undefined) return cachedResult;
|
45
46
|
/**
|
46
47
|
* @param {T} a first item
|
@@ -48,7 +49,7 @@ const createCachedParameterizedComparator = fn => {
|
|
48
49
|
* @returns {-1|0|1} compare result
|
49
50
|
*/
|
50
51
|
const result = fn.bind(null, arg);
|
51
|
-
map.set(arg, result);
|
52
|
+
map.set(/** @type {EXPECTED_OBJECT} */ (arg), result);
|
52
53
|
return result;
|
53
54
|
};
|
54
55
|
};
|
@@ -233,7 +234,7 @@ module.exports.compareModulesByIdOrIdentifier =
|
|
233
234
|
* @param {ChunkGraph} chunkGraph the chunk graph
|
234
235
|
* @param {Chunk} a chunk
|
235
236
|
* @param {Chunk} b chunk
|
236
|
-
* @returns {-1|0|1} compare result
|
237
|
+
* @returns {-1 | 0 | 1} compare result
|
237
238
|
*/
|
238
239
|
const compareChunks = (chunkGraph, a, b) => chunkGraph.compareChunks(a, b);
|
239
240
|
/** @type {ParameterizedComparator<ChunkGraph, Chunk>} */
|
@@ -241,9 +242,9 @@ module.exports.compareChunks =
|
|
241
242
|
createCachedParameterizedComparator(compareChunks);
|
242
243
|
|
243
244
|
/**
|
244
|
-
* @param {string|number} a first id
|
245
|
-
* @param {string|number} b second id
|
246
|
-
* @returns {-1|0|1} compare result
|
245
|
+
* @param {string | number} a first id
|
246
|
+
* @param {string | number} b second id
|
247
|
+
* @returns {-1 | 0 | 1} compare result
|
247
248
|
*/
|
248
249
|
const compareIds = (a, b) => {
|
249
250
|
if (typeof a !== typeof b) {
|
@@ -272,22 +273,22 @@ module.exports.compareStrings = compareStrings;
|
|
272
273
|
/**
|
273
274
|
* @param {ChunkGroup} a first chunk group
|
274
275
|
* @param {ChunkGroup} b second chunk group
|
275
|
-
* @returns {-1|0|1} compare result
|
276
|
+
* @returns {-1 | 0 | 1} compare result
|
276
277
|
*/
|
277
278
|
const compareChunkGroupsByIndex = (a, b) =>
|
278
279
|
/** @type {number} */ (a.index) < /** @type {number} */ (b.index) ? -1 : 1;
|
279
280
|
module.exports.compareChunkGroupsByIndex = compareChunkGroupsByIndex;
|
280
281
|
|
281
282
|
/**
|
282
|
-
* @template
|
283
|
-
* @template K2
|
283
|
+
* @template {EXPECTED_OBJECT} K1
|
284
|
+
* @template {EXPECTED_OBJECT} K2
|
284
285
|
* @template T
|
285
286
|
*/
|
286
287
|
class TwoKeyWeakMap {
|
287
288
|
constructor() {
|
288
289
|
/**
|
289
290
|
* @private
|
290
|
-
* @type {WeakMap<
|
291
|
+
* @type {WeakMap<K1, WeakMap<K2, T | undefined>>}
|
291
292
|
*/
|
292
293
|
this._map = new WeakMap();
|
293
294
|
}
|
@@ -321,7 +322,7 @@ class TwoKeyWeakMap {
|
|
321
322
|
}
|
322
323
|
}
|
323
324
|
|
324
|
-
/** @type {TwoKeyWeakMap<Comparator<
|
325
|
+
/** @type {TwoKeyWeakMap<Comparator<EXPECTED_ANY>, Comparator<EXPECTED_ANY>, Comparator<EXPECTED_ANY>>}} */
|
325
326
|
const concatComparatorsCache = new TwoKeyWeakMap();
|
326
327
|
|
327
328
|
/**
|
@@ -397,7 +398,7 @@ const compareSelect = (getter, comparator) => {
|
|
397
398
|
};
|
398
399
|
module.exports.compareSelect = compareSelect;
|
399
400
|
|
400
|
-
/** @type {WeakMap<Comparator<
|
401
|
+
/** @type {WeakMap<Comparator<EXPECTED_ANY>, Comparator<Iterable<EXPECTED_ANY>>>} */
|
401
402
|
const compareIteratorsCache = new WeakMap();
|
402
403
|
|
403
404
|
/**
|
@@ -23,8 +23,8 @@ const toSimpleString = str => {
|
|
23
23
|
};
|
24
24
|
|
25
25
|
/**
|
26
|
-
* @param {Record<string|number, boolean>} map value map
|
27
|
-
* @returns {boolean|(
|
26
|
+
* @param {Record<string | number, boolean>} map value map
|
27
|
+
* @returns {boolean | ((value: string) => string)} true/false, when unconditionally true/false, or a template function to determine the value at runtime
|
28
28
|
*/
|
29
29
|
const compileBooleanMatcher = map => {
|
30
30
|
const positiveItems = Object.keys(map).filter(i => map[i]);
|
@@ -37,7 +37,7 @@ const compileBooleanMatcher = map => {
|
|
37
37
|
/**
|
38
38
|
* @param {string[]} positiveItems positive items
|
39
39
|
* @param {string[]} negativeItems negative items
|
40
|
-
* @returns {
|
40
|
+
* @returns {(value: string) => string} a template function to determine the value at runtime
|
41
41
|
*/
|
42
42
|
const compileBooleanMatcherFromLists = (positiveItems, negativeItems) => {
|
43
43
|
if (positiveItems.length === 0) return () => "false";
|
package/lib/util/concatenate.js
CHANGED
@@ -139,11 +139,13 @@ function findNewName(oldName, usedNamed1, usedNamed2, extraInfo) {
|
|
139
139
|
return nameWithNumber;
|
140
140
|
}
|
141
141
|
|
142
|
+
/** @typedef {Set<Scope>} ScopeSet */
|
143
|
+
|
142
144
|
/**
|
143
145
|
* @param {Scope | null} s scope
|
144
146
|
* @param {UsedNames} nameSet name set
|
145
|
-
* @param {
|
146
|
-
* @param {
|
147
|
+
* @param {ScopeSet} scopeSet1 scope set 1
|
148
|
+
* @param {ScopeSet} scopeSet2 scope set 2
|
147
149
|
*/
|
148
150
|
const addScopeSymbols = (s, nameSet, scopeSet1, scopeSet2) => {
|
149
151
|
let scope = s;
|
@@ -197,10 +199,10 @@ const RESERVED_NAMES = new Set(
|
|
197
199
|
);
|
198
200
|
|
199
201
|
/**
|
200
|
-
* @param {Map<string, { usedNames: UsedNames, alreadyCheckedScopes:
|
202
|
+
* @param {Map<string, { usedNames: UsedNames, alreadyCheckedScopes: ScopeSet }>} usedNamesInScopeInfo used names in scope info
|
201
203
|
* @param {string} module module identifier
|
202
204
|
* @param {string} id export id
|
203
|
-
* @returns {{ usedNames: UsedNames, alreadyCheckedScopes:
|
205
|
+
* @returns {{ usedNames: UsedNames, alreadyCheckedScopes: ScopeSet }} info
|
204
206
|
*/
|
205
207
|
const getUsedNamesInScopeInfo = (usedNamesInScopeInfo, module, id) => {
|
206
208
|
const key = `${module}-${id}`;
|
@@ -14,18 +14,18 @@ const getValidate = memoize(() => require("schema-utils").validate);
|
|
14
14
|
|
15
15
|
/**
|
16
16
|
* @template {object | object[]} T
|
17
|
-
* @param {(
|
17
|
+
* @param {((value: T) => boolean) | undefined} check check
|
18
18
|
* @param {() => JsonObject} getSchema get schema fn
|
19
19
|
* @param {ValidationErrorConfiguration} options options
|
20
|
-
* @returns {
|
20
|
+
* @returns {(value?: T) => void} validate
|
21
21
|
*/
|
22
22
|
const createSchemaValidation = (check, getSchema, options) => {
|
23
23
|
getSchema = memoize(getSchema);
|
24
24
|
return value => {
|
25
|
-
if (check && !check(
|
25
|
+
if (check && value && !check(value)) {
|
26
26
|
getValidate()(
|
27
27
|
getSchema(),
|
28
|
-
/** @type {
|
28
|
+
/** @type {EXPECTED_OBJECT | EXPECTED_OBJECT[]} */
|
29
29
|
(value),
|
30
30
|
options
|
31
31
|
);
|
package/lib/util/createHash.js
CHANGED
@@ -14,12 +14,12 @@ const BULK_SIZE = 2000;
|
|
14
14
|
/** @type {{[key: string]: Map<string, string>}} */
|
15
15
|
const digestCaches = {};
|
16
16
|
|
17
|
-
/** @typedef {
|
17
|
+
/** @typedef {() => Hash} HashFactory */
|
18
18
|
|
19
19
|
class BulkUpdateDecorator extends Hash {
|
20
20
|
/**
|
21
21
|
* @param {Hash | HashFactory} hashOrFactory function to create a hash
|
22
|
-
* @param {string
|
22
|
+
* @param {string} [hashKey] key for caching
|
23
23
|
*/
|
24
24
|
constructor(hashOrFactory, hashKey) {
|
25
25
|
super();
|