webpack 5.90.2 → 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 +263 -94
- package/lib/Compiler.js +199 -83
- package/lib/ConditionalInitFragment.js +4 -5
- package/lib/ContextModule.js +4 -1
- package/lib/ContextModuleFactory.js +4 -2
- package/lib/ContextReplacementPlugin.js +3 -2
- package/lib/CssModule.js +0 -3
- package/lib/DefinePlugin.js +4 -2
- package/lib/DelegatedModule.js +2 -1
- package/lib/Dependency.js +4 -2
- package/lib/DependencyTemplate.js +7 -2
- package/lib/DllModule.js +3 -1
- 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 +120 -25
- 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 +54 -5
- package/lib/ModuleFilenameHelpers.js +1 -1
- package/lib/ModuleGraph.js +56 -27
- package/lib/ModuleGraphConnection.js +2 -1
- package/lib/MultiCompiler.js +61 -17
- package/lib/NodeStuffPlugin.js +14 -3
- package/lib/NormalModule.js +239 -86
- package/lib/NormalModuleFactory.js +163 -32
- package/lib/NormalModuleReplacementPlugin.js +5 -1
- package/lib/ProvidePlugin.js +3 -1
- package/lib/RawModule.js +4 -2
- package/lib/ResolverFactory.js +5 -1
- package/lib/RuntimeModule.js +6 -5
- package/lib/RuntimePlugin.js +1 -0
- package/lib/RuntimeTemplate.js +102 -34
- package/lib/SourceMapDevToolPlugin.js +4 -1
- package/lib/Stats.js +12 -5
- 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 +5 -2
- package/lib/async-modules/AwaitDependenciesInitFragment.js +2 -2
- package/lib/buildChunkGraph.js +220 -392
- 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 +5 -2
- package/lib/container/ContainerPlugin.js +14 -10
- package/lib/container/FallbackModule.js +3 -2
- package/lib/container/RemoteModule.js +2 -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 +21 -10
- 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/WorkerDependency.js +1 -1
- package/lib/dependencies/WorkerPlugin.js +6 -5
- package/lib/dependencies/getFunctionExpression.js +3 -1
- package/lib/esm/ModuleChunkLoadingRuntimeModule.js +2 -1
- package/lib/hmr/LazyCompilationPlugin.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 +140 -55
- 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 +3 -2
- package/lib/sharing/ConsumeSharedPlugin.js +17 -3
- package/lib/sharing/ConsumeSharedRuntimeModule.js +9 -2
- package/lib/sharing/ProvideSharedModule.js +2 -1
- 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/memoize.js +2 -0
- 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/WebAssemblyJavascriptGenerator.js +2 -1
- package/lib/wasm-sync/WebAssemblyParser.js +7 -4
- package/lib/web/JsonpChunkLoadingRuntimeModule.js +2 -1
- package/lib/webpack.js +11 -5
- 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 +1772 -673
package/lib/ContextModule.js
CHANGED
@@ -38,11 +38,13 @@ const makeSerializable = require("./util/makeSerializable");
|
|
38
38
|
/** @typedef {import("./Module").CodeGenerationResult} CodeGenerationResult */
|
39
39
|
/** @typedef {import("./Module").LibIdentOptions} LibIdentOptions */
|
40
40
|
/** @typedef {import("./Module").NeedBuildContext} NeedBuildContext */
|
41
|
+
/** @typedef {import("./Module").SourceTypes} SourceTypes */
|
41
42
|
/** @typedef {import("./ModuleGraph")} ModuleGraph */
|
42
43
|
/** @typedef {import("./RequestShortener")} RequestShortener */
|
43
44
|
/** @typedef {import("./ResolverFactory").ResolverWithOptions} ResolverWithOptions */
|
44
45
|
/** @typedef {import("./RuntimeTemplate")} RuntimeTemplate */
|
45
46
|
/** @typedef {import("./dependencies/ContextElementDependency")} ContextElementDependency */
|
47
|
+
/** @typedef {import("./javascript/JavascriptParser").Attributes} Attributes */
|
46
48
|
/** @typedef {import("./serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
|
47
49
|
/** @typedef {import("./serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
|
48
50
|
/** @template T @typedef {import("./util/LazySet")<T>} LazySet<T> */
|
@@ -65,6 +67,7 @@ const makeSerializable = require("./util/makeSerializable");
|
|
65
67
|
* @property {string=} category
|
66
68
|
* @property {(string[][] | null)=} referencedExports exports referenced from modules (won't be mangled)
|
67
69
|
* @property {string=} layer
|
70
|
+
* @property {Attributes=} attributes
|
68
71
|
*/
|
69
72
|
|
70
73
|
/**
|
@@ -144,7 +147,7 @@ class ContextModule extends Module {
|
|
144
147
|
}
|
145
148
|
|
146
149
|
/**
|
147
|
-
* @returns {
|
150
|
+
* @returns {SourceTypes} types available (do not mutate)
|
148
151
|
*/
|
149
152
|
getSourceTypes() {
|
150
153
|
return TYPES;
|
@@ -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/CssModule.js
CHANGED
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/DelegatedModule.js
CHANGED
@@ -25,6 +25,7 @@ const makeSerializable = require("./util/makeSerializable");
|
|
25
25
|
/** @typedef {import("./Module").LibIdentOptions} LibIdentOptions */
|
26
26
|
/** @typedef {import("./Module").NeedBuildContext} NeedBuildContext */
|
27
27
|
/** @typedef {import("./Module").SourceContext} SourceContext */
|
28
|
+
/** @typedef {import("./Module").SourceTypes} SourceTypes */
|
28
29
|
/** @typedef {import("./RequestShortener")} RequestShortener */
|
29
30
|
/** @typedef {import("./ResolverFactory").ResolverWithOptions} ResolverWithOptions */
|
30
31
|
/** @typedef {import("./RuntimeTemplate")} RuntimeTemplate */
|
@@ -66,7 +67,7 @@ class DelegatedModule extends Module {
|
|
66
67
|
}
|
67
68
|
|
68
69
|
/**
|
69
|
-
* @returns {
|
70
|
+
* @returns {SourceTypes} types available (do not mutate)
|
70
71
|
*/
|
71
72
|
getSourceTypes() {
|
72
73
|
return TYPES;
|
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
@@ -22,6 +22,7 @@ const makeSerializable = require("./util/makeSerializable");
|
|
22
22
|
/** @typedef {import("./Module").CodeGenerationResult} CodeGenerationResult */
|
23
23
|
/** @typedef {import("./Module").NeedBuildContext} NeedBuildContext */
|
24
24
|
/** @typedef {import("./Module").SourceContext} SourceContext */
|
25
|
+
/** @typedef {import("./Module").SourceTypes} SourceTypes */
|
25
26
|
/** @typedef {import("./RequestShortener")} RequestShortener */
|
26
27
|
/** @typedef {import("./ResolverFactory").ResolverWithOptions} ResolverWithOptions */
|
27
28
|
/** @typedef {import("./RuntimeTemplate")} RuntimeTemplate */
|
@@ -47,12 +48,13 @@ class DllModule extends Module {
|
|
47
48
|
super(JAVASCRIPT_MODULE_TYPE_DYNAMIC, context);
|
48
49
|
|
49
50
|
// Info from Factory
|
51
|
+
/** @type {Dependency[]} */
|
50
52
|
this.dependencies = dependencies;
|
51
53
|
this.name = name;
|
52
54
|
}
|
53
55
|
|
54
56
|
/**
|
55
|
-
* @returns {
|
57
|
+
* @returns {SourceTypes} types available (do not mutate)
|
56
58
|
*/
|
57
59
|
getSourceTypes() {
|
58
60
|
return TYPES;
|
@@ -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,17 +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 */
|
40
|
+
/** @typedef {import("./Module").SourceTypes} SourceTypes */
|
41
|
+
/** @typedef {import("./ModuleGraph")} ModuleGraph */
|
37
42
|
/** @typedef {import("./NormalModuleFactory")} NormalModuleFactory */
|
38
43
|
/** @typedef {import("./RequestShortener")} RequestShortener */
|
39
44
|
/** @typedef {import("./ResolverFactory").ResolverWithOptions} ResolverWithOptions */
|
40
45
|
/** @typedef {import("./RuntimeTemplate")} RuntimeTemplate */
|
41
46
|
/** @typedef {import("./WebpackError")} WebpackError */
|
42
47
|
/** @typedef {import("./javascript/JavascriptModulesPlugin").ChunkRenderContext} ChunkRenderContext */
|
48
|
+
/** @typedef {import("./javascript/JavascriptParser").Attributes} Attributes */
|
43
49
|
/** @typedef {import("./serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
|
44
50
|
/** @typedef {import("./serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
|
45
51
|
/** @typedef {import("./util/Hash")} Hash */
|
@@ -47,13 +53,18 @@ const { register } = require("./util/serialization");
|
|
47
53
|
/** @typedef {import("./util/fs").InputFileSystem} InputFileSystem */
|
48
54
|
/** @typedef {import("./util/runtime").RuntimeSpec} RuntimeSpec */
|
49
55
|
|
56
|
+
/** @typedef {{ attributes?: Attributes }} ImportDependencyMeta */
|
57
|
+
/** @typedef {{ layer?: string, supports?: string, media?: string }} CssImportDependencyMeta */
|
58
|
+
|
59
|
+
/** @typedef {ImportDependencyMeta | CssImportDependencyMeta} DependencyMeta */
|
60
|
+
|
50
61
|
/**
|
51
62
|
* @typedef {Object} SourceData
|
52
63
|
* @property {boolean=} iife
|
53
64
|
* @property {string=} init
|
54
65
|
* @property {string} expression
|
55
66
|
* @property {InitFragment<ChunkRenderContext>[]=} chunkInitFragments
|
56
|
-
* @property {
|
67
|
+
* @property {ReadOnlyRuntimeRequirements=} runtimeRequirements
|
57
68
|
*/
|
58
69
|
|
59
70
|
const TYPES = new Set(["javascript"]);
|
@@ -140,43 +151,60 @@ const getSourceForCommonJsExternalInNodeModule = (
|
|
140
151
|
/**
|
141
152
|
* @param {string|string[]} moduleAndSpecifiers the module request
|
142
153
|
* @param {RuntimeTemplate} runtimeTemplate the runtime template
|
154
|
+
* @param {ImportDependencyMeta=} dependencyMeta the dependency meta
|
143
155
|
* @returns {SourceData} the generated source
|
144
156
|
*/
|
145
|
-
const getSourceForImportExternal = (
|
157
|
+
const getSourceForImportExternal = (
|
158
|
+
moduleAndSpecifiers,
|
159
|
+
runtimeTemplate,
|
160
|
+
dependencyMeta
|
161
|
+
) => {
|
146
162
|
const importName = runtimeTemplate.outputOptions.importFunctionName;
|
147
163
|
if (!runtimeTemplate.supportsDynamicImport() && importName === "import") {
|
148
164
|
throw new Error(
|
149
165
|
"The target environment doesn't support 'import()' so it's not possible to use external type 'import'"
|
150
166
|
);
|
151
167
|
}
|
168
|
+
const attributes =
|
169
|
+
dependencyMeta && dependencyMeta.attributes
|
170
|
+
? `, ${JSON.stringify(dependencyMeta.attributes)}`
|
171
|
+
: "";
|
152
172
|
if (!Array.isArray(moduleAndSpecifiers)) {
|
153
173
|
return {
|
154
|
-
expression: `${importName}(${JSON.stringify(
|
174
|
+
expression: `${importName}(${JSON.stringify(
|
175
|
+
moduleAndSpecifiers
|
176
|
+
)}${attributes});`
|
155
177
|
};
|
156
178
|
}
|
157
179
|
if (moduleAndSpecifiers.length === 1) {
|
158
180
|
return {
|
159
|
-
expression: `${importName}(${JSON.stringify(
|
181
|
+
expression: `${importName}(${JSON.stringify(
|
182
|
+
moduleAndSpecifiers[0]
|
183
|
+
)}${attributes});`
|
160
184
|
};
|
161
185
|
}
|
162
186
|
const moduleName = moduleAndSpecifiers[0];
|
163
187
|
return {
|
164
188
|
expression: `${importName}(${JSON.stringify(
|
165
189
|
moduleName
|
166
|
-
)}).then(${runtimeTemplate.returningFunction(
|
190
|
+
)}${attributes}).then(${runtimeTemplate.returningFunction(
|
167
191
|
`module${propertyAccess(moduleAndSpecifiers, 1)}`,
|
168
192
|
"module"
|
169
193
|
)});`
|
170
194
|
};
|
171
195
|
};
|
172
196
|
|
197
|
+
/**
|
198
|
+
* @extends {InitFragment<ChunkRenderContext>}
|
199
|
+
*/
|
173
200
|
class ModuleExternalInitFragment extends InitFragment {
|
174
201
|
/**
|
175
202
|
* @param {string} request import source
|
176
203
|
* @param {string=} ident recomputed ident
|
204
|
+
* @param {ImportDependencyMeta=} dependencyMeta the dependency meta
|
177
205
|
* @param {string | HashConstructor=} hashFunction the hash function to use
|
178
206
|
*/
|
179
|
-
constructor(request, ident, hashFunction = "md4") {
|
207
|
+
constructor(request, ident, dependencyMeta, hashFunction = "md4") {
|
180
208
|
if (ident === undefined) {
|
181
209
|
ident = Template.toIdentifier(request);
|
182
210
|
if (ident !== request) {
|
@@ -188,14 +216,19 @@ class ModuleExternalInitFragment extends InitFragment {
|
|
188
216
|
}
|
189
217
|
const identifier = `__WEBPACK_EXTERNAL_MODULE_${ident}__`;
|
190
218
|
super(
|
191
|
-
`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`,
|
192
224
|
InitFragment.STAGE_HARMONY_IMPORTS,
|
193
225
|
0,
|
194
226
|
`external module import ${ident}`
|
195
227
|
);
|
196
228
|
this._ident = ident;
|
197
|
-
this._identifier = identifier;
|
198
229
|
this._request = request;
|
230
|
+
this._dependencyMeta = request;
|
231
|
+
this._identifier = identifier;
|
199
232
|
}
|
200
233
|
|
201
234
|
getNamespaceIdentifier() {
|
@@ -211,13 +244,21 @@ register(
|
|
211
244
|
serialize(obj, { write }) {
|
212
245
|
write(obj._request);
|
213
246
|
write(obj._ident);
|
247
|
+
write(obj._dependencyMeta);
|
214
248
|
},
|
215
249
|
deserialize({ read }) {
|
216
|
-
return new ModuleExternalInitFragment(read(), read());
|
250
|
+
return new ModuleExternalInitFragment(read(), read(), read());
|
217
251
|
}
|
218
252
|
}
|
219
253
|
);
|
220
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
|
+
*/
|
221
262
|
const generateModuleRemapping = (
|
222
263
|
input,
|
223
264
|
exportsInfo,
|
@@ -241,9 +282,11 @@ const generateModuleRemapping = (
|
|
241
282
|
}
|
242
283
|
}
|
243
284
|
properties.push(
|
244
|
-
`[${JSON.stringify(used)}]: ${
|
245
|
-
|
246
|
-
|
285
|
+
`[${JSON.stringify(used)}]: ${
|
286
|
+
/** @type {RuntimeTemplate} */ (runtimeTemplate).returningFunction(
|
287
|
+
`${input}${propertyAccess([exportInfo.name])}`
|
288
|
+
)
|
289
|
+
}`
|
247
290
|
);
|
248
291
|
}
|
249
292
|
return `x({ ${properties.join(", ")} })`;
|
@@ -255,19 +298,22 @@ const generateModuleRemapping = (
|
|
255
298
|
* @param {ExportsInfo} exportsInfo exports info of this module
|
256
299
|
* @param {RuntimeSpec} runtime the runtime
|
257
300
|
* @param {RuntimeTemplate} runtimeTemplate the runtime template
|
301
|
+
* @param {ImportDependencyMeta} dependencyMeta the dependency meta
|
258
302
|
* @returns {SourceData} the generated source
|
259
303
|
*/
|
260
304
|
const getSourceForModuleExternal = (
|
261
305
|
moduleAndSpecifiers,
|
262
306
|
exportsInfo,
|
263
307
|
runtime,
|
264
|
-
runtimeTemplate
|
308
|
+
runtimeTemplate,
|
309
|
+
dependencyMeta
|
265
310
|
) => {
|
266
311
|
if (!Array.isArray(moduleAndSpecifiers))
|
267
312
|
moduleAndSpecifiers = [moduleAndSpecifiers];
|
268
313
|
const initFragment = new ModuleExternalInitFragment(
|
269
314
|
moduleAndSpecifiers[0],
|
270
315
|
undefined,
|
316
|
+
dependencyMeta,
|
271
317
|
runtimeTemplate.outputOptions.hashFunction
|
272
318
|
);
|
273
319
|
const baseAccess = `${initFragment.getNamespaceIdentifier()}${propertyAccess(
|
@@ -399,10 +445,11 @@ const getSourceForDefaultCase = (optional, request, runtimeTemplate) => {
|
|
399
445
|
class ExternalModule extends Module {
|
400
446
|
/**
|
401
447
|
* @param {string | string[] | Record<string, string | string[]>} request request
|
402
|
-
* @param {
|
448
|
+
* @param {string} type type
|
403
449
|
* @param {string} userRequest user request
|
450
|
+
* @param {DependencyMeta=} dependencyMeta dependency meta
|
404
451
|
*/
|
405
|
-
constructor(request, type, userRequest) {
|
452
|
+
constructor(request, type, userRequest, dependencyMeta) {
|
406
453
|
super(JAVASCRIPT_MODULE_TYPE_DYNAMIC, null);
|
407
454
|
|
408
455
|
// Info from Factory
|
@@ -412,10 +459,12 @@ class ExternalModule extends Module {
|
|
412
459
|
this.externalType = type;
|
413
460
|
/** @type {string} */
|
414
461
|
this.userRequest = userRequest;
|
462
|
+
/** @type {DependencyMeta=} */
|
463
|
+
this.dependencyMeta = dependencyMeta;
|
415
464
|
}
|
416
465
|
|
417
466
|
/**
|
418
|
-
* @returns {
|
467
|
+
* @returns {SourceTypes} types available (do not mutate)
|
419
468
|
*/
|
420
469
|
getSourceTypes() {
|
421
470
|
return this.externalType === "css-import" ? CSS_TYPES : TYPES;
|
@@ -548,6 +597,11 @@ class ExternalModule extends Module {
|
|
548
597
|
callback();
|
549
598
|
}
|
550
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
|
+
*/
|
551
605
|
restoreFromUnsafeCache(unsafeCacheData, normalModuleFactory) {
|
552
606
|
this._restoreFromUnsafeCache(unsafeCacheData, normalModuleFactory);
|
553
607
|
}
|
@@ -576,13 +630,25 @@ class ExternalModule extends Module {
|
|
576
630
|
return { request, externalType };
|
577
631
|
}
|
578
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
|
+
*/
|
579
644
|
_getSourceData(
|
580
645
|
request,
|
581
646
|
externalType,
|
582
647
|
runtimeTemplate,
|
583
648
|
moduleGraph,
|
584
649
|
chunkGraph,
|
585
|
-
runtime
|
650
|
+
runtime,
|
651
|
+
dependencyMeta
|
586
652
|
) {
|
587
653
|
switch (externalType) {
|
588
654
|
case "this":
|
@@ -600,10 +666,12 @@ class ExternalModule extends Module {
|
|
600
666
|
case "commonjs-static":
|
601
667
|
return getSourceForCommonJsExternal(request);
|
602
668
|
case "node-commonjs":
|
603
|
-
return this.buildInfo.module
|
669
|
+
return /** @type {BuildInfo} */ (this.buildInfo).module
|
604
670
|
? getSourceForCommonJsExternalInNodeModule(
|
605
671
|
request,
|
606
|
-
|
672
|
+
/** @type {string} */ (
|
673
|
+
runtimeTemplate.outputOptions.importMetaName
|
674
|
+
)
|
607
675
|
)
|
608
676
|
: getSourceForCommonJsExternal(request);
|
609
677
|
case "amd":
|
@@ -621,11 +689,15 @@ class ExternalModule extends Module {
|
|
621
689
|
);
|
622
690
|
}
|
623
691
|
case "import":
|
624
|
-
return getSourceForImportExternal(
|
692
|
+
return getSourceForImportExternal(
|
693
|
+
request,
|
694
|
+
runtimeTemplate,
|
695
|
+
/** @type {ImportDependencyMeta} */ (dependencyMeta)
|
696
|
+
);
|
625
697
|
case "script":
|
626
698
|
return getSourceForScriptExternal(request, runtimeTemplate);
|
627
699
|
case "module": {
|
628
|
-
if (!this.buildInfo.module) {
|
700
|
+
if (!(/** @type {BuildInfo} */ (this.buildInfo).module)) {
|
629
701
|
if (!runtimeTemplate.supportsDynamicImport()) {
|
630
702
|
throw new Error(
|
631
703
|
"The target environment doesn't support dynamic import() syntax so it's not possible to use external type 'module' within a script" +
|
@@ -634,7 +706,11 @@ class ExternalModule extends Module {
|
|
634
706
|
: "")
|
635
707
|
);
|
636
708
|
}
|
637
|
-
return getSourceForImportExternal(
|
709
|
+
return getSourceForImportExternal(
|
710
|
+
request,
|
711
|
+
runtimeTemplate,
|
712
|
+
/** @type {ImportDependencyMeta} */ (dependencyMeta)
|
713
|
+
);
|
638
714
|
}
|
639
715
|
if (!runtimeTemplate.supportsEcmaScriptModuleSyntax()) {
|
640
716
|
throw new Error(
|
@@ -645,7 +721,8 @@ class ExternalModule extends Module {
|
|
645
721
|
request,
|
646
722
|
moduleGraph.getExportsInfo(this),
|
647
723
|
runtime,
|
648
|
-
runtimeTemplate
|
724
|
+
runtimeTemplate,
|
725
|
+
/** @type {ImportDependencyMeta} */ (dependencyMeta)
|
649
726
|
);
|
650
727
|
}
|
651
728
|
case "var":
|
@@ -687,9 +764,24 @@ class ExternalModule extends Module {
|
|
687
764
|
}
|
688
765
|
case "css-import": {
|
689
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}` : "";
|
690
778
|
sources.set(
|
691
779
|
"css-import",
|
692
|
-
new RawSource(
|
780
|
+
new RawSource(
|
781
|
+
`@import url(${JSON.stringify(
|
782
|
+
request
|
783
|
+
)})${layer}${supports}${media};`
|
784
|
+
)
|
693
785
|
);
|
694
786
|
return {
|
695
787
|
sources,
|
@@ -703,7 +795,8 @@ class ExternalModule extends Module {
|
|
703
795
|
runtimeTemplate,
|
704
796
|
moduleGraph,
|
705
797
|
chunkGraph,
|
706
|
-
runtime
|
798
|
+
runtime,
|
799
|
+
this.dependencyMeta
|
707
800
|
);
|
708
801
|
|
709
802
|
let sourceString = sourceData.expression;
|
@@ -791,6 +884,7 @@ class ExternalModule extends Module {
|
|
791
884
|
write(this.request);
|
792
885
|
write(this.externalType);
|
793
886
|
write(this.userRequest);
|
887
|
+
write(this.dependencyMeta);
|
794
888
|
|
795
889
|
super.serialize(context);
|
796
890
|
}
|
@@ -804,6 +898,7 @@ class ExternalModule extends Module {
|
|
804
898
|
this.request = read();
|
805
899
|
this.externalType = read();
|
806
900
|
this.userRequest = read();
|
901
|
+
this.dependencyMeta = read();
|
807
902
|
|
808
903
|
super.deserialize(context);
|
809
904
|
}
|