webpack 5.102.1 → 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/README.md +121 -134
- 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 +28 -2
- package/lib/Compilation.js +58 -21
- package/lib/Compiler.js +3 -3
- package/lib/ConcatenationScope.js +0 -15
- package/lib/ContextModule.js +6 -3
- package/lib/ContextModuleFactory.js +6 -4
- package/lib/CssModule.js +6 -1
- package/lib/DefinePlugin.js +45 -14
- package/lib/DelegatedModule.js +7 -4
- package/lib/Dependency.js +8 -1
- package/lib/DependencyTemplate.js +1 -0
- package/lib/DllModule.js +6 -3
- package/lib/DotenvPlugin.js +462 -0
- package/lib/EnvironmentPlugin.js +19 -16
- package/lib/EvalSourceMapDevToolPlugin.js +16 -0
- package/lib/ExportsInfo.js +6 -2
- package/lib/ExternalModule.js +28 -35
- package/lib/ExternalModuleFactoryPlugin.js +11 -9
- package/lib/ExternalsPlugin.js +2 -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 +235 -0
- package/lib/Module.js +27 -15
- package/lib/ModuleBuildError.js +1 -1
- package/lib/ModuleError.js +1 -1
- package/lib/ModuleFilenameHelpers.js +1 -1
- package/lib/ModuleGraph.js +29 -13
- 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/MultiCompiler.js +1 -1
- package/lib/NodeStuffPlugin.js +424 -116
- package/lib/NormalModule.js +23 -20
- package/lib/NormalModuleFactory.js +7 -10
- package/lib/Parser.js +1 -1
- package/lib/RawModule.js +7 -4
- package/lib/RuntimeGlobals.js +22 -4
- package/lib/RuntimeModule.js +1 -1
- package/lib/RuntimePlugin.js +27 -6
- package/lib/RuntimeTemplate.js +120 -57
- package/lib/SourceMapDevToolPlugin.js +26 -1
- package/lib/Template.js +17 -6
- package/lib/TemplatedPathPlugin.js +5 -6
- package/lib/WebpackError.js +0 -1
- package/lib/WebpackOptionsApply.js +67 -15
- package/lib/asset/AssetBytesGenerator.js +16 -12
- package/lib/asset/AssetGenerator.js +31 -26
- package/lib/asset/AssetSourceGenerator.js +16 -12
- 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 +24 -0
- package/lib/config/defaults.js +226 -61
- package/lib/config/normalization.js +4 -3
- package/lib/config/target.js +11 -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 +304 -76
- package/lib/css/CssLoadingRuntimeModule.js +14 -4
- package/lib/css/CssMergeStyleSheetsRuntimeModule.js +56 -0
- package/lib/css/CssModulesPlugin.js +72 -67
- package/lib/css/CssParser.js +1726 -732
- package/lib/css/walkCssTokens.js +128 -11
- package/lib/dependencies/CachedConstDependency.js +24 -10
- package/lib/dependencies/CommonJsImportsParserPlugin.js +0 -9
- package/lib/dependencies/CommonJsPlugin.js +12 -0
- 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 +389 -12
- package/lib/dependencies/CssIcssImportDependency.js +114 -51
- package/lib/dependencies/CssIcssSymbolDependency.js +31 -33
- package/lib/dependencies/CssImportDependency.js +17 -6
- 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 +3 -2
- package/lib/dependencies/ExternalModuleInitFragmentDependency.js +96 -0
- package/lib/dependencies/HarmonyAcceptDependency.js +6 -1
- package/lib/dependencies/HarmonyAcceptImportDependency.js +2 -1
- package/lib/dependencies/HarmonyEvaluatedImportSpecifierDependency.js +12 -1
- package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +35 -23
- package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +13 -9
- package/lib/dependencies/HarmonyExports.js +4 -4
- package/lib/dependencies/HarmonyImportDependency.js +28 -27
- package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +28 -69
- package/lib/dependencies/HarmonyImportSideEffectDependency.js +4 -3
- package/lib/dependencies/HarmonyImportSpecifierDependency.js +10 -8
- package/lib/dependencies/ImportDependency.js +8 -2
- package/lib/dependencies/ImportEagerDependency.js +6 -3
- package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +1 -1
- package/lib/dependencies/ImportMetaPlugin.js +154 -9
- package/lib/dependencies/ImportParserPlugin.js +21 -23
- package/lib/dependencies/ImportPhase.js +121 -0
- package/lib/dependencies/ImportWeakDependency.js +6 -3
- package/lib/dependencies/LocalModulesHelpers.js +3 -3
- package/lib/dependencies/ModuleDependency.js +5 -1
- package/lib/dependencies/ModuleHotAcceptDependency.js +1 -1
- package/lib/dependencies/WorkerPlugin.js +2 -2
- package/lib/dependencies/getFunctionExpression.js +1 -1
- package/lib/esm/ExportWebpackRequireRuntimeModule.js +1 -8
- package/lib/esm/ModuleChunkFormatPlugin.js +5 -4
- package/lib/hmr/HotModuleReplacement.runtime.js +2 -1
- package/lib/hmr/LazyCompilationPlugin.js +5 -3
- package/lib/ids/IdHelpers.js +20 -8
- package/lib/index.js +6 -0
- package/lib/javascript/ChunkHelpers.js +16 -5
- package/lib/javascript/JavascriptGenerator.js +105 -104
- package/lib/javascript/JavascriptModulesPlugin.js +80 -37
- package/lib/javascript/JavascriptParser.js +161 -44
- package/lib/json/JsonGenerator.js +5 -4
- package/lib/json/JsonParser.js +9 -2
- 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 -23
- package/lib/library/SystemLibraryPlugin.js +8 -1
- package/lib/library/UmdLibraryPlugin.js +2 -2
- package/lib/logging/Logger.js +5 -4
- package/lib/logging/createConsoleLogger.js +2 -2
- package/lib/node/NodeTargetPlugin.js +9 -1
- package/lib/node/ReadFileCompileWasmPlugin.js +0 -2
- package/lib/optimize/ConcatenatedModule.js +208 -167
- 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/AsyncModuleRuntimeModule.js +28 -18
- package/lib/runtime/AutoPublicPathRuntimeModule.js +8 -3
- package/lib/runtime/GetChunkFilenameRuntimeModule.js +3 -2
- package/lib/runtime/MakeDeferredNamespaceObjectRuntime.js +89 -55
- 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 +54 -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/EnableWasmLoadingPlugin.js +10 -4
- package/lib/wasm-async/AsyncWebAssemblyGenerator.js +3 -2
- package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +11 -7
- package/lib/wasm-sync/WebAssemblyGenerator.js +9 -6
- package/lib/wasm-sync/WebAssemblyJavascriptGenerator.js +11 -6
- package/lib/wasm-sync/WebAssemblyModulesPlugin.js +6 -2
- package/lib/web/FetchCompileWasmPlugin.js +0 -2
- package/lib/webpack.js +85 -82
- package/module.d.ts +5 -0
- package/package.json +34 -28
- package/schemas/WebpackOptions.check.js +1 -1
- package/schemas/WebpackOptions.json +160 -101
- package/schemas/plugins/{css/CssAutoParserOptions.check.d.ts → ManifestPlugin.check.d.ts} +1 -1
- package/schemas/plugins/ManifestPlugin.check.js +6 -0
- package/schemas/plugins/ManifestPlugin.json +98 -0
- package/schemas/plugins/SourceMapDevToolPlugin.check.js +1 -1
- package/schemas/plugins/SourceMapDevToolPlugin.json +16 -3
- package/schemas/plugins/container/ContainerReferencePlugin.check.js +1 -1
- package/schemas/plugins/container/ContainerReferencePlugin.json +4 -1
- package/schemas/plugins/container/ExternalsType.check.js +1 -1
- package/schemas/plugins/container/ModuleFederationPlugin.check.js +1 -1
- package/schemas/plugins/container/ModuleFederationPlugin.json +4 -1
- package/schemas/plugins/css/CssModuleGeneratorOptions.check.js +1 -1
- package/schemas/plugins/css/CssModuleParserOptions.check.js +1 -1
- package/schemas/plugins/css/CssParserOptions.check.js +1 -1
- package/schemas/plugins/json/JsonModulesPluginParser.check.js +1 -1
- package/types.d.ts +771 -436
- package/lib/ModuleSourceTypesConstants.js +0 -123
- package/lib/dependencies/CssLocalIdentifierDependency.js +0 -250
- package/lib/dependencies/CssSelfLocalIdentifierDependency.js +0 -112
- 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.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
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
/*
|
|
2
|
+
MIT License http://www.opensource.org/licenses/mit-license.php
|
|
3
|
+
Author Haijie Xie @hai-x
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
"use strict";
|
|
7
|
+
|
|
8
|
+
const { RawSource } = require("webpack-sources");
|
|
9
|
+
const Compilation = require("./Compilation");
|
|
10
|
+
const HotUpdateChunk = require("./HotUpdateChunk");
|
|
11
|
+
const createSchemaValidation = require("./util/create-schema-validation");
|
|
12
|
+
|
|
13
|
+
/** @typedef {import("./Compiler")} Compiler */
|
|
14
|
+
/** @typedef {import("./Chunk")} Chunk */
|
|
15
|
+
/** @typedef {import("./Chunk").ChunkName} ChunkName */
|
|
16
|
+
/** @typedef {import("./Chunk").ChunkId} ChunkId */
|
|
17
|
+
/** @typedef {import("./Compilation").Asset} Asset */
|
|
18
|
+
/** @typedef {import("./Compilation").AssetInfo} AssetInfo */
|
|
19
|
+
|
|
20
|
+
/** @typedef {import("../declarations/plugins/ManifestPlugin").ManifestPluginOptions} ManifestPluginOptions */
|
|
21
|
+
/** @typedef {import("../declarations/plugins/ManifestPlugin").ManifestObject} ManifestObject */
|
|
22
|
+
/** @typedef {import("../declarations/plugins/ManifestPlugin").ManifestEntrypoint} ManifestEntrypoint */
|
|
23
|
+
/** @typedef {import("../declarations/plugins/ManifestPlugin").ManifestItem} ManifestItem */
|
|
24
|
+
|
|
25
|
+
const PLUGIN_NAME = "ManifestPlugin";
|
|
26
|
+
|
|
27
|
+
const validate = createSchemaValidation(
|
|
28
|
+
require("../schemas/plugins/ManifestPlugin.check"),
|
|
29
|
+
() => require("../schemas/plugins/ManifestPlugin.json"),
|
|
30
|
+
{
|
|
31
|
+
name: "ManifestPlugin",
|
|
32
|
+
baseDataPath: "options"
|
|
33
|
+
}
|
|
34
|
+
);
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* @param {string} filename filename
|
|
38
|
+
* @returns {string} extname
|
|
39
|
+
*/
|
|
40
|
+
const extname = (filename) => {
|
|
41
|
+
const replaced = filename.replace(/\?.*/, "");
|
|
42
|
+
const split = replaced.split(".");
|
|
43
|
+
const last = split.pop();
|
|
44
|
+
if (!last) return "";
|
|
45
|
+
return last && /^(gz|br|map)$/i.test(last) ? `${split.pop()}.${last}` : last;
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
class ManifestPlugin {
|
|
49
|
+
/**
|
|
50
|
+
* @param {ManifestPluginOptions} options options
|
|
51
|
+
*/
|
|
52
|
+
constructor(options) {
|
|
53
|
+
validate(options);
|
|
54
|
+
|
|
55
|
+
/** @type {ManifestPluginOptions & Required<Omit<ManifestPluginOptions, "filter" | "generate">>} */
|
|
56
|
+
this.options = {
|
|
57
|
+
filename: "manifest.json",
|
|
58
|
+
prefix: "[publicpath]",
|
|
59
|
+
entrypoints: true,
|
|
60
|
+
serialize: (manifest) => JSON.stringify(manifest, null, 2),
|
|
61
|
+
...options
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Apply the plugin
|
|
67
|
+
* @param {Compiler} compiler the compiler instance
|
|
68
|
+
* @returns {void}
|
|
69
|
+
*/
|
|
70
|
+
apply(compiler) {
|
|
71
|
+
compiler.hooks.thisCompilation.tap(PLUGIN_NAME, (compilation) => {
|
|
72
|
+
compilation.hooks.processAssets.tap(
|
|
73
|
+
{
|
|
74
|
+
name: PLUGIN_NAME,
|
|
75
|
+
stage: Compilation.PROCESS_ASSETS_STAGE_SUMMARIZE
|
|
76
|
+
},
|
|
77
|
+
() => {
|
|
78
|
+
const hashDigestLength = compilation.outputOptions.hashDigestLength;
|
|
79
|
+
const publicPath = compilation.getPath(
|
|
80
|
+
compilation.outputOptions.publicPath
|
|
81
|
+
);
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* @param {string | string[]} value value
|
|
85
|
+
* @returns {RegExp} regexp to remove hash
|
|
86
|
+
*/
|
|
87
|
+
const createHashRegExp = (value) =>
|
|
88
|
+
new RegExp(
|
|
89
|
+
`(?:\\.${Array.isArray(value) ? `(${value.join("|")})` : value})(?=\\.)`,
|
|
90
|
+
"gi"
|
|
91
|
+
);
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* @param {string} name name
|
|
95
|
+
* @param {AssetInfo | null} info asset info
|
|
96
|
+
* @returns {string} hash removed name
|
|
97
|
+
*/
|
|
98
|
+
const removeHash = (name, info) => {
|
|
99
|
+
// Handles hashes that match configured `hashDigestLength`
|
|
100
|
+
// i.e. index.XXXX.html -> index.html (html-webpack-plugin)
|
|
101
|
+
if (hashDigestLength <= 0) return name;
|
|
102
|
+
const reg = createHashRegExp(`[a-f0-9]{${hashDigestLength},32}`);
|
|
103
|
+
return name.replace(reg, "");
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* @param {Chunk} chunk chunk
|
|
108
|
+
* @returns {ChunkName | ChunkId} chunk name or chunk id
|
|
109
|
+
*/
|
|
110
|
+
const getName = (chunk) => {
|
|
111
|
+
if (chunk.name) return chunk.name;
|
|
112
|
+
|
|
113
|
+
return chunk.id;
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
/** @type {ManifestObject} */
|
|
117
|
+
let manifest = {};
|
|
118
|
+
|
|
119
|
+
if (this.options.entrypoints) {
|
|
120
|
+
/** @type {ManifestObject["entrypoints"]} */
|
|
121
|
+
const entrypoints = {};
|
|
122
|
+
|
|
123
|
+
for (const [name, entrypoint] of compilation.entrypoints) {
|
|
124
|
+
const imports = [];
|
|
125
|
+
|
|
126
|
+
for (const chunk of entrypoint.chunks) {
|
|
127
|
+
for (const file of chunk.files) {
|
|
128
|
+
const name = getName(chunk);
|
|
129
|
+
|
|
130
|
+
imports.push(name ? `${name}.${extname(file)}` : file);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/** @type {ManifestEntrypoint} */
|
|
135
|
+
const item = { imports };
|
|
136
|
+
const parents = entrypoint
|
|
137
|
+
.getParents()
|
|
138
|
+
.map((item) => /** @type {string} */ (item.name));
|
|
139
|
+
|
|
140
|
+
if (parents.length > 0) {
|
|
141
|
+
item.parents = parents;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
entrypoints[name] = item;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
manifest.entrypoints = entrypoints;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/** @type {ManifestObject["assets"]} */
|
|
151
|
+
const assets = {};
|
|
152
|
+
|
|
153
|
+
/** @type {Set<string>} */
|
|
154
|
+
const added = new Set();
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* @param {string} file file
|
|
158
|
+
* @param {string=} usedName usedName
|
|
159
|
+
* @returns {void}
|
|
160
|
+
*/
|
|
161
|
+
const handleFile = (file, usedName) => {
|
|
162
|
+
if (added.has(file)) return;
|
|
163
|
+
added.add(file);
|
|
164
|
+
|
|
165
|
+
const asset = compilation.getAsset(file);
|
|
166
|
+
if (!asset) return;
|
|
167
|
+
const sourceFilename = asset.info.sourceFilename;
|
|
168
|
+
const name =
|
|
169
|
+
usedName ||
|
|
170
|
+
sourceFilename ||
|
|
171
|
+
// Fallback for unofficial plugins, just remove hash from filename
|
|
172
|
+
removeHash(file, asset.info);
|
|
173
|
+
|
|
174
|
+
const prefix = this.options.prefix.replace(
|
|
175
|
+
/\[publicpath\]/gi,
|
|
176
|
+
() => (publicPath === "auto" ? "/" : publicPath)
|
|
177
|
+
);
|
|
178
|
+
/** @type {ManifestItem} */
|
|
179
|
+
const item = { file: prefix + file };
|
|
180
|
+
|
|
181
|
+
if (sourceFilename) {
|
|
182
|
+
item.src = sourceFilename;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
if (this.options.filter) {
|
|
186
|
+
const needKeep = this.options.filter(item);
|
|
187
|
+
|
|
188
|
+
if (!needKeep) {
|
|
189
|
+
return;
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
assets[name] = item;
|
|
194
|
+
};
|
|
195
|
+
|
|
196
|
+
for (const chunk of compilation.chunks) {
|
|
197
|
+
if (chunk instanceof HotUpdateChunk) continue;
|
|
198
|
+
|
|
199
|
+
for (const auxiliaryFile of chunk.auxiliaryFiles) {
|
|
200
|
+
handleFile(auxiliaryFile);
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
const name = getName(chunk);
|
|
204
|
+
|
|
205
|
+
for (const file of chunk.files) {
|
|
206
|
+
handleFile(file, name ? `${name}.${extname(file)}` : file);
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
for (const asset of compilation.getAssets()) {
|
|
211
|
+
if (asset.info.hotModuleReplacement) {
|
|
212
|
+
continue;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
handleFile(asset.name);
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
manifest.assets = assets;
|
|
219
|
+
|
|
220
|
+
if (this.options.generate) {
|
|
221
|
+
manifest = this.options.generate(manifest);
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
compilation.emitAsset(
|
|
225
|
+
this.options.filename,
|
|
226
|
+
new RawSource(this.options.serialize(manifest)),
|
|
227
|
+
{ manifest: true }
|
|
228
|
+
);
|
|
229
|
+
}
|
|
230
|
+
);
|
|
231
|
+
});
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
module.exports = ManifestPlugin;
|
package/lib/Module.js
CHANGED
|
@@ -9,7 +9,11 @@ const util = require("util");
|
|
|
9
9
|
const ChunkGraph = require("./ChunkGraph");
|
|
10
10
|
const DependenciesBlock = require("./DependenciesBlock");
|
|
11
11
|
const ModuleGraph = require("./ModuleGraph");
|
|
12
|
-
const {
|
|
12
|
+
const {
|
|
13
|
+
JAVASCRIPT_TYPE,
|
|
14
|
+
UNKNOWN_TYPE
|
|
15
|
+
} = require("./ModuleSourceTypeConstants");
|
|
16
|
+
const { JAVASCRIPT_TYPES } = require("./ModuleSourceTypeConstants");
|
|
13
17
|
const RuntimeGlobals = require("./RuntimeGlobals");
|
|
14
18
|
const { first } = require("./util/SetHelpers");
|
|
15
19
|
const { compareChunksById } = require("./util/comparators");
|
|
@@ -24,12 +28,14 @@ const makeSerializable = require("./util/makeSerializable");
|
|
|
24
28
|
/** @typedef {import("./CodeGenerationResults")} CodeGenerationResults */
|
|
25
29
|
/** @typedef {import("./Compilation")} Compilation */
|
|
26
30
|
/** @typedef {import("./Compilation").AssetInfo} AssetInfo */
|
|
31
|
+
/** @typedef {import("./Compilation").FileSystemDependencies} FileSystemDependencies */
|
|
27
32
|
/** @typedef {import("./Compilation").UnsafeCacheData} UnsafeCacheData */
|
|
28
33
|
/** @typedef {import("./ConcatenationScope")} ConcatenationScope */
|
|
29
34
|
/** @typedef {import("./Dependency")} Dependency */
|
|
30
35
|
/** @typedef {import("./Dependency").UpdateHashContext} UpdateHashContext */
|
|
31
36
|
/** @typedef {import("./DependencyTemplate").CssData} CssData */
|
|
32
37
|
/** @typedef {import("./DependencyTemplates")} DependencyTemplates */
|
|
38
|
+
/** @typedef {import("./ModuleSourceTypeConstants").AllTypes} AllTypes */
|
|
33
39
|
/** @typedef {import("./FileSystemInfo")} FileSystemInfo */
|
|
34
40
|
/** @typedef {import("./FileSystemInfo").Snapshot} Snapshot */
|
|
35
41
|
/** @typedef {import("./ModuleGraphConnection").ConnectionState} ConnectionState */
|
|
@@ -39,6 +45,8 @@ const makeSerializable = require("./util/makeSerializable");
|
|
|
39
45
|
/** @typedef {import("./RequestShortener")} RequestShortener */
|
|
40
46
|
/** @typedef {import("./ResolverFactory").ResolverWithOptions} ResolverWithOptions */
|
|
41
47
|
/** @typedef {import("./RuntimeTemplate")} RuntimeTemplate */
|
|
48
|
+
/** @typedef {import("../declarations/WebpackOptions").CssParserExportType} CssParserExportType */
|
|
49
|
+
|
|
42
50
|
/**
|
|
43
51
|
* @template T
|
|
44
52
|
* @typedef {import("./InitFragment")<T>} InitFragment
|
|
@@ -68,7 +76,9 @@ const makeSerializable = require("./util/makeSerializable");
|
|
|
68
76
|
* @property {string=} type the type of source that should be generated
|
|
69
77
|
*/
|
|
70
78
|
|
|
71
|
-
/** @typedef {
|
|
79
|
+
/** @typedef {AllTypes} KnownSourceType */
|
|
80
|
+
/** @typedef {KnownSourceType | string} SourceType */
|
|
81
|
+
/** @typedef {ReadonlySet<SourceType>} SourceTypes */
|
|
72
82
|
|
|
73
83
|
// TODO webpack 6: compilation will be required in CodeGenerationContext
|
|
74
84
|
/**
|
|
@@ -78,6 +88,7 @@ const makeSerializable = require("./util/makeSerializable");
|
|
|
78
88
|
* @property {ModuleGraph} moduleGraph the module graph
|
|
79
89
|
* @property {ChunkGraph} chunkGraph the chunk graph
|
|
80
90
|
* @property {RuntimeSpec} runtime the runtimes code should be generated for
|
|
91
|
+
* @property {RuntimeSpec[]} runtimes all runtimes code should be generated for
|
|
81
92
|
* @property {ConcatenationScope=} concatenationScope when in concatenated module, information about other concatenated modules
|
|
82
93
|
* @property {CodeGenerationResults | undefined} codeGenerationResults code generation results of other modules (need to have a codeGenerationDependency to use that)
|
|
83
94
|
* @property {Compilation=} compilation the compilation
|
|
@@ -101,7 +112,7 @@ const makeSerializable = require("./util/makeSerializable");
|
|
|
101
112
|
|
|
102
113
|
/**
|
|
103
114
|
* @typedef {object} CodeGenerationResult
|
|
104
|
-
* @property {Map<
|
|
115
|
+
* @property {Map<SourceType, Source>} sources the resulting sources for all source types
|
|
105
116
|
* @property {CodeGenerationResultData=} data the resulting data for all source types
|
|
106
117
|
* @property {ReadOnlyRuntimeRequirements | null} runtimeRequirements the runtime requirements
|
|
107
118
|
* @property {string=} hash a hash of the code generation result (will be automatically calculated from sources and runtimeRequirements if not provided)
|
|
@@ -116,6 +127,7 @@ const makeSerializable = require("./util/makeSerializable");
|
|
|
116
127
|
/**
|
|
117
128
|
* @typedef {object} KnownBuildMeta
|
|
118
129
|
* @property {("default" | "namespace" | "flagged" | "dynamic")=} exportsType
|
|
130
|
+
* @property {CssParserExportType=} exportType
|
|
119
131
|
* @property {(false | "redirect" | "redirect-warn")=} defaultObject
|
|
120
132
|
* @property {boolean=} strictHarmonyModule
|
|
121
133
|
* @property {boolean=} treatAsCommonJs
|
|
@@ -123,12 +135,10 @@ const makeSerializable = require("./util/makeSerializable");
|
|
|
123
135
|
* @property {boolean=} sideEffectFree
|
|
124
136
|
* @property {boolean=} isCSSModule
|
|
125
137
|
* @property {Record<string, string>=} jsIncompatibleExports
|
|
126
|
-
* @property {Record<string, string
|
|
127
|
-
* @property {string
|
|
138
|
+
* @property {Map<RuntimeSpec, Record<string, string>>=} exportsFinalNameByRuntime
|
|
139
|
+
* @property {Map<RuntimeSpec, string>=} exportsSourceByRuntime
|
|
128
140
|
*/
|
|
129
141
|
|
|
130
|
-
/** @typedef {LazySet<string>} FileSystemDependencies */
|
|
131
|
-
|
|
132
142
|
/**
|
|
133
143
|
* @typedef {object} KnownBuildInfo
|
|
134
144
|
* @property {boolean=} cacheable
|
|
@@ -185,7 +195,8 @@ const EMPTY_RESOLVE_OPTIONS = {};
|
|
|
185
195
|
|
|
186
196
|
let debugId = 1000;
|
|
187
197
|
|
|
188
|
-
|
|
198
|
+
/** @type {SourceTypes} */
|
|
199
|
+
const DEFAULT_TYPES_UNKNOWN = new Set([UNKNOWN_TYPE]);
|
|
189
200
|
|
|
190
201
|
const deprecatedNeedRebuild = util.deprecate(
|
|
191
202
|
/**
|
|
@@ -836,8 +847,8 @@ class Module extends DependenciesBlock {
|
|
|
836
847
|
|
|
837
848
|
/**
|
|
838
849
|
* @deprecated Use needBuild instead
|
|
839
|
-
* @param {Map<string, number|null>} fileTimestamps timestamps of files
|
|
840
|
-
* @param {Map<string, number|null>} contextTimestamps timestamps of directories
|
|
850
|
+
* @param {Map<string, number | null>} fileTimestamps timestamps of files
|
|
851
|
+
* @param {Map<string, number | null>} contextTimestamps timestamps of directories
|
|
841
852
|
* @returns {boolean} true, if the module needs a rebuild
|
|
842
853
|
*/
|
|
843
854
|
needRebuild(fileTimestamps, contextTimestamps) {
|
|
@@ -925,7 +936,7 @@ class Module extends DependenciesBlock {
|
|
|
925
936
|
if (this.source === Module.prototype.source) {
|
|
926
937
|
return DEFAULT_TYPES_UNKNOWN;
|
|
927
938
|
}
|
|
928
|
-
return
|
|
939
|
+
return JAVASCRIPT_TYPES;
|
|
929
940
|
}
|
|
930
941
|
|
|
931
942
|
/**
|
|
@@ -933,10 +944,10 @@ class Module extends DependenciesBlock {
|
|
|
933
944
|
* @deprecated Use codeGeneration() instead
|
|
934
945
|
* @param {DependencyTemplates} dependencyTemplates the dependency templates
|
|
935
946
|
* @param {RuntimeTemplate} runtimeTemplate the runtime template
|
|
936
|
-
* @param {
|
|
947
|
+
* @param {SourceType=} type the type of source that should be generated
|
|
937
948
|
* @returns {Source} generated source
|
|
938
949
|
*/
|
|
939
|
-
source(dependencyTemplates, runtimeTemplate, type =
|
|
950
|
+
source(dependencyTemplates, runtimeTemplate, type = JAVASCRIPT_TYPE) {
|
|
940
951
|
if (this.codeGeneration === Module.prototype.codeGeneration) {
|
|
941
952
|
const AbstractMethodError = require("./AbstractMethodError");
|
|
942
953
|
|
|
@@ -954,6 +965,7 @@ class Module extends DependenciesBlock {
|
|
|
954
965
|
moduleGraph: chunkGraph.moduleGraph,
|
|
955
966
|
chunkGraph,
|
|
956
967
|
runtime: undefined,
|
|
968
|
+
runtimes: [],
|
|
957
969
|
codeGenerationResults: undefined
|
|
958
970
|
};
|
|
959
971
|
const sources = this.codeGeneration(codeGenContext).sources;
|
|
@@ -961,7 +973,7 @@ class Module extends DependenciesBlock {
|
|
|
961
973
|
return /** @type {Source} */ (
|
|
962
974
|
type
|
|
963
975
|
? sources.get(type)
|
|
964
|
-
: sources.get(/** @type {
|
|
976
|
+
: sources.get(/** @type {SourceType} */ (first(this.getSourceTypes())))
|
|
965
977
|
);
|
|
966
978
|
}
|
|
967
979
|
|
|
@@ -1016,7 +1028,7 @@ class Module extends DependenciesBlock {
|
|
|
1016
1028
|
// Best override this method
|
|
1017
1029
|
const sources = new Map();
|
|
1018
1030
|
for (const type of this.getSourceTypes()) {
|
|
1019
|
-
if (type !==
|
|
1031
|
+
if (type !== UNKNOWN_TYPE) {
|
|
1020
1032
|
sources.set(
|
|
1021
1033
|
type,
|
|
1022
1034
|
this.source(
|
package/lib/ModuleBuildError.js
CHANGED
|
@@ -17,7 +17,7 @@ const makeSerializable = require("./util/makeSerializable");
|
|
|
17
17
|
class ModuleBuildError extends WebpackError {
|
|
18
18
|
/**
|
|
19
19
|
* @param {string | ErrorWithHideStack} err error thrown
|
|
20
|
-
* @param {{from?: string|null}} info additional info
|
|
20
|
+
* @param {{from?: string | null}} info additional info
|
|
21
21
|
*/
|
|
22
22
|
constructor(err, { from = null } = {}) {
|
|
23
23
|
let message = "Module build failed";
|
package/lib/ModuleError.js
CHANGED
|
@@ -15,7 +15,7 @@ const makeSerializable = require("./util/makeSerializable");
|
|
|
15
15
|
class ModuleError extends WebpackError {
|
|
16
16
|
/**
|
|
17
17
|
* @param {Error} err error thrown
|
|
18
|
-
* @param {{from?: string|null}} info additional info
|
|
18
|
+
* @param {{from?: string | null}} info additional info
|
|
19
19
|
*/
|
|
20
20
|
constructor(err, { from = null } = {}) {
|
|
21
21
|
let message = "Module Error";
|
|
@@ -281,7 +281,7 @@ ModuleFilenameHelpers.createFilename = (
|
|
|
281
281
|
* @template T
|
|
282
282
|
* @param {T[]} array the array with duplicates to be replaced
|
|
283
283
|
* @param {(duplicateItem: T, duplicateItemIndex: number, numberOfTimesReplaced: number) => T} fn callback function to generate new values for the duplicate items
|
|
284
|
-
* @param {(firstElement:T, nextElement:T) => -1 | 0 | 1=} comparator optional comparator function to sort the duplicate items
|
|
284
|
+
* @param {(firstElement: T, nextElement: T) => -1 | 0 | 1=} comparator optional comparator function to sort the duplicate items
|
|
285
285
|
* @returns {T[]} the array with duplicates replaced
|
|
286
286
|
* @example
|
|
287
287
|
* ```js
|
package/lib/ModuleGraph.js
CHANGED
|
@@ -9,6 +9,7 @@ const util = require("util");
|
|
|
9
9
|
const ExportsInfo = require("./ExportsInfo");
|
|
10
10
|
const ModuleGraphConnection = require("./ModuleGraphConnection");
|
|
11
11
|
const HarmonyImportDependency = require("./dependencies/HarmonyImportDependency");
|
|
12
|
+
const { ImportPhaseUtils } = require("./dependencies/ImportPhase");
|
|
12
13
|
const SortableSet = require("./util/SortableSet");
|
|
13
14
|
const WeakTupleMap = require("./util/WeakTupleMap");
|
|
14
15
|
const { sortWithSourceOrder } = require("./util/comparators");
|
|
@@ -168,6 +169,12 @@ class ModuleGraph {
|
|
|
168
169
|
* @private
|
|
169
170
|
*/
|
|
170
171
|
this._dependencySourceOrderMap = new WeakMap();
|
|
172
|
+
|
|
173
|
+
/**
|
|
174
|
+
* @type {Set<Module>}
|
|
175
|
+
* @private
|
|
176
|
+
*/
|
|
177
|
+
this._modulesNeedingSort = new Set();
|
|
171
178
|
}
|
|
172
179
|
|
|
173
180
|
/**
|
|
@@ -304,17 +311,15 @@ class ModuleGraph {
|
|
|
304
311
|
// import { a, b } from "lib" -> a and b have the same source order -> a = b = 1
|
|
305
312
|
// import { d } from "lib/d" -> d = 2
|
|
306
313
|
const currentSourceOrder =
|
|
307
|
-
/** @type {
|
|
308
|
-
|
|
309
|
-
).sourceOrder;
|
|
314
|
+
/** @type {HarmonyImportSideEffectDependency | HarmonyImportSpecifierDependency} */
|
|
315
|
+
(dependency).sourceOrder;
|
|
310
316
|
|
|
311
317
|
// lib/index.js (reexport)
|
|
312
318
|
// import { a } from "lib/a" -> a = 0
|
|
313
319
|
// import { b } from "lib/b" -> b = 1
|
|
314
320
|
const originSourceOrder =
|
|
315
|
-
/** @type {
|
|
316
|
-
|
|
317
|
-
).sourceOrder;
|
|
321
|
+
/** @type {HarmonyImportSideEffectDependency | HarmonyImportSpecifierDependency} */
|
|
322
|
+
(originDependency).sourceOrder;
|
|
318
323
|
if (
|
|
319
324
|
typeof currentSourceOrder === "number" &&
|
|
320
325
|
typeof originSourceOrder === "number"
|
|
@@ -329,17 +334,28 @@ class ModuleGraph {
|
|
|
329
334
|
sub: originSourceOrder
|
|
330
335
|
});
|
|
331
336
|
|
|
337
|
+
// Save for later batch sorting
|
|
338
|
+
this._modulesNeedingSort.add(parentModule);
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
/**
|
|
343
|
+
* @returns {void}
|
|
344
|
+
*/
|
|
345
|
+
finishUpdateParent() {
|
|
346
|
+
if (this._modulesNeedingSort.size === 0) {
|
|
347
|
+
return;
|
|
348
|
+
}
|
|
349
|
+
for (const mod of this._modulesNeedingSort) {
|
|
332
350
|
// If dependencies like HarmonyImportSideEffectDependency and HarmonyImportSpecifierDependency have a SourceOrder,
|
|
333
351
|
// we sort based on it; otherwise, we preserve the original order.
|
|
334
352
|
sortWithSourceOrder(
|
|
335
|
-
|
|
336
|
-
this._dependencySourceOrderMap
|
|
353
|
+
mod.dependencies,
|
|
354
|
+
this._dependencySourceOrderMap,
|
|
355
|
+
(dep, index) => this.setParentDependenciesBlockIndex(dep, index)
|
|
337
356
|
);
|
|
338
|
-
|
|
339
|
-
for (const [index, dep] of parentModule.dependencies.entries()) {
|
|
340
|
-
this.setParentDependenciesBlockIndex(dep, index);
|
|
341
|
-
}
|
|
342
357
|
}
|
|
358
|
+
this._modulesNeedingSort.clear();
|
|
343
359
|
}
|
|
344
360
|
|
|
345
361
|
/**
|
|
@@ -844,7 +860,7 @@ class ModuleGraph {
|
|
|
844
860
|
) {
|
|
845
861
|
continue;
|
|
846
862
|
}
|
|
847
|
-
if (connection.dependency.
|
|
863
|
+
if (ImportPhaseUtils.isDefer(connection.dependency.phase)) return true;
|
|
848
864
|
}
|
|
849
865
|
return false;
|
|
850
866
|
}
|
|
@@ -52,8 +52,8 @@ const intersectConnectionStates = (a, b) => {
|
|
|
52
52
|
|
|
53
53
|
class ModuleGraphConnection {
|
|
54
54
|
/**
|
|
55
|
-
* @param {Module|null} originModule the referencing module
|
|
56
|
-
* @param {Dependency|null} dependency the referencing dependency
|
|
55
|
+
* @param {Module | null} originModule the referencing module
|
|
56
|
+
* @param {Dependency | null} dependency the referencing dependency
|
|
57
57
|
* @param {Module} module the referenced module
|
|
58
58
|
* @param {string=} explanation some extra detail
|
|
59
59
|
* @param {boolean=} weak the reference is weak
|