webpack 5.88.2 → 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/CommonJsFullRequireDependency.js +27 -6
- package/lib/dependencies/CommonJsImportsParserPlugin.js +21 -5
- 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/HarmonyImportSpecifierDependency.js +13 -63
- 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 +18 -6
- 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/chainedImports.js +96 -0
- 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 +180 -22
@@ -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
|
|
@@ -7,6 +7,7 @@
|
|
7
7
|
|
8
8
|
const Template = require("../Template");
|
9
9
|
const { equals } = require("../util/ArrayHelpers");
|
10
|
+
const { getTrimmedIdsAndRange } = require("../util/chainedImports");
|
10
11
|
const makeSerializable = require("../util/makeSerializable");
|
11
12
|
const propertyAccess = require("../util/propertyAccess");
|
12
13
|
const ModuleDependency = require("./ModuleDependency");
|
@@ -26,11 +27,18 @@ class CommonJsFullRequireDependency extends ModuleDependency {
|
|
26
27
|
* @param {string} request the request string
|
27
28
|
* @param {Range} range location in source code
|
28
29
|
* @param {string[]} names accessed properties on module
|
30
|
+
* @param {Range[]=} idRanges ranges for members of ids; the two arrays are right-aligned
|
29
31
|
*/
|
30
|
-
constructor(
|
32
|
+
constructor(
|
33
|
+
request,
|
34
|
+
range,
|
35
|
+
names,
|
36
|
+
idRanges /* TODO webpack 6 make this non-optional. It must always be set to properly trim ids. */
|
37
|
+
) {
|
31
38
|
super(request);
|
32
39
|
this.range = range;
|
33
40
|
this.names = names;
|
41
|
+
this.idRanges = idRanges;
|
34
42
|
this.call = false;
|
35
43
|
this.asiSafe = undefined;
|
36
44
|
}
|
@@ -60,6 +68,7 @@ class CommonJsFullRequireDependency extends ModuleDependency {
|
|
60
68
|
serialize(context) {
|
61
69
|
const { write } = context;
|
62
70
|
write(this.names);
|
71
|
+
write(this.idRanges);
|
63
72
|
write(this.call);
|
64
73
|
write(this.asiSafe);
|
65
74
|
super.serialize(context);
|
@@ -71,6 +80,7 @@ class CommonJsFullRequireDependency extends ModuleDependency {
|
|
71
80
|
deserialize(context) {
|
72
81
|
const { read } = context;
|
73
82
|
this.names = read();
|
83
|
+
this.idRanges = read();
|
74
84
|
this.call = read();
|
75
85
|
this.asiSafe = read();
|
76
86
|
super.deserialize(context);
|
@@ -117,15 +127,26 @@ CommonJsFullRequireDependency.Template = class CommonJsFullRequireDependencyTemp
|
|
117
127
|
weak: dep.weak,
|
118
128
|
runtimeRequirements
|
119
129
|
});
|
130
|
+
|
131
|
+
const {
|
132
|
+
trimmedRange: [trimmedRangeStart, trimmedRangeEnd],
|
133
|
+
trimmedIds
|
134
|
+
} = getTrimmedIdsAndRange(
|
135
|
+
dep.names,
|
136
|
+
dep.range,
|
137
|
+
dep.idRanges,
|
138
|
+
moduleGraph,
|
139
|
+
dep
|
140
|
+
);
|
141
|
+
|
120
142
|
if (importedModule) {
|
121
|
-
const ids = dep.names;
|
122
143
|
const usedImported = moduleGraph
|
123
144
|
.getExportsInfo(importedModule)
|
124
|
-
.getUsedName(
|
145
|
+
.getUsedName(trimmedIds, runtime);
|
125
146
|
if (usedImported) {
|
126
|
-
const comment = equals(usedImported,
|
147
|
+
const comment = equals(usedImported, trimmedIds)
|
127
148
|
? ""
|
128
|
-
: Template.toNormalComment(propertyAccess(
|
149
|
+
: Template.toNormalComment(propertyAccess(trimmedIds)) + " ";
|
129
150
|
const access = `${comment}${propertyAccess(usedImported)}`;
|
130
151
|
requireExpr =
|
131
152
|
dep.asiSafe === true
|
@@ -133,7 +154,7 @@ CommonJsFullRequireDependency.Template = class CommonJsFullRequireDependencyTemp
|
|
133
154
|
: `${requireExpr}${access}`;
|
134
155
|
}
|
135
156
|
}
|
136
|
-
source.replace(
|
157
|
+
source.replace(trimmedRangeStart, trimmedRangeEnd - 1, requireExpr);
|
137
158
|
}
|
138
159
|
};
|
139
160
|
|
@@ -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) => {
|
@@ -379,9 +379,16 @@ class CommonJsImportsParserPlugin {
|
|
379
379
|
* @param {string[]} calleeMembers callee members
|
380
380
|
* @param {CallExpression} callExpr call expression
|
381
381
|
* @param {string[]} members members
|
382
|
+
* @param {Range[]} memberRanges member ranges
|
382
383
|
* @returns {boolean | void} true when handled
|
383
384
|
*/
|
384
|
-
const chainHandler = (
|
385
|
+
const chainHandler = (
|
386
|
+
expr,
|
387
|
+
calleeMembers,
|
388
|
+
callExpr,
|
389
|
+
members,
|
390
|
+
memberRanges
|
391
|
+
) => {
|
385
392
|
if (callExpr.arguments.length !== 1) return;
|
386
393
|
const param = parser.evaluateExpression(callExpr.arguments[0]);
|
387
394
|
if (
|
@@ -391,7 +398,8 @@ class CommonJsImportsParserPlugin {
|
|
391
398
|
const dep = new CommonJsFullRequireDependency(
|
392
399
|
/** @type {string} */ (param.string),
|
393
400
|
/** @type {Range} */ (expr.range),
|
394
|
-
members
|
401
|
+
members,
|
402
|
+
/** @type {Range[]} */ memberRanges
|
395
403
|
);
|
396
404
|
dep.asiSafe = !parser.isAsiPosition(
|
397
405
|
/** @type {Range} */ (expr.range)[0]
|
@@ -407,9 +415,16 @@ class CommonJsImportsParserPlugin {
|
|
407
415
|
* @param {string[]} calleeMembers callee members
|
408
416
|
* @param {CallExpression} callExpr call expression
|
409
417
|
* @param {string[]} members members
|
418
|
+
* @param {Range[]} memberRanges member ranges
|
410
419
|
* @returns {boolean | void} true when handled
|
411
420
|
*/
|
412
|
-
const callChainHandler = (
|
421
|
+
const callChainHandler = (
|
422
|
+
expr,
|
423
|
+
calleeMembers,
|
424
|
+
callExpr,
|
425
|
+
members,
|
426
|
+
memberRanges
|
427
|
+
) => {
|
413
428
|
if (callExpr.arguments.length !== 1) return;
|
414
429
|
const param = parser.evaluateExpression(callExpr.arguments[0]);
|
415
430
|
if (
|
@@ -419,7 +434,8 @@ class CommonJsImportsParserPlugin {
|
|
419
434
|
const dep = new CommonJsFullRequireDependency(
|
420
435
|
/** @type {string} */ (param.string),
|
421
436
|
/** @type {Range} */ (expr.callee.range),
|
422
|
-
members
|
437
|
+
members,
|
438
|
+
/** @type {Range[]} */ memberRanges
|
423
439
|
);
|
424
440
|
dep.call = true;
|
425
441
|
dep.asiSafe = !parser.isAsiPosition(
|
@@ -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
|
/**
|