webpack 5.72.0 → 5.74.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 +16 -9
- package/lib/Compilation.js +5 -1
- package/lib/Compiler.js +1 -1
- package/lib/DllReferencePlugin.js +1 -1
- package/lib/FileSystemInfo.js +35 -14
- package/lib/NodeStuffPlugin.js +3 -3
- package/lib/NormalModule.js +1 -1
- package/lib/RuntimePlugin.js +7 -0
- package/lib/config/defaults.js +12 -4
- package/lib/container/ModuleFederationPlugin.js +2 -0
- package/lib/css/CssLoadingRuntimeModule.js +9 -7
- package/lib/dependencies/CommonJsImportsParserPlugin.js +342 -61
- package/lib/dependencies/CommonJsRequireContextDependency.js +2 -2
- package/lib/dependencies/CommonJsRequireDependency.js +2 -1
- package/lib/dependencies/ContextDependency.js +15 -2
- package/lib/dependencies/ContextDependencyHelpers.js +18 -5
- package/lib/dependencies/ContextElementDependency.js +0 -16
- package/lib/dependencies/HarmonyEvaluatedImportSpecifierDependency.js +35 -3
- package/lib/dependencies/ImportParserPlugin.js +31 -25
- package/lib/dependencies/JsonExportsDependency.js +17 -21
- package/lib/dependencies/LoaderDependency.js +13 -0
- package/lib/dependencies/LoaderImportDependency.js +13 -0
- package/lib/dependencies/ModuleDependency.js +11 -1
- package/lib/dependencies/ProvidedDependency.js +31 -8
- package/lib/dependencies/RequireResolveContextDependency.js +2 -2
- package/lib/dependencies/RequireResolveDependency.js +2 -1
- package/lib/dependencies/URLPlugin.js +21 -0
- package/lib/index.js +4 -0
- package/lib/javascript/JavascriptParser.js +47 -21
- package/lib/json/JsonData.js +8 -0
- package/lib/json/JsonParser.js +4 -6
- package/lib/optimize/ConcatenatedModule.js +40 -17
- package/lib/optimize/ModuleConcatenationPlugin.js +1 -1
- package/lib/runtime/AsyncModuleRuntimeModule.js +32 -58
- package/lib/runtime/LoadScriptRuntimeModule.js +9 -7
- package/lib/runtime/NonceRuntimeModule.js +24 -0
- package/lib/sharing/ProvideSharedPlugin.js +1 -2
- package/lib/web/JsonpChunkLoadingRuntimeModule.js +11 -9
- package/package.json +6 -5
- package/schemas/WebpackOptions.check.js +1 -1
- package/schemas/WebpackOptions.json +60 -0
- package/types.d.ts +94 -4
@@ -49,20 +49,6 @@ class ContextElementDependency extends ModuleDependency {
|
|
49
49
|
return "context element";
|
50
50
|
}
|
51
51
|
|
52
|
-
/**
|
53
|
-
* @returns {string | undefined} a request context
|
54
|
-
*/
|
55
|
-
getContext() {
|
56
|
-
return this._context;
|
57
|
-
}
|
58
|
-
|
59
|
-
/**
|
60
|
-
* @returns {string | null} an identifier to merge equal requests
|
61
|
-
*/
|
62
|
-
getResourceIdentifier() {
|
63
|
-
return `context${this._context || ""}|${super.getResourceIdentifier()}`;
|
64
|
-
}
|
65
|
-
|
66
52
|
get category() {
|
67
53
|
return this._category;
|
68
54
|
}
|
@@ -86,7 +72,6 @@ class ContextElementDependency extends ModuleDependency {
|
|
86
72
|
const { write } = context;
|
87
73
|
write(this._typePrefix);
|
88
74
|
write(this._category);
|
89
|
-
write(this._context);
|
90
75
|
write(this.referencedExports);
|
91
76
|
super.serialize(context);
|
92
77
|
}
|
@@ -95,7 +80,6 @@ class ContextElementDependency extends ModuleDependency {
|
|
95
80
|
const { read } = context;
|
96
81
|
this._typePrefix = read();
|
97
82
|
this._category = read();
|
98
|
-
this._context = read();
|
99
83
|
this.referencedExports = read();
|
100
84
|
super.deserialize(context);
|
101
85
|
}
|
@@ -61,17 +61,49 @@ HarmonyEvaluatedImportSpecifierDependency.Template = class HarmonyEvaluatedImpor
|
|
61
61
|
const dep = /** @type {HarmonyEvaluatedImportSpecifierDependency} */ (
|
62
62
|
dependency
|
63
63
|
);
|
64
|
-
const { moduleGraph, runtime } = templateContext;
|
64
|
+
const { module, moduleGraph, runtime } = templateContext;
|
65
65
|
const connection = moduleGraph.getConnection(dep);
|
66
66
|
// Skip rendering depending when dependency is conditional
|
67
67
|
if (connection && !connection.isTargetActive(runtime)) return;
|
68
68
|
|
69
69
|
const exportsInfo = moduleGraph.getExportsInfo(connection.module);
|
70
70
|
const ids = dep.getIds(moduleGraph);
|
71
|
-
|
71
|
+
|
72
|
+
let value;
|
73
|
+
|
74
|
+
const exportsType = connection.module.getExportsType(
|
75
|
+
moduleGraph,
|
76
|
+
module.buildMeta.strictHarmonyModule
|
77
|
+
);
|
78
|
+
switch (exportsType) {
|
79
|
+
case "default-with-named": {
|
80
|
+
if (ids[0] === "default") {
|
81
|
+
value =
|
82
|
+
ids.length === 1 || exportsInfo.isExportProvided(ids.slice(1));
|
83
|
+
} else {
|
84
|
+
value = exportsInfo.isExportProvided(ids);
|
85
|
+
}
|
86
|
+
break;
|
87
|
+
}
|
88
|
+
case "namespace": {
|
89
|
+
if (ids[0] === "__esModule") {
|
90
|
+
value = ids.length === 1 || undefined;
|
91
|
+
} else {
|
92
|
+
value = exportsInfo.isExportProvided(ids);
|
93
|
+
}
|
94
|
+
break;
|
95
|
+
}
|
96
|
+
case "dynamic": {
|
97
|
+
if (ids[0] !== "default") {
|
98
|
+
value = exportsInfo.isExportProvided(ids);
|
99
|
+
}
|
100
|
+
break;
|
101
|
+
}
|
102
|
+
// default-only could lead to runtime error, when default value is primitive
|
103
|
+
}
|
72
104
|
|
73
105
|
if (typeof value === "boolean") {
|
74
|
-
source.replace(dep.range[0], dep.range[1] - 1,
|
106
|
+
source.replace(dep.range[0], dep.range[1] - 1, ` ${value}`);
|
75
107
|
} else {
|
76
108
|
const usedName = exportsInfo.getUsedName(ids, runtime);
|
77
109
|
|
@@ -14,10 +14,14 @@ const ImportDependency = require("./ImportDependency");
|
|
14
14
|
const ImportEagerDependency = require("./ImportEagerDependency");
|
15
15
|
const ImportWeakDependency = require("./ImportWeakDependency");
|
16
16
|
|
17
|
+
/** @typedef {import("../../declarations/WebpackOptions").JavascriptParserOptions} JavascriptParserOptions */
|
17
18
|
/** @typedef {import("../ChunkGroup").RawChunkGroupOptions} RawChunkGroupOptions */
|
18
19
|
/** @typedef {import("../ContextModule").ContextMode} ContextMode */
|
19
20
|
|
20
21
|
class ImportParserPlugin {
|
22
|
+
/**
|
23
|
+
* @param {JavascriptParserOptions} options options
|
24
|
+
*/
|
21
25
|
constructor(options) {
|
22
26
|
this.options = options;
|
23
27
|
}
|
@@ -28,7 +32,7 @@ class ImportParserPlugin {
|
|
28
32
|
|
29
33
|
let chunkName = null;
|
30
34
|
/** @type {ContextMode} */
|
31
|
-
let mode =
|
35
|
+
let mode = this.options.dynamicImportMode;
|
32
36
|
let include = null;
|
33
37
|
let exclude = null;
|
34
38
|
/** @type {string[][] | null} */
|
@@ -36,6 +40,17 @@ class ImportParserPlugin {
|
|
36
40
|
/** @type {RawChunkGroupOptions} */
|
37
41
|
const groupOptions = {};
|
38
42
|
|
43
|
+
const { dynamicImportPreload, dynamicImportPrefetch } = this.options;
|
44
|
+
if (dynamicImportPreload !== undefined && dynamicImportPreload !== false)
|
45
|
+
groupOptions.preloadOrder =
|
46
|
+
dynamicImportPreload === true ? 0 : dynamicImportPreload;
|
47
|
+
if (
|
48
|
+
dynamicImportPrefetch !== undefined &&
|
49
|
+
dynamicImportPrefetch !== false
|
50
|
+
)
|
51
|
+
groupOptions.prefetchOrder =
|
52
|
+
dynamicImportPrefetch === true ? 0 : dynamicImportPrefetch;
|
53
|
+
|
39
54
|
const { options: importOptions, errors: commentErrors } =
|
40
55
|
parser.parseCommentOptions(expr.range);
|
41
56
|
|
@@ -175,16 +190,22 @@ class ImportParserPlugin {
|
|
175
190
|
}
|
176
191
|
}
|
177
192
|
|
178
|
-
if (
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
193
|
+
if (
|
194
|
+
mode !== "lazy" &&
|
195
|
+
mode !== "lazy-once" &&
|
196
|
+
mode !== "eager" &&
|
197
|
+
mode !== "weak"
|
198
|
+
) {
|
199
|
+
parser.state.module.addWarning(
|
200
|
+
new UnsupportedFeatureWarning(
|
201
|
+
`\`webpackMode\` expected 'lazy', 'lazy-once', 'eager' or 'weak', but received: ${mode}.`,
|
202
|
+
expr.loc
|
203
|
+
)
|
204
|
+
);
|
205
|
+
mode = "lazy";
|
206
|
+
}
|
187
207
|
|
208
|
+
if (param.isString()) {
|
188
209
|
if (mode === "eager") {
|
189
210
|
const dep = new ImportEagerDependency(
|
190
211
|
param.string,
|
@@ -215,21 +236,6 @@ class ImportParserPlugin {
|
|
215
236
|
}
|
216
237
|
return true;
|
217
238
|
} else {
|
218
|
-
if (
|
219
|
-
mode !== "lazy" &&
|
220
|
-
mode !== "lazy-once" &&
|
221
|
-
mode !== "eager" &&
|
222
|
-
mode !== "weak"
|
223
|
-
) {
|
224
|
-
parser.state.module.addWarning(
|
225
|
-
new UnsupportedFeatureWarning(
|
226
|
-
`\`webpackMode\` expected 'lazy', 'lazy-once', 'eager' or 'weak', but received: ${mode}.`,
|
227
|
-
expr.loc
|
228
|
-
)
|
229
|
-
);
|
230
|
-
mode = "lazy";
|
231
|
-
}
|
232
|
-
|
233
239
|
if (mode === "weak") {
|
234
240
|
mode = "async-weak";
|
235
241
|
}
|
@@ -13,18 +13,21 @@ const NullDependency = require("./NullDependency");
|
|
13
13
|
/** @typedef {import("../Dependency").ExportsSpec} ExportsSpec */
|
14
14
|
/** @typedef {import("../Dependency").UpdateHashContext} UpdateHashContext */
|
15
15
|
/** @typedef {import("../ModuleGraph")} ModuleGraph */
|
16
|
+
/** @typedef {import("../json/JsonData")} JsonData */
|
16
17
|
/** @typedef {import("../util/Hash")} Hash */
|
17
18
|
|
18
19
|
const getExportsFromData = data => {
|
19
20
|
if (data && typeof data === "object") {
|
20
21
|
if (Array.isArray(data)) {
|
21
|
-
return data.
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
22
|
+
return data.length < 100
|
23
|
+
? data.map((item, idx) => {
|
24
|
+
return {
|
25
|
+
name: `${idx}`,
|
26
|
+
canMangle: true,
|
27
|
+
exports: getExportsFromData(item)
|
28
|
+
};
|
29
|
+
})
|
30
|
+
: undefined;
|
28
31
|
} else {
|
29
32
|
const exports = [];
|
30
33
|
for (const key of Object.keys(data)) {
|
@@ -42,12 +45,11 @@ const getExportsFromData = data => {
|
|
42
45
|
|
43
46
|
class JsonExportsDependency extends NullDependency {
|
44
47
|
/**
|
45
|
-
* @param {
|
48
|
+
* @param {JsonData=} data json data
|
46
49
|
*/
|
47
|
-
constructor(
|
50
|
+
constructor(data) {
|
48
51
|
super();
|
49
|
-
this.
|
50
|
-
this._hashUpdate = undefined;
|
52
|
+
this.data = data;
|
51
53
|
}
|
52
54
|
|
53
55
|
get type() {
|
@@ -61,7 +63,7 @@ class JsonExportsDependency extends NullDependency {
|
|
61
63
|
*/
|
62
64
|
getExports(moduleGraph) {
|
63
65
|
return {
|
64
|
-
exports: this.
|
66
|
+
exports: getExportsFromData(this.data && this.data.get()),
|
65
67
|
dependencies: undefined
|
66
68
|
};
|
67
69
|
}
|
@@ -73,23 +75,18 @@ class JsonExportsDependency extends NullDependency {
|
|
73
75
|
* @returns {void}
|
74
76
|
*/
|
75
77
|
updateHash(hash, context) {
|
76
|
-
|
77
|
-
this._hashUpdate = this.exports
|
78
|
-
? JSON.stringify(this.exports)
|
79
|
-
: "undefined";
|
80
|
-
}
|
81
|
-
hash.update(this._hashUpdate);
|
78
|
+
this.data.updateHash(hash);
|
82
79
|
}
|
83
80
|
|
84
81
|
serialize(context) {
|
85
82
|
const { write } = context;
|
86
|
-
write(this.
|
83
|
+
write(this.data);
|
87
84
|
super.serialize(context);
|
88
85
|
}
|
89
86
|
|
90
87
|
deserialize(context) {
|
91
88
|
const { read } = context;
|
92
|
-
this.
|
89
|
+
this.data = read();
|
93
90
|
super.deserialize(context);
|
94
91
|
}
|
95
92
|
}
|
@@ -100,4 +97,3 @@ makeSerializable(
|
|
100
97
|
);
|
101
98
|
|
102
99
|
module.exports = JsonExportsDependency;
|
103
|
-
module.exports.getExportsFromData = getExportsFromData;
|
@@ -7,6 +7,11 @@
|
|
7
7
|
|
8
8
|
const ModuleDependency = require("./ModuleDependency");
|
9
9
|
|
10
|
+
/** @typedef {import("../ModuleGraph")} ModuleGraph */
|
11
|
+
/** @typedef {import("../ModuleGraphConnection")} ModuleGraphConnection */
|
12
|
+
/** @typedef {import("../ModuleGraphConnection").ConnectionState} ConnectionState */
|
13
|
+
/** @typedef {import("../util/runtime").RuntimeSpec} RuntimeSpec */
|
14
|
+
|
10
15
|
class LoaderDependency extends ModuleDependency {
|
11
16
|
/**
|
12
17
|
* @param {string} request request string
|
@@ -22,6 +27,14 @@ class LoaderDependency extends ModuleDependency {
|
|
22
27
|
get category() {
|
23
28
|
return "loader";
|
24
29
|
}
|
30
|
+
|
31
|
+
/**
|
32
|
+
* @param {ModuleGraph} moduleGraph module graph
|
33
|
+
* @returns {null | false | function(ModuleGraphConnection, RuntimeSpec): ConnectionState} function to determine if the connection is active
|
34
|
+
*/
|
35
|
+
getCondition(moduleGraph) {
|
36
|
+
return false;
|
37
|
+
}
|
25
38
|
}
|
26
39
|
|
27
40
|
module.exports = LoaderDependency;
|
@@ -7,6 +7,11 @@
|
|
7
7
|
|
8
8
|
const ModuleDependency = require("./ModuleDependency");
|
9
9
|
|
10
|
+
/** @typedef {import("../ModuleGraph")} ModuleGraph */
|
11
|
+
/** @typedef {import("../ModuleGraphConnection")} ModuleGraphConnection */
|
12
|
+
/** @typedef {import("../ModuleGraphConnection").ConnectionState} ConnectionState */
|
13
|
+
/** @typedef {import("../util/runtime").RuntimeSpec} RuntimeSpec */
|
14
|
+
|
10
15
|
class LoaderImportDependency extends ModuleDependency {
|
11
16
|
/**
|
12
17
|
* @param {string} request request string
|
@@ -23,6 +28,14 @@ class LoaderImportDependency extends ModuleDependency {
|
|
23
28
|
get category() {
|
24
29
|
return "loaderImport";
|
25
30
|
}
|
31
|
+
|
32
|
+
/**
|
33
|
+
* @param {ModuleGraph} moduleGraph module graph
|
34
|
+
* @returns {null | false | function(ModuleGraphConnection, RuntimeSpec): ConnectionState} function to determine if the connection is active
|
35
|
+
*/
|
36
|
+
getCondition(moduleGraph) {
|
37
|
+
return false;
|
38
|
+
}
|
26
39
|
}
|
27
40
|
|
28
41
|
module.exports = LoaderImportDependency;
|
@@ -26,13 +26,21 @@ class ModuleDependency extends Dependency {
|
|
26
26
|
// assertions must be serialized by subclasses that use it
|
27
27
|
/** @type {Record<string, any> | undefined} */
|
28
28
|
this.assertions = undefined;
|
29
|
+
this._context = undefined;
|
30
|
+
}
|
31
|
+
|
32
|
+
/**
|
33
|
+
* @returns {string | undefined} a request context
|
34
|
+
*/
|
35
|
+
getContext() {
|
36
|
+
return this._context;
|
29
37
|
}
|
30
38
|
|
31
39
|
/**
|
32
40
|
* @returns {string | null} an identifier to merge equal requests
|
33
41
|
*/
|
34
42
|
getResourceIdentifier() {
|
35
|
-
let str = `module${this.request}`;
|
43
|
+
let str = `context${this._context || ""}|module${this.request}`;
|
36
44
|
if (this.assertions !== undefined) {
|
37
45
|
str += JSON.stringify(this.assertions);
|
38
46
|
}
|
@@ -63,6 +71,7 @@ class ModuleDependency extends Dependency {
|
|
63
71
|
const { write } = context;
|
64
72
|
write(this.request);
|
65
73
|
write(this.userRequest);
|
74
|
+
write(this._context);
|
66
75
|
write(this.range);
|
67
76
|
super.serialize(context);
|
68
77
|
}
|
@@ -71,6 +80,7 @@ class ModuleDependency extends Dependency {
|
|
71
80
|
const { read } = context;
|
72
81
|
this.request = read();
|
73
82
|
this.userRequest = read();
|
83
|
+
this._context = read();
|
74
84
|
this.range = read();
|
75
85
|
super.deserialize(context);
|
76
86
|
}
|
@@ -5,19 +5,21 @@
|
|
5
5
|
|
6
6
|
"use strict";
|
7
7
|
|
8
|
+
const Dependency = require("../Dependency");
|
8
9
|
const InitFragment = require("../InitFragment");
|
9
10
|
const makeSerializable = require("../util/makeSerializable");
|
10
11
|
const ModuleDependency = require("./ModuleDependency");
|
11
12
|
|
12
13
|
/** @typedef {import("webpack-sources").ReplaceSource} ReplaceSource */
|
13
14
|
/** @typedef {import("../ChunkGraph")} ChunkGraph */
|
14
|
-
/** @typedef {import("../Dependency")}
|
15
|
+
/** @typedef {import("../Dependency").ReferencedExport} ReferencedExport */
|
15
16
|
/** @typedef {import("../Dependency").UpdateHashContext} UpdateHashContext */
|
16
17
|
/** @typedef {import("../DependencyTemplate").DependencyTemplateContext} DependencyTemplateContext */
|
17
18
|
/** @typedef {import("../DependencyTemplates")} DependencyTemplates */
|
18
19
|
/** @typedef {import("../ModuleGraph")} ModuleGraph */
|
19
20
|
/** @typedef {import("../RuntimeTemplate")} RuntimeTemplate */
|
20
21
|
/** @typedef {import("../util/Hash")} Hash */
|
22
|
+
/** @typedef {import("../util/runtime").RuntimeSpec} RuntimeSpec */
|
21
23
|
|
22
24
|
/**
|
23
25
|
* @param {string[]|null} path the property path array
|
@@ -29,10 +31,16 @@ const pathToString = path =>
|
|
29
31
|
: "";
|
30
32
|
|
31
33
|
class ProvidedDependency extends ModuleDependency {
|
32
|
-
|
34
|
+
/**
|
35
|
+
* @param {string} request request
|
36
|
+
* @param {string} identifier identifier
|
37
|
+
* @param {string[]} ids ids
|
38
|
+
* @param {[number, number]} range range
|
39
|
+
*/
|
40
|
+
constructor(request, identifier, ids, range) {
|
33
41
|
super(request);
|
34
42
|
this.identifier = identifier;
|
35
|
-
this.
|
43
|
+
this.ids = ids;
|
36
44
|
this.range = range;
|
37
45
|
this._hashUpdate = undefined;
|
38
46
|
}
|
@@ -45,6 +53,18 @@ class ProvidedDependency extends ModuleDependency {
|
|
45
53
|
return "esm";
|
46
54
|
}
|
47
55
|
|
56
|
+
/**
|
57
|
+
* Returns list of exports referenced by this dependency
|
58
|
+
* @param {ModuleGraph} moduleGraph module graph
|
59
|
+
* @param {RuntimeSpec} runtime the runtime for which the module is analysed
|
60
|
+
* @returns {(string[] | ReferencedExport)[]} referenced exports
|
61
|
+
*/
|
62
|
+
getReferencedExports(moduleGraph, runtime) {
|
63
|
+
let ids = this.ids;
|
64
|
+
if (ids.length === 0) return Dependency.EXPORTS_OBJECT_REFERENCED;
|
65
|
+
return [ids];
|
66
|
+
}
|
67
|
+
|
48
68
|
/**
|
49
69
|
* Update the hash
|
50
70
|
* @param {Hash} hash hash to be updated
|
@@ -53,8 +73,7 @@ class ProvidedDependency extends ModuleDependency {
|
|
53
73
|
*/
|
54
74
|
updateHash(hash, context) {
|
55
75
|
if (this._hashUpdate === undefined) {
|
56
|
-
this._hashUpdate =
|
57
|
-
this.identifier + (this.path ? this.path.join(",") : "null");
|
76
|
+
this._hashUpdate = this.identifier + (this.ids ? this.ids.join(",") : "");
|
58
77
|
}
|
59
78
|
hash.update(this._hashUpdate);
|
60
79
|
}
|
@@ -62,14 +81,14 @@ class ProvidedDependency extends ModuleDependency {
|
|
62
81
|
serialize(context) {
|
63
82
|
const { write } = context;
|
64
83
|
write(this.identifier);
|
65
|
-
write(this.
|
84
|
+
write(this.ids);
|
66
85
|
super.serialize(context);
|
67
86
|
}
|
68
87
|
|
69
88
|
deserialize(context) {
|
70
89
|
const { read } = context;
|
71
90
|
this.identifier = read();
|
72
|
-
this.
|
91
|
+
this.ids = read();
|
73
92
|
super.deserialize(context);
|
74
93
|
}
|
75
94
|
}
|
@@ -90,6 +109,7 @@ class ProvidedDependencyTemplate extends ModuleDependency.Template {
|
|
90
109
|
dependency,
|
91
110
|
source,
|
92
111
|
{
|
112
|
+
runtime,
|
93
113
|
runtimeTemplate,
|
94
114
|
moduleGraph,
|
95
115
|
chunkGraph,
|
@@ -98,6 +118,9 @@ class ProvidedDependencyTemplate extends ModuleDependency.Template {
|
|
98
118
|
}
|
99
119
|
) {
|
100
120
|
const dep = /** @type {ProvidedDependency} */ (dependency);
|
121
|
+
const connection = moduleGraph.getConnection(dep);
|
122
|
+
const exportsInfo = moduleGraph.getExportsInfo(connection.module);
|
123
|
+
const usedName = exportsInfo.getUsedName(dep.ids, runtime);
|
101
124
|
initFragments.push(
|
102
125
|
new InitFragment(
|
103
126
|
`/* provided dependency */ var ${
|
@@ -107,7 +130,7 @@ class ProvidedDependencyTemplate extends ModuleDependency.Template {
|
|
107
130
|
chunkGraph,
|
108
131
|
request: dep.request,
|
109
132
|
runtimeRequirements
|
110
|
-
})}${pathToString(
|
133
|
+
})}${pathToString(/** @type {string[]} */ (usedName))};\n`,
|
111
134
|
InitFragment.STAGE_PROVIDES,
|
112
135
|
1,
|
113
136
|
`provided ${dep.identifier}`
|
@@ -10,8 +10,8 @@ const ContextDependency = require("./ContextDependency");
|
|
10
10
|
const ContextDependencyTemplateAsId = require("./ContextDependencyTemplateAsId");
|
11
11
|
|
12
12
|
class RequireResolveContextDependency extends ContextDependency {
|
13
|
-
constructor(options, range, valueRange) {
|
14
|
-
super(options);
|
13
|
+
constructor(options, range, valueRange, context) {
|
14
|
+
super(options, context);
|
15
15
|
|
16
16
|
this.range = range;
|
17
17
|
this.valueRange = valueRange;
|
@@ -15,10 +15,11 @@ const ModuleDependencyAsId = require("./ModuleDependencyTemplateAsId");
|
|
15
15
|
/** @typedef {import("../util/runtime").RuntimeSpec} RuntimeSpec */
|
16
16
|
|
17
17
|
class RequireResolveDependency extends ModuleDependency {
|
18
|
-
constructor(request, range) {
|
18
|
+
constructor(request, range, context) {
|
19
19
|
super(request);
|
20
20
|
|
21
21
|
this.range = range;
|
22
|
+
this._context = context;
|
22
23
|
}
|
23
24
|
|
24
25
|
get type() {
|
@@ -5,12 +5,15 @@
|
|
5
5
|
|
6
6
|
"use strict";
|
7
7
|
|
8
|
+
const { pathToFileURL } = require("url");
|
9
|
+
const BasicEvaluatedExpression = require("../javascript/BasicEvaluatedExpression");
|
8
10
|
const { approve } = require("../javascript/JavascriptParserHelpers");
|
9
11
|
const InnerGraph = require("../optimize/InnerGraph");
|
10
12
|
const URLDependency = require("./URLDependency");
|
11
13
|
|
12
14
|
/** @typedef {import("estree").NewExpression} NewExpressionNode */
|
13
15
|
/** @typedef {import("../Compiler")} Compiler */
|
16
|
+
/** @typedef {import("../NormalModule")} NormalModule */
|
14
17
|
/** @typedef {import("../javascript/JavascriptParser")} JavascriptParser */
|
15
18
|
|
16
19
|
class URLPlugin {
|
@@ -27,6 +30,13 @@ class URLPlugin {
|
|
27
30
|
new URLDependency.Template()
|
28
31
|
);
|
29
32
|
|
33
|
+
/**
|
34
|
+
* @param {NormalModule} module module
|
35
|
+
* @returns {URL} file url
|
36
|
+
*/
|
37
|
+
const getUrl = module => {
|
38
|
+
return pathToFileURL(module.resource);
|
39
|
+
};
|
30
40
|
/**
|
31
41
|
* @param {JavascriptParser} parser parser
|
32
42
|
* @param {object} parserOptions options
|
@@ -67,6 +77,17 @@ class URLPlugin {
|
|
67
77
|
};
|
68
78
|
|
69
79
|
parser.hooks.canRename.for("URL").tap("URLPlugin", approve);
|
80
|
+
parser.hooks.evaluateNewExpression
|
81
|
+
.for("URL")
|
82
|
+
.tap("URLPlugin", expr => {
|
83
|
+
const request = getUrlRequest(expr);
|
84
|
+
if (!request) return;
|
85
|
+
const url = new URL(request, getUrl(parser.state.module));
|
86
|
+
|
87
|
+
return new BasicEvaluatedExpression()
|
88
|
+
.setString(url.toString())
|
89
|
+
.setRange(expr.range);
|
90
|
+
});
|
70
91
|
parser.hooks.new.for("URL").tap("URLPlugin", _expr => {
|
71
92
|
const expr = /** @type {NewExpressionNode} */ (_expr);
|
72
93
|
|
package/lib/index.js
CHANGED
@@ -28,6 +28,7 @@ const memoize = require("./util/memoize");
|
|
28
28
|
/** @typedef {import("./Compilation").Asset} Asset */
|
29
29
|
/** @typedef {import("./Compilation").AssetInfo} AssetInfo */
|
30
30
|
/** @typedef {import("./Compilation").EntryOptions} EntryOptions */
|
31
|
+
/** @typedef {import("./Compilation").PathData} PathData */
|
31
32
|
/** @typedef {import("./Compiler").AssetEmittedInfo} AssetEmittedInfo */
|
32
33
|
/** @typedef {import("./MultiStats")} MultiStats */
|
33
34
|
/** @typedef {import("./Parser").ParserState} ParserState */
|
@@ -341,6 +342,9 @@ module.exports = mergeExports(fn, {
|
|
341
342
|
get ModuleDependency() {
|
342
343
|
return require("./dependencies/ModuleDependency");
|
343
344
|
},
|
345
|
+
get HarmonyImportDependency() {
|
346
|
+
return require("./dependencies/HarmonyImportDependency");
|
347
|
+
},
|
344
348
|
get ConstDependency() {
|
345
349
|
return require("./dependencies/ConstDependency");
|
346
350
|
},
|