webpack 5.99.7 → 5.99.9
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 +0 -3
- package/lib/CacheFacade.js +2 -1
- package/lib/ChunkGraph.js +0 -1
- package/lib/ChunkGroup.js +13 -6
- package/lib/Compilation.js +22 -33
- package/lib/ConstPlugin.js +61 -43
- package/lib/ContextModule.js +1 -1
- package/lib/ContextModuleFactory.js +1 -2
- package/lib/ContextReplacementPlugin.js +2 -1
- package/lib/CssModule.js +0 -1
- package/lib/DefinePlugin.js +2 -2
- package/lib/DelegatedModule.js +18 -8
- package/lib/DelegatedModuleFactoryPlugin.js +9 -7
- package/lib/Dependency.js +10 -11
- package/lib/EvalSourceMapDevToolPlugin.js +1 -1
- package/lib/ExportsInfo.js +35 -16
- package/lib/ExternalModule.js +6 -5
- package/lib/FileSystemInfo.js +2 -4
- package/lib/LibManifestPlugin.js +2 -2
- package/lib/ModuleFilenameHelpers.js +8 -4
- package/lib/NormalModule.js +38 -19
- package/lib/NormalModuleFactory.js +23 -18
- package/lib/RuntimePlugin.js +1 -1
- package/lib/SourceMapDevToolPlugin.js +2 -3
- package/lib/WebpackOptionsApply.js +1 -4
- package/lib/asset/AssetGenerator.js +13 -12
- package/lib/asset/AssetSourceGenerator.js +7 -5
- package/lib/config/defaults.js +10 -6
- package/lib/config/normalization.js +5 -5
- package/lib/css/CssModulesPlugin.js +2 -2
- package/lib/debug/ProfilingPlugin.js +18 -21
- package/lib/dependencies/CommonJsImportsParserPlugin.js +1 -1
- package/lib/dependencies/ContextElementDependency.js +1 -1
- package/lib/dependencies/CssLocalIdentifierDependency.js +2 -2
- package/lib/dependencies/CssUrlDependency.js +1 -1
- package/lib/dependencies/ModuleDependency.js +1 -1
- package/lib/dependencies/RequireContextPlugin.js +2 -1
- package/lib/dependencies/RequireEnsureDependenciesBlockParserPlugin.js +3 -0
- package/lib/dependencies/URLDependency.js +1 -1
- package/lib/dependencies/WorkerPlugin.js +2 -2
- package/lib/esm/ModuleChunkLoadingRuntimeModule.js +3 -3
- package/lib/hmr/JavascriptHotModuleReplacement.runtime.js +0 -1
- package/lib/index.js +11 -0
- package/lib/javascript/JavascriptModulesPlugin.js +2 -2
- package/lib/javascript/JavascriptParser.js +19 -5
- package/lib/json/JsonModulesPlugin.js +4 -4
- package/lib/library/AbstractLibraryPlugin.js +1 -1
- package/lib/library/ModuleLibraryPlugin.js +4 -1
- package/lib/node/nodeConsole.js +3 -2
- package/lib/optimize/AggressiveSplittingPlugin.js +1 -1
- package/lib/optimize/ConcatenatedModule.js +3 -1
- package/lib/optimize/ModuleConcatenationPlugin.js +2 -2
- package/lib/optimize/RuntimeChunkPlugin.js +5 -6
- package/lib/optimize/SideEffectsFlagPlugin.js +12 -7
- package/lib/optimize/SplitChunksPlugin.js +2 -2
- package/lib/rules/BasicEffectRulePlugin.js +1 -2
- package/lib/rules/ObjectMatcherRulePlugin.js +2 -1
- package/lib/rules/RuleSetCompiler.js +19 -5
- package/lib/rules/UseEffectRulePlugin.js +4 -6
- package/lib/schemes/DataUriPlugin.js +3 -1
- package/lib/schemes/HttpUriPlugin.js +154 -149
- package/lib/sharing/ProvideSharedPlugin.js +3 -1
- package/lib/stats/DefaultStatsPrinterPlugin.js +13 -13
- package/lib/util/createHash.js +3 -3
- package/package.json +45 -40
- package/schemas/WebpackOptions.check.d.ts +1 -1
- package/schemas/WebpackOptions.check.js +2 -2
- package/schemas/WebpackOptions.json +243 -24
- package/schemas/plugins/BannerPlugin.check.d.ts +1 -1
- package/schemas/plugins/BannerPlugin.check.js +1 -1
- package/schemas/plugins/DllPlugin.check.d.ts +1 -1
- package/schemas/plugins/DllPlugin.check.js +1 -1
- package/schemas/plugins/DllReferencePlugin.check.d.ts +1 -1
- package/schemas/plugins/DllReferencePlugin.check.js +1 -1
- package/schemas/plugins/HashedModuleIdsPlugin.check.d.ts +1 -1
- package/schemas/plugins/HashedModuleIdsPlugin.check.js +1 -1
- package/schemas/plugins/IgnorePlugin.check.d.ts +1 -1
- package/schemas/plugins/IgnorePlugin.check.js +1 -1
- package/schemas/plugins/LoaderOptionsPlugin.check.d.ts +1 -1
- package/schemas/plugins/LoaderOptionsPlugin.check.js +1 -1
- package/schemas/plugins/ProgressPlugin.check.d.ts +1 -1
- package/schemas/plugins/ProgressPlugin.check.js +1 -1
- package/schemas/plugins/SourceMapDevToolPlugin.check.d.ts +1 -1
- package/schemas/plugins/SourceMapDevToolPlugin.check.js +1 -1
- package/schemas/plugins/SourceMapDevToolPlugin.json +2 -2
- package/schemas/plugins/WatchIgnorePlugin.check.d.ts +1 -1
- package/schemas/plugins/WatchIgnorePlugin.check.js +1 -1
- package/schemas/plugins/asset/AssetGeneratorOptions.check.d.ts +1 -1
- package/schemas/plugins/asset/AssetGeneratorOptions.check.js +1 -1
- package/schemas/plugins/asset/AssetInlineGeneratorOptions.check.d.ts +1 -1
- package/schemas/plugins/asset/AssetInlineGeneratorOptions.check.js +1 -1
- package/schemas/plugins/asset/AssetParserOptions.check.d.ts +1 -1
- package/schemas/plugins/asset/AssetParserOptions.check.js +1 -1
- package/schemas/plugins/asset/AssetResourceGeneratorOptions.check.d.ts +1 -1
- package/schemas/plugins/asset/AssetResourceGeneratorOptions.check.js +1 -1
- package/schemas/plugins/container/ContainerPlugin.check.d.ts +1 -1
- package/schemas/plugins/container/ContainerPlugin.check.js +1 -1
- package/schemas/plugins/container/ContainerReferencePlugin.check.d.ts +1 -1
- package/schemas/plugins/container/ContainerReferencePlugin.check.js +1 -1
- package/schemas/plugins/container/ExternalsType.check.d.ts +1 -1
- package/schemas/plugins/container/ExternalsType.check.js +1 -1
- package/schemas/plugins/container/ModuleFederationPlugin.check.d.ts +1 -1
- package/schemas/plugins/container/ModuleFederationPlugin.check.js +1 -1
- package/schemas/plugins/css/CssAutoGeneratorOptions.check.d.ts +1 -1
- package/schemas/plugins/css/CssAutoGeneratorOptions.check.js +1 -1
- package/schemas/plugins/css/CssAutoParserOptions.check.d.ts +1 -1
- package/schemas/plugins/css/CssAutoParserOptions.check.js +1 -1
- package/schemas/plugins/css/CssGeneratorOptions.check.d.ts +1 -1
- package/schemas/plugins/css/CssGeneratorOptions.check.js +1 -1
- package/schemas/plugins/css/CssGlobalGeneratorOptions.check.d.ts +1 -1
- package/schemas/plugins/css/CssGlobalGeneratorOptions.check.js +1 -1
- package/schemas/plugins/css/CssGlobalParserOptions.check.d.ts +1 -1
- package/schemas/plugins/css/CssGlobalParserOptions.check.js +1 -1
- package/schemas/plugins/css/CssModuleGeneratorOptions.check.d.ts +1 -1
- package/schemas/plugins/css/CssModuleGeneratorOptions.check.js +1 -1
- package/schemas/plugins/css/CssModuleParserOptions.check.d.ts +1 -1
- package/schemas/plugins/css/CssModuleParserOptions.check.js +1 -1
- package/schemas/plugins/css/CssParserOptions.check.d.ts +1 -1
- package/schemas/plugins/css/CssParserOptions.check.js +1 -1
- package/schemas/plugins/debug/ProfilingPlugin.check.d.ts +1 -1
- package/schemas/plugins/debug/ProfilingPlugin.check.js +1 -1
- package/schemas/plugins/ids/OccurrenceChunkIdsPlugin.check.d.ts +1 -1
- package/schemas/plugins/ids/OccurrenceChunkIdsPlugin.check.js +1 -1
- package/schemas/plugins/ids/OccurrenceModuleIdsPlugin.check.d.ts +1 -1
- package/schemas/plugins/ids/OccurrenceModuleIdsPlugin.check.js +1 -1
- package/schemas/plugins/json/JsonModulesPluginGenerator.check.d.ts +7 -0
- package/schemas/plugins/{JsonModulesPluginGenerator.check.js → json/JsonModulesPluginGenerator.check.js} +1 -1
- package/schemas/plugins/json/JsonModulesPluginGenerator.json +3 -0
- package/schemas/plugins/json/JsonModulesPluginParser.check.d.ts +7 -0
- package/schemas/plugins/{JsonModulesPluginParser.check.js → json/JsonModulesPluginParser.check.js} +1 -1
- package/schemas/plugins/json/JsonModulesPluginParser.json +3 -0
- package/schemas/plugins/optimize/AggressiveSplittingPlugin.check.d.ts +1 -1
- package/schemas/plugins/optimize/AggressiveSplittingPlugin.check.js +1 -1
- package/schemas/plugins/optimize/LimitChunkCountPlugin.check.d.ts +1 -1
- package/schemas/plugins/optimize/LimitChunkCountPlugin.check.js +1 -1
- package/schemas/plugins/optimize/MergeDuplicateChunksPlugin.check.d.ts +1 -1
- package/schemas/plugins/optimize/MergeDuplicateChunksPlugin.check.js +1 -1
- package/schemas/plugins/optimize/MinChunkSizePlugin.check.d.ts +1 -1
- package/schemas/plugins/optimize/MinChunkSizePlugin.check.js +1 -1
- package/schemas/plugins/schemes/HttpUriPlugin.check.d.ts +1 -1
- package/schemas/plugins/schemes/HttpUriPlugin.check.js +1 -1
- package/schemas/plugins/sharing/ConsumeSharedPlugin.check.d.ts +1 -1
- package/schemas/plugins/sharing/ConsumeSharedPlugin.check.js +1 -1
- package/schemas/plugins/sharing/ProvideSharedPlugin.check.d.ts +1 -1
- package/schemas/plugins/sharing/ProvideSharedPlugin.check.js +1 -1
- package/schemas/plugins/sharing/SharePlugin.check.d.ts +1 -1
- package/schemas/plugins/sharing/SharePlugin.check.js +1 -1
- package/types.d.ts +468 -156
- package/schemas/plugins/JsonModulesPluginGenerator.check.d.ts +0 -7
- package/schemas/plugins/JsonModulesPluginGenerator.json +0 -11
- package/schemas/plugins/JsonModulesPluginParser.check.d.ts +0 -7
- package/schemas/plugins/JsonModulesPluginParser.json +0 -16
@@ -195,7 +195,7 @@ class AggressiveSplittingPlugin {
|
|
195
195
|
moveModuleBetween(chunkGraph, chunk, newChunk)(module);
|
196
196
|
}
|
197
197
|
chunk.split(newChunk);
|
198
|
-
chunk.name =
|
198
|
+
chunk.name = null;
|
199
199
|
}
|
200
200
|
fromAggressiveSplittingSet.add(newChunk);
|
201
201
|
chunkSplitDataMap.set(newChunk, splitData);
|
@@ -1739,7 +1739,9 @@ ${defineGetters}`
|
|
1739
1739
|
sourceType: "module"
|
1740
1740
|
});
|
1741
1741
|
} catch (_err) {
|
1742
|
-
const err =
|
1742
|
+
const err =
|
1743
|
+
/** @type {Error & { loc?: { line: number, column: number } }} */
|
1744
|
+
(_err);
|
1743
1745
|
if (
|
1744
1746
|
err.loc &&
|
1745
1747
|
typeof err.loc === "object" &&
|
@@ -398,9 +398,9 @@ class ModuleConcatenationPlugin {
|
|
398
398
|
newModule.build(
|
399
399
|
compiler.options,
|
400
400
|
compilation,
|
401
|
-
/** @type {
|
401
|
+
/** @type {EXPECTED_ANY} */
|
402
402
|
(null),
|
403
|
-
/** @type {
|
403
|
+
/** @type {EXPECTED_ANY} */
|
404
404
|
(null),
|
405
405
|
err => {
|
406
406
|
if (err) {
|
@@ -11,16 +11,15 @@
|
|
11
11
|
|
12
12
|
const PLUGIN_NAME = "RuntimeChunkPlugin";
|
13
13
|
|
14
|
+
/** @typedef {(entrypoint: { name: string }) => string} RuntimeChunkFunction */
|
15
|
+
|
14
16
|
class RuntimeChunkPlugin {
|
15
17
|
/**
|
16
|
-
* @param {{ name?:
|
18
|
+
* @param {{ name?: RuntimeChunkFunction }=} options options
|
17
19
|
*/
|
18
20
|
constructor(options) {
|
19
21
|
this.options = {
|
20
|
-
/**
|
21
|
-
* @param {Entrypoint} entrypoint entrypoint name
|
22
|
-
* @returns {string} runtime chunk name
|
23
|
-
*/
|
22
|
+
/** @type {RuntimeChunkFunction} */
|
24
23
|
name: entrypoint => `runtime~${entrypoint.name}`,
|
25
24
|
...options
|
26
25
|
};
|
@@ -41,7 +40,7 @@ class RuntimeChunkPlugin {
|
|
41
40
|
if (data.options.runtime === undefined && !data.options.dependOn) {
|
42
41
|
// Determine runtime chunk name
|
43
42
|
let name =
|
44
|
-
/** @type {string |
|
43
|
+
/** @type {string | RuntimeChunkFunction} */
|
45
44
|
(this.options.name);
|
46
45
|
if (typeof name === "function") {
|
47
46
|
name = name({ name: entryName });
|
@@ -105,7 +105,9 @@ class SideEffectsFlagPlugin {
|
|
105
105
|
}
|
106
106
|
const hasSideEffects = SideEffectsFlagPlugin.moduleHasSideEffects(
|
107
107
|
resolveData.relativePath,
|
108
|
-
|
108
|
+
/** @type {string | boolean | string[] | undefined} */ (
|
109
|
+
sideEffects
|
110
|
+
),
|
109
111
|
/** @type {CacheItem} */ (cache)
|
110
112
|
);
|
111
113
|
module.factoryMeta.sideEffectFree = !hasSideEffects;
|
@@ -145,7 +147,8 @@ class SideEffectsFlagPlugin {
|
|
145
147
|
if (
|
146
148
|
!parser.isPure(
|
147
149
|
statement.expression,
|
148
|
-
/** @type {Range} */
|
150
|
+
/** @type {Range} */
|
151
|
+
(statement.range)[0]
|
149
152
|
)
|
150
153
|
) {
|
151
154
|
sideEffectsStatement = statement;
|
@@ -157,7 +160,8 @@ class SideEffectsFlagPlugin {
|
|
157
160
|
if (
|
158
161
|
!parser.isPure(
|
159
162
|
statement.test,
|
160
|
-
/** @type {Range} */
|
163
|
+
/** @type {Range} */
|
164
|
+
(statement.range)[0]
|
161
165
|
)
|
162
166
|
) {
|
163
167
|
sideEffectsStatement = statement;
|
@@ -193,7 +197,8 @@ class SideEffectsFlagPlugin {
|
|
193
197
|
if (
|
194
198
|
!parser.isPure(
|
195
199
|
statement.discriminant,
|
196
|
-
/** @type {Range} */
|
200
|
+
/** @type {Range} */
|
201
|
+
(statement.range)[0]
|
197
202
|
)
|
198
203
|
) {
|
199
204
|
sideEffectsStatement = statement;
|
@@ -216,9 +221,9 @@ class SideEffectsFlagPlugin {
|
|
216
221
|
case "ExportDefaultDeclaration":
|
217
222
|
if (
|
218
223
|
!parser.isPure(
|
219
|
-
|
220
|
-
|
221
|
-
|
224
|
+
statement.declaration,
|
225
|
+
/** @type {Range} */
|
226
|
+
(statement.range)[0]
|
222
227
|
)
|
223
228
|
) {
|
224
229
|
sideEffectsStatement = statement;
|
@@ -21,6 +21,7 @@ const { makePathsRelative } = require("../util/identifier");
|
|
21
21
|
const memoize = require("../util/memoize");
|
22
22
|
const MinMaxSizeWarning = require("./MinMaxSizeWarning");
|
23
23
|
|
24
|
+
/** @typedef {import("../../declarations/WebpackOptions").HashFunction} HashFunction */
|
24
25
|
/** @typedef {import("../../declarations/WebpackOptions").OptimizationSplitChunksCacheGroup} OptimizationSplitChunksCacheGroup */
|
25
26
|
/** @typedef {import("../../declarations/WebpackOptions").OptimizationSplitChunksGetCacheGroups} OptimizationSplitChunksGetCacheGroups */
|
26
27
|
/** @typedef {import("../../declarations/WebpackOptions").OptimizationSplitChunksOptions} OptimizationSplitChunksOptions */
|
@@ -33,7 +34,6 @@ const MinMaxSizeWarning = require("./MinMaxSizeWarning");
|
|
33
34
|
/** @typedef {import("../Module")} Module */
|
34
35
|
/** @typedef {import("../ModuleGraph")} ModuleGraph */
|
35
36
|
/** @typedef {import("../TemplatedPathPlugin").TemplatePath} TemplatePath */
|
36
|
-
/** @typedef {import("../util/createHash").Algorithm} Algorithm */
|
37
37
|
/** @typedef {import("../util/deterministicGrouping").GroupedItems<Module>} DeterministicGroupingGroupedItemsForModule */
|
38
38
|
/** @typedef {import("../util/deterministicGrouping").Options<Module>} DeterministicGroupingOptionsForModule */
|
39
39
|
|
@@ -184,7 +184,7 @@ const hashFilename = (name, outputOptions) => {
|
|
184
184
|
const digest =
|
185
185
|
/** @type {string} */
|
186
186
|
(
|
187
|
-
createHash(/** @type {
|
187
|
+
createHash(/** @type {HashFunction} */ (outputOptions.hashFunction))
|
188
188
|
.update(name)
|
189
189
|
.digest(outputOptions.hashDigest)
|
190
190
|
);
|
@@ -37,8 +37,7 @@ class BasicEffectRulePlugin {
|
|
37
37
|
if (unhandledProperties.has(this.ruleProperty)) {
|
38
38
|
unhandledProperties.delete(this.ruleProperty);
|
39
39
|
|
40
|
-
const value =
|
41
|
-
rule[/** @type {keyof RuleSetRule} */ (this.ruleProperty)];
|
40
|
+
const value = rule[this.ruleProperty];
|
42
41
|
|
43
42
|
result.effects.push({
|
44
43
|
type: this.effectType,
|
@@ -8,6 +8,7 @@
|
|
8
8
|
/** @typedef {import("../../declarations/WebpackOptions").RuleSetConditionOrConditions} RuleSetConditionOrConditions */
|
9
9
|
/** @typedef {import("../../declarations/WebpackOptions").RuleSetRule} RuleSetRule */
|
10
10
|
/** @typedef {import("./RuleSetCompiler")} RuleSetCompiler */
|
11
|
+
/** @typedef {import("./RuleSetCompiler").EffectData} EffectData */
|
11
12
|
/** @typedef {import("./RuleSetCompiler").RuleCondition} RuleCondition */
|
12
13
|
/** @typedef {import("./RuleSetCompiler").RuleConditionFunction} RuleConditionFunction */
|
13
14
|
|
@@ -22,7 +23,7 @@
|
|
22
23
|
class ObjectMatcherRulePlugin {
|
23
24
|
/**
|
24
25
|
* @param {ObjectMatcherRuleKeys} ruleProperty the rule property
|
25
|
-
* @param {
|
26
|
+
* @param {keyof EffectData=} dataProperty the data property
|
26
27
|
* @param {RuleConditionFunction=} additionalConditionFunction need to check
|
27
28
|
*/
|
28
29
|
constructor(ruleProperty, dataProperty, additionalConditionFunction) {
|
@@ -13,7 +13,9 @@ const { SyncHook } = require("tapable");
|
|
13
13
|
|
14
14
|
/** @typedef {(Falsy | RuleSetRule)[]} RuleSetRules */
|
15
15
|
|
16
|
-
/**
|
16
|
+
/**
|
17
|
+
* @typedef {(value: EffectData[keyof EffectData]) => boolean} RuleConditionFunction
|
18
|
+
*/
|
17
19
|
|
18
20
|
/**
|
19
21
|
* @typedef {object} RuleCondition
|
@@ -29,7 +31,19 @@ const { SyncHook } = require("tapable");
|
|
29
31
|
*/
|
30
32
|
|
31
33
|
/**
|
32
|
-
* @typedef {
|
34
|
+
* @typedef {object} EffectData
|
35
|
+
* @property {string=} resource
|
36
|
+
* @property {string=} realResource
|
37
|
+
* @property {string=} resourceQuery
|
38
|
+
* @property {string=} resourceFragment
|
39
|
+
* @property {string=} scheme
|
40
|
+
* @property {ImportAttributes=} assertions
|
41
|
+
* @property {string=} mimetype
|
42
|
+
* @property {string} dependency
|
43
|
+
* @property {Record<string, EXPECTED_ANY>=} descriptionData
|
44
|
+
* @property {string=} compiler
|
45
|
+
* @property {string} issuer
|
46
|
+
* @property {string} issuerLayer
|
33
47
|
*/
|
34
48
|
|
35
49
|
/**
|
@@ -102,7 +116,7 @@ class RuleSetCompiler {
|
|
102
116
|
for (const condition of rule.conditions) {
|
103
117
|
const p = condition.property;
|
104
118
|
if (Array.isArray(p)) {
|
105
|
-
/** @type {EffectData |
|
119
|
+
/** @type {EffectData | EffectData[keyof EffectData] | undefined} */
|
106
120
|
let current = data;
|
107
121
|
for (const subProperty of p) {
|
108
122
|
if (
|
@@ -110,7 +124,7 @@ class RuleSetCompiler {
|
|
110
124
|
typeof current === "object" &&
|
111
125
|
Object.prototype.hasOwnProperty.call(current, subProperty)
|
112
126
|
) {
|
113
|
-
current = current[subProperty];
|
127
|
+
current = current[/** @type {keyof EffectData} */ (subProperty)];
|
114
128
|
} else {
|
115
129
|
current = undefined;
|
116
130
|
break;
|
@@ -121,7 +135,7 @@ class RuleSetCompiler {
|
|
121
135
|
continue;
|
122
136
|
}
|
123
137
|
} else if (p in data) {
|
124
|
-
const value = data[p];
|
138
|
+
const value = data[/** @type {keyof EffectData} */ (p)];
|
125
139
|
if (value !== undefined) {
|
126
140
|
if (!condition.fn(value)) return false;
|
127
141
|
continue;
|
@@ -15,6 +15,7 @@ const util = require("util");
|
|
15
15
|
/** @typedef {import("../../declarations/WebpackOptions").RuleSetUseItem} RuleSetUseItem */
|
16
16
|
/** @typedef {import("./RuleSetCompiler")} RuleSetCompiler */
|
17
17
|
/** @typedef {import("./RuleSetCompiler").Effect} Effect */
|
18
|
+
/** @typedef {import("./RuleSetCompiler").EffectData} EffectData */
|
18
19
|
|
19
20
|
class UseEffectRulePlugin {
|
20
21
|
/**
|
@@ -55,7 +56,7 @@ class UseEffectRulePlugin {
|
|
55
56
|
* @param {string} path options path
|
56
57
|
* @param {string} defaultIdent default ident when none is provided
|
57
58
|
* @param {RuleSetUseItem} item user provided use value
|
58
|
-
* @returns {Effect | ((
|
59
|
+
* @returns {(Effect | ((effectData: EffectData) => Effect[]))} effect
|
59
60
|
*/
|
60
61
|
const useToEffect = (path, defaultIdent, item) => {
|
61
62
|
if (typeof item === "function") {
|
@@ -139,7 +140,7 @@ class UseEffectRulePlugin {
|
|
139
140
|
/**
|
140
141
|
* @param {string} path current path
|
141
142
|
* @param {RuleSetUse} items user provided use value
|
142
|
-
* @returns {(Effect | ((
|
143
|
+
* @returns {(Effect | ((effectData: EffectData) => Effect[]))[]} effects
|
143
144
|
*/
|
144
145
|
const useToEffects = (path, items) => {
|
145
146
|
if (Array.isArray(items)) {
|
@@ -160,10 +161,7 @@ class UseEffectRulePlugin {
|
|
160
161
|
|
161
162
|
if (typeof use === "function") {
|
162
163
|
result.effects.push(data =>
|
163
|
-
useToEffectsWithoutIdent(
|
164
|
-
`${path}.use`,
|
165
|
-
use(/** @type {TODO} */ (data))
|
166
|
-
)
|
164
|
+
useToEffectsWithoutIdent(`${path}.use`, use(data))
|
167
165
|
);
|
168
166
|
} else {
|
169
167
|
for (const effect of useToEffects(`${path}.use`, use)) {
|
@@ -56,7 +56,9 @@ class DataUriPlugin {
|
|
56
56
|
if (match) {
|
57
57
|
resourceData.data.mimetype = match[1] || "";
|
58
58
|
resourceData.data.parameters = match[2] || "";
|
59
|
-
resourceData.data.encoding =
|
59
|
+
resourceData.data.encoding = /** @type {"base64" | false} */ (
|
60
|
+
match[3] || false
|
61
|
+
);
|
60
62
|
resourceData.data.encodedContent = match[4] || "";
|
61
63
|
}
|
62
64
|
});
|
@@ -16,6 +16,7 @@ const { mkdirp, dirname, join } = require("../util/fs");
|
|
16
16
|
const memoize = require("../util/memoize");
|
17
17
|
|
18
18
|
/** @typedef {import("http").IncomingMessage} IncomingMessage */
|
19
|
+
/** @typedef {import("http").OutgoingHttpHeaders} OutgoingHttpHeaders */
|
19
20
|
/** @typedef {import("http").RequestOptions} RequestOptions */
|
20
21
|
/** @typedef {import("net").Socket} Socket */
|
21
22
|
/** @typedef {import("stream").Readable} Readable */
|
@@ -147,7 +148,7 @@ const parseKeyValuePairs = str => {
|
|
147
148
|
/**
|
148
149
|
* @param {string | undefined} cacheControl Cache-Control header
|
149
150
|
* @param {number} requestTime timestamp of request
|
150
|
-
* @returns {{storeCache: boolean, storeLock: boolean, validUntil: number}} Logic for storing in cache and lockfile cache
|
151
|
+
* @returns {{ storeCache: boolean, storeLock: boolean, validUntil: number }} Logic for storing in cache and lockfile cache
|
151
152
|
*/
|
152
153
|
const parseCacheControl = (cacheControl, requestTime) => {
|
153
154
|
// When false resource is not stored in cache
|
@@ -190,7 +191,7 @@ const areLockfileEntriesEqual = (a, b) =>
|
|
190
191
|
|
191
192
|
/**
|
192
193
|
* @param {LockfileEntry} entry lockfile entry
|
193
|
-
* @returns {`resolved: ${string}, integrity: ${string}, contentType: ${
|
194
|
+
* @returns {`resolved: ${string}, integrity: ${string}, contentType: ${string}`} stringified entry
|
194
195
|
*/
|
195
196
|
const entryToString = entry =>
|
196
197
|
`resolved: ${entry.resolved}, integrity: ${entry.integrity}, contentType: ${entry.contentType}`;
|
@@ -636,11 +637,14 @@ class HttpUriPlugin {
|
|
636
637
|
const resolveContent = (url, integrity, callback) => {
|
637
638
|
/**
|
638
639
|
* @param {Error | null} err error
|
639
|
-
* @param {
|
640
|
+
* @param {FetchResult=} _result fetch result
|
640
641
|
* @returns {void}
|
641
642
|
*/
|
642
|
-
const handleResult = (err,
|
643
|
+
const handleResult = (err, _result) => {
|
643
644
|
if (err) return callback(err);
|
645
|
+
|
646
|
+
const result = /** @type {FetchResult} */ (_result);
|
647
|
+
|
644
648
|
if ("location" in result) {
|
645
649
|
return resolveContent(
|
646
650
|
result.location,
|
@@ -657,6 +661,7 @@ class HttpUriPlugin {
|
|
657
661
|
}
|
658
662
|
);
|
659
663
|
}
|
664
|
+
|
660
665
|
if (
|
661
666
|
!result.fresh &&
|
662
667
|
integrity &&
|
@@ -665,12 +670,14 @@ class HttpUriPlugin {
|
|
665
670
|
) {
|
666
671
|
return fetchContent.force(url, handleResult);
|
667
672
|
}
|
673
|
+
|
668
674
|
return callback(null, {
|
669
675
|
entry: result.entry,
|
670
676
|
content: result.content,
|
671
677
|
storeLock: result.storeLock
|
672
678
|
});
|
673
679
|
};
|
680
|
+
|
674
681
|
fetchContent(url, handleResult);
|
675
682
|
};
|
676
683
|
|
@@ -682,164 +689,162 @@ class HttpUriPlugin {
|
|
682
689
|
*/
|
683
690
|
const fetchContentRaw = (url, cachedResult, callback) => {
|
684
691
|
const requestTime = Date.now();
|
685
|
-
|
686
|
-
|
687
|
-
|
688
|
-
|
689
|
-
|
690
|
-
|
691
|
-
|
692
|
-
|
693
|
-
|
694
|
-
|
695
|
-
|
696
|
-
|
697
|
-
|
698
|
-
|
699
|
-
|
700
|
-
|
701
|
-
|
702
|
-
|
703
|
-
|
704
|
-
|
705
|
-
|
706
|
-
|
707
|
-
|
708
|
-
|
709
|
-
|
710
|
-
|
711
|
-
|
712
|
-
|
713
|
-
|
714
|
-
|
715
|
-
|
716
|
-
|
717
|
-
)} kB${!storeLock ? " no-cache" : ""}`
|
718
|
-
);
|
719
|
-
}
|
720
|
-
const result = {
|
721
|
-
...partialResult,
|
722
|
-
fresh: true,
|
723
|
-
storeLock,
|
724
|
-
storeCache,
|
725
|
-
validUntil,
|
726
|
-
etag
|
727
|
-
};
|
728
|
-
if (!storeCache) {
|
729
|
-
logger.log(
|
730
|
-
`${url} can't be stored in cache, due to Cache-Control header: ${cacheControl}`
|
731
|
-
);
|
732
|
-
return callback(null, result);
|
733
|
-
}
|
734
|
-
cache.store(
|
735
|
-
url,
|
736
|
-
null,
|
737
|
-
{
|
738
|
-
...result,
|
739
|
-
fresh: false
|
740
|
-
},
|
741
|
-
err => {
|
742
|
-
if (err) {
|
743
|
-
logger.warn(
|
744
|
-
`${url} can't be stored in cache: ${err.message}`
|
745
|
-
);
|
746
|
-
logger.debug(err.stack);
|
747
|
-
}
|
748
|
-
callback(null, result);
|
749
|
-
}
|
692
|
+
/** @type {OutgoingHttpHeaders} */
|
693
|
+
const headers = {
|
694
|
+
"accept-encoding": "gzip, deflate, br",
|
695
|
+
"user-agent": "webpack"
|
696
|
+
};
|
697
|
+
|
698
|
+
if (cachedResult && cachedResult.etag) {
|
699
|
+
headers["if-none-match"] = cachedResult.etag;
|
700
|
+
}
|
701
|
+
|
702
|
+
fetch(new URL(url), { headers }, res => {
|
703
|
+
const etag = res.headers.etag;
|
704
|
+
const location = res.headers.location;
|
705
|
+
const cacheControl = res.headers["cache-control"];
|
706
|
+
const { storeLock, storeCache, validUntil } = parseCacheControl(
|
707
|
+
cacheControl,
|
708
|
+
requestTime
|
709
|
+
);
|
710
|
+
/**
|
711
|
+
* @param {Partial<Pick<FetchResultMeta, "fresh">> & (Pick<RedirectFetchResult, "location"> | Pick<ContentFetchResult, "content" | "entry">)} partialResult result
|
712
|
+
* @returns {void}
|
713
|
+
*/
|
714
|
+
const finishWith = partialResult => {
|
715
|
+
if ("location" in partialResult) {
|
716
|
+
logger.debug(
|
717
|
+
`GET ${url} [${res.statusCode}] -> ${partialResult.location}`
|
718
|
+
);
|
719
|
+
} else {
|
720
|
+
logger.debug(
|
721
|
+
`GET ${url} [${res.statusCode}] ${Math.ceil(
|
722
|
+
partialResult.content.length / 1024
|
723
|
+
)} kB${!storeLock ? " no-cache" : ""}`
|
750
724
|
);
|
725
|
+
}
|
726
|
+
const result = {
|
727
|
+
...partialResult,
|
728
|
+
fresh: true,
|
729
|
+
storeLock,
|
730
|
+
storeCache,
|
731
|
+
validUntil,
|
732
|
+
etag
|
751
733
|
};
|
752
|
-
if (
|
753
|
-
|
754
|
-
|
755
|
-
|
756
|
-
|
757
|
-
result.storeCache !== storeCache ||
|
758
|
-
result.etag !== etag
|
759
|
-
) {
|
760
|
-
return finishWith(result);
|
761
|
-
}
|
762
|
-
logger.debug(`GET ${url} [${res.statusCode}] (unchanged)`);
|
763
|
-
return callback(null, { ...result, fresh: true });
|
734
|
+
if (!storeCache) {
|
735
|
+
logger.log(
|
736
|
+
`${url} can't be stored in cache, due to Cache-Control header: ${cacheControl}`
|
737
|
+
);
|
738
|
+
return callback(null, result);
|
764
739
|
}
|
740
|
+
cache.store(
|
741
|
+
url,
|
742
|
+
null,
|
743
|
+
{
|
744
|
+
...result,
|
745
|
+
fresh: false
|
746
|
+
},
|
747
|
+
err => {
|
748
|
+
if (err) {
|
749
|
+
logger.warn(
|
750
|
+
`${url} can't be stored in cache: ${err.message}`
|
751
|
+
);
|
752
|
+
logger.debug(err.stack);
|
753
|
+
}
|
754
|
+
callback(null, result);
|
755
|
+
}
|
756
|
+
);
|
757
|
+
};
|
758
|
+
if (res.statusCode === 304) {
|
759
|
+
const result = /** @type {FetchResult} */ (cachedResult);
|
765
760
|
if (
|
766
|
-
|
767
|
-
|
768
|
-
|
769
|
-
|
761
|
+
result.validUntil < validUntil ||
|
762
|
+
result.storeLock !== storeLock ||
|
763
|
+
result.storeCache !== storeCache ||
|
764
|
+
result.etag !== etag
|
770
765
|
) {
|
771
|
-
|
772
|
-
location: new URL(location, url).href
|
773
|
-
};
|
774
|
-
if (
|
775
|
-
!cachedResult ||
|
776
|
-
!("location" in cachedResult) ||
|
777
|
-
cachedResult.location !== result.location ||
|
778
|
-
cachedResult.validUntil < validUntil ||
|
779
|
-
cachedResult.storeLock !== storeLock ||
|
780
|
-
cachedResult.storeCache !== storeCache ||
|
781
|
-
cachedResult.etag !== etag
|
782
|
-
) {
|
783
|
-
return finishWith(result);
|
784
|
-
}
|
785
|
-
logger.debug(`GET ${url} [${res.statusCode}] (unchanged)`);
|
786
|
-
return callback(null, {
|
787
|
-
...result,
|
788
|
-
fresh: true,
|
789
|
-
storeLock,
|
790
|
-
storeCache,
|
791
|
-
validUntil,
|
792
|
-
etag
|
793
|
-
});
|
766
|
+
return finishWith(result);
|
794
767
|
}
|
795
|
-
|
796
|
-
|
797
|
-
|
798
|
-
|
799
|
-
|
800
|
-
|
801
|
-
|
802
|
-
|
803
|
-
|
804
|
-
|
805
|
-
|
806
|
-
}
|
807
|
-
|
768
|
+
logger.debug(`GET ${url} [${res.statusCode}] (unchanged)`);
|
769
|
+
return callback(null, { ...result, fresh: true });
|
770
|
+
}
|
771
|
+
if (
|
772
|
+
location &&
|
773
|
+
res.statusCode &&
|
774
|
+
res.statusCode >= 301 &&
|
775
|
+
res.statusCode <= 308
|
776
|
+
) {
|
777
|
+
const result = {
|
778
|
+
location: new URL(location, url).href
|
779
|
+
};
|
780
|
+
if (
|
781
|
+
!cachedResult ||
|
782
|
+
!("location" in cachedResult) ||
|
783
|
+
cachedResult.location !== result.location ||
|
784
|
+
cachedResult.validUntil < validUntil ||
|
785
|
+
cachedResult.storeLock !== storeLock ||
|
786
|
+
cachedResult.storeCache !== storeCache ||
|
787
|
+
cachedResult.etag !== etag
|
788
|
+
) {
|
789
|
+
return finishWith(result);
|
808
790
|
}
|
809
|
-
|
810
|
-
|
811
|
-
|
791
|
+
logger.debug(`GET ${url} [${res.statusCode}] (unchanged)`);
|
792
|
+
return callback(null, {
|
793
|
+
...result,
|
794
|
+
fresh: true,
|
795
|
+
storeLock,
|
796
|
+
storeCache,
|
797
|
+
validUntil,
|
798
|
+
etag
|
812
799
|
});
|
800
|
+
}
|
801
|
+
const contentType = res.headers["content-type"] || "";
|
802
|
+
/** @type {Buffer[]} */
|
803
|
+
const bufferArr = [];
|
813
804
|
|
814
|
-
|
815
|
-
|
816
|
-
|
817
|
-
|
818
|
-
|
805
|
+
const contentEncoding = res.headers["content-encoding"];
|
806
|
+
/** @type {Readable} */
|
807
|
+
let stream = res;
|
808
|
+
if (contentEncoding === "gzip") {
|
809
|
+
stream = stream.pipe(createGunzip());
|
810
|
+
} else if (contentEncoding === "br") {
|
811
|
+
stream = stream.pipe(createBrotliDecompress());
|
812
|
+
} else if (contentEncoding === "deflate") {
|
813
|
+
stream = stream.pipe(createInflate());
|
814
|
+
}
|
819
815
|
|
820
|
-
|
816
|
+
stream.on("data", chunk => {
|
817
|
+
bufferArr.push(chunk);
|
818
|
+
});
|
821
819
|
|
822
|
-
|
823
|
-
|
824
|
-
|
825
|
-
|
826
|
-
|
827
|
-
res.statusCode
|
828
|
-
}\n${content.toString("utf-8")}`
|
829
|
-
)
|
830
|
-
);
|
831
|
-
}
|
820
|
+
stream.on("end", () => {
|
821
|
+
if (!res.complete) {
|
822
|
+
logger.log(`GET ${url} [${res.statusCode}] (terminated)`);
|
823
|
+
return callback(new Error(`${url} request was terminated`));
|
824
|
+
}
|
832
825
|
|
833
|
-
|
834
|
-
const entry = { resolved: url, integrity, contentType };
|
826
|
+
const content = Buffer.concat(bufferArr);
|
835
827
|
|
836
|
-
|
837
|
-
|
838
|
-
|
839
|
-
|
828
|
+
if (res.statusCode !== 200) {
|
829
|
+
logger.log(`GET ${url} [${res.statusCode}]`);
|
830
|
+
return callback(
|
831
|
+
new Error(
|
832
|
+
`${url} request status code = ${
|
833
|
+
res.statusCode
|
834
|
+
}\n${content.toString("utf-8")}`
|
835
|
+
)
|
836
|
+
);
|
837
|
+
}
|
838
|
+
|
839
|
+
const integrity = computeIntegrity(content);
|
840
|
+
const entry = { resolved: url, integrity, contentType };
|
841
|
+
|
842
|
+
finishWith({
|
843
|
+
entry,
|
844
|
+
content
|
840
845
|
});
|
841
|
-
}
|
842
|
-
).on("error", err => {
|
846
|
+
});
|
847
|
+
}).on("error", err => {
|
843
848
|
logger.log(`GET ${url} (error)`);
|
844
849
|
err.message += `\nwhile fetching ${url}`;
|
845
850
|
callback(err);
|
@@ -849,7 +854,7 @@ class HttpUriPlugin {
|
|
849
854
|
const fetchContent = cachedWithKey(
|
850
855
|
/**
|
851
856
|
* @param {string} url URL
|
852
|
-
* @param {(err: Error | null, result?:
|
857
|
+
* @param {(err: Error | null, result?: FetchResult) => void} callback callback
|
853
858
|
* @returns {void}
|
854
859
|
*/
|
855
860
|
(url, callback) => {
|