webpack 5.90.3 → 5.92.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 +6 -3
- package/lib/APIPlugin.js +14 -6
- package/lib/AutomaticPrefetchPlugin.js +1 -1
- package/lib/BannerPlugin.js +3 -1
- package/lib/Cache.js +8 -2
- package/lib/CacheFacade.js +3 -3
- package/lib/Chunk.js +7 -4
- package/lib/ChunkGraph.js +52 -25
- package/lib/ChunkGroup.js +23 -17
- package/lib/CleanPlugin.js +8 -6
- package/lib/Compilation.js +295 -120
- package/lib/Compiler.js +223 -87
- package/lib/ConcatenationScope.js +3 -3
- package/lib/ConditionalInitFragment.js +4 -5
- package/lib/ContextModule.js +95 -41
- package/lib/ContextModuleFactory.js +4 -2
- package/lib/ContextReplacementPlugin.js +3 -2
- package/lib/DefinePlugin.js +18 -6
- package/lib/Dependency.js +12 -10
- package/lib/DependencyTemplate.js +17 -7
- package/lib/DllModule.js +1 -0
- package/lib/DllReferencePlugin.js +7 -3
- package/lib/EntryOptionPlugin.js +4 -1
- package/lib/EntryPlugin.js +6 -1
- package/lib/Entrypoint.js +1 -1
- package/lib/EvalDevToolModulePlugin.js +11 -0
- package/lib/ExportsInfo.js +23 -8
- package/lib/ExternalModule.js +160 -35
- package/lib/ExternalModuleFactoryPlugin.js +37 -2
- package/lib/FileSystemInfo.js +69 -42
- package/lib/FlagDependencyExportsPlugin.js +21 -7
- package/lib/Generator.js +4 -4
- package/lib/HookWebpackError.js +2 -2
- package/lib/HotModuleReplacementPlugin.js +108 -45
- package/lib/IgnorePlugin.js +4 -1
- package/lib/InitFragment.js +5 -3
- package/lib/LibManifestPlugin.js +17 -9
- package/lib/Module.js +41 -14
- package/lib/ModuleFactory.js +3 -3
- package/lib/ModuleFilenameHelpers.js +30 -17
- package/lib/ModuleGraph.js +60 -31
- package/lib/ModuleGraphConnection.js +2 -1
- package/lib/MultiCompiler.js +62 -9
- package/lib/NodeStuffPlugin.js +14 -3
- package/lib/NormalModule.js +13 -13
- package/lib/NormalModuleFactory.js +18 -9
- package/lib/NormalModuleReplacementPlugin.js +5 -1
- package/lib/Parser.js +1 -1
- package/lib/PlatformPlugin.js +39 -0
- package/lib/ProgressPlugin.js +1 -1
- package/lib/ProvidePlugin.js +3 -1
- package/lib/RawModule.js +2 -1
- package/lib/RecordIdsPlugin.js +4 -4
- package/lib/ResolverFactory.js +6 -4
- package/lib/RuntimeModule.js +4 -4
- package/lib/RuntimePlugin.js +1 -0
- package/lib/RuntimeTemplate.js +124 -52
- package/lib/SourceMapDevToolPlugin.js +4 -1
- package/lib/Stats.js +11 -4
- package/lib/Template.js +5 -5
- package/lib/TemplatedPathPlugin.js +48 -7
- package/lib/Watching.js +67 -60
- package/lib/WebpackError.js +6 -6
- package/lib/WebpackOptionsApply.js +18 -5
- package/lib/asset/AssetGenerator.js +15 -0
- package/lib/asset/RawDataUrlModule.js +3 -1
- package/lib/async-modules/AwaitDependenciesInitFragment.js +2 -2
- package/lib/buildChunkGraph.js +120 -67
- 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 +51 -18
- package/lib/cache/ResolverCachePlugin.js +22 -14
- package/lib/cache/getLazyHashedEtag.js +2 -2
- package/lib/cli.js +5 -5
- package/lib/config/browserslistTargetHandler.js +7 -1
- package/lib/config/defaults.js +108 -34
- package/lib/config/normalization.js +3 -1
- package/lib/config/target.js +18 -11
- package/lib/container/ContainerEntryDependency.js +2 -1
- package/lib/container/ContainerEntryModule.js +4 -2
- 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 +68 -25
- package/lib/css/CssGenerator.js +34 -6
- package/lib/css/CssLoadingRuntimeModule.js +217 -98
- package/lib/css/CssModulesPlugin.js +238 -107
- package/lib/css/CssParser.js +24 -15
- package/lib/css/walkCssTokens.js +1 -1
- package/lib/debug/ProfilingPlugin.js +28 -3
- 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/CssExportDependency.js +2 -2
- package/lib/dependencies/CssLocalIdentifierDependency.js +71 -9
- package/lib/dependencies/CssUrlDependency.js +10 -7
- package/lib/dependencies/ExportsInfoDependency.js +5 -4
- package/lib/dependencies/ExternalModuleDependency.js +4 -2
- 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 +70 -19
- package/lib/dependencies/HarmonyImportSideEffectDependency.js +7 -6
- package/lib/dependencies/HarmonyImportSpecifierDependency.js +47 -35
- 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/ImportMetaPlugin.js +1 -1
- package/lib/dependencies/ImportParserPlugin.js +15 -5
- package/lib/dependencies/ImportWeakDependency.js +4 -2
- package/lib/dependencies/LoaderDependency.js +2 -1
- package/lib/dependencies/LoaderImportDependency.js +2 -1
- package/lib/dependencies/LoaderPlugin.js +2 -2
- package/lib/dependencies/ModuleDependency.js +4 -5
- package/lib/dependencies/PureExpressionDependency.js +64 -47
- 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/WorkerDependency.js +1 -1
- package/lib/dependencies/WorkerPlugin.js +2 -1
- package/lib/dependencies/getFunctionExpression.js +3 -1
- package/lib/esm/ModuleChunkLoadingRuntimeModule.js +92 -3
- package/lib/hmr/LazyCompilationPlugin.js +2 -2
- package/lib/ids/ChunkModuleIdRangePlugin.js +1 -1
- package/lib/ids/DeterministicChunkIdsPlugin.js +1 -1
- package/lib/ids/DeterministicModuleIdsPlugin.js +1 -1
- package/lib/ids/IdHelpers.js +6 -6
- package/lib/ids/NamedChunkIdsPlugin.js +1 -1
- package/lib/ids/NamedModuleIdsPlugin.js +1 -1
- package/lib/ids/SyncModuleIdsPlugin.js +2 -2
- package/lib/index.js +11 -0
- package/lib/javascript/BasicEvaluatedExpression.js +2 -2
- package/lib/javascript/ChunkHelpers.js +2 -2
- package/lib/javascript/CommonJsChunkFormatPlugin.js +1 -1
- package/lib/javascript/JavascriptGenerator.js +0 -1
- package/lib/javascript/JavascriptModulesPlugin.js +174 -17
- package/lib/javascript/JavascriptParser.js +204 -71
- package/lib/javascript/JavascriptParserHelpers.js +1 -1
- package/lib/javascript/StartupHelpers.js +22 -5
- package/lib/library/AbstractLibraryPlugin.js +2 -2
- package/lib/library/AmdLibraryPlugin.js +2 -2
- package/lib/library/AssignLibraryPlugin.js +3 -3
- package/lib/library/ExportPropertyLibraryPlugin.js +2 -2
- package/lib/library/JsonpLibraryPlugin.js +2 -2
- package/lib/library/ModuleLibraryPlugin.js +2 -2
- package/lib/library/SystemLibraryPlugin.js +2 -2
- package/lib/library/UmdLibraryPlugin.js +33 -12
- package/lib/logging/Logger.js +27 -2
- package/lib/logging/createConsoleLogger.js +13 -9
- package/lib/node/CommonJsChunkLoadingPlugin.js +2 -1
- package/lib/node/NodeEnvironmentPlugin.js +14 -8
- package/lib/node/NodeTemplatePlugin.js +1 -1
- package/lib/node/NodeWatchFileSystem.js +37 -26
- package/lib/node/ReadFileChunkLoadingRuntimeModule.js +2 -1
- package/lib/node/ReadFileCompileWasmPlugin.js +1 -1
- package/lib/node/RequireChunkLoadingRuntimeModule.js +2 -1
- package/lib/node/nodeConsole.js +24 -1
- package/lib/optimize/AggressiveMergingPlugin.js +1 -1
- package/lib/optimize/AggressiveSplittingPlugin.js +1 -0
- package/lib/optimize/ConcatenatedModule.js +140 -121
- package/lib/optimize/EnsureChunkConditionsPlugin.js +1 -1
- package/lib/optimize/InnerGraph.js +8 -3
- package/lib/optimize/InnerGraphPlugin.js +36 -13
- package/lib/optimize/LimitChunkCountPlugin.js +1 -2
- package/lib/optimize/ModuleConcatenationPlugin.js +13 -3
- package/lib/optimize/RealContentHashPlugin.js +3 -3
- package/lib/optimize/RemoveParentModulesPlugin.js +1 -0
- package/lib/optimize/RuntimeChunkPlugin.js +6 -1
- package/lib/optimize/SideEffectsFlagPlugin.js +48 -17
- package/lib/optimize/SplitChunksPlugin.js +10 -10
- package/lib/performance/SizeLimitsPlugin.js +13 -2
- package/lib/rules/ObjectMatcherRulePlugin.js +15 -1
- package/lib/rules/RuleSetCompiler.js +9 -7
- package/lib/runtime/EnsureChunkRuntimeModule.js +2 -1
- package/lib/runtime/GetTrustedTypesPolicyRuntimeModule.js +2 -1
- package/lib/runtime/LoadScriptRuntimeModule.js +1 -1
- package/lib/runtime/StartupChunkDependenciesPlugin.js +1 -1
- package/lib/schemes/HttpUriPlugin.js +1 -1
- package/lib/serialization/BinaryMiddleware.js +4 -4
- package/lib/serialization/FileMiddleware.js +4 -3
- package/lib/serialization/NullPrototypeObjectSerializer.js +2 -2
- package/lib/serialization/ObjectMiddleware.js +8 -5
- package/lib/serialization/PlainObjectSerializer.js +2 -2
- package/lib/serialization/Serializer.js +19 -0
- package/lib/serialization/SerializerMiddleware.js +2 -2
- package/lib/serialization/SingleItemMiddleware.js +2 -2
- package/lib/serialization/types.js +1 -1
- package/lib/sharing/ConsumeSharedModule.js +2 -2
- package/lib/sharing/ConsumeSharedPlugin.js +17 -3
- package/lib/sharing/ConsumeSharedRuntimeModule.js +9 -2
- package/lib/sharing/ProvideSharedPlugin.js +13 -6
- package/lib/sharing/resolveMatchedConfigs.js +3 -3
- package/lib/sharing/utils.js +13 -6
- package/lib/stats/DefaultStatsFactoryPlugin.js +20 -20
- package/lib/stats/DefaultStatsPrinterPlugin.js +1 -1
- package/lib/stats/StatsFactory.js +2 -2
- package/lib/stats/StatsPrinter.js +6 -6
- package/lib/util/ArrayQueue.js +14 -21
- package/lib/util/AsyncQueue.js +1 -1
- package/lib/util/Queue.js +8 -2
- package/lib/util/SortableSet.js +16 -4
- package/lib/util/StackedCacheMap.js +26 -0
- package/lib/util/TupleQueue.js +8 -2
- package/lib/util/WeakTupleMap.js +57 -13
- package/lib/util/binarySearchBounds.js +1 -1
- package/lib/util/cleverMerge.js +26 -13
- package/lib/util/comparators.js +37 -15
- package/lib/util/conventions.js +129 -0
- package/lib/util/createHash.js +3 -5
- package/lib/util/deprecation.js +3 -3
- package/lib/util/deterministicGrouping.js +2 -2
- package/lib/util/findGraphRoots.js +1 -1
- package/lib/util/fs.js +383 -69
- package/lib/util/hash/BatchedHash.js +3 -0
- package/lib/util/hash/xxhash64.js +2 -2
- package/lib/util/identifier.js +5 -5
- package/lib/util/mergeScope.js +79 -0
- package/lib/util/runtime.js +2 -17
- package/lib/util/semver.js +3 -0
- package/lib/util/smartGrouping.js +3 -3
- package/lib/wasm-async/AsyncWasmLoadingRuntimeModule.js +4 -2
- package/lib/wasm-async/AsyncWebAssemblyGenerator.js +1 -1
- package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +4 -2
- package/lib/wasm-async/AsyncWebAssemblyModulesPlugin.js +3 -3
- package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +16 -7
- package/lib/wasm-sync/WebAssemblyGenerator.js +40 -19
- package/lib/wasm-sync/WebAssemblyModulesPlugin.js +1 -1
- package/lib/wasm-sync/WebAssemblyParser.js +7 -4
- package/lib/wasm-sync/WebAssemblyUtils.js +2 -1
- package/lib/web/FetchCompileWasmPlugin.js +1 -1
- package/lib/web/JsonpChunkLoadingRuntimeModule.js +3 -2
- package/lib/webpack.js +19 -6
- package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +2 -1
- package/package.json +40 -39
- package/schemas/WebpackOptions.check.js +1 -1
- package/schemas/WebpackOptions.json +97 -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 +1826 -639
package/lib/RuntimeTemplate.js
CHANGED
@@ -13,13 +13,18 @@ const compileBooleanMatcher = require("./util/compileBooleanMatcher");
|
|
13
13
|
const propertyAccess = require("./util/propertyAccess");
|
14
14
|
const { forEachRuntime, subtractRuntime } = require("./util/runtime");
|
15
15
|
|
16
|
+
/** @typedef {import("../declarations/WebpackOptions").Environment} Environment */
|
16
17
|
/** @typedef {import("../declarations/WebpackOptions").OutputNormalized} OutputOptions */
|
17
18
|
/** @typedef {import("./AsyncDependenciesBlock")} AsyncDependenciesBlock */
|
19
|
+
/** @typedef {import("./Chunk")} Chunk */
|
18
20
|
/** @typedef {import("./ChunkGraph")} ChunkGraph */
|
19
21
|
/** @typedef {import("./CodeGenerationResults")} CodeGenerationResults */
|
22
|
+
/** @typedef {import("./CodeGenerationResults").CodeGenerationResult} CodeGenerationResult */
|
20
23
|
/** @typedef {import("./Compilation")} Compilation */
|
21
24
|
/** @typedef {import("./Dependency")} Dependency */
|
22
25
|
/** @typedef {import("./Module")} Module */
|
26
|
+
/** @typedef {import("./Module").BuildMeta} BuildMeta */
|
27
|
+
/** @typedef {import("./Module").RuntimeRequirements} RuntimeRequirements */
|
23
28
|
/** @typedef {import("./ModuleGraph")} ModuleGraph */
|
24
29
|
/** @typedef {import("./RequestShortener")} RequestShortener */
|
25
30
|
/** @typedef {import("./util/runtime").RuntimeSpec} RuntimeSpec */
|
@@ -52,8 +57,8 @@ Module has these incoming connections: ${Array.from(
|
|
52
57
|
};
|
53
58
|
|
54
59
|
/**
|
55
|
-
* @param {string|undefined} definition global object definition
|
56
|
-
* @returns {string} save to use global object
|
60
|
+
* @param {string | undefined} definition global object definition
|
61
|
+
* @returns {string | undefined} save to use global object
|
57
62
|
*/
|
58
63
|
function getGlobalObject(definition) {
|
59
64
|
if (!definition) return definition;
|
@@ -82,8 +87,13 @@ class RuntimeTemplate {
|
|
82
87
|
this.compilation = compilation;
|
83
88
|
this.outputOptions = outputOptions || {};
|
84
89
|
this.requestShortener = requestShortener;
|
85
|
-
this.globalObject =
|
86
|
-
|
90
|
+
this.globalObject =
|
91
|
+
/** @type {string} */
|
92
|
+
(getGlobalObject(outputOptions.globalObject));
|
93
|
+
this.contentHashReplacement = "X".repeat(
|
94
|
+
/** @type {NonNullable<OutputOptions["hashDigestLength"]>} */
|
95
|
+
(outputOptions.hashDigestLength)
|
96
|
+
);
|
87
97
|
}
|
88
98
|
|
89
99
|
isIIFE() {
|
@@ -95,51 +105,73 @@ class RuntimeTemplate {
|
|
95
105
|
}
|
96
106
|
|
97
107
|
supportsConst() {
|
98
|
-
return this.outputOptions.environment.const;
|
108
|
+
return /** @type {Environment} */ (this.outputOptions.environment).const;
|
99
109
|
}
|
100
110
|
|
101
111
|
supportsArrowFunction() {
|
102
|
-
return this.outputOptions.environment
|
112
|
+
return /** @type {Environment} */ (this.outputOptions.environment)
|
113
|
+
.arrowFunction;
|
103
114
|
}
|
104
115
|
|
105
116
|
supportsAsyncFunction() {
|
106
|
-
return this.outputOptions.environment
|
117
|
+
return /** @type {Environment} */ (this.outputOptions.environment)
|
118
|
+
.asyncFunction;
|
107
119
|
}
|
108
120
|
|
109
121
|
supportsOptionalChaining() {
|
110
|
-
return this.outputOptions.environment
|
122
|
+
return /** @type {Environment} */ (this.outputOptions.environment)
|
123
|
+
.optionalChaining;
|
111
124
|
}
|
112
125
|
|
113
126
|
supportsForOf() {
|
114
|
-
return this.outputOptions.environment.forOf;
|
127
|
+
return /** @type {Environment} */ (this.outputOptions.environment).forOf;
|
115
128
|
}
|
116
129
|
|
117
130
|
supportsDestructuring() {
|
118
|
-
return this.outputOptions.environment
|
131
|
+
return /** @type {Environment} */ (this.outputOptions.environment)
|
132
|
+
.destructuring;
|
119
133
|
}
|
120
134
|
|
121
135
|
supportsBigIntLiteral() {
|
122
|
-
return this.outputOptions.environment
|
136
|
+
return /** @type {Environment} */ (this.outputOptions.environment)
|
137
|
+
.bigIntLiteral;
|
123
138
|
}
|
124
139
|
|
125
140
|
supportsDynamicImport() {
|
126
|
-
return this.outputOptions.environment
|
141
|
+
return /** @type {Environment} */ (this.outputOptions.environment)
|
142
|
+
.dynamicImport;
|
127
143
|
}
|
128
144
|
|
129
145
|
supportsEcmaScriptModuleSyntax() {
|
130
|
-
return this.outputOptions.environment.module;
|
146
|
+
return /** @type {Environment} */ (this.outputOptions.environment).module;
|
131
147
|
}
|
132
148
|
|
133
149
|
supportTemplateLiteral() {
|
134
|
-
return this.outputOptions.environment
|
150
|
+
return /** @type {Environment} */ (this.outputOptions.environment)
|
151
|
+
.templateLiteral;
|
152
|
+
}
|
153
|
+
|
154
|
+
supportNodePrefixForCoreModules() {
|
155
|
+
return /** @type {Environment} */ (this.outputOptions.environment)
|
156
|
+
.nodePrefixForCoreModules;
|
135
157
|
}
|
136
158
|
|
159
|
+
/**
|
160
|
+
* @param {string} returnValue return value
|
161
|
+
* @param {string} args arguments
|
162
|
+
* @returns {string} returning function
|
163
|
+
*/
|
137
164
|
returningFunction(returnValue, args = "") {
|
138
165
|
return this.supportsArrowFunction()
|
139
166
|
? `(${args}) => (${returnValue})`
|
140
167
|
: `function(${args}) { return ${returnValue}; }`;
|
141
168
|
}
|
142
169
|
|
170
|
+
/**
|
171
|
+
* @param {string} args arguments
|
172
|
+
* @param {string | string[]} body body
|
173
|
+
* @returns {string} basic function
|
174
|
+
*/
|
143
175
|
basicFunction(args, body) {
|
144
176
|
return this.supportsArrowFunction()
|
145
177
|
? `(${args}) => {\n${Template.indent(body)}\n}`
|
@@ -211,16 +243,29 @@ class RuntimeTemplate {
|
|
211
243
|
: str;
|
212
244
|
}
|
213
245
|
|
246
|
+
/**
|
247
|
+
* @param {string} expression expression
|
248
|
+
* @param {string} args arguments
|
249
|
+
* @returns {string} expression function code
|
250
|
+
*/
|
214
251
|
expressionFunction(expression, args = "") {
|
215
252
|
return this.supportsArrowFunction()
|
216
253
|
? `(${args}) => (${expression})`
|
217
254
|
: `function(${args}) { ${expression}; }`;
|
218
255
|
}
|
219
256
|
|
257
|
+
/**
|
258
|
+
* @returns {string} empty function code
|
259
|
+
*/
|
220
260
|
emptyFunction() {
|
221
261
|
return this.supportsArrowFunction() ? "x => {}" : "function() {}";
|
222
262
|
}
|
223
263
|
|
264
|
+
/**
|
265
|
+
* @param {string[]} items items
|
266
|
+
* @param {string} value value
|
267
|
+
* @returns {string} destructure array code
|
268
|
+
*/
|
224
269
|
destructureArray(items, value) {
|
225
270
|
return this.supportsDestructuring()
|
226
271
|
? `var [${items.join(", ")}] = ${value};`
|
@@ -229,6 +274,11 @@ class RuntimeTemplate {
|
|
229
274
|
);
|
230
275
|
}
|
231
276
|
|
277
|
+
/**
|
278
|
+
* @param {string[]} items items
|
279
|
+
* @param {string} value value
|
280
|
+
* @returns {string} destructure object code
|
281
|
+
*/
|
232
282
|
destructureObject(items, value) {
|
233
283
|
return this.supportsDestructuring()
|
234
284
|
? `var {${items.join(", ")}} = ${value};`
|
@@ -237,10 +287,21 @@ class RuntimeTemplate {
|
|
237
287
|
);
|
238
288
|
}
|
239
289
|
|
290
|
+
/**
|
291
|
+
* @param {string} args arguments
|
292
|
+
* @param {string} body body
|
293
|
+
* @returns {string} IIFE code
|
294
|
+
*/
|
240
295
|
iife(args, body) {
|
241
296
|
return `(${this.basicFunction(args, body)})()`;
|
242
297
|
}
|
243
298
|
|
299
|
+
/**
|
300
|
+
* @param {string} variable variable
|
301
|
+
* @param {string} array array
|
302
|
+
* @param {string | string[]} body body
|
303
|
+
* @returns {string} for each code
|
304
|
+
*/
|
244
305
|
forEach(variable, array, body) {
|
245
306
|
return this.supportsForOf()
|
246
307
|
? `for(const ${variable} of ${array}) {\n${Template.indent(body)}\n}`
|
@@ -333,10 +394,10 @@ class RuntimeTemplate {
|
|
333
394
|
}
|
334
395
|
|
335
396
|
/**
|
336
|
-
* @param {
|
397
|
+
* @param {object} options options object
|
337
398
|
* @param {ChunkGraph} options.chunkGraph the chunk graph
|
338
399
|
* @param {Module} options.module the module
|
339
|
-
* @param {string} options.request the request that should be printed as comment
|
400
|
+
* @param {string=} options.request the request that should be printed as comment
|
340
401
|
* @param {string=} options.idExpr expression to use as id expression
|
341
402
|
* @param {"expression" | "promise" | "statements"} options.type which kind of code should be returned
|
342
403
|
* @returns {string} the code
|
@@ -370,10 +431,10 @@ class RuntimeTemplate {
|
|
370
431
|
}
|
371
432
|
|
372
433
|
/**
|
373
|
-
* @param {
|
434
|
+
* @param {object} options options object
|
374
435
|
* @param {Module} options.module the module
|
375
436
|
* @param {ChunkGraph} options.chunkGraph the chunk graph
|
376
|
-
* @param {string} options.request the request that should be printed as comment
|
437
|
+
* @param {string=} options.request the request that should be printed as comment
|
377
438
|
* @param {boolean=} options.weak if the dependency is weak (will create a nice error message)
|
378
439
|
* @returns {string} the expression
|
379
440
|
*/
|
@@ -399,12 +460,12 @@ class RuntimeTemplate {
|
|
399
460
|
}
|
400
461
|
|
401
462
|
/**
|
402
|
-
* @param {
|
463
|
+
* @param {object} options options object
|
403
464
|
* @param {Module | null} options.module the module
|
404
465
|
* @param {ChunkGraph} options.chunkGraph the chunk graph
|
405
|
-
* @param {string} options.request the request that should be printed as comment
|
466
|
+
* @param {string=} options.request the request that should be printed as comment
|
406
467
|
* @param {boolean=} options.weak if the dependency is weak (will create a nice error message)
|
407
|
-
* @param {
|
468
|
+
* @param {RuntimeRequirements} options.runtimeRequirements if set, will be filled with runtime requirements
|
408
469
|
* @returns {string} the expression
|
409
470
|
*/
|
410
471
|
moduleRaw({ module, chunkGraph, request, weak, runtimeRequirements }) {
|
@@ -442,12 +503,12 @@ class RuntimeTemplate {
|
|
442
503
|
}
|
443
504
|
|
444
505
|
/**
|
445
|
-
* @param {
|
506
|
+
* @param {object} options options object
|
446
507
|
* @param {Module | null} options.module the module
|
447
508
|
* @param {ChunkGraph} options.chunkGraph the chunk graph
|
448
509
|
* @param {string} options.request the request that should be printed as comment
|
449
510
|
* @param {boolean=} options.weak if the dependency is weak (will create a nice error message)
|
450
|
-
* @param {
|
511
|
+
* @param {RuntimeRequirements} options.runtimeRequirements if set, will be filled with runtime requirements
|
451
512
|
* @returns {string} the expression
|
452
513
|
*/
|
453
514
|
moduleExports({ module, chunkGraph, request, weak, runtimeRequirements }) {
|
@@ -461,13 +522,13 @@ class RuntimeTemplate {
|
|
461
522
|
}
|
462
523
|
|
463
524
|
/**
|
464
|
-
* @param {
|
525
|
+
* @param {object} options options object
|
465
526
|
* @param {Module} options.module the module
|
466
527
|
* @param {ChunkGraph} options.chunkGraph the chunk graph
|
467
528
|
* @param {string} options.request the request that should be printed as comment
|
468
529
|
* @param {boolean=} options.strict if the current module is in strict esm mode
|
469
530
|
* @param {boolean=} options.weak if the dependency is weak (will create a nice error message)
|
470
|
-
* @param {
|
531
|
+
* @param {RuntimeRequirements} options.runtimeRequirements if set, will be filled with runtime requirements
|
471
532
|
* @returns {string} the expression
|
472
533
|
*/
|
473
534
|
moduleNamespace({
|
@@ -530,7 +591,7 @@ class RuntimeTemplate {
|
|
530
591
|
}
|
531
592
|
|
532
593
|
/**
|
533
|
-
* @param {
|
594
|
+
* @param {object} options options object
|
534
595
|
* @param {ChunkGraph} options.chunkGraph the chunk graph
|
535
596
|
* @param {AsyncDependenciesBlock=} options.block the current dependencies block
|
536
597
|
* @param {Module} options.module the module
|
@@ -538,7 +599,7 @@ class RuntimeTemplate {
|
|
538
599
|
* @param {string} options.message a message for the comment
|
539
600
|
* @param {boolean=} options.strict if the current module is in strict esm mode
|
540
601
|
* @param {boolean=} options.weak if the dependency is weak (will create a nice error message)
|
541
|
-
* @param {
|
602
|
+
* @param {RuntimeRequirements} options.runtimeRequirements if set, will be filled with runtime requirements
|
542
603
|
* @returns {string} the promise expression
|
543
604
|
*/
|
544
605
|
moduleNamespacePromise({
|
@@ -680,11 +741,11 @@ class RuntimeTemplate {
|
|
680
741
|
}
|
681
742
|
|
682
743
|
/**
|
683
|
-
* @param {
|
744
|
+
* @param {object} options options object
|
684
745
|
* @param {ChunkGraph} options.chunkGraph the chunk graph
|
685
746
|
* @param {RuntimeSpec=} options.runtime runtime for which this code will be generated
|
686
747
|
* @param {RuntimeSpec | boolean=} options.runtimeCondition only execute the statement in some runtimes
|
687
|
-
* @param {
|
748
|
+
* @param {RuntimeRequirements} options.runtimeRequirements if set, will be filled with runtime requirements
|
688
749
|
* @returns {string} expression
|
689
750
|
*/
|
690
751
|
runtimeConditionExpression({
|
@@ -698,12 +759,16 @@ class RuntimeTemplate {
|
|
698
759
|
/** @type {Set<string>} */
|
699
760
|
const positiveRuntimeIds = new Set();
|
700
761
|
forEachRuntime(runtimeCondition, runtime =>
|
701
|
-
positiveRuntimeIds.add(
|
762
|
+
positiveRuntimeIds.add(
|
763
|
+
`${chunkGraph.getRuntimeId(/** @type {string} */ (runtime))}`
|
764
|
+
)
|
702
765
|
);
|
703
766
|
/** @type {Set<string>} */
|
704
767
|
const negativeRuntimeIds = new Set();
|
705
768
|
forEachRuntime(subtractRuntime(runtime, runtimeCondition), runtime =>
|
706
|
-
negativeRuntimeIds.add(
|
769
|
+
negativeRuntimeIds.add(
|
770
|
+
`${chunkGraph.getRuntimeId(/** @type {string} */ (runtime))}`
|
771
|
+
)
|
707
772
|
);
|
708
773
|
runtimeRequirements.add(RuntimeGlobals.runtimeId);
|
709
774
|
return compileBooleanMatcher.fromLists(
|
@@ -714,7 +779,7 @@ class RuntimeTemplate {
|
|
714
779
|
|
715
780
|
/**
|
716
781
|
*
|
717
|
-
* @param {
|
782
|
+
* @param {object} options options object
|
718
783
|
* @param {boolean=} options.update whether a new variable should be created or the existing one updated
|
719
784
|
* @param {Module} options.module the module
|
720
785
|
* @param {ChunkGraph} options.chunkGraph the chunk graph
|
@@ -722,7 +787,7 @@ class RuntimeTemplate {
|
|
722
787
|
* @param {string} options.importVar name of the import variable
|
723
788
|
* @param {Module} options.originModule module in which the statement is emitted
|
724
789
|
* @param {boolean=} options.weak true, if this is a weak dependency
|
725
|
-
* @param {
|
790
|
+
* @param {RuntimeRequirements} options.runtimeRequirements if set, will be filled with runtime requirements
|
726
791
|
* @returns {[string, string]} the import statement and the compat statement
|
727
792
|
*/
|
728
793
|
importStatement({
|
@@ -774,7 +839,8 @@ class RuntimeTemplate {
|
|
774
839
|
|
775
840
|
const exportsType = module.getExportsType(
|
776
841
|
chunkGraph.moduleGraph,
|
777
|
-
|
842
|
+
/** @type {BuildMeta} */
|
843
|
+
(originModule.buildMeta).strictHarmonyModule
|
778
844
|
);
|
779
845
|
runtimeRequirements.add(RuntimeGlobals.require);
|
780
846
|
const importContent = `/* harmony import */ ${optDeclaration}${importVar} = ${RuntimeGlobals.require}(${moduleId});\n`;
|
@@ -790,7 +856,7 @@ class RuntimeTemplate {
|
|
790
856
|
}
|
791
857
|
|
792
858
|
/**
|
793
|
-
* @param {
|
859
|
+
* @param {object} options options
|
794
860
|
* @param {ModuleGraph} options.moduleGraph the module graph
|
795
861
|
* @param {Module} options.module the module
|
796
862
|
* @param {string} options.request the request
|
@@ -803,7 +869,7 @@ class RuntimeTemplate {
|
|
803
869
|
* @param {string} options.importVar the identifier name of the import variable
|
804
870
|
* @param {InitFragment<TODO>[]} options.initFragments init fragments will be added here
|
805
871
|
* @param {RuntimeSpec} options.runtime runtime for which this code will be generated
|
806
|
-
* @param {
|
872
|
+
* @param {RuntimeRequirements} options.runtimeRequirements if set, will be filled with runtime requirements
|
807
873
|
* @returns {string} expression
|
808
874
|
*/
|
809
875
|
exportFromImport({
|
@@ -831,7 +897,8 @@ class RuntimeTemplate {
|
|
831
897
|
}
|
832
898
|
const exportsType = module.getExportsType(
|
833
899
|
moduleGraph,
|
834
|
-
|
900
|
+
/** @type {BuildMeta} */
|
901
|
+
(originModule.buildMeta).strictHarmonyModule
|
835
902
|
);
|
836
903
|
|
837
904
|
if (defaultInterop) {
|
@@ -912,11 +979,11 @@ class RuntimeTemplate {
|
|
912
979
|
}
|
913
980
|
|
914
981
|
/**
|
915
|
-
* @param {
|
916
|
-
* @param {AsyncDependenciesBlock} options.block the async block
|
982
|
+
* @param {object} options options
|
983
|
+
* @param {AsyncDependenciesBlock | undefined} options.block the async block
|
917
984
|
* @param {string} options.message the message
|
918
985
|
* @param {ChunkGraph} options.chunkGraph the chunk graph
|
919
|
-
* @param {
|
986
|
+
* @param {RuntimeRequirements} options.runtimeRequirements if set, will be filled with runtime requirements
|
920
987
|
* @returns {string} expression
|
921
988
|
*/
|
922
989
|
blockPromise({ block, message, chunkGraph, runtimeRequirements }) {
|
@@ -962,6 +1029,10 @@ class RuntimeTemplate {
|
|
962
1029
|
runtimeRequirements.add(RuntimeGlobals.hasFetchPriority);
|
963
1030
|
}
|
964
1031
|
|
1032
|
+
/**
|
1033
|
+
* @param {Chunk} chunk chunk
|
1034
|
+
* @returns {string} require chunk id code
|
1035
|
+
*/
|
965
1036
|
const requireChunkId = chunk =>
|
966
1037
|
`${RuntimeGlobals.ensureChunk}(${JSON.stringify(chunk.id)}${
|
967
1038
|
fetchPriority ? `, ${JSON.stringify(fetchPriority)}` : ""
|
@@ -975,10 +1046,10 @@ class RuntimeTemplate {
|
|
975
1046
|
}
|
976
1047
|
|
977
1048
|
/**
|
978
|
-
* @param {
|
1049
|
+
* @param {object} options options
|
979
1050
|
* @param {AsyncDependenciesBlock} options.block the async block
|
980
1051
|
* @param {ChunkGraph} options.chunkGraph the chunk graph
|
981
|
-
* @param {
|
1052
|
+
* @param {RuntimeRequirements} options.runtimeRequirements if set, will be filled with runtime requirements
|
982
1053
|
* @param {string=} options.request request string used originally
|
983
1054
|
* @returns {string} expression
|
984
1055
|
*/
|
@@ -1007,10 +1078,10 @@ class RuntimeTemplate {
|
|
1007
1078
|
}
|
1008
1079
|
|
1009
1080
|
/**
|
1010
|
-
* @param {
|
1081
|
+
* @param {object} options options
|
1011
1082
|
* @param {Dependency} options.dependency the dependency
|
1012
1083
|
* @param {ChunkGraph} options.chunkGraph the chunk graph
|
1013
|
-
* @param {
|
1084
|
+
* @param {RuntimeRequirements} options.runtimeRequirements if set, will be filled with runtime requirements
|
1014
1085
|
* @param {string=} options.request request string used originally
|
1015
1086
|
* @returns {string} expression
|
1016
1087
|
*/
|
@@ -1028,9 +1099,9 @@ class RuntimeTemplate {
|
|
1028
1099
|
}
|
1029
1100
|
|
1030
1101
|
/**
|
1031
|
-
* @param {
|
1102
|
+
* @param {object} options options
|
1032
1103
|
* @param {string} options.exportsArgument the name of the exports object
|
1033
|
-
* @param {
|
1104
|
+
* @param {RuntimeRequirements} options.runtimeRequirements if set, will be filled with runtime requirements
|
1034
1105
|
* @returns {string} statement
|
1035
1106
|
*/
|
1036
1107
|
defineEsModuleFlagStatement({ exportsArgument, runtimeRequirements }) {
|
@@ -1040,23 +1111,24 @@ class RuntimeTemplate {
|
|
1040
1111
|
}
|
1041
1112
|
|
1042
1113
|
/**
|
1043
|
-
* @param {
|
1114
|
+
* @param {object} options options object
|
1044
1115
|
* @param {Module} options.module the module
|
1045
|
-
* @param {string} options.publicPath the public path
|
1046
1116
|
* @param {RuntimeSpec=} options.runtime runtime
|
1047
1117
|
* @param {CodeGenerationResults} options.codeGenerationResults the code generation results
|
1048
1118
|
* @returns {string} the url of the asset
|
1049
1119
|
*/
|
1050
|
-
assetUrl({
|
1120
|
+
assetUrl({ runtime, module, codeGenerationResults }) {
|
1051
1121
|
if (!module) {
|
1052
1122
|
return "data:,";
|
1053
1123
|
}
|
1054
1124
|
const codeGen = codeGenerationResults.get(module, runtime);
|
1055
|
-
const {
|
1125
|
+
const data = /** @type {NonNullable<CodeGenerationResult["data"]>} */ (
|
1126
|
+
codeGen.data
|
1127
|
+
);
|
1056
1128
|
const url = data.get("url");
|
1057
1129
|
if (url) return url.toString();
|
1058
|
-
const
|
1059
|
-
return
|
1130
|
+
const assetPath = data.get("assetPathForCss");
|
1131
|
+
return assetPath;
|
1060
1132
|
}
|
1061
1133
|
}
|
1062
1134
|
|
@@ -29,6 +29,7 @@ const { makePathsAbsolute } = require("./util/identifier");
|
|
29
29
|
/** @typedef {import("./Module")} Module */
|
30
30
|
/** @typedef {import("./NormalModule").SourceMap} SourceMap */
|
31
31
|
/** @typedef {import("./util/Hash")} Hash */
|
32
|
+
/** @typedef {import("./util/fs").OutputFileSystem} OutputFileSystem */
|
32
33
|
|
33
34
|
const validate = createSchemaValidation(
|
34
35
|
require("../schemas/plugins/SourceMapDevToolPlugin.check.js"),
|
@@ -165,7 +166,9 @@ class SourceMapDevToolPlugin {
|
|
165
166
|
* @returns {void}
|
166
167
|
*/
|
167
168
|
apply(compiler) {
|
168
|
-
const outputFs =
|
169
|
+
const outputFs = /** @type {OutputFileSystem} */ (
|
170
|
+
compiler.outputFileSystem
|
171
|
+
);
|
169
172
|
const sourceMapFilename = this.sourceMapFilename;
|
170
173
|
const sourceMappingURLComment = this.sourceMappingURLComment;
|
171
174
|
const moduleFilenameTemplate = this.moduleFilenameTemplate;
|
package/lib/Stats.js
CHANGED
@@ -7,6 +7,7 @@
|
|
7
7
|
|
8
8
|
/** @typedef {import("../declarations/WebpackOptions").StatsOptions} StatsOptions */
|
9
9
|
/** @typedef {import("./Compilation")} Compilation */
|
10
|
+
/** @typedef {import("./Compilation").NormalizedStatsOptions} NormalizedStatsOptions */
|
10
11
|
/** @typedef {import("./stats/DefaultStatsFactoryPlugin").StatsCompilation} StatsCompilation */
|
11
12
|
|
12
13
|
class Stats {
|
@@ -34,7 +35,7 @@ class Stats {
|
|
34
35
|
*/
|
35
36
|
hasWarnings() {
|
36
37
|
return (
|
37
|
-
this.compilation.
|
38
|
+
this.compilation.getWarnings().length > 0 ||
|
38
39
|
this.compilation.children.some(child => child.getStats().hasWarnings())
|
39
40
|
);
|
40
41
|
}
|
@@ -58,7 +59,9 @@ class Stats {
|
|
58
59
|
forToString: false
|
59
60
|
});
|
60
61
|
|
61
|
-
const statsFactory = this.compilation.createStatsFactory(
|
62
|
+
const statsFactory = this.compilation.createStatsFactory(
|
63
|
+
/** @type {NormalizedStatsOptions} */ (options)
|
64
|
+
);
|
62
65
|
|
63
66
|
return statsFactory.create("compilation", this.compilation, {
|
64
67
|
compilation: this.compilation
|
@@ -74,8 +77,12 @@ class Stats {
|
|
74
77
|
forToString: true
|
75
78
|
});
|
76
79
|
|
77
|
-
const statsFactory = this.compilation.createStatsFactory(
|
78
|
-
|
80
|
+
const statsFactory = this.compilation.createStatsFactory(
|
81
|
+
/** @type {NormalizedStatsOptions} */ (options)
|
82
|
+
);
|
83
|
+
const statsPrinter = this.compilation.createStatsPrinter(
|
84
|
+
/** @type {NormalizedStatsOptions} */ (options)
|
85
|
+
);
|
79
86
|
|
80
87
|
const data = statsFactory.create("compilation", this.compilation, {
|
81
88
|
compilation: this.compilation
|
package/lib/Template.js
CHANGED
@@ -41,7 +41,7 @@ const PATH_NAME_NORMALIZE_REPLACE_REGEX = /[^a-zA-Z0-9_!§$()=\-^°]+/g;
|
|
41
41
|
const MATCH_PADDED_HYPHENS_REPLACE_REGEX = /^-|-$/g;
|
42
42
|
|
43
43
|
/**
|
44
|
-
* @typedef {
|
44
|
+
* @typedef {object} RenderManifestOptions
|
45
45
|
* @property {Chunk} chunk the chunk used to render
|
46
46
|
* @property {string} hash
|
47
47
|
* @property {string} fullHash
|
@@ -57,7 +57,7 @@ const MATCH_PADDED_HYPHENS_REPLACE_REGEX = /^-|-$/g;
|
|
57
57
|
/** @typedef {RenderManifestEntryTemplated | RenderManifestEntryStatic} RenderManifestEntry */
|
58
58
|
|
59
59
|
/**
|
60
|
-
* @typedef {
|
60
|
+
* @typedef {object} RenderManifestEntryTemplated
|
61
61
|
* @property {function(): Source} render
|
62
62
|
* @property {string | function(PathData, AssetInfo=): string} filenameTemplate
|
63
63
|
* @property {PathData=} pathOptions
|
@@ -68,7 +68,7 @@ const MATCH_PADDED_HYPHENS_REPLACE_REGEX = /^-|-$/g;
|
|
68
68
|
*/
|
69
69
|
|
70
70
|
/**
|
71
|
-
* @typedef {
|
71
|
+
* @typedef {object} RenderManifestEntryStatic
|
72
72
|
* @property {function(): Source} render
|
73
73
|
* @property {string} filename
|
74
74
|
* @property {AssetInfo} info
|
@@ -78,7 +78,7 @@ const MATCH_PADDED_HYPHENS_REPLACE_REGEX = /^-|-$/g;
|
|
78
78
|
*/
|
79
79
|
|
80
80
|
/**
|
81
|
-
* @typedef {
|
81
|
+
* @typedef {object} HasId
|
82
82
|
* @property {number | string} id
|
83
83
|
*/
|
84
84
|
|
@@ -252,7 +252,7 @@ class Template {
|
|
252
252
|
}
|
253
253
|
|
254
254
|
/**
|
255
|
-
* @typedef {
|
255
|
+
* @typedef {object} WithId
|
256
256
|
* @property {string|number} id
|
257
257
|
*/
|
258
258
|
|