webpack 5.108.3 → 5.109.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.
- package/lib/APIPlugin.js +48 -29
- package/lib/CacheFacade.js +8 -0
- package/lib/ChunkGroup.js +1 -0
- package/lib/CompatibilityPlugin.js +31 -29
- package/lib/Compilation.js +50 -8
- package/lib/ConstPlugin.js +11 -11
- package/lib/ContextModule.js +239 -6
- package/lib/ContextModuleFactory.js +139 -14
- package/lib/DefinePlugin.js +396 -101
- package/lib/Entrypoint.js +1 -1
- package/lib/ExportsInfoApiPlugin.js +2 -2
- package/lib/ExternalModule.js +107 -5
- package/lib/ExternalModuleFactoryPlugin.js +20 -1
- package/lib/FileSystemInfo.js +130 -74
- package/lib/FlagDependencyExportsPlugin.js +55 -8
- package/lib/HotModuleReplacementPlugin.js +18 -15
- package/lib/LazyBarrel.js +30 -3
- package/lib/Module.js +3 -0
- package/lib/ModuleFilenameHelpers.js +2 -2
- package/lib/ModuleTypeConstants.js +8 -1
- package/lib/MultiCompiler.js +13 -2
- package/lib/MultiWatching.js +1 -0
- package/lib/NodeStuffPlugin.js +51 -33
- package/lib/NormalModule.js +169 -405
- package/lib/NormalModuleFactory.js +76 -2
- package/lib/ProgressPlugin.js +211 -119
- package/lib/ProvidePlugin.js +2 -2
- package/lib/RuntimeGlobals.js +47 -0
- package/lib/RuntimePlugin.js +33 -0
- package/lib/RuntimeTemplate.js +304 -16
- package/lib/UseStrictPlugin.js +1 -1
- package/lib/WebpackIsIncludedPlugin.js +1 -1
- package/lib/WebpackOptionsApply.js +24 -19
- package/lib/asset/AssetGenerator.js +110 -28
- package/lib/asset/AssetModulesPlugin.js +92 -2
- package/lib/asset/WebManifestGenerator.js +164 -0
- package/lib/asset/WebManifestParser.js +130 -0
- package/lib/async-modules/AwaitDependenciesInitFragment.js +14 -4
- package/lib/async-modules/isGeneratorLowered.js +26 -0
- package/lib/cache/PackFileCacheStrategy.js +9 -3
- package/lib/config/browserslistTargetHandler.js +40 -0
- package/lib/config/defaults.js +222 -32
- package/lib/config/normalization.js +26 -0
- package/lib/config/target.js +9 -1
- package/lib/css/CssGenerator.js +73 -73
- package/lib/css/CssLoadingRuntimeModule.js +5 -1
- package/lib/css/CssModulesPlugin.js +92 -53
- package/lib/css/CssParser.js +843 -302
- package/lib/css/syntax.js +1219 -483
- package/lib/dependencies/AMDDefineDependencyParserPlugin.js +6 -6
- package/lib/dependencies/AMDPlugin.js +2 -2
- package/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js +13 -13
- package/lib/dependencies/CommonJsDependencyHelpers.js +39 -0
- package/lib/dependencies/CommonJsExportsDependency.js +47 -2
- package/lib/dependencies/CommonJsExportsParserPlugin.js +10 -10
- package/lib/dependencies/CommonJsImportsParserPlugin.js +18 -18
- package/lib/dependencies/CommonJsPlugin.js +2 -2
- package/lib/dependencies/CommonJsRequireDependency.js +26 -1
- package/lib/dependencies/CommonJsSelfReferenceDependency.js +32 -1
- package/lib/dependencies/ContextDependencyHelpers.js +3 -3
- package/lib/dependencies/CreateRequireParserPlugin.js +6 -6
- package/lib/dependencies/CssIcssExportDependency.js +190 -87
- package/lib/dependencies/CssUrlDependency.js +35 -4
- package/lib/dependencies/ExternalModuleInitFragmentDependency.js +2 -2
- package/lib/dependencies/HarmonyCompatibilityDependency.js +32 -14
- package/lib/dependencies/HarmonyDetectionParserPlugin.js +43 -13
- package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +7 -19
- package/lib/dependencies/HarmonyImportDependency.js +12 -1
- package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +34 -107
- package/lib/dependencies/HarmonyImportGuard.js +192 -20
- package/lib/dependencies/HarmonyModulesPlugin.js +6 -0
- package/lib/dependencies/HarmonyTopLevelThisParserPlugin.js +1 -1
- package/lib/dependencies/HtmlEntryDependency.js +797 -172
- package/lib/dependencies/HtmlSourceDependency.js +26 -0
- package/lib/dependencies/ImportDependency.js +43 -1
- package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +31 -18
- package/lib/dependencies/ImportMetaContextPlugin.js +38 -7
- package/lib/dependencies/ImportMetaGlobDependency.js +81 -0
- package/lib/dependencies/ImportMetaGlobDependencyParserPlugin.js +78 -0
- package/lib/dependencies/ImportMetaGlobHelpers.js +660 -0
- package/lib/dependencies/ImportMetaPlugin.js +532 -180
- package/lib/dependencies/ImportMetaResolveDependency.js +90 -0
- package/lib/dependencies/ImportParserPlugin.js +87 -26
- package/lib/dependencies/ImportPhase.js +10 -8
- package/lib/dependencies/LoaderPlugin.js +5 -1
- package/lib/dependencies/RequireContextDependencyParserPlugin.js +1 -1
- package/lib/dependencies/RequireEnsureDependenciesBlockParserPlugin.js +3 -6
- package/lib/dependencies/RequireIncludeDependencyParserPlugin.js +4 -11
- package/lib/dependencies/SystemPlugin.js +2 -4
- package/lib/dependencies/TopLevelAwaitDependency.js +93 -0
- package/lib/dependencies/URLDependency.js +141 -21
- package/lib/dependencies/{WorkerPlugin.js → WorkerAndWorkletPlugin.js} +324 -112
- package/lib/dependencies/WorkerDependency.js +86 -18
- package/lib/dependencies/WorkletDependency.js +278 -0
- package/lib/dll/DelegatedModuleFactoryPlugin.js +19 -0
- package/lib/errors/EnvironmentNotSupportAsyncWarning.js +1 -1
- package/lib/errors/LoaderLoadingError.js +20 -0
- package/lib/errors/ModuleParseError.js +39 -22
- package/lib/errors/NodeStuffInWebError.js +1 -1
- package/lib/esm/ModuleChunkFormatPlugin.js +47 -14
- package/lib/esm/ModuleChunkLoadingPlugin.js +8 -1
- package/lib/esm/ModuleChunkLoadingRuntimeModule.js +29 -1
- package/lib/hmr/lazyCompilationBackend.js +32 -8
- package/lib/html/HtmlGenerator.js +940 -91
- package/lib/html/HtmlModule.js +3 -2
- package/lib/html/HtmlModulesPlugin.js +625 -170
- package/lib/html/HtmlParser.js +812 -340
- package/lib/html/favicon.svg +1 -0
- package/lib/html/syntax.js +2116 -834
- package/lib/ids/IdHelpers.js +1 -1
- package/lib/index.js +6 -0
- package/lib/javascript/ArrayPushCallbackChunkFormatPlugin.js +4 -5
- package/lib/javascript/BasicEvaluatedExpression.js +366 -48
- package/lib/javascript/JavascriptGenerator.js +197 -49
- package/lib/javascript/JavascriptModulesPlugin.js +178 -24
- package/lib/javascript/JavascriptParser.js +711 -355
- package/lib/javascript/JavascriptParserHelpers.js +3 -6
- package/lib/javascript/syntax.js +4380 -0
- package/lib/library/ModuleLibraryPlugin.js +38 -1
- package/lib/loaders/LoaderRunner.js +714 -0
- package/lib/loaders/loadLoader.js +100 -0
- package/lib/node/ReadFileCompileAsyncWasmPlugin.js +19 -0
- package/lib/node/ReadFileCompileWasmPlugin.js +14 -0
- package/lib/optimize/ConcatenatedModule.js +120 -16
- package/lib/optimize/FlagIncludedChunksPlugin.js +13 -3
- package/lib/optimize/InnerGraphPlugin.js +50 -30
- package/lib/optimize/ModuleConcatenationPlugin.js +69 -3
- package/lib/optimize/SideEffectsFlagPlugin.js +86 -43
- package/lib/prefetch/ChunkPrefetchPreloadPlugin.js +15 -0
- package/lib/prefetch/ChunkPreloadTriggerRuntimeModule.js +24 -13
- package/lib/prefetch/ResourceHintPlugin.js +663 -0
- package/lib/prefetch/ResourceHintRuntimeModule.js +149 -0
- package/lib/prefetch/StartupAssetHintRuntimeModule.js +210 -0
- package/lib/prefetch/parseResourceHintOptions.js +103 -0
- package/lib/rules/RuleSetCompiler.js +114 -0
- package/lib/runtime/AsyncModuleGeneratorRuntimeModule.js +56 -0
- package/lib/runtime/AsyncModuleRuntimeModule.js +24 -8
- package/lib/runtime/AutoPublicPathRuntimeModule.js +7 -1
- package/lib/runtime/CommonJsWrapRuntimeModule.js +37 -0
- package/lib/runtime/GetWorkletBootstrapRuntimeModule.js +59 -0
- package/lib/runtime/MakeDeferredNamespaceObjectRuntime.js +204 -8
- package/lib/runtime/SetAnonymousDefaultNameRuntimeModule.js +4 -1
- package/lib/schemes/HttpUriPlugin.js +40 -1
- package/lib/schemes/VirtualUrlPlugin.js +1 -2
- package/lib/serialization/FileMiddleware.js +29 -3
- package/lib/stats/DefaultStatsFactoryPlugin.js +32 -3
- package/lib/stats/DefaultStatsPresetPlugin.js +2 -0
- package/lib/stats/DefaultStatsPrinterPlugin.js +12 -2
- package/lib/stats/StatsFactory.js +15 -8
- package/lib/url/URLParserPlugin.js +98 -19
- package/lib/util/AsyncQueue.js +122 -72
- package/lib/util/LocConverter.js +9 -8
- package/lib/util/SetHelpers.js +1 -1
- package/lib/util/SourceProcessor.js +41 -28
- package/lib/util/StackedMap.js +122 -48
- package/lib/util/binarySearchBounds.js +2 -2
- package/lib/util/concatenate.js +40 -14
- package/lib/util/createHooksRegistry.js +13 -5
- package/lib/util/dataURL.js +2 -2
- package/lib/util/deterministicGrouping.js +7 -5
- package/lib/util/formatSize.js +6 -2
- package/lib/util/globUtils.js +710 -0
- package/lib/util/identifier.js +23 -6
- package/lib/util/implicitTypeLoaderFallback.js +62 -0
- package/lib/util/internalSerializables.js +88 -71
- package/lib/util/magicComment.js +121 -25
- package/lib/util/numberHash.js +2 -2
- package/lib/wasm-async/AsyncWasmCompileRuntimeModule.js +24 -18
- package/lib/wasm-async/AsyncWasmLoadingRuntimeModule.js +33 -22
- package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +79 -16
- package/lib/web/FetchCompileAsyncWasmPlugin.js +19 -0
- package/lib/web/FetchCompileWasmPlugin.js +14 -0
- package/lib/web/JsonpChunkLoadingRuntimeModule.js +2 -0
- package/lib/webpack.js +65 -0
- package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +3 -0
- package/module.d.ts +21 -0
- package/package.json +14 -13
- package/schemas/WebpackOptions.check.js +1 -1
- package/schemas/WebpackOptions.json +759 -36
- package/schemas/plugins/HtmlParserOptions.check.js +1 -1
- package/schemas/plugins/ProgressPlugin.check.js +1 -1
- package/schemas/plugins/ProgressPlugin.json +17 -1
- package/schemas/plugins/container/ContainerReferencePlugin.check.js +1 -1
- package/schemas/plugins/container/ContainerReferencePlugin.json +1 -0
- package/schemas/plugins/container/ExternalsType.check.js +1 -1
- package/schemas/plugins/container/ModuleFederationPlugin.check.js +1 -1
- package/schemas/plugins/container/ModuleFederationPlugin.json +1 -0
- package/schemas/plugins/css/CssAutoOrModuleParserOptions.check.js +1 -1
- package/schemas/plugins/css/CssModuleParserOptions.check.js +1 -1
- package/schemas/plugins/css/CssParserOptions.check.js +1 -1
- package/types.d.ts +1300 -325
|
@@ -39,6 +39,18 @@ class HtmlSourceDependency extends ModuleDependency {
|
|
|
39
39
|
constructor(request, range) {
|
|
40
40
|
super(request);
|
|
41
41
|
this.range = range;
|
|
42
|
+
/** @type {true | undefined} */
|
|
43
|
+
this.prefetch = undefined;
|
|
44
|
+
/** @type {true | undefined} */
|
|
45
|
+
this.preload = undefined;
|
|
46
|
+
/** @type {"low" | "high" | "auto" | undefined} */
|
|
47
|
+
this.fetchPriority = undefined;
|
|
48
|
+
/** @type {string | undefined} */
|
|
49
|
+
this.asAttribute = undefined;
|
|
50
|
+
/** @type {string | undefined} */
|
|
51
|
+
this.typeAttribute = undefined;
|
|
52
|
+
/** @type {string | undefined} */
|
|
53
|
+
this.mediaAttribute = undefined;
|
|
42
54
|
}
|
|
43
55
|
|
|
44
56
|
get type() {
|
|
@@ -78,6 +90,13 @@ class HtmlSourceDependency extends ModuleDependency {
|
|
|
78
90
|
* @param {ObjectSerializerContext} context context
|
|
79
91
|
*/
|
|
80
92
|
serialize(context) {
|
|
93
|
+
const { write } = context;
|
|
94
|
+
write(this.prefetch);
|
|
95
|
+
write(this.preload);
|
|
96
|
+
write(this.fetchPriority);
|
|
97
|
+
write(this.asAttribute);
|
|
98
|
+
write(this.typeAttribute);
|
|
99
|
+
write(this.mediaAttribute);
|
|
81
100
|
super.serialize(context);
|
|
82
101
|
}
|
|
83
102
|
|
|
@@ -86,6 +105,13 @@ class HtmlSourceDependency extends ModuleDependency {
|
|
|
86
105
|
* @param {ObjectDeserializerContext} context context
|
|
87
106
|
*/
|
|
88
107
|
deserialize(context) {
|
|
108
|
+
const { read } = context;
|
|
109
|
+
this.prefetch = read();
|
|
110
|
+
this.preload = read();
|
|
111
|
+
this.fetchPriority = read();
|
|
112
|
+
this.asAttribute = read();
|
|
113
|
+
this.typeAttribute = read();
|
|
114
|
+
this.mediaAttribute = read();
|
|
89
115
|
super.deserialize(context);
|
|
90
116
|
}
|
|
91
117
|
}
|
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
"use strict";
|
|
7
7
|
|
|
8
8
|
const Dependency = require("../Dependency");
|
|
9
|
+
const Template = require("../Template");
|
|
9
10
|
const makeSerializable = require("../util/makeSerializable");
|
|
10
11
|
const memoize = require("../util/memoize");
|
|
11
12
|
const { ImportPhaseUtils } = require("./ImportPhase");
|
|
@@ -50,6 +51,11 @@ class ImportDependency extends ModuleDependency {
|
|
|
50
51
|
this.attributes = attributes;
|
|
51
52
|
/** @type {DependencyGuard[] | undefined} */
|
|
52
53
|
this.branchGuards = undefined;
|
|
54
|
+
// Range of the `import(specifier, options)` second argument, set only when
|
|
55
|
+
// it is not a statically extractable attributes object and must therefore
|
|
56
|
+
// be evaluated and validated at runtime.
|
|
57
|
+
/** @type {Range | undefined} */
|
|
58
|
+
this.optionsRange = undefined;
|
|
53
59
|
}
|
|
54
60
|
|
|
55
61
|
get type() {
|
|
@@ -137,6 +143,7 @@ class ImportDependency extends ModuleDependency {
|
|
|
137
143
|
context.write(this.phase);
|
|
138
144
|
context.write(this.attributes);
|
|
139
145
|
context.write(this.branchGuards);
|
|
146
|
+
context.write(this.optionsRange);
|
|
140
147
|
super.serialize(context);
|
|
141
148
|
}
|
|
142
149
|
|
|
@@ -150,6 +157,7 @@ class ImportDependency extends ModuleDependency {
|
|
|
150
157
|
this.phase = context.read();
|
|
151
158
|
this.attributes = context.read();
|
|
152
159
|
this.branchGuards = context.read();
|
|
160
|
+
this.optionsRange = context.read();
|
|
153
161
|
super.deserialize(context);
|
|
154
162
|
}
|
|
155
163
|
}
|
|
@@ -200,7 +208,8 @@ ImportDependency.Template = class ImportDependencyTemplate extends (
|
|
|
200
208
|
strict: /** @type {BuildMeta} */ (module.buildMeta).strictHarmonyModule,
|
|
201
209
|
dependency: dep,
|
|
202
210
|
message: "import()",
|
|
203
|
-
runtimeRequirements
|
|
211
|
+
runtimeRequirements,
|
|
212
|
+
originModule: module
|
|
204
213
|
});
|
|
205
214
|
|
|
206
215
|
// For source phase imports, unwrap the default export
|
|
@@ -212,6 +221,39 @@ ImportDependency.Template = class ImportDependencyTemplate extends (
|
|
|
212
221
|
)})`;
|
|
213
222
|
}
|
|
214
223
|
|
|
224
|
+
// A non-static second argument must still be evaluated (for its side
|
|
225
|
+
// effects and evaluation order) and validated per spec. Keep it in place
|
|
226
|
+
// and wrap it in an inline validator that mirrors the runtime checks of
|
|
227
|
+
// the spec's `import(specifier, options)` evaluation.
|
|
228
|
+
if (dep.optionsRange) {
|
|
229
|
+
const validator = runtimeTemplate.basicFunction("o", [
|
|
230
|
+
"try {",
|
|
231
|
+
Template.indent([
|
|
232
|
+
"if (o !== undefined) {",
|
|
233
|
+
Template.indent([
|
|
234
|
+
'if ((typeof o !== "object" && typeof o !== "function") || o === null) throw new TypeError("The second argument to import() must be an object");',
|
|
235
|
+
'var a = o["with"];',
|
|
236
|
+
"if (a !== undefined) {",
|
|
237
|
+
Template.indent([
|
|
238
|
+
'if ((typeof a !== "object" && typeof a !== "function") || a === null) throw new TypeError("The \'with\' option must be an object");',
|
|
239
|
+
"for (var k = Object.keys(a), i = 0; i < k.length; i++) {",
|
|
240
|
+
Template.indent([
|
|
241
|
+
'if (typeof a[k[i]] !== "string") throw new TypeError("Import attribute values must be strings");'
|
|
242
|
+
]),
|
|
243
|
+
"}"
|
|
244
|
+
]),
|
|
245
|
+
"}"
|
|
246
|
+
]),
|
|
247
|
+
"}"
|
|
248
|
+
]),
|
|
249
|
+
"} catch (e) { return Promise.reject(e); }",
|
|
250
|
+
`return ${content};`
|
|
251
|
+
]);
|
|
252
|
+
source.replace(dep.range[0], dep.optionsRange[0] - 1, `(${validator})(`);
|
|
253
|
+
source.replace(dep.optionsRange[1], dep.range[1] - 1, ")");
|
|
254
|
+
return;
|
|
255
|
+
}
|
|
256
|
+
|
|
215
257
|
source.replace(dep.range[0], dep.range[1] - 1, content);
|
|
216
258
|
}
|
|
217
259
|
};
|
|
@@ -29,18 +29,18 @@ const ImportMetaContextDependency = require("./ImportMetaContextDependency");
|
|
|
29
29
|
|
|
30
30
|
/**
|
|
31
31
|
* Creates a property parse error.
|
|
32
|
+
* @param {JavascriptParser} parser the parser
|
|
32
33
|
* @param {Property} prop property
|
|
33
34
|
* @param {string} expect except message
|
|
34
35
|
* @returns {WebpackError} error
|
|
35
36
|
*/
|
|
36
|
-
function createPropertyParseError(prop, expect) {
|
|
37
|
+
function createPropertyParseError(parser, prop, expect) {
|
|
37
38
|
return createError(
|
|
38
39
|
`Parsing import.meta.webpackContext options failed. Unknown value for property ${JSON.stringify(
|
|
39
40
|
/** @type {Identifier} */
|
|
40
41
|
(prop.key).name
|
|
41
42
|
)}, expected type ${expect}.`,
|
|
42
|
-
|
|
43
|
-
(prop.value.loc)
|
|
43
|
+
parser.getLocation(prop.value)
|
|
44
44
|
);
|
|
45
45
|
}
|
|
46
46
|
|
|
@@ -110,8 +110,7 @@ module.exports = class ImportMetaContextDependencyParserPlugin {
|
|
|
110
110
|
errors.push(
|
|
111
111
|
createError(
|
|
112
112
|
"Parsing import.meta.webpackContext options failed.",
|
|
113
|
-
|
|
114
|
-
(optionsNode.loc)
|
|
113
|
+
parser.getLocation(optionsNode)
|
|
115
114
|
)
|
|
116
115
|
);
|
|
117
116
|
break;
|
|
@@ -122,7 +121,7 @@ module.exports = class ImportMetaContextDependencyParserPlugin {
|
|
|
122
121
|
/** @type {Expression} */ (prop.value)
|
|
123
122
|
);
|
|
124
123
|
if (!regExpExpr.isRegExp()) {
|
|
125
|
-
errors.push(createPropertyParseError(prop, "RegExp"));
|
|
124
|
+
errors.push(createPropertyParseError(parser, prop, "RegExp"));
|
|
126
125
|
} else {
|
|
127
126
|
regExp = /** @type {RegExp} */ (regExpExpr.regExp);
|
|
128
127
|
}
|
|
@@ -133,7 +132,7 @@ module.exports = class ImportMetaContextDependencyParserPlugin {
|
|
|
133
132
|
/** @type {Expression} */ (prop.value)
|
|
134
133
|
);
|
|
135
134
|
if (!regExpExpr.isRegExp()) {
|
|
136
|
-
errors.push(createPropertyParseError(prop, "RegExp"));
|
|
135
|
+
errors.push(createPropertyParseError(parser, prop, "RegExp"));
|
|
137
136
|
} else {
|
|
138
137
|
include = regExpExpr.regExp;
|
|
139
138
|
}
|
|
@@ -144,7 +143,7 @@ module.exports = class ImportMetaContextDependencyParserPlugin {
|
|
|
144
143
|
/** @type {Expression} */ (prop.value)
|
|
145
144
|
);
|
|
146
145
|
if (!regExpExpr.isRegExp()) {
|
|
147
|
-
errors.push(createPropertyParseError(prop, "RegExp"));
|
|
146
|
+
errors.push(createPropertyParseError(parser, prop, "RegExp"));
|
|
148
147
|
} else {
|
|
149
148
|
exclude = regExpExpr.regExp;
|
|
150
149
|
}
|
|
@@ -155,7 +154,7 @@ module.exports = class ImportMetaContextDependencyParserPlugin {
|
|
|
155
154
|
/** @type {Expression} */ (prop.value)
|
|
156
155
|
);
|
|
157
156
|
if (!modeExpr.isString()) {
|
|
158
|
-
errors.push(createPropertyParseError(prop, "string"));
|
|
157
|
+
errors.push(createPropertyParseError(parser, prop, "string"));
|
|
159
158
|
} else {
|
|
160
159
|
mode = /** @type {ContextModuleOptions["mode"]} */ (
|
|
161
160
|
modeExpr.string
|
|
@@ -168,7 +167,7 @@ module.exports = class ImportMetaContextDependencyParserPlugin {
|
|
|
168
167
|
/** @type {Expression} */ (prop.value)
|
|
169
168
|
);
|
|
170
169
|
if (!expr.isString()) {
|
|
171
|
-
errors.push(createPropertyParseError(prop, "string"));
|
|
170
|
+
errors.push(createPropertyParseError(parser, prop, "string"));
|
|
172
171
|
} else {
|
|
173
172
|
chunkName = expr.string;
|
|
174
173
|
}
|
|
@@ -206,12 +205,16 @@ module.exports = class ImportMetaContextDependencyParserPlugin {
|
|
|
206
205
|
}
|
|
207
206
|
} else {
|
|
208
207
|
errors.push(
|
|
209
|
-
createPropertyParseError(
|
|
208
|
+
createPropertyParseError(
|
|
209
|
+
parser,
|
|
210
|
+
prop,
|
|
211
|
+
"string|string[][]"
|
|
212
|
+
)
|
|
210
213
|
);
|
|
211
214
|
}
|
|
212
215
|
} else {
|
|
213
216
|
errors.push(
|
|
214
|
-
createPropertyParseError(prop, "string|string[][]")
|
|
217
|
+
createPropertyParseError(parser, prop, "string|string[][]")
|
|
215
218
|
);
|
|
216
219
|
}
|
|
217
220
|
break;
|
|
@@ -225,7 +228,9 @@ module.exports = class ImportMetaContextDependencyParserPlugin {
|
|
|
225
228
|
} else if (expr.isNumber()) {
|
|
226
229
|
groupOptions.prefetchOrder = expr.number;
|
|
227
230
|
} else {
|
|
228
|
-
errors.push(
|
|
231
|
+
errors.push(
|
|
232
|
+
createPropertyParseError(parser, prop, "boolean|number")
|
|
233
|
+
);
|
|
229
234
|
}
|
|
230
235
|
break;
|
|
231
236
|
}
|
|
@@ -238,7 +243,9 @@ module.exports = class ImportMetaContextDependencyParserPlugin {
|
|
|
238
243
|
} else if (expr.isNumber()) {
|
|
239
244
|
groupOptions.preloadOrder = expr.number;
|
|
240
245
|
} else {
|
|
241
|
-
errors.push(
|
|
246
|
+
errors.push(
|
|
247
|
+
createPropertyParseError(parser, prop, "boolean|number")
|
|
248
|
+
);
|
|
242
249
|
}
|
|
243
250
|
break;
|
|
244
251
|
}
|
|
@@ -258,7 +265,11 @@ module.exports = class ImportMetaContextDependencyParserPlugin {
|
|
|
258
265
|
);
|
|
259
266
|
} else {
|
|
260
267
|
errors.push(
|
|
261
|
-
createPropertyParseError(
|
|
268
|
+
createPropertyParseError(
|
|
269
|
+
parser,
|
|
270
|
+
prop,
|
|
271
|
+
'"high"|"low"|"auto"'
|
|
272
|
+
)
|
|
262
273
|
);
|
|
263
274
|
}
|
|
264
275
|
break;
|
|
@@ -268,7 +279,9 @@ module.exports = class ImportMetaContextDependencyParserPlugin {
|
|
|
268
279
|
/** @type {Expression} */ (prop.value)
|
|
269
280
|
);
|
|
270
281
|
if (!recursiveExpr.isBoolean()) {
|
|
271
|
-
errors.push(
|
|
282
|
+
errors.push(
|
|
283
|
+
createPropertyParseError(parser, prop, "boolean")
|
|
284
|
+
);
|
|
272
285
|
} else {
|
|
273
286
|
recursive = /** @type {boolean} */ (recursiveExpr.bool);
|
|
274
287
|
}
|
|
@@ -280,7 +293,7 @@ module.exports = class ImportMetaContextDependencyParserPlugin {
|
|
|
280
293
|
`Parsing import.meta.webpackContext options failed. Unknown property ${JSON.stringify(
|
|
281
294
|
prop.key.name
|
|
282
295
|
)}.`,
|
|
283
|
-
|
|
296
|
+
parser.getLocation(optionsNode)
|
|
284
297
|
)
|
|
285
298
|
);
|
|
286
299
|
}
|
|
@@ -306,7 +319,7 @@ module.exports = class ImportMetaContextDependencyParserPlugin {
|
|
|
306
319
|
},
|
|
307
320
|
/** @type {Range} */ (expr.range)
|
|
308
321
|
);
|
|
309
|
-
dep.loc =
|
|
322
|
+
dep.loc = parser.getLocation(expr);
|
|
310
323
|
dep.optional = Boolean(parser.scope.inTry);
|
|
311
324
|
parser.state.current.addDependency(dep);
|
|
312
325
|
return true;
|
|
@@ -12,6 +12,9 @@ const {
|
|
|
12
12
|
const ContextElementDependency = require("./ContextElementDependency");
|
|
13
13
|
const ImportMetaContextDependency = require("./ImportMetaContextDependency");
|
|
14
14
|
const ImportMetaContextDependencyParserPlugin = require("./ImportMetaContextDependencyParserPlugin");
|
|
15
|
+
const ImportMetaGlobDependency = require("./ImportMetaGlobDependency");
|
|
16
|
+
const ImportMetaGlobDependencyParserPlugin = require("./ImportMetaGlobDependencyParserPlugin");
|
|
17
|
+
const { isImportMetaFieldEnabled } = require("./ImportMetaPlugin");
|
|
15
18
|
|
|
16
19
|
/** @typedef {import("../../declarations/WebpackOptions").JavascriptParserOptions} JavascriptParserOptions */
|
|
17
20
|
/** @typedef {import("../Compiler")} Compiler */
|
|
@@ -19,6 +22,28 @@ const ImportMetaContextDependencyParserPlugin = require("./ImportMetaContextDepe
|
|
|
19
22
|
|
|
20
23
|
const PLUGIN_NAME = "ImportMetaContextPlugin";
|
|
21
24
|
|
|
25
|
+
/** @type {(parserOptions: JavascriptParserOptions) => boolean} */
|
|
26
|
+
const isImportMetaContextEnabled = (parserOptions) => {
|
|
27
|
+
const importMeta = parserOptions.importMeta;
|
|
28
|
+
if (
|
|
29
|
+
Boolean(importMeta) &&
|
|
30
|
+
typeof importMeta === "object" &&
|
|
31
|
+
Object.prototype.hasOwnProperty.call(importMeta, "webpackContext")
|
|
32
|
+
) {
|
|
33
|
+
return isImportMetaFieldEnabled(importMeta, "webpackContext");
|
|
34
|
+
}
|
|
35
|
+
if (parserOptions.importMetaContext === false) {
|
|
36
|
+
return false;
|
|
37
|
+
}
|
|
38
|
+
return isImportMetaFieldEnabled(importMeta, "webpackContext");
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
// Gated only by the `importMeta.glob` field — independent of the legacy
|
|
42
|
+
// `importMetaContext` toggle, which controls `import.meta.webpackContext`.
|
|
43
|
+
/** @type {(parserOptions: JavascriptParserOptions) => boolean} */
|
|
44
|
+
const isImportMetaGlobEnabled = (parserOptions) =>
|
|
45
|
+
isImportMetaFieldEnabled(parserOptions.importMeta, "glob");
|
|
46
|
+
|
|
22
47
|
class ImportMetaContextPlugin {
|
|
23
48
|
/**
|
|
24
49
|
* Applies the plugin by registering its hooks on the compiler.
|
|
@@ -37,6 +62,14 @@ class ImportMetaContextPlugin {
|
|
|
37
62
|
ImportMetaContextDependency,
|
|
38
63
|
new ImportMetaContextDependency.Template()
|
|
39
64
|
);
|
|
65
|
+
compilation.dependencyFactories.set(
|
|
66
|
+
ImportMetaGlobDependency,
|
|
67
|
+
contextModuleFactory
|
|
68
|
+
);
|
|
69
|
+
compilation.dependencyTemplates.set(
|
|
70
|
+
ImportMetaGlobDependency,
|
|
71
|
+
new ImportMetaGlobDependency.Template()
|
|
72
|
+
);
|
|
40
73
|
compilation.dependencyFactories.set(
|
|
41
74
|
ContextElementDependency,
|
|
42
75
|
normalModuleFactory
|
|
@@ -49,14 +82,12 @@ class ImportMetaContextPlugin {
|
|
|
49
82
|
* @returns {void}
|
|
50
83
|
*/
|
|
51
84
|
const handler = (parser, parserOptions) => {
|
|
52
|
-
if (
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
) {
|
|
56
|
-
|
|
85
|
+
if (isImportMetaContextEnabled(parserOptions)) {
|
|
86
|
+
new ImportMetaContextDependencyParserPlugin().apply(parser);
|
|
87
|
+
}
|
|
88
|
+
if (isImportMetaGlobEnabled(parserOptions)) {
|
|
89
|
+
new ImportMetaGlobDependencyParserPlugin().apply(parser);
|
|
57
90
|
}
|
|
58
|
-
|
|
59
|
-
new ImportMetaContextDependencyParserPlugin().apply(parser);
|
|
60
91
|
};
|
|
61
92
|
|
|
62
93
|
normalModuleFactory.hooks.parser
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/*
|
|
2
|
+
MIT License http://www.opensource.org/licenses/mit-license.php
|
|
3
|
+
Author Natsu @xiaoxiaojx
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
"use strict";
|
|
7
|
+
|
|
8
|
+
const makeSerializable = require("../util/makeSerializable");
|
|
9
|
+
const ContextDependency = require("./ContextDependency");
|
|
10
|
+
const ModuleDependencyTemplateAsRequireId = require("./ModuleDependencyTemplateAsRequireId");
|
|
11
|
+
|
|
12
|
+
/** @typedef {import("../javascript/JavascriptParser").Range} Range */
|
|
13
|
+
/** @typedef {import("./ContextDependency").ContextDependencyOptions} ContextDependencyOptions */
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* @typedef {ContextDependencyOptions & {
|
|
17
|
+
* patterns: string[],
|
|
18
|
+
* requestContext: string,
|
|
19
|
+
* importName?: string,
|
|
20
|
+
* exhaustive?: boolean,
|
|
21
|
+
* caseSensitive?: boolean,
|
|
22
|
+
* }} ImportMetaGlobDependencyOptions
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
class ImportMetaGlobDependency extends ContextDependency {
|
|
26
|
+
/**
|
|
27
|
+
* @param {ImportMetaGlobDependencyOptions} options options
|
|
28
|
+
* @param {Range} range range
|
|
29
|
+
*/
|
|
30
|
+
constructor(options, range) {
|
|
31
|
+
super(options, options ? options.requestContext : undefined);
|
|
32
|
+
|
|
33
|
+
this.range = range;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
get category() {
|
|
37
|
+
return "esm";
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
get type() {
|
|
41
|
+
return `import.meta.glob ${this.options.mode}`;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Returns an identifier to merge equal requests.
|
|
46
|
+
* @returns {string | null} an identifier to merge equal requests
|
|
47
|
+
*/
|
|
48
|
+
getResourceIdentifier() {
|
|
49
|
+
const {
|
|
50
|
+
patterns,
|
|
51
|
+
request,
|
|
52
|
+
recursive,
|
|
53
|
+
mode,
|
|
54
|
+
exhaustive,
|
|
55
|
+
caseSensitive,
|
|
56
|
+
importName,
|
|
57
|
+
referencedExports
|
|
58
|
+
} = /** @type {ImportMetaGlobDependencyOptions} */ (this.options);
|
|
59
|
+
return (
|
|
60
|
+
`context${this.getContext() || ""}|glob request${request} ` +
|
|
61
|
+
`${recursive} ${patterns.join(",")} ` +
|
|
62
|
+
`${mode}${exhaustive ? " exhaustive" : ""}` +
|
|
63
|
+
`${caseSensitive === false ? " case-insensitive" : ""}` +
|
|
64
|
+
`${importName ? ` import:${importName}` : ""}` +
|
|
65
|
+
`${
|
|
66
|
+
referencedExports
|
|
67
|
+
? ` referencedExports:${JSON.stringify(referencedExports)}`
|
|
68
|
+
: ""
|
|
69
|
+
}`
|
|
70
|
+
);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
makeSerializable(
|
|
75
|
+
ImportMetaGlobDependency,
|
|
76
|
+
"webpack/lib/dependencies/ImportMetaGlobDependency"
|
|
77
|
+
);
|
|
78
|
+
|
|
79
|
+
ImportMetaGlobDependency.Template = ModuleDependencyTemplateAsRequireId;
|
|
80
|
+
|
|
81
|
+
module.exports = ImportMetaGlobDependency;
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/*
|
|
2
|
+
MIT License http://www.opensource.org/licenses/mit-license.php
|
|
3
|
+
Author Natsu @xiaoxiaojx
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
"use strict";
|
|
7
|
+
|
|
8
|
+
const {
|
|
9
|
+
evaluateToIdentifier
|
|
10
|
+
} = require("../javascript/JavascriptParserHelpers");
|
|
11
|
+
const ImportMetaGlobDependency = require("./ImportMetaGlobDependency");
|
|
12
|
+
const { parseImportMetaGlobCall } = require("./ImportMetaGlobHelpers");
|
|
13
|
+
|
|
14
|
+
/** @typedef {import("estree").CallExpression} CallExpression */
|
|
15
|
+
/** @typedef {import("../javascript/JavascriptParser")} JavascriptParser */
|
|
16
|
+
/** @typedef {import("../Dependency").DependencyLocation} DependencyLocation */
|
|
17
|
+
|
|
18
|
+
const PLUGIN_NAME = "ImportMetaGlobDependencyParserPlugin";
|
|
19
|
+
|
|
20
|
+
module.exports = class ImportMetaGlobDependencyParserPlugin {
|
|
21
|
+
/**
|
|
22
|
+
* Applies the plugin by registering its hooks on the compiler.
|
|
23
|
+
* @param {JavascriptParser} parser the parser
|
|
24
|
+
* @returns {void}
|
|
25
|
+
*/
|
|
26
|
+
apply(parser) {
|
|
27
|
+
parser.hooks.evaluateIdentifier
|
|
28
|
+
.for("import.meta.glob")
|
|
29
|
+
.tap(PLUGIN_NAME, (expr) =>
|
|
30
|
+
evaluateToIdentifier(
|
|
31
|
+
"import.meta.glob",
|
|
32
|
+
"import.meta",
|
|
33
|
+
() => ["glob"],
|
|
34
|
+
true
|
|
35
|
+
)(expr)
|
|
36
|
+
);
|
|
37
|
+
parser.hooks.call.for("import.meta.glob").tap(PLUGIN_NAME, (expr) => {
|
|
38
|
+
const {
|
|
39
|
+
options: globOptions,
|
|
40
|
+
errors,
|
|
41
|
+
warnings
|
|
42
|
+
} = parseImportMetaGlobCall(/** @type {CallExpression} */ (expr), parser);
|
|
43
|
+
for (const warning of warnings) {
|
|
44
|
+
parser.state.module.addWarning(warning);
|
|
45
|
+
}
|
|
46
|
+
if (errors.length) {
|
|
47
|
+
for (const error of errors) parser.state.current.addError(error);
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
if (!globOptions) return;
|
|
51
|
+
const dep = new ImportMetaGlobDependency(
|
|
52
|
+
{
|
|
53
|
+
request: `${globOptions.baseDir}${globOptions.query}`,
|
|
54
|
+
recursive: globOptions.recursive,
|
|
55
|
+
regExp: false,
|
|
56
|
+
patterns: globOptions.patterns,
|
|
57
|
+
requestContext: globOptions.requestContext,
|
|
58
|
+
importName: globOptions.importName,
|
|
59
|
+
exhaustive: globOptions.exhaustive,
|
|
60
|
+
caseSensitive: globOptions.caseSensitive,
|
|
61
|
+
referencedExports: globOptions.referencedExports,
|
|
62
|
+
namespaceObject:
|
|
63
|
+
/** @type {import("../Module").BuildMeta} */
|
|
64
|
+
(parser.state.module.buildMeta).strictHarmonyModule
|
|
65
|
+
? "strict"
|
|
66
|
+
: true,
|
|
67
|
+
mode: globOptions.mode,
|
|
68
|
+
category: "esm"
|
|
69
|
+
},
|
|
70
|
+
globOptions.range
|
|
71
|
+
);
|
|
72
|
+
dep.loc = parser.getLocation(expr);
|
|
73
|
+
dep.optional = Boolean(parser.scope.inTry);
|
|
74
|
+
parser.state.current.addDependency(dep);
|
|
75
|
+
return true;
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
};
|