webpack 5.89.0 → 5.90.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 +3 -0
- package/bin/webpack.js +1 -3
- package/hot/log.js +0 -2
- package/lib/APIPlugin.js +1 -1
- package/lib/ChunkGraph.js +1 -1
- package/lib/CleanPlugin.js +12 -12
- package/lib/Compilation.js +25 -16
- package/lib/Compiler.js +13 -0
- package/lib/ConcatenationScope.js +2 -2
- package/lib/ContextModule.js +4 -4
- package/lib/ContextModuleFactory.js +1 -1
- package/lib/DependencyTemplate.js +3 -1
- package/lib/EnvironmentNotSupportAsyncWarning.js +52 -0
- package/lib/EvalDevToolModulePlugin.js +1 -1
- package/lib/EvalSourceMapDevToolPlugin.js +1 -1
- package/lib/ExportsInfoApiPlugin.js +2 -2
- package/lib/ExternalModule.js +47 -12
- package/lib/ExternalModuleFactoryPlugin.js +1 -1
- package/lib/FileSystemInfo.js +20 -3
- package/lib/FlagDependencyExportsPlugin.js +1 -1
- package/lib/Generator.js +1 -0
- package/lib/HotModuleReplacementPlugin.js +3 -3
- package/lib/LibManifestPlugin.js +4 -1
- package/lib/Module.js +2 -1
- package/lib/ModuleFilenameHelpers.js +1 -1
- package/lib/ModuleInfoHeaderPlugin.js +1 -1
- package/lib/MultiStats.js +2 -2
- package/lib/NodeStuffPlugin.js +48 -0
- package/lib/NormalModule.js +13 -11
- package/lib/NormalModuleFactory.js +7 -7
- package/lib/RuntimeTemplate.js +15 -11
- package/lib/SourceMapDevToolPlugin.js +2 -2
- package/lib/WebpackOptionsApply.js +4 -3
- package/lib/asset/AssetModulesPlugin.js +2 -3
- package/lib/cache/AddManagedPathsPlugin.js +6 -1
- package/lib/cache/IdleFileCachePlugin.js +12 -5
- package/lib/cache/PackFileCacheStrategy.js +3 -3
- package/lib/cache/ResolverCachePlugin.js +2 -2
- package/lib/config/browserslistTargetHandler.js +24 -5
- package/lib/config/defaults.js +87 -52
- package/lib/config/normalization.js +17 -18
- package/lib/config/target.js +5 -0
- package/lib/container/ContainerReferencePlugin.js +1 -1
- package/lib/css/CssExportsGenerator.js +14 -1
- package/lib/css/CssGenerator.js +14 -1
- package/lib/css/CssLoadingRuntimeModule.js +23 -23
- package/lib/css/CssModulesPlugin.js +68 -32
- package/lib/css/CssParser.js +8 -3
- package/lib/debug/ProfilingPlugin.js +2 -2
- package/lib/dependencies/CachedConstDependency.js +8 -1
- package/lib/dependencies/CommonJsImportsParserPlugin.js +1 -1
- package/lib/dependencies/ContextElementDependency.js +1 -1
- package/lib/dependencies/ExternalModuleDependency.js +98 -0
- package/lib/dependencies/ExternalModuleInitFragment.js +124 -0
- package/lib/dependencies/HarmonyAcceptDependency.js +1 -1
- package/lib/dependencies/HarmonyDetectionParserPlugin.js +7 -1
- package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +18 -18
- package/lib/dependencies/HarmonyExportInitFragment.js +4 -4
- package/lib/dependencies/HarmonyImportDependency.js +4 -4
- package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +6 -6
- package/lib/dependencies/ImportDependency.js +26 -6
- package/lib/dependencies/JsonExportsDependency.js +1 -1
- package/lib/dependencies/LoaderPlugin.js +2 -1
- package/lib/dependencies/PureExpressionDependency.js +12 -4
- package/lib/dependencies/RequireIncludeDependency.js +1 -1
- package/lib/dependencies/WebpackIsIncludedDependency.js +1 -1
- package/lib/dependencies/WorkerPlugin.js +7 -1
- package/lib/esm/ModuleChunkLoadingRuntimeModule.js +6 -6
- package/lib/hmr/HotModuleReplacement.runtime.js +3 -5
- package/lib/hmr/lazyCompilationBackend.js +4 -4
- package/lib/ids/DeterministicModuleIdsPlugin.js +1 -1
- package/lib/index.js +4 -0
- package/lib/javascript/JavascriptGenerator.js +16 -1
- package/lib/javascript/JavascriptModulesPlugin.js +33 -33
- package/lib/javascript/JavascriptParser.js +8 -0
- package/lib/json/JsonGenerator.js +1 -1
- package/lib/library/AmdLibraryPlugin.js +5 -1
- package/lib/library/AssignLibraryPlugin.js +1 -1
- package/lib/library/SystemLibraryPlugin.js +1 -1
- package/lib/library/UmdLibraryPlugin.js +39 -39
- package/lib/logging/createConsoleLogger.js +1 -19
- package/lib/node/ReadFileChunkLoadingRuntimeModule.js +8 -8
- package/lib/node/RequireChunkLoadingRuntimeModule.js +8 -8
- package/lib/node/nodeConsole.js +1 -5
- package/lib/optimize/ConcatenatedModule.js +7 -7
- package/lib/optimize/InnerGraphPlugin.js +9 -1
- package/lib/optimize/ModuleConcatenationPlugin.js +2 -2
- package/lib/optimize/RemoveParentModulesPlugin.js +123 -47
- package/lib/optimize/SideEffectsFlagPlugin.js +15 -3
- package/lib/optimize/SplitChunksPlugin.js +16 -16
- package/lib/prefetch/ChunkPrefetchStartupRuntimeModule.js +2 -2
- package/lib/rules/RuleSetCompiler.js +1 -1
- package/lib/runtime/AutoPublicPathRuntimeModule.js +2 -2
- package/lib/runtime/GetChunkFilenameRuntimeModule.js +4 -4
- package/lib/runtime/GetTrustedTypesPolicyRuntimeModule.js +4 -4
- package/lib/runtime/LoadScriptRuntimeModule.js +2 -2
- package/lib/runtime/StartupChunkDependenciesRuntimeModule.js +23 -22
- package/lib/runtime/StartupEntrypointRuntimeModule.js +2 -2
- package/lib/schemes/HttpUriPlugin.js +1 -1
- package/lib/serialization/FileMiddleware.js +4 -4
- package/lib/serialization/ObjectMiddleware.js +4 -4
- package/lib/sharing/ConsumeSharedPlugin.js +5 -5
- package/lib/sharing/ConsumeSharedRuntimeModule.js +8 -4
- package/lib/sharing/ProvideSharedModule.js +2 -2
- package/lib/sharing/SharePlugin.js +2 -2
- package/lib/sharing/ShareRuntimeModule.js +1 -1
- package/lib/sharing/utils.js +24 -28
- package/lib/stats/DefaultStatsFactoryPlugin.js +10 -10
- package/lib/stats/DefaultStatsPresetPlugin.js +3 -7
- package/lib/stats/DefaultStatsPrinterPlugin.js +34 -31
- package/lib/util/cleverMerge.js +4 -4
- package/lib/util/hash/xxhash64.js +2 -2
- package/lib/util/identifier.js +2 -2
- package/lib/util/internalSerializables.js +6 -0
- package/lib/util/runtime.js +18 -1
- package/lib/util/semver.js +19 -24
- package/lib/util/smartGrouping.js +1 -1
- package/lib/wasm-async/AsyncWasmLoadingRuntimeModule.js +1 -1
- package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +2 -2
- package/lib/wasm-async/AsyncWebAssemblyParser.js +6 -0
- package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +2 -2
- package/lib/wasm-sync/WebAssemblyJavascriptGenerator.js +2 -2
- package/lib/web/JsonpChunkLoadingRuntimeModule.js +13 -13
- package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +6 -6
- package/package.json +23 -23
- package/schemas/WebpackOptions.check.js +1 -1
- package/schemas/WebpackOptions.json +140 -32
- package/schemas/plugins/css/CssAutoGeneratorOptions.check.d.ts +7 -0
- package/schemas/plugins/css/CssAutoGeneratorOptions.check.js +6 -0
- package/schemas/plugins/css/CssAutoGeneratorOptions.json +3 -0
- package/schemas/plugins/css/CssAutoParserOptions.check.d.ts +7 -0
- package/schemas/plugins/css/CssAutoParserOptions.check.js +6 -0
- package/schemas/plugins/css/CssAutoParserOptions.json +3 -0
- package/schemas/plugins/css/CssGeneratorOptions.check.js +1 -1
- package/schemas/plugins/css/CssGlobalGeneratorOptions.check.d.ts +7 -0
- package/schemas/plugins/css/CssGlobalGeneratorOptions.check.js +6 -0
- package/schemas/plugins/css/CssGlobalGeneratorOptions.json +3 -0
- package/schemas/plugins/css/CssGlobalParserOptions.check.d.ts +7 -0
- package/schemas/plugins/css/CssGlobalParserOptions.check.js +6 -0
- package/schemas/plugins/css/CssGlobalParserOptions.json +3 -0
- package/schemas/plugins/css/CssModuleGeneratorOptions.check.d.ts +7 -0
- package/schemas/plugins/css/CssModuleGeneratorOptions.check.js +6 -0
- package/schemas/plugins/css/CssModuleGeneratorOptions.json +3 -0
- package/schemas/plugins/css/CssModuleParserOptions.check.d.ts +7 -0
- package/schemas/plugins/css/CssModuleParserOptions.check.js +6 -0
- package/schemas/plugins/css/CssModuleParserOptions.json +3 -0
- package/schemas/plugins/css/CssParserOptions.check.js +1 -1
- package/types.d.ts +172 -20
@@ -33,7 +33,6 @@ const CssGenerator = require("./CssGenerator");
|
|
33
33
|
const CssParser = require("./CssParser");
|
34
34
|
|
35
35
|
/** @typedef {import("webpack-sources").Source} Source */
|
36
|
-
/** @typedef {import("../../declarations/WebpackOptions").CssExperimentOptions} CssExperimentOptions */
|
37
36
|
/** @typedef {import("../../declarations/WebpackOptions").Output} OutputOptions */
|
38
37
|
/** @typedef {import("../Chunk")} Chunk */
|
39
38
|
/** @typedef {import("../ChunkGraph")} ChunkGraph */
|
@@ -59,22 +58,59 @@ const getSchema = name => {
|
|
59
58
|
};
|
60
59
|
};
|
61
60
|
|
62
|
-
const
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
)
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
61
|
+
const generatorValidationOptions = {
|
62
|
+
name: "Css Modules Plugin",
|
63
|
+
baseDataPath: "generator"
|
64
|
+
};
|
65
|
+
const validateGeneratorOptions = {
|
66
|
+
css: createSchemaValidation(
|
67
|
+
require("../../schemas/plugins/css/CssGeneratorOptions.check.js"),
|
68
|
+
() => getSchema("CssGeneratorOptions"),
|
69
|
+
generatorValidationOptions
|
70
|
+
),
|
71
|
+
"css/auto": createSchemaValidation(
|
72
|
+
require("../../schemas/plugins/css/CssAutoGeneratorOptions.check.js"),
|
73
|
+
() => getSchema("CssAutoGeneratorOptions"),
|
74
|
+
generatorValidationOptions
|
75
|
+
),
|
76
|
+
"css/module": createSchemaValidation(
|
77
|
+
require("../../schemas/plugins/css/CssModuleGeneratorOptions.check.js"),
|
78
|
+
() => getSchema("CssModuleGeneratorOptions"),
|
79
|
+
generatorValidationOptions
|
80
|
+
),
|
81
|
+
"css/global": createSchemaValidation(
|
82
|
+
require("../../schemas/plugins/css/CssGlobalGeneratorOptions.check.js"),
|
83
|
+
() => getSchema("CssGlobalGeneratorOptions"),
|
84
|
+
generatorValidationOptions
|
85
|
+
)
|
86
|
+
};
|
87
|
+
|
88
|
+
const parserValidationOptions = {
|
89
|
+
name: "Css Modules Plugin",
|
90
|
+
baseDataPath: "parser"
|
91
|
+
};
|
92
|
+
const validateParserOptions = {
|
93
|
+
css: createSchemaValidation(
|
94
|
+
require("../../schemas/plugins/css/CssParserOptions.check.js"),
|
95
|
+
() => getSchema("CssParserOptions"),
|
96
|
+
parserValidationOptions
|
97
|
+
),
|
98
|
+
"css/auto": createSchemaValidation(
|
99
|
+
require("../../schemas/plugins/css/CssAutoParserOptions.check.js"),
|
100
|
+
() => getSchema("CssAutoParserOptions"),
|
101
|
+
parserValidationOptions
|
102
|
+
),
|
103
|
+
"css/module": createSchemaValidation(
|
104
|
+
require("../../schemas/plugins/css/CssModuleParserOptions.check.js"),
|
105
|
+
() => getSchema("CssModuleParserOptions"),
|
106
|
+
parserValidationOptions
|
107
|
+
),
|
108
|
+
"css/global": createSchemaValidation(
|
109
|
+
require("../../schemas/plugins/css/CssGlobalParserOptions.check.js"),
|
110
|
+
() => getSchema("CssGlobalParserOptions"),
|
111
|
+
parserValidationOptions
|
112
|
+
)
|
113
|
+
};
|
78
114
|
|
79
115
|
/**
|
80
116
|
* @param {string} str string
|
@@ -95,12 +131,6 @@ const escapeCss = (str, omitOptionalUnderscore) => {
|
|
95
131
|
const plugin = "CssModulesPlugin";
|
96
132
|
|
97
133
|
class CssModulesPlugin {
|
98
|
-
/**
|
99
|
-
* @param {CssExperimentOptions} options options
|
100
|
-
*/
|
101
|
-
constructor({ exportsOnly = false }) {
|
102
|
-
this._exportsOnly = exportsOnly;
|
103
|
-
}
|
104
134
|
/**
|
105
135
|
* Apply the plugin
|
106
136
|
* @param {Compiler} compiler the compiler instance
|
@@ -156,27 +186,33 @@ class CssModulesPlugin {
|
|
156
186
|
normalModuleFactory.hooks.createParser
|
157
187
|
.for(type)
|
158
188
|
.tap(plugin, parserOptions => {
|
159
|
-
validateParserOptions(parserOptions);
|
189
|
+
validateParserOptions[type](parserOptions);
|
190
|
+
const { namedExports } = parserOptions;
|
160
191
|
|
161
192
|
switch (type) {
|
162
193
|
case CSS_MODULE_TYPE:
|
163
194
|
case CSS_MODULE_TYPE_AUTO:
|
164
|
-
return new CssParser(
|
195
|
+
return new CssParser({
|
196
|
+
namedExports
|
197
|
+
});
|
165
198
|
case CSS_MODULE_TYPE_GLOBAL:
|
166
199
|
return new CssParser({
|
167
|
-
allowModeSwitch: false
|
200
|
+
allowModeSwitch: false,
|
201
|
+
namedExports
|
168
202
|
});
|
169
203
|
case CSS_MODULE_TYPE_MODULE:
|
170
204
|
return new CssParser({
|
171
|
-
defaultMode: "local"
|
205
|
+
defaultMode: "local",
|
206
|
+
namedExports
|
172
207
|
});
|
173
208
|
}
|
174
209
|
});
|
175
210
|
normalModuleFactory.hooks.createGenerator
|
176
211
|
.for(type)
|
177
212
|
.tap(plugin, generatorOptions => {
|
178
|
-
validateGeneratorOptions(generatorOptions);
|
179
|
-
|
213
|
+
validateGeneratorOptions[type](generatorOptions);
|
214
|
+
|
215
|
+
return generatorOptions.exportsOnly
|
180
216
|
? new CssExportsGenerator()
|
181
217
|
: new CssGenerator();
|
182
218
|
});
|
@@ -589,9 +625,9 @@ class CssModulesPlugin {
|
|
589
625
|
return v === shortcutValue
|
590
626
|
? `${escapeCss(n)}/`
|
591
627
|
: v === "--" + shortcutValue
|
592
|
-
|
593
|
-
|
594
|
-
|
628
|
+
? `${escapeCss(n)}%`
|
629
|
+
: `${escapeCss(n)}(${escapeCss(v)})`;
|
630
|
+
}).join("")
|
595
631
|
: ""
|
596
632
|
}${escapeCss(moduleId)}`
|
597
633
|
);
|
package/lib/css/CssParser.js
CHANGED
@@ -131,10 +131,15 @@ const CSS_MODE_AT_IMPORT_INVALID = 3;
|
|
131
131
|
const CSS_MODE_AT_NAMESPACE_INVALID = 4;
|
132
132
|
|
133
133
|
class CssParser extends Parser {
|
134
|
-
constructor({
|
134
|
+
constructor({
|
135
|
+
allowModeSwitch = true,
|
136
|
+
defaultMode = "global",
|
137
|
+
namedExports = true
|
138
|
+
} = {}) {
|
135
139
|
super();
|
136
140
|
this.allowModeSwitch = allowModeSwitch;
|
137
141
|
this.defaultMode = defaultMode;
|
142
|
+
this.namedExports = namedExports;
|
138
143
|
}
|
139
144
|
|
140
145
|
/**
|
@@ -911,7 +916,7 @@ class CssParser extends Parser {
|
|
911
916
|
) {
|
912
917
|
modeData = balanced[balanced.length - 1]
|
913
918
|
? /** @type {"local" | "global"} */
|
914
|
-
|
919
|
+
(balanced[balanced.length - 1][0])
|
915
920
|
: undefined;
|
916
921
|
const dep = new ConstDependency("", [start, end]);
|
917
922
|
module.addPresentationalDependency(dep);
|
@@ -1024,7 +1029,7 @@ class CssParser extends Parser {
|
|
1024
1029
|
}
|
1025
1030
|
|
1026
1031
|
module.buildInfo.strict = true;
|
1027
|
-
module.buildMeta.exportsType = "namespace";
|
1032
|
+
module.buildMeta.exportsType = this.namedExports ? "namespace" : "default";
|
1028
1033
|
module.addDependency(new StaticExportsDependency([], true));
|
1029
1034
|
return state;
|
1030
1035
|
}
|
@@ -31,7 +31,7 @@ const validate = createSchemaValidation(
|
|
31
31
|
let inspector = undefined;
|
32
32
|
|
33
33
|
try {
|
34
|
-
// eslint-disable-next-line
|
34
|
+
// eslint-disable-next-line n/no-unsupported-features/node-builtins
|
35
35
|
inspector = require("inspector");
|
36
36
|
} catch (e) {
|
37
37
|
console.log("Unable to CPU profile in < node 8.0");
|
@@ -374,7 +374,7 @@ const makeInterceptorFor = (instance, tracer) => hookName => ({
|
|
374
374
|
name,
|
375
375
|
type,
|
376
376
|
fn
|
377
|
-
|
377
|
+
});
|
378
378
|
return {
|
379
379
|
...tapInfo,
|
380
380
|
fn: newFn
|
@@ -38,6 +38,13 @@ class CachedConstDependency extends NullDependency {
|
|
38
38
|
this._hashUpdate = undefined;
|
39
39
|
}
|
40
40
|
|
41
|
+
/**
|
42
|
+
* @returns {string} hash update
|
43
|
+
*/
|
44
|
+
_createHashUpdate() {
|
45
|
+
return `${this.identifier}${this.range}${this.expression}`;
|
46
|
+
}
|
47
|
+
|
41
48
|
/**
|
42
49
|
* Update the hash
|
43
50
|
* @param {Hash} hash hash to be updated
|
@@ -46,7 +53,7 @@ class CachedConstDependency extends NullDependency {
|
|
46
53
|
*/
|
47
54
|
updateHash(hash, context) {
|
48
55
|
if (this._hashUpdate === undefined)
|
49
|
-
this._hashUpdate =
|
56
|
+
this._hashUpdate = this._createHashUpdate();
|
50
57
|
hash.update(this._hashUpdate);
|
51
58
|
}
|
52
59
|
|
@@ -65,7 +65,7 @@ class CommonJsImportsParserPlugin {
|
|
65
65
|
|
66
66
|
//#region metadata
|
67
67
|
/**
|
68
|
-
* @param {
|
68
|
+
* @param {string} expression expression
|
69
69
|
* @param {() => string[]} getMembers get members
|
70
70
|
*/
|
71
71
|
const tapRequireExpression = (expression, getMembers) => {
|
@@ -0,0 +1,98 @@
|
|
1
|
+
/*
|
2
|
+
MIT License http://www.opensource.org/licenses/mit-license.php
|
3
|
+
Author Ivan Kopeykin @vankop
|
4
|
+
*/
|
5
|
+
|
6
|
+
"use strict";
|
7
|
+
|
8
|
+
const makeSerializable = require("../util/makeSerializable");
|
9
|
+
const CachedConstDependency = require("./CachedConstDependency");
|
10
|
+
const ExternalModuleInitFragment = require("./ExternalModuleInitFragment");
|
11
|
+
|
12
|
+
/** @typedef {import("webpack-sources").ReplaceSource} ReplaceSource */
|
13
|
+
/** @typedef {import("../Dependency")} Dependency */
|
14
|
+
/** @typedef {import("../Dependency").UpdateHashContext} UpdateHashContext */
|
15
|
+
/** @typedef {import("../DependencyTemplate").DependencyTemplateContext} DependencyTemplateContext */
|
16
|
+
/** @typedef {import("../javascript/JavascriptModulesPlugin").ChunkRenderContext} ChunkRenderContext */
|
17
|
+
/** @typedef {import("../serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
|
18
|
+
/** @typedef {import("../serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
|
19
|
+
/** @typedef {import("../util/Hash")} Hash */
|
20
|
+
|
21
|
+
class ExternalModuleDependency extends CachedConstDependency {
|
22
|
+
constructor(
|
23
|
+
module,
|
24
|
+
importSpecifiers,
|
25
|
+
defaultImport,
|
26
|
+
expression,
|
27
|
+
range,
|
28
|
+
identifier
|
29
|
+
) {
|
30
|
+
super(expression, range, identifier);
|
31
|
+
|
32
|
+
this.importedModule = module;
|
33
|
+
this.specifiers = importSpecifiers;
|
34
|
+
this.default = defaultImport;
|
35
|
+
}
|
36
|
+
|
37
|
+
/**
|
38
|
+
* @returns {string} hash update
|
39
|
+
*/
|
40
|
+
_createHashUpdate() {
|
41
|
+
return `${this.importedModule}${JSON.stringify(this.specifiers)}${
|
42
|
+
this.default || "null"
|
43
|
+
}${super._createHashUpdate()}`;
|
44
|
+
}
|
45
|
+
|
46
|
+
/**
|
47
|
+
* @param {ObjectSerializerContext} context context
|
48
|
+
*/
|
49
|
+
serialize(context) {
|
50
|
+
super.serialize(context);
|
51
|
+
const { write } = context;
|
52
|
+
write(this.importedModule);
|
53
|
+
write(this.specifiers);
|
54
|
+
write(this.default);
|
55
|
+
}
|
56
|
+
|
57
|
+
/**
|
58
|
+
* @param {ObjectDeserializerContext} context context
|
59
|
+
*/
|
60
|
+
deserialize(context) {
|
61
|
+
super.deserialize(context);
|
62
|
+
const { read } = context;
|
63
|
+
this.importedModule = read();
|
64
|
+
this.specifiers = read();
|
65
|
+
this.default = read();
|
66
|
+
}
|
67
|
+
}
|
68
|
+
|
69
|
+
makeSerializable(
|
70
|
+
ExternalModuleDependency,
|
71
|
+
"webpack/lib/dependencies/ExternalModuleDependency"
|
72
|
+
);
|
73
|
+
|
74
|
+
ExternalModuleDependency.Template = class ExternalModuleDependencyTemplate extends (
|
75
|
+
CachedConstDependency.Template
|
76
|
+
) {
|
77
|
+
/**
|
78
|
+
* @param {Dependency} dependency the dependency for which the template should be applied
|
79
|
+
* @param {ReplaceSource} source the current replace source which can be modified
|
80
|
+
* @param {DependencyTemplateContext} templateContext the context object
|
81
|
+
* @returns {void}
|
82
|
+
*/
|
83
|
+
apply(dependency, source, templateContext) {
|
84
|
+
super.apply(dependency, source, templateContext);
|
85
|
+
const dep = /** @type {ExternalModuleDependency} */ (dependency);
|
86
|
+
const { chunkInitFragments } = templateContext;
|
87
|
+
|
88
|
+
chunkInitFragments.push(
|
89
|
+
new ExternalModuleInitFragment(
|
90
|
+
dep.importedModule,
|
91
|
+
dep.specifiers,
|
92
|
+
dep.default
|
93
|
+
)
|
94
|
+
);
|
95
|
+
}
|
96
|
+
};
|
97
|
+
|
98
|
+
module.exports = ExternalModuleDependency;
|
@@ -0,0 +1,124 @@
|
|
1
|
+
/*
|
2
|
+
MIT License http://www.opensource.org/licenses/mit-license.php
|
3
|
+
Author Ivan Kopeykin @vankop
|
4
|
+
*/
|
5
|
+
|
6
|
+
"use strict";
|
7
|
+
|
8
|
+
const InitFragment = require("../InitFragment");
|
9
|
+
const makeSerializable = require("../util/makeSerializable");
|
10
|
+
|
11
|
+
/** @typedef {import("webpack-sources").Source} Source */
|
12
|
+
/** @typedef {import("../Generator").GenerateContext} Context */
|
13
|
+
/** @typedef {import("../serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
|
14
|
+
/** @typedef {import("../serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
|
15
|
+
/** @typedef {Map<string, Set<string>>} ImportSpecifiers */
|
16
|
+
|
17
|
+
class ExternalModuleInitFragment extends InitFragment {
|
18
|
+
/**
|
19
|
+
* @param {string} importedModule imported module
|
20
|
+
* @param {Array<{ name: string, value?: string }>|ImportSpecifiers} specifiers import specifiers
|
21
|
+
* @param {string=} defaultImport default import
|
22
|
+
*/
|
23
|
+
constructor(importedModule, specifiers, defaultImport) {
|
24
|
+
super(
|
25
|
+
undefined,
|
26
|
+
InitFragment.STAGE_CONSTANTS,
|
27
|
+
0,
|
28
|
+
`external module imports|${importedModule}|${defaultImport || "null"}`
|
29
|
+
);
|
30
|
+
this.importedModule = importedModule;
|
31
|
+
if (Array.isArray(specifiers)) {
|
32
|
+
/** @type {ImportSpecifiers} */
|
33
|
+
this.specifiers = new Map();
|
34
|
+
for (const { name, value } of specifiers) {
|
35
|
+
let specifiers = this.specifiers.get(name);
|
36
|
+
if (!specifiers) {
|
37
|
+
specifiers = new Set();
|
38
|
+
this.specifiers.set(name, specifiers);
|
39
|
+
}
|
40
|
+
specifiers.add(value || name);
|
41
|
+
}
|
42
|
+
} else {
|
43
|
+
this.specifiers = specifiers;
|
44
|
+
}
|
45
|
+
this.defaultImport = defaultImport;
|
46
|
+
}
|
47
|
+
|
48
|
+
merge(other) {
|
49
|
+
const newSpecifiersMap = new Map(this.specifiers);
|
50
|
+
for (const [name, specifiers] of other.specifiers) {
|
51
|
+
if (newSpecifiersMap.has(name)) {
|
52
|
+
const currentSpecifiers = newSpecifiersMap.get(name);
|
53
|
+
for (const spec of specifiers) currentSpecifiers.add(spec);
|
54
|
+
} else {
|
55
|
+
newSpecifiersMap.set(name, specifiers);
|
56
|
+
}
|
57
|
+
}
|
58
|
+
return new ExternalModuleInitFragment(
|
59
|
+
this.importedModule,
|
60
|
+
newSpecifiersMap,
|
61
|
+
this.defaultImport
|
62
|
+
);
|
63
|
+
}
|
64
|
+
|
65
|
+
/**
|
66
|
+
* @param {Context} context context
|
67
|
+
* @returns {string|Source} the source code that will be included as initialization code
|
68
|
+
*/
|
69
|
+
getContent({ runtimeRequirements }) {
|
70
|
+
const namedImports = [];
|
71
|
+
|
72
|
+
for (const [name, specifiers] of this.specifiers) {
|
73
|
+
for (const spec of specifiers) {
|
74
|
+
if (spec === name) {
|
75
|
+
namedImports.push(name);
|
76
|
+
} else {
|
77
|
+
namedImports.push(`${name} as ${spec}`);
|
78
|
+
}
|
79
|
+
}
|
80
|
+
}
|
81
|
+
|
82
|
+
let importsString =
|
83
|
+
namedImports.length > 0 ? `{${namedImports.join(",")}}` : "";
|
84
|
+
|
85
|
+
if (this.defaultImport) {
|
86
|
+
importsString = `${this.defaultImport}${
|
87
|
+
importsString ? `, ${importsString}` : ""
|
88
|
+
}`;
|
89
|
+
}
|
90
|
+
|
91
|
+
return `import ${importsString} from ${JSON.stringify(
|
92
|
+
this.importedModule
|
93
|
+
)};`;
|
94
|
+
}
|
95
|
+
|
96
|
+
/**
|
97
|
+
* @param {ObjectSerializerContext} context context
|
98
|
+
*/
|
99
|
+
serialize(context) {
|
100
|
+
super.serialize(context);
|
101
|
+
const { write } = context;
|
102
|
+
write(this.importedModule);
|
103
|
+
write(this.specifiers);
|
104
|
+
write(this.defaultImport);
|
105
|
+
}
|
106
|
+
|
107
|
+
/**
|
108
|
+
* @param {ObjectDeserializerContext} context context
|
109
|
+
*/
|
110
|
+
deserialize(context) {
|
111
|
+
super.deserialize(context);
|
112
|
+
const { read } = context;
|
113
|
+
this.importedModule = read();
|
114
|
+
this.specifiers = read();
|
115
|
+
this.defaultImport = read();
|
116
|
+
}
|
117
|
+
}
|
118
|
+
|
119
|
+
makeSerializable(
|
120
|
+
ExternalModuleInitFragment,
|
121
|
+
"webpack/lib/dependencies/ExternalModuleInitFragment"
|
122
|
+
);
|
123
|
+
|
124
|
+
module.exports = ExternalModuleInitFragment;
|
@@ -5,6 +5,7 @@
|
|
5
5
|
|
6
6
|
"use strict";
|
7
7
|
|
8
|
+
const EnvironmentNotSupportAsyncWarning = require("../EnvironmentNotSupportAsyncWarning");
|
8
9
|
const { JAVASCRIPT_MODULE_TYPE_ESM } = require("../ModuleTypeConstants");
|
9
10
|
const DynamicExports = require("./DynamicExports");
|
10
11
|
const HarmonyCompatibilityDependency = require("./HarmonyCompatibilityDependency");
|
@@ -65,7 +66,7 @@ module.exports = class HarmonyDetectionParserPlugin {
|
|
65
66
|
const module = parser.state.module;
|
66
67
|
if (!this.topLevelAwait) {
|
67
68
|
throw new Error(
|
68
|
-
"The top-level-await experiment is not enabled (set experiments.topLevelAwait: true to
|
69
|
+
"The top-level-await experiment is not enabled (set experiments.topLevelAwait: true to enable it)"
|
69
70
|
);
|
70
71
|
}
|
71
72
|
if (!HarmonyExports.isEnabled(parser.state)) {
|
@@ -75,6 +76,11 @@ module.exports = class HarmonyDetectionParserPlugin {
|
|
75
76
|
}
|
76
77
|
/** @type {BuildMeta} */
|
77
78
|
(module.buildMeta).async = true;
|
79
|
+
EnvironmentNotSupportAsyncWarning.check(
|
80
|
+
module,
|
81
|
+
parser.state.compilation.runtimeTemplate,
|
82
|
+
"topLevelAwait"
|
83
|
+
);
|
78
84
|
});
|
79
85
|
|
80
86
|
/**
|
@@ -31,10 +31,10 @@ module.exports = class HarmonyExportDependencyParserPlugin {
|
|
31
31
|
options.reexportExportsPresence !== undefined
|
32
32
|
? ExportPresenceModes.fromUserOption(options.reexportExportsPresence)
|
33
33
|
: options.exportsPresence !== undefined
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
34
|
+
? ExportPresenceModes.fromUserOption(options.exportsPresence)
|
35
|
+
: options.strictExportPresence
|
36
|
+
? ExportPresenceModes.ERROR
|
37
|
+
: ExportPresenceModes.AUTO;
|
38
38
|
}
|
39
39
|
|
40
40
|
apply(parser) {
|
@@ -97,20 +97,20 @@ module.exports = class HarmonyExportDependencyParserPlugin {
|
|
97
97
|
expr.type.endsWith("Declaration") && expr.id
|
98
98
|
? expr.id.name
|
99
99
|
: isFunctionDeclaration
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
100
|
+
? {
|
101
|
+
id: expr.id ? expr.id.name : undefined,
|
102
|
+
range: [
|
103
|
+
expr.range[0],
|
104
|
+
expr.params.length > 0
|
105
|
+
? expr.params[0].range[0]
|
106
|
+
: expr.body.range[0]
|
107
|
+
],
|
108
|
+
prefix: `${expr.async ? "async " : ""}function${
|
109
|
+
expr.generator ? "*" : ""
|
110
|
+
} `,
|
111
|
+
suffix: `(${expr.params.length > 0 ? "" : ") "}`
|
112
|
+
}
|
113
|
+
: undefined
|
114
114
|
);
|
115
115
|
dep.loc = Object.create(statement.loc);
|
116
116
|
dep.loc.index = -1;
|
@@ -141,10 +141,10 @@ class HarmonyExportInitFragment extends InitFragment {
|
|
141
141
|
this.unusedExports.size > 1
|
142
142
|
? `/* unused harmony exports ${joinIterableWithComma(
|
143
143
|
this.unusedExports
|
144
|
-
|
144
|
+
)} */\n`
|
145
145
|
: this.unusedExports.size > 0
|
146
|
-
|
147
|
-
|
146
|
+
? `/* unused harmony export ${first(this.unusedExports)} */\n`
|
147
|
+
: "";
|
148
148
|
const definitions = [];
|
149
149
|
const orderedExportMap = Array.from(this.exportMap).sort(([a], [b]) =>
|
150
150
|
a < b ? -1 : 1
|
@@ -160,7 +160,7 @@ class HarmonyExportInitFragment extends InitFragment {
|
|
160
160
|
this.exportMap.size > 0
|
161
161
|
? `/* harmony export */ ${RuntimeGlobals.definePropertyGetters}(${
|
162
162
|
this.exportsArgument
|
163
|
-
|
163
|
+
}, {${definitions.join(",")}\n/* harmony export */ });\n`
|
164
164
|
: "";
|
165
165
|
return `${definePart}${unusedPart}`;
|
166
166
|
}
|
@@ -157,8 +157,8 @@ class HarmonyImportDependency extends ModuleDependency {
|
|
157
157
|
const moreInfo = !Array.isArray(providedExports)
|
158
158
|
? " (possible exports unknown)"
|
159
159
|
: providedExports.length === 0
|
160
|
-
|
161
|
-
|
160
|
+
? " (module has no exports)"
|
161
|
+
: ` (possible exports: ${providedExports.join(", ")})`;
|
162
162
|
return [
|
163
163
|
new HarmonyLinkingError(
|
164
164
|
`export ${ids
|
@@ -287,8 +287,8 @@ HarmonyImportDependency.Template = class HarmonyImportDependencyTemplate extends
|
|
287
287
|
const runtimeCondition = dep.weak
|
288
288
|
? false
|
289
289
|
: connection
|
290
|
-
|
291
|
-
|
290
|
+
? filterRuntime(runtime, r => connection.isTargetActive(r))
|
291
|
+
: true;
|
292
292
|
|
293
293
|
if (module && referencedModule) {
|
294
294
|
let emittedModules = importEmittedMap.get(module);
|
@@ -75,10 +75,10 @@ module.exports = class HarmonyImportDependencyParserPlugin {
|
|
75
75
|
options.importExportsPresence !== undefined
|
76
76
|
? ExportPresenceModes.fromUserOption(options.importExportsPresence)
|
77
77
|
: options.exportsPresence !== undefined
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
78
|
+
? ExportPresenceModes.fromUserOption(options.exportsPresence)
|
79
|
+
: options.strictExportPresence
|
80
|
+
? ExportPresenceModes.ERROR
|
81
|
+
: ExportPresenceModes.AUTO;
|
82
82
|
this.strictThisContextOnImports = options.strictThisContextOnImports;
|
83
83
|
}
|
84
84
|
|
@@ -240,7 +240,7 @@ module.exports = class HarmonyImportDependencyParserPlugin {
|
|
240
240
|
? getNonOptionalMemberChain(
|
241
241
|
expression,
|
242
242
|
members.length - nonOptionalMembers.length
|
243
|
-
|
243
|
+
)
|
244
244
|
: expression;
|
245
245
|
const ids = settings.ids.concat(nonOptionalMembers);
|
246
246
|
const dep = new HarmonyImportSpecifierDependency(
|
@@ -286,7 +286,7 @@ module.exports = class HarmonyImportDependencyParserPlugin {
|
|
286
286
|
? getNonOptionalMemberChain(
|
287
287
|
callee,
|
288
288
|
members.length - nonOptionalMembers.length
|
289
|
-
|
289
|
+
)
|
290
290
|
: callee;
|
291
291
|
const ids = settings.ids.concat(nonOptionalMembers);
|
292
292
|
const dep = new HarmonyImportSpecifierDependency(
|
@@ -48,12 +48,32 @@ class ImportDependency extends ModuleDependency {
|
|
48
48
|
* @returns {(string[] | ReferencedExport)[]} referenced exports
|
49
49
|
*/
|
50
50
|
getReferencedExports(moduleGraph, runtime) {
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
51
|
+
if (!this.referencedExports) return Dependency.EXPORTS_OBJECT_REFERENCED;
|
52
|
+
const refs = [];
|
53
|
+
for (const referencedExport of this.referencedExports) {
|
54
|
+
if (referencedExport[0] === "default") {
|
55
|
+
const selfModule = moduleGraph.getParentModule(this);
|
56
|
+
const importedModule =
|
57
|
+
/** @type {Module} */
|
58
|
+
(moduleGraph.getModule(this));
|
59
|
+
const exportsType = importedModule.getExportsType(
|
60
|
+
moduleGraph,
|
61
|
+
/** @type {BuildMeta} */
|
62
|
+
(selfModule.buildMeta).strictHarmonyModule
|
63
|
+
);
|
64
|
+
if (
|
65
|
+
exportsType === "default-only" ||
|
66
|
+
exportsType === "default-with-named"
|
67
|
+
) {
|
68
|
+
return Dependency.EXPORTS_OBJECT_REFERENCED;
|
69
|
+
}
|
70
|
+
}
|
71
|
+
refs.push({
|
72
|
+
name: referencedExport,
|
73
|
+
canMangle: false
|
74
|
+
});
|
75
|
+
}
|
76
|
+
return refs;
|
57
77
|
}
|
58
78
|
|
59
79
|
/**
|