webpack 5.76.3 → 5.78.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/bin/webpack.js +0 -0
- package/lib/APIPlugin.js +25 -18
- package/lib/CompatibilityPlugin.js +53 -52
- package/lib/ConstPlugin.js +22 -15
- package/lib/ContextModule.js +3 -2
- package/lib/DefinePlugin.js +44 -36
- package/lib/DelegatedModule.js +2 -1
- package/lib/DllModule.js +2 -1
- package/lib/ErrorHelpers.js +61 -22
- package/lib/ExportsInfoApiPlugin.js +16 -9
- package/lib/ExternalModule.js +2 -1
- package/lib/FlagAllModulesAsUsedPlugin.js +22 -27
- package/lib/FlagDependencyExportsPlugin.js +336 -348
- package/lib/FlagDependencyUsagePlugin.js +6 -8
- package/lib/FlagEntryExportAsUsedPlugin.js +22 -23
- package/lib/HotModuleReplacementPlugin.js +50 -45
- package/lib/JavascriptMetaInfoPlugin.js +16 -9
- package/lib/ModuleTypeConstants.js +50 -0
- package/lib/NodeStuffPlugin.js +35 -31
- package/lib/NormalModule.js +2 -1
- package/lib/NormalModuleFactory.js +27 -1
- package/lib/ProvidePlugin.js +17 -10
- package/lib/RawModule.js +2 -1
- package/lib/RequireJsStuffPlugin.js +15 -15
- package/lib/UseStrictPlugin.js +15 -8
- package/lib/WebpackIsIncludedPlugin.js +16 -9
- package/lib/WebpackOptionsApply.js +2 -1
- package/lib/config/defaults.js +17 -8
- package/lib/config/normalization.js +5 -0
- package/lib/container/ContainerEntryModule.js +2 -1
- package/lib/css/CssParser.js +22 -2
- package/lib/debug/ProfilingPlugin.js +20 -12
- package/lib/dependencies/AMDPlugin.js +26 -20
- package/lib/dependencies/CommonJsImportsParserPlugin.js +5 -4
- package/lib/dependencies/CommonJsPlugin.js +29 -25
- package/lib/dependencies/HarmonyDetectionParserPlugin.js +3 -1
- package/lib/dependencies/HarmonyModulesPlugin.js +11 -5
- package/lib/dependencies/ImportMetaContextPlugin.js +11 -5
- package/lib/dependencies/ImportMetaPlugin.js +26 -20
- package/lib/dependencies/ImportPlugin.js +14 -7
- package/lib/dependencies/RequireContextPlugin.js +12 -6
- package/lib/dependencies/RequireEnsurePlugin.js +13 -7
- package/lib/dependencies/RequireIncludePlugin.js +11 -5
- package/lib/dependencies/SystemPlugin.js +21 -15
- package/lib/dependencies/URLPlugin.js +15 -9
- package/lib/dependencies/WorkerDependency.js +37 -2
- package/lib/dependencies/WorkerPlugin.js +19 -10
- package/lib/javascript/JavascriptModulesPlugin.js +157 -164
- package/lib/json/JsonModulesPlugin.js +13 -5
- package/lib/library/AmdLibraryPlugin.js +22 -6
- package/lib/node/ReadFileCompileAsyncWasmPlugin.js +2 -1
- package/lib/node/ReadFileCompileWasmPlugin.js +2 -1
- package/lib/optimize/ConcatenatedModule.js +2 -1
- package/lib/optimize/InnerGraphPlugin.js +47 -46
- package/lib/optimize/SideEffectsFlagPlugin.js +43 -43
- package/lib/sharing/ConsumeSharedPlugin.js +4 -0
- package/lib/wasm-async/AsyncWebAssemblyModulesPlugin.js +9 -6
- package/lib/wasm-sync/WebAssemblyModulesPlugin.js +42 -43
- package/lib/web/FetchCompileAsyncWasmPlugin.js +2 -1
- package/lib/web/FetchCompileWasmPlugin.js +40 -40
- package/package.json +1 -1
- package/schemas/WebpackOptions.check.js +1 -1
- package/schemas/WebpackOptions.json +28 -0
- package/schemas/plugins/container/ContainerPlugin.check.js +1 -1
- package/schemas/plugins/container/ContainerPlugin.json +8 -0
- package/schemas/plugins/container/ModuleFederationPlugin.check.js +1 -1
- package/schemas/plugins/container/ModuleFederationPlugin.json +8 -0
- package/types.d.ts +20 -0
@@ -5,6 +5,10 @@
|
|
5
5
|
|
6
6
|
"use strict";
|
7
7
|
|
8
|
+
const {
|
9
|
+
JAVASCRIPT_MODULE_TYPE_AUTO,
|
10
|
+
JAVASCRIPT_MODULE_TYPE_DYNAMIC
|
11
|
+
} = require("../ModuleTypeConstants");
|
8
12
|
const RuntimeGlobals = require("../RuntimeGlobals");
|
9
13
|
const {
|
10
14
|
approve,
|
@@ -31,6 +35,8 @@ const UnsupportedDependency = require("./UnsupportedDependency");
|
|
31
35
|
/** @typedef {import("../../declarations/WebpackOptions").ModuleOptionsNormalized} ModuleOptions */
|
32
36
|
/** @typedef {import("../Compiler")} Compiler */
|
33
37
|
|
38
|
+
const PLUGIN_NAME = "AMDPlugin";
|
39
|
+
|
34
40
|
class AMDPlugin {
|
35
41
|
/**
|
36
42
|
* @param {Record<string, any>} amdOptions the AMD options
|
@@ -47,7 +53,7 @@ class AMDPlugin {
|
|
47
53
|
apply(compiler) {
|
48
54
|
const amdOptions = this.amdOptions;
|
49
55
|
compiler.hooks.compilation.tap(
|
50
|
-
|
56
|
+
PLUGIN_NAME,
|
51
57
|
(compilation, { contextModuleFactory, normalModuleFactory }) => {
|
52
58
|
compilation.dependencyTemplates.set(
|
53
59
|
AMDRequireDependency,
|
@@ -94,25 +100,25 @@ class AMDPlugin {
|
|
94
100
|
|
95
101
|
compilation.hooks.runtimeRequirementInModule
|
96
102
|
.for(RuntimeGlobals.amdDefine)
|
97
|
-
.tap(
|
103
|
+
.tap(PLUGIN_NAME, (module, set) => {
|
98
104
|
set.add(RuntimeGlobals.require);
|
99
105
|
});
|
100
106
|
|
101
107
|
compilation.hooks.runtimeRequirementInModule
|
102
108
|
.for(RuntimeGlobals.amdOptions)
|
103
|
-
.tap(
|
109
|
+
.tap(PLUGIN_NAME, (module, set) => {
|
104
110
|
set.add(RuntimeGlobals.requireScope);
|
105
111
|
});
|
106
112
|
|
107
113
|
compilation.hooks.runtimeRequirementInTree
|
108
114
|
.for(RuntimeGlobals.amdDefine)
|
109
|
-
.tap(
|
115
|
+
.tap(PLUGIN_NAME, (chunk, set) => {
|
110
116
|
compilation.addRuntimeModule(chunk, new AMDDefineRuntimeModule());
|
111
117
|
});
|
112
118
|
|
113
119
|
compilation.hooks.runtimeRequirementInTree
|
114
120
|
.for(RuntimeGlobals.amdOptions)
|
115
|
-
.tap(
|
121
|
+
.tap(PLUGIN_NAME, (chunk, set) => {
|
116
122
|
compilation.addRuntimeModule(
|
117
123
|
chunk,
|
118
124
|
new AMDOptionsRuntimeModule(amdOptions)
|
@@ -126,7 +132,7 @@ class AMDPlugin {
|
|
126
132
|
parser.hooks.expression
|
127
133
|
.for(optionExpr)
|
128
134
|
.tap(
|
129
|
-
|
135
|
+
PLUGIN_NAME,
|
130
136
|
toConstantDependency(parser, RuntimeGlobals.amdOptions, [
|
131
137
|
RuntimeGlobals.amdOptions
|
132
138
|
])
|
@@ -134,16 +140,16 @@ class AMDPlugin {
|
|
134
140
|
parser.hooks.evaluateIdentifier
|
135
141
|
.for(optionExpr)
|
136
142
|
.tap(
|
137
|
-
|
143
|
+
PLUGIN_NAME,
|
138
144
|
evaluateToIdentifier(optionExpr, rootName, getMembers, true)
|
139
145
|
);
|
140
146
|
parser.hooks.evaluateTypeof
|
141
147
|
.for(optionExpr)
|
142
|
-
.tap(
|
148
|
+
.tap(PLUGIN_NAME, evaluateToString("object"));
|
143
149
|
parser.hooks.typeof
|
144
150
|
.for(optionExpr)
|
145
151
|
.tap(
|
146
|
-
|
152
|
+
PLUGIN_NAME,
|
147
153
|
toConstantDependency(parser, JSON.stringify("object"))
|
148
154
|
);
|
149
155
|
};
|
@@ -161,7 +167,7 @@ class AMDPlugin {
|
|
161
167
|
() => []
|
162
168
|
);
|
163
169
|
|
164
|
-
parser.hooks.expression.for("define").tap(
|
170
|
+
parser.hooks.expression.for("define").tap(PLUGIN_NAME, expr => {
|
165
171
|
const dep = new ConstDependency(
|
166
172
|
RuntimeGlobals.amdDefine,
|
167
173
|
expr.range,
|
@@ -174,14 +180,14 @@ class AMDPlugin {
|
|
174
180
|
parser.hooks.typeof
|
175
181
|
.for("define")
|
176
182
|
.tap(
|
177
|
-
|
183
|
+
PLUGIN_NAME,
|
178
184
|
toConstantDependency(parser, JSON.stringify("function"))
|
179
185
|
);
|
180
186
|
parser.hooks.evaluateTypeof
|
181
187
|
.for("define")
|
182
|
-
.tap(
|
183
|
-
parser.hooks.canRename.for("define").tap(
|
184
|
-
parser.hooks.rename.for("define").tap(
|
188
|
+
.tap(PLUGIN_NAME, evaluateToString("function"));
|
189
|
+
parser.hooks.canRename.for("define").tap(PLUGIN_NAME, approve);
|
190
|
+
parser.hooks.rename.for("define").tap(PLUGIN_NAME, expr => {
|
185
191
|
const dep = new ConstDependency(
|
186
192
|
RuntimeGlobals.amdDefine,
|
187
193
|
expr.range,
|
@@ -194,20 +200,20 @@ class AMDPlugin {
|
|
194
200
|
parser.hooks.typeof
|
195
201
|
.for("require")
|
196
202
|
.tap(
|
197
|
-
|
203
|
+
PLUGIN_NAME,
|
198
204
|
toConstantDependency(parser, JSON.stringify("function"))
|
199
205
|
);
|
200
206
|
parser.hooks.evaluateTypeof
|
201
207
|
.for("require")
|
202
|
-
.tap(
|
208
|
+
.tap(PLUGIN_NAME, evaluateToString("function"));
|
203
209
|
};
|
204
210
|
|
205
211
|
normalModuleFactory.hooks.parser
|
206
|
-
.for(
|
207
|
-
.tap(
|
212
|
+
.for(JAVASCRIPT_MODULE_TYPE_AUTO)
|
213
|
+
.tap(PLUGIN_NAME, handler);
|
208
214
|
normalModuleFactory.hooks.parser
|
209
|
-
.for(
|
210
|
-
.tap(
|
215
|
+
.for(JAVASCRIPT_MODULE_TYPE_DYNAMIC)
|
216
|
+
.tap(PLUGIN_NAME, handler);
|
211
217
|
}
|
212
218
|
);
|
213
219
|
}
|
@@ -444,13 +444,14 @@ class CommonJsImportsParserPlugin {
|
|
444
444
|
|
445
445
|
if (!options.createRequire) return;
|
446
446
|
|
447
|
-
let moduleName;
|
447
|
+
let moduleName = [];
|
448
448
|
let specifierName;
|
449
449
|
|
450
450
|
if (options.createRequire === true) {
|
451
|
-
moduleName = "module";
|
451
|
+
moduleName = ["module", "node:module"];
|
452
452
|
specifierName = "createRequire";
|
453
453
|
} else {
|
454
|
+
let moduleName;
|
454
455
|
const match = /^(.*) from (.*)$/.exec(options.createRequire);
|
455
456
|
if (match) {
|
456
457
|
[, specifierName, moduleName] = match;
|
@@ -545,7 +546,7 @@ class CommonJsImportsParserPlugin {
|
|
545
546
|
},
|
546
547
|
(statement, source) => {
|
547
548
|
if (
|
548
|
-
source
|
549
|
+
!moduleName.includes(source) ||
|
549
550
|
statement.specifiers.length !== 1 ||
|
550
551
|
statement.specifiers[0].type !== "ImportSpecifier" ||
|
551
552
|
statement.specifiers[0].imported.type !== "Identifier" ||
|
@@ -570,7 +571,7 @@ class CommonJsImportsParserPlugin {
|
|
570
571
|
stage: -10
|
571
572
|
},
|
572
573
|
(statement, source, id, name) => {
|
573
|
-
if (source
|
574
|
+
if (!moduleName.includes(source) || id !== specifierName) return;
|
574
575
|
parser.tagVariable(name, createRequireSpecifierTag);
|
575
576
|
return true;
|
576
577
|
}
|
@@ -24,16 +24,22 @@ const RuntimeRequirementsDependency = require("./RuntimeRequirementsDependency")
|
|
24
24
|
const CommonJsExportsParserPlugin = require("./CommonJsExportsParserPlugin");
|
25
25
|
const CommonJsImportsParserPlugin = require("./CommonJsImportsParserPlugin");
|
26
26
|
|
27
|
+
const {
|
28
|
+
JAVASCRIPT_MODULE_TYPE_AUTO,
|
29
|
+
JAVASCRIPT_MODULE_TYPE_DYNAMIC
|
30
|
+
} = require("../ModuleTypeConstants");
|
27
31
|
const {
|
28
32
|
evaluateToIdentifier,
|
29
33
|
toConstantDependency
|
30
34
|
} = require("../javascript/JavascriptParserHelpers");
|
31
35
|
const CommonJsExportRequireDependency = require("./CommonJsExportRequireDependency");
|
32
36
|
|
37
|
+
const PLUGIN_NAME = "CommonJsPlugin";
|
38
|
+
|
33
39
|
class CommonJsPlugin {
|
34
40
|
apply(compiler) {
|
35
41
|
compiler.hooks.compilation.tap(
|
36
|
-
|
42
|
+
PLUGIN_NAME,
|
37
43
|
(compilation, { contextModuleFactory, normalModuleFactory }) => {
|
38
44
|
compilation.dependencyFactories.set(
|
39
45
|
CommonJsRequireDependency,
|
@@ -126,21 +132,21 @@ class CommonJsPlugin {
|
|
126
132
|
|
127
133
|
compilation.hooks.runtimeRequirementInModule
|
128
134
|
.for(RuntimeGlobals.harmonyModuleDecorator)
|
129
|
-
.tap(
|
135
|
+
.tap(PLUGIN_NAME, (module, set) => {
|
130
136
|
set.add(RuntimeGlobals.module);
|
131
137
|
set.add(RuntimeGlobals.requireScope);
|
132
138
|
});
|
133
139
|
|
134
140
|
compilation.hooks.runtimeRequirementInModule
|
135
141
|
.for(RuntimeGlobals.nodeModuleDecorator)
|
136
|
-
.tap(
|
142
|
+
.tap(PLUGIN_NAME, (module, set) => {
|
137
143
|
set.add(RuntimeGlobals.module);
|
138
144
|
set.add(RuntimeGlobals.requireScope);
|
139
145
|
});
|
140
146
|
|
141
147
|
compilation.hooks.runtimeRequirementInTree
|
142
148
|
.for(RuntimeGlobals.harmonyModuleDecorator)
|
143
|
-
.tap(
|
149
|
+
.tap(PLUGIN_NAME, (chunk, set) => {
|
144
150
|
compilation.addRuntimeModule(
|
145
151
|
chunk,
|
146
152
|
new HarmonyModuleDecoratorRuntimeModule()
|
@@ -149,7 +155,7 @@ class CommonJsPlugin {
|
|
149
155
|
|
150
156
|
compilation.hooks.runtimeRequirementInTree
|
151
157
|
.for(RuntimeGlobals.nodeModuleDecorator)
|
152
|
-
.tap(
|
158
|
+
.tap(PLUGIN_NAME, (chunk, set) => {
|
153
159
|
compilation.addRuntimeModule(
|
154
160
|
chunk,
|
155
161
|
new NodeModuleDecoratorRuntimeModule()
|
@@ -162,14 +168,14 @@ class CommonJsPlugin {
|
|
162
168
|
parser.hooks.typeof
|
163
169
|
.for("module")
|
164
170
|
.tap(
|
165
|
-
|
171
|
+
PLUGIN_NAME,
|
166
172
|
toConstantDependency(parser, JSON.stringify("object"))
|
167
173
|
);
|
168
174
|
|
169
175
|
parser.hooks.expression
|
170
176
|
.for("require.main")
|
171
177
|
.tap(
|
172
|
-
|
178
|
+
PLUGIN_NAME,
|
173
179
|
toConstantDependency(
|
174
180
|
parser,
|
175
181
|
`${RuntimeGlobals.moduleCache}[${RuntimeGlobals.entryModuleId}]`,
|
@@ -178,7 +184,7 @@ class CommonJsPlugin {
|
|
178
184
|
);
|
179
185
|
parser.hooks.expression
|
180
186
|
.for("module.loaded")
|
181
|
-
.tap(
|
187
|
+
.tap(PLUGIN_NAME, expr => {
|
182
188
|
parser.state.module.buildInfo.moduleConcatenationBailout =
|
183
189
|
"module.loaded";
|
184
190
|
const dep = new RuntimeRequirementsDependency([
|
@@ -189,21 +195,19 @@ class CommonJsPlugin {
|
|
189
195
|
return true;
|
190
196
|
});
|
191
197
|
|
192
|
-
parser.hooks.expression
|
193
|
-
.
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
return true;
|
203
|
-
});
|
198
|
+
parser.hooks.expression.for("module.id").tap(PLUGIN_NAME, expr => {
|
199
|
+
parser.state.module.buildInfo.moduleConcatenationBailout =
|
200
|
+
"module.id";
|
201
|
+
const dep = new RuntimeRequirementsDependency([
|
202
|
+
RuntimeGlobals.moduleId
|
203
|
+
]);
|
204
|
+
dep.loc = expr.loc;
|
205
|
+
parser.state.module.addPresentationalDependency(dep);
|
206
|
+
return true;
|
207
|
+
});
|
204
208
|
|
205
209
|
parser.hooks.evaluateIdentifier.for("module.hot").tap(
|
206
|
-
|
210
|
+
PLUGIN_NAME,
|
207
211
|
evaluateToIdentifier("module.hot", "module", () => ["hot"], null)
|
208
212
|
);
|
209
213
|
|
@@ -214,11 +218,11 @@ class CommonJsPlugin {
|
|
214
218
|
};
|
215
219
|
|
216
220
|
normalModuleFactory.hooks.parser
|
217
|
-
.for(
|
218
|
-
.tap(
|
221
|
+
.for(JAVASCRIPT_MODULE_TYPE_AUTO)
|
222
|
+
.tap(PLUGIN_NAME, handler);
|
219
223
|
normalModuleFactory.hooks.parser
|
220
|
-
.for(
|
221
|
-
.tap(
|
224
|
+
.for(JAVASCRIPT_MODULE_TYPE_DYNAMIC)
|
225
|
+
.tap(PLUGIN_NAME, handler);
|
222
226
|
}
|
223
227
|
);
|
224
228
|
}
|
@@ -5,6 +5,7 @@
|
|
5
5
|
|
6
6
|
"use strict";
|
7
7
|
|
8
|
+
const { JAVASCRIPT_MODULE_TYPE_ESM } = require("../ModuleTypeConstants");
|
8
9
|
const DynamicExports = require("./DynamicExports");
|
9
10
|
const HarmonyCompatibilityDependency = require("./HarmonyCompatibilityDependency");
|
10
11
|
const HarmonyExports = require("./HarmonyExports");
|
@@ -17,7 +18,8 @@ module.exports = class HarmonyDetectionParserPlugin {
|
|
17
18
|
|
18
19
|
apply(parser) {
|
19
20
|
parser.hooks.program.tap("HarmonyDetectionParserPlugin", ast => {
|
20
|
-
const isStrictHarmony =
|
21
|
+
const isStrictHarmony =
|
22
|
+
parser.state.module.type === JAVASCRIPT_MODULE_TYPE_ESM;
|
21
23
|
const isHarmony =
|
22
24
|
isStrictHarmony ||
|
23
25
|
ast.body.some(
|
@@ -16,6 +16,10 @@ const HarmonyExportSpecifierDependency = require("./HarmonyExportSpecifierDepend
|
|
16
16
|
const HarmonyImportSideEffectDependency = require("./HarmonyImportSideEffectDependency");
|
17
17
|
const HarmonyImportSpecifierDependency = require("./HarmonyImportSpecifierDependency");
|
18
18
|
|
19
|
+
const {
|
20
|
+
JAVASCRIPT_MODULE_TYPE_AUTO,
|
21
|
+
JAVASCRIPT_MODULE_TYPE_ESM
|
22
|
+
} = require("../ModuleTypeConstants");
|
19
23
|
const HarmonyDetectionParserPlugin = require("./HarmonyDetectionParserPlugin");
|
20
24
|
const HarmonyExportDependencyParserPlugin = require("./HarmonyExportDependencyParserPlugin");
|
21
25
|
const HarmonyImportDependencyParserPlugin = require("./HarmonyImportDependencyParserPlugin");
|
@@ -23,6 +27,8 @@ const HarmonyTopLevelThisParserPlugin = require("./HarmonyTopLevelThisParserPlug
|
|
23
27
|
|
24
28
|
/** @typedef {import("../Compiler")} Compiler */
|
25
29
|
|
30
|
+
const PLUGIN_NAME = "HarmonyModulesPlugin";
|
31
|
+
|
26
32
|
class HarmonyModulesPlugin {
|
27
33
|
constructor(options) {
|
28
34
|
this.options = options;
|
@@ -35,7 +41,7 @@ class HarmonyModulesPlugin {
|
|
35
41
|
*/
|
36
42
|
apply(compiler) {
|
37
43
|
compiler.hooks.compilation.tap(
|
38
|
-
|
44
|
+
PLUGIN_NAME,
|
39
45
|
(compilation, { normalModuleFactory }) => {
|
40
46
|
compilation.dependencyTemplates.set(
|
41
47
|
HarmonyCompatibilityDependency,
|
@@ -119,11 +125,11 @@ class HarmonyModulesPlugin {
|
|
119
125
|
};
|
120
126
|
|
121
127
|
normalModuleFactory.hooks.parser
|
122
|
-
.for(
|
123
|
-
.tap(
|
128
|
+
.for(JAVASCRIPT_MODULE_TYPE_AUTO)
|
129
|
+
.tap(PLUGIN_NAME, handler);
|
124
130
|
normalModuleFactory.hooks.parser
|
125
|
-
.for(
|
126
|
-
.tap(
|
131
|
+
.for(JAVASCRIPT_MODULE_TYPE_ESM)
|
132
|
+
.tap(PLUGIN_NAME, handler);
|
127
133
|
}
|
128
134
|
);
|
129
135
|
}
|
@@ -5,6 +5,10 @@
|
|
5
5
|
|
6
6
|
"use strict";
|
7
7
|
|
8
|
+
const {
|
9
|
+
JAVASCRIPT_MODULE_TYPE_AUTO,
|
10
|
+
JAVASCRIPT_MODULE_TYPE_ESM
|
11
|
+
} = require("../ModuleTypeConstants");
|
8
12
|
const ContextElementDependency = require("./ContextElementDependency");
|
9
13
|
const ImportMetaContextDependency = require("./ImportMetaContextDependency");
|
10
14
|
const ImportMetaContextDependencyParserPlugin = require("./ImportMetaContextDependencyParserPlugin");
|
@@ -12,6 +16,8 @@ const ImportMetaContextDependencyParserPlugin = require("./ImportMetaContextDepe
|
|
12
16
|
/** @typedef {import("../../declarations/WebpackOptions").ResolveOptions} ResolveOptions */
|
13
17
|
/** @typedef {import("../Compiler")} Compiler */
|
14
18
|
|
19
|
+
const PLUGIN_NAME = "ImportMetaContextPlugin";
|
20
|
+
|
15
21
|
class ImportMetaContextPlugin {
|
16
22
|
/**
|
17
23
|
* Apply the plugin
|
@@ -20,7 +26,7 @@ class ImportMetaContextPlugin {
|
|
20
26
|
*/
|
21
27
|
apply(compiler) {
|
22
28
|
compiler.hooks.compilation.tap(
|
23
|
-
|
29
|
+
PLUGIN_NAME,
|
24
30
|
(compilation, { contextModuleFactory, normalModuleFactory }) => {
|
25
31
|
compilation.dependencyFactories.set(
|
26
32
|
ImportMetaContextDependency,
|
@@ -46,11 +52,11 @@ class ImportMetaContextPlugin {
|
|
46
52
|
};
|
47
53
|
|
48
54
|
normalModuleFactory.hooks.parser
|
49
|
-
.for(
|
50
|
-
.tap(
|
55
|
+
.for(JAVASCRIPT_MODULE_TYPE_AUTO)
|
56
|
+
.tap(PLUGIN_NAME, handler);
|
51
57
|
normalModuleFactory.hooks.parser
|
52
|
-
.for(
|
53
|
-
.tap(
|
58
|
+
.for(JAVASCRIPT_MODULE_TYPE_ESM)
|
59
|
+
.tap(PLUGIN_NAME, handler);
|
54
60
|
}
|
55
61
|
);
|
56
62
|
}
|
@@ -7,6 +7,10 @@
|
|
7
7
|
|
8
8
|
const { pathToFileURL } = require("url");
|
9
9
|
const ModuleDependencyWarning = require("../ModuleDependencyWarning");
|
10
|
+
const {
|
11
|
+
JAVASCRIPT_MODULE_TYPE_AUTO,
|
12
|
+
JAVASCRIPT_MODULE_TYPE_ESM
|
13
|
+
} = require("../ModuleTypeConstants");
|
10
14
|
const Template = require("../Template");
|
11
15
|
const BasicEvaluatedExpression = require("../javascript/BasicEvaluatedExpression");
|
12
16
|
const {
|
@@ -29,13 +33,15 @@ const getCriticalDependencyWarning = memoize(() =>
|
|
29
33
|
require("./CriticalDependencyWarning")
|
30
34
|
);
|
31
35
|
|
36
|
+
const PLUGIN_NAME = "ImportMetaPlugin";
|
37
|
+
|
32
38
|
class ImportMetaPlugin {
|
33
39
|
/**
|
34
40
|
* @param {Compiler} compiler compiler
|
35
41
|
*/
|
36
42
|
apply(compiler) {
|
37
43
|
compiler.hooks.compilation.tap(
|
38
|
-
|
44
|
+
PLUGIN_NAME,
|
39
45
|
(compilation, { normalModuleFactory }) => {
|
40
46
|
/**
|
41
47
|
* @param {NormalModule} module module
|
@@ -56,7 +62,7 @@ class ImportMetaPlugin {
|
|
56
62
|
|
57
63
|
parser.hooks.expression
|
58
64
|
.for("import.meta")
|
59
|
-
.tap(
|
65
|
+
.tap(PLUGIN_NAME, metaProperty => {
|
60
66
|
const dep = new ConstDependency(
|
61
67
|
importMetaName,
|
62
68
|
metaProperty.range
|
@@ -72,12 +78,12 @@ class ImportMetaPlugin {
|
|
72
78
|
parser.hooks.typeof
|
73
79
|
.for("import.meta")
|
74
80
|
.tap(
|
75
|
-
|
81
|
+
PLUGIN_NAME,
|
76
82
|
toConstantDependency(parser, JSON.stringify("object"))
|
77
83
|
);
|
78
84
|
parser.hooks.expression
|
79
85
|
.for("import.meta")
|
80
|
-
.tap(
|
86
|
+
.tap(PLUGIN_NAME, metaProperty => {
|
81
87
|
const CriticalDependencyWarning = getCriticalDependencyWarning();
|
82
88
|
parser.state.module.addWarning(
|
83
89
|
new ModuleDependencyWarning(
|
@@ -98,9 +104,9 @@ class ImportMetaPlugin {
|
|
98
104
|
});
|
99
105
|
parser.hooks.evaluateTypeof
|
100
106
|
.for("import.meta")
|
101
|
-
.tap(
|
107
|
+
.tap(PLUGIN_NAME, evaluateToString("object"));
|
102
108
|
parser.hooks.evaluateIdentifier.for("import.meta").tap(
|
103
|
-
|
109
|
+
PLUGIN_NAME,
|
104
110
|
evaluateToIdentifier("import.meta", "import.meta", () => [], true)
|
105
111
|
);
|
106
112
|
|
@@ -108,12 +114,12 @@ class ImportMetaPlugin {
|
|
108
114
|
parser.hooks.typeof
|
109
115
|
.for("import.meta.url")
|
110
116
|
.tap(
|
111
|
-
|
117
|
+
PLUGIN_NAME,
|
112
118
|
toConstantDependency(parser, JSON.stringify("string"))
|
113
119
|
);
|
114
120
|
parser.hooks.expression
|
115
121
|
.for("import.meta.url")
|
116
|
-
.tap(
|
122
|
+
.tap(PLUGIN_NAME, expr => {
|
117
123
|
const dep = new ConstDependency(
|
118
124
|
JSON.stringify(getUrl(parser.state.module)),
|
119
125
|
expr.range
|
@@ -124,10 +130,10 @@ class ImportMetaPlugin {
|
|
124
130
|
});
|
125
131
|
parser.hooks.evaluateTypeof
|
126
132
|
.for("import.meta.url")
|
127
|
-
.tap(
|
133
|
+
.tap(PLUGIN_NAME, evaluateToString("string"));
|
128
134
|
parser.hooks.evaluateIdentifier
|
129
135
|
.for("import.meta.url")
|
130
|
-
.tap(
|
136
|
+
.tap(PLUGIN_NAME, expr => {
|
131
137
|
return new BasicEvaluatedExpression()
|
132
138
|
.setString(getUrl(parser.state.module))
|
133
139
|
.setRange(expr.range);
|
@@ -141,26 +147,26 @@ class ImportMetaPlugin {
|
|
141
147
|
parser.hooks.typeof
|
142
148
|
.for("import.meta.webpack")
|
143
149
|
.tap(
|
144
|
-
|
150
|
+
PLUGIN_NAME,
|
145
151
|
toConstantDependency(parser, JSON.stringify("number"))
|
146
152
|
);
|
147
153
|
parser.hooks.expression
|
148
154
|
.for("import.meta.webpack")
|
149
155
|
.tap(
|
150
|
-
|
156
|
+
PLUGIN_NAME,
|
151
157
|
toConstantDependency(parser, JSON.stringify(webpackVersion))
|
152
158
|
);
|
153
159
|
parser.hooks.evaluateTypeof
|
154
160
|
.for("import.meta.webpack")
|
155
|
-
.tap(
|
161
|
+
.tap(PLUGIN_NAME, evaluateToString("number"));
|
156
162
|
parser.hooks.evaluateIdentifier
|
157
163
|
.for("import.meta.webpack")
|
158
|
-
.tap(
|
164
|
+
.tap(PLUGIN_NAME, evaluateToNumber(webpackVersion));
|
159
165
|
|
160
166
|
/// Unknown properties ///
|
161
167
|
parser.hooks.unhandledExpressionMemberChain
|
162
168
|
.for("import.meta")
|
163
|
-
.tap(
|
169
|
+
.tap(PLUGIN_NAME, (expr, members) => {
|
164
170
|
const dep = new ConstDependency(
|
165
171
|
`${Template.toNormalComment(
|
166
172
|
"unsupported import.meta." + members.join(".")
|
@@ -173,7 +179,7 @@ class ImportMetaPlugin {
|
|
173
179
|
});
|
174
180
|
parser.hooks.evaluate
|
175
181
|
.for("MemberExpression")
|
176
|
-
.tap(
|
182
|
+
.tap(PLUGIN_NAME, expression => {
|
177
183
|
const expr = /** @type {MemberExpression} */ (expression);
|
178
184
|
if (
|
179
185
|
expr.object.type === "MetaProperty" &&
|
@@ -190,11 +196,11 @@ class ImportMetaPlugin {
|
|
190
196
|
};
|
191
197
|
|
192
198
|
normalModuleFactory.hooks.parser
|
193
|
-
.for(
|
194
|
-
.tap(
|
199
|
+
.for(JAVASCRIPT_MODULE_TYPE_AUTO)
|
200
|
+
.tap(PLUGIN_NAME, parserHandler);
|
195
201
|
normalModuleFactory.hooks.parser
|
196
|
-
.for(
|
197
|
-
.tap(
|
202
|
+
.for(JAVASCRIPT_MODULE_TYPE_ESM)
|
203
|
+
.tap(PLUGIN_NAME, parserHandler);
|
198
204
|
}
|
199
205
|
);
|
200
206
|
}
|
@@ -5,6 +5,11 @@
|
|
5
5
|
|
6
6
|
"use strict";
|
7
7
|
|
8
|
+
const {
|
9
|
+
JAVASCRIPT_MODULE_TYPE_AUTO,
|
10
|
+
JAVASCRIPT_MODULE_TYPE_DYNAMIC,
|
11
|
+
JAVASCRIPT_MODULE_TYPE_ESM
|
12
|
+
} = require("../ModuleTypeConstants");
|
8
13
|
const ImportContextDependency = require("./ImportContextDependency");
|
9
14
|
const ImportDependency = require("./ImportDependency");
|
10
15
|
const ImportEagerDependency = require("./ImportEagerDependency");
|
@@ -13,6 +18,8 @@ const ImportWeakDependency = require("./ImportWeakDependency");
|
|
13
18
|
|
14
19
|
/** @typedef {import("../Compiler")} Compiler */
|
15
20
|
|
21
|
+
const PLUGIN_NAME = "ImportPlugin";
|
22
|
+
|
16
23
|
class ImportPlugin {
|
17
24
|
/**
|
18
25
|
* Apply the plugin
|
@@ -21,7 +28,7 @@ class ImportPlugin {
|
|
21
28
|
*/
|
22
29
|
apply(compiler) {
|
23
30
|
compiler.hooks.compilation.tap(
|
24
|
-
|
31
|
+
PLUGIN_NAME,
|
25
32
|
(compilation, { contextModuleFactory, normalModuleFactory }) => {
|
26
33
|
compilation.dependencyFactories.set(
|
27
34
|
ImportDependency,
|
@@ -67,14 +74,14 @@ class ImportPlugin {
|
|
67
74
|
};
|
68
75
|
|
69
76
|
normalModuleFactory.hooks.parser
|
70
|
-
.for(
|
71
|
-
.tap(
|
77
|
+
.for(JAVASCRIPT_MODULE_TYPE_AUTO)
|
78
|
+
.tap(PLUGIN_NAME, handler);
|
72
79
|
normalModuleFactory.hooks.parser
|
73
|
-
.for(
|
74
|
-
.tap(
|
80
|
+
.for(JAVASCRIPT_MODULE_TYPE_DYNAMIC)
|
81
|
+
.tap(PLUGIN_NAME, handler);
|
75
82
|
normalModuleFactory.hooks.parser
|
76
|
-
.for(
|
77
|
-
.tap(
|
83
|
+
.for(JAVASCRIPT_MODULE_TYPE_ESM)
|
84
|
+
.tap(PLUGIN_NAME, handler);
|
78
85
|
}
|
79
86
|
);
|
80
87
|
}
|
@@ -5,6 +5,10 @@
|
|
5
5
|
|
6
6
|
"use strict";
|
7
7
|
|
8
|
+
const {
|
9
|
+
JAVASCRIPT_MODULE_TYPE_AUTO,
|
10
|
+
JAVASCRIPT_MODULE_TYPE_DYNAMIC
|
11
|
+
} = require("../ModuleTypeConstants");
|
8
12
|
const { cachedSetProperty } = require("../util/cleverMerge");
|
9
13
|
const ContextElementDependency = require("./ContextElementDependency");
|
10
14
|
const RequireContextDependency = require("./RequireContextDependency");
|
@@ -16,6 +20,8 @@ const RequireContextDependencyParserPlugin = require("./RequireContextDependency
|
|
16
20
|
/** @type {ResolveOptions} */
|
17
21
|
const EMPTY_RESOLVE_OPTIONS = {};
|
18
22
|
|
23
|
+
const PLUGIN_NAME = "RequireContextPlugin";
|
24
|
+
|
19
25
|
class RequireContextPlugin {
|
20
26
|
/**
|
21
27
|
* Apply the plugin
|
@@ -24,7 +30,7 @@ class RequireContextPlugin {
|
|
24
30
|
*/
|
25
31
|
apply(compiler) {
|
26
32
|
compiler.hooks.compilation.tap(
|
27
|
-
|
33
|
+
PLUGIN_NAME,
|
28
34
|
(compilation, { contextModuleFactory, normalModuleFactory }) => {
|
29
35
|
compilation.dependencyFactories.set(
|
30
36
|
RequireContextDependency,
|
@@ -51,14 +57,14 @@ class RequireContextPlugin {
|
|
51
57
|
};
|
52
58
|
|
53
59
|
normalModuleFactory.hooks.parser
|
54
|
-
.for(
|
55
|
-
.tap(
|
60
|
+
.for(JAVASCRIPT_MODULE_TYPE_AUTO)
|
61
|
+
.tap(PLUGIN_NAME, handler);
|
56
62
|
normalModuleFactory.hooks.parser
|
57
|
-
.for(
|
58
|
-
.tap(
|
63
|
+
.for(JAVASCRIPT_MODULE_TYPE_DYNAMIC)
|
64
|
+
.tap(PLUGIN_NAME, handler);
|
59
65
|
|
60
66
|
contextModuleFactory.hooks.alternativeRequests.tap(
|
61
|
-
|
67
|
+
PLUGIN_NAME,
|
62
68
|
(items, options) => {
|
63
69
|
if (items.length === 0) return items;
|
64
70
|
|