webpack 5.90.3 → 5.91.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of webpack might be problematic. Click here for more details.
- package/README.md +5 -5
- package/bin/webpack.js +5 -1
- package/lib/APIPlugin.js +8 -4
- package/lib/AutomaticPrefetchPlugin.js +1 -1
- package/lib/BannerPlugin.js +3 -1
- package/lib/Cache.js +7 -1
- package/lib/CacheFacade.js +3 -3
- package/lib/ChunkGraph.js +32 -18
- package/lib/ChunkGroup.js +14 -14
- package/lib/CleanPlugin.js +7 -5
- package/lib/Compilation.js +262 -93
- package/lib/Compiler.js +199 -83
- package/lib/ConditionalInitFragment.js +4 -5
- package/lib/ContextModule.js +2 -0
- package/lib/ContextModuleFactory.js +4 -2
- package/lib/ContextReplacementPlugin.js +3 -2
- package/lib/DefinePlugin.js +4 -2
- package/lib/Dependency.js +4 -2
- package/lib/DependencyTemplate.js +7 -2
- package/lib/DllModule.js +1 -0
- package/lib/DllReferencePlugin.js +6 -2
- package/lib/EntryOptionPlugin.js +4 -1
- package/lib/EntryPlugin.js +6 -1
- package/lib/Entrypoint.js +1 -1
- package/lib/ExportsInfo.js +1 -4
- package/lib/ExternalModule.js +118 -24
- package/lib/ExternalModuleFactoryPlugin.js +37 -2
- package/lib/FileSystemInfo.js +1 -1
- package/lib/Generator.js +2 -1
- package/lib/HookWebpackError.js +2 -2
- package/lib/InitFragment.js +5 -3
- package/lib/LibManifestPlugin.js +15 -7
- package/lib/Module.js +30 -2
- package/lib/ModuleFilenameHelpers.js +1 -1
- package/lib/ModuleGraph.js +56 -27
- package/lib/ModuleGraphConnection.js +2 -1
- package/lib/MultiCompiler.js +26 -8
- package/lib/NodeStuffPlugin.js +14 -3
- package/lib/NormalModule.js +3 -1
- package/lib/NormalModuleFactory.js +1 -1
- package/lib/NormalModuleReplacementPlugin.js +5 -1
- package/lib/ProvidePlugin.js +3 -1
- package/lib/RawModule.js +2 -1
- package/lib/ResolverFactory.js +3 -1
- package/lib/RuntimeModule.js +4 -4
- package/lib/RuntimePlugin.js +1 -0
- package/lib/RuntimeTemplate.js +102 -34
- package/lib/SourceMapDevToolPlugin.js +4 -1
- package/lib/Stats.js +10 -3
- package/lib/TemplatedPathPlugin.js +32 -6
- package/lib/Watching.js +67 -60
- package/lib/WebpackError.js +6 -6
- package/lib/WebpackOptionsApply.js +18 -5
- package/lib/asset/RawDataUrlModule.js +3 -1
- package/lib/async-modules/AwaitDependenciesInitFragment.js +2 -2
- package/lib/buildChunkGraph.js +117 -64
- package/lib/cache/IdleFileCachePlugin.js +8 -3
- package/lib/cache/MemoryCachePlugin.js +1 -1
- package/lib/cache/MemoryWithGcCachePlugin.js +6 -2
- package/lib/cache/PackFileCacheStrategy.js +49 -16
- package/lib/cache/ResolverCachePlugin.js +14 -6
- package/lib/cache/getLazyHashedEtag.js +1 -1
- package/lib/config/defaults.js +24 -1
- package/lib/config/normalization.js +3 -1
- package/lib/container/ContainerEntryDependency.js +2 -1
- package/lib/container/ContainerEntryModule.js +3 -1
- package/lib/container/ContainerPlugin.js +14 -10
- package/lib/container/FallbackModule.js +1 -1
- package/lib/container/RemoteRuntimeModule.js +12 -3
- package/lib/css/CssExportsGenerator.js +34 -17
- package/lib/css/CssGenerator.js +20 -2
- package/lib/css/CssLoadingRuntimeModule.js +212 -96
- package/lib/css/CssModulesPlugin.js +47 -13
- package/lib/debug/ProfilingPlugin.js +27 -2
- package/lib/dependencies/AMDDefineDependencyParserPlugin.js +9 -5
- package/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js +4 -1
- package/lib/dependencies/CommonJsDependencyHelpers.js +2 -1
- package/lib/dependencies/CommonJsExportRequireDependency.js +33 -18
- package/lib/dependencies/CommonJsExportsDependency.js +13 -5
- package/lib/dependencies/CommonJsExportsParserPlugin.js +20 -15
- package/lib/dependencies/CommonJsImportsParserPlugin.js +1 -2
- package/lib/dependencies/ContextDependencyHelpers.js +49 -29
- package/lib/dependencies/ContextElementDependency.js +8 -1
- package/lib/dependencies/CssLocalIdentifierDependency.js +63 -8
- package/lib/dependencies/CssUrlDependency.js +5 -3
- package/lib/dependencies/ExportsInfoDependency.js +4 -3
- package/lib/dependencies/ExternalModuleInitFragment.js +5 -3
- package/lib/dependencies/HarmonyEvaluatedImportSpecifierDependency.js +4 -4
- package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +43 -23
- package/lib/dependencies/HarmonyExportHeaderDependency.js +1 -1
- package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +73 -32
- package/lib/dependencies/HarmonyExportInitFragment.js +10 -2
- package/lib/dependencies/HarmonyImportDependency.js +28 -12
- package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +44 -16
- package/lib/dependencies/HarmonyImportSideEffectDependency.js +7 -6
- package/lib/dependencies/HarmonyImportSpecifierDependency.js +6 -5
- package/lib/dependencies/ImportDependency.js +9 -2
- package/lib/dependencies/ImportEagerDependency.js +4 -2
- package/lib/dependencies/ImportMetaContextDependency.js +7 -0
- package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +25 -14
- package/lib/dependencies/ImportParserPlugin.js +12 -4
- package/lib/dependencies/ImportWeakDependency.js +4 -2
- package/lib/dependencies/LoaderDependency.js +2 -1
- package/lib/dependencies/LoaderImportDependency.js +2 -1
- package/lib/dependencies/ModuleDependency.js +4 -5
- package/lib/dependencies/PureExpressionDependency.js +4 -1
- package/lib/dependencies/RequireContextPlugin.js +1 -1
- package/lib/dependencies/RequireEnsureDependenciesBlockParserPlugin.js +26 -14
- package/lib/dependencies/RequireEnsureDependency.js +1 -1
- package/lib/dependencies/URLDependency.js +7 -4
- package/lib/dependencies/WorkerPlugin.js +2 -1
- package/lib/dependencies/getFunctionExpression.js +3 -1
- package/lib/esm/ModuleChunkLoadingRuntimeModule.js +2 -1
- package/lib/javascript/BasicEvaluatedExpression.js +2 -2
- package/lib/javascript/ChunkHelpers.js +2 -2
- package/lib/javascript/JavascriptParser.js +169 -57
- package/lib/javascript/JavascriptParserHelpers.js +1 -1
- package/lib/javascript/StartupHelpers.js +22 -5
- package/lib/logging/Logger.js +27 -2
- package/lib/logging/createConsoleLogger.js +11 -7
- package/lib/node/NodeEnvironmentPlugin.js +13 -7
- package/lib/node/NodeWatchFileSystem.js +37 -26
- package/lib/node/ReadFileChunkLoadingRuntimeModule.js +2 -1
- package/lib/node/RequireChunkLoadingRuntimeModule.js +2 -1
- package/lib/node/nodeConsole.js +24 -1
- package/lib/optimize/AggressiveSplittingPlugin.js +1 -0
- package/lib/optimize/ConcatenatedModule.js +138 -54
- package/lib/optimize/EnsureChunkConditionsPlugin.js +1 -1
- package/lib/optimize/InnerGraph.js +7 -2
- package/lib/optimize/InnerGraphPlugin.js +36 -13
- package/lib/optimize/ModuleConcatenationPlugin.js +12 -2
- package/lib/optimize/RemoveParentModulesPlugin.js +1 -0
- package/lib/optimize/RuntimeChunkPlugin.js +6 -1
- package/lib/optimize/SideEffectsFlagPlugin.js +46 -15
- package/lib/optimize/SplitChunksPlugin.js +2 -2
- package/lib/performance/SizeLimitsPlugin.js +11 -0
- package/lib/rules/ObjectMatcherRulePlugin.js +4 -0
- package/lib/runtime/EnsureChunkRuntimeModule.js +2 -1
- package/lib/runtime/GetTrustedTypesPolicyRuntimeModule.js +2 -1
- package/lib/serialization/FileMiddleware.js +1 -0
- package/lib/serialization/ObjectMiddleware.js +2 -0
- package/lib/serialization/Serializer.js +19 -0
- package/lib/sharing/ConsumeSharedModule.js +1 -1
- package/lib/sharing/ConsumeSharedPlugin.js +17 -3
- package/lib/sharing/ConsumeSharedRuntimeModule.js +9 -2
- package/lib/sharing/ProvideSharedPlugin.js +12 -5
- package/lib/sharing/resolveMatchedConfigs.js +2 -2
- package/lib/sharing/utils.js +13 -6
- package/lib/util/StackedCacheMap.js +26 -0
- package/lib/util/WeakTupleMap.js +57 -13
- package/lib/util/cleverMerge.js +24 -11
- package/lib/util/comparators.js +34 -14
- package/lib/util/conventions.js +129 -0
- package/lib/util/fs.js +379 -65
- package/lib/util/hash/BatchedHash.js +3 -0
- package/lib/util/hash/xxhash64.js +2 -2
- package/lib/util/runtime.js +1 -1
- package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +4 -2
- package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +15 -6
- package/lib/wasm-sync/WebAssemblyGenerator.js +27 -6
- package/lib/wasm-sync/WebAssemblyParser.js +7 -4
- package/lib/web/JsonpChunkLoadingRuntimeModule.js +2 -1
- package/lib/webpack.js +7 -3
- package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +2 -1
- package/package.json +25 -26
- package/schemas/WebpackOptions.check.js +1 -1
- package/schemas/WebpackOptions.json +69 -8
- package/schemas/plugins/BannerPlugin.check.js +1 -1
- package/schemas/plugins/BannerPlugin.json +5 -1
- package/schemas/plugins/css/CssAutoGeneratorOptions.check.js +1 -1
- package/schemas/plugins/css/CssGeneratorOptions.check.js +1 -1
- package/schemas/plugins/css/CssGlobalGeneratorOptions.check.js +1 -1
- package/schemas/plugins/css/CssModuleGeneratorOptions.check.js +1 -1
- package/types.d.ts +1668 -613
@@ -23,6 +23,7 @@ const ConcatenatedModule = require("./ConcatenatedModule");
|
|
23
23
|
/** @typedef {import("../Compilation")} Compilation */
|
24
24
|
/** @typedef {import("../Compiler")} Compiler */
|
25
25
|
/** @typedef {import("../Module")} Module */
|
26
|
+
/** @typedef {import("../Module").BuildInfo} BuildInfo */
|
26
27
|
/** @typedef {import("../RequestShortener")} RequestShortener */
|
27
28
|
/** @typedef {import("../util/runtime").RuntimeSpec} RuntimeSpec */
|
28
29
|
|
@@ -49,6 +50,9 @@ const formatBailoutReason = msg => {
|
|
49
50
|
};
|
50
51
|
|
51
52
|
class ModuleConcatenationPlugin {
|
53
|
+
/**
|
54
|
+
* @param {TODO} options options
|
55
|
+
*/
|
52
56
|
constructor(options) {
|
53
57
|
if (typeof options !== "object") options = {};
|
54
58
|
this.options = options;
|
@@ -171,7 +175,7 @@ class ModuleConcatenationPlugin {
|
|
171
175
|
}
|
172
176
|
|
173
177
|
// Must be in strict mode
|
174
|
-
if (!module.buildInfo.strict) {
|
178
|
+
if (!(/** @type {BuildInfo} */ (module.buildInfo).strict)) {
|
175
179
|
setBailoutReason(module, `Module is not in strict mode`);
|
176
180
|
continue;
|
177
181
|
}
|
@@ -242,7 +246,10 @@ class ModuleConcatenationPlugin {
|
|
242
246
|
// this improves performance, because modules already selected as inner are skipped
|
243
247
|
logger.time("sort relevant modules");
|
244
248
|
relevantModules.sort((a, b) => {
|
245
|
-
return
|
249
|
+
return (
|
250
|
+
/** @type {number} */ (moduleGraph.getDepth(a)) -
|
251
|
+
/** @type {number} */ (moduleGraph.getDepth(b))
|
252
|
+
);
|
246
253
|
});
|
247
254
|
logger.timeEnd("sort relevant modules");
|
248
255
|
|
@@ -927,6 +934,9 @@ class ConcatConfiguration {
|
|
927
934
|
return this.modules.size;
|
928
935
|
}
|
929
936
|
|
937
|
+
/**
|
938
|
+
* @param {number} snapshot snapshot
|
939
|
+
*/
|
930
940
|
rollback(snapshot) {
|
931
941
|
const modules = this.modules;
|
932
942
|
for (const m of modules) {
|
@@ -10,6 +10,9 @@
|
|
10
10
|
/** @typedef {import("../Entrypoint")} Entrypoint */
|
11
11
|
|
12
12
|
class RuntimeChunkPlugin {
|
13
|
+
/**
|
14
|
+
* @param {{ name?: (entrypoint: { name: string }) => string }} options options
|
15
|
+
*/
|
13
16
|
constructor(options) {
|
14
17
|
this.options = {
|
15
18
|
/**
|
@@ -37,7 +40,9 @@ class RuntimeChunkPlugin {
|
|
37
40
|
(compilation.entries.get(entryName));
|
38
41
|
if (data.options.runtime === undefined && !data.options.dependOn) {
|
39
42
|
// Determine runtime chunk name
|
40
|
-
let name =
|
43
|
+
let name =
|
44
|
+
/** @type {string | ((entrypoint: { name: string }) => string)} */
|
45
|
+
(this.options.name);
|
41
46
|
if (typeof name === "function") {
|
42
47
|
name = name({ name: entryName });
|
43
48
|
}
|
@@ -20,8 +20,11 @@ const formatLocation = require("../formatLocation");
|
|
20
20
|
/** @typedef {import("estree").Statement} Statement */
|
21
21
|
/** @typedef {import("../Compiler")} Compiler */
|
22
22
|
/** @typedef {import("../Dependency")} Dependency */
|
23
|
+
/** @typedef {import("../Dependency").DependencyLocation} DependencyLocation */
|
23
24
|
/** @typedef {import("../Module")} Module */
|
25
|
+
/** @typedef {import("../Module").BuildMeta} BuildMeta */
|
24
26
|
/** @typedef {import("../javascript/JavascriptParser")} JavascriptParser */
|
27
|
+
/** @typedef {import("../javascript/JavascriptParser").Range} Range */
|
25
28
|
|
26
29
|
/**
|
27
30
|
* @typedef {Object} ExportInModule
|
@@ -36,7 +39,9 @@ const formatLocation = require("../formatLocation");
|
|
36
39
|
* @property {Map<Module, Set<string>>} dynamic
|
37
40
|
*/
|
38
41
|
|
39
|
-
/** @
|
42
|
+
/** @typedef {Map<string, RegExp>} CacheItem */
|
43
|
+
|
44
|
+
/** @type {WeakMap<any, CacheItem>} */
|
40
45
|
const globToRegexpCache = new WeakMap();
|
41
46
|
|
42
47
|
/**
|
@@ -96,7 +101,7 @@ class SideEffectsFlagPlugin {
|
|
96
101
|
const hasSideEffects = SideEffectsFlagPlugin.moduleHasSideEffects(
|
97
102
|
resolveData.relativePath,
|
98
103
|
sideEffects,
|
99
|
-
cache
|
104
|
+
/** @type {CacheItem} */ (cache)
|
100
105
|
);
|
101
106
|
module.factoryMeta.sideEffectFree = !hasSideEffects;
|
102
107
|
}
|
@@ -132,7 +137,10 @@ class SideEffectsFlagPlugin {
|
|
132
137
|
switch (statement.type) {
|
133
138
|
case "ExpressionStatement":
|
134
139
|
if (
|
135
|
-
!parser.isPure(
|
140
|
+
!parser.isPure(
|
141
|
+
statement.expression,
|
142
|
+
/** @type {Range} */ (statement.range)[0]
|
143
|
+
)
|
136
144
|
) {
|
137
145
|
sideEffectsStatement = statement;
|
138
146
|
}
|
@@ -140,27 +148,35 @@ class SideEffectsFlagPlugin {
|
|
140
148
|
case "IfStatement":
|
141
149
|
case "WhileStatement":
|
142
150
|
case "DoWhileStatement":
|
143
|
-
if (
|
151
|
+
if (
|
152
|
+
!parser.isPure(
|
153
|
+
statement.test,
|
154
|
+
/** @type {Range} */ (statement.range)[0]
|
155
|
+
)
|
156
|
+
) {
|
144
157
|
sideEffectsStatement = statement;
|
145
158
|
}
|
146
159
|
// statement hook will be called for child statements too
|
147
160
|
break;
|
148
161
|
case "ForStatement":
|
149
162
|
if (
|
150
|
-
!parser.isPure(
|
163
|
+
!parser.isPure(
|
164
|
+
statement.init,
|
165
|
+
/** @type {Range} */ (statement.range)[0]
|
166
|
+
) ||
|
151
167
|
!parser.isPure(
|
152
168
|
statement.test,
|
153
169
|
statement.init
|
154
|
-
? statement.init.range[1]
|
155
|
-
: statement.range[0]
|
170
|
+
? /** @type {Range} */ (statement.init.range)[1]
|
171
|
+
: /** @type {Range} */ (statement.range)[0]
|
156
172
|
) ||
|
157
173
|
!parser.isPure(
|
158
174
|
statement.update,
|
159
175
|
statement.test
|
160
|
-
? statement.test.range[1]
|
176
|
+
? /** @type {Range} */ (statement.test.range)[1]
|
161
177
|
: statement.init
|
162
|
-
? statement.init.range[1]
|
163
|
-
: statement.range[0]
|
178
|
+
? /** @type {Range} */ (statement.init.range)[1]
|
179
|
+
: /** @type {Range} */ (statement.range)[0]
|
164
180
|
)
|
165
181
|
) {
|
166
182
|
sideEffectsStatement = statement;
|
@@ -169,7 +185,10 @@ class SideEffectsFlagPlugin {
|
|
169
185
|
break;
|
170
186
|
case "SwitchStatement":
|
171
187
|
if (
|
172
|
-
!parser.isPure(
|
188
|
+
!parser.isPure(
|
189
|
+
statement.discriminant,
|
190
|
+
/** @type {Range} */ (statement.range)[0]
|
191
|
+
)
|
173
192
|
) {
|
174
193
|
sideEffectsStatement = statement;
|
175
194
|
}
|
@@ -178,14 +197,22 @@ class SideEffectsFlagPlugin {
|
|
178
197
|
case "VariableDeclaration":
|
179
198
|
case "ClassDeclaration":
|
180
199
|
case "FunctionDeclaration":
|
181
|
-
if (
|
200
|
+
if (
|
201
|
+
!parser.isPure(
|
202
|
+
statement,
|
203
|
+
/** @type {Range} */ (statement.range)[0]
|
204
|
+
)
|
205
|
+
) {
|
182
206
|
sideEffectsStatement = statement;
|
183
207
|
}
|
184
208
|
break;
|
185
209
|
case "ExportNamedDeclaration":
|
186
210
|
case "ExportDefaultDeclaration":
|
187
211
|
if (
|
188
|
-
!parser.isPure(
|
212
|
+
!parser.isPure(
|
213
|
+
statement.declaration,
|
214
|
+
/** @type {Range} */ (statement.range)[0]
|
215
|
+
)
|
189
216
|
) {
|
190
217
|
sideEffectsStatement = statement;
|
191
218
|
}
|
@@ -208,7 +235,8 @@ class SideEffectsFlagPlugin {
|
|
208
235
|
);
|
209
236
|
parser.hooks.finish.tap(PLUGIN_NAME, () => {
|
210
237
|
if (sideEffectsStatement === undefined) {
|
211
|
-
|
238
|
+
/** @type {BuildMeta} */
|
239
|
+
(parser.state.module.buildMeta).sideEffectFree = true;
|
212
240
|
} else {
|
213
241
|
const { loc, type } = sideEffectsStatement;
|
214
242
|
moduleGraph
|
@@ -216,7 +244,7 @@ class SideEffectsFlagPlugin {
|
|
216
244
|
.push(
|
217
245
|
() =>
|
218
246
|
`Statement (${type}) with side effects in source code at ${formatLocation(
|
219
|
-
loc
|
247
|
+
/** @type {DependencyLocation} */ (loc)
|
220
248
|
)}`
|
221
249
|
);
|
222
250
|
}
|
@@ -246,6 +274,9 @@ class SideEffectsFlagPlugin {
|
|
246
274
|
|
247
275
|
const optimizedModules = new Set();
|
248
276
|
|
277
|
+
/**
|
278
|
+
* @param {Module} module module
|
279
|
+
*/
|
249
280
|
const optimizeIncomingConnections = module => {
|
250
281
|
if (optimizedModules.has(module)) return;
|
251
282
|
optimizedModules.add(module);
|
@@ -160,7 +160,7 @@ const MinMaxSizeWarning = require("./MinMaxSizeWarning");
|
|
160
160
|
* @property {string} name
|
161
161
|
* @property {Record<string, number>} sizes
|
162
162
|
* @property {Set<Chunk>} chunks
|
163
|
-
* @property {Set<Chunk>}
|
163
|
+
* @property {Set<Chunk>} reusableChunks
|
164
164
|
* @property {Set<bigint | Chunk>} chunksKeys
|
165
165
|
*/
|
166
166
|
|
@@ -1177,7 +1177,7 @@ module.exports = class SplitChunksPlugin {
|
|
1177
1177
|
name,
|
1178
1178
|
sizes: {},
|
1179
1179
|
chunks: new Set(),
|
1180
|
-
|
1180
|
+
reusableChunks: new Set(),
|
1181
1181
|
chunksKeys: new Set()
|
1182
1182
|
})
|
1183
1183
|
);
|
@@ -13,6 +13,7 @@ const NoAsyncChunksWarning = require("./NoAsyncChunksWarning");
|
|
13
13
|
/** @typedef {import("webpack-sources").Source} Source */
|
14
14
|
/** @typedef {import("../../declarations/WebpackOptions").PerformanceOptions} PerformanceOptions */
|
15
15
|
/** @typedef {import("../ChunkGroup")} ChunkGroup */
|
16
|
+
/** @typedef {import("../Compilation").Asset} Asset */
|
16
17
|
/** @typedef {import("../Compiler")} Compiler */
|
17
18
|
/** @typedef {import("../Entrypoint")} Entrypoint */
|
18
19
|
/** @typedef {import("../WebpackError")} WebpackError */
|
@@ -32,6 +33,12 @@ const NoAsyncChunksWarning = require("./NoAsyncChunksWarning");
|
|
32
33
|
|
33
34
|
const isOverSizeLimitSet = new WeakSet();
|
34
35
|
|
36
|
+
/**
|
37
|
+
* @param {Asset["name"]} name the name
|
38
|
+
* @param {Asset["source"]} source the source
|
39
|
+
* @param {Asset["info"]} info the info
|
40
|
+
* @returns {boolean} result
|
41
|
+
*/
|
35
42
|
const excludeSourceMap = (name, source, info) => !info.development;
|
36
43
|
|
37
44
|
module.exports = class SizeLimitsPlugin {
|
@@ -104,6 +111,10 @@ module.exports = class SizeLimitsPlugin {
|
|
104
111
|
}
|
105
112
|
}
|
106
113
|
|
114
|
+
/**
|
115
|
+
* @param {Asset["name"]} name the name
|
116
|
+
* @returns {boolean | undefined} result
|
117
|
+
*/
|
107
118
|
const fileFilter = name => {
|
108
119
|
const asset = compilation.getAsset(name);
|
109
120
|
return asset && assetFilter(asset.name, asset.source, asset.info);
|
@@ -9,6 +9,10 @@
|
|
9
9
|
/** @typedef {import("./RuleSetCompiler").RuleCondition} RuleCondition */
|
10
10
|
|
11
11
|
class ObjectMatcherRulePlugin {
|
12
|
+
/**
|
13
|
+
* @param {string} ruleProperty the rule property
|
14
|
+
* @param {string=} dataProperty the data property
|
15
|
+
*/
|
12
16
|
constructor(ruleProperty, dataProperty) {
|
13
17
|
this.ruleProperty = ruleProperty;
|
14
18
|
this.dataProperty = dataProperty || ruleProperty;
|
@@ -9,10 +9,11 @@ const RuntimeModule = require("../RuntimeModule");
|
|
9
9
|
const Template = require("../Template");
|
10
10
|
|
11
11
|
/** @typedef {import("../Compilation")} Compilation */
|
12
|
+
/** @typedef {import("../Module").ReadOnlyRuntimeRequirements} ReadOnlyRuntimeRequirements */
|
12
13
|
|
13
14
|
class EnsureChunkRuntimeModule extends RuntimeModule {
|
14
15
|
/**
|
15
|
-
* @param {
|
16
|
+
* @param {ReadOnlyRuntimeRequirements} runtimeRequirements runtime requirements
|
16
17
|
*/
|
17
18
|
constructor(runtimeRequirements) {
|
18
19
|
super("ensure chunk");
|
@@ -9,10 +9,11 @@ const Template = require("../Template");
|
|
9
9
|
const HelperRuntimeModule = require("./HelperRuntimeModule");
|
10
10
|
|
11
11
|
/** @typedef {import("../Compilation")} Compilation */
|
12
|
+
/** @typedef {import("../Module").ReadOnlyRuntimeRequirements} ReadOnlyRuntimeRequirements */
|
12
13
|
|
13
14
|
class GetTrustedTypesPolicyRuntimeModule extends HelperRuntimeModule {
|
14
15
|
/**
|
15
|
-
* @param {
|
16
|
+
* @param {ReadOnlyRuntimeRequirements} runtimeRequirements runtime requirements
|
16
17
|
*/
|
17
18
|
constructor(runtimeRequirements) {
|
18
19
|
super("trusted types policy");
|
@@ -576,6 +576,7 @@ class FileMiddleware extends SerializerMiddleware {
|
|
576
576
|
/** @type {number | undefined} */
|
577
577
|
let currentBufferUsed;
|
578
578
|
const buf = [];
|
579
|
+
/** @type {import("zlib").Zlib & import("stream").Transform | undefined} */
|
579
580
|
let decompression;
|
580
581
|
if (file.endsWith(".gz")) {
|
581
582
|
decompression = createGunzip({
|
@@ -46,6 +46,8 @@ Technically any value can be used.
|
|
46
46
|
/**
|
47
47
|
* @typedef {Object} ObjectSerializerContext
|
48
48
|
* @property {function(any): void} write
|
49
|
+
* @property {(function(any): void)=} writeLazy
|
50
|
+
* @property {(function(any, object=): (() => Promise<any> | any))=} writeSeparate
|
49
51
|
* @property {function(any): void} setCircularReference
|
50
52
|
*/
|
51
53
|
|
@@ -4,13 +4,27 @@
|
|
4
4
|
|
5
5
|
"use strict";
|
6
6
|
|
7
|
+
/**
|
8
|
+
* @template T, K
|
9
|
+
* @typedef {import("./SerializerMiddleware")<T, K>} SerializerMiddleware
|
10
|
+
*/
|
11
|
+
|
7
12
|
class Serializer {
|
13
|
+
/**
|
14
|
+
* @param {SerializerMiddleware<any, any>[]} middlewares serializer middlewares
|
15
|
+
* @param {TODO=} context context
|
16
|
+
*/
|
8
17
|
constructor(middlewares, context) {
|
9
18
|
this.serializeMiddlewares = middlewares.slice();
|
10
19
|
this.deserializeMiddlewares = middlewares.slice().reverse();
|
11
20
|
this.context = context;
|
12
21
|
}
|
13
22
|
|
23
|
+
/**
|
24
|
+
* @param {any} obj object
|
25
|
+
* @param {TODO} context content
|
26
|
+
* @returns {Promise<any>} result
|
27
|
+
*/
|
14
28
|
serialize(obj, context) {
|
15
29
|
const ctx = { ...context, ...this.context };
|
16
30
|
let current = obj;
|
@@ -28,6 +42,11 @@ class Serializer {
|
|
28
42
|
return current;
|
29
43
|
}
|
30
44
|
|
45
|
+
/**
|
46
|
+
* @param {any} value value
|
47
|
+
* @param {TODO} context context
|
48
|
+
* @returns {Promise<any>} result
|
49
|
+
*/
|
31
50
|
deserialize(value, context) {
|
32
51
|
const ctx = { ...context, ...this.context };
|
33
52
|
/** @type {any} */
|
@@ -42,7 +42,7 @@ const ConsumeSharedFallbackDependency = require("./ConsumeSharedFallbackDependen
|
|
42
42
|
* @property {string} shareKey global share key
|
43
43
|
* @property {string} shareScope share scope
|
44
44
|
* @property {SemVerRange | false | undefined} requiredVersion version requirement
|
45
|
-
* @property {string} packageName package name to determine required version automatically
|
45
|
+
* @property {string=} packageName package name to determine required version automatically
|
46
46
|
* @property {boolean} strictVersion don't use shared version even if version isn't valid
|
47
47
|
* @property {boolean} singleton use single global version
|
48
48
|
* @property {boolean} eager include the fallback module in a sync way
|
@@ -117,7 +117,12 @@ class ConsumeSharedPlugin {
|
|
117
117
|
normalModuleFactory
|
118
118
|
);
|
119
119
|
|
120
|
-
|
120
|
+
/** @type {Map<string, ConsumeOptions>} */
|
121
|
+
let unresolvedConsumes;
|
122
|
+
/** @type {Map<string, ConsumeOptions>} */
|
123
|
+
let resolvedConsumes;
|
124
|
+
/** @type {Map<string, ConsumeOptions>} */
|
125
|
+
let prefixedConsumes;
|
121
126
|
const promise = resolveMatchedConfigs(compilation, this._consumes).then(
|
122
127
|
({ resolved, unresolved, prefixed }) => {
|
123
128
|
resolvedConsumes = resolved;
|
@@ -138,6 +143,9 @@ class ConsumeSharedPlugin {
|
|
138
143
|
* @returns {Promise<ConsumeSharedModule>} create module
|
139
144
|
*/
|
140
145
|
const createConsumeSharedModule = (context, request, config) => {
|
146
|
+
/**
|
147
|
+
* @param {string} details details
|
148
|
+
*/
|
141
149
|
const requiredVersionWarning = details => {
|
142
150
|
const error = new WebpackError(
|
143
151
|
`No required version specified and unable to automatically determine one. ${details}`
|
@@ -293,9 +301,15 @@ class ConsumeSharedPlugin {
|
|
293
301
|
) {
|
294
302
|
return Promise.resolve();
|
295
303
|
}
|
296
|
-
const options = resolvedConsumes.get(
|
304
|
+
const options = resolvedConsumes.get(
|
305
|
+
/** @type {string} */ (resource)
|
306
|
+
);
|
297
307
|
if (options !== undefined) {
|
298
|
-
return createConsumeSharedModule(
|
308
|
+
return createConsumeSharedModule(
|
309
|
+
context,
|
310
|
+
/** @type {string} */ (resource),
|
311
|
+
options
|
312
|
+
);
|
299
313
|
}
|
300
314
|
return Promise.resolve();
|
301
315
|
}
|
@@ -17,14 +17,16 @@ const {
|
|
17
17
|
|
18
18
|
/** @typedef {import("webpack-sources").Source} Source */
|
19
19
|
/** @typedef {import("../Chunk")} Chunk */
|
20
|
+
/** @typedef {import("../Chunk").ChunkId} ChunkId */
|
20
21
|
/** @typedef {import("../ChunkGraph")} ChunkGraph */
|
21
22
|
/** @typedef {import("../Compilation")} Compilation */
|
22
23
|
/** @typedef {import("../Module")} Module */
|
24
|
+
/** @typedef {import("../Module").ReadOnlyRuntimeRequirements} ReadOnlyRuntimeRequirements */
|
23
25
|
/** @typedef {import("./ConsumeSharedModule")} ConsumeSharedModule */
|
24
26
|
|
25
27
|
class ConsumeSharedRuntimeModule extends RuntimeModule {
|
26
28
|
/**
|
27
|
-
* @param {
|
29
|
+
* @param {ReadOnlyRuntimeRequirements} runtimeRequirements runtime requirements
|
28
30
|
*/
|
29
31
|
constructor(runtimeRequirements) {
|
30
32
|
super("consumes", RuntimeModule.STAGE_ATTACH);
|
@@ -38,6 +40,7 @@ class ConsumeSharedRuntimeModule extends RuntimeModule {
|
|
38
40
|
const compilation = /** @type {Compilation} */ (this.compilation);
|
39
41
|
const chunkGraph = /** @type {ChunkGraph} */ (this.chunkGraph);
|
40
42
|
const { runtimeTemplate, codeGenerationResults } = compilation;
|
43
|
+
/** @type {Record<ChunkId, (string | number)[]>} */
|
41
44
|
const chunkToModuleMapping = {};
|
42
45
|
/** @type {Map<string | number, Source>} */
|
43
46
|
const moduleIdToSourceMapping = new Map();
|
@@ -70,7 +73,11 @@ class ConsumeSharedRuntimeModule extends RuntimeModule {
|
|
70
73
|
"consume-shared"
|
71
74
|
);
|
72
75
|
if (!modules) continue;
|
73
|
-
addModules(
|
76
|
+
addModules(
|
77
|
+
modules,
|
78
|
+
chunk,
|
79
|
+
(chunkToModuleMapping[/** @type {ChunkId} */ (chunk.id)] = [])
|
80
|
+
);
|
74
81
|
}
|
75
82
|
for (const chunk of /** @type {Chunk} */ (
|
76
83
|
this.chunk
|
@@ -15,6 +15,7 @@ const ProvideSharedModuleFactory = require("./ProvideSharedModuleFactory");
|
|
15
15
|
/** @typedef {import("../../declarations/plugins/sharing/ProvideSharedPlugin").ProvideSharedPluginOptions} ProvideSharedPluginOptions */
|
16
16
|
/** @typedef {import("../Compilation")} Compilation */
|
17
17
|
/** @typedef {import("../Compiler")} Compiler */
|
18
|
+
/** @typedef {import("../NormalModuleFactory").NormalModuleCreateData} NormalModuleCreateData */
|
18
19
|
|
19
20
|
const validate = createSchemaValidation(
|
20
21
|
require("../../schemas/plugins/sharing/ProvideSharedPlugin.check.js"),
|
@@ -112,6 +113,12 @@ class ProvideSharedPlugin {
|
|
112
113
|
}
|
113
114
|
}
|
114
115
|
compilationData.set(compilation, resolvedProvideMap);
|
116
|
+
/**
|
117
|
+
* @param {string} key key
|
118
|
+
* @param {ProvideOptions} config config
|
119
|
+
* @param {NormalModuleCreateData["resource"]} resource resource
|
120
|
+
* @param {NormalModuleCreateData["resourceResolveData"]} resourceResolveData resource resolve data
|
121
|
+
*/
|
115
122
|
const provideSharedModule = (
|
116
123
|
key,
|
117
124
|
config,
|
@@ -151,7 +158,7 @@ class ProvideSharedPlugin {
|
|
151
158
|
normalModuleFactory.hooks.module.tap(
|
152
159
|
"ProvideSharedPlugin",
|
153
160
|
(module, { resource, resourceResolveData }, resolveData) => {
|
154
|
-
if (resolvedProvideMap.has(resource)) {
|
161
|
+
if (resolvedProvideMap.has(/** @type {string} */ (resource))) {
|
155
162
|
return module;
|
156
163
|
}
|
157
164
|
const { request } = resolveData;
|
@@ -161,7 +168,7 @@ class ProvideSharedPlugin {
|
|
161
168
|
provideSharedModule(
|
162
169
|
request,
|
163
170
|
config,
|
164
|
-
resource,
|
171
|
+
/** @type {string} */ (resource),
|
165
172
|
resourceResolveData
|
166
173
|
);
|
167
174
|
resolveData.cacheable = false;
|
@@ -171,12 +178,12 @@ class ProvideSharedPlugin {
|
|
171
178
|
if (request.startsWith(prefix)) {
|
172
179
|
const remainder = request.slice(prefix.length);
|
173
180
|
provideSharedModule(
|
174
|
-
resource,
|
181
|
+
/** @type {string} */ (resource),
|
175
182
|
{
|
176
183
|
...config,
|
177
184
|
shareKey: config.shareKey + remainder
|
178
185
|
},
|
179
|
-
resource,
|
186
|
+
/** @type {string} */ (resource),
|
180
187
|
resourceResolveData
|
181
188
|
);
|
182
189
|
resolveData.cacheable = false;
|
@@ -209,7 +216,7 @@ class ProvideSharedPlugin {
|
|
209
216
|
},
|
210
217
|
err => {
|
211
218
|
if (err) return reject(err);
|
212
|
-
resolve();
|
219
|
+
resolve(null);
|
213
220
|
}
|
214
221
|
);
|
215
222
|
})
|
@@ -64,10 +64,10 @@ exports.resolveMatchedConfigs = (compilation, configs) => {
|
|
64
64
|
name: `shared module ${request}`
|
65
65
|
})
|
66
66
|
);
|
67
|
-
return resolve();
|
67
|
+
return resolve(null);
|
68
68
|
}
|
69
69
|
resolved.set(/** @type {string} */ (result), config);
|
70
|
-
resolve();
|
70
|
+
resolve(null);
|
71
71
|
}
|
72
72
|
);
|
73
73
|
});
|
package/lib/sharing/utils.js
CHANGED
@@ -8,6 +8,8 @@
|
|
8
8
|
const { join, dirname, readJson } = require("../util/fs");
|
9
9
|
|
10
10
|
/** @typedef {import("../util/fs").InputFileSystem} InputFileSystem */
|
11
|
+
/** @typedef {import("../util/fs").JsonObject} JsonObject */
|
12
|
+
/** @typedef {import("../util/fs").JsonPrimitive} JsonPrimitive */
|
11
13
|
|
12
14
|
// Extreme shorthand only for github. eg: foo/bar
|
13
15
|
const RE_URL_GITHUB_EXTREME_SHORT = /^[^/@:.\s][^/@:\s]*\/[^@:\s]*[^/@:\s]#\S+/;
|
@@ -373,9 +375,9 @@ exports.getDescriptionFile = getDescriptionFile;
|
|
373
375
|
|
374
376
|
/**
|
375
377
|
*
|
376
|
-
* @param {
|
378
|
+
* @param {JsonObject} data description file data i.e.: package.json
|
377
379
|
* @param {string} packageName name of the dependency
|
378
|
-
* @returns {string} normalized version
|
380
|
+
* @returns {string | undefined} normalized version
|
379
381
|
*/
|
380
382
|
const getRequiredVersionFromDescriptionFile = (data, packageName) => {
|
381
383
|
const dependencyTypes = [
|
@@ -386,12 +388,17 @@ const getRequiredVersionFromDescriptionFile = (data, packageName) => {
|
|
386
388
|
];
|
387
389
|
|
388
390
|
for (const dependencyType of dependencyTypes) {
|
391
|
+
const dependency = /** @type {JsonObject} */ (data[dependencyType]);
|
389
392
|
if (
|
390
|
-
|
391
|
-
typeof
|
392
|
-
packageName in
|
393
|
+
dependency &&
|
394
|
+
typeof dependency === "object" &&
|
395
|
+
packageName in dependency
|
393
396
|
) {
|
394
|
-
return normalizeVersion(
|
397
|
+
return normalizeVersion(
|
398
|
+
/** @type {Exclude<JsonPrimitive, null | boolean| number>} */ (
|
399
|
+
dependency[packageName]
|
400
|
+
)
|
401
|
+
);
|
395
402
|
}
|
396
403
|
}
|
397
404
|
};
|
@@ -8,6 +8,29 @@
|
|
8
8
|
/**
|
9
9
|
* @template K
|
10
10
|
* @template V
|
11
|
+
*
|
12
|
+
* The StackedCacheMap is a data structure designed as an alternative to a Map
|
13
|
+
* in situations where you need to handle multiple item additions and
|
14
|
+
* frequently access the largest map.
|
15
|
+
*
|
16
|
+
* It is particularly optimized for efficiently adding multiple items
|
17
|
+
* at once, which can be achieved using the `addAll` method.
|
18
|
+
*
|
19
|
+
* It has a fallback Map that is used when the map to be added is mutable.
|
20
|
+
*
|
21
|
+
* Note: `delete` and `has` are not supported for performance reasons.
|
22
|
+
*
|
23
|
+
* @example
|
24
|
+
* ```js
|
25
|
+
* const map = new StackedCacheMap();
|
26
|
+
* map.addAll(new Map([["a", 1], ["b", 2]]), true);
|
27
|
+
* map.addAll(new Map([["c", 3], ["d", 4]]), true);
|
28
|
+
* map.get("a"); // 1
|
29
|
+
* map.get("d"); // 4
|
30
|
+
* for (const [key, value] of map) {
|
31
|
+
* console.log(key, value);
|
32
|
+
* }
|
33
|
+
* ```
|
11
34
|
*/
|
12
35
|
class StackedCacheMap {
|
13
36
|
constructor() {
|
@@ -18,6 +41,9 @@ class StackedCacheMap {
|
|
18
41
|
}
|
19
42
|
|
20
43
|
/**
|
44
|
+
* If `immutable` is true, the map can be referenced by the StackedCacheMap
|
45
|
+
* and should not be changed afterwards. If the map is mutable, all items
|
46
|
+
* are copied into a fallback Map.
|
21
47
|
* @param {ReadonlyMap<K, V>} map map to add
|
22
48
|
* @param {boolean=} immutable if 'map' is immutable and StackedCacheMap can keep referencing it
|
23
49
|
*/
|