webpack 5.98.0 → 5.99.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.
- package/README.md +7 -3
- package/lib/AsyncDependenciesBlock.js +3 -1
- package/lib/BannerPlugin.js +1 -1
- package/lib/Cache.js +9 -7
- package/lib/CacheFacade.js +5 -5
- package/lib/Chunk.js +2 -2
- package/lib/ChunkGraph.js +21 -16
- package/lib/ChunkTemplate.js +6 -6
- package/lib/CleanPlugin.js +10 -10
- package/lib/CodeGenerationResults.js +4 -3
- package/lib/CompatibilityPlugin.js +4 -1
- package/lib/Compilation.js +326 -152
- package/lib/Compiler.js +13 -18
- package/lib/ConditionalInitFragment.js +1 -1
- package/lib/ConstPlugin.js +5 -3
- package/lib/ContextModule.js +4 -2
- package/lib/ContextModuleFactory.js +3 -3
- package/lib/ContextReplacementPlugin.js +43 -16
- package/lib/DefinePlugin.js +25 -24
- package/lib/DelegatedModule.js +4 -2
- package/lib/DelegatedModuleFactoryPlugin.js +2 -1
- package/lib/Dependency.js +19 -13
- package/lib/DependencyTemplates.js +4 -3
- package/lib/DllModule.js +4 -2
- package/lib/DllModuleFactory.js +2 -2
- package/lib/DllReferencePlugin.js +2 -1
- package/lib/DynamicEntryPlugin.js +1 -1
- package/lib/EnvironmentPlugin.js +4 -2
- package/lib/ExportsInfo.js +72 -40
- package/lib/ExternalModule.js +14 -5
- package/lib/ExternalModuleFactoryPlugin.js +24 -12
- package/lib/FileSystemInfo.js +129 -94
- package/lib/FlagDependencyExportsPlugin.js +6 -4
- package/lib/FlagDependencyUsagePlugin.js +1 -1
- package/lib/Generator.js +29 -1
- package/lib/HookWebpackError.js +2 -2
- package/lib/HotModuleReplacementPlugin.js +3 -9
- package/lib/IgnoreErrorModuleFactory.js +2 -2
- package/lib/IgnorePlugin.js +0 -5
- package/lib/InitFragment.js +1 -1
- package/lib/LoaderOptionsPlugin.js +8 -5
- package/lib/MainTemplate.js +7 -7
- package/lib/Module.js +40 -17
- package/lib/ModuleBuildError.js +3 -1
- package/lib/ModuleDependencyError.js +4 -3
- package/lib/ModuleDependencyWarning.js +4 -3
- package/lib/ModuleFactory.js +9 -3
- package/lib/ModuleFilenameHelpers.js +13 -13
- package/lib/ModuleGraph.js +20 -14
- package/lib/ModuleGraphConnection.js +7 -13
- package/lib/ModuleNotFoundError.js +1 -1
- package/lib/ModuleParseError.js +2 -1
- package/lib/ModuleSourceTypesConstants.js +11 -0
- package/lib/ModuleTemplate.js +5 -5
- package/lib/ModuleTypeConstants.js +15 -0
- package/lib/MultiCompiler.js +4 -4
- package/lib/MultiStats.js +1 -1
- package/lib/NormalModule.js +101 -54
- package/lib/NormalModuleFactory.js +38 -33
- package/lib/NormalModuleReplacementPlugin.js +3 -2
- package/lib/NullFactory.js +2 -2
- package/lib/Parser.js +4 -3
- package/lib/ProgressPlugin.js +1 -2
- package/lib/RawModule.js +4 -2
- package/lib/RecordIdsPlugin.js +6 -2
- package/lib/RequestShortener.js +3 -1
- package/lib/ResolverFactory.js +12 -9
- package/lib/RuntimeModule.js +4 -2
- package/lib/RuntimeTemplate.js +2 -1
- package/lib/SelfModuleFactory.js +2 -2
- package/lib/SourceMapDevToolPlugin.js +0 -8
- package/lib/Template.js +6 -5
- package/lib/TemplatedPathPlugin.js +15 -12
- package/lib/WebpackOptionsApply.js +1 -1
- package/lib/asset/AssetGenerator.js +237 -170
- package/lib/asset/AssetModulesPlugin.js +50 -8
- package/lib/asset/AssetSourceGenerator.js +18 -0
- package/lib/asset/RawDataUrlModule.js +4 -2
- package/lib/buildChunkGraph.js +14 -4
- package/lib/cache/MemoryWithGcCachePlugin.js +6 -2
- package/lib/cache/PackFileCacheStrategy.js +137 -121
- package/lib/cache/ResolverCachePlugin.js +15 -7
- package/lib/cache/getLazyHashedEtag.js +4 -3
- package/lib/cli.js +23 -15
- package/lib/config/defaults.js +93 -26
- package/lib/config/normalization.js +14 -13
- package/lib/config/target.js +8 -8
- package/lib/container/ContainerEntryModule.js +4 -2
- package/lib/container/ContainerEntryModuleFactory.js +2 -2
- package/lib/container/FallbackModule.js +4 -2
- package/lib/container/FallbackModuleFactory.js +2 -2
- package/lib/container/RemoteModule.js +4 -2
- package/lib/container/options.js +5 -5
- package/lib/css/CssGenerator.js +71 -9
- package/lib/css/CssModulesPlugin.js +30 -5
- package/lib/css/CssParser.js +37 -17
- package/lib/css/walkCssTokens.js +17 -17
- package/lib/debug/ProfilingPlugin.js +98 -38
- package/lib/dependencies/AMDDefineDependencyParserPlugin.js +10 -4
- package/lib/dependencies/AMDPlugin.js +5 -2
- package/lib/dependencies/AMDRequireArrayDependency.js +4 -3
- package/lib/dependencies/AMDRequireContextDependency.js +2 -1
- package/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js +15 -7
- package/lib/dependencies/AMDRuntimeModules.js +3 -1
- package/lib/dependencies/CommonJsExportRequireDependency.js +4 -5
- package/lib/dependencies/CommonJsExportsParserPlugin.js +3 -3
- package/lib/dependencies/CommonJsImportsParserPlugin.js +8 -7
- package/lib/dependencies/CommonJsRequireContextDependency.js +2 -1
- package/lib/dependencies/ContextDependencyHelpers.js +13 -6
- package/lib/dependencies/CssIcssExportDependency.js +15 -12
- package/lib/dependencies/CssIcssImportDependency.js +4 -1
- package/lib/dependencies/CssLocalIdentifierDependency.js +17 -14
- package/lib/dependencies/ExportsInfoDependency.js +6 -1
- package/lib/dependencies/HarmonyEvaluatedImportSpecifierDependency.js +5 -5
- package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +22 -15
- package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +23 -8
- package/lib/dependencies/HarmonyExportSpecifierDependency.js +2 -2
- package/lib/dependencies/HarmonyImportDependency.js +8 -6
- package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +19 -14
- package/lib/dependencies/HarmonyImportSpecifierDependency.js +5 -5
- package/lib/dependencies/ImportContextDependency.js +2 -1
- package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +8 -4
- package/lib/dependencies/JsonExportsDependency.js +24 -8
- package/lib/dependencies/LoaderPlugin.js +4 -14
- package/lib/dependencies/RequireContextDependency.js +2 -1
- package/lib/dependencies/RequireContextDependencyParserPlugin.js +6 -3
- package/lib/dependencies/RequireEnsureDependenciesBlock.js +3 -2
- package/lib/dependencies/RequireEnsureDependenciesBlockParserPlugin.js +11 -5
- package/lib/dependencies/RequireResolveContextDependency.js +1 -1
- package/lib/dependencies/WebAssemblyExportImportedDependency.js +1 -1
- package/lib/dependencies/WorkerDependency.js +6 -3
- package/lib/dependencies/WorkerPlugin.js +100 -41
- package/lib/esm/ModuleChunkFormatPlugin.js +5 -0
- package/lib/hmr/HotModuleReplacement.runtime.js +1 -0
- package/lib/hmr/JavascriptHotModuleReplacement.runtime.js +1 -0
- package/lib/hmr/LazyCompilationPlugin.js +32 -24
- package/lib/hmr/lazyCompilationBackend.js +1 -1
- package/lib/ids/DeterministicModuleIdsPlugin.js +1 -1
- package/lib/ids/HashedModuleIdsPlugin.js +2 -1
- package/lib/ids/IdHelpers.js +15 -14
- package/lib/ids/SyncModuleIdsPlugin.js +9 -5
- package/lib/index.js +5 -5
- package/lib/javascript/BasicEvaluatedExpression.js +6 -6
- package/lib/javascript/JavascriptGenerator.js +11 -1
- package/lib/javascript/JavascriptModulesPlugin.js +51 -31
- package/lib/javascript/JavascriptParser.js +287 -188
- package/lib/javascript/JavascriptParserHelpers.js +10 -9
- package/lib/javascript/StartupHelpers.js +4 -1
- package/lib/json/JsonData.js +4 -4
- package/lib/json/JsonGenerator.js +54 -22
- package/lib/json/JsonModulesPlugin.js +16 -2
- package/lib/json/JsonParser.js +8 -4
- package/lib/library/AbstractLibraryPlugin.js +7 -3
- package/lib/library/AssignLibraryPlugin.js +29 -1
- package/lib/library/EnableLibraryPlugin.js +7 -10
- package/lib/library/ExportPropertyLibraryPlugin.js +4 -1
- package/lib/library/ModuleLibraryPlugin.js +121 -15
- package/lib/logging/Logger.js +2 -2
- package/lib/logging/createConsoleLogger.js +4 -4
- package/lib/node/NodeEnvironmentPlugin.js +6 -2
- package/lib/node/ReadFileCompileAsyncWasmPlugin.js +1 -2
- package/lib/node/ReadFileCompileWasmPlugin.js +1 -2
- package/lib/node/nodeConsole.js +3 -1
- package/lib/optimize/AggressiveSplittingPlugin.js +1 -1
- package/lib/optimize/ConcatenatedModule.js +19 -12
- package/lib/optimize/InnerGraph.js +3 -2
- package/lib/optimize/InnerGraphPlugin.js +13 -7
- package/lib/optimize/LimitChunkCountPlugin.js +20 -0
- package/lib/optimize/ModuleConcatenationPlugin.js +10 -7
- package/lib/optimize/RealContentHashPlugin.js +8 -4
- package/lib/optimize/SideEffectsFlagPlugin.js +4 -2
- package/lib/optimize/SplitChunksPlugin.js +87 -65
- package/lib/rules/BasicEffectRulePlugin.js +9 -1
- package/lib/rules/BasicMatcherRulePlugin.js +15 -4
- package/lib/rules/ObjectMatcherRulePlugin.js +12 -3
- package/lib/rules/RuleSetCompiler.js +25 -14
- package/lib/rules/UseEffectRulePlugin.js +47 -17
- package/lib/runtime/GetChunkFilenameRuntimeModule.js +6 -6
- package/lib/schemes/HttpUriPlugin.js +38 -17
- package/lib/serialization/BinaryMiddleware.js +52 -19
- package/lib/serialization/FileMiddleware.js +78 -48
- package/lib/serialization/ObjectMiddleware.js +78 -29
- package/lib/serialization/PlainObjectSerializer.js +1 -1
- package/lib/serialization/Serializer.js +15 -10
- package/lib/serialization/SerializerMiddleware.js +80 -41
- package/lib/serialization/SingleItemMiddleware.js +10 -7
- package/lib/serialization/types.js +1 -1
- package/lib/sharing/ConsumeSharedModule.js +4 -2
- package/lib/sharing/ProvideSharedModule.js +4 -2
- package/lib/sharing/ProvideSharedModuleFactory.js +5 -3
- package/lib/sharing/utils.js +2 -2
- package/lib/stats/DefaultStatsFactoryPlugin.js +80 -78
- package/lib/stats/DefaultStatsPresetPlugin.js +43 -23
- package/lib/stats/DefaultStatsPrinterPlugin.js +85 -43
- package/lib/stats/StatsFactory.js +11 -11
- package/lib/stats/StatsPrinter.js +7 -7
- package/lib/util/ArrayHelpers.js +2 -4
- package/lib/util/ArrayQueue.js +1 -1
- package/lib/util/AsyncQueue.js +4 -4
- package/lib/util/IterableHelpers.js +1 -1
- package/lib/util/LazyBucketSortedSet.js +41 -23
- package/lib/util/LazySet.js +3 -2
- package/lib/util/MapHelpers.js +1 -1
- package/lib/util/ParallelismFactorCalculator.js +1 -1
- package/lib/util/Semaphore.js +3 -3
- package/lib/util/SetHelpers.js +1 -1
- package/lib/util/SortableSet.js +9 -7
- package/lib/util/TupleQueue.js +9 -8
- package/lib/util/TupleSet.js +2 -2
- package/lib/util/WeakTupleMap.js +12 -11
- package/lib/util/binarySearchBounds.js +2 -1
- package/lib/util/cleverMerge.js +84 -54
- package/lib/util/comparators.js +22 -21
- package/lib/util/compileBooleanMatcher.js +3 -3
- package/lib/util/concatenate.js +6 -4
- package/lib/util/create-schema-validation.js +4 -4
- package/lib/util/createHash.js +2 -2
- package/lib/util/deprecation.js +35 -33
- package/lib/util/deterministicGrouping.js +6 -6
- package/lib/util/findGraphRoots.js +1 -1
- package/lib/util/fs.js +39 -39
- package/lib/util/hash/wasm-hash.js +2 -2
- package/lib/util/identifier.js +15 -18
- package/lib/util/makeSerializable.js +1 -1
- package/lib/util/memoize.js +4 -1
- package/lib/util/objectToMap.js +3 -2
- package/lib/util/processAsyncTree.js +2 -2
- package/lib/util/propertyName.js +0 -1
- package/lib/util/registerExternalSerializer.js +15 -18
- package/lib/util/removeBOM.js +25 -0
- package/lib/util/runtime.js +34 -27
- package/lib/util/serialization.js +5 -16
- package/lib/util/smartGrouping.js +3 -3
- package/lib/wasm-async/AsyncWasmLoadingRuntimeModule.js +3 -3
- package/lib/wasm-async/AsyncWebAssemblyGenerator.js +11 -0
- package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +10 -0
- package/lib/wasm-async/UniversalCompileAsyncWasmPlugin.js +4 -0
- package/lib/wasm-sync/WebAssemblyGenerator.js +28 -12
- package/lib/wasm-sync/WebAssemblyJavascriptGenerator.js +10 -0
- package/lib/wasm-sync/WebAssemblyParser.js +9 -4
- package/lib/webworker/ImportScriptsChunkLoadingPlugin.js +3 -0
- package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +30 -25
- package/package.json +19 -17
- package/schemas/WebpackOptions.check.js +1 -1
- package/schemas/WebpackOptions.json +48 -13
- package/schemas/plugins/JsonModulesPluginGenerator.check.d.ts +7 -0
- package/schemas/plugins/JsonModulesPluginGenerator.check.js +6 -0
- package/schemas/plugins/JsonModulesPluginGenerator.json +11 -0
- package/schemas/plugins/SourceMapDevToolPlugin.json +2 -2
- package/types.d.ts +918 -615
- package/lib/library/ModernModuleLibraryPlugin.js +0 -144
package/lib/ProgressPlugin.js
CHANGED
@@ -479,8 +479,7 @@ class ProgressPlugin {
|
|
479
479
|
compilation.hooks.failedEntry.tap("ProgressPlugin", entryDone);
|
480
480
|
compilation.hooks.succeedEntry.tap("ProgressPlugin", entryDone);
|
481
481
|
|
482
|
-
// avoid dynamic require if bundled with webpack
|
483
|
-
// @ts-expect-error
|
482
|
+
// @ts-expect-error avoid dynamic require if bundled with webpack
|
484
483
|
if (typeof __webpack_require__ !== "function") {
|
485
484
|
const requiredLoaders = new Set();
|
486
485
|
NormalModule.getCompilationHooks(compilation).beforeLoaders.tap(
|
package/lib/RawModule.js
CHANGED
@@ -18,8 +18,10 @@ const makeSerializable = require("./util/makeSerializable");
|
|
18
18
|
/** @typedef {import("./Dependency").UpdateHashContext} UpdateHashContext */
|
19
19
|
/** @typedef {import("./DependencyTemplates")} DependencyTemplates */
|
20
20
|
/** @typedef {import("./Generator").SourceTypes} SourceTypes */
|
21
|
+
/** @typedef {import("./Module").BuildCallback} BuildCallback */
|
21
22
|
/** @typedef {import("./Module").CodeGenerationContext} CodeGenerationContext */
|
22
23
|
/** @typedef {import("./Module").CodeGenerationResult} CodeGenerationResult */
|
24
|
+
/** @typedef {import("./Module").NeedBuildCallback} NeedBuildCallback */
|
23
25
|
/** @typedef {import("./Module").NeedBuildContext} NeedBuildContext */
|
24
26
|
/** @typedef {import("./Module").ReadOnlyRuntimeRequirements} ReadOnlyRuntimeRequirements */
|
25
27
|
/** @typedef {import("./RequestShortener")} RequestShortener */
|
@@ -80,7 +82,7 @@ class RawModule extends Module {
|
|
80
82
|
|
81
83
|
/**
|
82
84
|
* @param {NeedBuildContext} context context info
|
83
|
-
* @param {
|
85
|
+
* @param {NeedBuildCallback} callback callback function, returns true, if the module needs a rebuild
|
84
86
|
* @returns {void}
|
85
87
|
*/
|
86
88
|
needBuild(context, callback) {
|
@@ -92,7 +94,7 @@ class RawModule extends Module {
|
|
92
94
|
* @param {Compilation} compilation the compilation
|
93
95
|
* @param {ResolverWithOptions} resolver the resolver
|
94
96
|
* @param {InputFileSystem} fs the file system
|
95
|
-
* @param {
|
97
|
+
* @param {BuildCallback} callback callback function
|
96
98
|
* @returns {void}
|
97
99
|
*/
|
98
100
|
build(options, compilation, resolver, fs, callback) {
|
package/lib/RecordIdsPlugin.js
CHANGED
@@ -32,10 +32,14 @@ const identifierUtils = require("./util/identifier");
|
|
32
32
|
* @property {RecordsModules=} modules
|
33
33
|
*/
|
34
34
|
|
35
|
+
/**
|
36
|
+
* @typedef {object} RecordIdsPluginOptions
|
37
|
+
* @property {boolean=} portableIds true, when ids need to be portable
|
38
|
+
*/
|
39
|
+
|
35
40
|
class RecordIdsPlugin {
|
36
41
|
/**
|
37
|
-
* @param {
|
38
|
-
* @param {boolean=} options.portableIds true, when ids need to be portable
|
42
|
+
* @param {RecordIdsPluginOptions} [options] object
|
39
43
|
*/
|
40
44
|
constructor(options) {
|
41
45
|
this.options = options || {};
|
package/lib/RequestShortener.js
CHANGED
@@ -7,10 +7,12 @@
|
|
7
7
|
|
8
8
|
const { contextify } = require("./util/identifier");
|
9
9
|
|
10
|
+
/** @typedef {import("./util/identifier").AssociatedObjectForCache} AssociatedObjectForCache */
|
11
|
+
|
10
12
|
class RequestShortener {
|
11
13
|
/**
|
12
14
|
* @param {string} dir the directory
|
13
|
-
* @param {
|
15
|
+
* @param {AssociatedObjectForCache=} associatedObjectForCache an object to which the cache will be attached
|
14
16
|
*/
|
15
17
|
constructor(dir, associatedObjectForCache) {
|
16
18
|
this.contextify = contextify.bindContextCache(
|
package/lib/ResolverFactory.js
CHANGED
@@ -20,15 +20,16 @@ const {
|
|
20
20
|
/** @typedef {import("../declarations/WebpackOptions").ResolveOptions} WebpackResolveOptions */
|
21
21
|
/** @typedef {import("../declarations/WebpackOptions").ResolvePluginInstance} ResolvePluginInstance */
|
22
22
|
|
23
|
-
/** @typedef {WebpackResolveOptions & {dependencyType?: string, resolveToContext?: boolean }} ResolveOptionsWithDependencyType */
|
23
|
+
/** @typedef {WebpackResolveOptions & { dependencyType?: string, resolveToContext?: boolean }} ResolveOptionsWithDependencyType */
|
24
24
|
/**
|
25
25
|
* @typedef {object} WithOptions
|
26
|
-
* @property {
|
26
|
+
* @property {(options: Partial<ResolveOptionsWithDependencyType>) => ResolverWithOptions} withOptions create a resolver with additional/different options
|
27
27
|
*/
|
28
28
|
|
29
29
|
/** @typedef {Resolver & WithOptions} ResolverWithOptions */
|
30
30
|
|
31
31
|
// need to be hoisted on module level for caching identity
|
32
|
+
/** @type {ResolveOptionsWithDependencyType} */
|
32
33
|
const EMPTY_RESOLVE_OPTIONS = {};
|
33
34
|
|
34
35
|
/**
|
@@ -39,7 +40,7 @@ const convertToResolveOptions = resolveOptionsWithDepType => {
|
|
39
40
|
const { dependencyType, plugins, ...remaining } = resolveOptionsWithDepType;
|
40
41
|
|
41
42
|
// check type compat
|
42
|
-
/** @type {Partial<
|
43
|
+
/** @type {Partial<ResolveOptionsWithDependencyType>} */
|
43
44
|
const partialOptions = {
|
44
45
|
...remaining,
|
45
46
|
plugins:
|
@@ -56,20 +57,22 @@ const convertToResolveOptions = resolveOptionsWithDepType => {
|
|
56
57
|
}
|
57
58
|
// These weird types validate that we checked all non-optional properties
|
58
59
|
const options =
|
59
|
-
/** @type {Partial<
|
60
|
+
/** @type {Partial<ResolveOptionsWithDependencyType> & Pick<ResolveOptionsWithDependencyType, "fileSystem">} */ (
|
60
61
|
partialOptions
|
61
62
|
);
|
62
63
|
|
63
|
-
return
|
64
|
-
|
65
|
-
|
66
|
-
|
64
|
+
return /** @type {ResolveOptions} */ (
|
65
|
+
removeOperations(
|
66
|
+
resolveByProperty(options, "byDependency", dependencyType),
|
67
|
+
// Keep the `unsafeCache` because it can be a `Proxy`
|
68
|
+
["unsafeCache"]
|
69
|
+
)
|
67
70
|
);
|
68
71
|
};
|
69
72
|
|
70
73
|
/**
|
71
74
|
* @typedef {object} ResolverCache
|
72
|
-
* @property {WeakMap<
|
75
|
+
* @property {WeakMap<ResolveOptionsWithDependencyType, ResolverWithOptions>} direct
|
73
76
|
* @property {Map<string, ResolverWithOptions>} stringified
|
74
77
|
*/
|
75
78
|
|
package/lib/RuntimeModule.js
CHANGED
@@ -18,8 +18,10 @@ const { WEBPACK_MODULE_TYPE_RUNTIME } = require("./ModuleTypeConstants");
|
|
18
18
|
/** @typedef {import("./Compilation")} Compilation */
|
19
19
|
/** @typedef {import("./Dependency").UpdateHashContext} UpdateHashContext */
|
20
20
|
/** @typedef {import("./Generator").SourceTypes} SourceTypes */
|
21
|
+
/** @typedef {import("./Module").BuildCallback} BuildCallback */
|
21
22
|
/** @typedef {import("./Module").CodeGenerationContext} CodeGenerationContext */
|
22
23
|
/** @typedef {import("./Module").CodeGenerationResult} CodeGenerationResult */
|
24
|
+
/** @typedef {import("./Module").NeedBuildCallback} NeedBuildCallback */
|
23
25
|
/** @typedef {import("./Module").NeedBuildContext} NeedBuildContext */
|
24
26
|
/** @typedef {import("./RequestShortener")} RequestShortener */
|
25
27
|
/** @typedef {import("./ResolverFactory").ResolverWithOptions} ResolverWithOptions */
|
@@ -79,7 +81,7 @@ class RuntimeModule extends Module {
|
|
79
81
|
|
80
82
|
/**
|
81
83
|
* @param {NeedBuildContext} context context info
|
82
|
-
* @param {
|
84
|
+
* @param {NeedBuildCallback} callback callback function, returns true, if the module needs a rebuild
|
83
85
|
* @returns {void}
|
84
86
|
*/
|
85
87
|
needBuild(context, callback) {
|
@@ -91,7 +93,7 @@ class RuntimeModule extends Module {
|
|
91
93
|
* @param {Compilation} compilation the compilation
|
92
94
|
* @param {ResolverWithOptions} resolver the resolver
|
93
95
|
* @param {InputFileSystem} fs the file system
|
94
|
-
* @param {
|
96
|
+
* @param {BuildCallback} callback callback function
|
95
97
|
* @returns {void}
|
96
98
|
*/
|
97
99
|
build(options, compilation, resolver, fs, callback) {
|
package/lib/RuntimeTemplate.js
CHANGED
@@ -853,6 +853,7 @@ class RuntimeTemplate {
|
|
853
853
|
}
|
854
854
|
|
855
855
|
/**
|
856
|
+
* @template GenerateContext
|
856
857
|
* @param {object} options options
|
857
858
|
* @param {ModuleGraph} options.moduleGraph the module graph
|
858
859
|
* @param {Module} options.module the module
|
@@ -864,7 +865,7 @@ class RuntimeTemplate {
|
|
864
865
|
* @param {boolean | null} options.callContext when false, call context will not be preserved
|
865
866
|
* @param {boolean} options.defaultInterop when true and accessing the default exports, interop code will be generated
|
866
867
|
* @param {string} options.importVar the identifier name of the import variable
|
867
|
-
* @param {InitFragment<
|
868
|
+
* @param {InitFragment<GenerateContext>[]} options.initFragments init fragments will be added here
|
868
869
|
* @param {RuntimeSpec} options.runtime runtime for which this code will be generated
|
869
870
|
* @param {RuntimeRequirements} options.runtimeRequirements if set, will be filled with runtime requirements
|
870
871
|
* @returns {string} expression
|
package/lib/SelfModuleFactory.js
CHANGED
@@ -5,8 +5,8 @@
|
|
5
5
|
|
6
6
|
"use strict";
|
7
7
|
|
8
|
+
/** @typedef {import("./ModuleFactory").ModuleFactoryCallback} ModuleFactoryCallback */
|
8
9
|
/** @typedef {import("./ModuleFactory").ModuleFactoryCreateData} ModuleFactoryCreateData */
|
9
|
-
/** @typedef {import("./ModuleFactory").ModuleFactoryResult} ModuleFactoryResult */
|
10
10
|
/** @typedef {import("./ModuleGraph")} ModuleGraph */
|
11
11
|
|
12
12
|
class SelfModuleFactory {
|
@@ -19,7 +19,7 @@ class SelfModuleFactory {
|
|
19
19
|
|
20
20
|
/**
|
21
21
|
* @param {ModuleFactoryCreateData} data data object
|
22
|
-
* @param {
|
22
|
+
* @param {ModuleFactoryCallback} callback callback
|
23
23
|
* @returns {void}
|
24
24
|
*/
|
25
25
|
create(data, callback) {
|
@@ -146,16 +146,12 @@ class SourceMapDevToolPlugin {
|
|
146
146
|
? false
|
147
147
|
: // eslint-disable-next-line no-useless-concat
|
148
148
|
options.append || "\n//# source" + "MappingURL=[url]";
|
149
|
-
/** @type {string | Function} */
|
150
149
|
this.moduleFilenameTemplate =
|
151
150
|
options.moduleFilenameTemplate || "webpack://[namespace]/[resourcePath]";
|
152
|
-
/** @type {string | Function} */
|
153
151
|
this.fallbackModuleFilenameTemplate =
|
154
152
|
options.fallbackModuleFilenameTemplate ||
|
155
153
|
"webpack://[namespace]/[resourcePath]?[hash]";
|
156
|
-
/** @type {string} */
|
157
154
|
this.namespace = options.namespace || "";
|
158
|
-
/** @type {SourceMapDevToolPluginOptions} */
|
159
155
|
this.options = options;
|
160
156
|
}
|
161
157
|
|
@@ -196,10 +192,6 @@ class SourceMapDevToolPlugin {
|
|
196
192
|
const cache = compilation.getCache("SourceMapDevToolPlugin");
|
197
193
|
/** @type {Map<string | Module, string>} */
|
198
194
|
const moduleToSourceNameMapping = new Map();
|
199
|
-
/**
|
200
|
-
* @type {Function}
|
201
|
-
* @returns {void}
|
202
|
-
*/
|
203
195
|
const reportProgress =
|
204
196
|
ProgressPlugin.getReporter(compilation.compiler) || (() => {});
|
205
197
|
|
package/lib/Template.js
CHANGED
@@ -60,7 +60,7 @@ const MATCH_PADDED_HYPHENS_REPLACE_REGEX = /^-|-$/g;
|
|
60
60
|
|
61
61
|
/**
|
62
62
|
* @typedef {object} RenderManifestEntryTemplated
|
63
|
-
* @property {
|
63
|
+
* @property {() => Source} render
|
64
64
|
* @property {TemplatePath} filenameTemplate
|
65
65
|
* @property {PathData=} pathOptions
|
66
66
|
* @property {AssetInfo=} info
|
@@ -71,7 +71,7 @@ const MATCH_PADDED_HYPHENS_REPLACE_REGEX = /^-|-$/g;
|
|
71
71
|
|
72
72
|
/**
|
73
73
|
* @typedef {object} RenderManifestEntryStatic
|
74
|
-
* @property {
|
74
|
+
* @property {() => Source} render
|
75
75
|
* @property {string} filename
|
76
76
|
* @property {AssetInfo} info
|
77
77
|
* @property {string} identifier
|
@@ -85,12 +85,13 @@ const MATCH_PADDED_HYPHENS_REPLACE_REGEX = /^-|-$/g;
|
|
85
85
|
*/
|
86
86
|
|
87
87
|
/**
|
88
|
-
* @typedef {
|
88
|
+
* @typedef {(module: Module) => boolean} ModuleFilterPredicate
|
89
89
|
*/
|
90
90
|
|
91
91
|
class Template {
|
92
92
|
/**
|
93
|
-
* @
|
93
|
+
* @template {EXPECTED_FUNCTION} T
|
94
|
+
* @param {T} fn a runtime function (.runtime.js) "template"
|
94
95
|
* @returns {string} the updated and normalized function string
|
95
96
|
*/
|
96
97
|
static getFunctionContent(fn) {
|
@@ -284,7 +285,7 @@ class Template {
|
|
284
285
|
/**
|
285
286
|
* @param {ChunkRenderContext} renderContext render context
|
286
287
|
* @param {Module[]} modules modules to render (should be ordered by identifier)
|
287
|
-
* @param {
|
288
|
+
* @param {(module: Module) => Source | null} renderModule function to render a module
|
288
289
|
* @param {string=} prefix applying prefix strings
|
289
290
|
* @returns {Source | null} rendered chunk modules in a Source object or null if no modules
|
290
291
|
*/
|
@@ -50,10 +50,10 @@ const prepareId = id => {
|
|
50
50
|
* @param {((arg0: number) => string) | undefined} handler handler
|
51
51
|
* @param {AssetInfo | undefined} assetInfo asset info
|
52
52
|
* @param {string} hashName hash name
|
53
|
-
* @returns {
|
53
|
+
* @returns {Replacer} hash replacer function
|
54
54
|
*/
|
55
55
|
const hashLength = (replacer, handler, assetInfo, hashName) => {
|
56
|
-
/** @type {
|
56
|
+
/** @type {Replacer} */
|
57
57
|
const fn = (match, arg, input) => {
|
58
58
|
let result;
|
59
59
|
const length = arg && Number.parseInt(arg, 10);
|
@@ -81,7 +81,7 @@ const hashLength = (replacer, handler, assetInfo, hashName) => {
|
|
81
81
|
return fn;
|
82
82
|
};
|
83
83
|
|
84
|
-
/** @typedef {(match: string, arg
|
84
|
+
/** @typedef {(match: string, arg: string | undefined, input: string) => string} Replacer */
|
85
85
|
|
86
86
|
/**
|
87
87
|
* @param {string | number | null | undefined | (() => string | number | null | undefined)} value value
|
@@ -113,10 +113,11 @@ const replacer = (value, allowEmpty) => {
|
|
113
113
|
const deprecationCache = new Map();
|
114
114
|
const deprecatedFunction = (() => () => {})();
|
115
115
|
/**
|
116
|
-
* @
|
116
|
+
* @template {(...args: EXPECTED_ANY[]) => EXPECTED_ANY} T
|
117
|
+
* @param {T} fn function
|
117
118
|
* @param {string} message message
|
118
119
|
* @param {string} code code
|
119
|
-
* @returns {
|
120
|
+
* @returns {T} function with deprecation output
|
120
121
|
*/
|
121
122
|
const deprecated = (fn, message, code) => {
|
122
123
|
let d = deprecationCache.get(message);
|
@@ -124,13 +125,15 @@ const deprecated = (fn, message, code) => {
|
|
124
125
|
d = util.deprecate(deprecatedFunction, message, code);
|
125
126
|
deprecationCache.set(message, d);
|
126
127
|
}
|
127
|
-
return
|
128
|
-
|
129
|
-
|
130
|
-
|
128
|
+
return /** @type {T} */ (
|
129
|
+
(...args) => {
|
130
|
+
d();
|
131
|
+
return fn(...args);
|
132
|
+
}
|
133
|
+
);
|
131
134
|
};
|
132
135
|
|
133
|
-
/** @typedef {string |
|
136
|
+
/** @typedef {string | ((pathData: PathData, assetInfo?: AssetInfo) => string)} TemplatePath */
|
134
137
|
|
135
138
|
/**
|
136
139
|
* @param {TemplatePath} path the raw path
|
@@ -141,7 +144,7 @@ const deprecated = (fn, message, code) => {
|
|
141
144
|
const replacePathVariables = (path, data, assetInfo) => {
|
142
145
|
const chunkGraph = data.chunkGraph;
|
143
146
|
|
144
|
-
/** @type {Map<string,
|
147
|
+
/** @type {Map<string, Replacer>} */
|
145
148
|
const replacements = new Map();
|
146
149
|
|
147
150
|
// Filename context
|
@@ -366,7 +369,7 @@ const replacePathVariables = (path, data, assetInfo) => {
|
|
366
369
|
const [, kind, arg] = contentMatch;
|
367
370
|
const replacer = replacements.get(kind);
|
368
371
|
if (replacer !== undefined) {
|
369
|
-
return replacer(match, arg, path);
|
372
|
+
return replacer(match, arg, /** @type {string} */ (path));
|
370
373
|
}
|
371
374
|
} else if (match.startsWith("[\\") && match.endsWith("\\]")) {
|
372
375
|
return `[${match.slice(2, -2)}]`;
|
@@ -395,7 +395,7 @@ class WebpackOptionsApply extends OptionsApply {
|
|
395
395
|
new RequireJsStuffPlugin().apply(compiler);
|
396
396
|
}
|
397
397
|
new CommonJsPlugin().apply(compiler);
|
398
|
-
new LoaderPlugin(
|
398
|
+
new LoaderPlugin().apply(compiler);
|
399
399
|
if (options.node !== false) {
|
400
400
|
const NodeStuffPlugin = require("./NodeStuffPlugin");
|
401
401
|
new NodeStuffPlugin(options.node).apply(compiler);
|