webpack 5.35.1 → 5.37.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/Chunk.js +8 -2
- package/lib/ChunkGraph.js +58 -35
- package/lib/Compilation.js +73 -43
- package/lib/Compiler.js +27 -13
- package/lib/Dependency.js +69 -4
- package/lib/EntryPlugin.js +1 -1
- package/lib/FileSystemInfo.js +1 -1
- package/lib/InitFragment.js +21 -6
- package/lib/ModuleGraph.js +2 -2
- package/lib/NormalModule.js +16 -2
- package/lib/NormalModuleFactory.js +27 -23
- package/lib/RuntimeGlobals.js +7 -0
- package/lib/RuntimePlugin.js +19 -1
- package/lib/SourceMapDevToolPlugin.js +1 -1
- package/lib/WebpackOptionsApply.js +1 -0
- package/lib/buildChunkGraph.js +7 -2
- package/lib/cache/PackFileCacheStrategy.js +65 -4
- package/lib/config/defaults.js +12 -1
- package/lib/config/normalization.js +10 -0
- package/lib/dependencies/CreateScriptUrlDependency.js +54 -0
- package/lib/dependencies/HarmonyExportInitFragment.js +47 -0
- package/lib/dependencies/NullDependency.js +0 -8
- package/lib/dependencies/WorkerPlugin.js +32 -4
- package/lib/javascript/JavascriptParser.js +39 -31
- package/lib/optimize/InnerGraphPlugin.js +8 -9
- package/lib/runtime/CreateScriptUrlRuntimeModule.js +61 -0
- package/lib/runtime/LoadScriptRuntimeModule.js +10 -2
- package/lib/util/AsyncQueue.js +6 -1
- package/lib/util/comparators.js +22 -16
- package/lib/util/fs.js +8 -8
- package/lib/util/internalSerializables.js +2 -0
- package/lib/webworker/ImportScriptsChunkLoadingPlugin.js +13 -1
- package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +14 -4
- package/package.json +5 -5
- package/schemas/WebpackOptions.check.js +1 -1
- package/schemas/WebpackOptions.json +35 -0
- package/types.d.ts +479 -44
@@ -0,0 +1,61 @@
|
|
1
|
+
/*
|
2
|
+
MIT License http://www.opensource.org/licenses/mit-license.php
|
3
|
+
*/
|
4
|
+
|
5
|
+
"use strict";
|
6
|
+
|
7
|
+
const RuntimeGlobals = require("../RuntimeGlobals");
|
8
|
+
const Template = require("../Template");
|
9
|
+
const HelperRuntimeModule = require("./HelperRuntimeModule");
|
10
|
+
|
11
|
+
class CreateScriptUrlRuntimeModule extends HelperRuntimeModule {
|
12
|
+
constructor() {
|
13
|
+
super("trusted types");
|
14
|
+
}
|
15
|
+
|
16
|
+
/**
|
17
|
+
* @returns {string} runtime code
|
18
|
+
*/
|
19
|
+
generate() {
|
20
|
+
const { compilation } = this;
|
21
|
+
const { runtimeTemplate, outputOptions } = compilation;
|
22
|
+
const { trustedTypes } = outputOptions;
|
23
|
+
const fn = RuntimeGlobals.createScriptUrl;
|
24
|
+
|
25
|
+
if (!trustedTypes) {
|
26
|
+
// Skip Trusted Types logic.
|
27
|
+
return Template.asString([
|
28
|
+
`${fn} = ${runtimeTemplate.returningFunction("url", "url")};`
|
29
|
+
]);
|
30
|
+
}
|
31
|
+
|
32
|
+
return Template.asString([
|
33
|
+
"var policy;",
|
34
|
+
`${fn} = ${runtimeTemplate.basicFunction("url", [
|
35
|
+
"// Create Trusted Type policy if Trusted Types are available and the policy doesn't exist yet.",
|
36
|
+
"if (policy === undefined) {",
|
37
|
+
Template.indent([
|
38
|
+
"policy = {",
|
39
|
+
Template.indent([
|
40
|
+
`createScriptURL: ${runtimeTemplate.returningFunction(
|
41
|
+
"url",
|
42
|
+
"url"
|
43
|
+
)}`
|
44
|
+
]),
|
45
|
+
"};",
|
46
|
+
'if (typeof trustedTypes !== "undefined" && trustedTypes.createPolicy) {',
|
47
|
+
Template.indent([
|
48
|
+
`policy = trustedTypes.createPolicy(${JSON.stringify(
|
49
|
+
trustedTypes.policyName
|
50
|
+
)}, policy);`
|
51
|
+
]),
|
52
|
+
"}"
|
53
|
+
]),
|
54
|
+
"}",
|
55
|
+
"return policy.createScriptURL(url);"
|
56
|
+
])};`
|
57
|
+
]);
|
58
|
+
}
|
59
|
+
}
|
60
|
+
|
61
|
+
module.exports = CreateScriptUrlRuntimeModule;
|
@@ -42,8 +42,12 @@ class LoadScriptRuntimeModule extends HelperRuntimeModule {
|
|
42
42
|
return hooks;
|
43
43
|
}
|
44
44
|
|
45
|
-
|
45
|
+
/**
|
46
|
+
* @param {boolean=} withCreateScriptUrl use create script url for trusted types
|
47
|
+
*/
|
48
|
+
constructor(withCreateScriptUrl) {
|
46
49
|
super("load script");
|
50
|
+
this._withCreateScriptUrl = withCreateScriptUrl;
|
47
51
|
}
|
48
52
|
|
49
53
|
/**
|
@@ -78,7 +82,11 @@ class LoadScriptRuntimeModule extends HelperRuntimeModule {
|
|
78
82
|
uniqueName
|
79
83
|
? 'script.setAttribute("data-webpack", dataWebpackPrefix + key);'
|
80
84
|
: "",
|
81
|
-
`script.src =
|
85
|
+
`script.src = ${
|
86
|
+
this._withCreateScriptUrl
|
87
|
+
? `${RuntimeGlobals.createScriptUrl}(url)`
|
88
|
+
: "url"
|
89
|
+
};`,
|
82
90
|
crossOriginLoading
|
83
91
|
? Template.asString([
|
84
92
|
"if (script.src.indexOf(window.location.origin + '/') !== 0) {",
|
package/lib/util/AsyncQueue.js
CHANGED
@@ -119,7 +119,12 @@ class AsyncQueue {
|
|
119
119
|
const entry = this._entries.get(key);
|
120
120
|
if (entry !== undefined) {
|
121
121
|
if (entry.state === DONE_STATE) {
|
122
|
-
|
122
|
+
if (inHandleResult++ > 3) {
|
123
|
+
process.nextTick(() => callback(entry.error, entry.result));
|
124
|
+
} else {
|
125
|
+
callback(entry.error, entry.result);
|
126
|
+
}
|
127
|
+
inHandleResult--;
|
123
128
|
} else if (entry.callbacks === undefined) {
|
124
129
|
entry.callbacks = [callback];
|
125
130
|
} else {
|
package/lib/util/comparators.js
CHANGED
@@ -433,21 +433,27 @@ exports.compareLocations = (a, b) => {
|
|
433
433
|
if (isObjectB) return -1;
|
434
434
|
return 0;
|
435
435
|
}
|
436
|
-
if ("start" in a
|
437
|
-
|
438
|
-
|
439
|
-
|
440
|
-
|
441
|
-
|
442
|
-
|
443
|
-
|
444
|
-
|
445
|
-
|
446
|
-
|
447
|
-
|
448
|
-
|
449
|
-
|
450
|
-
|
451
|
-
}
|
436
|
+
if ("start" in a) {
|
437
|
+
if ("start" in b) {
|
438
|
+
const ap = a.start;
|
439
|
+
const bp = b.start;
|
440
|
+
if (ap.line < bp.line) return -1;
|
441
|
+
if (ap.line > bp.line) return 1;
|
442
|
+
if (ap.column < bp.column) return -1;
|
443
|
+
if (ap.column > bp.column) return 1;
|
444
|
+
} else return -1;
|
445
|
+
} else if ("start" in b) return 1;
|
446
|
+
if ("name" in a) {
|
447
|
+
if ("name" in b) {
|
448
|
+
if (a.name < b.name) return -1;
|
449
|
+
if (a.name > b.name) return 1;
|
450
|
+
} else return -1;
|
451
|
+
} else if ("name" in b) return 1;
|
452
|
+
if ("index" in a) {
|
453
|
+
if ("index" in b) {
|
454
|
+
if (a.index < b.index) return -1;
|
455
|
+
if (a.index > b.index) return 1;
|
456
|
+
} else return -1;
|
457
|
+
} else if ("index" in b) return 1;
|
452
458
|
return 0;
|
453
459
|
};
|
package/lib/util/fs.js
CHANGED
@@ -51,14 +51,14 @@ const path = require("path");
|
|
51
51
|
* @property {string | Buffer} name
|
52
52
|
*/
|
53
53
|
|
54
|
-
/** @typedef {function(NodeJS.ErrnoException=): void} Callback */
|
55
|
-
/** @typedef {function(NodeJS.ErrnoException=, Buffer=): void} BufferCallback */
|
56
|
-
/** @typedef {function(NodeJS.ErrnoException=, Buffer|string=): void} BufferOrStringCallback */
|
57
|
-
/** @typedef {function(NodeJS.ErrnoException=, (string | Buffer)[] | IDirent[]=): void} DirentArrayCallback */
|
58
|
-
/** @typedef {function(NodeJS.ErrnoException=, string=): void} StringCallback */
|
59
|
-
/** @typedef {function(NodeJS.ErrnoException=, number=): void} NumberCallback */
|
60
|
-
/** @typedef {function(NodeJS.ErrnoException=, IStats=): void} StatsCallback */
|
61
|
-
/** @typedef {function((NodeJS.ErrnoException | Error)=, any=): void} ReadJsonCallback */
|
54
|
+
/** @typedef {function((NodeJS.ErrnoException | null)=): void} Callback */
|
55
|
+
/** @typedef {function((NodeJS.ErrnoException | null)=, Buffer=): void} BufferCallback */
|
56
|
+
/** @typedef {function((NodeJS.ErrnoException | null)=, Buffer|string=): void} BufferOrStringCallback */
|
57
|
+
/** @typedef {function((NodeJS.ErrnoException | null)=, (string | Buffer)[] | IDirent[]=): void} DirentArrayCallback */
|
58
|
+
/** @typedef {function((NodeJS.ErrnoException | null)=, string=): void} StringCallback */
|
59
|
+
/** @typedef {function((NodeJS.ErrnoException | null)=, number=): void} NumberCallback */
|
60
|
+
/** @typedef {function((NodeJS.ErrnoException | null)=, IStats=): void} StatsCallback */
|
61
|
+
/** @typedef {function((NodeJS.ErrnoException | Error | null)=, any=): void} ReadJsonCallback */
|
62
62
|
|
63
63
|
/**
|
64
64
|
* @typedef {Object} Watcher
|
@@ -45,6 +45,8 @@ module.exports = {
|
|
45
45
|
require("../dependencies/AMDRequireItemDependency"),
|
46
46
|
"dependencies/CachedConstDependency": () =>
|
47
47
|
require("../dependencies/CachedConstDependency"),
|
48
|
+
"dependencies/CreateScriptUrlDependency": () =>
|
49
|
+
require("../dependencies/CreateScriptUrlDependency"),
|
48
50
|
"dependencies/CommonJsRequireContextDependency": () =>
|
49
51
|
require("../dependencies/CommonJsRequireContextDependency"),
|
50
52
|
"dependencies/CommonJsExportRequireDependency": () =>
|
@@ -6,6 +6,7 @@
|
|
6
6
|
"use strict";
|
7
7
|
|
8
8
|
const RuntimeGlobals = require("../RuntimeGlobals");
|
9
|
+
const CreateScriptUrlRuntimeModule = require("../runtime/CreateScriptUrlRuntimeModule");
|
9
10
|
const StartupChunkDependenciesPlugin = require("../runtime/StartupChunkDependenciesPlugin");
|
10
11
|
const ImportScriptsChunkLoadingRuntimeModule = require("./ImportScriptsChunkLoadingRuntimeModule");
|
11
12
|
|
@@ -39,11 +40,13 @@ class ImportScriptsChunkLoadingPlugin {
|
|
39
40
|
if (onceForChunkSet.has(chunk)) return;
|
40
41
|
onceForChunkSet.add(chunk);
|
41
42
|
if (!isEnabledForChunk(chunk)) return;
|
43
|
+
const withCreateScriptUrl = !!compilation.outputOptions.trustedTypes;
|
42
44
|
set.add(RuntimeGlobals.moduleFactoriesAddOnly);
|
43
45
|
set.add(RuntimeGlobals.hasOwnProperty);
|
46
|
+
if (withCreateScriptUrl) set.add(RuntimeGlobals.createScriptUrl);
|
44
47
|
compilation.addRuntimeModule(
|
45
48
|
chunk,
|
46
|
-
new ImportScriptsChunkLoadingRuntimeModule(set)
|
49
|
+
new ImportScriptsChunkLoadingRuntimeModule(set, withCreateScriptUrl)
|
47
50
|
);
|
48
51
|
};
|
49
52
|
compilation.hooks.runtimeRequirementInTree
|
@@ -58,6 +61,15 @@ class ImportScriptsChunkLoadingPlugin {
|
|
58
61
|
compilation.hooks.runtimeRequirementInTree
|
59
62
|
.for(RuntimeGlobals.baseURI)
|
60
63
|
.tap("ImportScriptsChunkLoadingPlugin", handler);
|
64
|
+
compilation.hooks.runtimeRequirementInTree
|
65
|
+
.for(RuntimeGlobals.createScriptUrl)
|
66
|
+
.tap("RuntimePlugin", (chunk, set) => {
|
67
|
+
compilation.addRuntimeModule(
|
68
|
+
chunk,
|
69
|
+
new CreateScriptUrlRuntimeModule()
|
70
|
+
);
|
71
|
+
return true;
|
72
|
+
});
|
61
73
|
|
62
74
|
compilation.hooks.runtimeRequirementInTree
|
63
75
|
.for(RuntimeGlobals.ensureChunkHandlers)
|
@@ -16,9 +16,10 @@ const compileBooleanMatcher = require("../util/compileBooleanMatcher");
|
|
16
16
|
const { getUndoPath } = require("../util/identifier");
|
17
17
|
|
18
18
|
class ImportScriptsChunkLoadingRuntimeModule extends RuntimeModule {
|
19
|
-
constructor(runtimeRequirements) {
|
19
|
+
constructor(runtimeRequirements, withCreateScriptUrl) {
|
20
20
|
super("importScripts chunk loading", RuntimeModule.STAGE_ATTACH);
|
21
21
|
this.runtimeRequirements = runtimeRequirements;
|
22
|
+
this._withCreateScriptUrl = withCreateScriptUrl;
|
22
23
|
}
|
23
24
|
|
24
25
|
/**
|
@@ -31,7 +32,8 @@ class ImportScriptsChunkLoadingRuntimeModule extends RuntimeModule {
|
|
31
32
|
compilation: {
|
32
33
|
runtimeTemplate,
|
33
34
|
outputOptions: { globalObject, chunkLoadingGlobal, hotUpdateGlobal }
|
34
|
-
}
|
35
|
+
},
|
36
|
+
_withCreateScriptUrl: withCreateScriptUrl
|
35
37
|
} = this;
|
36
38
|
const fn = RuntimeGlobals.ensureChunkHandlers;
|
37
39
|
const withBaseURI = this.runtimeRequirements.has(RuntimeGlobals.baseURI);
|
@@ -121,7 +123,11 @@ class ImportScriptsChunkLoadingRuntimeModule extends RuntimeModule {
|
|
121
123
|
? "if(true) { // all chunks have JS"
|
122
124
|
: `if(${hasJsMatcher("chunkId")}) {`,
|
123
125
|
Template.indent(
|
124
|
-
`importScripts(${
|
126
|
+
`importScripts(${
|
127
|
+
withCreateScriptUrl
|
128
|
+
? `${RuntimeGlobals.createScriptUrl}(${RuntimeGlobals.publicPath} + ${RuntimeGlobals.getChunkScriptFilename}(chunkId))`
|
129
|
+
: `${RuntimeGlobals.publicPath} + ${RuntimeGlobals.getChunkScriptFilename}(chunkId)`
|
130
|
+
});`
|
125
131
|
),
|
126
132
|
"}"
|
127
133
|
]),
|
@@ -158,7 +164,11 @@ class ImportScriptsChunkLoadingRuntimeModule extends RuntimeModule {
|
|
158
164
|
"success = true;"
|
159
165
|
])};`,
|
160
166
|
"// start update chunk loading",
|
161
|
-
`importScripts(${
|
167
|
+
`importScripts(${
|
168
|
+
withCreateScriptUrl
|
169
|
+
? `${RuntimeGlobals.createScriptUrl}(${RuntimeGlobals.publicPath} + ${RuntimeGlobals.getChunkUpdateScriptFilename}(chunkId))`
|
170
|
+
: `${RuntimeGlobals.publicPath} + ${RuntimeGlobals.getChunkUpdateScriptFilename}(chunkId)`
|
171
|
+
});`,
|
162
172
|
'if(!success) throw new Error("Loading update chunk failed for unknown reason");'
|
163
173
|
]),
|
164
174
|
"}",
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "webpack",
|
3
|
-
"version": "5.
|
3
|
+
"version": "5.37.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",
|
@@ -10,7 +10,7 @@
|
|
10
10
|
"@webassemblyjs/ast": "1.11.0",
|
11
11
|
"@webassemblyjs/wasm-edit": "1.11.0",
|
12
12
|
"@webassemblyjs/wasm-parser": "1.11.0",
|
13
|
-
"acorn": "^8.
|
13
|
+
"acorn": "^8.2.1",
|
14
14
|
"browserslist": "^4.14.5",
|
15
15
|
"chrome-trace-event": "^1.0.2",
|
16
16
|
"enhanced-resolve": "^5.8.0",
|
@@ -39,7 +39,7 @@
|
|
39
39
|
"@babel/preset-react": "^7.10.4",
|
40
40
|
"@types/es-module-lexer": "^0.3.0",
|
41
41
|
"@types/jest": "^26.0.15",
|
42
|
-
"@types/node": "^
|
42
|
+
"@types/node": "^15.0.1",
|
43
43
|
"babel-loader": "^8.1.0",
|
44
44
|
"benchmark": "^2.1.4",
|
45
45
|
"bundle-loader": "^0.5.6",
|
@@ -55,7 +55,7 @@
|
|
55
55
|
"eslint": "^7.14.0",
|
56
56
|
"eslint-config-prettier": "^8.1.0",
|
57
57
|
"eslint-plugin-jest": "^24.1.3",
|
58
|
-
"eslint-plugin-jsdoc": "^
|
58
|
+
"eslint-plugin-jsdoc": "^33.0.0",
|
59
59
|
"eslint-plugin-node": "^11.0.0",
|
60
60
|
"eslint-plugin-prettier": "^3.1.4",
|
61
61
|
"file-loader": "^6.0.0",
|
@@ -92,7 +92,7 @@
|
|
92
92
|
"style-loader": "^2.0.0",
|
93
93
|
"terser": "^5.5.0",
|
94
94
|
"toml": "^3.0.0",
|
95
|
-
"tooling": "webpack/tooling#v1.
|
95
|
+
"tooling": "webpack/tooling#v1.19.0",
|
96
96
|
"ts-loader": "^8.0.2",
|
97
97
|
"typescript": "^4.2.0-beta",
|
98
98
|
"url-loader": "^4.1.0",
|