webpack 5.110.2 → 5.110.3
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/README.md +0 -2
- package/lib/ChunkGraph.js +20 -18
- package/lib/Compilation.js +1 -1
- package/lib/ConcatenationScope.js +25 -35
- package/lib/DotenvPlugin.js +41 -13
- package/lib/FlagDependencyUsagePlugin.js +8 -2
- package/lib/NormalModule.js +13 -20
- package/lib/RuntimePlugin.js +3 -0
- package/lib/RuntimeTemplate.js +14 -2
- package/lib/async-modules/AsyncModuleHelpers.js +10 -4
- package/lib/config/defaults.js +26 -16
- package/lib/config/normalization.js +18 -8
- package/lib/dependencies/CommonJsRequireDependency.js +18 -4
- package/lib/dependencies/ContextDependencyTemplateAsRequireCall.js +20 -7
- package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +100 -19
- package/lib/dependencies/HarmonyImportDependency.js +94 -41
- package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +12 -2
- package/lib/dependencies/HtmlEntryDependency.js +12 -2
- package/lib/dependencies/ImportContextDependency.js +43 -3
- package/lib/dependencies/ImportDependency.js +8 -29
- package/lib/dependencies/ImportParserPlugin.js +24 -14
- package/lib/dependencies/RequireHeaderDependency.js +20 -21
- package/lib/dependencies/importOptionsCheck.js +47 -0
- package/lib/errors/DotenvFileError.js +29 -0
- package/lib/errors/ImportedBindingAssignmentError.js +30 -0
- package/lib/html/HtmlModulesPlugin.js +29 -22
- package/lib/html/syntax.js +304 -143
- package/lib/javascript/JavascriptModulesPlugin.js +2 -0
- package/lib/optimize/ConcatenatedModule.js +38 -7
- package/lib/prefetch/ResourceHintPlugin.js +6 -1
- package/lib/runtime/AsyncModuleRuntimeModule.js +5 -1
- package/lib/runtime/MakeDeferredNamespaceObjectRuntime.js +11 -1
- package/lib/schemes/HttpUriPlugin.js +22 -5
- package/lib/serialization/FileMiddleware.js +15 -2
- package/lib/util/ArrayQueue.js +3 -3
- package/lib/util/URLAbsoluteSpecifier.js +3 -1
- package/lib/util/conventions.js +5 -1
- package/lib/util/internalSerializables.js +2 -0
- package/package.json +1 -1
- package/schemas/WebpackOptions.check.js +1 -1
- package/schemas/WebpackOptions.json +9 -10
- package/types.d.ts +26 -17
|
@@ -76,30 +76,29 @@ RequireHeaderDependency.Template = class RequireHeaderDependencyTemplate extends
|
|
|
76
76
|
{ moduleGraph, runtime, runtimeRequirements, concatenationScope }
|
|
77
77
|
) {
|
|
78
78
|
const dep = /** @type {RequireHeaderDependency} */ (dependency);
|
|
79
|
-
|
|
80
|
-
// the paired require dependency already replaced the whole call
|
|
81
|
-
if (
|
|
82
|
-
concatenationScope !== undefined &&
|
|
83
|
-
concatenationScope.isInsideReplacedRequire(dep.range[0])
|
|
84
|
-
) {
|
|
85
|
-
return;
|
|
86
|
-
}
|
|
87
|
-
|
|
88
79
|
const requireDep = dep.requireDependency;
|
|
89
|
-
// Skip when the paired call became `0`; dead-branch still needs the header.
|
|
90
80
|
if (requireDep) {
|
|
91
81
|
const connection = moduleGraph.getConnection(requireDep);
|
|
92
|
-
if (
|
|
93
|
-
connection
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
82
|
+
if (connection) {
|
|
83
|
+
if (connection.isTargetActive(runtime)) {
|
|
84
|
+
if (
|
|
85
|
+
concatenationScope !== undefined &&
|
|
86
|
+
requireDep.rendersAsConcatenatedReference(
|
|
87
|
+
connection,
|
|
88
|
+
concatenationScope
|
|
89
|
+
)
|
|
90
|
+
) {
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
} else if (requireDep.isEvaluationOnly()) {
|
|
94
|
+
// Skip when the paired call became `0`; dead-branch still needs the header.
|
|
95
|
+
const guards = requireDep.branchGuards;
|
|
96
|
+
if (
|
|
97
|
+
guards === undefined ||
|
|
98
|
+
!HarmonyImportGuard.isDeadByGuards(guards, moduleGraph, runtime)
|
|
99
|
+
) {
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
103
102
|
}
|
|
104
103
|
}
|
|
105
104
|
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/*
|
|
2
|
+
MIT License http://www.opensource.org/licenses/mit-license.php
|
|
3
|
+
Author Alexander Akait @alexander-akait
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
"use strict";
|
|
7
|
+
|
|
8
|
+
const Template = require("../Template");
|
|
9
|
+
|
|
10
|
+
/** @import RuntimeTemplate from "../RuntimeTemplate" */
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Wraps an import so its arguments evaluate in source order and the options are
|
|
14
|
+
* checked, rejecting rather than throwing. The last parameter holds them.
|
|
15
|
+
* @param {RuntimeTemplate} runtimeTemplate the runtime template
|
|
16
|
+
* @param {string[]} parameters parameter names, the options one last
|
|
17
|
+
* @param {string} content the import expression to return once the check passes
|
|
18
|
+
* @returns {string} the wrapping function
|
|
19
|
+
*/
|
|
20
|
+
const importOptionsCheck = (runtimeTemplate, parameters, content) => {
|
|
21
|
+
const options = parameters[parameters.length - 1];
|
|
22
|
+
return runtimeTemplate.basicFunction(parameters.join(", "), [
|
|
23
|
+
"try {",
|
|
24
|
+
Template.indent([
|
|
25
|
+
`if (${options} !== undefined) {`,
|
|
26
|
+
Template.indent([
|
|
27
|
+
`if ((typeof ${options} !== "object" && typeof ${options} !== "function") || ${options} === null) throw new TypeError("The second argument to import() must be an object");`,
|
|
28
|
+
`var a = ${options}["with"];`,
|
|
29
|
+
"if (a !== undefined) {",
|
|
30
|
+
Template.indent([
|
|
31
|
+
'if ((typeof a !== "object" && typeof a !== "function") || a === null) throw new TypeError("The \'with\' option must be an object");',
|
|
32
|
+
"for (var k = Object.keys(a), i = 0; i < k.length; i++) {",
|
|
33
|
+
Template.indent([
|
|
34
|
+
'if (typeof a[k[i]] !== "string") throw new TypeError("Import attribute values must be strings");'
|
|
35
|
+
]),
|
|
36
|
+
"}"
|
|
37
|
+
]),
|
|
38
|
+
"}"
|
|
39
|
+
]),
|
|
40
|
+
"}"
|
|
41
|
+
]),
|
|
42
|
+
"} catch (e) { return Promise.reject(e); }",
|
|
43
|
+
`return ${content};`
|
|
44
|
+
]);
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
module.exports = importOptionsCheck;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/*
|
|
2
|
+
MIT License http://www.opensource.org/licenses/mit-license.php
|
|
3
|
+
Author Alexander Akait @alexander-akait
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
"use strict";
|
|
7
|
+
|
|
8
|
+
const WebpackError = require("./WebpackError");
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Error for a dotenv file that exists but could not be read. An absent file is
|
|
12
|
+
* normal and reported through `missingDependencies` instead.
|
|
13
|
+
*/
|
|
14
|
+
class DotenvFileError extends WebpackError {
|
|
15
|
+
/**
|
|
16
|
+
* @param {string} file path of the dotenv file
|
|
17
|
+
* @param {Error} error underlying file system error
|
|
18
|
+
*/
|
|
19
|
+
constructor(file, error) {
|
|
20
|
+
super(`Unable to read the dotenv file ${file}\n${error.message}`);
|
|
21
|
+
|
|
22
|
+
this.name = "DotenvFileError";
|
|
23
|
+
/** @type {string} */
|
|
24
|
+
this.file = file;
|
|
25
|
+
this.error = error;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
module.exports = DotenvFileError;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/*
|
|
2
|
+
MIT License http://www.opensource.org/licenses/mit-license.php
|
|
3
|
+
Author Alexander Akait @alexander-akait
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
"use strict";
|
|
7
|
+
|
|
8
|
+
const makeSerializable = require("../util/makeSerializable");
|
|
9
|
+
const WebpackError = require("./WebpackError");
|
|
10
|
+
|
|
11
|
+
class ImportedBindingAssignmentError extends WebpackError {
|
|
12
|
+
/**
|
|
13
|
+
* Creates an instance of ImportedBindingAssignmentError.
|
|
14
|
+
* @param {string} name the local name of the namespace binding
|
|
15
|
+
*/
|
|
16
|
+
constructor(name) {
|
|
17
|
+
super(
|
|
18
|
+
`Assignment to the imported binding '${name}'. A namespace import is immutable, so this throws a TypeError where the module is a real ES module.`
|
|
19
|
+
);
|
|
20
|
+
|
|
21
|
+
this.name = "ImportedBindingAssignmentError";
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
makeSerializable(
|
|
26
|
+
ImportedBindingAssignmentError,
|
|
27
|
+
"webpack/lib/errors/ImportedBindingAssignmentError"
|
|
28
|
+
);
|
|
29
|
+
|
|
30
|
+
module.exports = ImportedBindingAssignmentError;
|
|
@@ -241,7 +241,12 @@ const collectHtmlEntryRequests = (name, entries) => {
|
|
|
241
241
|
const seenRequests = new Set();
|
|
242
242
|
/** @type {Set<string>} */
|
|
243
243
|
const visited = new Set();
|
|
244
|
-
|
|
244
|
+
/**
|
|
245
|
+
* Collects an entry's non-html requests, `dependOn` entries included.
|
|
246
|
+
* @param {string} entryName entry to walk
|
|
247
|
+
* @returns {void}
|
|
248
|
+
*/
|
|
249
|
+
const walk = (entryName) => {
|
|
245
250
|
if (visited.has(entryName)) return;
|
|
246
251
|
visited.add(entryName);
|
|
247
252
|
const desc = entries[entryName];
|
|
@@ -613,12 +618,13 @@ class HtmlModulesPlugin {
|
|
|
613
618
|
);
|
|
614
619
|
}
|
|
615
620
|
const { htmlModules } = getState(compilation);
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
621
|
+
/**
|
|
622
|
+
* Records HTML modules as they are built or restored, so `finishMake`
|
|
623
|
+
* creates their entries without scanning the whole module graph.
|
|
624
|
+
* @param {import("../Module")} module built or restored module
|
|
625
|
+
* @returns {void}
|
|
626
|
+
*/
|
|
627
|
+
const trackHtmlModule = (module) => {
|
|
622
628
|
if (module.type !== HTML_MODULE_TYPE) return;
|
|
623
629
|
// enabled here, not on the compilation hook: an integrity build
|
|
624
630
|
// with no html module must not load the generator
|
|
@@ -981,15 +987,15 @@ class HtmlModulesPlugin {
|
|
|
981
987
|
/** @type {WeakMap<import("webpack-sources").Source, { resolvedContent: string, contentHash: string }>} */
|
|
982
988
|
const resolvedSentinelHashCache = new WeakMap();
|
|
983
989
|
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
) => {
|
|
990
|
+
/**
|
|
991
|
+
* Computes an HTML page's emitted filename, chunk-URL-resolved content and
|
|
992
|
+
* content hash. Links to other pages stay sentinels, so a page's filename
|
|
993
|
+
* never depends on the filenames of the pages it links to.
|
|
994
|
+
* @param {NormalModule} module the page's html module
|
|
995
|
+
* @param {import("../Chunk")} chunk chunk the page is emitted from
|
|
996
|
+
* @returns {{ resolvedContent: string, contentHash: string, filename: string, info: import("../Compilation").AssetInfo } | undefined} the page's emit, or `undefined` when it generates no html
|
|
997
|
+
*/
|
|
998
|
+
const computePageEmit = (module, chunk) => {
|
|
993
999
|
const { chunkGraph, outputOptions } = compilation;
|
|
994
1000
|
const codeGenResult =
|
|
995
1001
|
/** @type {import("../CodeGenerationResults")} */ (
|
|
@@ -1066,14 +1072,15 @@ class HtmlModulesPlugin {
|
|
|
1066
1072
|
};
|
|
1067
1073
|
};
|
|
1068
1074
|
|
|
1069
|
-
// Emitted filename of a linked `type: "html"` page, keyed by its entry
|
|
1070
|
-
// name. Looked up from the page's own entry chunk so it's independent of
|
|
1071
|
-
// chunk render order; cached for the compilation.
|
|
1072
1075
|
/** @type {Map<string, string>} */
|
|
1073
1076
|
const htmlPageFilenameCache = new Map();
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
+
/**
|
|
1078
|
+
* Emitted filename of a linked `type: "html"` page, read from the page's
|
|
1079
|
+
* own entry chunk so chunk render order cannot affect it.
|
|
1080
|
+
* @param {string} entryName entry name of the linked page
|
|
1081
|
+
* @returns {string} the page's emitted filename, `"data:,"` when it has none
|
|
1082
|
+
*/
|
|
1083
|
+
const computePageFilenameByEntry = (entryName) => {
|
|
1077
1084
|
const cached = htmlPageFilenameCache.get(entryName);
|
|
1078
1085
|
if (cached !== undefined) return cached;
|
|
1079
1086
|
let filename = "data:,";
|