webpack 5.67.0 → 5.68.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/lib/APIPlugin.js +33 -0
- package/lib/Module.js +0 -2
- package/lib/async-modules/AwaitDependenciesInitFragment.js +4 -4
- package/lib/config/defaults.js +1 -0
- package/lib/dependencies/HarmonyCompatibilityDependency.js +5 -5
- package/lib/dependencies/ImportMetaPlugin.js +22 -3
- package/lib/runtime/AsyncModuleRuntimeModule.js +25 -15
- package/lib/util/ArrayHelpers.js +18 -4
- package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +9 -3
- package/package.json +1 -1
- package/schemas/WebpackOptions.check.js +1 -1
- package/schemas/WebpackOptions.json +4 -0
- package/types.d.ts +5 -0
package/lib/APIPlugin.js
CHANGED
@@ -201,6 +201,39 @@ class APIPlugin {
|
|
201
201
|
)
|
202
202
|
.setRange(expr.range)
|
203
203
|
);
|
204
|
+
|
205
|
+
parser.hooks.expression
|
206
|
+
.for("__webpack_module__.id")
|
207
|
+
.tap("APIPlugin", expr => {
|
208
|
+
parser.state.module.buildInfo.moduleConcatenationBailout =
|
209
|
+
"__webpack_module__.id";
|
210
|
+
const dep = new ConstDependency(
|
211
|
+
parser.state.module.moduleArgument + ".id",
|
212
|
+
expr.range,
|
213
|
+
[RuntimeGlobals.moduleId]
|
214
|
+
);
|
215
|
+
dep.loc = expr.loc;
|
216
|
+
parser.state.module.addPresentationalDependency(dep);
|
217
|
+
return true;
|
218
|
+
});
|
219
|
+
|
220
|
+
parser.hooks.expression
|
221
|
+
.for("__webpack_module__")
|
222
|
+
.tap("APIPlugin", expr => {
|
223
|
+
parser.state.module.buildInfo.moduleConcatenationBailout =
|
224
|
+
"__webpack_module__";
|
225
|
+
const dep = new ConstDependency(
|
226
|
+
parser.state.module.moduleArgument,
|
227
|
+
expr.range,
|
228
|
+
[RuntimeGlobals.module]
|
229
|
+
);
|
230
|
+
dep.loc = expr.loc;
|
231
|
+
parser.state.module.addPresentationalDependency(dep);
|
232
|
+
return true;
|
233
|
+
});
|
234
|
+
parser.hooks.evaluateTypeof
|
235
|
+
.for("__webpack_module__")
|
236
|
+
.tap("APIPlugin", evaluateToString("object"));
|
204
237
|
};
|
205
238
|
|
206
239
|
normalModuleFactory.hooks.parser
|
package/lib/Module.js
CHANGED
@@ -400,7 +400,6 @@ class Module extends DependenciesBlock {
|
|
400
400
|
// BACKWARD-COMPAT END
|
401
401
|
|
402
402
|
/**
|
403
|
-
* @deprecated moved to .buildInfo.exportsArgument
|
404
403
|
* @returns {string} name of the exports argument
|
405
404
|
*/
|
406
405
|
get exportsArgument() {
|
@@ -408,7 +407,6 @@ class Module extends DependenciesBlock {
|
|
408
407
|
}
|
409
408
|
|
410
409
|
/**
|
411
|
-
* @deprecated moved to .buildInfo.moduleArgument
|
412
410
|
* @returns {string} name of the module argument
|
413
411
|
*/
|
414
412
|
get moduleArgument() {
|
@@ -30,8 +30,8 @@ class AwaitDependenciesInitFragment extends InitFragment {
|
|
30
30
|
}
|
31
31
|
|
32
32
|
merge(other) {
|
33
|
-
const promises = new Set(
|
34
|
-
for (const p of
|
33
|
+
const promises = new Set(other.promises);
|
34
|
+
for (const p of this.promises) {
|
35
35
|
promises.add(p);
|
36
36
|
}
|
37
37
|
return new AwaitDependenciesInitFragment(promises);
|
@@ -51,7 +51,7 @@ class AwaitDependenciesInitFragment extends InitFragment {
|
|
51
51
|
for (const p of promises) {
|
52
52
|
return Template.asString([
|
53
53
|
`var __webpack_async_dependencies__ = __webpack_handle_async_dependencies__([${p}]);`,
|
54
|
-
`${p} = (__webpack_async_dependencies__.then ? await __webpack_async_dependencies__ : __webpack_async_dependencies__)[0];`,
|
54
|
+
`${p} = (__webpack_async_dependencies__.then ? (await __webpack_async_dependencies__)() : __webpack_async_dependencies__)[0];`,
|
55
55
|
""
|
56
56
|
]);
|
57
57
|
}
|
@@ -60,7 +60,7 @@ class AwaitDependenciesInitFragment extends InitFragment {
|
|
60
60
|
// TODO check if destructuring is supported
|
61
61
|
return Template.asString([
|
62
62
|
`var __webpack_async_dependencies__ = __webpack_handle_async_dependencies__([${sepPromises}]);`,
|
63
|
-
`([${sepPromises}] = __webpack_async_dependencies__.then ? await __webpack_async_dependencies__ : __webpack_async_dependencies__);`,
|
63
|
+
`([${sepPromises}] = __webpack_async_dependencies__.then ? (await __webpack_async_dependencies__)() : __webpack_async_dependencies__);`,
|
64
64
|
""
|
65
65
|
]);
|
66
66
|
}
|
package/lib/config/defaults.js
CHANGED
@@ -469,6 +469,7 @@ const applyJavascriptParserOptionsDefaults = (
|
|
469
469
|
D(parserOptions, "wrappedContextRecursive", true);
|
470
470
|
D(parserOptions, "wrappedContextCritical", false);
|
471
471
|
D(parserOptions, "strictThisContextOnImports", false);
|
472
|
+
D(parserOptions, "importMeta", true);
|
472
473
|
if (futureDefaults) D(parserOptions, "exportsPresence", "error");
|
473
474
|
};
|
474
475
|
|
@@ -74,14 +74,14 @@ HarmonyCompatibilityDependency.Template = class HarmonyExportDependencyTemplate
|
|
74
74
|
initFragments.push(
|
75
75
|
new InitFragment(
|
76
76
|
runtimeTemplate.supportsArrowFunction()
|
77
|
-
? `${RuntimeGlobals.asyncModule}(${module.moduleArgument}, async (__webpack_handle_async_dependencies__) => {\n`
|
78
|
-
: `${RuntimeGlobals.asyncModule}(${module.moduleArgument}, async function (__webpack_handle_async_dependencies__) {\n`,
|
77
|
+
? `${RuntimeGlobals.asyncModule}(${module.moduleArgument}, async (__webpack_handle_async_dependencies__, __webpack_async_result__) => { try {\n`
|
78
|
+
: `${RuntimeGlobals.asyncModule}(${module.moduleArgument}, async function (__webpack_handle_async_dependencies__, __webpack_async_result__) { try {\n`,
|
79
79
|
InitFragment.STAGE_ASYNC_BOUNDARY,
|
80
80
|
0,
|
81
81
|
undefined,
|
82
|
-
|
83
|
-
?
|
84
|
-
|
82
|
+
`\n__webpack_async_result__();\n} catch(e) { __webpack_async_result__(e); } }${
|
83
|
+
module.buildMeta.async ? ", 1" : ""
|
84
|
+
});`
|
85
85
|
)
|
86
86
|
);
|
87
87
|
}
|
@@ -20,6 +20,7 @@ const propertyAccess = require("../util/propertyAccess");
|
|
20
20
|
const ConstDependency = require("./ConstDependency");
|
21
21
|
|
22
22
|
/** @typedef {import("estree").MemberExpression} MemberExpression */
|
23
|
+
/** @typedef {import("../../declarations/WebpackOptions").JavascriptParserOptions} JavascriptParserOptions */
|
23
24
|
/** @typedef {import("../Compiler")} Compiler */
|
24
25
|
/** @typedef {import("../NormalModule")} NormalModule */
|
25
26
|
/** @typedef {import("../javascript/JavascriptParser")} Parser */
|
@@ -44,11 +45,29 @@ class ImportMetaPlugin {
|
|
44
45
|
return pathToFileURL(module.resource).toString();
|
45
46
|
};
|
46
47
|
/**
|
47
|
-
* @param {Parser} parser parser
|
48
|
-
* @param {
|
48
|
+
* @param {Parser} parser parser parser
|
49
|
+
* @param {JavascriptParserOptions} parserOptions parserOptions
|
49
50
|
* @returns {void}
|
50
51
|
*/
|
51
|
-
const parserHandler = (parser,
|
52
|
+
const parserHandler = (parser, { importMeta }) => {
|
53
|
+
if (importMeta === false) {
|
54
|
+
const { importMetaName } = compilation.outputOptions;
|
55
|
+
if (importMetaName === "import.meta") return;
|
56
|
+
|
57
|
+
parser.hooks.expression
|
58
|
+
.for("import.meta")
|
59
|
+
.tap("ImportMetaPlugin", metaProperty => {
|
60
|
+
const dep = new ConstDependency(
|
61
|
+
importMetaName,
|
62
|
+
metaProperty.range
|
63
|
+
);
|
64
|
+
dep.loc = metaProperty.loc;
|
65
|
+
parser.state.module.addPresentationalDependency(dep);
|
66
|
+
return true;
|
67
|
+
});
|
68
|
+
return;
|
69
|
+
}
|
70
|
+
|
52
71
|
/// import.meta direct ///
|
53
72
|
parser.hooks.typeof
|
54
73
|
.for("import.meta")
|
@@ -22,6 +22,7 @@ class AsyncModuleRuntimeModule extends HelperRuntimeModule {
|
|
22
22
|
return Template.asString([
|
23
23
|
'var webpackThen = typeof Symbol === "function" ? Symbol("webpack then") : "__webpack_then__";',
|
24
24
|
'var webpackExports = typeof Symbol === "function" ? Symbol("webpack exports") : "__webpack_exports__";',
|
25
|
+
'var webpackError = typeof Symbol === "function" ? Symbol("webpack error") : "__webpack_error__";',
|
25
26
|
`var completeQueue = ${runtimeTemplate.basicFunction("queue", [
|
26
27
|
"if(queue) {",
|
27
28
|
Template.indent([
|
@@ -56,9 +57,13 @@ class AsyncModuleRuntimeModule extends HelperRuntimeModule {
|
|
56
57
|
"obj[webpackExports] = r;",
|
57
58
|
"completeQueue(queue);",
|
58
59
|
"queue = 0;"
|
60
|
+
])}, ${runtimeTemplate.basicFunction("e", [
|
61
|
+
"obj[webpackError] = e;",
|
62
|
+
"completeQueue(queue);",
|
63
|
+
"queue = 0;"
|
59
64
|
])});`,
|
60
|
-
|
61
|
-
obj[webpackThen] = ${runtimeTemplate.expressionFunction(
|
65
|
+
"var obj = {};",
|
66
|
+
`obj[webpackThen] = ${runtimeTemplate.expressionFunction(
|
62
67
|
"queueFunction(queue, fn), dep['catch'](reject)",
|
63
68
|
"fn, reject"
|
64
69
|
)};`,
|
@@ -67,13 +72,13 @@ class AsyncModuleRuntimeModule extends HelperRuntimeModule {
|
|
67
72
|
"}"
|
68
73
|
]),
|
69
74
|
"}",
|
70
|
-
|
71
|
-
ret[webpackThen] = ${runtimeTemplate.expressionFunction(
|
75
|
+
"var ret = {};",
|
76
|
+
`ret[webpackThen] = ${runtimeTemplate.expressionFunction(
|
72
77
|
"completeFunction(fn)",
|
73
78
|
"fn"
|
74
|
-
)}
|
75
|
-
ret[webpackExports] = dep;
|
76
|
-
return ret
|
79
|
+
)};`,
|
80
|
+
"ret[webpackExports] = dep;",
|
81
|
+
"return ret;"
|
77
82
|
])})`,
|
78
83
|
"deps"
|
79
84
|
)};`,
|
@@ -119,24 +124,29 @@ class AsyncModuleRuntimeModule extends HelperRuntimeModule {
|
|
119
124
|
)};`,
|
120
125
|
"module.exports = promise;",
|
121
126
|
`body(${runtimeTemplate.basicFunction("deps", [
|
122
|
-
"if(!deps) return outerResolve();",
|
123
127
|
"currentDeps = wrapDeps(deps);",
|
124
|
-
"var fn
|
128
|
+
"var fn;",
|
129
|
+
`var getResult = ${runtimeTemplate.returningFunction(
|
130
|
+
`currentDeps.map(${runtimeTemplate.basicFunction("d", [
|
131
|
+
"if(d[webpackError]) throw d[webpackError];",
|
132
|
+
"return d[webpackExports];"
|
133
|
+
])})`
|
134
|
+
)}`,
|
125
135
|
`var promise = new Promise(${runtimeTemplate.basicFunction(
|
126
136
|
"resolve, reject",
|
127
137
|
[
|
128
138
|
`fn = ${runtimeTemplate.expressionFunction(
|
129
|
-
|
130
|
-
"d[webpackExports]",
|
131
|
-
"d"
|
132
|
-
)}))`
|
139
|
+
"resolve(getResult)"
|
133
140
|
)};`,
|
134
141
|
"fn.r = 0;",
|
135
142
|
"whenAll(currentDeps, fn, reject);"
|
136
143
|
]
|
137
144
|
)});`,
|
138
|
-
"return fn.r ? promise :
|
139
|
-
])}
|
145
|
+
"return fn.r ? promise : getResult();"
|
146
|
+
])}, ${runtimeTemplate.expressionFunction(
|
147
|
+
"err && reject(promise[webpackError] = err), outerResolve()",
|
148
|
+
"err"
|
149
|
+
)});`,
|
140
150
|
"isEvaluating = false;"
|
141
151
|
])};`
|
142
152
|
]);
|
package/lib/util/ArrayHelpers.js
CHANGED
@@ -5,6 +5,14 @@
|
|
5
5
|
|
6
6
|
"use strict";
|
7
7
|
|
8
|
+
/**
|
9
|
+
* Compare two arrays or strings by performing strict equality check for each value.
|
10
|
+
* @template T [T=any]
|
11
|
+
* @param {ArrayLike<T>} a Array of values to be compared
|
12
|
+
* @param {ArrayLike<T>} b Array of values to be compared
|
13
|
+
* @returns {boolean} returns true if all the elements of passed arrays are strictly equal.
|
14
|
+
*/
|
15
|
+
|
8
16
|
exports.equals = (a, b) => {
|
9
17
|
if (a.length !== b.length) return false;
|
10
18
|
for (let i = 0; i < a.length; i++) {
|
@@ -14,13 +22,19 @@ exports.equals = (a, b) => {
|
|
14
22
|
};
|
15
23
|
|
16
24
|
/**
|
17
|
-
*
|
18
|
-
* @
|
19
|
-
* @param {
|
20
|
-
* @
|
25
|
+
* Partition an array by calling a predicate function on each value.
|
26
|
+
* @template T [T=any]
|
27
|
+
* @param {Array<T>} arr Array of values to be partitioned
|
28
|
+
* @param {(value: T) => boolean} fn Partition function which partitions based on truthiness of result.
|
29
|
+
* @returns {[Array<T>, Array<T>]} returns the values of `arr` partitioned into two new arrays based on fn predicate.
|
21
30
|
*/
|
22
31
|
exports.groupBy = (arr = [], fn) => {
|
23
32
|
return arr.reduce(
|
33
|
+
/**
|
34
|
+
* @param {[Array<T>, Array<T>]} groups An accumulator storing already partitioned values returned from previous call.
|
35
|
+
* @param {T} value The value of the current element
|
36
|
+
* @returns {[Array<T>, Array<T>]} returns an array of partitioned groups accumulator resulting from calling a predicate on the current value.
|
37
|
+
*/
|
24
38
|
(groups, value) => {
|
25
39
|
groups[fn(value) ? 0 : 1].push(value);
|
26
40
|
return groups;
|
@@ -167,14 +167,20 @@ class AsyncWebAssemblyJavascriptGenerator extends Generator {
|
|
167
167
|
)}`,
|
168
168
|
`${RuntimeGlobals.asyncModule}(${
|
169
169
|
module.moduleArgument
|
170
|
-
}, ${runtimeTemplate.basicFunction(
|
171
|
-
"__webpack_handle_async_dependencies__",
|
170
|
+
}, async ${runtimeTemplate.basicFunction(
|
171
|
+
"__webpack_handle_async_dependencies__, __webpack_async_result__",
|
172
172
|
[
|
173
|
+
"try {",
|
173
174
|
importsCode,
|
174
175
|
`var __webpack_async_dependencies__ = __webpack_handle_async_dependencies__([${promises.join(
|
175
176
|
", "
|
176
177
|
)}]);`,
|
177
|
-
|
178
|
+
`var [${promises.join(
|
179
|
+
", "
|
180
|
+
)}] = __webpack_async_dependencies__.then ? (await __webpack_async_dependencies__)() : __webpack_async_dependencies__;`,
|
181
|
+
`${importsCompatCode}await ${instantiateCall};`,
|
182
|
+
"__webpack_async_result__();",
|
183
|
+
"} catch(e) { __webpack_async_result__(e); }"
|
178
184
|
]
|
179
185
|
)}, 1);`
|
180
186
|
])
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "webpack",
|
3
|
-
"version": "5.
|
3
|
+
"version": "5.68.0",
|
4
4
|
"author": "Tobias Koppers @sokra",
|
5
5
|
"description": "Packs CommonJs/AMD modules for the browser. Allows to split your codebase into multiple bundles, which can be loaded on demand. Support loaders to preprocess files, i.e. json, jsx, es7, css, less, ... and your custom stuff.",
|
6
6
|
"license": "MIT",
|