webpack 5.85.0 → 5.88.1
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.
Potentially problematic release.
This version of webpack might be problematic. Click here for more details.
- package/README.md +5 -2
- package/lib/APIPlugin.js +150 -99
- package/lib/AsyncDependenciesBlock.js +3 -3
- package/lib/BannerPlugin.js +2 -1
- package/lib/CaseSensitiveModulesWarning.js +3 -1
- package/lib/Chunk.js +35 -17
- package/lib/ChunkGraph.js +4 -4
- package/lib/ChunkGroup.js +20 -9
- package/lib/CompatibilityPlugin.js +50 -30
- package/lib/Compilation.js +2 -1
- package/lib/Compiler.js +10 -9
- package/lib/ConcatenationScope.js +2 -2
- package/lib/ConditionalInitFragment.js +11 -1
- package/lib/ConstPlugin.js +73 -32
- package/lib/ContextModule.js +8 -3
- package/lib/ContextModuleFactory.js +1 -0
- package/lib/ContextReplacementPlugin.js +13 -0
- package/lib/DelegatedModule.js +15 -3
- package/lib/DelegatedModuleFactoryPlugin.js +6 -0
- package/lib/DependenciesBlock.js +1 -1
- package/lib/Dependency.js +11 -5
- package/lib/DependencyTemplates.js +1 -1
- package/lib/DllEntryPlugin.js +11 -1
- package/lib/DllModule.js +6 -0
- package/lib/DllReferencePlugin.js +13 -1
- package/lib/Entrypoint.js +1 -1
- package/lib/ErrorHelpers.js +1 -0
- package/lib/EvalSourceMapDevToolPlugin.js +6 -1
- package/lib/ExportsInfo.js +22 -4
- package/lib/ExportsInfoApiPlugin.js +14 -5
- package/lib/ExternalModule.js +20 -8
- package/lib/FileSystemInfo.js +52 -24
- package/lib/FlagAllModulesAsUsedPlugin.js +6 -1
- package/lib/FlagDependencyUsagePlugin.js +3 -1
- package/lib/FlagEntryExportAsUsedPlugin.js +4 -0
- package/lib/Generator.js +7 -0
- package/lib/HotModuleReplacementPlugin.js +8 -0
- package/lib/InitFragment.js +28 -5
- package/lib/JavascriptMetaInfoPlugin.js +11 -6
- package/lib/LibManifestPlugin.js +20 -4
- package/lib/Module.js +14 -3
- package/lib/ModuleDependencyError.js +4 -2
- package/lib/ModuleDependencyWarning.js +4 -2
- package/lib/ModuleGraph.js +31 -24
- package/lib/ModuleGraphConnection.js +19 -6
- package/lib/ModuleInfoHeaderPlugin.js +9 -2
- package/lib/ModuleNotFoundError.js +5 -2
- package/lib/ModuleProfile.js +1 -0
- package/lib/ModuleRestoreError.js +2 -0
- package/lib/ModuleStoreError.js +2 -1
- package/lib/ModuleTypeConstants.js +7 -0
- package/lib/MultiWatching.js +4 -0
- package/lib/NodeStuffPlugin.js +32 -6
- package/lib/ProgressPlugin.js +71 -15
- package/lib/ProvidePlugin.js +13 -4
- package/lib/RawModule.js +3 -1
- package/lib/RequireJsStuffPlugin.js +7 -0
- package/lib/RuntimeGlobals.js +5 -0
- package/lib/RuntimeModule.js +3 -3
- package/lib/RuntimePlugin.js +6 -3
- package/lib/RuntimeTemplate.js +22 -4
- package/lib/SourceMapDevToolModuleOptionsPlugin.js +4 -0
- package/lib/SourceMapDevToolPlugin.js +7 -2
- package/lib/UseStrictPlugin.js +10 -3
- package/lib/Watching.js +62 -25
- package/lib/WebpackError.js +6 -5
- package/lib/WebpackIsIncludedPlugin.js +6 -4
- package/lib/WebpackOptionsApply.js +4 -2
- package/lib/WebpackOptionsDefaulter.js +10 -3
- package/lib/asset/AssetGenerator.js +2 -1
- package/lib/asset/AssetParser.js +11 -6
- package/lib/asset/AssetSourceParser.js +8 -3
- package/lib/async-modules/AwaitDependenciesInitFragment.js +4 -0
- package/lib/buildChunkGraph.js +37 -21
- package/lib/cache/IdleFileCachePlugin.js +2 -1
- package/lib/cache/PackFileCacheStrategy.js +53 -22
- package/lib/config/browserslistTargetHandler.js +7 -7
- package/lib/config/defaults.js +43 -26
- package/lib/container/RemoteRuntimeModule.js +1 -1
- package/lib/css/CssExportsGenerator.js +9 -0
- package/lib/css/CssGenerator.js +1 -1
- package/lib/css/CssLoadingRuntimeModule.js +43 -19
- package/lib/css/CssModulesPlugin.js +42 -14
- package/lib/css/CssParser.js +22 -0
- package/lib/dependencies/AMDDefineDependency.js +34 -4
- package/lib/dependencies/AMDDefineDependencyParserPlugin.js +5 -0
- package/lib/dependencies/AMDRuntimeModules.js +2 -2
- package/lib/dependencies/CommonJsExportsParserPlugin.js +14 -4
- package/lib/dependencies/CommonJsImportsParserPlugin.js +169 -59
- package/lib/dependencies/CommonJsPlugin.js +13 -8
- package/lib/dependencies/CommonJsRequireContextDependency.js +2 -2
- package/lib/dependencies/ConstDependency.js +2 -2
- package/lib/dependencies/ContextDependency.js +7 -2
- package/lib/dependencies/CssImportDependency.js +1 -1
- package/lib/dependencies/CssLocalIdentifierDependency.js +5 -0
- package/lib/dependencies/CssUrlDependency.js +3 -3
- package/lib/dependencies/DllEntryDependency.js +5 -0
- package/lib/dependencies/DynamicExports.js +10 -6
- package/lib/dependencies/ExportsInfoDependency.js +14 -4
- package/lib/dependencies/HarmonyCompatibilityDependency.js +2 -1
- package/lib/dependencies/HarmonyDetectionParserPlugin.js +3 -1
- package/lib/dependencies/HarmonyEvaluatedImportSpecifierDependency.js +12 -5
- package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +2 -0
- package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +4 -4
- package/lib/dependencies/HarmonyExports.js +9 -5
- package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +40 -27
- package/lib/dependencies/HarmonyImportSideEffectDependency.js +1 -2
- package/lib/dependencies/HarmonyImportSpecifierDependency.js +31 -21
- package/lib/dependencies/HarmonyTopLevelThisParserPlugin.js +15 -3
- package/lib/dependencies/ImportDependency.js +5 -3
- package/lib/dependencies/ImportEagerDependency.js +5 -3
- package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +19 -0
- package/lib/dependencies/ImportMetaPlugin.js +31 -15
- package/lib/dependencies/ImportParserPlugin.js +62 -25
- package/lib/dependencies/ImportWeakDependency.js +5 -3
- package/lib/dependencies/JsonExportsDependency.js +1 -1
- package/lib/dependencies/ModuleDependency.js +1 -1
- package/lib/dependencies/ModuleDependencyTemplateAsId.js +2 -1
- package/lib/dependencies/ProvidedDependency.js +4 -1
- package/lib/dependencies/RequireContextDependencyParserPlugin.js +13 -5
- package/lib/dependencies/RequireEnsureDependenciesBlock.js +5 -2
- package/lib/dependencies/RequireEnsureDependenciesBlockParserPlugin.js +6 -1
- package/lib/dependencies/RequireHeaderDependency.js +4 -0
- package/lib/dependencies/RequireIncludeDependencyParserPlugin.js +26 -5
- package/lib/dependencies/RequireResolveHeaderDependency.js +9 -0
- package/lib/dependencies/SystemPlugin.js +17 -5
- package/lib/dependencies/SystemRuntimeModule.js +1 -1
- package/lib/dependencies/URLDependency.js +2 -2
- package/lib/dependencies/URLPlugin.js +9 -4
- package/lib/dependencies/WebAssemblyImportDependency.js +1 -1
- package/lib/dependencies/WorkerPlugin.js +59 -22
- package/lib/esm/ExportWebpackRequireRuntimeModule.js +1 -1
- package/lib/esm/ModuleChunkLoadingRuntimeModule.js +1 -1
- package/lib/hmr/HotModuleReplacementRuntimeModule.js +1 -1
- package/lib/ids/HashedModuleIdsPlugin.js +1 -1
- package/lib/ids/SyncModuleIdsPlugin.js +1 -0
- package/lib/javascript/BasicEvaluatedExpression.js +28 -19
- package/lib/javascript/CommonJsChunkFormatPlugin.js +6 -2
- package/lib/javascript/JavascriptModulesPlugin.js +25 -5
- package/lib/javascript/JavascriptParser.js +157 -85
- package/lib/javascript/JavascriptParserHelpers.js +37 -15
- package/lib/json/JsonData.js +2 -2
- package/lib/json/JsonParser.js +25 -12
- package/lib/library/AmdLibraryPlugin.js +2 -2
- package/lib/library/AssignLibraryPlugin.js +13 -1
- package/lib/library/EnableLibraryPlugin.js +4 -0
- package/lib/library/SystemLibraryPlugin.js +1 -1
- package/lib/library/UmdLibraryPlugin.js +20 -2
- package/lib/logging/runtime.js +1 -1
- package/lib/logging/truncateArgs.js +4 -0
- package/lib/node/ReadFileChunkLoadingRuntimeModule.js +10 -6
- package/lib/node/ReadFileCompileAsyncWasmPlugin.js +2 -1
- package/lib/node/RequireChunkLoadingRuntimeModule.js +10 -6
- package/lib/optimize/AggressiveMergingPlugin.js +8 -0
- package/lib/optimize/AggressiveSplittingPlugin.js +9 -2
- package/lib/optimize/EnsureChunkConditionsPlugin.js +3 -0
- package/lib/optimize/FlagIncludedChunksPlugin.js +11 -5
- package/lib/optimize/InnerGraph.js +5 -5
- package/lib/optimize/InnerGraphPlugin.js +2 -1
- package/lib/optimize/LimitChunkCountPlugin.js +29 -4
- package/lib/optimize/MangleExportsPlugin.js +1 -1
- package/lib/optimize/MinMaxSizeWarning.js +5 -0
- package/lib/optimize/ModuleConcatenationPlugin.js +59 -2
- package/lib/optimize/RealContentHashPlugin.js +80 -30
- package/lib/optimize/RemoveParentModulesPlugin.js +6 -0
- package/lib/optimize/RuntimeChunkPlugin.js +9 -1
- package/lib/optimize/SideEffectsFlagPlugin.js +10 -1
- package/lib/optimize/SplitChunksPlugin.js +71 -31
- package/lib/performance/SizeLimitsPlugin.js +7 -4
- package/lib/prefetch/ChunkPrefetchFunctionRuntimeModule.js +4 -2
- package/lib/prefetch/ChunkPrefetchPreloadPlugin.js +3 -1
- package/lib/prefetch/ChunkPrefetchStartupRuntimeModule.js +6 -3
- package/lib/prefetch/ChunkPrefetchTriggerRuntimeModule.js +4 -2
- package/lib/prefetch/ChunkPreloadTriggerRuntimeModule.js +4 -2
- package/lib/rules/BasicEffectRulePlugin.js +4 -0
- package/lib/rules/BasicMatcherRulePlugin.js +5 -0
- package/lib/rules/RuleSetCompiler.js +3 -3
- package/lib/rules/UseEffectRulePlugin.js +6 -4
- package/lib/runtime/AsyncModuleRuntimeModule.js +8 -5
- package/lib/runtime/AutoPublicPathRuntimeModule.js +4 -2
- package/lib/runtime/BaseUriRuntimeModule.js +3 -3
- package/lib/runtime/ChunkNameRuntimeModule.js +1 -1
- package/lib/runtime/CompatGetDefaultExportRuntimeModule.js +5 -2
- package/lib/runtime/CompatRuntimeModule.js +7 -2
- package/lib/runtime/CreateFakeNamespaceObjectRuntimeModule.js +5 -2
- package/lib/runtime/CreateScriptRuntimeModule.js +4 -2
- package/lib/runtime/CreateScriptUrlRuntimeModule.js +4 -2
- package/lib/runtime/DefinePropertyGettersRuntimeModule.js +5 -2
- package/lib/runtime/EnsureChunkRuntimeModule.js +15 -4
- package/lib/runtime/GetChunkFilenameRuntimeModule.js +6 -10
- package/lib/runtime/GetFullHashRuntimeModule.js +4 -3
- package/lib/runtime/GetMainFilenameRuntimeModule.js +5 -2
- package/lib/runtime/GetTrustedTypesPolicyRuntimeModule.js +4 -2
- package/lib/runtime/GlobalRuntimeModule.js +1 -1
- package/lib/runtime/HasOwnPropertyRuntimeModule.js +5 -2
- package/lib/runtime/LoadScriptRuntimeModule.js +64 -48
- package/lib/runtime/MakeNamespaceObjectRuntimeModule.js +5 -2
- package/lib/runtime/NonceRuntimeModule.js +1 -1
- package/lib/runtime/OnChunksLoadedRuntimeModule.js +4 -2
- package/lib/runtime/PublicPathRuntimeModule.js +4 -2
- package/lib/runtime/RelativeUrlRuntimeModule.js +5 -2
- package/lib/runtime/RuntimeIdRuntimeModule.js +6 -2
- package/lib/runtime/StartupChunkDependenciesRuntimeModule.js +9 -3
- package/lib/runtime/StartupEntrypointRuntimeModule.js +3 -2
- package/lib/runtime/SystemContextRuntimeModule.js +1 -1
- package/lib/serialization/BinaryMiddleware.js +143 -1
- package/lib/serialization/ErrorObjectSerializer.js +3 -0
- package/lib/serialization/ObjectMiddleware.js +9 -3
- package/lib/serialization/types.js +1 -1
- package/lib/sharing/ConsumeSharedFallbackDependency.js +3 -0
- package/lib/sharing/ConsumeSharedRuntimeModule.js +14 -5
- package/lib/sharing/ProvideSharedDependency.js +11 -0
- package/lib/sharing/ProvideSharedModule.js +4 -0
- package/lib/sharing/ProvideSharedPlugin.js +22 -21
- package/lib/sharing/ShareRuntimeModule.js +12 -5
- package/lib/sharing/resolveMatchedConfigs.js +1 -1
- package/lib/sharing/utils.js +32 -5
- package/lib/util/AsyncQueue.js +4 -2
- package/lib/util/ParallelismFactorCalculator.js +10 -0
- package/lib/util/Semaphore.js +1 -1
- package/lib/util/StackedCacheMap.js +1 -1
- package/lib/util/URLAbsoluteSpecifier.js +1 -1
- package/lib/util/createHash.js +30 -9
- package/lib/util/deprecation.js +10 -3
- package/lib/util/deterministicGrouping.js +50 -11
- package/lib/util/findGraphRoots.js +4 -2
- package/lib/util/memoize.js +3 -3
- package/lib/util/processAsyncTree.js +7 -1
- package/lib/util/registerExternalSerializer.js +1 -1
- package/lib/util/runtime.js +84 -21
- package/lib/util/semver.js +1 -0
- package/lib/util/smartGrouping.js +1 -1
- package/lib/validateSchema.js +6 -2
- package/lib/wasm-async/AsyncWasmLoadingRuntimeModule.js +6 -2
- package/lib/wasm-async/AsyncWebAssemblyParser.js +7 -3
- package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +14 -7
- package/lib/wasm-sync/WasmFinalizeExportsPlugin.js +3 -1
- package/lib/wasm-sync/WebAssemblyGenerator.js +1 -0
- package/lib/wasm-sync/WebAssemblyParser.js +6 -2
- package/lib/web/JsonpChunkLoadingRuntimeModule.js +14 -4
- package/lib/webpack.js +11 -2
- package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +15 -16
- package/module.d.ts +1 -0
- package/package.json +5 -4
- package/schemas/WebpackOptions.check.js +1 -1
- package/schemas/WebpackOptions.json +52 -6
- package/schemas/plugins/css/CssGeneratorOptions.json +1 -1
- package/schemas/plugins/css/CssParserOptions.json +1 -1
- package/types.d.ts +606 -292
package/lib/NodeStuffPlugin.js
CHANGED
@@ -21,14 +21,23 @@ const { relative } = require("./util/fs");
|
|
21
21
|
const { parseResource } = require("./util/identifier");
|
22
22
|
|
23
23
|
/** @typedef {import("webpack-sources").ReplaceSource} ReplaceSource */
|
24
|
+
/** @typedef {import("../declarations/WebpackOptions").JavascriptParserOptions} JavascriptParserOptions */
|
25
|
+
/** @typedef {import("../declarations/WebpackOptions").NodeOptions} NodeOptions */
|
24
26
|
/** @typedef {import("./Compiler")} Compiler */
|
25
27
|
/** @typedef {import("./Dependency")} Dependency */
|
28
|
+
/** @typedef {import("./Dependency").DependencyLocation} DependencyLocation */
|
26
29
|
/** @typedef {import("./DependencyTemplates")} DependencyTemplates */
|
30
|
+
/** @typedef {import("./NormalModule")} NormalModule */
|
27
31
|
/** @typedef {import("./RuntimeTemplate")} RuntimeTemplate */
|
32
|
+
/** @typedef {import("./javascript/JavascriptParser")} JavascriptParser */
|
33
|
+
/** @typedef {import("./javascript/JavascriptParser").Range} Range */
|
28
34
|
|
29
35
|
const PLUGIN_NAME = "NodeStuffPlugin";
|
30
36
|
|
31
37
|
class NodeStuffPlugin {
|
38
|
+
/**
|
39
|
+
* @param {NodeOptions} options options
|
40
|
+
*/
|
32
41
|
constructor(options) {
|
33
42
|
this.options = options;
|
34
43
|
}
|
@@ -43,6 +52,11 @@ class NodeStuffPlugin {
|
|
43
52
|
compiler.hooks.compilation.tap(
|
44
53
|
PLUGIN_NAME,
|
45
54
|
(compilation, { normalModuleFactory }) => {
|
55
|
+
/**
|
56
|
+
* @param {JavascriptParser} parser the parser
|
57
|
+
* @param {JavascriptParserOptions} parserOptions options
|
58
|
+
* @returns {void}
|
59
|
+
*/
|
46
60
|
const handler = (parser, parserOptions) => {
|
47
61
|
if (parserOptions.node === false) return;
|
48
62
|
|
@@ -56,10 +70,10 @@ class NodeStuffPlugin {
|
|
56
70
|
parser.hooks.expression.for("global").tap(PLUGIN_NAME, expr => {
|
57
71
|
const dep = new ConstDependency(
|
58
72
|
RuntimeGlobals.global,
|
59
|
-
expr.range,
|
73
|
+
/** @type {Range} */ (expr.range),
|
60
74
|
[RuntimeGlobals.global]
|
61
75
|
);
|
62
|
-
dep.loc = expr.loc;
|
76
|
+
dep.loc = /** @type {DependencyLocation} */ (expr.loc);
|
63
77
|
parser.state.module.addPresentationalDependency(dep);
|
64
78
|
|
65
79
|
// TODO webpack 6 remove
|
@@ -76,25 +90,31 @@ class NodeStuffPlugin {
|
|
76
90
|
parser.hooks.rename.for("global").tap(PLUGIN_NAME, expr => {
|
77
91
|
const dep = new ConstDependency(
|
78
92
|
RuntimeGlobals.global,
|
79
|
-
expr.range,
|
93
|
+
/** @type {Range} */ (expr.range),
|
80
94
|
[RuntimeGlobals.global]
|
81
95
|
);
|
82
|
-
dep.loc = expr.loc;
|
96
|
+
dep.loc = /** @type {DependencyLocation} */ (expr.loc);
|
83
97
|
parser.state.module.addPresentationalDependency(dep);
|
84
98
|
return false;
|
85
99
|
});
|
86
100
|
}
|
87
101
|
|
102
|
+
/**
|
103
|
+
* @param {string} expressionName expression name
|
104
|
+
* @param {(module: NormalModule) => string} fn function
|
105
|
+
* @param {string=} warning warning
|
106
|
+
* @returns {void}
|
107
|
+
*/
|
88
108
|
const setModuleConstant = (expressionName, fn, warning) => {
|
89
109
|
parser.hooks.expression
|
90
110
|
.for(expressionName)
|
91
111
|
.tap(PLUGIN_NAME, expr => {
|
92
112
|
const dep = new CachedConstDependency(
|
93
113
|
JSON.stringify(fn(parser.state.module)),
|
94
|
-
expr.range,
|
114
|
+
/** @type {Range} */ (expr.range),
|
95
115
|
expressionName
|
96
116
|
);
|
97
|
-
dep.loc = expr.loc;
|
117
|
+
dep.loc = /** @type {DependencyLocation} */ (expr.loc);
|
98
118
|
parser.state.module.addPresentationalDependency(dep);
|
99
119
|
|
100
120
|
// TODO webpack 6 remove
|
@@ -108,6 +128,12 @@ class NodeStuffPlugin {
|
|
108
128
|
});
|
109
129
|
};
|
110
130
|
|
131
|
+
/**
|
132
|
+
* @param {string} expressionName expression name
|
133
|
+
* @param {string} value value
|
134
|
+
* @param {string=} warning warning
|
135
|
+
* @returns {void}
|
136
|
+
*/
|
111
137
|
const setConstant = (expressionName, value, warning) =>
|
112
138
|
setModuleConstant(expressionName, () => value, warning);
|
113
139
|
|
package/lib/ProgressPlugin.js
CHANGED
@@ -11,9 +11,20 @@ const NormalModule = require("./NormalModule");
|
|
11
11
|
const createSchemaValidation = require("./util/create-schema-validation");
|
12
12
|
const { contextify } = require("./util/identifier");
|
13
13
|
|
14
|
+
/** @typedef {import("tapable").Tap} Tap */
|
14
15
|
/** @typedef {import("../declarations/plugins/ProgressPlugin").HandlerFunction} HandlerFunction */
|
15
16
|
/** @typedef {import("../declarations/plugins/ProgressPlugin").ProgressPluginArgument} ProgressPluginArgument */
|
16
17
|
/** @typedef {import("../declarations/plugins/ProgressPlugin").ProgressPluginOptions} ProgressPluginOptions */
|
18
|
+
/** @typedef {import("./Dependency")} Dependency */
|
19
|
+
/** @typedef {import("./Entrypoint").EntryOptions} EntryOptions */
|
20
|
+
/** @typedef {import("./Module")} Module */
|
21
|
+
/** @typedef {import("./logging/Logger").Logger} Logger */
|
22
|
+
|
23
|
+
/**
|
24
|
+
* @typedef {Object} CountsData
|
25
|
+
* @property {number} modulesCount modules count
|
26
|
+
* @property {number} dependenciesCount dependencies count
|
27
|
+
*/
|
17
28
|
|
18
29
|
const validate = createSchemaValidation(
|
19
30
|
require("../schemas/plugins/ProgressPlugin.check.js"),
|
@@ -23,14 +34,31 @@ const validate = createSchemaValidation(
|
|
23
34
|
baseDataPath: "options"
|
24
35
|
}
|
25
36
|
);
|
37
|
+
|
38
|
+
/**
|
39
|
+
* @param {number} a a
|
40
|
+
* @param {number} b b
|
41
|
+
* @param {number} c c
|
42
|
+
* @returns {number} median
|
43
|
+
*/
|
26
44
|
const median3 = (a, b, c) => {
|
27
45
|
return a + b + c - Math.max(a, b, c) - Math.min(a, b, c);
|
28
46
|
};
|
29
47
|
|
48
|
+
/**
|
49
|
+
* @param {boolean | null | undefined} profile need profile
|
50
|
+
* @param {Logger} logger logger
|
51
|
+
* @returns {defaultHandler} default handler
|
52
|
+
*/
|
30
53
|
const createDefaultHandler = (profile, logger) => {
|
31
|
-
/** @type {{ value: string, time: number }[]} */
|
54
|
+
/** @type {{ value: string | undefined, time: number }[]} */
|
32
55
|
const lastStateInfo = [];
|
33
56
|
|
57
|
+
/**
|
58
|
+
* @param {number} percentage percentage
|
59
|
+
* @param {string} msg message
|
60
|
+
* @param {...string} args additional arguments
|
61
|
+
*/
|
34
62
|
const defaultHandler = (percentage, msg, ...args) => {
|
35
63
|
if (profile) {
|
36
64
|
if (percentage === 0) {
|
@@ -95,18 +123,18 @@ const createDefaultHandler = (profile, logger) => {
|
|
95
123
|
|
96
124
|
/**
|
97
125
|
* @callback ReportProgress
|
98
|
-
* @param {number} p
|
99
|
-
* @param {...string}
|
126
|
+
* @param {number} p percentage
|
127
|
+
* @param {...string} args additional arguments
|
100
128
|
* @returns {void}
|
101
129
|
*/
|
102
130
|
|
103
|
-
/** @type {WeakMap<Compiler,ReportProgress>} */
|
131
|
+
/** @type {WeakMap<Compiler, ReportProgress | undefined>} */
|
104
132
|
const progressReporters = new WeakMap();
|
105
133
|
|
106
134
|
class ProgressPlugin {
|
107
135
|
/**
|
108
136
|
* @param {Compiler} compiler the current compiler
|
109
|
-
* @returns {ReportProgress} a progress reporter, if any
|
137
|
+
* @returns {ReportProgress | undefined} a progress reporter, if any
|
110
138
|
*/
|
111
139
|
static getReporter(compiler) {
|
112
140
|
return progressReporters.get(compiler);
|
@@ -288,6 +316,9 @@ class ProgressPlugin {
|
|
288
316
|
};
|
289
317
|
|
290
318
|
// only used when showActiveModules is set
|
319
|
+
/**
|
320
|
+
* @param {Module} module the module
|
321
|
+
*/
|
291
322
|
const moduleBuild = module => {
|
292
323
|
const ident = module.identifier();
|
293
324
|
if (ident) {
|
@@ -297,11 +328,18 @@ class ProgressPlugin {
|
|
297
328
|
}
|
298
329
|
};
|
299
330
|
|
331
|
+
/**
|
332
|
+
* @param {Dependency} entry entry dependency
|
333
|
+
* @param {EntryOptions} options options object
|
334
|
+
*/
|
300
335
|
const entryAdd = (entry, options) => {
|
301
336
|
entriesCount++;
|
302
337
|
if (entriesCount < 5 || entriesCount % 10 === 0) updateThrottled();
|
303
338
|
};
|
304
339
|
|
340
|
+
/**
|
341
|
+
* @param {Module} module the module
|
342
|
+
*/
|
305
343
|
const moduleDone = module => {
|
306
344
|
doneModules++;
|
307
345
|
if (showActiveModules) {
|
@@ -321,6 +359,10 @@ class ProgressPlugin {
|
|
321
359
|
if (doneModules < 50 || doneModules % 100 === 0) updateThrottled();
|
322
360
|
};
|
323
361
|
|
362
|
+
/**
|
363
|
+
* @param {Dependency} entry entry dependency
|
364
|
+
* @param {EntryOptions} options options object
|
365
|
+
*/
|
324
366
|
const entryDone = (entry, options) => {
|
325
367
|
doneEntries++;
|
326
368
|
update();
|
@@ -330,6 +372,7 @@ class ProgressPlugin {
|
|
330
372
|
.getCache("ProgressPlugin")
|
331
373
|
.getItemCache("counts", null);
|
332
374
|
|
375
|
+
/** @type {Promise<CountsData> | undefined} */
|
333
376
|
let cacheGetPromise;
|
334
377
|
|
335
378
|
compiler.hooks.beforeCompile.tap("ProgressPlugin", () => {
|
@@ -352,15 +395,17 @@ class ProgressPlugin {
|
|
352
395
|
|
353
396
|
compiler.hooks.afterCompile.tapPromise("ProgressPlugin", compilation => {
|
354
397
|
if (compilation.compiler.isChild()) return Promise.resolve();
|
355
|
-
return cacheGetPromise.then(
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
398
|
+
return /** @type {Promise<CountsData>} */ (cacheGetPromise).then(
|
399
|
+
async oldData => {
|
400
|
+
if (
|
401
|
+
!oldData ||
|
402
|
+
oldData.modulesCount !== modulesCount ||
|
403
|
+
oldData.dependenciesCount !== dependenciesCount
|
404
|
+
) {
|
405
|
+
await cache.storePromise({ modulesCount, dependenciesCount });
|
406
|
+
}
|
362
407
|
}
|
363
|
-
|
408
|
+
);
|
364
409
|
});
|
365
410
|
|
366
411
|
compiler.hooks.compilation.tap("ProgressPlugin", compilation => {
|
@@ -463,9 +508,9 @@ class ProgressPlugin {
|
|
463
508
|
};
|
464
509
|
const numberOfHooks = Object.keys(hooks).length;
|
465
510
|
Object.keys(hooks).forEach((name, idx) => {
|
466
|
-
const title = hooks[name];
|
511
|
+
const title = hooks[/** @type {keyof typeof hooks} */ (name)];
|
467
512
|
const percentage = (idx / numberOfHooks) * 0.25 + 0.7;
|
468
|
-
compilation.hooks[name].intercept({
|
513
|
+
compilation.hooks[/** @type {keyof typeof hooks} */ (name)].intercept({
|
469
514
|
name: "ProgressPlugin",
|
470
515
|
call() {
|
471
516
|
handler(percentage, "sealing", title);
|
@@ -500,6 +545,12 @@ class ProgressPlugin {
|
|
500
545
|
handler(0.65, "building");
|
501
546
|
}
|
502
547
|
});
|
548
|
+
/**
|
549
|
+
* @param {TODO} hook hook
|
550
|
+
* @param {number} progress progress from 0 to 1
|
551
|
+
* @param {string} category category
|
552
|
+
* @param {string} name name
|
553
|
+
*/
|
503
554
|
const interceptHook = (hook, progress, category, name) => {
|
504
555
|
hook.intercept({
|
505
556
|
name: "ProgressPlugin",
|
@@ -516,6 +567,9 @@ class ProgressPlugin {
|
|
516
567
|
error() {
|
517
568
|
handler(progress, category, name);
|
518
569
|
},
|
570
|
+
/**
|
571
|
+
* @param {Tap} tap tap
|
572
|
+
*/
|
519
573
|
tap(tap) {
|
520
574
|
progressReporters.set(compiler, (p, ...args) => {
|
521
575
|
handler(progress, category, name, tap.name, ...args);
|
@@ -610,4 +664,6 @@ ProgressPlugin.defaultOptions = {
|
|
610
664
|
entries: true
|
611
665
|
};
|
612
666
|
|
667
|
+
ProgressPlugin.createDefaultHandler = createDefaultHandler;
|
668
|
+
|
613
669
|
module.exports = ProgressPlugin;
|
package/lib/ProvidePlugin.js
CHANGED
@@ -14,7 +14,11 @@ const ConstDependency = require("./dependencies/ConstDependency");
|
|
14
14
|
const ProvidedDependency = require("./dependencies/ProvidedDependency");
|
15
15
|
const { approve } = require("./javascript/JavascriptParserHelpers");
|
16
16
|
|
17
|
+
/** @typedef {import("../declarations/WebpackOptions").JavascriptParserOptions} JavascriptParserOptions */
|
17
18
|
/** @typedef {import("./Compiler")} Compiler */
|
19
|
+
/** @typedef {import("./Dependency").DependencyLocation} DependencyLocation */
|
20
|
+
/** @typedef {import("./javascript/JavascriptParser")} JavascriptParser */
|
21
|
+
/** @typedef {import("./javascript/JavascriptParser").Range} Range */
|
18
22
|
|
19
23
|
const PLUGIN_NAME = "ProvidePlugin";
|
20
24
|
|
@@ -48,6 +52,11 @@ class ProvidePlugin {
|
|
48
52
|
ProvidedDependency,
|
49
53
|
new ProvidedDependency.Template()
|
50
54
|
);
|
55
|
+
/**
|
56
|
+
* @param {JavascriptParser} parser the parser
|
57
|
+
* @param {JavascriptParserOptions} parserOptions options
|
58
|
+
* @returns {void}
|
59
|
+
*/
|
51
60
|
const handler = (parser, parserOptions) => {
|
52
61
|
Object.keys(definitions).forEach(name => {
|
53
62
|
const request = [].concat(definitions[name]);
|
@@ -67,9 +76,9 @@ class ProvidePlugin {
|
|
67
76
|
request[0],
|
68
77
|
nameIdentifier,
|
69
78
|
request.slice(1),
|
70
|
-
expr.range
|
79
|
+
/** @type {Range} */ (expr.range)
|
71
80
|
);
|
72
|
-
dep.loc = expr.loc;
|
81
|
+
dep.loc = /** @type {DependencyLocation} */ (expr.loc);
|
73
82
|
parser.state.module.addDependency(dep);
|
74
83
|
return true;
|
75
84
|
});
|
@@ -82,9 +91,9 @@ class ProvidePlugin {
|
|
82
91
|
request[0],
|
83
92
|
nameIdentifier,
|
84
93
|
request.slice(1),
|
85
|
-
expr.callee.range
|
94
|
+
/** @type {Range} */ (expr.callee.range)
|
86
95
|
);
|
87
|
-
dep.loc = expr.callee.loc;
|
96
|
+
dep.loc = /** @type {DependencyLocation} */ (expr.callee.loc);
|
88
97
|
parser.state.module.addDependency(dep);
|
89
98
|
parser.walkExpressions(expr.arguments);
|
90
99
|
return true;
|
package/lib/RawModule.js
CHANGED
@@ -72,7 +72,9 @@ class RawModule extends Module {
|
|
72
72
|
* @returns {string} a user readable identifier of the module
|
73
73
|
*/
|
74
74
|
readableIdentifier(requestShortener) {
|
75
|
-
return
|
75
|
+
return /** @type {string} */ (
|
76
|
+
requestShortener.shorten(this.readableIdentifierStr)
|
77
|
+
);
|
76
78
|
}
|
77
79
|
|
78
80
|
/**
|
@@ -15,7 +15,9 @@ const {
|
|
15
15
|
toConstantDependency
|
16
16
|
} = require("./javascript/JavascriptParserHelpers");
|
17
17
|
|
18
|
+
/** @typedef {import("../declarations/WebpackOptions").JavascriptParserOptions} JavascriptParserOptions */
|
18
19
|
/** @typedef {import("./Compiler")} Compiler */
|
20
|
+
/** @typedef {import("./javascript/JavascriptParser")} JavascriptParser */
|
19
21
|
|
20
22
|
const PLUGIN_NAME = "RequireJsStuffPlugin";
|
21
23
|
|
@@ -33,6 +35,11 @@ module.exports = class RequireJsStuffPlugin {
|
|
33
35
|
ConstDependency,
|
34
36
|
new ConstDependency.Template()
|
35
37
|
);
|
38
|
+
/**
|
39
|
+
* @param {JavascriptParser} parser the parser
|
40
|
+
* @param {JavascriptParserOptions} parserOptions options
|
41
|
+
* @returns {void}
|
42
|
+
*/
|
36
43
|
const handler = (parser, parserOptions) => {
|
37
44
|
if (
|
38
45
|
parserOptions.requireJs === undefined ||
|
package/lib/RuntimeGlobals.js
CHANGED
@@ -188,6 +188,11 @@ exports.createScriptUrl = "__webpack_require__.tu";
|
|
188
188
|
*/
|
189
189
|
exports.getTrustedTypesPolicy = "__webpack_require__.tt";
|
190
190
|
|
191
|
+
/**
|
192
|
+
* a flag when a chunk has a fetch priority
|
193
|
+
*/
|
194
|
+
exports.hasFetchPriority = "has fetch priority";
|
195
|
+
|
191
196
|
/**
|
192
197
|
* the chunk name of the chunk with the runtime
|
193
198
|
*/
|
package/lib/RuntimeModule.js
CHANGED
@@ -166,7 +166,7 @@ class RuntimeModule extends Module {
|
|
166
166
|
/* istanbul ignore next */
|
167
167
|
/**
|
168
168
|
* @abstract
|
169
|
-
* @returns {string} runtime code
|
169
|
+
* @returns {string | null} runtime code
|
170
170
|
*/
|
171
171
|
generate() {
|
172
172
|
const AbstractMethodError = require("./AbstractMethodError");
|
@@ -174,11 +174,11 @@ class RuntimeModule extends Module {
|
|
174
174
|
}
|
175
175
|
|
176
176
|
/**
|
177
|
-
* @returns {string} runtime code
|
177
|
+
* @returns {string | null} runtime code
|
178
178
|
*/
|
179
179
|
getGeneratedCode() {
|
180
180
|
if (this._cachedGeneratedCode) {
|
181
|
-
return this._cachedGeneratedCode;
|
181
|
+
return /** @type {string | null} */ (this._cachedGeneratedCode);
|
182
182
|
}
|
183
183
|
return (this._cachedGeneratedCode = this.generate());
|
184
184
|
}
|
package/lib/RuntimePlugin.js
CHANGED
@@ -128,7 +128,8 @@ class RuntimePlugin {
|
|
128
128
|
});
|
129
129
|
}
|
130
130
|
for (const req of Object.keys(TREE_DEPENDENCIES)) {
|
131
|
-
const deps =
|
131
|
+
const deps =
|
132
|
+
TREE_DEPENDENCIES[/** @type {keyof TREE_DEPENDENCIES} */ (req)];
|
132
133
|
compilation.hooks.runtimeRequirementInTree
|
133
134
|
.for(req)
|
134
135
|
.tap("RuntimePlugin", (chunk, set) => {
|
@@ -136,7 +137,8 @@ class RuntimePlugin {
|
|
136
137
|
});
|
137
138
|
}
|
138
139
|
for (const req of Object.keys(MODULE_DEPENDENCIES)) {
|
139
|
-
const deps =
|
140
|
+
const deps =
|
141
|
+
MODULE_DEPENDENCIES[/** @type {keyof MODULE_DEPENDENCIES} */ (req)];
|
140
142
|
compilation.hooks.runtimeRequirementInModule
|
141
143
|
.for(req)
|
142
144
|
.tap("RuntimePlugin", (chunk, set) => {
|
@@ -377,9 +379,10 @@ class RuntimePlugin {
|
|
377
379
|
if (withCreateScriptUrl) {
|
378
380
|
set.add(RuntimeGlobals.createScriptUrl);
|
379
381
|
}
|
382
|
+
const withFetchPriority = set.has(RuntimeGlobals.hasFetchPriority);
|
380
383
|
compilation.addRuntimeModule(
|
381
384
|
chunk,
|
382
|
-
new LoadScriptRuntimeModule(withCreateScriptUrl)
|
385
|
+
new LoadScriptRuntimeModule(withCreateScriptUrl, withFetchPriority)
|
383
386
|
);
|
384
387
|
return true;
|
385
388
|
});
|
package/lib/RuntimeTemplate.js
CHANGED
@@ -396,7 +396,7 @@ class RuntimeTemplate {
|
|
396
396
|
|
397
397
|
/**
|
398
398
|
* @param {Object} options options object
|
399
|
-
* @param {Module} options.module the module
|
399
|
+
* @param {Module | null} options.module the module
|
400
400
|
* @param {ChunkGraph} options.chunkGraph the chunk graph
|
401
401
|
* @param {string} options.request the request that should be printed as comment
|
402
402
|
* @param {boolean=} options.weak if the dependency is weak (will create a nice error message)
|
@@ -439,7 +439,7 @@ class RuntimeTemplate {
|
|
439
439
|
|
440
440
|
/**
|
441
441
|
* @param {Object} options options object
|
442
|
-
* @param {Module} options.module the module
|
442
|
+
* @param {Module | null} options.module the module
|
443
443
|
* @param {ChunkGraph} options.chunkGraph the chunk graph
|
444
444
|
* @param {string} options.request the request that should be printed as comment
|
445
445
|
* @param {boolean=} options.weak if the dependency is weak (will create a nice error message)
|
@@ -939,11 +939,29 @@ class RuntimeTemplate {
|
|
939
939
|
if (chunks.length === 1) {
|
940
940
|
const chunkId = JSON.stringify(chunks[0].id);
|
941
941
|
runtimeRequirements.add(RuntimeGlobals.ensureChunk);
|
942
|
-
|
942
|
+
|
943
|
+
const fetchPriority = chunkGroup.options.fetchPriority;
|
944
|
+
|
945
|
+
if (fetchPriority) {
|
946
|
+
runtimeRequirements.add(RuntimeGlobals.hasFetchPriority);
|
947
|
+
}
|
948
|
+
|
949
|
+
return `${RuntimeGlobals.ensureChunk}(${comment}${chunkId}${
|
950
|
+
fetchPriority ? `, ${JSON.stringify(fetchPriority)}` : ""
|
951
|
+
})`;
|
943
952
|
} else if (chunks.length > 0) {
|
944
953
|
runtimeRequirements.add(RuntimeGlobals.ensureChunk);
|
954
|
+
|
955
|
+
const fetchPriority = chunkGroup.options.fetchPriority;
|
956
|
+
|
957
|
+
if (fetchPriority) {
|
958
|
+
runtimeRequirements.add(RuntimeGlobals.hasFetchPriority);
|
959
|
+
}
|
960
|
+
|
945
961
|
const requireChunkId = chunk =>
|
946
|
-
`${RuntimeGlobals.ensureChunk}(${JSON.stringify(chunk.id)}
|
962
|
+
`${RuntimeGlobals.ensureChunk}(${JSON.stringify(chunk.id)}${
|
963
|
+
fetchPriority ? `, ${JSON.stringify(fetchPriority)}` : ""
|
964
|
+
})`;
|
947
965
|
return `Promise.all(${comment.trim()}[${chunks
|
948
966
|
.map(requireChunkId)
|
949
967
|
.join(", ")}])`;
|
@@ -7,9 +7,13 @@
|
|
7
7
|
|
8
8
|
const JavascriptModulesPlugin = require("./javascript/JavascriptModulesPlugin");
|
9
9
|
|
10
|
+
/** @typedef {import("../declarations/plugins/SourceMapDevToolPlugin").SourceMapDevToolPluginOptions} SourceMapDevToolPluginOptions */
|
10
11
|
/** @typedef {import("./Compilation")} Compilation */
|
11
12
|
|
12
13
|
class SourceMapDevToolModuleOptionsPlugin {
|
14
|
+
/**
|
15
|
+
* @param {SourceMapDevToolPluginOptions} options options
|
16
|
+
*/
|
13
17
|
constructor(options) {
|
14
18
|
this.options = options;
|
15
19
|
}
|
@@ -22,6 +22,7 @@ const { makePathsAbsolute } = require("./util/identifier");
|
|
22
22
|
/** @typedef {import("./Cache").Etag} Etag */
|
23
23
|
/** @typedef {import("./CacheFacade").ItemCacheFacade} ItemCacheFacade */
|
24
24
|
/** @typedef {import("./Chunk")} Chunk */
|
25
|
+
/** @typedef {import("./Compilation").Asset} Asset */
|
25
26
|
/** @typedef {import("./Compilation").AssetInfo} AssetInfo */
|
26
27
|
/** @typedef {import("./Compilation").PathData} PathData */
|
27
28
|
/** @typedef {import("./Compiler")} Compiler */
|
@@ -227,7 +228,9 @@ class SourceMapDevToolPlugin {
|
|
227
228
|
asyncLib.each(
|
228
229
|
files,
|
229
230
|
(file, callback) => {
|
230
|
-
const asset =
|
231
|
+
const asset =
|
232
|
+
/** @type {Readonly<Asset>} */
|
233
|
+
(compilation.getAsset(file));
|
231
234
|
if (asset.info.related && asset.info.related.sourceMap) {
|
232
235
|
fileIndex++;
|
233
236
|
return callback();
|
@@ -363,7 +366,9 @@ class SourceMapDevToolPlugin {
|
|
363
366
|
// find modules with conflicting source names
|
364
367
|
for (let idx = 0; idx < allModules.length; idx++) {
|
365
368
|
const module = allModules[idx];
|
366
|
-
let sourceName =
|
369
|
+
let sourceName =
|
370
|
+
/** @type {string} */
|
371
|
+
(moduleToSourceNameMapping.get(module));
|
367
372
|
let hasName = conflictDetectionSet.has(sourceName);
|
368
373
|
if (!hasName) {
|
369
374
|
conflictDetectionSet.add(sourceName);
|
package/lib/UseStrictPlugin.js
CHANGED
@@ -13,7 +13,10 @@ const {
|
|
13
13
|
const ConstDependency = require("./dependencies/ConstDependency");
|
14
14
|
|
15
15
|
/** @typedef {import("./Compiler")} Compiler */
|
16
|
+
/** @typedef {import("./Dependency").DependencyLocation} DependencyLocation */
|
17
|
+
/** @typedef {import("./Module").BuildInfo} BuildInfo */
|
16
18
|
/** @typedef {import("./javascript/JavascriptParser")} JavascriptParser */
|
19
|
+
/** @typedef {import("./javascript/JavascriptParser").Range} Range */
|
17
20
|
|
18
21
|
const PLUGIN_NAME = "UseStrictPlugin";
|
19
22
|
|
@@ -42,10 +45,14 @@ class UseStrictPlugin {
|
|
42
45
|
// Remove "use strict" expression. It will be added later by the renderer again.
|
43
46
|
// This is necessary in order to not break the strict mode when webpack prepends code.
|
44
47
|
// @see https://github.com/webpack/webpack/issues/1970
|
45
|
-
const dep = new ConstDependency(
|
46
|
-
|
48
|
+
const dep = new ConstDependency(
|
49
|
+
"",
|
50
|
+
/** @type {Range} */ (firstNode.range)
|
51
|
+
);
|
52
|
+
dep.loc = /** @type {DependencyLocation} */ (firstNode.loc);
|
47
53
|
parser.state.module.addPresentationalDependency(dep);
|
48
|
-
|
54
|
+
/** @type {BuildInfo} */
|
55
|
+
(parser.state.module.buildInfo).strict = true;
|
49
56
|
}
|
50
57
|
});
|
51
58
|
};
|