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
@@ -289,7 +289,8 @@ module.exports = class ContextModuleFactory extends ModuleFactory {
|
|
289
289
|
exclude,
|
290
290
|
referencedExports,
|
291
291
|
category,
|
292
|
-
typePrefix
|
292
|
+
typePrefix,
|
293
|
+
attributes
|
293
294
|
} = options;
|
294
295
|
if (!regExp || !resource) return callback(null, []);
|
295
296
|
|
@@ -365,7 +366,8 @@ module.exports = class ContextModuleFactory extends ModuleFactory {
|
|
365
366
|
typePrefix,
|
366
367
|
category,
|
367
368
|
referencedExports,
|
368
|
-
obj.context
|
369
|
+
obj.context,
|
370
|
+
attributes
|
369
371
|
);
|
370
372
|
dep.optional = true;
|
371
373
|
return dep;
|
@@ -9,6 +9,7 @@ const ContextElementDependency = require("./dependencies/ContextElementDependenc
|
|
9
9
|
const { join } = require("./util/fs");
|
10
10
|
|
11
11
|
/** @typedef {import("./Compiler")} Compiler */
|
12
|
+
/** @typedef {import("./util/fs").InputFileSystem} InputFileSystem */
|
12
13
|
|
13
14
|
class ContextReplacementPlugin {
|
14
15
|
/**
|
@@ -104,7 +105,7 @@ class ContextReplacementPlugin {
|
|
104
105
|
result.resource = newContentResource;
|
105
106
|
} else {
|
106
107
|
result.resource = join(
|
107
|
-
compiler.inputFileSystem,
|
108
|
+
/** @type {InputFileSystem} */ (compiler.inputFileSystem),
|
108
109
|
result.resource,
|
109
110
|
newContentResource
|
110
111
|
);
|
@@ -132,7 +133,7 @@ class ContextReplacementPlugin {
|
|
132
133
|
) {
|
133
134
|
// When the function changed it to an relative path
|
134
135
|
result.resource = join(
|
135
|
-
compiler.inputFileSystem,
|
136
|
+
/** @type {InputFileSystem} */ (compiler.inputFileSystem),
|
136
137
|
origResource,
|
137
138
|
result.resource
|
138
139
|
);
|
package/lib/DefinePlugin.js
CHANGED
@@ -308,8 +308,10 @@ const PLUGIN_NAME = "DefinePlugin";
|
|
308
308
|
const VALUE_DEP_PREFIX = `webpack/${PLUGIN_NAME} `;
|
309
309
|
const VALUE_DEP_MAIN = `webpack/${PLUGIN_NAME}_hash`;
|
310
310
|
const TYPEOF_OPERATOR_REGEXP = /^typeof\s+/;
|
311
|
-
const WEBPACK_REQUIRE_FUNCTION_REGEXP =
|
312
|
-
|
311
|
+
const WEBPACK_REQUIRE_FUNCTION_REGEXP = new RegExp(
|
312
|
+
`${RuntimeGlobals.require}\\s*(!?\\.)`
|
313
|
+
);
|
314
|
+
const WEBPACK_REQUIRE_IDENTIFIER_REGEXP = new RegExp(RuntimeGlobals.require);
|
313
315
|
|
314
316
|
class DefinePlugin {
|
315
317
|
/**
|
package/lib/Dependency.js
CHANGED
@@ -5,6 +5,7 @@
|
|
5
5
|
|
6
6
|
"use strict";
|
7
7
|
|
8
|
+
const RawModule = require("./RawModule");
|
8
9
|
const memoize = require("./util/memoize");
|
9
10
|
|
10
11
|
/** @typedef {import("webpack-sources").Source} Source */
|
@@ -80,10 +81,11 @@ const memoize = require("./util/memoize");
|
|
80
81
|
* @property {boolean=} canMangle when false, referenced export can not be mangled, defaults to true
|
81
82
|
*/
|
82
83
|
|
84
|
+
/** @typedef {function(ModuleGraphConnection, RuntimeSpec): ConnectionState} GetConditionFn */
|
85
|
+
|
83
86
|
const TRANSITIVE = Symbol("transitive");
|
84
87
|
|
85
88
|
const getIgnoredModule = memoize(() => {
|
86
|
-
const RawModule = require("./RawModule");
|
87
89
|
return new RawModule("/* (ignored) */", `ignored`, `(ignored)`);
|
88
90
|
});
|
89
91
|
|
@@ -235,7 +237,7 @@ class Dependency {
|
|
235
237
|
|
236
238
|
/**
|
237
239
|
* @param {ModuleGraph} moduleGraph module graph
|
238
|
-
* @returns {null | false |
|
240
|
+
* @returns {null | false | GetConditionFn} function to determine if the connection is active
|
239
241
|
*/
|
240
242
|
getCondition(moduleGraph) {
|
241
243
|
return null;
|
@@ -13,18 +13,23 @@
|
|
13
13
|
/** @typedef {import("./Dependency").RuntimeSpec} RuntimeSpec */
|
14
14
|
/** @typedef {import("./DependencyTemplates")} DependencyTemplates */
|
15
15
|
/** @typedef {import("./Generator").GenerateContext} GenerateContext */
|
16
|
-
/** @template T @typedef {import("./InitFragment")<T>} InitFragment */
|
17
16
|
/** @typedef {import("./Module")} Module */
|
17
|
+
/** @typedef {import("./Module").RuntimeRequirements} RuntimeRequirements */
|
18
18
|
/** @typedef {import("./ModuleGraph")} ModuleGraph */
|
19
19
|
/** @typedef {import("./RuntimeTemplate")} RuntimeTemplate */
|
20
20
|
|
21
|
+
/**
|
22
|
+
* @template T
|
23
|
+
* @typedef {import("./InitFragment")<T>} InitFragment
|
24
|
+
*/
|
25
|
+
|
21
26
|
/**
|
22
27
|
* @typedef {Object} DependencyTemplateContext
|
23
28
|
* @property {RuntimeTemplate} runtimeTemplate the runtime template
|
24
29
|
* @property {DependencyTemplates} dependencyTemplates the dependency templates
|
25
30
|
* @property {ModuleGraph} moduleGraph the module graph
|
26
31
|
* @property {ChunkGraph} chunkGraph the chunk graph
|
27
|
-
* @property {
|
32
|
+
* @property {RuntimeRequirements} runtimeRequirements the requirements for runtime
|
28
33
|
* @property {Module} module current module
|
29
34
|
* @property {RuntimeSpec} runtime current runtime, for which code is generated
|
30
35
|
* @property {RuntimeSpec[]} [runtimes] current runtimes, for which code is generated
|
package/lib/DllModule.js
CHANGED
@@ -17,6 +17,7 @@ const makePathsRelative = require("./util/identifier").makePathsRelative;
|
|
17
17
|
/** @typedef {import("../declarations/plugins/DllReferencePlugin").DllReferencePluginOptions} DllReferencePluginOptions */
|
18
18
|
/** @typedef {import("../declarations/plugins/DllReferencePlugin").DllReferencePluginOptionsManifest} DllReferencePluginOptionsManifest */
|
19
19
|
/** @typedef {import("./Compiler")} Compiler */
|
20
|
+
/** @typedef {import("./util/fs").InputFileSystem} InputFileSystem */
|
20
21
|
|
21
22
|
const validate = createSchemaValidation(
|
22
23
|
require("../schemas/plugins/DllReferencePlugin.check.js"),
|
@@ -60,7 +61,8 @@ class DllReferencePlugin {
|
|
60
61
|
if ("manifest" in this.options) {
|
61
62
|
const manifest = this.options.manifest;
|
62
63
|
if (typeof manifest === "string") {
|
63
|
-
|
64
|
+
/** @type {InputFileSystem} */
|
65
|
+
(compiler.inputFileSystem).readFile(manifest, (err, result) => {
|
64
66
|
if (err) return callback(err);
|
65
67
|
const data = {
|
66
68
|
path: manifest,
|
@@ -70,7 +72,9 @@ class DllReferencePlugin {
|
|
70
72
|
// Catch errors parsing the manifest so that blank
|
71
73
|
// or malformed manifest files don't kill the process.
|
72
74
|
try {
|
73
|
-
data.data = parseJson(
|
75
|
+
data.data = parseJson(
|
76
|
+
/** @type {Buffer} */ (result).toString("utf-8")
|
77
|
+
);
|
74
78
|
} catch (e) {
|
75
79
|
// Store the error in the params so that it can
|
76
80
|
// be added as a compilation error later on.
|
package/lib/EntryOptionPlugin.js
CHANGED
@@ -41,7 +41,10 @@ class EntryOptionPlugin {
|
|
41
41
|
name,
|
42
42
|
desc
|
43
43
|
);
|
44
|
-
|
44
|
+
const descImport =
|
45
|
+
/** @type {Exclude<EntryDescription["import"], undefined>} */
|
46
|
+
(desc.import);
|
47
|
+
for (const entry of descImport) {
|
45
48
|
new EntryPlugin(context, entry, options).apply(compiler);
|
46
49
|
}
|
47
50
|
}
|
package/lib/EntryPlugin.js
CHANGED
@@ -59,7 +59,12 @@ class EntryPlugin {
|
|
59
59
|
static createDependency(entry, options) {
|
60
60
|
const dep = new EntryDependency(entry);
|
61
61
|
// TODO webpack 6 remove string option
|
62
|
-
dep.loc = {
|
62
|
+
dep.loc = {
|
63
|
+
name:
|
64
|
+
typeof options === "object"
|
65
|
+
? /** @type {string} */ (options.name)
|
66
|
+
: options
|
67
|
+
};
|
63
68
|
return dep;
|
64
69
|
}
|
65
70
|
}
|
package/lib/Entrypoint.js
CHANGED
@@ -89,7 +89,7 @@ class Entrypoint extends ChunkGroup {
|
|
89
89
|
/**
|
90
90
|
* @param {Chunk} oldChunk chunk to be replaced
|
91
91
|
* @param {Chunk} newChunk New chunk that will be replaced with
|
92
|
-
* @returns {boolean} returns true if the replacement was successful
|
92
|
+
* @returns {boolean | undefined} returns true if the replacement was successful
|
93
93
|
*/
|
94
94
|
replaceChunk(oldChunk, newChunk) {
|
95
95
|
if (this._runtimeChunk === oldChunk) this._runtimeChunk = newChunk;
|
package/lib/ExportsInfo.js
CHANGED
@@ -207,9 +207,6 @@ class ExportsInfo {
|
|
207
207
|
this._redirectTo.setHasUseInfo();
|
208
208
|
} else {
|
209
209
|
this._otherExportsInfo.setHasUseInfo();
|
210
|
-
if (this._otherExportsInfo.canMangleUse === undefined) {
|
211
|
-
this._otherExportsInfo.canMangleUse = true;
|
212
|
-
}
|
213
210
|
}
|
214
211
|
}
|
215
212
|
|
@@ -670,7 +667,7 @@ class ExportsInfo {
|
|
670
667
|
}
|
671
668
|
|
672
669
|
/**
|
673
|
-
* @param {string | string[]} name the export name
|
670
|
+
* @param {string | string[] | undefined} name the export name
|
674
671
|
* @param {RuntimeSpec} runtime check usage for this runtime only
|
675
672
|
* @returns {string | string[] | false} the used name
|
676
673
|
*/
|
package/lib/ExternalModule.js
CHANGED
@@ -29,18 +29,23 @@ const { register } = require("./util/serialization");
|
|
29
29
|
/** @typedef {import("./Dependency").UpdateHashContext} UpdateHashContext */
|
30
30
|
/** @typedef {import("./DependencyTemplates")} DependencyTemplates */
|
31
31
|
/** @typedef {import("./ExportsInfo")} ExportsInfo */
|
32
|
+
/** @typedef {import("./Generator").GenerateContext} GenerateContext */
|
33
|
+
/** @typedef {import("./Module").BuildInfo} BuildInfo */
|
32
34
|
/** @typedef {import("./Module").CodeGenerationContext} CodeGenerationContext */
|
33
35
|
/** @typedef {import("./Module").CodeGenerationResult} CodeGenerationResult */
|
34
36
|
/** @typedef {import("./Module").ConcatenationBailoutReasonContext} ConcatenationBailoutReasonContext */
|
35
37
|
/** @typedef {import("./Module").LibIdentOptions} LibIdentOptions */
|
36
38
|
/** @typedef {import("./Module").NeedBuildContext} NeedBuildContext */
|
39
|
+
/** @typedef {import("./Module").ReadOnlyRuntimeRequirements} ReadOnlyRuntimeRequirements */
|
37
40
|
/** @typedef {import("./Module").SourceTypes} SourceTypes */
|
41
|
+
/** @typedef {import("./ModuleGraph")} ModuleGraph */
|
38
42
|
/** @typedef {import("./NormalModuleFactory")} NormalModuleFactory */
|
39
43
|
/** @typedef {import("./RequestShortener")} RequestShortener */
|
40
44
|
/** @typedef {import("./ResolverFactory").ResolverWithOptions} ResolverWithOptions */
|
41
45
|
/** @typedef {import("./RuntimeTemplate")} RuntimeTemplate */
|
42
46
|
/** @typedef {import("./WebpackError")} WebpackError */
|
43
47
|
/** @typedef {import("./javascript/JavascriptModulesPlugin").ChunkRenderContext} ChunkRenderContext */
|
48
|
+
/** @typedef {import("./javascript/JavascriptParser").Attributes} Attributes */
|
44
49
|
/** @typedef {import("./serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
|
45
50
|
/** @typedef {import("./serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
|
46
51
|
/** @typedef {import("./util/Hash")} Hash */
|
@@ -48,13 +53,18 @@ const { register } = require("./util/serialization");
|
|
48
53
|
/** @typedef {import("./util/fs").InputFileSystem} InputFileSystem */
|
49
54
|
/** @typedef {import("./util/runtime").RuntimeSpec} RuntimeSpec */
|
50
55
|
|
56
|
+
/** @typedef {{ attributes?: Attributes }} ImportDependencyMeta */
|
57
|
+
/** @typedef {{ layer?: string, supports?: string, media?: string }} CssImportDependencyMeta */
|
58
|
+
|
59
|
+
/** @typedef {ImportDependencyMeta | CssImportDependencyMeta} DependencyMeta */
|
60
|
+
|
51
61
|
/**
|
52
62
|
* @typedef {Object} SourceData
|
53
63
|
* @property {boolean=} iife
|
54
64
|
* @property {string=} init
|
55
65
|
* @property {string} expression
|
56
66
|
* @property {InitFragment<ChunkRenderContext>[]=} chunkInitFragments
|
57
|
-
* @property {
|
67
|
+
* @property {ReadOnlyRuntimeRequirements=} runtimeRequirements
|
58
68
|
*/
|
59
69
|
|
60
70
|
const TYPES = new Set(["javascript"]);
|
@@ -141,43 +151,60 @@ const getSourceForCommonJsExternalInNodeModule = (
|
|
141
151
|
/**
|
142
152
|
* @param {string|string[]} moduleAndSpecifiers the module request
|
143
153
|
* @param {RuntimeTemplate} runtimeTemplate the runtime template
|
154
|
+
* @param {ImportDependencyMeta=} dependencyMeta the dependency meta
|
144
155
|
* @returns {SourceData} the generated source
|
145
156
|
*/
|
146
|
-
const getSourceForImportExternal = (
|
157
|
+
const getSourceForImportExternal = (
|
158
|
+
moduleAndSpecifiers,
|
159
|
+
runtimeTemplate,
|
160
|
+
dependencyMeta
|
161
|
+
) => {
|
147
162
|
const importName = runtimeTemplate.outputOptions.importFunctionName;
|
148
163
|
if (!runtimeTemplate.supportsDynamicImport() && importName === "import") {
|
149
164
|
throw new Error(
|
150
165
|
"The target environment doesn't support 'import()' so it's not possible to use external type 'import'"
|
151
166
|
);
|
152
167
|
}
|
168
|
+
const attributes =
|
169
|
+
dependencyMeta && dependencyMeta.attributes
|
170
|
+
? `, ${JSON.stringify(dependencyMeta.attributes)}`
|
171
|
+
: "";
|
153
172
|
if (!Array.isArray(moduleAndSpecifiers)) {
|
154
173
|
return {
|
155
|
-
expression: `${importName}(${JSON.stringify(
|
174
|
+
expression: `${importName}(${JSON.stringify(
|
175
|
+
moduleAndSpecifiers
|
176
|
+
)}${attributes});`
|
156
177
|
};
|
157
178
|
}
|
158
179
|
if (moduleAndSpecifiers.length === 1) {
|
159
180
|
return {
|
160
|
-
expression: `${importName}(${JSON.stringify(
|
181
|
+
expression: `${importName}(${JSON.stringify(
|
182
|
+
moduleAndSpecifiers[0]
|
183
|
+
)}${attributes});`
|
161
184
|
};
|
162
185
|
}
|
163
186
|
const moduleName = moduleAndSpecifiers[0];
|
164
187
|
return {
|
165
188
|
expression: `${importName}(${JSON.stringify(
|
166
189
|
moduleName
|
167
|
-
)}).then(${runtimeTemplate.returningFunction(
|
190
|
+
)}${attributes}).then(${runtimeTemplate.returningFunction(
|
168
191
|
`module${propertyAccess(moduleAndSpecifiers, 1)}`,
|
169
192
|
"module"
|
170
193
|
)});`
|
171
194
|
};
|
172
195
|
};
|
173
196
|
|
197
|
+
/**
|
198
|
+
* @extends {InitFragment<ChunkRenderContext>}
|
199
|
+
*/
|
174
200
|
class ModuleExternalInitFragment extends InitFragment {
|
175
201
|
/**
|
176
202
|
* @param {string} request import source
|
177
203
|
* @param {string=} ident recomputed ident
|
204
|
+
* @param {ImportDependencyMeta=} dependencyMeta the dependency meta
|
178
205
|
* @param {string | HashConstructor=} hashFunction the hash function to use
|
179
206
|
*/
|
180
|
-
constructor(request, ident, hashFunction = "md4") {
|
207
|
+
constructor(request, ident, dependencyMeta, hashFunction = "md4") {
|
181
208
|
if (ident === undefined) {
|
182
209
|
ident = Template.toIdentifier(request);
|
183
210
|
if (ident !== request) {
|
@@ -189,14 +216,19 @@ class ModuleExternalInitFragment extends InitFragment {
|
|
189
216
|
}
|
190
217
|
const identifier = `__WEBPACK_EXTERNAL_MODULE_${ident}__`;
|
191
218
|
super(
|
192
|
-
`import * as ${identifier} from ${JSON.stringify(request)}
|
219
|
+
`import * as ${identifier} from ${JSON.stringify(request)}${
|
220
|
+
dependencyMeta && dependencyMeta.attributes
|
221
|
+
? ` assert ${JSON.stringify(dependencyMeta.attributes)}`
|
222
|
+
: ""
|
223
|
+
};\n`,
|
193
224
|
InitFragment.STAGE_HARMONY_IMPORTS,
|
194
225
|
0,
|
195
226
|
`external module import ${ident}`
|
196
227
|
);
|
197
228
|
this._ident = ident;
|
198
|
-
this._identifier = identifier;
|
199
229
|
this._request = request;
|
230
|
+
this._dependencyMeta = request;
|
231
|
+
this._identifier = identifier;
|
200
232
|
}
|
201
233
|
|
202
234
|
getNamespaceIdentifier() {
|
@@ -212,13 +244,21 @@ register(
|
|
212
244
|
serialize(obj, { write }) {
|
213
245
|
write(obj._request);
|
214
246
|
write(obj._ident);
|
247
|
+
write(obj._dependencyMeta);
|
215
248
|
},
|
216
249
|
deserialize({ read }) {
|
217
|
-
return new ModuleExternalInitFragment(read(), read());
|
250
|
+
return new ModuleExternalInitFragment(read(), read(), read());
|
218
251
|
}
|
219
252
|
}
|
220
253
|
);
|
221
254
|
|
255
|
+
/**
|
256
|
+
* @param {string} input input
|
257
|
+
* @param {ExportsInfo} exportsInfo the exports info
|
258
|
+
* @param {RuntimeSpec=} runtime the runtime
|
259
|
+
* @param {RuntimeTemplate=} runtimeTemplate the runtime template
|
260
|
+
* @returns {string | undefined} the module remapping
|
261
|
+
*/
|
222
262
|
const generateModuleRemapping = (
|
223
263
|
input,
|
224
264
|
exportsInfo,
|
@@ -242,9 +282,11 @@ const generateModuleRemapping = (
|
|
242
282
|
}
|
243
283
|
}
|
244
284
|
properties.push(
|
245
|
-
`[${JSON.stringify(used)}]: ${
|
246
|
-
|
247
|
-
|
285
|
+
`[${JSON.stringify(used)}]: ${
|
286
|
+
/** @type {RuntimeTemplate} */ (runtimeTemplate).returningFunction(
|
287
|
+
`${input}${propertyAccess([exportInfo.name])}`
|
288
|
+
)
|
289
|
+
}`
|
248
290
|
);
|
249
291
|
}
|
250
292
|
return `x({ ${properties.join(", ")} })`;
|
@@ -256,19 +298,22 @@ const generateModuleRemapping = (
|
|
256
298
|
* @param {ExportsInfo} exportsInfo exports info of this module
|
257
299
|
* @param {RuntimeSpec} runtime the runtime
|
258
300
|
* @param {RuntimeTemplate} runtimeTemplate the runtime template
|
301
|
+
* @param {ImportDependencyMeta} dependencyMeta the dependency meta
|
259
302
|
* @returns {SourceData} the generated source
|
260
303
|
*/
|
261
304
|
const getSourceForModuleExternal = (
|
262
305
|
moduleAndSpecifiers,
|
263
306
|
exportsInfo,
|
264
307
|
runtime,
|
265
|
-
runtimeTemplate
|
308
|
+
runtimeTemplate,
|
309
|
+
dependencyMeta
|
266
310
|
) => {
|
267
311
|
if (!Array.isArray(moduleAndSpecifiers))
|
268
312
|
moduleAndSpecifiers = [moduleAndSpecifiers];
|
269
313
|
const initFragment = new ModuleExternalInitFragment(
|
270
314
|
moduleAndSpecifiers[0],
|
271
315
|
undefined,
|
316
|
+
dependencyMeta,
|
272
317
|
runtimeTemplate.outputOptions.hashFunction
|
273
318
|
);
|
274
319
|
const baseAccess = `${initFragment.getNamespaceIdentifier()}${propertyAccess(
|
@@ -400,10 +445,11 @@ const getSourceForDefaultCase = (optional, request, runtimeTemplate) => {
|
|
400
445
|
class ExternalModule extends Module {
|
401
446
|
/**
|
402
447
|
* @param {string | string[] | Record<string, string | string[]>} request request
|
403
|
-
* @param {
|
448
|
+
* @param {string} type type
|
404
449
|
* @param {string} userRequest user request
|
450
|
+
* @param {DependencyMeta=} dependencyMeta dependency meta
|
405
451
|
*/
|
406
|
-
constructor(request, type, userRequest) {
|
452
|
+
constructor(request, type, userRequest, dependencyMeta) {
|
407
453
|
super(JAVASCRIPT_MODULE_TYPE_DYNAMIC, null);
|
408
454
|
|
409
455
|
// Info from Factory
|
@@ -413,6 +459,8 @@ class ExternalModule extends Module {
|
|
413
459
|
this.externalType = type;
|
414
460
|
/** @type {string} */
|
415
461
|
this.userRequest = userRequest;
|
462
|
+
/** @type {DependencyMeta=} */
|
463
|
+
this.dependencyMeta = dependencyMeta;
|
416
464
|
}
|
417
465
|
|
418
466
|
/**
|
@@ -549,6 +597,11 @@ class ExternalModule extends Module {
|
|
549
597
|
callback();
|
550
598
|
}
|
551
599
|
|
600
|
+
/**
|
601
|
+
* restore unsafe cache data
|
602
|
+
* @param {object} unsafeCacheData data from getUnsafeCacheData
|
603
|
+
* @param {NormalModuleFactory} normalModuleFactory the normal module factory handling the unsafe caching
|
604
|
+
*/
|
552
605
|
restoreFromUnsafeCache(unsafeCacheData, normalModuleFactory) {
|
553
606
|
this._restoreFromUnsafeCache(unsafeCacheData, normalModuleFactory);
|
554
607
|
}
|
@@ -577,13 +630,25 @@ class ExternalModule extends Module {
|
|
577
630
|
return { request, externalType };
|
578
631
|
}
|
579
632
|
|
633
|
+
/**
|
634
|
+
* @private
|
635
|
+
* @param {string | string[]} request request
|
636
|
+
* @param {string} externalType the external type
|
637
|
+
* @param {RuntimeTemplate} runtimeTemplate the runtime template
|
638
|
+
* @param {ModuleGraph} moduleGraph the module graph
|
639
|
+
* @param {ChunkGraph} chunkGraph the chunk graph
|
640
|
+
* @param {RuntimeSpec} runtime the runtime
|
641
|
+
* @param {DependencyMeta | undefined} dependencyMeta the dependency meta
|
642
|
+
* @returns {SourceData} the source data
|
643
|
+
*/
|
580
644
|
_getSourceData(
|
581
645
|
request,
|
582
646
|
externalType,
|
583
647
|
runtimeTemplate,
|
584
648
|
moduleGraph,
|
585
649
|
chunkGraph,
|
586
|
-
runtime
|
650
|
+
runtime,
|
651
|
+
dependencyMeta
|
587
652
|
) {
|
588
653
|
switch (externalType) {
|
589
654
|
case "this":
|
@@ -601,10 +666,12 @@ class ExternalModule extends Module {
|
|
601
666
|
case "commonjs-static":
|
602
667
|
return getSourceForCommonJsExternal(request);
|
603
668
|
case "node-commonjs":
|
604
|
-
return this.buildInfo.module
|
669
|
+
return /** @type {BuildInfo} */ (this.buildInfo).module
|
605
670
|
? getSourceForCommonJsExternalInNodeModule(
|
606
671
|
request,
|
607
|
-
|
672
|
+
/** @type {string} */ (
|
673
|
+
runtimeTemplate.outputOptions.importMetaName
|
674
|
+
)
|
608
675
|
)
|
609
676
|
: getSourceForCommonJsExternal(request);
|
610
677
|
case "amd":
|
@@ -622,11 +689,15 @@ class ExternalModule extends Module {
|
|
622
689
|
);
|
623
690
|
}
|
624
691
|
case "import":
|
625
|
-
return getSourceForImportExternal(
|
692
|
+
return getSourceForImportExternal(
|
693
|
+
request,
|
694
|
+
runtimeTemplate,
|
695
|
+
/** @type {ImportDependencyMeta} */ (dependencyMeta)
|
696
|
+
);
|
626
697
|
case "script":
|
627
698
|
return getSourceForScriptExternal(request, runtimeTemplate);
|
628
699
|
case "module": {
|
629
|
-
if (!this.buildInfo.module) {
|
700
|
+
if (!(/** @type {BuildInfo} */ (this.buildInfo).module)) {
|
630
701
|
if (!runtimeTemplate.supportsDynamicImport()) {
|
631
702
|
throw new Error(
|
632
703
|
"The target environment doesn't support dynamic import() syntax so it's not possible to use external type 'module' within a script" +
|
@@ -635,7 +706,11 @@ class ExternalModule extends Module {
|
|
635
706
|
: "")
|
636
707
|
);
|
637
708
|
}
|
638
|
-
return getSourceForImportExternal(
|
709
|
+
return getSourceForImportExternal(
|
710
|
+
request,
|
711
|
+
runtimeTemplate,
|
712
|
+
/** @type {ImportDependencyMeta} */ (dependencyMeta)
|
713
|
+
);
|
639
714
|
}
|
640
715
|
if (!runtimeTemplate.supportsEcmaScriptModuleSyntax()) {
|
641
716
|
throw new Error(
|
@@ -646,7 +721,8 @@ class ExternalModule extends Module {
|
|
646
721
|
request,
|
647
722
|
moduleGraph.getExportsInfo(this),
|
648
723
|
runtime,
|
649
|
-
runtimeTemplate
|
724
|
+
runtimeTemplate,
|
725
|
+
/** @type {ImportDependencyMeta} */ (dependencyMeta)
|
650
726
|
);
|
651
727
|
}
|
652
728
|
case "var":
|
@@ -688,9 +764,24 @@ class ExternalModule extends Module {
|
|
688
764
|
}
|
689
765
|
case "css-import": {
|
690
766
|
const sources = new Map();
|
767
|
+
const dependencyMeta = /** @type {CssImportDependencyMeta} */ (
|
768
|
+
this.dependencyMeta
|
769
|
+
);
|
770
|
+
const layer =
|
771
|
+
dependencyMeta.layer !== undefined
|
772
|
+
? ` layer(${dependencyMeta.layer})`
|
773
|
+
: "";
|
774
|
+
const supports = dependencyMeta.supports
|
775
|
+
? ` supports(${dependencyMeta.supports})`
|
776
|
+
: "";
|
777
|
+
const media = dependencyMeta.media ? ` ${dependencyMeta.media}` : "";
|
691
778
|
sources.set(
|
692
779
|
"css-import",
|
693
|
-
new RawSource(
|
780
|
+
new RawSource(
|
781
|
+
`@import url(${JSON.stringify(
|
782
|
+
request
|
783
|
+
)})${layer}${supports}${media};`
|
784
|
+
)
|
694
785
|
);
|
695
786
|
return {
|
696
787
|
sources,
|
@@ -704,7 +795,8 @@ class ExternalModule extends Module {
|
|
704
795
|
runtimeTemplate,
|
705
796
|
moduleGraph,
|
706
797
|
chunkGraph,
|
707
|
-
runtime
|
798
|
+
runtime,
|
799
|
+
this.dependencyMeta
|
708
800
|
);
|
709
801
|
|
710
802
|
let sourceString = sourceData.expression;
|
@@ -792,6 +884,7 @@ class ExternalModule extends Module {
|
|
792
884
|
write(this.request);
|
793
885
|
write(this.externalType);
|
794
886
|
write(this.userRequest);
|
887
|
+
write(this.dependencyMeta);
|
795
888
|
|
796
889
|
super.serialize(context);
|
797
890
|
}
|
@@ -805,6 +898,7 @@ class ExternalModule extends Module {
|
|
805
898
|
this.request = read();
|
806
899
|
this.externalType = read();
|
807
900
|
this.userRequest = read();
|
901
|
+
this.dependencyMeta = read();
|
808
902
|
|
809
903
|
super.deserialize(context);
|
810
904
|
}
|
@@ -7,9 +7,16 @@
|
|
7
7
|
|
8
8
|
const util = require("util");
|
9
9
|
const ExternalModule = require("./ExternalModule");
|
10
|
+
const ContextElementDependency = require("./dependencies/ContextElementDependency");
|
11
|
+
const CssImportDependency = require("./dependencies/CssImportDependency");
|
12
|
+
const HarmonyImportDependency = require("./dependencies/HarmonyImportDependency");
|
13
|
+
const ImportDependency = require("./dependencies/ImportDependency");
|
10
14
|
const { resolveByProperty, cachedSetProperty } = require("./util/cleverMerge");
|
11
15
|
|
12
16
|
/** @typedef {import("../declarations/WebpackOptions").Externals} Externals */
|
17
|
+
/** @typedef {import("./Compilation").DepConstructor} DepConstructor */
|
18
|
+
/** @typedef {import("./ExternalModule").DependencyMeta} DependencyMeta */
|
19
|
+
/** @typedef {import("./Module")} Module */
|
13
20
|
/** @typedef {import("./NormalModuleFactory")} NormalModuleFactory */
|
14
21
|
|
15
22
|
const UNSPECIFIED_EXTERNAL_TYPE_REGEXP = /^[a-z0-9-]+ /;
|
@@ -67,7 +74,7 @@ class ExternalModuleFactoryPlugin {
|
|
67
74
|
/**
|
68
75
|
* @param {string|string[]|boolean|Record<string, string|string[]>} value the external config
|
69
76
|
* @param {string|undefined} type type of external
|
70
|
-
* @param {function(Error=, ExternalModule=): void} callback callback
|
77
|
+
* @param {function((Error | null)=, ExternalModule=): void} callback callback
|
71
78
|
* @returns {void}
|
72
79
|
*/
|
73
80
|
const handleExternal = (value, type, callback) => {
|
@@ -105,12 +112,34 @@ class ExternalModuleFactoryPlugin {
|
|
105
112
|
];
|
106
113
|
}
|
107
114
|
}
|
115
|
+
|
116
|
+
// TODO make it pluggable/add hooks to `ExternalModule` to allow output modules own externals?
|
117
|
+
/** @type {DependencyMeta | undefined} */
|
118
|
+
let dependencyMeta;
|
119
|
+
|
120
|
+
if (
|
121
|
+
dependency instanceof HarmonyImportDependency ||
|
122
|
+
dependency instanceof ImportDependency ||
|
123
|
+
dependency instanceof ContextElementDependency
|
124
|
+
) {
|
125
|
+
dependencyMeta = {
|
126
|
+
attributes: dependency.assertions
|
127
|
+
};
|
128
|
+
} else if (dependency instanceof CssImportDependency) {
|
129
|
+
dependencyMeta = {
|
130
|
+
layer: dependency.layer,
|
131
|
+
supports: dependency.supports,
|
132
|
+
media: dependency.media
|
133
|
+
};
|
134
|
+
}
|
135
|
+
|
108
136
|
callback(
|
109
137
|
null,
|
110
138
|
new ExternalModule(
|
111
139
|
externalConfig,
|
112
140
|
type || globalType,
|
113
|
-
dependency.request
|
141
|
+
dependency.request,
|
142
|
+
dependencyMeta
|
114
143
|
)
|
115
144
|
);
|
116
145
|
};
|
@@ -128,7 +157,13 @@ class ExternalModuleFactoryPlugin {
|
|
128
157
|
} else if (Array.isArray(externals)) {
|
129
158
|
let i = 0;
|
130
159
|
const next = () => {
|
160
|
+
/** @type {boolean | undefined} */
|
131
161
|
let asyncFlag;
|
162
|
+
/**
|
163
|
+
* @param {(Error | null)=} err err
|
164
|
+
* @param {ExternalModule=} module module
|
165
|
+
* @returns {void}
|
166
|
+
*/
|
132
167
|
const handleExternalsAndCallback = (err, module) => {
|
133
168
|
if (err) return callback(err);
|
134
169
|
if (!module) {
|
package/lib/FileSystemInfo.js
CHANGED
package/lib/Generator.js
CHANGED
@@ -13,6 +13,7 @@
|
|
13
13
|
/** @typedef {import("./DependencyTemplate")} DependencyTemplate */
|
14
14
|
/** @typedef {import("./DependencyTemplates")} DependencyTemplates */
|
15
15
|
/** @typedef {import("./Module").ConcatenationBailoutReasonContext} ConcatenationBailoutReasonContext */
|
16
|
+
/** @typedef {import("./Module").RuntimeRequirements} RuntimeRequirements */
|
16
17
|
/** @typedef {import("./ModuleGraph")} ModuleGraph */
|
17
18
|
/** @typedef {import("./NormalModule")} NormalModule */
|
18
19
|
/** @typedef {import("./RuntimeTemplate")} RuntimeTemplate */
|
@@ -25,7 +26,7 @@
|
|
25
26
|
* @property {RuntimeTemplate} runtimeTemplate the runtime template
|
26
27
|
* @property {ModuleGraph} moduleGraph the module graph
|
27
28
|
* @property {ChunkGraph} chunkGraph the chunk graph
|
28
|
-
* @property {
|
29
|
+
* @property {RuntimeRequirements} runtimeRequirements the requirements for runtime
|
29
30
|
* @property {RuntimeSpec} runtime the runtime
|
30
31
|
* @property {RuntimeSpec[]} [runtimes] the runtimes
|
31
32
|
* @property {ConcatenationScope=} concatenationScope when in concatenated module, information about other concatenated modules
|