webpack 5.95.0 → 5.96.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 +1 -1
- package/lib/AsyncDependenciesBlock.js +1 -1
- package/lib/BannerPlugin.js +2 -1
- package/lib/Chunk.js +30 -0
- package/lib/ChunkGraph.js +11 -6
- package/lib/ChunkGroup.js +2 -2
- package/lib/CleanPlugin.js +4 -5
- package/lib/CodeGenerationResults.js +6 -5
- package/lib/Compilation.js +71 -48
- package/lib/Compiler.js +7 -5
- package/lib/ConcatenationScope.js +7 -20
- package/lib/ContextModule.js +7 -8
- package/lib/CssModule.js +25 -21
- package/lib/DefinePlugin.js +14 -8
- package/lib/DelegatedModule.js +3 -3
- package/lib/DllModule.js +4 -4
- package/lib/DynamicEntryPlugin.js +29 -22
- package/lib/EvalDevToolModulePlugin.js +5 -2
- package/lib/EvalSourceMapDevToolPlugin.js +5 -2
- package/lib/ExternalModule.js +40 -7
- package/lib/ExternalModuleFactoryPlugin.js +33 -9
- package/lib/FileSystemInfo.js +12 -8
- package/lib/Generator.js +5 -4
- package/lib/HotModuleReplacementPlugin.js +8 -6
- package/lib/IgnorePlugin.js +19 -1
- package/lib/LoaderOptionsPlugin.js +3 -1
- package/lib/Module.js +9 -8
- package/lib/ModuleSourceTypesConstants.js +100 -0
- package/lib/NormalModule.js +27 -17
- package/lib/NormalModuleFactory.js +38 -22
- package/lib/OptionsApply.js +12 -1
- package/lib/ProgressPlugin.js +50 -10
- package/lib/RawModule.js +3 -4
- package/lib/RuntimeModule.js +3 -4
- package/lib/RuntimePlugin.js +11 -4
- package/lib/RuntimeTemplate.js +13 -42
- package/lib/SourceMapDevToolPlugin.js +10 -7
- package/lib/Watching.js +2 -2
- package/lib/WebpackOptionsApply.js +42 -21
- package/lib/asset/AssetGenerator.js +347 -194
- package/lib/asset/AssetModulesPlugin.js +2 -1
- package/lib/asset/AssetSourceGenerator.js +82 -27
- package/lib/asset/RawDataUrlModule.js +5 -4
- package/lib/buildChunkGraph.js +2 -2
- package/lib/cache/PackFileCacheStrategy.js +69 -31
- package/lib/cache/ResolverCachePlugin.js +248 -173
- package/lib/config/defaults.js +134 -126
- package/lib/container/ContainerEntryModule.js +3 -4
- package/lib/container/ContainerPlugin.js +8 -0
- package/lib/container/FallbackModule.js +2 -2
- package/lib/container/HoistContainerReferencesPlugin.js +250 -0
- package/lib/container/ModuleFederationPlugin.js +38 -1
- package/lib/container/RemoteModule.js +4 -2
- package/lib/container/RemoteRuntimeModule.js +4 -2
- package/lib/css/CssExportsGenerator.js +16 -12
- package/lib/css/CssGenerator.js +22 -16
- package/lib/css/CssLoadingRuntimeModule.js +7 -6
- package/lib/css/CssModulesPlugin.js +122 -77
- package/lib/css/CssParser.js +655 -526
- package/lib/css/walkCssTokens.js +1168 -338
- package/lib/debug/ProfilingPlugin.js +5 -0
- package/lib/dependencies/CommonJsExportsParserPlugin.js +5 -2
- package/lib/dependencies/CommonJsImportsParserPlugin.js +3 -6
- package/lib/dependencies/CssExportDependency.js +3 -3
- package/lib/dependencies/CssLocalIdentifierDependency.js +26 -17
- package/lib/dependencies/CssUrlDependency.js +33 -3
- package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +3 -3
- package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +39 -14
- package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +15 -82
- package/lib/dependencies/HarmonyImportSpecifierDependency.js +5 -2
- package/lib/dependencies/ImportParserPlugin.js +9 -7
- package/lib/dependencies/LoaderPlugin.js +19 -0
- package/lib/dependencies/SystemPlugin.js +2 -1
- package/lib/dependencies/URLPlugin.js +7 -1
- package/lib/dependencies/WorkerPlugin.js +1 -1
- package/lib/esm/ModuleChunkLoadingRuntimeModule.js +4 -2
- package/lib/hmr/HotModuleReplacement.runtime.js +1 -0
- package/lib/hmr/JavascriptHotModuleReplacement.runtime.js +1 -0
- package/lib/hmr/LazyCompilationPlugin.js +16 -4
- package/lib/hmr/lazyCompilationBackend.js +1 -7
- package/lib/index.js +35 -6
- package/lib/javascript/EnableChunkLoadingPlugin.js +2 -2
- package/lib/javascript/JavascriptGenerator.js +8 -8
- package/lib/javascript/JavascriptModulesPlugin.js +126 -73
- package/lib/javascript/JavascriptParser.js +338 -117
- package/lib/json/JsonGenerator.js +5 -5
- package/lib/library/EnableLibraryPlugin.js +2 -2
- package/lib/library/ExportPropertyLibraryPlugin.js +1 -1
- package/lib/library/UmdLibraryPlugin.js +16 -8
- package/lib/logging/Logger.js +11 -11
- package/lib/logging/createConsoleLogger.js +14 -14
- package/lib/logging/truncateArgs.js +1 -1
- package/lib/node/NodeWatchFileSystem.js +3 -1
- package/lib/node/ReadFileCompileAsyncWasmPlugin.js +20 -18
- package/lib/node/ReadFileCompileWasmPlugin.js +1 -2
- package/lib/node/nodeConsole.js +11 -8
- package/lib/optimize/AggressiveSplittingPlugin.js +21 -7
- package/lib/optimize/ConcatenatedModule.js +43 -145
- package/lib/optimize/FlagIncludedChunksPlugin.js +6 -0
- package/lib/optimize/InnerGraphPlugin.js +57 -16
- package/lib/optimize/LimitChunkCountPlugin.js +2 -4
- package/lib/optimize/ModuleConcatenationPlugin.js +4 -2
- package/lib/optimize/RealContentHashPlugin.js +1 -1
- package/lib/optimize/SideEffectsFlagPlugin.js +6 -3
- package/lib/rules/RuleSetCompiler.js +2 -2
- package/lib/runtime/GetChunkFilenameRuntimeModule.js +2 -2
- package/lib/schemes/DataUriPlugin.js +1 -1
- package/lib/serialization/BinaryMiddleware.js +32 -19
- package/lib/serialization/ObjectMiddleware.js +23 -9
- package/lib/serialization/SerializerMiddleware.js +3 -2
- package/lib/serialization/types.js +2 -2
- package/lib/sharing/ConsumeSharedModule.js +2 -3
- package/lib/sharing/ConsumeSharedRuntimeModule.js +3 -1
- package/lib/sharing/ProvideSharedModule.js +2 -3
- package/lib/stats/DefaultStatsFactoryPlugin.js +22 -20
- package/lib/stats/StatsFactory.js +12 -12
- package/lib/stats/StatsPrinter.js +7 -7
- package/lib/util/AsyncQueue.js +17 -1
- package/lib/util/IterableHelpers.js +1 -1
- package/lib/util/SetHelpers.js +1 -1
- package/lib/util/cleverMerge.js +48 -24
- package/lib/util/concatenate.js +227 -0
- package/lib/util/create-schema-validation.js +22 -9
- package/lib/util/deprecation.js +86 -28
- package/lib/util/fs.js +9 -9
- package/lib/util/hash/wasm-hash.js +12 -1
- package/lib/util/magicComment.js +21 -0
- package/lib/util/makeSerializable.js +24 -1
- package/lib/util/memoize.js +2 -1
- package/lib/util/runtime.js +4 -1
- package/lib/util/semver.js +130 -23
- package/lib/wasm/EnableWasmLoadingPlugin.js +2 -2
- package/lib/wasm-async/AsyncWasmLoadingRuntimeModule.js +3 -3
- package/lib/wasm-async/AsyncWebAssemblyGenerator.js +5 -5
- package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +5 -5
- package/lib/wasm-sync/WebAssemblyGenerator.js +8 -9
- package/lib/wasm-sync/WebAssemblyJavascriptGenerator.js +5 -5
- package/lib/web/FetchCompileAsyncWasmPlugin.js +1 -2
- package/lib/web/FetchCompileWasmPlugin.js +1 -2
- package/lib/web/JsonpChunkLoadingRuntimeModule.js +6 -6
- package/package.json +17 -18
- package/schemas/WebpackOptions.check.js +1 -1
- package/schemas/WebpackOptions.json +8 -2
- package/types.d.ts +801 -259
- package/lib/util/mergeScope.js +0 -76
@@ -9,10 +9,12 @@ const util = require("util");
|
|
9
9
|
const ExternalModule = require("./ExternalModule");
|
10
10
|
const ContextElementDependency = require("./dependencies/ContextElementDependency");
|
11
11
|
const CssImportDependency = require("./dependencies/CssImportDependency");
|
12
|
+
const CssUrlDependency = require("./dependencies/CssUrlDependency");
|
12
13
|
const HarmonyImportDependency = require("./dependencies/HarmonyImportDependency");
|
13
14
|
const ImportDependency = require("./dependencies/ImportDependency");
|
14
15
|
const { resolveByProperty, cachedSetProperty } = require("./util/cleverMerge");
|
15
16
|
|
17
|
+
/** @typedef {import("../declarations/WebpackOptions").ExternalItemFunctionData} ExternalItemFunctionData */
|
16
18
|
/** @typedef {import("../declarations/WebpackOptions").Externals} Externals */
|
17
19
|
/** @typedef {import("./Compilation").DepConstructor} DepConstructor */
|
18
20
|
/** @typedef {import("./ExternalModule").DependencyMeta} DependencyMeta */
|
@@ -24,6 +26,12 @@ const EMPTY_RESOLVE_OPTIONS = {};
|
|
24
26
|
|
25
27
|
// TODO webpack 6 remove this
|
26
28
|
const callDeprecatedExternals = util.deprecate(
|
29
|
+
/**
|
30
|
+
* @param {TODO} externalsFunction externals function
|
31
|
+
* @param {string} context context
|
32
|
+
* @param {string} request request
|
33
|
+
* @param {(err: Error | null | undefined, value: ExternalValue | undefined, ty: ExternalType | undefined) => void} cb cb
|
34
|
+
*/
|
27
35
|
(externalsFunction, context, request, cb) => {
|
28
36
|
// eslint-disable-next-line no-useless-call
|
29
37
|
externalsFunction.call(null, context, request, cb);
|
@@ -35,15 +43,16 @@ const callDeprecatedExternals = util.deprecate(
|
|
35
43
|
const cache = new WeakMap();
|
36
44
|
|
37
45
|
/**
|
38
|
-
* @
|
46
|
+
* @template {object} T
|
47
|
+
* @param {T} obj obj
|
39
48
|
* @param {TODO} layer layer
|
40
|
-
* @returns {
|
49
|
+
* @returns {Omit<T, "byLayer">} result
|
41
50
|
*/
|
42
51
|
const resolveLayer = (obj, layer) => {
|
43
|
-
let map = cache.get(obj);
|
52
|
+
let map = cache.get(/** @type {object} */ (obj));
|
44
53
|
if (map === undefined) {
|
45
54
|
map = new Map();
|
46
|
-
cache.set(obj, map);
|
55
|
+
cache.set(/** @type {object} */ (obj), map);
|
47
56
|
} else {
|
48
57
|
const cacheEntry = map.get(layer);
|
49
58
|
if (cacheEntry !== undefined) return cacheEntry;
|
@@ -53,8 +62,8 @@ const resolveLayer = (obj, layer) => {
|
|
53
62
|
return result;
|
54
63
|
};
|
55
64
|
|
56
|
-
/** @typedef {string|string[]|boolean|Record<string, string|string[]>} ExternalValue */
|
57
|
-
/** @typedef {string|undefined} ExternalType */
|
65
|
+
/** @typedef {string | string[] | boolean | Record<string, string | string[]>} ExternalValue */
|
66
|
+
/** @typedef {string | undefined} ExternalType */
|
58
67
|
|
59
68
|
class ExternalModuleFactoryPlugin {
|
60
69
|
/**
|
@@ -117,6 +126,8 @@ class ExternalModuleFactoryPlugin {
|
|
117
126
|
}
|
118
127
|
}
|
119
128
|
|
129
|
+
const resolvedType = /** @type {string} */ (type || globalType);
|
130
|
+
|
120
131
|
// TODO make it pluggable/add hooks to `ExternalModule` to allow output modules own externals?
|
121
132
|
/** @type {DependencyMeta | undefined} */
|
122
133
|
let dependencyMeta;
|
@@ -145,12 +156,18 @@ class ExternalModuleFactoryPlugin {
|
|
145
156
|
};
|
146
157
|
}
|
147
158
|
|
159
|
+
if (
|
160
|
+
resolvedType === "asset" &&
|
161
|
+
dependency instanceof CssUrlDependency
|
162
|
+
) {
|
163
|
+
dependencyMeta = { sourceType: "css-url" };
|
164
|
+
}
|
165
|
+
|
148
166
|
callback(
|
149
167
|
null,
|
150
168
|
new ExternalModule(
|
151
169
|
externalConfig,
|
152
|
-
|
153
|
-
(type || globalType),
|
170
|
+
resolvedType,
|
154
171
|
dependency.request,
|
155
172
|
dependencyMeta
|
156
173
|
)
|
@@ -204,6 +221,12 @@ class ExternalModuleFactoryPlugin {
|
|
204
221
|
return handleExternal(dependency.request, undefined, callback);
|
205
222
|
}
|
206
223
|
} else if (typeof externals === "function") {
|
224
|
+
/**
|
225
|
+
* @param {Error | null | undefined} err err
|
226
|
+
* @param {ExternalValue=} value value
|
227
|
+
* @param {ExternalType=} type type
|
228
|
+
* @returns {void}
|
229
|
+
*/
|
207
230
|
const cb = (err, value, type) => {
|
208
231
|
if (err) return callback(err);
|
209
232
|
if (value !== undefined) {
|
@@ -250,7 +273,8 @@ class ExternalModuleFactoryPlugin {
|
|
250
273
|
context,
|
251
274
|
request,
|
252
275
|
resolveContext,
|
253
|
-
|
276
|
+
/** @type {TODO} */
|
277
|
+
(callback)
|
254
278
|
);
|
255
279
|
} else {
|
256
280
|
return new Promise((resolve, reject) => {
|
package/lib/FileSystemInfo.js
CHANGED
@@ -3631,8 +3631,7 @@ class FileSystemInfo {
|
|
3631
3631
|
this._readContext(
|
3632
3632
|
{
|
3633
3633
|
path,
|
3634
|
-
fromImmutablePath: () =>
|
3635
|
-
/** @type {ContextHash} */ (/** @type {unknown} */ ("")),
|
3634
|
+
fromImmutablePath: () => /** @type {ContextHash | ""} */ (""),
|
3636
3635
|
fromManagedItem: info => info || "",
|
3637
3636
|
fromSymlink: (file, target, callback) => {
|
3638
3637
|
callback(
|
@@ -3773,18 +3772,23 @@ class FileSystemInfo {
|
|
3773
3772
|
this._readContext(
|
3774
3773
|
{
|
3775
3774
|
path,
|
3776
|
-
fromImmutablePath: () =>
|
3775
|
+
fromImmutablePath: () =>
|
3776
|
+
/** @type {ContextTimestampAndHash | null} */ (null),
|
3777
3777
|
fromManagedItem: info => ({
|
3778
3778
|
safeTime: 0,
|
3779
3779
|
timestampHash: info,
|
3780
3780
|
hash: info || ""
|
3781
3781
|
}),
|
3782
3782
|
fromSymlink: (file, target, callback) => {
|
3783
|
-
callback(
|
3784
|
-
|
3785
|
-
|
3786
|
-
|
3787
|
-
|
3783
|
+
callback(
|
3784
|
+
null,
|
3785
|
+
/** @type {TODO} */
|
3786
|
+
({
|
3787
|
+
timestampHash: target,
|
3788
|
+
hash: target,
|
3789
|
+
symlinks: new Set([target])
|
3790
|
+
})
|
3791
|
+
);
|
3788
3792
|
},
|
3789
3793
|
fromFile: (file, stat, callback) => {
|
3790
3794
|
this._getFileTimestampAndHash(file, callback);
|
package/lib/Generator.js
CHANGED
@@ -14,6 +14,7 @@
|
|
14
14
|
/** @typedef {import("./DependencyTemplates")} DependencyTemplates */
|
15
15
|
/** @typedef {import("./Module").ConcatenationBailoutReasonContext} ConcatenationBailoutReasonContext */
|
16
16
|
/** @typedef {import("./Module").RuntimeRequirements} RuntimeRequirements */
|
17
|
+
/** @typedef {import("./Module").SourceTypes} SourceTypes */
|
17
18
|
/** @typedef {import("./ModuleGraph")} ModuleGraph */
|
18
19
|
/** @typedef {import("./NormalModule")} NormalModule */
|
19
20
|
/** @typedef {import("./RuntimeTemplate")} RuntimeTemplate */
|
@@ -55,7 +56,7 @@ class Generator {
|
|
55
56
|
/**
|
56
57
|
* @abstract
|
57
58
|
* @param {NormalModule} module fresh module
|
58
|
-
* @returns {
|
59
|
+
* @returns {SourceTypes} available types (do not mutate)
|
59
60
|
*/
|
60
61
|
getTypes(module) {
|
61
62
|
const AbstractMethodError = require("./AbstractMethodError");
|
@@ -79,7 +80,7 @@ class Generator {
|
|
79
80
|
* @abstract
|
80
81
|
* @param {NormalModule} module module for which the code should be generated
|
81
82
|
* @param {GenerateContext} generateContext context for generate
|
82
|
-
* @returns {Source} generated code
|
83
|
+
* @returns {Source | null} generated code
|
83
84
|
*/
|
84
85
|
generate(
|
85
86
|
module,
|
@@ -119,7 +120,7 @@ class ByTypeGenerator extends Generator {
|
|
119
120
|
|
120
121
|
/**
|
121
122
|
* @param {NormalModule} module fresh module
|
122
|
-
* @returns {
|
123
|
+
* @returns {SourceTypes} available types (do not mutate)
|
123
124
|
*/
|
124
125
|
getTypes(module) {
|
125
126
|
return this._types;
|
@@ -139,7 +140,7 @@ class ByTypeGenerator extends Generator {
|
|
139
140
|
/**
|
140
141
|
* @param {NormalModule} module module for which the code should be generated
|
141
142
|
* @param {GenerateContext} generateContext context for generate
|
142
|
-
* @returns {Source} generated code
|
143
|
+
* @returns {Source | null} generated code
|
143
144
|
*/
|
144
145
|
generate(module, generateContext) {
|
145
146
|
const type = generateContext.type;
|
@@ -44,6 +44,7 @@ const {
|
|
44
44
|
|
45
45
|
/** @typedef {import("estree").CallExpression} CallExpression */
|
46
46
|
/** @typedef {import("estree").Expression} Expression */
|
47
|
+
/** @typedef {import("estree").SpreadElement} SpreadElement */
|
47
48
|
/** @typedef {import("../declarations/WebpackOptions").OutputNormalized} OutputNormalized */
|
48
49
|
/** @typedef {import("./Chunk")} Chunk */
|
49
50
|
/** @typedef {import("./Chunk").ChunkId} ChunkId */
|
@@ -60,8 +61,8 @@ const {
|
|
60
61
|
|
61
62
|
/**
|
62
63
|
* @typedef {object} HMRJavascriptParserHooks
|
63
|
-
* @property {SyncBailHook<[
|
64
|
-
* @property {SyncBailHook<[
|
64
|
+
* @property {SyncBailHook<[Expression | SpreadElement, string[]], void>} hotAcceptCallback
|
65
|
+
* @property {SyncBailHook<[CallExpression, string[]], void>} hotAcceptWithoutCallback
|
65
66
|
*/
|
66
67
|
|
67
68
|
/** @typedef {{ updatedChunkIds: Set<ChunkId>, removedChunkIds: Set<ChunkId>, removedModules: Set<Module>, filename: string, assetInfo: AssetInfo }} HotUpdateMainContentByRuntimeItem */
|
@@ -133,10 +134,9 @@ class HotModuleReplacementPlugin {
|
|
133
134
|
/** @type {BuildInfo} */
|
134
135
|
(module.buildInfo).moduleConcatenationBailout =
|
135
136
|
"Hot Module Replacement";
|
137
|
+
|
136
138
|
if (expr.arguments.length >= 1) {
|
137
|
-
const arg = parser.evaluateExpression(
|
138
|
-
/** @type {Expression} */ (expr.arguments[0])
|
139
|
-
);
|
139
|
+
const arg = parser.evaluateExpression(expr.arguments[0]);
|
140
140
|
/** @type {BasicEvaluatedExpression[]} */
|
141
141
|
let params = [];
|
142
142
|
if (arg.isString()) {
|
@@ -686,7 +686,9 @@ class HotModuleReplacementPlugin {
|
|
686
686
|
if (backCompat)
|
687
687
|
ChunkGraph.setChunkGraphForChunk(hotUpdateChunk, chunkGraph);
|
688
688
|
hotUpdateChunk.id = chunkId;
|
689
|
-
hotUpdateChunk.runtime =
|
689
|
+
hotUpdateChunk.runtime = currentChunk
|
690
|
+
? currentChunk.runtime
|
691
|
+
: newRuntime;
|
690
692
|
if (currentChunk) {
|
691
693
|
for (const group of currentChunk.groupsIterable)
|
692
694
|
hotUpdateChunk.addGroup(group);
|
package/lib/IgnorePlugin.js
CHANGED
@@ -5,6 +5,8 @@
|
|
5
5
|
|
6
6
|
"use strict";
|
7
7
|
|
8
|
+
const RawModule = require("./RawModule");
|
9
|
+
const EntryDependency = require("./dependencies/EntryDependency");
|
8
10
|
const createSchemaValidation = require("./util/create-schema-validation");
|
9
11
|
|
10
12
|
/** @typedef {import("../declarations/plugins/IgnorePlugin").IgnorePluginOptions} IgnorePluginOptions */
|
@@ -73,7 +75,23 @@ class IgnorePlugin {
|
|
73
75
|
*/
|
74
76
|
apply(compiler) {
|
75
77
|
compiler.hooks.normalModuleFactory.tap("IgnorePlugin", nmf => {
|
76
|
-
nmf.hooks.beforeResolve.tap("IgnorePlugin",
|
78
|
+
nmf.hooks.beforeResolve.tap("IgnorePlugin", resolveData => {
|
79
|
+
const result = this.checkIgnore(resolveData);
|
80
|
+
|
81
|
+
if (
|
82
|
+
result === false &&
|
83
|
+
resolveData.dependencies.length > 0 &&
|
84
|
+
resolveData.dependencies[0] instanceof EntryDependency
|
85
|
+
) {
|
86
|
+
resolveData.ignoredModule = new RawModule(
|
87
|
+
"",
|
88
|
+
"ignored-entry-module",
|
89
|
+
"(ignored-entry-module)"
|
90
|
+
);
|
91
|
+
}
|
92
|
+
|
93
|
+
return result;
|
94
|
+
});
|
77
95
|
});
|
78
96
|
compiler.hooks.contextModuleFactory.tap("IgnorePlugin", cmf => {
|
79
97
|
cmf.hooks.beforeResolve.tap("IgnorePlugin", this.checkIgnore);
|
package/lib/Module.js
CHANGED
@@ -9,6 +9,7 @@ const util = require("util");
|
|
9
9
|
const ChunkGraph = require("./ChunkGraph");
|
10
10
|
const DependenciesBlock = require("./DependenciesBlock");
|
11
11
|
const ModuleGraph = require("./ModuleGraph");
|
12
|
+
const { JS_TYPES } = require("./ModuleSourceTypesConstants");
|
12
13
|
const RuntimeGlobals = require("./RuntimeGlobals");
|
13
14
|
const { first } = require("./util/SetHelpers");
|
14
15
|
const { compareChunksById } = require("./util/comparators");
|
@@ -23,7 +24,6 @@ const makeSerializable = require("./util/makeSerializable");
|
|
23
24
|
/** @typedef {import("./CodeGenerationResults")} CodeGenerationResults */
|
24
25
|
/** @typedef {import("./Compilation")} Compilation */
|
25
26
|
/** @typedef {import("./Compilation").AssetInfo} AssetInfo */
|
26
|
-
/** @typedef {import("./Compilation").ValueCacheVersion} ValueCacheVersion */
|
27
27
|
/** @typedef {import("./ConcatenationScope")} ConcatenationScope */
|
28
28
|
/** @typedef {import("./Dependency")} Dependency */
|
29
29
|
/** @typedef {import("./Dependency").UpdateHashContext} UpdateHashContext */
|
@@ -56,6 +56,8 @@ const makeSerializable = require("./util/makeSerializable");
|
|
56
56
|
* @property {string=} type the type of source that should be generated
|
57
57
|
*/
|
58
58
|
|
59
|
+
/** @typedef {ReadonlySet<string>} SourceTypes */
|
60
|
+
|
59
61
|
// TODO webpack 6: compilation will be required in CodeGenerationContext
|
60
62
|
/**
|
61
63
|
* @typedef {object} CodeGenerationContext
|
@@ -67,7 +69,7 @@ const makeSerializable = require("./util/makeSerializable");
|
|
67
69
|
* @property {ConcatenationScope=} concatenationScope when in concatenated module, information about other concatenated modules
|
68
70
|
* @property {CodeGenerationResults | undefined} codeGenerationResults code generation results of other modules (need to have a codeGenerationDependency to use that)
|
69
71
|
* @property {Compilation=} compilation the compilation
|
70
|
-
* @property {
|
72
|
+
* @property {SourceTypes=} sourceTypes source types
|
71
73
|
*/
|
72
74
|
|
73
75
|
/**
|
@@ -114,18 +116,20 @@ const makeSerializable = require("./util/makeSerializable");
|
|
114
116
|
* @property {LazySet<string>=} contextDependencies
|
115
117
|
* @property {LazySet<string>=} missingDependencies
|
116
118
|
* @property {LazySet<string>=} buildDependencies
|
117
|
-
* @property {
|
119
|
+
* @property {ValueCacheVersions=} valueDependencies
|
118
120
|
* @property {TODO=} hash
|
119
121
|
* @property {Record<string, Source>=} assets
|
120
122
|
* @property {Map<string, AssetInfo | undefined>=} assetsInfo
|
121
123
|
* @property {(Snapshot | null)=} snapshot
|
122
124
|
*/
|
123
125
|
|
126
|
+
/** @typedef {Map<string, string | Set<string>>} ValueCacheVersions */
|
127
|
+
|
124
128
|
/**
|
125
129
|
* @typedef {object} NeedBuildContext
|
126
130
|
* @property {Compilation} compilation
|
127
131
|
* @property {FileSystemInfo} fileSystemInfo
|
128
|
-
* @property {
|
132
|
+
* @property {ValueCacheVersions} valueCacheVersions
|
129
133
|
*/
|
130
134
|
|
131
135
|
/** @typedef {KnownBuildMeta & Record<string, any>} BuildMeta */
|
@@ -136,8 +140,6 @@ const makeSerializable = require("./util/makeSerializable");
|
|
136
140
|
* @property {boolean=} sideEffectFree
|
137
141
|
*/
|
138
142
|
|
139
|
-
/** @typedef {Set<string>} SourceTypes */
|
140
|
-
|
141
143
|
/** @typedef {{ factoryMeta: FactoryMeta | undefined, resolveOptions: ResolveOptions | undefined }} UnsafeCacheData */
|
142
144
|
|
143
145
|
const EMPTY_RESOLVE_OPTIONS = {};
|
@@ -145,7 +147,6 @@ const EMPTY_RESOLVE_OPTIONS = {};
|
|
145
147
|
let debugId = 1000;
|
146
148
|
|
147
149
|
const DEFAULT_TYPES_UNKNOWN = new Set(["unknown"]);
|
148
|
-
const DEFAULT_TYPES_JS = new Set(["javascript"]);
|
149
150
|
|
150
151
|
const deprecatedNeedRebuild = util.deprecate(
|
151
152
|
/**
|
@@ -873,7 +874,7 @@ class Module extends DependenciesBlock {
|
|
873
874
|
if (this.source === Module.prototype.source) {
|
874
875
|
return DEFAULT_TYPES_UNKNOWN;
|
875
876
|
}
|
876
|
-
return
|
877
|
+
return JS_TYPES;
|
877
878
|
}
|
878
879
|
|
879
880
|
/**
|
@@ -0,0 +1,100 @@
|
|
1
|
+
/*
|
2
|
+
MIT License http://www.opensource.org/licenses/mit-license.php
|
3
|
+
Author Alexander Akait @alexander-akait
|
4
|
+
*/
|
5
|
+
|
6
|
+
"use strict";
|
7
|
+
|
8
|
+
/**
|
9
|
+
* @type {ReadonlySet<never>}
|
10
|
+
*/
|
11
|
+
const NO_TYPES = new Set();
|
12
|
+
|
13
|
+
/**
|
14
|
+
* @type {ReadonlySet<"asset">}
|
15
|
+
*/
|
16
|
+
const ASSET_TYPES = new Set(["asset"]);
|
17
|
+
|
18
|
+
/**
|
19
|
+
* @type {ReadonlySet<"asset" | "javascript" | "asset">}
|
20
|
+
*/
|
21
|
+
const ASSET_AND_JS_TYPES = new Set(["asset", "javascript"]);
|
22
|
+
|
23
|
+
/**
|
24
|
+
* @type {ReadonlySet<"css-url" | "asset">}
|
25
|
+
*/
|
26
|
+
const ASSET_AND_CSS_URL_TYPES = new Set(["asset", "css-url"]);
|
27
|
+
|
28
|
+
/**
|
29
|
+
* @type {ReadonlySet<"javascript" | "css-url" | "asset">}
|
30
|
+
*/
|
31
|
+
const ASSET_AND_JS_AND_CSS_URL_TYPES = new Set([
|
32
|
+
"asset",
|
33
|
+
"javascript",
|
34
|
+
"css-url"
|
35
|
+
]);
|
36
|
+
|
37
|
+
/**
|
38
|
+
* @type {ReadonlySet<"javascript">}
|
39
|
+
*/
|
40
|
+
const JS_TYPES = new Set(["javascript"]);
|
41
|
+
|
42
|
+
/**
|
43
|
+
* @type {ReadonlySet<"javascript" | "css-url">}
|
44
|
+
*/
|
45
|
+
const JS_AND_CSS_URL_TYPES = new Set(["javascript", "css-url"]);
|
46
|
+
|
47
|
+
/**
|
48
|
+
* @type {ReadonlySet<"css">}
|
49
|
+
*/
|
50
|
+
const CSS_TYPES = new Set(["css"]);
|
51
|
+
|
52
|
+
/**
|
53
|
+
* @type {ReadonlySet<"css-url">}
|
54
|
+
*/
|
55
|
+
const CSS_URL_TYPES = new Set(["css-url"]);
|
56
|
+
/**
|
57
|
+
* @type {ReadonlySet<"css-import">}
|
58
|
+
*/
|
59
|
+
const CSS_IMPORT_TYPES = new Set(["css-import"]);
|
60
|
+
|
61
|
+
/**
|
62
|
+
* @type {ReadonlySet<"webassembly">}
|
63
|
+
*/
|
64
|
+
const WEBASSEMBLY_TYPES = new Set(["webassembly"]);
|
65
|
+
|
66
|
+
/**
|
67
|
+
* @type {ReadonlySet<"runtime">}
|
68
|
+
*/
|
69
|
+
const RUNTIME_TYPES = new Set(["runtime"]);
|
70
|
+
|
71
|
+
/**
|
72
|
+
* @type {ReadonlySet<"remote" | "share-init">}
|
73
|
+
*/
|
74
|
+
const REMOTE_AND_SHARE_INIT_TYPES = new Set(["remote", "share-init"]);
|
75
|
+
|
76
|
+
/**
|
77
|
+
* @type {ReadonlySet<"consume-shared">}
|
78
|
+
*/
|
79
|
+
const CONSUME_SHARED_TYPES = new Set(["consume-shared"]);
|
80
|
+
|
81
|
+
/**
|
82
|
+
* @type {ReadonlySet<"share-init">}
|
83
|
+
*/
|
84
|
+
const SHARED_INIT_TYPES = new Set(["share-init"]);
|
85
|
+
|
86
|
+
module.exports.NO_TYPES = NO_TYPES;
|
87
|
+
module.exports.JS_TYPES = JS_TYPES;
|
88
|
+
module.exports.JS_AND_CSS_URL_TYPES = JS_AND_CSS_URL_TYPES;
|
89
|
+
module.exports.ASSET_TYPES = ASSET_TYPES;
|
90
|
+
module.exports.ASSET_AND_JS_TYPES = ASSET_AND_JS_TYPES;
|
91
|
+
module.exports.ASSET_AND_CSS_URL_TYPES = ASSET_AND_CSS_URL_TYPES;
|
92
|
+
module.exports.ASSET_AND_JS_AND_CSS_URL_TYPES = ASSET_AND_JS_AND_CSS_URL_TYPES;
|
93
|
+
module.exports.CSS_TYPES = CSS_TYPES;
|
94
|
+
module.exports.CSS_URL_TYPES = CSS_URL_TYPES;
|
95
|
+
module.exports.CSS_IMPORT_TYPES = CSS_IMPORT_TYPES;
|
96
|
+
module.exports.WEBASSEMBLY_TYPES = WEBASSEMBLY_TYPES;
|
97
|
+
module.exports.RUNTIME_TYPES = RUNTIME_TYPES;
|
98
|
+
module.exports.REMOTE_AND_SHARE_INIT_TYPES = REMOTE_AND_SHARE_INIT_TYPES;
|
99
|
+
module.exports.CONSUME_SHARED_TYPES = CONSUME_SHARED_TYPES;
|
100
|
+
module.exports.SHARED_INIT_TYPES = SHARED_INIT_TYPES;
|
package/lib/NormalModule.js
CHANGED
@@ -65,12 +65,13 @@ const memoize = require("./util/memoize");
|
|
65
65
|
/** @typedef {import("./Module").KnownBuildInfo} KnownBuildInfo */
|
66
66
|
/** @typedef {import("./Module").LibIdentOptions} LibIdentOptions */
|
67
67
|
/** @typedef {import("./Module").NeedBuildContext} NeedBuildContext */
|
68
|
-
/** @typedef {import("./
|
68
|
+
/** @typedef {import("./Generator").SourceTypes} SourceTypes */
|
69
69
|
/** @typedef {import("./Module").UnsafeCacheData} UnsafeCacheData */
|
70
70
|
/** @typedef {import("./ModuleGraph")} ModuleGraph */
|
71
71
|
/** @typedef {import("./ModuleGraphConnection").ConnectionState} ConnectionState */
|
72
72
|
/** @typedef {import("./ModuleTypeConstants").JavaScriptModuleTypes} JavaScriptModuleTypes */
|
73
73
|
/** @typedef {import("./NormalModuleFactory")} NormalModuleFactory */
|
74
|
+
/** @typedef {import("./NormalModuleFactory").ResourceDataWithData} ResourceDataWithData */
|
74
75
|
/** @typedef {import("./Parser")} Parser */
|
75
76
|
/** @typedef {import("./RequestShortener")} RequestShortener */
|
76
77
|
/** @typedef {import("./ResolverFactory").ResolveContext} ResolveContext */
|
@@ -777,10 +778,10 @@ class NormalModule extends Module {
|
|
777
778
|
webpack: true,
|
778
779
|
sourceMap: Boolean(this.useSourceMap),
|
779
780
|
mode: options.mode || "production",
|
780
|
-
hashFunction: options.output.hashFunction,
|
781
|
-
hashDigest: options.output.hashDigest,
|
782
|
-
hashDigestLength: options.output.hashDigestLength,
|
783
|
-
hashSalt: options.output.hashSalt,
|
781
|
+
hashFunction: /** @type {TODO} */ (options.output.hashFunction),
|
782
|
+
hashDigest: /** @type {string} */ (options.output.hashDigest),
|
783
|
+
hashDigestLength: /** @type {number} */ (options.output.hashDigestLength),
|
784
|
+
hashSalt: /** @type {string} */ (options.output.hashSalt),
|
784
785
|
_module: this,
|
785
786
|
_compilation: compilation,
|
786
787
|
_compiler: compilation.compiler,
|
@@ -951,7 +952,7 @@ class NormalModule extends Module {
|
|
951
952
|
/** @type {LoaderContext<any>} */ (loaderContext)
|
952
953
|
);
|
953
954
|
} catch (err) {
|
954
|
-
processResult(err);
|
955
|
+
processResult(/** @type {Error} */ (err));
|
955
956
|
return;
|
956
957
|
}
|
957
958
|
|
@@ -965,6 +966,11 @@ class NormalModule extends Module {
|
|
965
966
|
resource: this.resource,
|
966
967
|
loaders: this.loaders,
|
967
968
|
context: loaderContext,
|
969
|
+
/**
|
970
|
+
* @param {LoaderContext<TODO>} loaderContext the loader context
|
971
|
+
* @param {string} resourcePath the resource Path
|
972
|
+
* @param {(err: Error | null, result?: string | Buffer) => void} callback callback
|
973
|
+
*/
|
968
974
|
processResource: (loaderContext, resourcePath, callback) => {
|
969
975
|
const resource = loaderContext.resource;
|
970
976
|
const scheme = getScheme(resource);
|
@@ -1601,24 +1607,28 @@ class NormalModule extends Module {
|
|
1601
1607
|
super.serialize(context);
|
1602
1608
|
}
|
1603
1609
|
|
1610
|
+
/**
|
1611
|
+
* @param {ObjectDeserializerContext} context context
|
1612
|
+
* @returns {TODO} Module
|
1613
|
+
*/
|
1604
1614
|
static deserialize(context) {
|
1605
1615
|
const obj = new NormalModule({
|
1606
1616
|
// will be deserialized by Module
|
1607
|
-
layer: null,
|
1617
|
+
layer: /** @type {EXPECTED_ANY} */ (null),
|
1608
1618
|
type: "",
|
1609
1619
|
// will be filled by updateCacheModule
|
1610
1620
|
resource: "",
|
1611
1621
|
context: "",
|
1612
|
-
request: null,
|
1613
|
-
userRequest: null,
|
1614
|
-
rawRequest: null,
|
1615
|
-
loaders: null,
|
1616
|
-
matchResource: null,
|
1617
|
-
parser: null,
|
1618
|
-
parserOptions: null,
|
1619
|
-
generator: null,
|
1620
|
-
generatorOptions: null,
|
1621
|
-
resolveOptions: null
|
1622
|
+
request: /** @type {EXPECTED_ANY} */ (null),
|
1623
|
+
userRequest: /** @type {EXPECTED_ANY} */ (null),
|
1624
|
+
rawRequest: /** @type {EXPECTED_ANY} */ (null),
|
1625
|
+
loaders: /** @type {EXPECTED_ANY} */ (null),
|
1626
|
+
matchResource: /** @type {EXPECTED_ANY} */ (null),
|
1627
|
+
parser: /** @type {EXPECTED_ANY} */ (null),
|
1628
|
+
parserOptions: /** @type {EXPECTED_ANY} */ (null),
|
1629
|
+
generator: /** @type {EXPECTED_ANY} */ (null),
|
1630
|
+
generatorOptions: /** @type {EXPECTED_ANY} */ (null),
|
1631
|
+
resolveOptions: /** @type {EXPECTED_ANY} */ (null)
|
1622
1632
|
});
|
1623
1633
|
obj.deserialize(context);
|
1624
1634
|
return obj;
|