webpack 5.99.5 → 5.99.7
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 +1 -1
- package/lib/APIPlugin.js +2 -2
- package/lib/AutomaticPrefetchPlugin.js +21 -22
- package/lib/BannerPlugin.js +31 -35
- package/lib/Cache.js +1 -1
- package/lib/Chunk.js +12 -9
- package/lib/CleanPlugin.js +5 -3
- package/lib/Compilation.js +45 -35
- package/lib/Compiler.js +6 -4
- package/lib/ContextExclusionPlugin.js +4 -2
- package/lib/ContextModule.js +2 -1
- package/lib/ContextReplacementPlugin.js +5 -3
- package/lib/DelegatedPlugin.js +4 -2
- package/lib/DllEntryPlugin.js +4 -2
- package/lib/DllPlugin.js +5 -3
- package/lib/DllReferencePlugin.js +56 -60
- package/lib/DynamicEntryPlugin.js +4 -2
- package/lib/EntryOptionPlugin.js +3 -1
- package/lib/EntryPlugin.js +4 -2
- package/lib/EnvironmentPlugin.js +4 -2
- package/lib/EvalDevToolModulePlugin.js +9 -7
- package/lib/EvalSourceMapDevToolPlugin.js +137 -138
- package/lib/ExternalsPlugin.js +3 -1
- package/lib/FlagDependencyExportsPlugin.js +2 -1
- package/lib/HotModuleReplacementPlugin.js +3 -3
- package/lib/IgnorePlugin.js +6 -4
- package/lib/IgnoreWarningsPlugin.js +4 -2
- package/lib/LibManifestPlugin.js +3 -4
- package/lib/LoaderOptionsPlugin.js +4 -2
- package/lib/LoaderTargetPlugin.js +4 -2
- package/lib/Module.js +29 -14
- package/lib/ModuleFilenameHelpers.js +1 -1
- package/lib/ModuleGraph.js +15 -10
- package/lib/ModuleInfoHeaderPlugin.js +11 -12
- package/lib/MultiCompiler.js +5 -3
- package/lib/NoEmitOnErrorsPlugin.js +5 -3
- package/lib/NormalModule.js +6 -2
- package/lib/NormalModuleReplacementPlugin.js +33 -36
- package/lib/PlatformPlugin.js +3 -1
- package/lib/PrefetchPlugin.js +5 -3
- package/lib/ProgressPlugin.js +23 -26
- package/lib/RecordIdsPlugin.js +73 -103
- package/lib/RuntimePlugin.js +34 -32
- package/lib/SourceMapDevToolPlugin.js +8 -6
- package/lib/Template.js +1 -1
- package/lib/WarnCaseSensitiveModulesPlugin.js +36 -37
- package/lib/WarnNoModeSetPlugin.js +3 -1
- package/lib/WatchIgnorePlugin.js +3 -1
- package/lib/WebpackError.js +11 -3
- package/lib/WebpackOptionsApply.js +22 -5
- package/lib/async-modules/InferAsyncModulesPlugin.js +25 -26
- package/lib/buildChunkGraph.js +7 -2
- package/lib/cache/IdleFileCachePlugin.js +12 -13
- package/lib/cache/MemoryCachePlugin.js +2 -1
- package/lib/cache/MemoryWithGcCachePlugin.js +10 -7
- package/lib/cache/PackFileCacheStrategy.js +13 -21
- package/lib/cache/ResolverCachePlugin.js +22 -22
- package/lib/cli.js +8 -4
- package/lib/config/defaults.js +2 -2
- package/lib/config/normalization.js +9 -3
- package/lib/config/target.js +6 -6
- package/lib/container/ContainerReferencePlugin.js +24 -26
- package/lib/container/ModuleFederationPlugin.js +2 -1
- package/lib/css/CssGenerator.js +1 -1
- package/lib/css/CssModulesPlugin.js +6 -4
- package/lib/css/CssParser.js +1 -1
- package/lib/debug/ProfilingPlugin.js +1 -1
- package/lib/dependencies/ContextDependencyHelpers.js +1 -1
- package/lib/dependencies/CssIcssImportDependency.js +3 -2
- package/lib/dependencies/HarmonyDetectionParserPlugin.js +9 -15
- package/lib/dependencies/HarmonyExportExpressionDependency.js +1 -1
- package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +2 -1
- package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +1 -1
- package/lib/dependencies/HarmonyTopLevelThisParserPlugin.js +15 -15
- package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +4 -2
- package/lib/dependencies/JsonExportsDependency.js +1 -1
- package/lib/dependencies/LoaderPlugin.js +5 -3
- package/lib/dependencies/LocalModulesHelpers.js +1 -1
- package/lib/dependencies/RequireContextDependencyParserPlugin.js +46 -46
- package/lib/dependencies/RequireEnsureDependenciesBlockParserPlugin.js +94 -100
- package/lib/dependencies/RequireResolveDependency.js +1 -1
- package/lib/dependencies/WorkerPlugin.js +2 -2
- package/lib/esm/ModuleChunkLoadingPlugin.js +76 -57
- package/lib/esm/ModuleChunkLoadingRuntimeModule.js +11 -9
- package/lib/hmr/HotModuleReplacement.runtime.js +0 -1
- package/lib/hmr/JavascriptHotModuleReplacement.runtime.js +0 -1
- package/lib/hmr/LazyCompilationPlugin.js +17 -18
- package/lib/ids/ChunkModuleIdRangePlugin.js +6 -6
- package/lib/ids/DeterministicChunkIdsPlugin.js +1 -1
- package/lib/ids/DeterministicModuleIdsPlugin.js +48 -49
- package/lib/ids/HashedModuleIdsPlugin.js +4 -2
- package/lib/ids/NamedChunkIdsPlugin.js +6 -4
- package/lib/ids/NamedModuleIdsPlugin.js +6 -4
- package/lib/ids/NaturalChunkIdsPlugin.js +4 -2
- package/lib/ids/NaturalModuleIdsPlugin.js +4 -2
- package/lib/ids/OccurrenceChunkIdsPlugin.js +4 -2
- package/lib/ids/OccurrenceModuleIdsPlugin.js +4 -2
- package/lib/index.js +1 -1
- package/lib/javascript/BasicEvaluatedExpression.js +2 -2
- package/lib/javascript/JavascriptParser.js +670 -688
- package/lib/library/EnableLibraryPlugin.js +15 -2
- package/lib/library/ModuleLibraryPlugin.js +66 -43
- package/lib/logging/createConsoleLogger.js +0 -1
- package/lib/node/CommonJsChunkLoadingPlugin.js +71 -75
- package/lib/node/NodeEnvironmentPlugin.js +3 -1
- package/lib/node/NodeTemplatePlugin.js +2 -2
- package/lib/node/ReadFileCompileAsyncWasmPlugin.js +2 -2
- package/lib/node/ReadFileCompileWasmPlugin.js +3 -3
- package/lib/optimize/AggressiveMergingPlugin.js +1 -1
- package/lib/optimize/AggressiveSplittingPlugin.js +224 -232
- package/lib/optimize/ConcatenatedModule.js +12 -15
- package/lib/optimize/FlagIncludedChunksPlugin.js +92 -97
- package/lib/optimize/LimitChunkCountPlugin.js +4 -2
- package/lib/optimize/MangleExportsPlugin.js +15 -16
- package/lib/optimize/MinChunkSizePlugin.js +4 -2
- package/lib/optimize/ModuleConcatenationPlugin.js +4 -2
- package/lib/optimize/RealContentHashPlugin.js +4 -2
- package/lib/optimize/RemoveEmptyChunksPlugin.js +5 -3
- package/lib/optimize/RemoveParentModulesPlugin.js +4 -2
- package/lib/optimize/RuntimeChunkPlugin.js +17 -18
- package/lib/optimize/SplitChunksPlugin.js +9 -6
- package/lib/performance/SizeLimitsPlugin.js +3 -1
- package/lib/prefetch/ChunkPrefetchPreloadPlugin.js +61 -62
- package/lib/runtime/GetChunkFilenameRuntimeModule.js +3 -4
- package/lib/runtime/StartupChunkDependenciesPlugin.js +39 -42
- package/lib/schemes/DataUriPlugin.js +5 -3
- package/lib/schemes/FileUriPlugin.js +5 -3
- package/lib/schemes/HttpUriPlugin.js +32 -39
- package/lib/serialization/AggregateErrorSerializer.js +42 -0
- package/lib/serialization/BinaryMiddleware.js +22 -38
- package/lib/serialization/ErrorObjectSerializer.js +7 -2
- package/lib/serialization/FileMiddleware.js +29 -33
- package/lib/serialization/ObjectMiddleware.js +42 -30
- package/lib/serialization/Serializer.js +29 -18
- package/lib/serialization/SerializerMiddleware.js +105 -72
- package/lib/serialization/SingleItemMiddleware.js +4 -5
- package/lib/sharing/ProvideSharedPlugin.js +6 -4
- package/lib/stats/DefaultStatsFactoryPlugin.js +128 -57
- package/lib/stats/DefaultStatsPresetPlugin.js +25 -20
- package/lib/stats/DefaultStatsPrinterPlugin.js +486 -334
- package/lib/stats/StatsFactory.js +47 -10
- package/lib/stats/StatsPrinter.js +52 -31
- package/lib/util/ArrayQueue.js +1 -1
- package/lib/util/AsyncQueue.js +1 -1
- package/lib/util/TupleQueue.js +9 -7
- package/lib/util/TupleSet.js +37 -18
- package/lib/util/WeakTupleMap.js +50 -37
- package/lib/util/cleverMerge.js +2 -2
- package/lib/util/comparators.js +1 -1
- package/lib/util/concatenate.js +4 -2
- package/lib/util/createHash.js +1 -1
- package/lib/util/fs.js +1 -1
- package/lib/util/makeSerializable.js +1 -1
- package/lib/util/runtime.js +1 -0
- package/lib/util/serialization.js +50 -42
- package/lib/wasm-async/AsyncWebAssemblyGenerator.js +1 -1
- package/lib/wasm-async/AsyncWebAssemblyModulesPlugin.js +1 -1
- package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +2 -2
- package/lib/wasm-sync/WasmFinalizeExportsPlugin.js +55 -57
- package/lib/wasm-sync/WebAssemblyGenerator.js +1 -1
- package/lib/wasm-sync/WebAssemblyModulesPlugin.js +1 -1
- package/lib/web/FetchCompileWasmPlugin.js +2 -2
- package/lib/web/JsonpChunkLoadingPlugin.js +73 -74
- package/lib/webpack.js +1 -1
- package/lib/webworker/ImportScriptsChunkLoadingPlugin.js +77 -78
- package/package.json +4 -3
- package/schemas/WebpackOptions.check.js +1 -1
- package/schemas/WebpackOptions.json +24 -2
- package/types.d.ts +273 -128
@@ -15,83 +15,82 @@ const ChunkPreloadTriggerRuntimeModule = require("./ChunkPreloadTriggerRuntimeMo
|
|
15
15
|
/** @typedef {import("../ChunkGroup").RawChunkGroupOptions} RawChunkGroupOptions */
|
16
16
|
/** @typedef {import("../Compiler")} Compiler */
|
17
17
|
|
18
|
+
const PLUGIN_NAME = "ChunkPrefetchPreloadPlugin";
|
19
|
+
|
18
20
|
class ChunkPrefetchPreloadPlugin {
|
19
21
|
/**
|
20
22
|
* @param {Compiler} compiler the compiler
|
21
23
|
* @returns {void}
|
22
24
|
*/
|
23
25
|
apply(compiler) {
|
24
|
-
compiler.hooks.compilation.tap(
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
26
|
+
compiler.hooks.compilation.tap(PLUGIN_NAME, compilation => {
|
27
|
+
compilation.hooks.additionalChunkRuntimeRequirements.tap(
|
28
|
+
PLUGIN_NAME,
|
29
|
+
(chunk, set, { chunkGraph }) => {
|
30
|
+
if (chunkGraph.getNumberOfEntryModules(chunk) === 0) return;
|
31
|
+
const startupChildChunks = chunk.getChildrenOfTypeInOrder(
|
32
|
+
chunkGraph,
|
33
|
+
"prefetchOrder"
|
34
|
+
);
|
35
|
+
if (startupChildChunks) {
|
36
|
+
set.add(RuntimeGlobals.prefetchChunk);
|
37
|
+
set.add(RuntimeGlobals.onChunksLoaded);
|
38
|
+
set.add(RuntimeGlobals.exports);
|
39
|
+
compilation.addRuntimeModule(
|
40
|
+
chunk,
|
41
|
+
new ChunkPrefetchStartupRuntimeModule(startupChildChunks)
|
34
42
|
);
|
35
|
-
if (startupChildChunks) {
|
36
|
-
set.add(RuntimeGlobals.prefetchChunk);
|
37
|
-
set.add(RuntimeGlobals.onChunksLoaded);
|
38
|
-
set.add(RuntimeGlobals.exports);
|
39
|
-
compilation.addRuntimeModule(
|
40
|
-
chunk,
|
41
|
-
new ChunkPrefetchStartupRuntimeModule(startupChildChunks)
|
42
|
-
);
|
43
|
-
}
|
44
43
|
}
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
44
|
+
}
|
45
|
+
);
|
46
|
+
compilation.hooks.additionalTreeRuntimeRequirements.tap(
|
47
|
+
PLUGIN_NAME,
|
48
|
+
(chunk, set, { chunkGraph }) => {
|
49
|
+
const chunkMap = chunk.getChildIdsByOrdersMap(chunkGraph);
|
50
50
|
|
51
|
-
|
52
|
-
|
53
|
-
compilation.addRuntimeModule(
|
54
|
-
chunk,
|
55
|
-
new ChunkPrefetchTriggerRuntimeModule(chunkMap.prefetch)
|
56
|
-
);
|
57
|
-
}
|
58
|
-
if (chunkMap.preload) {
|
59
|
-
set.add(RuntimeGlobals.preloadChunk);
|
60
|
-
compilation.addRuntimeModule(
|
61
|
-
chunk,
|
62
|
-
new ChunkPreloadTriggerRuntimeModule(chunkMap.preload)
|
63
|
-
);
|
64
|
-
}
|
65
|
-
}
|
66
|
-
);
|
67
|
-
compilation.hooks.runtimeRequirementInTree
|
68
|
-
.for(RuntimeGlobals.prefetchChunk)
|
69
|
-
.tap("ChunkPrefetchPreloadPlugin", (chunk, set) => {
|
51
|
+
if (chunkMap.prefetch) {
|
52
|
+
set.add(RuntimeGlobals.prefetchChunk);
|
70
53
|
compilation.addRuntimeModule(
|
71
54
|
chunk,
|
72
|
-
new
|
73
|
-
"prefetch",
|
74
|
-
RuntimeGlobals.prefetchChunk,
|
75
|
-
RuntimeGlobals.prefetchChunkHandlers
|
76
|
-
)
|
55
|
+
new ChunkPrefetchTriggerRuntimeModule(chunkMap.prefetch)
|
77
56
|
);
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
.for(RuntimeGlobals.preloadChunk)
|
82
|
-
.tap("ChunkPrefetchPreloadPlugin", (chunk, set) => {
|
57
|
+
}
|
58
|
+
if (chunkMap.preload) {
|
59
|
+
set.add(RuntimeGlobals.preloadChunk);
|
83
60
|
compilation.addRuntimeModule(
|
84
61
|
chunk,
|
85
|
-
new
|
86
|
-
"preload",
|
87
|
-
RuntimeGlobals.preloadChunk,
|
88
|
-
RuntimeGlobals.preloadChunkHandlers
|
89
|
-
)
|
62
|
+
new ChunkPreloadTriggerRuntimeModule(chunkMap.preload)
|
90
63
|
);
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
64
|
+
}
|
65
|
+
}
|
66
|
+
);
|
67
|
+
compilation.hooks.runtimeRequirementInTree
|
68
|
+
.for(RuntimeGlobals.prefetchChunk)
|
69
|
+
.tap(PLUGIN_NAME, (chunk, set) => {
|
70
|
+
compilation.addRuntimeModule(
|
71
|
+
chunk,
|
72
|
+
new ChunkPrefetchFunctionRuntimeModule(
|
73
|
+
"prefetch",
|
74
|
+
RuntimeGlobals.prefetchChunk,
|
75
|
+
RuntimeGlobals.prefetchChunkHandlers
|
76
|
+
)
|
77
|
+
);
|
78
|
+
set.add(RuntimeGlobals.prefetchChunkHandlers);
|
79
|
+
});
|
80
|
+
compilation.hooks.runtimeRequirementInTree
|
81
|
+
.for(RuntimeGlobals.preloadChunk)
|
82
|
+
.tap(PLUGIN_NAME, (chunk, set) => {
|
83
|
+
compilation.addRuntimeModule(
|
84
|
+
chunk,
|
85
|
+
new ChunkPrefetchFunctionRuntimeModule(
|
86
|
+
"preload",
|
87
|
+
RuntimeGlobals.preloadChunk,
|
88
|
+
RuntimeGlobals.preloadChunkHandlers
|
89
|
+
)
|
90
|
+
);
|
91
|
+
set.add(RuntimeGlobals.preloadChunkHandlers);
|
92
|
+
});
|
93
|
+
});
|
95
94
|
}
|
96
95
|
}
|
97
96
|
|
@@ -10,6 +10,7 @@ const Template = require("../Template");
|
|
10
10
|
const { first } = require("../util/SetHelpers");
|
11
11
|
|
12
12
|
/** @typedef {import("../Chunk")} Chunk */
|
13
|
+
/** @typedef {import("../Chunk").ChunkId} ChunkId */
|
13
14
|
/** @typedef {import("../ChunkGraph")} ChunkGraph */
|
14
15
|
/** @typedef {import("../Compilation")} Compilation */
|
15
16
|
/** @typedef {import("../Compilation").AssetInfo} AssetInfo */
|
@@ -156,14 +157,12 @@ class GetChunkFilenameRuntimeModule extends RuntimeModule {
|
|
156
157
|
hashWithLength: length =>
|
157
158
|
`" + ${RuntimeGlobals.getFullHash}().slice(0, ${length}) + "`,
|
158
159
|
chunk: {
|
159
|
-
id: unquotedStringify(/** @type {
|
160
|
+
id: unquotedStringify(/** @type {ChunkId} */ (c.id)),
|
160
161
|
hash: unquotedStringify(/** @type {string} */ (c.renderedHash)),
|
161
162
|
hashWithLength: unquotedStringifyWithLength(
|
162
163
|
/** @type {string} */ (c.renderedHash)
|
163
164
|
),
|
164
|
-
name: unquotedStringify(
|
165
|
-
c.name || /** @type {number | string} */ (c.id)
|
166
|
-
),
|
165
|
+
name: unquotedStringify(c.name || /** @type {ChunkId} */ (c.id)),
|
167
166
|
contentHash: {
|
168
167
|
[contentType]: unquotedStringify(c.contentHash[contentType])
|
169
168
|
},
|
@@ -18,6 +18,8 @@ const StartupEntrypointRuntimeModule = require("./StartupEntrypointRuntimeModule
|
|
18
18
|
* @property {boolean=} asyncChunkLoading
|
19
19
|
*/
|
20
20
|
|
21
|
+
const PLUGIN_NAME = "StartupChunkDependenciesPlugin";
|
22
|
+
|
21
23
|
class StartupChunkDependenciesPlugin {
|
22
24
|
/**
|
23
25
|
* @param {Options} options options
|
@@ -36,53 +38,48 @@ class StartupChunkDependenciesPlugin {
|
|
36
38
|
* @returns {void}
|
37
39
|
*/
|
38
40
|
apply(compiler) {
|
39
|
-
compiler.hooks.thisCompilation.tap(
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
const
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
(chunk
|
58
|
-
|
59
|
-
if (chunkGraph.hasChunkEntryDependentChunks(chunk)) {
|
60
|
-
set.add(RuntimeGlobals.startup);
|
61
|
-
set.add(RuntimeGlobals.ensureChunk);
|
62
|
-
set.add(RuntimeGlobals.ensureChunkIncludeEntries);
|
63
|
-
compilation.addRuntimeModule(
|
64
|
-
chunk,
|
65
|
-
new StartupChunkDependenciesRuntimeModule(
|
66
|
-
this.asyncChunkLoading
|
67
|
-
)
|
68
|
-
);
|
69
|
-
}
|
70
|
-
}
|
71
|
-
);
|
72
|
-
compilation.hooks.runtimeRequirementInTree
|
73
|
-
.for(RuntimeGlobals.startupEntrypoint)
|
74
|
-
.tap("StartupChunkDependenciesPlugin", (chunk, set) => {
|
75
|
-
if (!isEnabledForChunk(chunk)) return;
|
76
|
-
set.add(RuntimeGlobals.require);
|
41
|
+
compiler.hooks.thisCompilation.tap(PLUGIN_NAME, compilation => {
|
42
|
+
const globalChunkLoading = compilation.outputOptions.chunkLoading;
|
43
|
+
/**
|
44
|
+
* @param {Chunk} chunk chunk to check
|
45
|
+
* @returns {boolean} true, when the plugin is enabled for the chunk
|
46
|
+
*/
|
47
|
+
const isEnabledForChunk = chunk => {
|
48
|
+
const options = chunk.getEntryOptions();
|
49
|
+
const chunkLoading =
|
50
|
+
options && options.chunkLoading !== undefined
|
51
|
+
? options.chunkLoading
|
52
|
+
: globalChunkLoading;
|
53
|
+
return chunkLoading === this.chunkLoading;
|
54
|
+
};
|
55
|
+
compilation.hooks.additionalTreeRuntimeRequirements.tap(
|
56
|
+
PLUGIN_NAME,
|
57
|
+
(chunk, set, { chunkGraph }) => {
|
58
|
+
if (!isEnabledForChunk(chunk)) return;
|
59
|
+
if (chunkGraph.hasChunkEntryDependentChunks(chunk)) {
|
60
|
+
set.add(RuntimeGlobals.startup);
|
77
61
|
set.add(RuntimeGlobals.ensureChunk);
|
78
62
|
set.add(RuntimeGlobals.ensureChunkIncludeEntries);
|
79
63
|
compilation.addRuntimeModule(
|
80
64
|
chunk,
|
81
|
-
new
|
65
|
+
new StartupChunkDependenciesRuntimeModule(this.asyncChunkLoading)
|
82
66
|
);
|
83
|
-
}
|
84
|
-
|
85
|
-
|
67
|
+
}
|
68
|
+
}
|
69
|
+
);
|
70
|
+
compilation.hooks.runtimeRequirementInTree
|
71
|
+
.for(RuntimeGlobals.startupEntrypoint)
|
72
|
+
.tap(PLUGIN_NAME, (chunk, set) => {
|
73
|
+
if (!isEnabledForChunk(chunk)) return;
|
74
|
+
set.add(RuntimeGlobals.require);
|
75
|
+
set.add(RuntimeGlobals.ensureChunk);
|
76
|
+
set.add(RuntimeGlobals.ensureChunkIncludeEntries);
|
77
|
+
compilation.addRuntimeModule(
|
78
|
+
chunk,
|
79
|
+
new StartupEntrypointRuntimeModule(this.asyncChunkLoading)
|
80
|
+
);
|
81
|
+
});
|
82
|
+
});
|
86
83
|
}
|
87
84
|
}
|
88
85
|
|
@@ -37,6 +37,8 @@ const decodeDataURI = uri => {
|
|
37
37
|
}
|
38
38
|
};
|
39
39
|
|
40
|
+
const PLUGIN_NAME = "DataUriPlugin";
|
41
|
+
|
40
42
|
class DataUriPlugin {
|
41
43
|
/**
|
42
44
|
* Apply the plugin
|
@@ -45,11 +47,11 @@ class DataUriPlugin {
|
|
45
47
|
*/
|
46
48
|
apply(compiler) {
|
47
49
|
compiler.hooks.compilation.tap(
|
48
|
-
|
50
|
+
PLUGIN_NAME,
|
49
51
|
(compilation, { normalModuleFactory }) => {
|
50
52
|
normalModuleFactory.hooks.resolveForScheme
|
51
53
|
.for("data")
|
52
|
-
.tap(
|
54
|
+
.tap(PLUGIN_NAME, resourceData => {
|
53
55
|
const match = URIRegEx.exec(resourceData.resource);
|
54
56
|
if (match) {
|
55
57
|
resourceData.data.mimetype = match[1] || "";
|
@@ -60,7 +62,7 @@ class DataUriPlugin {
|
|
60
62
|
});
|
61
63
|
NormalModule.getCompilationHooks(compilation)
|
62
64
|
.readResourceForScheme.for("data")
|
63
|
-
.tap(
|
65
|
+
.tap(PLUGIN_NAME, resource => decodeDataURI(resource));
|
64
66
|
}
|
65
67
|
);
|
66
68
|
}
|
@@ -10,6 +10,8 @@ const { NormalModule } = require("..");
|
|
10
10
|
|
11
11
|
/** @typedef {import("../Compiler")} Compiler */
|
12
12
|
|
13
|
+
const PLUGIN_NAME = "FileUriPlugin";
|
14
|
+
|
13
15
|
class FileUriPlugin {
|
14
16
|
/**
|
15
17
|
* Apply the plugin
|
@@ -18,11 +20,11 @@ class FileUriPlugin {
|
|
18
20
|
*/
|
19
21
|
apply(compiler) {
|
20
22
|
compiler.hooks.compilation.tap(
|
21
|
-
|
23
|
+
PLUGIN_NAME,
|
22
24
|
(compilation, { normalModuleFactory }) => {
|
23
25
|
normalModuleFactory.hooks.resolveForScheme
|
24
26
|
.for("file")
|
25
|
-
.tap(
|
27
|
+
.tap(PLUGIN_NAME, resourceData => {
|
26
28
|
const url = new URL(resourceData.resource);
|
27
29
|
const path = fileURLToPath(url);
|
28
30
|
const query = url.search;
|
@@ -36,7 +38,7 @@ class FileUriPlugin {
|
|
36
38
|
const hooks = NormalModule.getCompilationHooks(compilation);
|
37
39
|
hooks.readResource
|
38
40
|
.for(undefined)
|
39
|
-
.tapAsync(
|
41
|
+
.tapAsync(PLUGIN_NAME, (loaderContext, callback) => {
|
40
42
|
const { resourcePath } = loaderContext;
|
41
43
|
loaderContext.addDependency(resourcePath);
|
42
44
|
loaderContext.fs.readFile(resourcePath, callback);
|
@@ -405,6 +405,8 @@ const cachedWithKey = (fn, forceFn = fn) => {
|
|
405
405
|
/** @typedef {FetchResultMeta & { entry: LockfileEntry, content: Buffer }} ContentFetchResult */
|
406
406
|
/** @typedef {RedirectFetchResult | ContentFetchResult} FetchResult */
|
407
407
|
|
408
|
+
const PLUGIN_NAME = "HttpUriPlugin";
|
409
|
+
|
408
410
|
class HttpUriPlugin {
|
409
411
|
/**
|
410
412
|
* @param {HttpUriPluginOptions} options options
|
@@ -440,14 +442,14 @@ class HttpUriPlugin {
|
|
440
442
|
/** @type {LockfileCache} */
|
441
443
|
let lockfileCache;
|
442
444
|
compiler.hooks.compilation.tap(
|
443
|
-
|
445
|
+
PLUGIN_NAME,
|
444
446
|
(compilation, { normalModuleFactory }) => {
|
445
447
|
const intermediateFs =
|
446
448
|
/** @type {IntermediateFileSystem} */
|
447
449
|
(compiler.intermediateFileSystem);
|
448
450
|
const fs = compilation.inputFileSystem;
|
449
|
-
const cache = compilation.getCache(
|
450
|
-
const logger = compilation.getLogger(
|
451
|
+
const cache = compilation.getCache(`webpack.${PLUGIN_NAME}`);
|
452
|
+
const logger = compilation.getLogger(`webpack.${PLUGIN_NAME}`);
|
451
453
|
/** @type {string} */
|
452
454
|
const lockfileLocation =
|
453
455
|
this._lockfileLocation ||
|
@@ -1154,19 +1156,16 @@ Run build with un-frozen lockfile to automatically fix lockfile.`
|
|
1154
1156
|
};
|
1155
1157
|
normalModuleFactory.hooks.resolveForScheme
|
1156
1158
|
.for(scheme)
|
1157
|
-
.tapAsync(
|
1158
|
-
|
1159
|
-
|
1160
|
-
|
1161
|
-
|
1162
|
-
|
1163
|
-
|
1164
|
-
);
|
1165
|
-
}
|
1166
|
-
);
|
1159
|
+
.tapAsync(PLUGIN_NAME, (resourceData, resolveData, callback) => {
|
1160
|
+
respondWithUrlModule(
|
1161
|
+
new URL(resourceData.resource),
|
1162
|
+
resourceData,
|
1163
|
+
callback
|
1164
|
+
);
|
1165
|
+
});
|
1167
1166
|
normalModuleFactory.hooks.resolveInScheme
|
1168
1167
|
.for(scheme)
|
1169
|
-
.tapAsync(
|
1168
|
+
.tapAsync(PLUGIN_NAME, (resourceData, data, callback) => {
|
1170
1169
|
// Only handle relative urls (./xxx, ../xxx, /xxx, //xxx)
|
1171
1170
|
if (
|
1172
1171
|
data.dependencyType !== "url" &&
|
@@ -1183,7 +1182,7 @@ Run build with un-frozen lockfile to automatically fix lockfile.`
|
|
1183
1182
|
const hooks = NormalModule.getCompilationHooks(compilation);
|
1184
1183
|
hooks.readResourceForScheme
|
1185
1184
|
.for(scheme)
|
1186
|
-
.tapAsync(
|
1185
|
+
.tapAsync(PLUGIN_NAME, (resource, module, callback) =>
|
1187
1186
|
getInfo(resource, (err, _result) => {
|
1188
1187
|
if (err) return callback(err);
|
1189
1188
|
const result = /** @type {Info} */ (_result);
|
@@ -1192,33 +1191,27 @@ Run build with un-frozen lockfile to automatically fix lockfile.`
|
|
1192
1191
|
callback(null, result.content);
|
1193
1192
|
})
|
1194
1193
|
);
|
1195
|
-
hooks.needBuild.tapAsync(
|
1196
|
-
|
1197
|
-
|
1198
|
-
|
1199
|
-
|
1200
|
-
|
1201
|
-
|
1202
|
-
|
1203
|
-
|
1204
|
-
|
1205
|
-
|
1206
|
-
|
1207
|
-
|
1208
|
-
|
1209
|
-
|
1210
|
-
|
1211
|
-
}
|
1212
|
-
callback();
|
1213
|
-
});
|
1214
|
-
} else {
|
1215
|
-
return callback();
|
1216
|
-
}
|
1194
|
+
hooks.needBuild.tapAsync(PLUGIN_NAME, (module, context, callback) => {
|
1195
|
+
if (module.resource && module.resource.startsWith(`${scheme}://`)) {
|
1196
|
+
getInfo(module.resource, (err, _result) => {
|
1197
|
+
if (err) return callback(err);
|
1198
|
+
const result = /** @type {Info} */ (_result);
|
1199
|
+
if (
|
1200
|
+
result.entry.integrity !==
|
1201
|
+
/** @type {BuildInfo} */
|
1202
|
+
(module.buildInfo).resourceIntegrity
|
1203
|
+
) {
|
1204
|
+
return callback(null, true);
|
1205
|
+
}
|
1206
|
+
callback();
|
1207
|
+
});
|
1208
|
+
} else {
|
1209
|
+
return callback();
|
1217
1210
|
}
|
1218
|
-
);
|
1211
|
+
});
|
1219
1212
|
}
|
1220
1213
|
compilation.hooks.finishModules.tapAsync(
|
1221
|
-
|
1214
|
+
PLUGIN_NAME,
|
1222
1215
|
(modules, callback) => {
|
1223
1216
|
if (!lockfileUpdates) return callback();
|
1224
1217
|
const ext = extname(lockfileLocation);
|
@@ -0,0 +1,42 @@
|
|
1
|
+
/*
|
2
|
+
MIT License http://www.opensource.org/licenses/mit-license.php
|
3
|
+
*/
|
4
|
+
|
5
|
+
"use strict";
|
6
|
+
|
7
|
+
/** @typedef {import("./ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
|
8
|
+
/** @typedef {import("./ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
|
9
|
+
|
10
|
+
/** @typedef {Error & { cause: unknown, errors: EXPECTED_ANY[] }} AggregateError */
|
11
|
+
|
12
|
+
class AggregateErrorSerializer {
|
13
|
+
/**
|
14
|
+
* @param {AggregateError} obj error
|
15
|
+
* @param {ObjectSerializerContext} context context
|
16
|
+
*/
|
17
|
+
serialize(obj, context) {
|
18
|
+
context.write(obj.errors);
|
19
|
+
context.write(obj.message);
|
20
|
+
context.write(obj.stack);
|
21
|
+
context.write(obj.cause);
|
22
|
+
}
|
23
|
+
|
24
|
+
/**
|
25
|
+
* @param {ObjectDeserializerContext} context context
|
26
|
+
* @returns {AggregateError} error
|
27
|
+
*/
|
28
|
+
deserialize(context) {
|
29
|
+
const errors = context.read();
|
30
|
+
// @ts-expect-error ES2018 doesn't `AggregateError`, but it can be used by developers
|
31
|
+
// eslint-disable-next-line n/no-unsupported-features/es-builtins, n/no-unsupported-features/es-syntax
|
32
|
+
const err = new AggregateError(errors);
|
33
|
+
|
34
|
+
err.message = context.read();
|
35
|
+
err.stack = context.read();
|
36
|
+
err.cause = context.read();
|
37
|
+
|
38
|
+
return err;
|
39
|
+
}
|
40
|
+
}
|
41
|
+
|
42
|
+
module.exports = AggregateErrorSerializer;
|
@@ -7,15 +7,9 @@
|
|
7
7
|
const memoize = require("../util/memoize");
|
8
8
|
const SerializerMiddleware = require("./SerializerMiddleware");
|
9
9
|
|
10
|
-
/** @typedef {import("./SerializerMiddleware").Context} Context */
|
11
10
|
/** @typedef {import("./types").BufferSerializableType} BufferSerializableType */
|
12
11
|
/** @typedef {import("./types").PrimitiveSerializableType} PrimitiveSerializableType */
|
13
12
|
|
14
|
-
/**
|
15
|
-
* @template LAZY_RESULT
|
16
|
-
* @typedef {import("./SerializerMiddleware").LazyFunction<LAZY_RESULT>} LazyFunction
|
17
|
-
*/
|
18
|
-
|
19
13
|
/*
|
20
14
|
Format:
|
21
15
|
|
@@ -141,10 +135,18 @@ const identifyBigInt = n => {
|
|
141
135
|
return 2;
|
142
136
|
};
|
143
137
|
|
138
|
+
/** @typedef {PrimitiveSerializableType[]} DeserializedType */
|
139
|
+
/** @typedef {BufferSerializableType[]} SerializedType} */
|
140
|
+
/** @typedef {{ retainedBuffer?: (x: Buffer) => Buffer }} Context} */
|
141
|
+
|
144
142
|
/**
|
145
|
-
* @
|
146
|
-
* @
|
147
|
-
* @
|
143
|
+
* @template LazyInputValue
|
144
|
+
* @template LazyOutputValue
|
145
|
+
* @typedef {import("./SerializerMiddleware").LazyFunction<LazyInputValue, LazyOutputValue, BinaryMiddleware, undefined>} LazyFunction
|
146
|
+
*/
|
147
|
+
|
148
|
+
/**
|
149
|
+
* @extends {SerializerMiddleware<DeserializedType, SerializedType, Context>}
|
148
150
|
*/
|
149
151
|
class BinaryMiddleware extends SerializerMiddleware {
|
150
152
|
/**
|
@@ -157,9 +159,9 @@ class BinaryMiddleware extends SerializerMiddleware {
|
|
157
159
|
}
|
158
160
|
|
159
161
|
/**
|
160
|
-
* @param {LazyFunction<DeserializedType>} fn lazy function
|
162
|
+
* @param {LazyFunction<DeserializedType, SerializedType>} fn lazy function
|
161
163
|
* @param {Context} context serialize function
|
162
|
-
* @returns {LazyFunction<SerializedType>} new lazy
|
164
|
+
* @returns {LazyFunction<SerializedType, DeserializedType>} new lazy
|
163
165
|
*/
|
164
166
|
_serializeLazy(fn, context) {
|
165
167
|
return SerializerMiddleware.serializeLazy(fn, data =>
|
@@ -281,7 +283,7 @@ class BinaryMiddleware extends SerializerMiddleware {
|
|
281
283
|
case "function": {
|
282
284
|
if (!SerializerMiddleware.isLazy(thing))
|
283
285
|
throw new Error(`Unexpected function ${thing}`);
|
284
|
-
/** @type {SerializedType | LazyFunction<SerializedType>} */
|
286
|
+
/** @type {SerializedType | LazyFunction<SerializedType, DeserializedType> | undefined} */
|
285
287
|
let serializedData =
|
286
288
|
SerializerMiddleware.getLazySerializedValue(thing);
|
287
289
|
if (serializedData === undefined) {
|
@@ -294,18 +296,10 @@ class BinaryMiddleware extends SerializerMiddleware {
|
|
294
296
|
const data = this._serialize(result, context, allocationScope);
|
295
297
|
leftOverBuffer = allocationScope.leftOverBuffer;
|
296
298
|
allocationScope.leftOverBuffer = null;
|
297
|
-
SerializerMiddleware.setLazySerializedValue(
|
298
|
-
/** @type {LazyFunction<DeserializedType>} */
|
299
|
-
(thing),
|
300
|
-
data
|
301
|
-
);
|
299
|
+
SerializerMiddleware.setLazySerializedValue(thing, data);
|
302
300
|
serializedData = data;
|
303
301
|
} else {
|
304
|
-
serializedData = this._serializeLazy(
|
305
|
-
/** @type {LazyFunction<DeserializedType>} */
|
306
|
-
(thing),
|
307
|
-
context
|
308
|
-
);
|
302
|
+
serializedData = this._serializeLazy(thing, context);
|
309
303
|
flush();
|
310
304
|
buffers.push(serializedData);
|
311
305
|
break;
|
@@ -666,7 +660,7 @@ class BinaryMiddleware extends SerializerMiddleware {
|
|
666
660
|
* @private
|
667
661
|
* @param {SerializedType} content content
|
668
662
|
* @param {Context} context context object
|
669
|
-
* @returns {LazyFunction<DeserializedType>} lazy function
|
663
|
+
* @returns {LazyFunction<DeserializedType, SerializedType>} lazy function
|
670
664
|
*/
|
671
665
|
_createLazyDeserialized(content, context) {
|
672
666
|
return SerializerMiddleware.createLazy(
|
@@ -679,9 +673,9 @@ class BinaryMiddleware extends SerializerMiddleware {
|
|
679
673
|
|
680
674
|
/**
|
681
675
|
* @private
|
682
|
-
* @param {LazyFunction<SerializedType>} fn lazy function
|
676
|
+
* @param {LazyFunction<SerializedType, DeserializedType>} fn lazy function
|
683
677
|
* @param {Context} context context object
|
684
|
-
* @returns {LazyFunction<DeserializedType>} new lazy
|
678
|
+
* @returns {LazyFunction<DeserializedType, SerializedType>} new lazy
|
685
679
|
*/
|
686
680
|
_deserializeLazy(fn, context) {
|
687
681
|
return SerializerMiddleware.deserializeLazy(fn, data =>
|
@@ -701,7 +695,6 @@ class BinaryMiddleware extends SerializerMiddleware {
|
|
701
695
|
let currentIsBuffer = Buffer.isBuffer(currentBuffer);
|
702
696
|
let currentPosition = 0;
|
703
697
|
|
704
|
-
/** @type {(x: Buffer) => Buffer} */
|
705
698
|
const retainedBuffer = context.retainedBuffer || (x => x);
|
706
699
|
|
707
700
|
const checkOverflow = () => {
|
@@ -818,17 +811,14 @@ class BinaryMiddleware extends SerializerMiddleware {
|
|
818
811
|
return () => {
|
819
812
|
const count = readU32();
|
820
813
|
const lengths = Array.from({ length: count }).map(() => readU32());
|
821
|
-
/** @type {(Buffer | LazyFunction<
|
814
|
+
/** @type {(Buffer | LazyFunction<SerializedType, DeserializedType>)[]} */
|
822
815
|
const content = [];
|
823
816
|
for (let l of lengths) {
|
824
817
|
if (l === 0) {
|
825
818
|
if (typeof currentBuffer !== "function") {
|
826
819
|
throw new Error("Unexpected non-lazy element in stream");
|
827
820
|
}
|
828
|
-
content.push(
|
829
|
-
/** @type {LazyFunction<BufferSerializableType[]>} */
|
830
|
-
(currentBuffer)
|
831
|
-
);
|
821
|
+
content.push(currentBuffer);
|
832
822
|
currentDataItem++;
|
833
823
|
currentBuffer =
|
834
824
|
currentDataItem < data.length ? data[currentDataItem] : null;
|
@@ -1144,13 +1134,7 @@ class BinaryMiddleware extends SerializerMiddleware {
|
|
1144
1134
|
let result = [];
|
1145
1135
|
while (currentBuffer !== null) {
|
1146
1136
|
if (typeof currentBuffer === "function") {
|
1147
|
-
result.push(
|
1148
|
-
this._deserializeLazy(
|
1149
|
-
/** @type {LazyFunction<SerializedType>} */
|
1150
|
-
(currentBuffer),
|
1151
|
-
context
|
1152
|
-
)
|
1153
|
-
);
|
1137
|
+
result.push(this._deserializeLazy(currentBuffer, context));
|
1154
1138
|
currentDataItem++;
|
1155
1139
|
currentBuffer =
|
1156
1140
|
currentDataItem < data.length ? data[currentDataItem] : null;
|
@@ -7,6 +7,8 @@
|
|
7
7
|
/** @typedef {import("./ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
|
8
8
|
/** @typedef {import("./ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
|
9
9
|
|
10
|
+
/** @typedef {Error & { cause?: unknown }} ErrorWithCause */
|
11
|
+
|
10
12
|
class ErrorObjectSerializer {
|
11
13
|
/**
|
12
14
|
* @param {ErrorConstructor | EvalErrorConstructor | RangeErrorConstructor | ReferenceErrorConstructor | SyntaxErrorConstructor | TypeErrorConstructor} Type error type
|
@@ -22,7 +24,10 @@ class ErrorObjectSerializer {
|
|
22
24
|
serialize(obj, context) {
|
23
25
|
context.write(obj.message);
|
24
26
|
context.write(obj.stack);
|
25
|
-
context.write(
|
27
|
+
context.write(
|
28
|
+
/** @type {ErrorWithCause} */
|
29
|
+
(obj).cause
|
30
|
+
);
|
26
31
|
}
|
27
32
|
|
28
33
|
/**
|
@@ -34,7 +39,7 @@ class ErrorObjectSerializer {
|
|
34
39
|
|
35
40
|
err.message = context.read();
|
36
41
|
err.stack = context.read();
|
37
|
-
/** @type {
|
42
|
+
/** @type {ErrorWithCause} */
|
38
43
|
(err).cause = context.read();
|
39
44
|
|
40
45
|
return err;
|