webpack 5.103.0 → 5.104.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.
- package/hot/dev-server.js +18 -3
- package/hot/emitter-event-target.js +7 -0
- package/hot/lazy-compilation-node.js +45 -29
- package/hot/lazy-compilation-universal.js +18 -0
- package/hot/lazy-compilation-web.js +15 -5
- package/hot/load-http.js +7 -0
- package/hot/only-dev-server.js +19 -4
- package/lib/APIPlugin.js +6 -0
- package/lib/Chunk.js +1 -1
- package/lib/ChunkGraph.js +9 -7
- package/lib/ChunkGroup.js +8 -5
- package/lib/CleanPlugin.js +6 -3
- package/lib/CodeGenerationResults.js +2 -1
- package/lib/CompatibilityPlugin.js +3 -0
- package/lib/Compilation.js +33 -19
- package/lib/Compiler.js +3 -3
- package/lib/ContextModule.js +6 -3
- package/lib/ContextModuleFactory.js +6 -4
- package/lib/DefinePlugin.js +34 -3
- package/lib/DelegatedModule.js +7 -4
- package/lib/DllModule.js +6 -3
- package/lib/DotenvPlugin.js +11 -6
- package/lib/ExportsInfo.js +5 -5
- package/lib/ExternalModule.js +8 -7
- package/lib/ExternalModuleFactoryPlugin.js +1 -1
- package/lib/FileSystemInfo.js +1 -1
- package/lib/Generator.js +10 -7
- package/lib/HookWebpackError.js +33 -4
- package/lib/HotModuleReplacementPlugin.js +22 -0
- package/lib/ManifestPlugin.js +1 -1
- package/lib/Module.js +24 -15
- package/lib/ModuleBuildError.js +1 -1
- package/lib/ModuleError.js +1 -1
- package/lib/ModuleFilenameHelpers.js +1 -1
- package/lib/ModuleGraph.js +27 -12
- package/lib/ModuleGraphConnection.js +2 -2
- package/lib/ModuleSourceTypeConstants.js +189 -0
- package/lib/ModuleTypeConstants.js +1 -4
- package/lib/ModuleWarning.js +1 -1
- package/lib/NodeStuffPlugin.js +52 -42
- package/lib/NormalModule.js +6 -4
- package/lib/NormalModuleFactory.js +7 -10
- package/lib/Parser.js +1 -1
- package/lib/RawModule.js +7 -4
- package/lib/RuntimeModule.js +1 -1
- package/lib/RuntimeTemplate.js +5 -1
- package/lib/SourceMapDevToolPlugin.js +6 -1
- package/lib/Template.js +17 -6
- package/lib/TemplatedPathPlugin.js +5 -6
- package/lib/WebpackError.js +0 -1
- package/lib/WebpackOptionsApply.js +37 -9
- package/lib/asset/AssetBytesGenerator.js +15 -11
- package/lib/asset/AssetGenerator.js +30 -24
- package/lib/asset/AssetSourceGenerator.js +15 -11
- package/lib/asset/RawDataUrlModule.js +6 -3
- package/lib/buildChunkGraph.js +4 -2
- package/lib/cache/PackFileCacheStrategy.js +6 -5
- package/lib/cli.js +2 -43
- package/lib/config/browserslistTargetHandler.js +19 -0
- package/lib/config/defaults.js +128 -43
- package/lib/config/normalization.js +2 -2
- package/lib/config/target.js +5 -0
- package/lib/container/ContainerEntryModule.js +6 -3
- package/lib/container/FallbackModule.js +6 -3
- package/lib/container/RemoteModule.js +1 -3
- package/lib/css/CssGenerator.js +26 -24
- package/lib/css/CssLoadingRuntimeModule.js +12 -4
- package/lib/css/CssModulesPlugin.js +29 -74
- package/lib/css/CssParser.js +828 -341
- package/lib/css/walkCssTokens.js +33 -13
- package/lib/dependencies/CachedConstDependency.js +24 -10
- package/lib/dependencies/CommonJsRequireContextDependency.js +1 -1
- package/lib/dependencies/ContextDependencyHelpers.js +2 -2
- package/lib/dependencies/ContextDependencyTemplateAsRequireCall.js +3 -1
- package/lib/dependencies/CssIcssExportDependency.js +242 -104
- package/lib/dependencies/CssIcssImportDependency.js +61 -4
- package/lib/dependencies/CssIcssSymbolDependency.js +2 -6
- package/lib/dependencies/CssImportDependency.js +2 -1
- package/lib/dependencies/CssUrlDependency.js +3 -2
- package/lib/dependencies/DynamicExports.js +7 -7
- package/lib/dependencies/ExternalModuleDependency.js +7 -4
- package/lib/dependencies/ExternalModuleInitFragment.js +2 -1
- package/lib/dependencies/ExternalModuleInitFragmentDependency.js +2 -1
- package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +3 -2
- package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +1 -1
- package/lib/dependencies/HarmonyExports.js +4 -4
- package/lib/dependencies/HarmonyImportDependency.js +8 -3
- package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +1 -1
- package/lib/dependencies/ImportMetaPlugin.js +57 -0
- package/lib/dependencies/ImportParserPlugin.js +2 -2
- package/lib/dependencies/LocalModulesHelpers.js +3 -3
- package/lib/dependencies/WorkerPlugin.js +2 -2
- package/lib/dependencies/getFunctionExpression.js +1 -1
- package/lib/esm/ModuleChunkFormatPlugin.js +5 -4
- package/lib/hmr/HotModuleReplacement.runtime.js +2 -1
- package/lib/hmr/LazyCompilationPlugin.js +4 -3
- package/lib/ids/IdHelpers.js +16 -7
- package/lib/javascript/ChunkHelpers.js +1 -1
- package/lib/javascript/JavascriptGenerator.js +4 -3
- package/lib/javascript/JavascriptModulesPlugin.js +57 -24
- package/lib/javascript/JavascriptParser.js +19 -6
- package/lib/json/JsonGenerator.js +5 -4
- package/lib/json/JsonParser.js +2 -1
- package/lib/library/AbstractLibraryPlugin.js +1 -1
- package/lib/library/AmdLibraryPlugin.js +4 -1
- package/lib/library/ExportPropertyLibraryPlugin.js +4 -1
- package/lib/library/ModuleLibraryPlugin.js +41 -13
- package/lib/library/SystemLibraryPlugin.js +4 -1
- package/lib/library/UmdLibraryPlugin.js +1 -1
- package/lib/logging/Logger.js +5 -4
- package/lib/logging/createConsoleLogger.js +2 -2
- package/lib/optimize/ConcatenatedModule.js +47 -32
- package/lib/optimize/ModuleConcatenationPlugin.js +5 -4
- package/lib/optimize/SideEffectsFlagPlugin.js +3 -2
- package/lib/optimize/SplitChunksPlugin.js +60 -46
- package/lib/rules/RuleSetCompiler.js +1 -1
- package/lib/runtime/GetChunkFilenameRuntimeModule.js +3 -2
- package/lib/schemes/HttpUriPlugin.js +78 -7
- package/lib/serialization/AggregateErrorSerializer.js +1 -2
- package/lib/serialization/ObjectMiddleware.js +0 -2
- package/lib/serialization/SingleItemMiddleware.js +1 -1
- package/lib/sharing/ConsumeSharedModule.js +1 -1
- package/lib/sharing/ConsumeSharedPlugin.js +5 -3
- package/lib/sharing/ProvideSharedModule.js +1 -1
- package/lib/sharing/resolveMatchedConfigs.js +15 -9
- package/lib/sharing/utils.js +1 -1
- package/lib/stats/DefaultStatsFactoryPlugin.js +8 -5
- package/lib/stats/DefaultStatsPresetPlugin.js +1 -1
- package/lib/stats/DefaultStatsPrinterPlugin.js +1 -1
- package/lib/util/StringXor.js +1 -1
- package/lib/util/URLAbsoluteSpecifier.js +2 -2
- package/lib/util/binarySearchBounds.js +2 -2
- package/lib/util/comparators.js +53 -76
- package/lib/util/compileBooleanMatcher.js +78 -6
- package/lib/util/createHash.js +20 -199
- package/lib/util/deprecation.js +1 -1
- package/lib/util/deterministicGrouping.js +6 -3
- package/lib/util/fs.js +75 -75
- package/lib/util/hash/BatchedHash.js +10 -9
- package/lib/util/hash/BulkUpdateHash.js +138 -0
- package/lib/util/hash/DebugHash.js +75 -0
- package/lib/util/hash/hash-digest.js +216 -0
- package/lib/util/identifier.js +82 -17
- package/lib/util/internalSerializables.js +2 -6
- package/lib/util/runtime.js +3 -3
- package/lib/util/source.js +2 -2
- package/lib/wasm-async/AsyncWebAssemblyGenerator.js +3 -2
- package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +3 -2
- package/lib/wasm-sync/WebAssemblyGenerator.js +9 -6
- package/lib/wasm-sync/WebAssemblyJavascriptGenerator.js +3 -2
- package/lib/wasm-sync/WebAssemblyModulesPlugin.js +6 -2
- package/lib/webpack.js +1 -1
- package/package.json +29 -25
- package/schemas/WebpackOptions.check.js +1 -1
- package/schemas/WebpackOptions.json +59 -82
- package/schemas/plugins/css/CssModuleGeneratorOptions.check.js +1 -1
- package/schemas/plugins/css/CssModuleParserOptions.check.js +1 -1
- package/types.d.ts +225 -157
- package/lib/ModuleSourceTypesConstants.js +0 -117
- package/lib/dependencies/CssIcssFromIdentifierDependency.js +0 -124
- package/lib/dependencies/CssIcssGlobalIdentifierDependency.js +0 -48
- package/lib/dependencies/CssIcssLocalIdentifierDependency.js +0 -61
- package/lib/dependencies/CssIcssSelfLocalIdentifierDependency.js +0 -190
- package/lib/util/jsonParseEvenBetterErrors.js +0 -10
- package/schemas/plugins/css/CssAutoGeneratorOptions.check.d.ts +0 -7
- package/schemas/plugins/css/CssAutoGeneratorOptions.check.js +0 -6
- package/schemas/plugins/css/CssAutoGeneratorOptions.json +0 -3
- package/schemas/plugins/css/CssAutoParserOptions.check.d.ts +0 -7
- package/schemas/plugins/css/CssAutoParserOptions.check.js +0 -6
- package/schemas/plugins/css/CssAutoParserOptions.json +0 -3
- package/schemas/plugins/css/CssGlobalGeneratorOptions.check.d.ts +0 -7
- package/schemas/plugins/css/CssGlobalGeneratorOptions.check.js +0 -6
- package/schemas/plugins/css/CssGlobalGeneratorOptions.json +0 -3
- package/schemas/plugins/css/CssGlobalParserOptions.check.d.ts +0 -7
- package/schemas/plugins/css/CssGlobalParserOptions.check.js +0 -6
- package/schemas/plugins/css/CssGlobalParserOptions.json +0 -3
package/hot/dev-server.js
CHANGED
|
@@ -61,14 +61,29 @@ if (module.hot) {
|
|
|
61
61
|
}
|
|
62
62
|
});
|
|
63
63
|
};
|
|
64
|
+
/** @type {EventTarget | NodeJS.EventEmitter} */
|
|
64
65
|
var hotEmitter = require("./emitter");
|
|
65
|
-
|
|
66
|
-
|
|
66
|
+
/**
|
|
67
|
+
* @param {CustomEvent<{ currentHash: string }>} event event or hash
|
|
68
|
+
*/
|
|
69
|
+
var handler = function (event) {
|
|
70
|
+
lastHash = typeof event === "string" ? event : event.detail.currentHash;
|
|
67
71
|
if (!upToDate() && module.hot.status() === "idle") {
|
|
68
72
|
log("info", "[HMR] Checking for updates on the server...");
|
|
69
73
|
check();
|
|
70
74
|
}
|
|
71
|
-
}
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
if (typeof EventTarget !== "undefined" && hotEmitter instanceof EventTarget) {
|
|
78
|
+
hotEmitter.addEventListener(
|
|
79
|
+
"webpackHotUpdate",
|
|
80
|
+
/** @type {EventListener} */
|
|
81
|
+
(handler)
|
|
82
|
+
);
|
|
83
|
+
} else {
|
|
84
|
+
hotEmitter.on("webpackHotUpdate", handler);
|
|
85
|
+
}
|
|
86
|
+
|
|
72
87
|
log("info", "[HMR] Waiting for update signal from WDS...");
|
|
73
88
|
} else {
|
|
74
89
|
throw new Error("[HMR] Hot Module Replacement is disabled.");
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
/* global __resourceQuery */
|
|
2
|
-
|
|
3
1
|
"use strict";
|
|
4
2
|
|
|
3
|
+
/* global __resourceQuery */
|
|
4
|
+
|
|
5
5
|
var urlBase = decodeURIComponent(__resourceQuery.slice(1));
|
|
6
6
|
|
|
7
7
|
/**
|
|
@@ -10,29 +10,6 @@ var urlBase = decodeURIComponent(__resourceQuery.slice(1));
|
|
|
10
10
|
*/
|
|
11
11
|
exports.keepAlive = function (options) {
|
|
12
12
|
var data = options.data;
|
|
13
|
-
var onError = options.onError;
|
|
14
|
-
var active = options.active;
|
|
15
|
-
var module = options.module;
|
|
16
|
-
/** @type {import("http").IncomingMessage} */
|
|
17
|
-
var response;
|
|
18
|
-
var request = (
|
|
19
|
-
urlBase.startsWith("https") ? require("https") : require("http")
|
|
20
|
-
).request(
|
|
21
|
-
urlBase + data,
|
|
22
|
-
{
|
|
23
|
-
agent: false,
|
|
24
|
-
headers: { accept: "text/event-stream" }
|
|
25
|
-
},
|
|
26
|
-
function (res) {
|
|
27
|
-
response = res;
|
|
28
|
-
response.on("error", errorHandler);
|
|
29
|
-
if (!active && !module.hot) {
|
|
30
|
-
console.log(
|
|
31
|
-
"Hot Module Replacement is not enabled. Waiting for process restart..."
|
|
32
|
-
);
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
);
|
|
36
13
|
|
|
37
14
|
/**
|
|
38
15
|
* @param {Error} err error
|
|
@@ -40,11 +17,50 @@ exports.keepAlive = function (options) {
|
|
|
40
17
|
function errorHandler(err) {
|
|
41
18
|
err.message =
|
|
42
19
|
"Problem communicating active modules to the server: " + err.message;
|
|
43
|
-
onError(err);
|
|
20
|
+
options.onError(err);
|
|
44
21
|
}
|
|
45
|
-
|
|
46
|
-
|
|
22
|
+
|
|
23
|
+
/** @type {Promise<import("http") | import("https")>} */
|
|
24
|
+
var mod = require("./load-http")(urlBase.startsWith("https"));
|
|
25
|
+
|
|
26
|
+
/** @type {import("http").ClientRequest} */
|
|
27
|
+
var request;
|
|
28
|
+
/** @type {import("http").IncomingMessage} */
|
|
29
|
+
var response;
|
|
30
|
+
|
|
31
|
+
mod.then(function (client) {
|
|
32
|
+
request = client.request(
|
|
33
|
+
urlBase + data,
|
|
34
|
+
{
|
|
35
|
+
agent: false,
|
|
36
|
+
headers: { accept: "text/event-stream" }
|
|
37
|
+
},
|
|
38
|
+
function (res) {
|
|
39
|
+
response = res;
|
|
40
|
+
response.on("error", errorHandler);
|
|
41
|
+
|
|
42
|
+
if (!options.active && !options.module.hot) {
|
|
43
|
+
console.log(
|
|
44
|
+
"Hot Module Replacement is not enabled. Waiting for process restart..."
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
);
|
|
49
|
+
|
|
50
|
+
request.on("error", errorHandler);
|
|
51
|
+
request.end();
|
|
52
|
+
});
|
|
53
|
+
|
|
47
54
|
return function () {
|
|
48
|
-
response
|
|
55
|
+
if (response) {
|
|
56
|
+
response.destroy();
|
|
57
|
+
}
|
|
49
58
|
};
|
|
50
59
|
};
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* @param {string} value new url value
|
|
63
|
+
*/
|
|
64
|
+
exports.setUrl = function (value) {
|
|
65
|
+
urlBase = value;
|
|
66
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
/* global __resourceQuery */
|
|
4
|
+
|
|
5
|
+
var isNodeLikeEnv =
|
|
6
|
+
typeof global !== "undefined" && typeof global.process !== "undefined";
|
|
7
|
+
|
|
8
|
+
var handler = isNodeLikeEnv
|
|
9
|
+
? require("./lazy-compilation-node")
|
|
10
|
+
: require("./lazy-compilation-web");
|
|
11
|
+
|
|
12
|
+
handler.setUrl(decodeURIComponent(__resourceQuery.slice(1)));
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* @param {{ data: string, onError: (err: Error) => void, active: boolean, module: module }} options options
|
|
16
|
+
* @returns {() => void} function to destroy response
|
|
17
|
+
*/
|
|
18
|
+
module.exports = handler;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
/* global __resourceQuery */
|
|
2
|
-
|
|
3
1
|
"use strict";
|
|
4
2
|
|
|
3
|
+
/* global __resourceQuery */
|
|
4
|
+
|
|
5
5
|
if (typeof EventSource !== "function") {
|
|
6
6
|
throw new Error(
|
|
7
7
|
"Environment doesn't support lazy compilation (requires EventSource)"
|
|
@@ -54,15 +54,18 @@ var updateEventSource = function updateEventSource() {
|
|
|
54
54
|
exports.keepAlive = function (options) {
|
|
55
55
|
var data = options.data;
|
|
56
56
|
var onError = options.onError;
|
|
57
|
-
|
|
58
|
-
var module = options.module;
|
|
57
|
+
|
|
59
58
|
errorHandlers.add(onError);
|
|
59
|
+
|
|
60
60
|
var value = activeKeys.get(data) || 0;
|
|
61
|
+
|
|
61
62
|
activeKeys.set(data, value + 1);
|
|
63
|
+
|
|
62
64
|
if (value === 0) {
|
|
63
65
|
updateEventSource();
|
|
64
66
|
}
|
|
65
|
-
|
|
67
|
+
|
|
68
|
+
if (!options.active && !options.module.hot) {
|
|
66
69
|
console.log(
|
|
67
70
|
"Hot Module Replacement is not enabled. Waiting for process restart..."
|
|
68
71
|
);
|
|
@@ -81,3 +84,10 @@ exports.keepAlive = function (options) {
|
|
|
81
84
|
}, 1000);
|
|
82
85
|
};
|
|
83
86
|
};
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* @param {string} value new url value
|
|
90
|
+
*/
|
|
91
|
+
exports.setUrl = function (value) {
|
|
92
|
+
urlBase = value;
|
|
93
|
+
};
|
package/hot/load-http.js
ADDED
package/hot/only-dev-server.js
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
*/
|
|
5
5
|
/* globals __webpack_hash__ */
|
|
6
6
|
if (module.hot) {
|
|
7
|
-
/** @type {undefined|string} */
|
|
7
|
+
/** @type {undefined | string} */
|
|
8
8
|
var lastHash;
|
|
9
9
|
var upToDate = function upToDate() {
|
|
10
10
|
return /** @type {string} */ (lastHash).indexOf(__webpack_hash__) >= 0;
|
|
@@ -79,9 +79,13 @@ if (module.hot) {
|
|
|
79
79
|
}
|
|
80
80
|
});
|
|
81
81
|
};
|
|
82
|
+
/** @type {EventTarget | NodeJS.EventEmitter} */
|
|
82
83
|
var hotEmitter = require("./emitter");
|
|
83
|
-
|
|
84
|
-
|
|
84
|
+
/**
|
|
85
|
+
* @param {CustomEvent<{ currentHash: string }>} event event or hash
|
|
86
|
+
*/
|
|
87
|
+
var handler = function (event) {
|
|
88
|
+
lastHash = typeof event === "string" ? event : event.detail.currentHash;
|
|
85
89
|
if (!upToDate()) {
|
|
86
90
|
var status = module.hot.status();
|
|
87
91
|
if (status === "idle") {
|
|
@@ -96,7 +100,18 @@ if (module.hot) {
|
|
|
96
100
|
);
|
|
97
101
|
}
|
|
98
102
|
}
|
|
99
|
-
}
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
if (typeof EventTarget !== "undefined" && hotEmitter instanceof EventTarget) {
|
|
106
|
+
hotEmitter.addEventListener(
|
|
107
|
+
"webpackHotUpdate",
|
|
108
|
+
/** @type {EventListener} */
|
|
109
|
+
(handler)
|
|
110
|
+
);
|
|
111
|
+
} else {
|
|
112
|
+
hotEmitter.on("webpackHotUpdate", handler);
|
|
113
|
+
}
|
|
114
|
+
|
|
100
115
|
log("info", "[HMR] Waiting for update signal from WDS...");
|
|
101
116
|
} else {
|
|
102
117
|
throw new Error("[HMR] Hot Module Replacement is disabled.");
|
package/lib/APIPlugin.js
CHANGED
|
@@ -42,6 +42,12 @@ function getReplacements() {
|
|
|
42
42
|
type: "function",
|
|
43
43
|
assign: false
|
|
44
44
|
},
|
|
45
|
+
__webpack_global__: {
|
|
46
|
+
expr: RuntimeGlobals.require,
|
|
47
|
+
req: [RuntimeGlobals.require],
|
|
48
|
+
type: "function",
|
|
49
|
+
assign: false
|
|
50
|
+
},
|
|
45
51
|
__webpack_public_path__: {
|
|
46
52
|
expr: RuntimeGlobals.publicPath,
|
|
47
53
|
req: [RuntimeGlobals.publicPath],
|
package/lib/Chunk.js
CHANGED
|
@@ -207,7 +207,7 @@ class Chunk {
|
|
|
207
207
|
|
|
208
208
|
/**
|
|
209
209
|
* @param {Chunk} otherChunk the chunk to compare with
|
|
210
|
-
* @returns {-1|0|1} the comparison result
|
|
210
|
+
* @returns {-1 | 0 | 1} the comparison result
|
|
211
211
|
*/
|
|
212
212
|
compareTo(otherChunk) {
|
|
213
213
|
const chunkGraph = ChunkGraph.getChunkGraphForChunk(
|
package/lib/ChunkGraph.js
CHANGED
|
@@ -35,8 +35,9 @@ const {
|
|
|
35
35
|
/** @typedef {import("./Chunk").Entrypoints} Entrypoints */
|
|
36
36
|
/** @typedef {import("./Chunk").ChunkId} ChunkId */
|
|
37
37
|
/** @typedef {import("./ChunkGroup")} ChunkGroup */
|
|
38
|
-
/** @typedef {import("./Generator").SourceTypes} SourceTypes */
|
|
39
38
|
/** @typedef {import("./Module")} Module */
|
|
39
|
+
/** @typedef {import("./Module").SourceType} SourceType */
|
|
40
|
+
/** @typedef {import("./Module").SourceTypes} SourceTypes */
|
|
40
41
|
/** @typedef {import("./Module").ReadOnlyRuntimeRequirements} ReadOnlyRuntimeRequirements */
|
|
41
42
|
/** @typedef {import("./Module").RuntimeRequirements} RuntimeRequirements */
|
|
42
43
|
/** @typedef {import("./ModuleGraph")} ModuleGraph */
|
|
@@ -97,7 +98,7 @@ const getModuleRuntimes = (chunks) => {
|
|
|
97
98
|
* @returns {(set: SortableSet<Module>) => Map<string, SortableSet<Module>>} modules by source type
|
|
98
99
|
*/
|
|
99
100
|
const modulesBySourceType = (sourceTypesByModule) => (set) => {
|
|
100
|
-
/** @type {Map<
|
|
101
|
+
/** @type {Map<SourceType, SortableSet<Module>>} */
|
|
101
102
|
const map = new Map();
|
|
102
103
|
for (const module of set) {
|
|
103
104
|
const sourceTypes =
|
|
@@ -220,7 +221,7 @@ class ChunkGraphModule {
|
|
|
220
221
|
}
|
|
221
222
|
}
|
|
222
223
|
|
|
223
|
-
/** @typedef {WeakMap<Module,
|
|
224
|
+
/** @typedef {WeakMap<Module, SourceTypes>} SourceTypesByModule */
|
|
224
225
|
/** @typedef {Map<Module, Entrypoint>} EntryModules */
|
|
225
226
|
|
|
226
227
|
class ChunkGraphChunk {
|
|
@@ -631,7 +632,7 @@ class ChunkGraph {
|
|
|
631
632
|
/**
|
|
632
633
|
* @param {Chunk} chunk chunk
|
|
633
634
|
* @param {Module} module chunk module
|
|
634
|
-
* @param {
|
|
635
|
+
* @param {SourceTypes} sourceTypes source types
|
|
635
636
|
*/
|
|
636
637
|
setChunkModuleSourceTypes(chunk, module, sourceTypes) {
|
|
637
638
|
const cgc = this._getChunkGraphChunk(chunk);
|
|
@@ -668,10 +669,11 @@ class ChunkGraph {
|
|
|
668
669
|
|
|
669
670
|
/**
|
|
670
671
|
* @param {Module} module module
|
|
671
|
-
* @returns {
|
|
672
|
+
* @returns {SourceTypes | undefined} source types
|
|
672
673
|
*/
|
|
673
674
|
_getOverwrittenModuleSourceTypes(module) {
|
|
674
675
|
let newSet = false;
|
|
676
|
+
/** @type {Set<SourceType> | undefined} */
|
|
675
677
|
let sourceTypes;
|
|
676
678
|
for (const chunk of this.getModuleChunksIterable(module)) {
|
|
677
679
|
const cgc = this._getChunkGraphChunk(chunk);
|
|
@@ -679,7 +681,7 @@ class ChunkGraph {
|
|
|
679
681
|
const st = cgc.sourceTypesByModule.get(module);
|
|
680
682
|
if (st === undefined) return;
|
|
681
683
|
if (!sourceTypes) {
|
|
682
|
-
sourceTypes = st;
|
|
684
|
+
sourceTypes = /** @type {Set<SourceType>} */ (st);
|
|
683
685
|
} else if (!newSet) {
|
|
684
686
|
for (const type of st) {
|
|
685
687
|
if (!newSet) {
|
|
@@ -871,7 +873,7 @@ class ChunkGraph {
|
|
|
871
873
|
/**
|
|
872
874
|
* @param {Chunk} chunkA first chunk
|
|
873
875
|
* @param {Chunk} chunkB second chunk
|
|
874
|
-
* @returns {-1|0|1} this is a comparator function like sort and returns -1, 0, or 1 based on sort order
|
|
876
|
+
* @returns {-1 | 0 | 1} this is a comparator function like sort and returns -1, 0, or 1 based on sort order
|
|
875
877
|
*/
|
|
876
878
|
compareChunks(chunkA, chunkB) {
|
|
877
879
|
const cgcA = this._getChunkGraphChunk(chunkA);
|
package/lib/ChunkGroup.js
CHANGED
|
@@ -45,7 +45,7 @@ const getArray = (set) => [...set];
|
|
|
45
45
|
* A convenience method used to sort chunks based on their id's
|
|
46
46
|
* @param {ChunkGroup} a first sorting comparator
|
|
47
47
|
* @param {ChunkGroup} b second sorting comparator
|
|
48
|
-
* @returns {1|0
|
|
48
|
+
* @returns {1 | 0 | -1} a sorting index to determine order
|
|
49
49
|
*/
|
|
50
50
|
const sortById = (a, b) => {
|
|
51
51
|
if (a.id < b.id) return -1;
|
|
@@ -56,7 +56,7 @@ const sortById = (a, b) => {
|
|
|
56
56
|
/**
|
|
57
57
|
* @param {OriginRecord} a the first comparator in sort
|
|
58
58
|
* @param {OriginRecord} b the second comparator in sort
|
|
59
|
-
* @returns {1
|
|
59
|
+
* @returns {1 | -1| 0} returns sorting order as index
|
|
60
60
|
*/
|
|
61
61
|
const sortOrigin = (a, b) => {
|
|
62
62
|
const aIdent = a.module ? a.module.identifier() : "";
|
|
@@ -91,16 +91,19 @@ class ChunkGroup {
|
|
|
91
91
|
this.chunks = [];
|
|
92
92
|
/** @type {OriginRecord[]} */
|
|
93
93
|
this.origins = [];
|
|
94
|
+
|
|
95
|
+
/** @typedef {Map<Module, number>} OrderIndices */
|
|
96
|
+
|
|
94
97
|
/** Indices in top-down order */
|
|
95
98
|
/**
|
|
96
99
|
* @private
|
|
97
|
-
* @type {
|
|
100
|
+
* @type {OrderIndices}
|
|
98
101
|
*/
|
|
99
102
|
this._modulePreOrderIndices = new Map();
|
|
100
103
|
/** Indices in bottom-up order */
|
|
101
104
|
/**
|
|
102
105
|
* @private
|
|
103
|
-
* @type {
|
|
106
|
+
* @type {OrderIndices}
|
|
104
107
|
*/
|
|
105
108
|
this._modulePostOrderIndices = new Map();
|
|
106
109
|
/** @type {number | undefined} */
|
|
@@ -485,7 +488,7 @@ class ChunkGroup {
|
|
|
485
488
|
* Sorting values are based off of number of chunks in ChunkGroup.
|
|
486
489
|
* @param {ChunkGraph} chunkGraph the chunk graph
|
|
487
490
|
* @param {ChunkGroup} otherGroup the chunkGroup to compare this against
|
|
488
|
-
* @returns {-1|0|1} sort position for comparison
|
|
491
|
+
* @returns {-1 | 0 | 1} sort position for comparison
|
|
489
492
|
*/
|
|
490
493
|
compareTo(chunkGraph, otherGroup) {
|
|
491
494
|
if (this.chunks.length > otherGroup.chunks.length) return -1;
|
package/lib/CleanPlugin.js
CHANGED
|
@@ -63,8 +63,10 @@ const mergeAssets = (as1, as2) => {
|
|
|
63
63
|
}
|
|
64
64
|
};
|
|
65
65
|
|
|
66
|
+
/** @typedef {Map<string, number>} CurrentAssets */
|
|
67
|
+
|
|
66
68
|
/**
|
|
67
|
-
* @param {
|
|
69
|
+
* @param {CurrentAssets} assets current assets
|
|
68
70
|
* @returns {Set<string>} Set of directory paths
|
|
69
71
|
*/
|
|
70
72
|
function getDirectories(assets) {
|
|
@@ -92,12 +94,13 @@ function getDirectories(assets) {
|
|
|
92
94
|
/**
|
|
93
95
|
* @param {OutputFileSystem} fs filesystem
|
|
94
96
|
* @param {string} outputPath output path
|
|
95
|
-
* @param {
|
|
97
|
+
* @param {CurrentAssets} currentAssets filename of the current assets (must not start with .. or ., must only use / as path separator)
|
|
96
98
|
* @param {(err?: Error | null, set?: Diff) => void} callback returns the filenames of the assets that shouldn't be there
|
|
97
99
|
* @returns {void}
|
|
98
100
|
*/
|
|
99
101
|
const getDiffToFs = (fs, outputPath, currentAssets, callback) => {
|
|
100
102
|
const directories = getDirectories(currentAssets);
|
|
103
|
+
/** @type {Diff} */
|
|
101
104
|
const diff = new Set();
|
|
102
105
|
asyncLib.forEachLimit(
|
|
103
106
|
directories,
|
|
@@ -388,7 +391,7 @@ class CleanPlugin {
|
|
|
388
391
|
// We assume that no external modification happens while the compiler is active
|
|
389
392
|
// So we can store the old assets and only diff to them to avoid fs access on
|
|
390
393
|
// incremental builds
|
|
391
|
-
/** @type {undefined|Assets} */
|
|
394
|
+
/** @type {undefined | Assets} */
|
|
392
395
|
let oldAssets;
|
|
393
396
|
|
|
394
397
|
compiler.hooks.emit.tapAsync(
|
|
@@ -13,6 +13,7 @@ const { RuntimeSpecMap, runtimeToString } = require("./util/runtime");
|
|
|
13
13
|
|
|
14
14
|
/** @typedef {import("webpack-sources").Source} Source */
|
|
15
15
|
/** @typedef {import("./Module")} Module */
|
|
16
|
+
/** @typedef {import("./Module").SourceType} SourceType */
|
|
16
17
|
/** @typedef {import("./Module").CodeGenerationResult} CodeGenerationResult */
|
|
17
18
|
/** @typedef {import("./Module").CodeGenerationResultData} CodeGenerationResultData */
|
|
18
19
|
/** @typedef {import("./Module").ReadOnlyRuntimeRequirements} ReadOnlyRuntimeRequirements */
|
|
@@ -96,7 +97,7 @@ Caller might not support runtime-dependent code generation (opt-out via optimiza
|
|
|
96
97
|
/**
|
|
97
98
|
* @param {Module} module the module
|
|
98
99
|
* @param {RuntimeSpec} runtime runtime(s)
|
|
99
|
-
* @param {
|
|
100
|
+
* @param {SourceType} sourceType the source type
|
|
100
101
|
* @returns {Source} a source
|
|
101
102
|
*/
|
|
102
103
|
getSource(module, runtime, sourceType) {
|
package/lib/Compilation.js
CHANGED
|
@@ -84,7 +84,6 @@ const processAsyncTree = require("./util/processAsyncTree");
|
|
|
84
84
|
const { getRuntimeKey } = require("./util/runtime");
|
|
85
85
|
const { isSourceEqual } = require("./util/source");
|
|
86
86
|
|
|
87
|
-
/** @template T @typedef {import("tapable").AsArray<T>} AsArray<T> */
|
|
88
87
|
/** @typedef {import("webpack-sources").Source} Source */
|
|
89
88
|
/** @typedef {import("../declarations/WebpackOptions").OutputNormalized} OutputOptions */
|
|
90
89
|
/** @typedef {import("../declarations/WebpackOptions").HashFunction} HashFunction */
|
|
@@ -135,6 +134,11 @@ const { isSourceEqual } = require("./util/source");
|
|
|
135
134
|
/** @typedef {import("./TemplatedPathPlugin").TemplatePath} TemplatePath */
|
|
136
135
|
/** @typedef {import("./util/Hash")} Hash */
|
|
137
136
|
|
|
137
|
+
/**
|
|
138
|
+
* @template T
|
|
139
|
+
* @typedef {import("tapable").AsArray<T>} AsArray<T>
|
|
140
|
+
*/
|
|
141
|
+
|
|
138
142
|
/**
|
|
139
143
|
* @template T
|
|
140
144
|
* @typedef {import("./util/deprecation").FakeHook<T>} FakeHook<T>
|
|
@@ -200,9 +204,9 @@ const { isSourceEqual } = require("./util/source");
|
|
|
200
204
|
* @property {string | number} id
|
|
201
205
|
* @property {string=} name
|
|
202
206
|
* @property {string} hash
|
|
203
|
-
* @property {
|
|
207
|
+
* @property {HashWithLengthFunction=} hashWithLength
|
|
204
208
|
* @property {(Record<string, string>)=} contentHash
|
|
205
|
-
* @property {(Record<string,
|
|
209
|
+
* @property {(Record<string, HashWithLengthFunction>)=} contentHashWithLength
|
|
206
210
|
*/
|
|
207
211
|
|
|
208
212
|
/**
|
|
@@ -224,17 +228,19 @@ const { isSourceEqual } = require("./util/source");
|
|
|
224
228
|
* @property {EntryOptions=} entryOptions
|
|
225
229
|
*/
|
|
226
230
|
|
|
231
|
+
/** @typedef {LazySet<string>} FileSystemDependencies */
|
|
232
|
+
|
|
227
233
|
/** @typedef {EXPECTED_ANY} ExecuteModuleExports */
|
|
228
234
|
|
|
229
235
|
/**
|
|
230
236
|
* @typedef {object} ExecuteModuleResult
|
|
231
237
|
* @property {ExecuteModuleExports} exports
|
|
232
238
|
* @property {boolean} cacheable
|
|
233
|
-
* @property {
|
|
234
|
-
* @property {
|
|
235
|
-
* @property {
|
|
236
|
-
* @property {
|
|
237
|
-
* @property {
|
|
239
|
+
* @property {ExecuteModuleAssets} assets
|
|
240
|
+
* @property {FileSystemDependencies} fileDependencies
|
|
241
|
+
* @property {FileSystemDependencies} contextDependencies
|
|
242
|
+
* @property {FileSystemDependencies} missingDependencies
|
|
243
|
+
* @property {FileSystemDependencies} buildDependencies
|
|
238
244
|
*/
|
|
239
245
|
|
|
240
246
|
/**
|
|
@@ -261,9 +267,11 @@ const { isSourceEqual } = require("./util/source");
|
|
|
261
267
|
* @property {WebpackRequire} require require function
|
|
262
268
|
*/
|
|
263
269
|
|
|
270
|
+
/** @typedef {Map<string, { source: Source, info: AssetInfo | undefined }>} ExecuteModuleAssets */
|
|
271
|
+
|
|
264
272
|
/**
|
|
265
273
|
* @typedef {object} ExecuteModuleContext
|
|
266
|
-
* @property {
|
|
274
|
+
* @property {ExecuteModuleAssets} assets
|
|
267
275
|
* @property {Chunk} chunk
|
|
268
276
|
* @property {ChunkGraph} chunkGraph
|
|
269
277
|
* @property {WebpackRequire=} __webpack_require__
|
|
@@ -312,18 +320,22 @@ const { isSourceEqual } = require("./util/source");
|
|
|
312
320
|
* @property {AssetInfo} info info about the asset
|
|
313
321
|
*/
|
|
314
322
|
|
|
323
|
+
/** @typedef {(length: number) => string} HashWithLengthFunction */
|
|
324
|
+
|
|
315
325
|
/**
|
|
316
326
|
* @typedef {object} ModulePathData
|
|
317
327
|
* @property {string | number} id
|
|
318
328
|
* @property {string} hash
|
|
319
|
-
* @property {
|
|
329
|
+
* @property {HashWithLengthFunction=} hashWithLength
|
|
320
330
|
*/
|
|
321
331
|
|
|
332
|
+
/** @typedef {(id: string | number) => string | number} PrepareIdFunction */
|
|
333
|
+
|
|
322
334
|
/**
|
|
323
335
|
* @typedef {object} PathData
|
|
324
336
|
* @property {ChunkGraph=} chunkGraph
|
|
325
337
|
* @property {string=} hash
|
|
326
|
-
* @property {
|
|
338
|
+
* @property {HashWithLengthFunction=} hashWithLength
|
|
327
339
|
* @property {(Chunk | ChunkPathData)=} chunk
|
|
328
340
|
* @property {(Module | ModulePathData)=} module
|
|
329
341
|
* @property {RuntimeSpec=} runtime
|
|
@@ -332,9 +344,10 @@ const { isSourceEqual } = require("./util/source");
|
|
|
332
344
|
* @property {string=} query
|
|
333
345
|
* @property {string=} contentHashType
|
|
334
346
|
* @property {string=} contentHash
|
|
335
|
-
* @property {
|
|
347
|
+
* @property {HashWithLengthFunction=} contentHashWithLength
|
|
336
348
|
* @property {boolean=} noChunkHash
|
|
337
349
|
* @property {string=} url
|
|
350
|
+
* @property {PrepareIdFunction=} prepareId
|
|
338
351
|
*/
|
|
339
352
|
|
|
340
353
|
/** @typedef {"module" | "chunk" | "root-of-chunk" | "nested"} ExcludeModulesType */
|
|
@@ -697,8 +710,8 @@ class Compilation {
|
|
|
697
710
|
) => `Can't automatically convert plugin using Compilation.hooks.${name} to Compilation.hooks.processAssets because ${reason}.
|
|
698
711
|
BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a single Compilation.hooks.processAssets hook.`;
|
|
699
712
|
/**
|
|
700
|
-
* @param {string | (import("tapable").TapOptions & { name: string
|
|
701
|
-
* @returns {import("tapable").TapOptions & { name: string
|
|
713
|
+
* @param {string | (import("tapable").TapOptions & { name: string } & ProcessAssetsAdditionalOptions)} options hook options
|
|
714
|
+
* @returns {import("tapable").TapOptions & { name: string } & ProcessAssetsAdditionalOptions} modified options
|
|
702
715
|
*/
|
|
703
716
|
const getOptions = (options) => {
|
|
704
717
|
if (typeof options === "string") options = { name: options };
|
|
@@ -1218,20 +1231,20 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
|
|
|
1218
1231
|
this.emittedAssets = new Set();
|
|
1219
1232
|
/** @type {Set<string>} */
|
|
1220
1233
|
this.comparedForEmitAssets = new Set();
|
|
1221
|
-
/** @type {
|
|
1234
|
+
/** @type {FileSystemDependencies} */
|
|
1222
1235
|
this.fileDependencies = new LazySet();
|
|
1223
|
-
/** @type {
|
|
1236
|
+
/** @type {FileSystemDependencies} */
|
|
1224
1237
|
this.contextDependencies = new LazySet();
|
|
1225
|
-
/** @type {
|
|
1238
|
+
/** @type {FileSystemDependencies} */
|
|
1226
1239
|
this.missingDependencies = new LazySet();
|
|
1227
|
-
/** @type {
|
|
1240
|
+
/** @type {FileSystemDependencies} */
|
|
1228
1241
|
this.buildDependencies = new LazySet();
|
|
1229
1242
|
// TODO webpack 6 remove
|
|
1230
1243
|
this.compilationDependencies = {
|
|
1231
1244
|
add: util.deprecate(
|
|
1232
1245
|
/**
|
|
1233
1246
|
* @param {string} item item
|
|
1234
|
-
* @returns {
|
|
1247
|
+
* @returns {FileSystemDependencies} file dependencies
|
|
1235
1248
|
*/
|
|
1236
1249
|
(item) => this.fileDependencies.add(item),
|
|
1237
1250
|
"Compilation.compilationDependencies is deprecated (used Compilation.fileDependencies instead)",
|
|
@@ -3744,6 +3757,7 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
|
|
|
3744
3757
|
dependencyTemplates,
|
|
3745
3758
|
runtimeTemplate,
|
|
3746
3759
|
runtime,
|
|
3760
|
+
runtimes,
|
|
3747
3761
|
codeGenerationResults: results,
|
|
3748
3762
|
compilation: this
|
|
3749
3763
|
});
|
package/lib/Compiler.js
CHANGED
|
@@ -719,9 +719,9 @@ class Compiler {
|
|
|
719
719
|
({ name: file, source, info }, callback) => {
|
|
720
720
|
let targetFile = file;
|
|
721
721
|
let immutable = info.immutable;
|
|
722
|
-
const
|
|
723
|
-
if (
|
|
724
|
-
targetFile = targetFile.slice(0,
|
|
722
|
+
const queryOrHashStringIdx = targetFile.search(/[?#]/);
|
|
723
|
+
if (queryOrHashStringIdx >= 0) {
|
|
724
|
+
targetFile = targetFile.slice(0, queryOrHashStringIdx);
|
|
725
725
|
// We may remove the hash, which is in the query string
|
|
726
726
|
// So we recheck if the file is immutable
|
|
727
727
|
// This doesn't cover all cases, but immutable is only a performance optimization anyway
|
package/lib/ContextModule.js
CHANGED
|
@@ -9,7 +9,10 @@ const { OriginalSource, RawSource } = require("webpack-sources");
|
|
|
9
9
|
const AsyncDependenciesBlock = require("./AsyncDependenciesBlock");
|
|
10
10
|
const { makeWebpackError } = require("./HookWebpackError");
|
|
11
11
|
const Module = require("./Module");
|
|
12
|
-
const {
|
|
12
|
+
const {
|
|
13
|
+
JAVASCRIPT_TYPE,
|
|
14
|
+
JAVASCRIPT_TYPES
|
|
15
|
+
} = require("./ModuleSourceTypeConstants");
|
|
13
16
|
const { JAVASCRIPT_MODULE_TYPE_DYNAMIC } = require("./ModuleTypeConstants");
|
|
14
17
|
const RuntimeGlobals = require("./RuntimeGlobals");
|
|
15
18
|
const Template = require("./Template");
|
|
@@ -162,7 +165,7 @@ class ContextModule extends Module {
|
|
|
162
165
|
* @returns {SourceTypes} types available (do not mutate)
|
|
163
166
|
*/
|
|
164
167
|
getSourceTypes() {
|
|
165
|
-
return
|
|
168
|
+
return JAVASCRIPT_TYPES;
|
|
166
169
|
}
|
|
167
170
|
|
|
168
171
|
/**
|
|
@@ -1184,7 +1187,7 @@ module.exports = webpackEmptyAsyncContext;`;
|
|
|
1184
1187
|
const { chunkGraph, compilation } = context;
|
|
1185
1188
|
const sources = new Map();
|
|
1186
1189
|
sources.set(
|
|
1187
|
-
|
|
1190
|
+
JAVASCRIPT_TYPE,
|
|
1188
1191
|
this.getSource(
|
|
1189
1192
|
this.getSourceString(this.options.mode, context),
|
|
1190
1193
|
compilation
|