From a1df00d339f782baded4bc394d62d702e7ed65d0 Mon Sep 17 00:00:00 2001 From: alexander-akait Date: Wed, 12 Mar 2025 04:56:14 +0300 Subject: [PATCH] refactor: improve eslint configuration and better types --- declarations.d.ts | 1 + eslint.config.mjs | 65 ++- lib/BannerPlugin.js | 2 +- lib/Cache.js | 8 +- lib/CacheFacade.js | 8 +- lib/ChunkGraph.js | 16 +- lib/ChunkTemplate.js | 12 +- lib/CleanPlugin.js | 18 +- lib/Compilation.js | 28 +- lib/Compiler.js | 2 +- lib/ContextModule.js | 6 +- lib/ContextModuleFactory.js | 6 +- lib/DefinePlugin.js | 10 +- lib/DelegatedModule.js | 6 +- lib/Dependency.js | 10 +- lib/DllModule.js | 6 +- lib/DllModuleFactory.js | 4 +- lib/ExportsInfo.js | 25 +- lib/ExternalModule.js | 6 +- lib/ExternalModuleFactoryPlugin.js | 6 +- lib/FileSystemInfo.js | 58 ++- lib/Generator.js | 2 +- lib/HookWebpackError.js | 4 +- lib/IgnoreErrorModuleFactory.js | 4 +- lib/MainTemplate.js | 14 +- lib/Module.js | 17 +- lib/ModuleFactory.js | 6 +- lib/ModuleFilenameHelpers.js | 2 +- lib/ModuleGraph.js | 6 +- lib/ModuleGraphConnection.js | 20 +- lib/ModuleTemplate.js | 10 +- lib/MultiCompiler.js | 6 +- lib/NormalModule.js | 15 +- lib/NormalModuleFactory.js | 3 +- lib/NormalModuleReplacementPlugin.js | 5 +- lib/NullFactory.js | 4 +- lib/ProgressPlugin.js | 3 +- lib/RawModule.js | 6 +- lib/ResolverFactory.js | 2 +- lib/RuntimeModule.js | 6 +- lib/SelfModuleFactory.js | 4 +- lib/Template.js | 8 +- lib/TemplatedPathPlugin.js | 4 +- lib/asset/RawDataUrlModule.js | 6 +- lib/cache/PackFileCacheStrategy.js | 8 +- lib/cache/ResolverCachePlugin.js | 9 +- lib/cache/getLazyHashedEtag.js | 2 +- lib/config/defaults.js | 10 +- lib/config/normalization.js | 26 +- lib/container/ContainerEntryModule.js | 6 +- lib/container/ContainerEntryModuleFactory.js | 4 +- lib/container/FallbackModule.js | 6 +- lib/container/FallbackModuleFactory.js | 4 +- lib/container/RemoteModule.js | 6 +- lib/container/options.js | 10 +- lib/css/CssModulesPlugin.js | 4 +- lib/css/walkCssTokens.js | 34 +- lib/dependencies/AMDPlugin.js | 2 +- lib/dependencies/LoaderPlugin.js | 3 +- lib/hmr/LazyCompilationPlugin.js | 18 +- lib/hmr/lazyCompilationBackend.js | 2 +- lib/ids/DeterministicModuleIdsPlugin.js | 2 +- lib/ids/IdHelpers.js | 16 +- lib/ids/SyncModuleIdsPlugin.js | 2 +- lib/index.js | 6 +- lib/javascript/JavascriptGenerator.js | 2 +- lib/javascript/JavascriptModulesPlugin.js | 2 +- lib/javascript/JavascriptParser.js | 44 +- lib/javascript/JavascriptParserHelpers.js | 19 +- lib/javascript/StartupHelpers.js | 2 +- lib/logging/Logger.js | 4 +- lib/logging/createConsoleLogger.js | 8 +- lib/node/nodeConsole.js | 2 +- lib/optimize/AggressiveSplittingPlugin.js | 2 +- lib/optimize/ConcatenatedModule.js | 5 +- lib/optimize/InnerGraph.js | 5 +- lib/optimize/ModuleConcatenationPlugin.js | 14 +- lib/optimize/RealContentHashPlugin.js | 2 +- lib/optimize/SplitChunksPlugin.js | 4 +- lib/rules/RuleSetCompiler.js | 8 +- lib/rules/UseEffectRulePlugin.js | 8 +- lib/runtime/GetChunkFilenameRuntimeModule.js | 12 +- lib/schemes/HttpUriPlugin.js | 55 +- lib/serialization/FileMiddleware.js | 8 +- lib/serialization/ObjectMiddleware.js | 24 +- lib/serialization/SerializerMiddleware.js | 6 +- lib/sharing/ConsumeSharedModule.js | 6 +- lib/sharing/ProvideSharedModule.js | 6 +- lib/sharing/ProvideSharedModuleFactory.js | 8 +- lib/sharing/utils.js | 4 +- lib/stats/DefaultStatsFactoryPlugin.js | 12 +- lib/stats/DefaultStatsPresetPlugin.js | 6 +- lib/stats/DefaultStatsPrinterPlugin.js | 10 +- lib/stats/StatsFactory.js | 16 +- lib/stats/StatsPrinter.js | 4 +- lib/util/ArrayQueue.js | 2 +- lib/util/AsyncQueue.js | 4 +- lib/util/IterableHelpers.js | 2 +- lib/util/LazyBucketSortedSet.js | 10 +- lib/util/LazySet.js | 2 +- lib/util/MapHelpers.js | 2 +- lib/util/ParallelismFactorCalculator.js | 2 +- lib/util/Semaphore.js | 6 +- lib/util/SetHelpers.js | 2 +- lib/util/SortableSet.js | 8 +- lib/util/TupleSet.js | 4 +- lib/util/WeakTupleMap.js | 2 +- lib/util/cleverMerge.js | 4 +- lib/util/comparators.js | 6 +- lib/util/compileBooleanMatcher.js | 6 +- lib/util/create-schema-validation.js | 4 +- lib/util/createHash.js | 4 +- lib/util/deterministicGrouping.js | 6 +- lib/util/findGraphRoots.js | 2 +- lib/util/fs.js | 74 +-- lib/util/identifier.js | 33 +- lib/util/memoize.js | 2 +- lib/util/processAsyncTree.js | 4 +- lib/util/runtime.js | 6 +- lib/util/smartGrouping.js | 6 +- .../AsyncWasmLoadingRuntimeModule.js | 6 +- setup/setup.js | 28 + test/FileSystemInfo.unittest.js | 2 +- .../1-use-library/webpack.config.js | 2 +- .../webpack.config.js | 2 +- .../css/css-modules-in-node/webpack.config.js | 2 +- .../css-modules-no-space/webpack.config.js | 2 +- .../css/css-modules/webpack.config.js | 2 +- .../0-create-library/webpack.config.js | 3 +- .../library/1-use-library/webpack.config.js | 7 +- .../lib-manifest-plugin/webpack.config.js | 2 +- .../records/issue-295/webpack.config.js | 2 +- .../records/issue-2991/webpack.config.js | 2 +- .../records/issue-7339/webpack.config.js | 2 +- .../records/stable-sort/webpack.config.js | 2 +- .../cache/managedPath/webpack.config.js | 2 +- .../webpack.config.js | 2 +- .../plugins/define-plugin/webpack.config.js | 2 +- .../unable-to-snapshot/webpack.config.js | 2 +- tsconfig.json | 3 +- types.d.ts | 484 ++++++++++-------- 141 files changed, 930 insertions(+), 782 deletions(-) diff --git a/declarations.d.ts b/declarations.d.ts index 5af9485b9..142f50980 100644 --- a/declarations.d.ts +++ b/declarations.d.ts @@ -408,6 +408,7 @@ interface ImportAttributeNode { type TODO = any; type EXPECTED_ANY = any; +type EXPECTED_OBJECT = object; type RecursiveArrayOrRecord = | { [index: string]: RecursiveArrayOrRecord } diff --git a/eslint.config.mjs b/eslint.config.mjs index 1a706d821..1aa1deaa3 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -97,11 +97,8 @@ export default [ "no-else-return": "error", "no-lonely-if": "error", "no-undef-init": "error", - // Disallow @ts-ignore directive. Use @ts-expect-error instead - "no-warning-comments": [ - "error", - { terms: ["@ts-ignore"], location: "start" } - ], + // Disallow ts-ignore directive. Use ts-expect-error instead + "no-warning-comments": ["error", { terms: ["@ts-ignore"] }], "no-constructor-return": "error", "symbol-description": "error", "array-callback-return": [ @@ -282,15 +279,12 @@ export default [ mode: "typescript", // supported tags https://github.com/microsoft/TypeScript-wiki/blob/master/JSDoc-support-in-JavaScript.md tagNamePreference: { - ...["implements", "const", "memberof", "yields"].reduce( - (acc, tag) => { - acc[tag] = { - message: `@${tag} currently not supported in TypeScript` - }; - return acc; - }, - {} - ), + ...["memberof", "yields", "member"].reduce((acc, tag) => { + acc[tag] = { + message: `@${tag} currently not supported in TypeScript` + }; + return acc; + }, {}), extends: "extends", return: "returns", constructor: "constructor", @@ -308,8 +302,7 @@ export default [ rules: { ...jsdocConfig.rules, // Override recommended - // TODO remove me after switch to typescript strict mode - "jsdoc/require-jsdoc": "off", + // // Doesn't support function overloading/tuples/`readonly`/module keyword/etc // Also `typescript` reports this itself "jsdoc/valid-types": "off", @@ -320,12 +313,36 @@ export default [ // More rules "jsdoc/check-indentation": "error", - "jsdoc/no-bad-blocks": "error", + "jsdoc/check-line-alignment": ["error", "never"], + "jsdoc/require-asterisk-prefix": "error", "jsdoc/require-hyphen-before-param-description": ["error", "never"], "jsdoc/require-template": "error", + "jsdoc/no-bad-blocks": "error", "jsdoc/no-blank-block-descriptions": "error", "jsdoc/no-blank-blocks": "error", - "jsdoc/require-asterisk-prefix": "error" + "jsdoc/no-restricted-syntax": [ + "error", + { + contexts: [ + // No `@type {*}` + { + comment: "JsdocBlock:has(JsdocTypeAny)", + message: "Please use `any`." + }, + // No `@type {?}` + { + comment: "JsdocBlock:has(JsdocTypeUnknown)", + message: "Please use `unknown` or `any`" + }, + // Prefer TypeScript syntax for functions + { + comment: "JsdocBlock:has(JsdocTypeFunction[arrow=false])", + message: + "Please use TypeScript syntax - `(a: string, b: boolean) => number`" + } + ] + } + ] } }, { @@ -363,7 +380,8 @@ export default [ "func-style": "off", "unicorn/prefer-includes": "off", "unicorn/no-useless-undefined": "off", - "unicorn/no-array-for-each": "off" + "unicorn/no-array-for-each": "off", + "jsdoc/require-jsdoc": "off" } }, { @@ -398,16 +416,17 @@ export default [ "jest/no-done-callback": "off", "jest/expect-expect": "off", "jest/no-conditional-expect": "off", + "object-shorthand": "off", + camelcase: "off", + "no-var": "off", + "jsdoc/require-jsdoc": "off", "n/no-unsupported-features/node-builtins": [ "error", { ignores: ["Blob"], allowExperimental: true } - ], - "object-shorthand": "off", - camelcase: "off", - "no-var": "off" + ] } }, { diff --git a/lib/BannerPlugin.js b/lib/BannerPlugin.js index e0e19a54a..70937a18f 100644 --- a/lib/BannerPlugin.js +++ b/lib/BannerPlugin.js @@ -19,7 +19,7 @@ const createSchemaValidation = require("./util/create-schema-validation"); /** @typedef {import("./TemplatedPathPlugin").TemplatePath} TemplatePath */ const validate = createSchemaValidation( - /** @type {(function(typeof import("../schemas/plugins/BannerPlugin.json")): boolean)} */ + /** @type {((value: typeof import("../schemas/plugins/BannerPlugin.json")) => boolean)} */ (require("../schemas/plugins/BannerPlugin.check.js")), () => require("../schemas/plugins/BannerPlugin.json"), { diff --git a/lib/Cache.js b/lib/Cache.js index 055ad6d22..e0f02195a 100644 --- a/lib/Cache.js +++ b/lib/Cache.js @@ -15,7 +15,7 @@ const { /** * @typedef {object} Etag - * @property {function(): string} toString + * @property {() => string} toString */ /** @@ -29,14 +29,14 @@ const { /** * @callback GotHandler * @param {any} result - * @param {function(Error=): void} callback + * @param {(err?: Error) => void} callback * @returns {void} */ /** * @param {number} times times - * @param {function(Error=): void} callback callback - * @returns {function(Error=): void} callback + * @param {(err?: Error) => void} callback callback + * @returns {(err?: Error) => void} callback */ const needCalls = (times, callback) => err => { if (--times === 0) { diff --git a/lib/CacheFacade.js b/lib/CacheFacade.js index eece96317..6155db4b1 100644 --- a/lib/CacheFacade.js +++ b/lib/CacheFacade.js @@ -160,7 +160,7 @@ class ItemCacheFacade { /** * @template T - * @param {function(CallbackNormalErrorCache): void} computer function to compute the value if not cached + * @param {(callback: CallbackNormalErrorCache) => void} computer function to compute the value if not cached * @param {CallbackNormalErrorCache} callback signals when the value is retrieved * @returns {void} */ @@ -180,7 +180,7 @@ class ItemCacheFacade { /** * @template T - * @param {function(): Promise | T} computer function to compute the value if not cached + * @param {() => Promise | T} computer function to compute the value if not cached * @returns {Promise} promise with the data */ async providePromise(computer) { @@ -310,7 +310,7 @@ class CacheFacade { * @template T * @param {string} identifier the cache identifier * @param {Etag | null} etag the etag - * @param {function(CallbackNormalErrorCache): void} computer function to compute the value if not cached + * @param {(callback: CallbackNormalErrorCache) => void} computer function to compute the value if not cached * @param {CallbackNormalErrorCache} callback signals when the value is retrieved * @returns {void} */ @@ -332,7 +332,7 @@ class CacheFacade { * @template T * @param {string} identifier the cache identifier * @param {Etag | null} etag the etag - * @param {function(): Promise | T} computer function to compute the value if not cached + * @param {() => Promise | T} computer function to compute the value if not cached * @returns {Promise} promise with the data */ async providePromise(identifier, etag, computer) { diff --git a/lib/ChunkGraph.js b/lib/ChunkGraph.js index d13e8afe5..93cd6758a 100644 --- a/lib/ChunkGraph.js +++ b/lib/ChunkGraph.js @@ -61,7 +61,7 @@ const compareModuleIterables = compareIterables(compareModulesByIdentifier); class ModuleHashInfo { /** * @param {string} hash hash - * @param {string} renderedHash rendered hash + * @param {string} renderedHash rendered hash */ constructor(hash, renderedHash) { this.hash = hash; @@ -92,7 +92,7 @@ const getModuleRuntimes = chunks => { /** * @param {WeakMap> | undefined} sourceTypesByModule sourceTypesByModule - * @returns {function (SortableSet): Map>} modules by source type + * @returns {(set: SortableSet) => Map>} modules by source type */ const modulesBySourceType = sourceTypesByModule => set => { /** @type {Map>} */ @@ -129,7 +129,7 @@ const createOrderedArrayFunctionMap = new WeakMap(); /** * @template T - * @param {function(T, T): -1|0|1} comparator comparator function + * @param {(a: T, b:T) => -1 | 0 | 1 } comparator comparator function * @returns {SetToArrayFunction} set as ordered array */ const createOrderedArrayFunction = comparator => { @@ -237,6 +237,8 @@ class ChunkGraphChunk { } } +/** @typedef {(a: Module, b: Module) => -1 | 0 | 1} ModuleComparator */ + class ChunkGraph { /** * @param {ModuleGraph} moduleGraph the module graph @@ -535,7 +537,7 @@ class ChunkGraph { /** * @param {Module} module the module - * @param {function(Chunk, Chunk): -1|0|1} sortFn sort function + * @param {(a: Chunk, b: Chunk) => -1 | 0 | 1} sortFn sort function * @returns {Iterable} iterable of chunks (do not modify) */ getOrderedModuleChunksIterable(module, sortFn) { @@ -686,7 +688,7 @@ class ChunkGraph { /** * @param {Chunk} chunk the chunk - * @param {function(Module, Module): -1|0|1} comparator comparator function + * @param {ModuleComparator} comparator comparator function * @returns {Iterable} return the modules for this chunk */ getOrderedChunkModulesIterable(chunk, comparator) { @@ -698,7 +700,7 @@ class ChunkGraph { /** * @param {Chunk} chunk the chunk * @param {string} sourceType source type - * @param {function(Module, Module): -1|0|1} comparator comparator function + * @param {ModuleComparator} comparator comparator function * @returns {Iterable | undefined} return the modules for this chunk */ getOrderedChunkModulesIterableBySourceType(chunk, sourceType, comparator) { @@ -722,7 +724,7 @@ class ChunkGraph { /** * @param {Chunk} chunk the chunk - * @param {function(Module, Module): -1|0|1} comparator comparator function + * @param {ModuleComparator} comparator comparator function * @returns {Module[]} return the modules for this chunk (cached, do not modify) */ getOrderedChunkModules(chunk, comparator) { diff --git a/lib/ChunkTemplate.js b/lib/ChunkTemplate.js index 238144a30..f76557e9e 100644 --- a/lib/ChunkTemplate.js +++ b/lib/ChunkTemplate.js @@ -42,7 +42,7 @@ class ChunkTemplate { /** * @template AdditionalOptions * @param {string | Tap & IfSet} options options - * @param {function(RenderManifestEntry[], RenderManifestOptions): RenderManifestEntry[]} fn function + * @param {(renderManifestEntries: RenderManifestEntry[], renderManifestOptions: RenderManifestOptions) => RenderManifestEntry[]} fn function */ (options, fn) => { compilation.hooks.renderManifest.tap( @@ -62,7 +62,7 @@ class ChunkTemplate { /** * @template AdditionalOptions * @param {string | Tap & IfSet} options options - * @param {function(Source, ModuleTemplate, RenderContext): Source} fn function + * @param {(source: Source, moduleTemplate: ModuleTemplate, renderContext: RenderContext) => Source} fn function */ (options, fn) => { getJavascriptModulesPlugin() @@ -84,7 +84,7 @@ class ChunkTemplate { /** * @template AdditionalOptions * @param {string | Tap & IfSet} options options - * @param {function(Source, ModuleTemplate, RenderContext): Source} fn function + * @param {(source: Source, moduleTemplate: ModuleTemplate, renderContext: RenderContext) => Source} fn function */ (options, fn) => { getJavascriptModulesPlugin() @@ -106,7 +106,7 @@ class ChunkTemplate { /** * @template AdditionalOptions * @param {string | Tap & IfSet} options options - * @param {function(Source, Chunk): Source} fn function + * @param {(source: Source, chunk: Chunk) => Source} fn function */ (options, fn) => { getJavascriptModulesPlugin() @@ -132,7 +132,7 @@ class ChunkTemplate { /** * @template AdditionalOptions * @param {string | Tap & IfSet} options options - * @param {function(Hash): void} fn function + * @param {(hash: Hash) => void} fn function */ (options, fn) => { compilation.hooks.fullHash.tap(options, fn); @@ -146,7 +146,7 @@ class ChunkTemplate { /** * @template AdditionalOptions * @param {string | Tap & IfSet} options options - * @param {function(Hash, Chunk, ChunkHashContext): void} fn function + * @param {(hash: Hash, chunk: Chunk, chunkHashContext: ChunkHashContext) => void} fn function */ (options, fn) => { getJavascriptModulesPlugin() diff --git a/lib/CleanPlugin.js b/lib/CleanPlugin.js index 33e601e6d..e64a9bab3 100644 --- a/lib/CleanPlugin.js +++ b/lib/CleanPlugin.js @@ -19,9 +19,7 @@ const processAsyncTree = require("./util/processAsyncTree"); /** @typedef {import("./util/fs").OutputFileSystem} OutputFileSystem */ /** @typedef {import("./util/fs").StatsCallback} StatsCallback */ -/** @typedef {(function(string):boolean)|RegExp} IgnoreItem */ /** @typedef {Map} Assets */ -/** @typedef {function(IgnoreItem): void} AddToIgnoreCallback */ /** * @typedef {object} CleanPluginCompilationHooks @@ -63,11 +61,13 @@ const mergeAssets = (as1, as2) => { } }; +/** @typedef {Set} Diff */ + /** * @param {OutputFileSystem} fs filesystem * @param {string} outputPath output path * @param {Map} currentAssets filename of the current assets (must not start with .. or ., must only use / as path separator) - * @param {function((Error | null)=, Set=): void} callback returns the filenames of the assets that shouldn't be there + * @param {(err?: Error | null, set?: Diff) => void} callback returns the filenames of the assets that shouldn't be there * @returns {void} */ const getDiffToFs = (fs, outputPath, currentAssets, callback) => { @@ -116,7 +116,7 @@ const getDiffToFs = (fs, outputPath, currentAssets, callback) => { /** * @param {Assets} currentAssets assets list * @param {Assets} oldAssets old assets list - * @returns {Set} diff + * @returns {Diff} diff */ const getDiffToOldAssets = (currentAssets, oldAssets) => { const diff = new Set(); @@ -148,9 +148,9 @@ const doStat = (fs, filename, callback) => { * @param {string} outputPath output path * @param {boolean} dry only log instead of fs modification * @param {Logger} logger logger - * @param {Set} diff filenames of the assets that shouldn't be there - * @param {function(string): boolean | void} isKept check if the entry is ignored - * @param {function(Error=, Assets=): void} callback callback + * @param {Diff} diff filenames of the assets that shouldn't be there + * @param {(path: string) => boolean | void} isKept check if the entry is ignored + * @param {(err?: Error, assets?: Assets) => void} callback callback * @returns {void} */ const applyDiff = (fs, outputPath, dry, logger, diff, isKept, callback) => { @@ -402,7 +402,7 @@ class CleanPlugin { /** * @param {(Error | null)=} err err - * @param {Set=} diff diff + * @param {Diff=} diff diff */ const diffCallback = (err, diff) => { if (err) { @@ -415,7 +415,7 @@ class CleanPlugin { outputPath, dry, logger, - /** @type {Set} */ (diff), + /** @type {Diff} */ (diff), isKept, (err, keptAssets) => { if (err) { diff --git a/lib/Compilation.js b/lib/Compilation.js index fdd326682..41984cb61 100644 --- a/lib/Compilation.js +++ b/lib/Compilation.js @@ -193,10 +193,10 @@ const { isSourceEqual } = require("./util/source"); /** * @typedef {object} ChunkPathData - * @property {string|number} id + * @property {string | number} id * @property {string=} name * @property {string} hash - * @property {function(number): string=} hashWithLength + * @property {((length: number) => string)=} hashWithLength * @property {(Record)=} contentHash * @property {(Record string>)=} contentHashWithLength */ @@ -310,25 +310,25 @@ const { isSourceEqual } = require("./util/source"); /** * @typedef {object} ModulePathData - * @property {string|number} id + * @property {string | number} id * @property {string} hash - * @property {function(number): string=} hashWithLength + * @property {((length: number) => string)=} hashWithLength */ /** * @typedef {object} PathData * @property {ChunkGraph=} chunkGraph * @property {string=} hash - * @property {function(number): string=} hashWithLength - * @property {(Chunk|ChunkPathData)=} chunk - * @property {(Module|ModulePathData)=} module + * @property {((length: number) => string)=} hashWithLength + * @property {(Chunk | ChunkPathData)=} chunk + * @property {(Module | ModulePathData)=} module * @property {RuntimeSpec=} runtime * @property {string=} filename * @property {string=} basename * @property {string=} query * @property {string=} contentHashType * @property {string=} contentHash - * @property {function(number): string=} contentHashWithLength + * @property {((length: number) => string)=} contentHashWithLength * @property {boolean=} noChunkHash * @property {string=} url */ @@ -644,7 +644,7 @@ class Compilation { * @template T * @param {string} name name of the hook * @param {number} stage new stage - * @param {function(): AsArray} getArgs get old hook function args + * @param {() => AsArray} getArgs get old hook function args * @param {string=} code deprecation code (not deprecated when unset) * @returns {FakeHook, "tap" | "tapAsync" | "tapPromise" | "name">>} fake hook which redirects */ @@ -936,7 +936,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si /** @type {SyncHook<[Chunk, string]>} */ chunkAsset: new SyncHook(["chunk", "filename"]), - /** @type {SyncWaterfallHook<[string, object, AssetInfo | undefined]>} */ + /** @type {SyncWaterfallHook<[string, PathData, AssetInfo | undefined]>} */ assetPath: new SyncWaterfallHook(["path", "options", "assetInfo"]), /** @type {SyncBailHook<[], boolean | void>} */ @@ -1255,7 +1255,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si } /** - * @param {string | (function(): string)} name name of the logger, or function called once to get the logger name + * @param {string | (() => string)} name name of the logger, or function called once to get the logger name * @returns {Logger} a logger with that name */ getLogger(name) { @@ -3565,7 +3565,7 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o * @param {RuntimeTemplate} runtimeTemplate runtimeTemplate * @param {WebpackError[]} errors errors * @param {CodeGenerationResults} results results - * @param {function((WebpackError | null)=, boolean=): void} callback callback + * @param {(err?: WebpackError | null, result?: boolean) => void} callback callback */ _codeGenerationModule( module, @@ -4651,8 +4651,8 @@ This prevents using hashes of each other and should be avoided.`); /** * @param {string} file file name - * @param {Source | function(Source): Source} newSourceOrFunction new asset source or function converting old to new - * @param {(AssetInfo | function(AssetInfo | undefined): AssetInfo) | undefined} assetInfoUpdateOrFunction new asset info or function converting old to new + * @param {Source | ((source: Source) => Source)} newSourceOrFunction new asset source or function converting old to new + * @param {(AssetInfo | ((assetInfo?: AssetInfo) => AssetInfo)) | undefined} assetInfoUpdateOrFunction new asset info or function converting old to new */ updateAsset( file, diff --git a/lib/Compiler.js b/lib/Compiler.js index 1a5a7a005..411cbc5b7 100644 --- a/lib/Compiler.js +++ b/lib/Compiler.js @@ -341,7 +341,7 @@ class Compiler { } /** - * @param {string | (function(): string)} name name of the logger, or function called once to get the logger name + * @param {string | (() => string)} name name of the logger, or function called once to get the logger name * @returns {Logger} a logger with that name */ getInfrastructureLogger(name) { diff --git a/lib/ContextModule.js b/lib/ContextModule.js index 0ad81bd0b..9dfa3c8ba 100644 --- a/lib/ContextModule.js +++ b/lib/ContextModule.js @@ -39,11 +39,13 @@ const makeSerializable = require("./util/makeSerializable"); /** @typedef {import("./Dependency")} Dependency */ /** @typedef {import("./DependencyTemplates")} DependencyTemplates */ /** @typedef {import("./Generator").SourceTypes} SourceTypes */ +/** @typedef {import("./Module").BuildCallback} BuildCallback */ /** @typedef {import("./Module").BuildInfo} BuildInfo */ /** @typedef {import("./Module").BuildMeta} BuildMeta */ /** @typedef {import("./Module").CodeGenerationContext} CodeGenerationContext */ /** @typedef {import("./Module").CodeGenerationResult} CodeGenerationResult */ /** @typedef {import("./Module").LibIdentOptions} LibIdentOptions */ +/** @typedef {import("./Module").NeedBuildCallback} NeedBuildCallback */ /** @typedef {import("./Module").NeedBuildContext} NeedBuildContext */ /** @typedef {import("./ModuleGraph")} ModuleGraph */ /** @typedef {import("./RequestShortener")} RequestShortener */ @@ -399,7 +401,7 @@ class ContextModule extends Module { /** * @param {NeedBuildContext} context context info - * @param {function((WebpackError | null)=, boolean=): void} callback callback function, returns true, if the module needs a rebuild + * @param {NeedBuildCallback} callback callback function, returns true, if the module needs a rebuild * @returns {void} */ needBuild({ fileSystemInfo }, callback) { @@ -422,7 +424,7 @@ class ContextModule extends Module { * @param {Compilation} compilation the compilation * @param {ResolverWithOptions} resolver the resolver * @param {InputFileSystem} fs the file system - * @param {function(WebpackError=): void} callback callback function + * @param {BuildCallback} callback callback function * @returns {void} */ build(options, compilation, resolver, fs, callback) { diff --git a/lib/ContextModuleFactory.js b/lib/ContextModuleFactory.js index 23da02663..37573f94c 100644 --- a/lib/ContextModuleFactory.js +++ b/lib/ContextModuleFactory.js @@ -19,7 +19,7 @@ const { join } = require("./util/fs"); /** @typedef {import("./ContextModule").ResolveDependenciesCallback} ResolveDependenciesCallback */ /** @typedef {import("./Module")} Module */ /** @typedef {import("./ModuleFactory").ModuleFactoryCreateData} ModuleFactoryCreateData */ -/** @typedef {import("./ModuleFactory").ModuleFactoryResult} ModuleFactoryResult */ +/** @typedef {import("./ModuleFactory").ModuleFactoryCallback} ModuleFactoryCallback */ /** @typedef {import("./ResolverFactory")} ResolverFactory */ /** @typedef {import("./dependencies/ContextDependency")} ContextDependency */ /** @typedef {import("enhanced-resolve").ResolveRequest} ResolveRequest */ @@ -86,7 +86,7 @@ module.exports = class ContextModuleFactory extends ModuleFactory { /** * @param {ModuleFactoryCreateData} data data object - * @param {function((Error | null)=, ModuleFactoryResult=): void} callback callback + * @param {ModuleFactoryCallback} callback callback * @returns {void} */ create(data, callback) { @@ -335,7 +335,7 @@ module.exports = class ContextModuleFactory extends ModuleFactory { /** * @param {string} ctx context * @param {string} directory directory - * @param {function(string, string, function(): void): void} addSubDirectory addSubDirectoryFn + * @param {(context: string, subResource: string, callback: () => void) => void} addSubDirectory addSubDirectoryFn * @param {ResolveDependenciesCallback} callback callback */ const addDirectory = (ctx, directory, addSubDirectory, callback) => { diff --git a/lib/DefinePlugin.js b/lib/DefinePlugin.js index 1c1cf7aa2..3f771bb03 100644 --- a/lib/DefinePlugin.js +++ b/lib/DefinePlugin.js @@ -33,7 +33,7 @@ const createHash = require("./util/createHash"); /** @typedef {import("./logging/Logger").Logger} Logger */ /** @typedef {import("./util/createHash").Algorithm} Algorithm */ -/** @typedef {null|undefined|RegExp|Function|string|number|boolean|bigint|undefined} CodeValuePrimitive */ +/** @typedef {null | undefined | RegExp | Function | string | number | boolean | bigint | undefined} CodeValuePrimitive */ /** @typedef {RecursiveArrayOrRecord} CodeValue */ /** @@ -42,11 +42,11 @@ const createHash = require("./util/createHash"); * @property {string[]=} contextDependencies * @property {string[]=} missingDependencies * @property {string[]=} buildDependencies - * @property {string|function(): string=} version + * @property {string| (() => string)=} version */ /** @typedef {string | Set} ValueCacheVersion */ -/** @typedef {function({ module: NormalModule, key: string, readonly version: ValueCacheVersion }): CodeValuePrimitive} GeneratorFn */ +/** @typedef {(value: { module: NormalModule, key: string, readonly version: ValueCacheVersion }) => CodeValuePrimitive} GeneratorFn */ class RuntimeValue { /** @@ -137,7 +137,7 @@ function getObjKeys(properties) { /** @typedef {boolean | undefined | null} AsiSafe */ /** - * @param {any[]|{[k: string]: any}} obj obj + * @param {any[] | {[k: string]: any}} obj obj * @param {JavascriptParser} parser Parser * @param {ValueCacheVersions} valueCacheVersions valueCacheVersions * @param {string} key the defined key @@ -411,7 +411,7 @@ class DefinePlugin { * @template {Function} T * @param {string} key key * @param {T} fn fn - * @returns {function(TODO): TODO} result + * @returns {(expression: Expression) => TODO} result */ const withValueDependency = (key, fn) => diff --git a/lib/DelegatedModule.js b/lib/DelegatedModule.js index e6bc5bc25..59b22366b 100644 --- a/lib/DelegatedModule.js +++ b/lib/DelegatedModule.js @@ -22,9 +22,11 @@ const makeSerializable = require("./util/makeSerializable"); /** @typedef {import("./DependencyTemplates")} DependencyTemplates */ /** @typedef {import("./Generator").SourceTypes} SourceTypes */ /** @typedef {import("./LibManifestPlugin").ManifestModuleData} ManifestModuleData */ +/** @typedef {import("./Module").BuildCallback} BuildCallback */ /** @typedef {import("./Module").CodeGenerationContext} CodeGenerationContext */ /** @typedef {import("./Module").CodeGenerationResult} CodeGenerationResult */ /** @typedef {import("./Module").LibIdentOptions} LibIdentOptions */ +/** @typedef {import("./Module").NeedBuildCallback} NeedBuildCallback */ /** @typedef {import("./Module").NeedBuildContext} NeedBuildContext */ /** @typedef {import("./Module").SourceContext} SourceContext */ /** @typedef {import("./RequestShortener")} RequestShortener */ @@ -106,7 +108,7 @@ class DelegatedModule extends Module { /** * @param {NeedBuildContext} context context info - * @param {function((WebpackError | null)=, boolean=): void} callback callback function, returns true, if the module needs a rebuild + * @param {NeedBuildCallback} callback callback function, returns true, if the module needs a rebuild * @returns {void} */ needBuild(context, callback) { @@ -118,7 +120,7 @@ class DelegatedModule extends Module { * @param {Compilation} compilation the compilation * @param {ResolverWithOptions} resolver the resolver * @param {InputFileSystem} fs the file system - * @param {function(WebpackError=): void} callback callback function + * @param {BuildCallback} callback callback function * @returns {void} */ build(options, compilation, resolver, fs, callback) { diff --git a/lib/Dependency.js b/lib/Dependency.js index a18f73654..5d861b016 100644 --- a/lib/Dependency.js +++ b/lib/Dependency.js @@ -81,7 +81,7 @@ const memoize = require("./util/memoize"); * @property {boolean=} canMangle when false, referenced export can not be mangled, defaults to true */ -/** @typedef {function(ModuleGraphConnection, RuntimeSpec): ConnectionState} GetConditionFn */ +/** @typedef {(moduleGraphConnection: ModuleGraphConnection, runtime: RuntimeSpec) => ConnectionState} GetConditionFn */ const TRANSITIVE = Symbol("transitive"); @@ -328,8 +328,8 @@ Dependency.NO_EXPORTS_REFERENCED = []; /** @type {string[][]} */ Dependency.EXPORTS_OBJECT_REFERENCED = [[]]; -// eslint-disable-next-line no-warning-comments -// @ts-ignore https://github.com/microsoft/TypeScript/issues/42919 +// TODO remove in webpack 6 +// @ts-expect-error https://github.com/microsoft/TypeScript/issues/42919 Object.defineProperty(Dependency.prototype, "module", { /** * @deprecated @@ -352,8 +352,8 @@ Object.defineProperty(Dependency.prototype, "module", { } }); -// eslint-disable-next-line no-warning-comments -// @ts-ignore https://github.com/microsoft/TypeScript/issues/42919 +// TODO remove in webpack 6 +// @ts-expect-error https://github.com/microsoft/TypeScript/issues/42919 Object.defineProperty(Dependency.prototype, "disconnect", { get() { throw new Error( diff --git a/lib/DllModule.js b/lib/DllModule.js index e9948fc61..58b06b0ec 100644 --- a/lib/DllModule.js +++ b/lib/DllModule.js @@ -20,8 +20,10 @@ const makeSerializable = require("./util/makeSerializable"); /** @typedef {import("./Dependency").UpdateHashContext} UpdateHashContext */ /** @typedef {import("./DependencyTemplates")} DependencyTemplates */ /** @typedef {import("./Generator").SourceTypes} SourceTypes */ +/** @typedef {import("./Module").BuildCallback} BuildCallback */ /** @typedef {import("./Module").CodeGenerationContext} CodeGenerationContext */ /** @typedef {import("./Module").CodeGenerationResult} CodeGenerationResult */ +/** @typedef {import("./Module").NeedBuildCallback} NeedBuildCallback */ /** @typedef {import("./Module").NeedBuildContext} NeedBuildContext */ /** @typedef {import("./Module").SourceContext} SourceContext */ /** @typedef {import("./RequestShortener")} RequestShortener */ @@ -80,7 +82,7 @@ class DllModule extends Module { * @param {Compilation} compilation the compilation * @param {ResolverWithOptions} resolver the resolver * @param {InputFileSystem} fs the file system - * @param {function(WebpackError=): void} callback callback function + * @param {BuildCallback} callback callback function * @returns {void} */ build(options, compilation, resolver, fs, callback) { @@ -107,7 +109,7 @@ class DllModule extends Module { /** * @param {NeedBuildContext} context context info - * @param {function((WebpackError | null)=, boolean=): void} callback callback function, returns true, if the module needs a rebuild + * @param {NeedBuildCallback} callback callback function, returns true, if the module needs a rebuild * @returns {void} */ needBuild(context, callback) { diff --git a/lib/DllModuleFactory.js b/lib/DllModuleFactory.js index d8800353d..41aa16107 100644 --- a/lib/DllModuleFactory.js +++ b/lib/DllModuleFactory.js @@ -8,8 +8,8 @@ const DllModule = require("./DllModule"); const ModuleFactory = require("./ModuleFactory"); +/** @typedef {import("./ModuleFactory").ModuleFactoryCallback} ModuleFactoryCallback */ /** @typedef {import("./ModuleFactory").ModuleFactoryCreateData} ModuleFactoryCreateData */ -/** @typedef {import("./ModuleFactory").ModuleFactoryResult} ModuleFactoryResult */ /** @typedef {import("./dependencies/DllEntryDependency")} DllEntryDependency */ class DllModuleFactory extends ModuleFactory { @@ -20,7 +20,7 @@ class DllModuleFactory extends ModuleFactory { /** * @param {ModuleFactoryCreateData} data data object - * @param {function((Error | null)=, ModuleFactoryResult=): void} callback callback + * @param {ModuleFactoryCallback} callback callback * @returns {void} */ create(data, callback) { diff --git a/lib/ExportsInfo.js b/lib/ExportsInfo.js index 0aac9f7e5..b5f3ec46d 100644 --- a/lib/ExportsInfo.js +++ b/lib/ExportsInfo.js @@ -819,8 +819,13 @@ class ExportsInfo { /** @typedef {Map} UsedInRuntime */ /** @typedef {{ module: Module, export: string[] }} TargetItemWithoutConnection */ + /** @typedef {{ module: Module, connection: ModuleGraphConnection, export: string[] | undefined }} TargetItemWithConnection */ +/** @typedef {(target: TargetItemWithConnection) => boolean} ResolveTargetFilter */ + +/** @typedef {(module: Module) => boolean} ValidTargetModuleFilter */ + /** @typedef {{ connection: ModuleGraphConnection, export: string[], priority: number }} TargetItem */ /** @typedef {Map} Target */ @@ -907,7 +912,7 @@ class ExportInfo { // TODO webpack 5 remove /** * @private - * @param {*} v v + * @param {EXPECTED_ANY} v v */ set used(v) { throw new Error("REMOVED"); @@ -922,7 +927,7 @@ class ExportInfo { // TODO webpack 5 remove /** * @private - * @param {*} v v + * @param {EXPECTED_ANY} v v */ set usedName(v) { throw new Error("REMOVED"); @@ -1007,7 +1012,7 @@ class ExportInfo { } /** - * @param {function(UsageStateType): boolean} condition compare with old value + * @param {(condition: UsageStateType) => boolean} condition compare with old value * @param {UsageStateType} newValue set when condition is true * @param {RuntimeSpec} runtime only apply to this runtime * @returns {boolean} true when something has changed @@ -1252,7 +1257,7 @@ class ExportInfo { /** * @param {ModuleGraph} moduleGraph the module graph - * @param {function(TargetItemWithConnection): boolean} resolveTargetFilter filter function to further resolve target + * @param {ResolveTargetFilter} resolveTargetFilter filter function to further resolve target * @returns {ExportInfo | ExportsInfo | undefined} the terminal binding export(s) info if known */ getTerminalBinding(moduleGraph, resolveTargetFilter = RETURNS_TRUE) { @@ -1295,7 +1300,7 @@ class ExportInfo { /** * @param {ModuleGraph} moduleGraph the module graph - * @param {function(Module): boolean} validTargetModuleFilter a valid target module + * @param {ValidTargetModuleFilter} validTargetModuleFilter a valid target module * @returns {TargetItemWithoutConnection | null | undefined | false} the target, undefined when there is no target, false when no target is valid */ findTarget(moduleGraph, validTargetModuleFilter) { @@ -1304,7 +1309,7 @@ class ExportInfo { /** * @param {ModuleGraph} moduleGraph the module graph - * @param {function(Module): boolean} validTargetModuleFilter a valid target module + * @param {ValidTargetModuleFilter} validTargetModuleFilter a valid target module * @param {Set} alreadyVisited set of already visited export info to avoid circular references * @returns {TargetItemWithoutConnection | null | undefined | false} the target, undefined when there is no target, false when no target is valid */ @@ -1345,7 +1350,7 @@ class ExportInfo { /** * @param {ModuleGraph} moduleGraph the module graph - * @param {function(TargetItemWithConnection): boolean} resolveTargetFilter filter function to further resolve target + * @param {ResolveTargetFilter} resolveTargetFilter filter function to further resolve target * @returns {TargetItemWithConnection | undefined} the target */ getTarget(moduleGraph, resolveTargetFilter = RETURNS_TRUE) { @@ -1356,7 +1361,7 @@ class ExportInfo { /** * @param {ModuleGraph} moduleGraph the module graph - * @param {function(TargetItemWithConnection): boolean} resolveTargetFilter filter function to further resolve target + * @param {ResolveTargetFilter} resolveTargetFilter filter function to further resolve target * @param {Set | undefined} alreadyVisited set of already visited export info to avoid circular references * @returns {TargetItemWithConnection | CIRCULAR | undefined} the target */ @@ -1454,8 +1459,8 @@ class ExportInfo { /** * Move the target forward as long resolveTargetFilter is fulfilled * @param {ModuleGraph} moduleGraph the module graph - * @param {function(TargetItemWithConnection): boolean} resolveTargetFilter filter function to further resolve target - * @param {function(TargetItemWithConnection): ModuleGraphConnection=} updateOriginalConnection updates the original connection instead of using the target connection + * @param {ResolveTargetFilter} resolveTargetFilter filter function to further resolve target + * @param {(target: TargetItemWithConnection) => ModuleGraphConnection=} updateOriginalConnection updates the original connection instead of using the target connection * @returns {TargetItemWithConnection | undefined} the resolved target when moved */ moveTarget(moduleGraph, resolveTargetFilter, updateOriginalConnection) { diff --git a/lib/ExternalModule.js b/lib/ExternalModule.js index ec9881e5d..fdb4e20d7 100644 --- a/lib/ExternalModule.js +++ b/lib/ExternalModule.js @@ -37,11 +37,13 @@ const { register } = require("./util/serialization"); /** @typedef {import("./ExportsInfo")} ExportsInfo */ /** @typedef {import("./Generator").GenerateContext} GenerateContext */ /** @typedef {import("./Generator").SourceTypes} SourceTypes */ +/** @typedef {import("./Module").BuildCallback} BuildCallback */ /** @typedef {import("./Module").BuildInfo} BuildInfo */ /** @typedef {import("./Module").CodeGenerationContext} CodeGenerationContext */ /** @typedef {import("./Module").CodeGenerationResult} CodeGenerationResult */ /** @typedef {import("./Module").ConcatenationBailoutReasonContext} ConcatenationBailoutReasonContext */ /** @typedef {import("./Module").LibIdentOptions} LibIdentOptions */ +/** @typedef {import("./Module").NeedBuildCallback} NeedBuildCallback */ /** @typedef {import("./Module").NeedBuildContext} NeedBuildContext */ /** @typedef {import("./Module").ReadOnlyRuntimeRequirements} ReadOnlyRuntimeRequirements */ /** @typedef {import("./ModuleGraph")} ModuleGraph */ @@ -555,7 +557,7 @@ class ExternalModule extends Module { /** * @param {NeedBuildContext} context context info - * @param {function((WebpackError | null)=, boolean=): void} callback callback function, returns true, if the module needs a rebuild + * @param {NeedBuildCallback} callback callback function, returns true, if the module needs a rebuild * @returns {void} */ needBuild(context, callback) { @@ -567,7 +569,7 @@ class ExternalModule extends Module { * @param {Compilation} compilation the compilation * @param {ResolverWithOptions} resolver the resolver * @param {InputFileSystem} fs the file system - * @param {function(WebpackError=): void} callback callback function + * @param {BuildCallback} callback callback function * @returns {void} */ build(options, compilation, resolver, fs, callback) { diff --git a/lib/ExternalModuleFactoryPlugin.js b/lib/ExternalModuleFactoryPlugin.js index 853a88c02..d7b9e0bbe 100644 --- a/lib/ExternalModuleFactoryPlugin.js +++ b/lib/ExternalModuleFactoryPlugin.js @@ -89,10 +89,12 @@ class ExternalModuleFactoryPlugin { const dependency = data.dependencies[0]; const dependencyType = data.dependencyType; + /** @typedef {(err?: Error | null, externalModule?: ExternalModule) => void} HandleExternalCallback */ + /** * @param {ExternalValue} value the external config * @param {ExternalType | undefined} type type of external - * @param {function((Error | null)=, ExternalModule=): void} callback callback + * @param {HandleExternalCallback} callback callback * @returns {void} */ const handleExternal = (value, type, callback) => { @@ -176,7 +178,7 @@ class ExternalModuleFactoryPlugin { /** * @param {Externals} externals externals config - * @param {function((Error | null)=, ExternalModule=): void} callback callback + * @param {HandleExternalCallback} callback callback * @returns {void} */ const handleExternals = (externals, callback) => { diff --git a/lib/FileSystemInfo.js b/lib/FileSystemInfo.js index 3ced1e4f2..4808515c1 100644 --- a/lib/FileSystemInfo.js +++ b/lib/FileSystemInfo.js @@ -604,9 +604,9 @@ const MIN_COMMON_SNAPSHOT_SIZE = 3; */ class SnapshotOptimization { /** - * @param {function(Snapshot): boolean} has has value - * @param {function(Snapshot): SnapshotOptimizationValue | undefined} get get value - * @param {function(Snapshot, SnapshotOptimizationValue): void} set set value + * @param {(snapshot: Snapshot) => boolean} has has value + * @param {(snapshot: Snapshot) => SnapshotOptimizationValue | undefined} get get value + * @param {(snapshot: Snapshot, value: SnapshotOptimizationValue) => void} set set value * @param {boolean=} useStartTime use the start time of snapshots * @param {U=} isSet value is an Set instead of a Map */ @@ -1045,6 +1045,8 @@ const addAll = (source, target) => { /** @typedef {ContextFileSystemInfoEntry | "ignore" | null} ContextTimestamp */ /** @typedef {ResolvedContextFileSystemInfoEntry | "ignore" | null} ResolvedContextTimestamp */ +/** @typedef {(err?: WebpackError | null, result?: boolean) => void} CheckSnapshotValidCallback */ + /** * Used to access information about the filesystem in a cached way */ @@ -1074,7 +1076,7 @@ class FileSystemInfo { /** @type {LoggedPaths | undefined} */ this._loggedPaths = logger ? new Set() : undefined; this._hashFunction = hashFunction; - /** @type {WeakMap} */ + /** @type {WeakMap} */ this._snapshotCache = new WeakMap(); this._fileTimestampsOptimization = new SnapshotOptimization( s => s.hasFileTimestamps(), @@ -1408,7 +1410,7 @@ class FileSystemInfo { /** * @param {string} path file path - * @param {function((WebpackError | null)=, FileTimestamp=): void} callback callback function + * @param {(err?: WebpackError | null, fileTimestamp?: FileTimestamp) => void} callback callback function * @returns {void} */ getFileTimestamp(path, callback) { @@ -1419,7 +1421,7 @@ class FileSystemInfo { /** * @param {string} path context path - * @param {function((WebpackError | null)=, ResolvedContextTimestamp=): void} callback callback function + * @param {(err?: WebpackError | null, resolvedContextTimestamp?: ResolvedContextTimestamp) => void} callback callback function * @returns {void} */ getContextTimestamp(path, callback) { @@ -1446,7 +1448,7 @@ class FileSystemInfo { /** * @private * @param {string} path context path - * @param {function((WebpackError | null)=, ContextTimestamp=): void} callback callback function + * @param {(err?: WebpackError | null, contextTimestamp?: ContextTimestamp) => void} callback callback function * @returns {void} */ _getUnresolvedContextTimestamp(path, callback) { @@ -1457,7 +1459,7 @@ class FileSystemInfo { /** * @param {string} path file path - * @param {function((WebpackError | null)=, (string | null)=): void} callback callback function + * @param {(err?: WebpackError | null, hash?: string | null) => void} callback callback function * @returns {void} */ getFileHash(path, callback) { @@ -1468,7 +1470,7 @@ class FileSystemInfo { /** * @param {string} path context path - * @param {function((WebpackError | null)=, string=): void} callback callback function + * @param {(err?: WebpackError | null, contextHash?: string) => void} callback callback function * @returns {void} */ getContextHash(path, callback) { @@ -1492,7 +1494,7 @@ class FileSystemInfo { /** * @private * @param {string} path context path - * @param {function((WebpackError | null)=, (ContextHash | null)=): void} callback callback function + * @param {(err?: WebpackError | null, contextHash?: ContextHash | null) => void} callback callback function * @returns {void} */ _getUnresolvedContextHash(path, callback) { @@ -1503,7 +1505,7 @@ class FileSystemInfo { /** * @param {string} path context path - * @param {function((WebpackError | null)=, (ResolvedContextTimestampAndHash | null)=): void} callback callback function + * @param {(err?: WebpackError | null, resolvedContextTimestampAndHash?: ResolvedContextTimestampAndHash | null) => void} callback callback function * @returns {void} */ getContextTsh(path, callback) { @@ -1525,7 +1527,7 @@ class FileSystemInfo { /** * @private * @param {string} path context path - * @param {function((WebpackError | null)=, (ContextTimestampAndHash | null)=): void} callback callback function + * @param {(err?: WebpackError | null, contextTimestampAndHash?: ContextTimestampAndHash | null) => void} callback callback function * @returns {void} */ _getUnresolvedContextTsh(path, callback) { @@ -1565,7 +1567,7 @@ class FileSystemInfo { /** * @param {string} context context directory * @param {Iterable} deps dependencies - * @param {function((Error | null)=, ResolveBuildDependenciesResult=): void} callback callback function + * @param {(err?: Error | null, resolveBuildDependenciesResult?: ResolveBuildDependenciesResult) => void} callback callback function * @returns {void} */ resolveBuildDependencies(context, deps, callback) { @@ -2085,7 +2087,7 @@ class FileSystemInfo { /** * @param {ResolveResults} resolveResults results from resolving - * @param {function((Error | null)=, boolean=): void} callback callback with true when resolveResults resolve the same way + * @param {(err?: Error | null, result?: boolean) => void} callback callback with true when resolveResults resolve the same way * @returns {void} */ checkResolveResultsValid(resolveResults, callback) { @@ -2164,7 +2166,7 @@ class FileSystemInfo { * @param {Iterable | null} directories all directories * @param {Iterable | null} missing all missing files or directories * @param {SnapshotOptions | null | undefined} options options object (for future extensions) - * @param {function(WebpackError | null, Snapshot | null): void} callback callback function + * @param {(err: WebpackError | null, snapshot: Snapshot | null) => void} callback callback function * @returns {void} */ createSnapshot(startTime, files, directories, missing, options, callback) { @@ -2614,7 +2616,7 @@ class FileSystemInfo { // Fallback to normal snapshotting /** * @param {Set} set set - * @param {function(Set): void} fn fn + * @param {(set: Set) => void} fn fn */ const process = (set, fn) => { if (set.size === 0) return; @@ -2723,7 +2725,7 @@ class FileSystemInfo { /** * @param {Snapshot} snapshot the snapshot made - * @param {function((WebpackError | null)=, boolean=): void} callback callback function + * @param {CheckSnapshotValidCallback} callback callback function * @returns {void} */ checkSnapshotValid(snapshot, callback) { @@ -2744,7 +2746,7 @@ class FileSystemInfo { /** * @private * @param {Snapshot} snapshot the snapshot made - * @param {function((WebpackError | null)=, boolean=): void} callback callback function + * @param {CheckSnapshotValidCallback} callback callback function * @returns {void} */ _checkSnapshotValidNoCache(snapshot, callback) { @@ -3326,7 +3328,7 @@ class FileSystemInfo { /** * @private * @param {string} path path - * @param {function(WebpackError | null, TimestampAndHash=) : void} callback callback + * @param {(err: WebpackError | null, timestampAndHash?: TimestampAndHash) => void} callback callback */ _getFileTimestampAndHash(path, callback) { /** @@ -3381,13 +3383,13 @@ class FileSystemInfo { * @template ItemType * @param {object} options options * @param {string} options.path path - * @param {function(string): ItemType} options.fromImmutablePath called when context item is an immutable path - * @param {function(string): ItemType} options.fromManagedItem called when context item is a managed path - * @param {function(string, string, function((WebpackError | null)=, ItemType=): void): void} options.fromSymlink called when context item is a symlink - * @param {function(string, IStats, function((WebpackError | null)=, (ItemType | null)=): void): void} options.fromFile called when context item is a file - * @param {function(string, IStats, function((WebpackError | null)=, ItemType=): void): void} options.fromDirectory called when context item is a directory - * @param {function(string[], ItemType[]): T} options.reduce called from all context items - * @param {function((Error | null)=, (T | null)=): void} callback callback + * @param {(value: string) => ItemType} options.fromImmutablePath called when context item is an immutable path + * @param {(value: string) => ItemType} options.fromManagedItem called when context item is a managed path + * @param {(value: string, result: string, callback: (err?: WebpackError | null, itemType?: ItemType) => void) => void} options.fromSymlink called when context item is a symlink + * @param {(value: string, stats: IStats, callback: (err?: WebpackError | null, itemType?: ItemType | null) => void) => void} options.fromFile called when context item is a file + * @param {(value: string, stats: IStats, callback: (err?: WebpackError | null, itemType?: ItemType) => void) => void} options.fromDirectory called when context item is a directory + * @param {(arr: string[], arr1: ItemType[]) => T} options.reduce called from all context items + * @param {(err?: Error | null, result?: T | null) => void} callback callback */ _readContext( { @@ -3605,7 +3607,7 @@ class FileSystemInfo { /** * @private * @param {ContextFileSystemInfoEntry} entry entry - * @param {function((WebpackError | null)=, ResolvedContextTimestamp=): void} callback callback + * @param {(err?: WebpackError | null, resolvedContextTimestamp?: ResolvedContextTimestamp) => void} callback callback * @returns {void} */ _resolveContextTimestamp(entry, callback) { @@ -3725,7 +3727,7 @@ class FileSystemInfo { /** * @private * @param {ContextHash} entry context hash - * @param {function(WebpackError | null, string=): void} callback callback + * @param {(err: WebpackError | null, contextHash?: string) => void} callback callback * @returns {void} */ _resolveContextHash(entry, callback) { diff --git a/lib/Generator.js b/lib/Generator.js index 276430575..fdb4a0bdd 100644 --- a/lib/Generator.js +++ b/lib/Generator.js @@ -32,7 +32,7 @@ * @property {ConcatenationScope=} concatenationScope when in concatenated module, information about other concatenated modules * @property {CodeGenerationResults=} codeGenerationResults code generation results of other modules (need to have a codeGenerationDependency to use that) * @property {string} type which kind of code should be generated - * @property {function(): Map=} getData get access to the code generation data + * @property {() => Map=} getData get access to the code generation data */ /** diff --git a/lib/HookWebpackError.js b/lib/HookWebpackError.js index 84702401a..127421f36 100644 --- a/lib/HookWebpackError.js +++ b/lib/HookWebpackError.js @@ -51,7 +51,7 @@ module.exports.makeWebpackError = makeWebpackError; /** * @template T - * @param {function(WebpackError | null, T=): void} callback webpack error callback + * @param {(err: WebpackError | null, result?: T) => void} callback webpack error callback * @param {string} hook name of hook * @returns {Callback} generic callback */ @@ -71,7 +71,7 @@ module.exports.makeWebpackErrorCallback = makeWebpackErrorCallback; /** * @template T - * @param {function(): T} fn function which will be wrapping in try catch + * @param {() => T} fn function which will be wrapping in try catch * @param {string} hook name of hook * @returns {T} the result */ diff --git a/lib/IgnoreErrorModuleFactory.js b/lib/IgnoreErrorModuleFactory.js index 4fd73e7fa..423277935 100644 --- a/lib/IgnoreErrorModuleFactory.js +++ b/lib/IgnoreErrorModuleFactory.js @@ -7,8 +7,8 @@ const ModuleFactory = require("./ModuleFactory"); +/** @typedef {import("./ModuleFactory").ModuleFactoryCallback} ModuleFactoryCallback */ /** @typedef {import("./ModuleFactory").ModuleFactoryCreateData} ModuleFactoryCreateData */ -/** @typedef {import("./ModuleFactory").ModuleFactoryResult} ModuleFactoryResult */ /** @typedef {import("./NormalModuleFactory")} NormalModuleFactory */ /** @@ -26,7 +26,7 @@ class IgnoreErrorModuleFactory extends ModuleFactory { /** * @param {ModuleFactoryCreateData} data data object - * @param {function((Error | null)=, ModuleFactoryResult=): void} callback callback + * @param {ModuleFactoryCallback} callback callback * @returns {void} */ create(data, callback) { diff --git a/lib/MainTemplate.js b/lib/MainTemplate.js index d05ebad2b..06ecbb045 100644 --- a/lib/MainTemplate.js +++ b/lib/MainTemplate.js @@ -62,7 +62,7 @@ class MainTemplate { /** * @template AdditionalOptions * @param {string | Tap & IfSet} options options - * @param {function(RenderManifestEntry[], RenderManifestOptions): RenderManifestEntry[]} fn fn + * @param {(renderManifestEntries: RenderManifestEntry[], renderManifestOptions: RenderManifestOptions) => RenderManifestEntry[]} fn fn */ (options, fn) => { compilation.hooks.renderManifest.tap( @@ -96,7 +96,7 @@ class MainTemplate { /** * @template AdditionalOptions * @param {string | Tap & IfSet} options options - * @param {function(string, RenderBootstrapContext): string} fn fn + * @param {(value: string, renderBootstrapContext: RenderBootstrapContext) => string} fn fn */ (options, fn) => { getJavascriptModulesPlugin() @@ -133,7 +133,7 @@ class MainTemplate { /** * @template AdditionalOptions * @param {string | Tap & IfSet} options options - * @param {function(Source, Chunk, string | undefined, ModuleTemplate, DependencyTemplates): Source} fn fn + * @param {(source: Source, chunk: Chunk, hash: string | undefined, moduleTemplate: ModuleTemplate, dependencyTemplates: DependencyTemplates) => Source} fn fn */ (options, fn) => { getJavascriptModulesPlugin() @@ -165,7 +165,7 @@ class MainTemplate { /** * @template AdditionalOptions * @param {string | Tap & IfSet} options options - * @param {function(Source, Chunk, string | undefined): Source} fn fn + * @param {(source: Source, chunk: Chunk, hash: string | undefined) => Source} fn fn */ (options, fn) => { getJavascriptModulesPlugin() @@ -191,7 +191,7 @@ class MainTemplate { /** * @template AdditionalOptions * @param {string | Tap & IfSet} options options - * @param {function(string, object, AssetInfo | undefined): string} fn fn + * @param {(value: string, path: PathData, assetInfo: AssetInfo | undefined) => string} fn fn */ (options, fn) => { compilation.hooks.assetPath.tap(options, fn); @@ -215,7 +215,7 @@ class MainTemplate { /** * @template AdditionalOptions * @param {string | Tap & IfSet} options options - * @param {function(Hash): void} fn fn + * @param {(hash: Hash) => void} fn fn */ (options, fn) => { compilation.hooks.fullHash.tap(options, fn); @@ -229,7 +229,7 @@ class MainTemplate { /** * @template AdditionalOptions * @param {string | Tap & IfSet} options options - * @param {function(Hash, Chunk): void} fn fn + * @param {(hash: Hash, chunk: Chunk) => void} fn fn */ (options, fn) => { getJavascriptModulesPlugin() diff --git a/lib/Module.js b/lib/Module.js index 95e542f54..058227d47 100644 --- a/lib/Module.js +++ b/lib/Module.js @@ -134,6 +134,10 @@ const makeSerializable = require("./util/makeSerializable"); * @property {ValueCacheVersions} valueCacheVersions */ +/** @typedef {(err?: WebpackError | null, needBuild?: boolean) => void} NeedBuildCallback */ + +/** @typedef {(err?: WebpackError) => void} BuildCallback */ + /** @typedef {KnownBuildMeta & Record} BuildMeta */ /** @typedef {KnownBuildInfo & Record} BuildInfo */ @@ -777,7 +781,7 @@ class Module extends DependenciesBlock { /** * @param {NeedBuildContext} context context info - * @param {function((WebpackError | null)=, boolean=): void} callback callback function, returns true, if the module needs a rebuild + * @param {NeedBuildCallback} callback callback function, returns true, if the module needs a rebuild * @returns {void} */ needBuild(context, callback) { @@ -860,7 +864,7 @@ class Module extends DependenciesBlock { * @param {Compilation} compilation the compilation * @param {ResolverWithOptions} resolver the resolver * @param {InputFileSystem} fs the file system - * @param {function(WebpackError=): void} callback callback function + * @param {BuildCallback} callback callback function * @returns {void} */ build(options, compilation, resolver, fs, callback) { @@ -1121,8 +1125,7 @@ class Module extends DependenciesBlock { makeSerializable(Module, "webpack/lib/Module"); // TODO remove in webpack 6 -// eslint-disable-next-line no-warning-comments -// @ts-ignore https://github.com/microsoft/TypeScript/issues/42919 +// @ts-expect-error https://github.com/microsoft/TypeScript/issues/42919 Object.defineProperty(Module.prototype, "hasEqualsChunks", { get() { throw new Error( @@ -1132,8 +1135,7 @@ Object.defineProperty(Module.prototype, "hasEqualsChunks", { }); // TODO remove in webpack 6 -// eslint-disable-next-line no-warning-comments -// @ts-ignore https://github.com/microsoft/TypeScript/issues/42919 +// @ts-expect-error https://github.com/microsoft/TypeScript/issues/42919 Object.defineProperty(Module.prototype, "isUsed", { get() { throw new Error( @@ -1179,8 +1181,7 @@ Object.defineProperty(Module.prototype, "warnings", { }); // TODO remove in webpack 6 -// eslint-disable-next-line no-warning-comments -// @ts-ignore https://github.com/microsoft/TypeScript/issues/42919 +// @ts-expect-error https://github.com/microsoft/TypeScript/issues/42919 Object.defineProperty(Module.prototype, "used", { get() { throw new Error( diff --git a/lib/ModuleFactory.js b/lib/ModuleFactory.js index 7b08be28b..4dc7b862d 100644 --- a/lib/ModuleFactory.js +++ b/lib/ModuleFactory.js @@ -33,12 +33,16 @@ * @property {Dependency[]} dependencies */ +/** + * @typedef {(err?: Error | null, result?: ModuleFactoryResult) => void} ModuleFactoryCallback + */ + class ModuleFactory { /* istanbul ignore next */ /** * @abstract * @param {ModuleFactoryCreateData} data data object - * @param {function((Error | null)=, ModuleFactoryResult=): void} callback callback + * @param {ModuleFactoryCallback} callback callback * @returns {void} */ create(data, callback) { diff --git a/lib/ModuleFilenameHelpers.js b/lib/ModuleFilenameHelpers.js index 738bc442a..d9cec75f1 100644 --- a/lib/ModuleFilenameHelpers.js +++ b/lib/ModuleFilenameHelpers.js @@ -203,7 +203,7 @@ ModuleFilenameHelpers.createFilename = ( } // TODO webpack 6: consider removing alternatives without dashes - /** @type {Map} */ + /** @type {Map string>} */ const replacements = new Map([ ["identifier", identifier], ["short-identifier", shortIdentifier], diff --git a/lib/ModuleGraph.js b/lib/ModuleGraph.js index 783c6e414..95c76c19c 100644 --- a/lib/ModuleGraph.js +++ b/lib/ModuleGraph.js @@ -119,6 +119,8 @@ class ModuleGraphModule { } } +/** @typedef {(moduleGraphConnection: ModuleGraphConnection) => boolean} FilterConnection */ + class ModuleGraph { constructor() { /** @@ -331,7 +333,7 @@ class ModuleGraph { /** * @param {Module} oldModule the old referencing module * @param {Module} newModule the new referencing module - * @param {function(ModuleGraphConnection): boolean} filterConnection filter predicate for replacement + * @param {FilterConnection} filterConnection filter predicate for replacement * @returns {void} */ moveModuleConnections(oldModule, newModule, filterConnection) { @@ -368,7 +370,7 @@ class ModuleGraph { /** * @param {Module} oldModule the old referencing module * @param {Module} newModule the new referencing module - * @param {function(ModuleGraphConnection): boolean} filterConnection filter predicate for replacement + * @param {FilterConnection} filterConnection filter predicate for replacement * @returns {void} */ copyOutgoingModuleConnections(oldModule, newModule, filterConnection) { diff --git a/lib/ModuleGraphConnection.js b/lib/ModuleGraphConnection.js index 1f12ac9e5..5b06d7587 100644 --- a/lib/ModuleGraphConnection.js +++ b/lib/ModuleGraphConnection.js @@ -75,7 +75,6 @@ class ModuleGraphConnection { this.weak = weak; this.conditional = Boolean(condition); this._active = condition !== false; - /** @type {(function(ModuleGraphConnection, RuntimeSpec): ConnectionState) | undefined} */ this.condition = condition || undefined; /** @type {Set | undefined} */ this.explanations = undefined; @@ -103,15 +102,16 @@ class ModuleGraphConnection { } /** - * @param {function(ModuleGraphConnection, RuntimeSpec): ConnectionState} condition condition for the connection + * @param {GetConditionFn} condition condition for the connection * @returns {void} */ addCondition(condition) { if (this.conditional) { const old = - /** @type {(function(ModuleGraphConnection, RuntimeSpec): ConnectionState)} */ + /** @type {GetConditionFn} */ (this.condition); - this.condition = (c, r) => + /** @type {GetConditionFn} */ + (this.condition) = (c, r) => intersectConnectionStates(old(c, r), condition(c, r)); } else if (this._active) { this.conditional = true; @@ -143,9 +143,7 @@ class ModuleGraphConnection { if (!this.conditional) return this._active; return ( - /** @type {(function(ModuleGraphConnection, RuntimeSpec): ConnectionState)} */ ( - this.condition - )(this, runtime) !== false + /** @type {GetConditionFn} */ (this.condition)(this, runtime) !== false ); } @@ -156,9 +154,7 @@ class ModuleGraphConnection { isTargetActive(runtime) { if (!this.conditional) return this._active; return ( - /** @type {(function(ModuleGraphConnection, RuntimeSpec): ConnectionState)} */ ( - this.condition - )(this, runtime) === true + /** @type {GetConditionFn} */ (this.condition)(this, runtime) === true ); } @@ -168,9 +164,7 @@ class ModuleGraphConnection { */ getActiveState(runtime) { if (!this.conditional) return this._active; - return /** @type {(function(ModuleGraphConnection, RuntimeSpec): ConnectionState)} */ ( - this.condition - )(this, runtime); + return /** @type {GetConditionFn} */ (this.condition)(this, runtime); } /** diff --git a/lib/ModuleTemplate.js b/lib/ModuleTemplate.js index 799037710..38f2bd786 100644 --- a/lib/ModuleTemplate.js +++ b/lib/ModuleTemplate.js @@ -44,7 +44,7 @@ class ModuleTemplate { /** * @template AdditionalOptions * @param {string | Tap & IfSet} options options - * @param {function(Source, Module, ChunkRenderContext, DependencyTemplates): Source} fn fn + * @param {(source: Source, module: Module, chunkRenderContext: ChunkRenderContext, dependencyTemplates: DependencyTemplates) => Source} fn fn */ (options, fn) => { getJavascriptModulesPlugin() @@ -69,7 +69,7 @@ class ModuleTemplate { /** * @template AdditionalOptions * @param {string | Tap & IfSet} options options - * @param {function(Source, Module, ChunkRenderContext, DependencyTemplates): Source} fn fn + * @param {(source: Source, module: Module, chunkRenderContext: ChunkRenderContext, dependencyTemplates: DependencyTemplates) => Source} fn fn */ (options, fn) => { getJavascriptModulesPlugin() @@ -94,7 +94,7 @@ class ModuleTemplate { /** * @template AdditionalOptions * @param {string | Tap & IfSet} options options - * @param {function(Source, Module, ChunkRenderContext, DependencyTemplates): Source} fn fn + * @param {(source: Source, module: Module, chunkRenderContext: ChunkRenderContext, dependencyTemplates: DependencyTemplates) => Source} fn fn */ (options, fn) => { getJavascriptModulesPlugin() @@ -119,7 +119,7 @@ class ModuleTemplate { /** * @template AdditionalOptions * @param {string | Tap & IfSet} options options - * @param {function(Source, Module, ChunkRenderContext, DependencyTemplates): Source} fn fn + * @param {(source: Source, module: Module, chunkRenderContext: ChunkRenderContext, dependencyTemplates: DependencyTemplates) => Source} fn fn */ (options, fn) => { getJavascriptModulesPlugin() @@ -144,7 +144,7 @@ class ModuleTemplate { /** * @template AdditionalOptions * @param {string | Tap & IfSet} options options - * @param {function(Hash): void} fn fn + * @param {(hash: Hash) => void} fn fn */ (options, fn) => { compilation.hooks.fullHash.tap(options, fn); diff --git a/lib/MultiCompiler.js b/lib/MultiCompiler.js index 8c72da319..9b43774b0 100644 --- a/lib/MultiCompiler.js +++ b/lib/MultiCompiler.js @@ -223,7 +223,7 @@ module.exports = class MultiCompiler { } /** - * @param {string | (function(): string)} name name of the logger, or function called once to get the logger name + * @param {string | (() => string)} name name of the logger, or function called once to get the logger name * @returns {Logger} a logger with that name */ getInfrastructureLogger(name) { @@ -377,8 +377,8 @@ module.exports = class MultiCompiler { /** * @template SetupResult - * @param {function(Compiler, number, Callback, function(): boolean, function(): void, function(): void): SetupResult} setup setup a single compiler - * @param {function(Compiler, SetupResult, Callback): void} run run/continue a single compiler + * @param {(compiler: Compiler, index: number, doneCallback: Callback, isBlocked: () => boolean, setChanged: () => void, setInvalid: () => void) => SetupResult} setup setup a single compiler + * @param {(compiler: Compiler, setupResult: SetupResult, callback: Callback) => void} run run/continue a single compiler * @param {Callback} callback callback when all compilers are done, result includes Stats of all changed compilers * @returns {SetupResult[]} result of setup */ diff --git a/lib/NormalModule.js b/lib/NormalModule.js index e8ac0e9c6..c0fce2f6f 100644 --- a/lib/NormalModule.js +++ b/lib/NormalModule.js @@ -70,6 +70,8 @@ const memoize = require("./util/memoize"); /** @typedef {import("./Module").KnownBuildInfo} KnownBuildInfo */ /** @typedef {import("./Module").LibIdentOptions} LibIdentOptions */ /** @typedef {import("./Module").NeedBuildContext} NeedBuildContext */ +/** @typedef {import("./Module").NeedBuildCallback} NeedBuildCallback */ +/** @typedef {import("./Module").BuildCallback} BuildCallback */ /** @typedef {import("./Generator").SourceTypes} SourceTypes */ /** @typedef {import("./Module").UnsafeCacheData} UnsafeCacheData */ /** @typedef {import("./ModuleGraph")} ModuleGraph */ @@ -158,7 +160,7 @@ const contextifySourceUrl = (context, source, associatedObjectForCache) => { const contextifySourceMap = (context, sourceMap, associatedObjectForCache) => { if (!Array.isArray(sourceMap.sources)) return sourceMap; const { sourceRoot } = sourceMap; - /** @type {function(string): string} */ + /** @type {(source: string) => string} */ const mapper = !sourceRoot ? source => source : sourceRoot.endsWith("/") @@ -880,7 +882,7 @@ class NormalModule extends Module { * @param {ResolverWithOptions} resolver the resolver * @param {InputFileSystem} fs the file system * @param {NormalModuleCompilationHooks} hooks the hooks - * @param {function((WebpackError | null)=): void} callback callback function + * @param {BuildCallback} callback callback function * @returns {void} */ _doBuild(options, compilation, resolver, fs, hooks, callback) { @@ -1015,8 +1017,7 @@ class NormalModule extends Module { loaderContext._compilation = loaderContext._compiler = loaderContext._module = - // eslint-disable-next-line no-warning-comments - // @ts-ignore + // @ts-expect-error avoid memory leaking loaderContext.fs = undefined; @@ -1140,7 +1141,7 @@ class NormalModule extends Module { * @param {Compilation} compilation the compilation * @param {ResolverWithOptions} resolver the resolver * @param {InputFileSystem} fs the file system - * @param {function(WebpackError=): void} callback callback function + * @param {BuildCallback} callback callback function * @returns {void} */ build(options, compilation, resolver, fs, callback) { @@ -1434,7 +1435,7 @@ class NormalModule extends Module { runtimeRequirements.add(RuntimeGlobals.thisAsExports); } - /** @type {function(): Map} */ + /** @type {() => Map} */ const getData = () => this._codeGeneratorData; const sources = new Map(); @@ -1486,7 +1487,7 @@ class NormalModule extends Module { /** * @param {NeedBuildContext} context context info - * @param {function((WebpackError | null)=, boolean=): void} callback callback function, returns true, if the module needs a rebuild + * @param {NeedBuildCallback} callback callback function, returns true, if the module needs a rebuild * @returns {void} */ needBuild(context, callback) { diff --git a/lib/NormalModuleFactory.js b/lib/NormalModuleFactory.js index 7f14906de..ef95f6de9 100644 --- a/lib/NormalModuleFactory.js +++ b/lib/NormalModuleFactory.js @@ -37,6 +37,7 @@ const { /** @typedef {import("../declarations/WebpackOptions").ModuleOptionsNormalized} ModuleOptions */ /** @typedef {import("../declarations/WebpackOptions").RuleSetRule} RuleSetRule */ /** @typedef {import("./Generator")} Generator */ +/** @typedef {import("./ModuleFactory").ModuleFactoryCallback} ModuleFactoryCallback */ /** @typedef {import("./ModuleFactory").ModuleFactoryCreateData} ModuleFactoryCreateData */ /** @typedef {import("./ModuleFactory").ModuleFactoryCreateDataContextInfo} ModuleFactoryCreateDataContextInfo */ /** @typedef {import("./ModuleFactory").ModuleFactoryResult} ModuleFactoryResult */ @@ -850,7 +851,7 @@ class NormalModuleFactory extends ModuleFactory { /** * @param {ModuleFactoryCreateData} data data object - * @param {function((Error | null)=, ModuleFactoryResult=): void} callback callback + * @param {ModuleFactoryCallback} callback callback * @returns {void} */ create(data, callback) { diff --git a/lib/NormalModuleReplacementPlugin.js b/lib/NormalModuleReplacementPlugin.js index fb44e088d..8a6f92780 100644 --- a/lib/NormalModuleReplacementPlugin.js +++ b/lib/NormalModuleReplacementPlugin.js @@ -8,15 +8,16 @@ const { join, dirname } = require("./util/fs"); /** @typedef {import("./Compiler")} Compiler */ +/** @typedef {import("./NormalModuleFactory").ResolveData} ResolveData */ /** @typedef {import("./util/fs").InputFileSystem} InputFileSystem */ -/** @typedef {function(import("./NormalModuleFactory").ResolveData): void} ModuleReplacer */ +/** @typedef {(resolveData: ResolveData) => void} ModuleReplacer */ class NormalModuleReplacementPlugin { /** * Create an instance of the plugin * @param {RegExp} resourceRegExp the resource matcher - * @param {string|ModuleReplacer} newResource the resource replacement + * @param {string | ModuleReplacer} newResource the resource replacement */ constructor(resourceRegExp, newResource) { this.resourceRegExp = resourceRegExp; diff --git a/lib/NullFactory.js b/lib/NullFactory.js index 50f3471be..4665f7590 100644 --- a/lib/NullFactory.js +++ b/lib/NullFactory.js @@ -7,13 +7,13 @@ const ModuleFactory = require("./ModuleFactory"); +/** @typedef {import("./ModuleFactory").ModuleFactoryCallback} ModuleFactoryCallback */ /** @typedef {import("./ModuleFactory").ModuleFactoryCreateData} ModuleFactoryCreateData */ -/** @typedef {import("./ModuleFactory").ModuleFactoryResult} ModuleFactoryResult */ class NullFactory extends ModuleFactory { /** * @param {ModuleFactoryCreateData} data data object - * @param {function((Error | null)=, ModuleFactoryResult=): void} callback callback + * @param {ModuleFactoryCallback} callback callback * @returns {void} */ create(data, callback) { diff --git a/lib/ProgressPlugin.js b/lib/ProgressPlugin.js index b8be13916..e866f44ca 100644 --- a/lib/ProgressPlugin.js +++ b/lib/ProgressPlugin.js @@ -479,8 +479,7 @@ class ProgressPlugin { compilation.hooks.failedEntry.tap("ProgressPlugin", entryDone); compilation.hooks.succeedEntry.tap("ProgressPlugin", entryDone); - // avoid dynamic require if bundled with webpack - // @ts-expect-error + // @ts-expect-error avoid dynamic require if bundled with webpack if (typeof __webpack_require__ !== "function") { const requiredLoaders = new Set(); NormalModule.getCompilationHooks(compilation).beforeLoaders.tap( diff --git a/lib/RawModule.js b/lib/RawModule.js index bd02863c6..6167915d7 100644 --- a/lib/RawModule.js +++ b/lib/RawModule.js @@ -18,8 +18,10 @@ const makeSerializable = require("./util/makeSerializable"); /** @typedef {import("./Dependency").UpdateHashContext} UpdateHashContext */ /** @typedef {import("./DependencyTemplates")} DependencyTemplates */ /** @typedef {import("./Generator").SourceTypes} SourceTypes */ +/** @typedef {import("./Module").BuildCallback} BuildCallback */ /** @typedef {import("./Module").CodeGenerationContext} CodeGenerationContext */ /** @typedef {import("./Module").CodeGenerationResult} CodeGenerationResult */ +/** @typedef {import("./Module").NeedBuildCallback} NeedBuildCallback */ /** @typedef {import("./Module").NeedBuildContext} NeedBuildContext */ /** @typedef {import("./Module").ReadOnlyRuntimeRequirements} ReadOnlyRuntimeRequirements */ /** @typedef {import("./RequestShortener")} RequestShortener */ @@ -80,7 +82,7 @@ class RawModule extends Module { /** * @param {NeedBuildContext} context context info - * @param {function((WebpackError | null)=, boolean=): void} callback callback function, returns true, if the module needs a rebuild + * @param {NeedBuildCallback} callback callback function, returns true, if the module needs a rebuild * @returns {void} */ needBuild(context, callback) { @@ -92,7 +94,7 @@ class RawModule extends Module { * @param {Compilation} compilation the compilation * @param {ResolverWithOptions} resolver the resolver * @param {InputFileSystem} fs the file system - * @param {function(WebpackError=): void} callback callback function + * @param {BuildCallback} callback callback function * @returns {void} */ build(options, compilation, resolver, fs, callback) { diff --git a/lib/ResolverFactory.js b/lib/ResolverFactory.js index 9651c6a73..0403e8706 100644 --- a/lib/ResolverFactory.js +++ b/lib/ResolverFactory.js @@ -23,7 +23,7 @@ const { /** @typedef {WebpackResolveOptions & {dependencyType?: string, resolveToContext?: boolean }} ResolveOptionsWithDependencyType */ /** * @typedef {object} WithOptions - * @property {function(Partial): ResolverWithOptions} withOptions create a resolver with additional/different options + * @property {(options: Partial) => ResolverWithOptions} withOptions create a resolver with additional/different options */ /** @typedef {Resolver & WithOptions} ResolverWithOptions */ diff --git a/lib/RuntimeModule.js b/lib/RuntimeModule.js index f4fff959c..6f5e82ea1 100644 --- a/lib/RuntimeModule.js +++ b/lib/RuntimeModule.js @@ -18,8 +18,10 @@ const { WEBPACK_MODULE_TYPE_RUNTIME } = require("./ModuleTypeConstants"); /** @typedef {import("./Compilation")} Compilation */ /** @typedef {import("./Dependency").UpdateHashContext} UpdateHashContext */ /** @typedef {import("./Generator").SourceTypes} SourceTypes */ +/** @typedef {import("./Module").BuildCallback} BuildCallback */ /** @typedef {import("./Module").CodeGenerationContext} CodeGenerationContext */ /** @typedef {import("./Module").CodeGenerationResult} CodeGenerationResult */ +/** @typedef {import("./Module").NeedBuildCallback} NeedBuildCallback */ /** @typedef {import("./Module").NeedBuildContext} NeedBuildContext */ /** @typedef {import("./RequestShortener")} RequestShortener */ /** @typedef {import("./ResolverFactory").ResolverWithOptions} ResolverWithOptions */ @@ -79,7 +81,7 @@ class RuntimeModule extends Module { /** * @param {NeedBuildContext} context context info - * @param {function((WebpackError | null)=, boolean=): void} callback callback function, returns true, if the module needs a rebuild + * @param {NeedBuildCallback} callback callback function, returns true, if the module needs a rebuild * @returns {void} */ needBuild(context, callback) { @@ -91,7 +93,7 @@ class RuntimeModule extends Module { * @param {Compilation} compilation the compilation * @param {ResolverWithOptions} resolver the resolver * @param {InputFileSystem} fs the file system - * @param {function(WebpackError=): void} callback callback function + * @param {BuildCallback} callback callback function * @returns {void} */ build(options, compilation, resolver, fs, callback) { diff --git a/lib/SelfModuleFactory.js b/lib/SelfModuleFactory.js index 3a10333e2..97562b280 100644 --- a/lib/SelfModuleFactory.js +++ b/lib/SelfModuleFactory.js @@ -5,8 +5,8 @@ "use strict"; +/** @typedef {import("./ModuleFactory").ModuleFactoryCallback} ModuleFactoryCallback */ /** @typedef {import("./ModuleFactory").ModuleFactoryCreateData} ModuleFactoryCreateData */ -/** @typedef {import("./ModuleFactory").ModuleFactoryResult} ModuleFactoryResult */ /** @typedef {import("./ModuleGraph")} ModuleGraph */ class SelfModuleFactory { @@ -19,7 +19,7 @@ class SelfModuleFactory { /** * @param {ModuleFactoryCreateData} data data object - * @param {function((Error | null)=, ModuleFactoryResult=): void} callback callback + * @param {ModuleFactoryCallback} callback callback * @returns {void} */ create(data, callback) { diff --git a/lib/Template.js b/lib/Template.js index 3b95cfc35..4d2d4c203 100644 --- a/lib/Template.js +++ b/lib/Template.js @@ -60,7 +60,7 @@ const MATCH_PADDED_HYPHENS_REPLACE_REGEX = /^-|-$/g; /** * @typedef {object} RenderManifestEntryTemplated - * @property {function(): Source} render + * @property {() => Source} render * @property {TemplatePath} filenameTemplate * @property {PathData=} pathOptions * @property {AssetInfo=} info @@ -71,7 +71,7 @@ const MATCH_PADDED_HYPHENS_REPLACE_REGEX = /^-|-$/g; /** * @typedef {object} RenderManifestEntryStatic - * @property {function(): Source} render + * @property {() => Source} render * @property {string} filename * @property {AssetInfo} info * @property {string} identifier @@ -85,7 +85,7 @@ const MATCH_PADDED_HYPHENS_REPLACE_REGEX = /^-|-$/g; */ /** - * @typedef {function(Module, number): boolean} ModuleFilterPredicate + * @typedef {(module: Module) => boolean} ModuleFilterPredicate */ class Template { @@ -284,7 +284,7 @@ class Template { /** * @param {ChunkRenderContext} renderContext render context * @param {Module[]} modules modules to render (should be ordered by identifier) - * @param {function(Module): Source | null} renderModule function to render a module + * @param {(module: Module) => Source | null} renderModule function to render a module * @param {string=} prefix applying prefix strings * @returns {Source | null} rendered chunk modules in a Source object or null if no modules */ diff --git a/lib/TemplatedPathPlugin.js b/lib/TemplatedPathPlugin.js index e7cc5b944..69b6c0cba 100644 --- a/lib/TemplatedPathPlugin.js +++ b/lib/TemplatedPathPlugin.js @@ -116,7 +116,7 @@ const deprecatedFunction = (() => () => {})(); * @param {Function} fn function * @param {string} message message * @param {string} code code - * @returns {function(...any[]): void} function with deprecation output + * @returns {(...args: any[]) => void} function with deprecation output */ const deprecated = (fn, message, code) => { let d = deprecationCache.get(message); @@ -130,7 +130,7 @@ const deprecated = (fn, message, code) => { }; }; -/** @typedef {string | function(PathData, AssetInfo=): string} TemplatePath */ +/** @typedef {string | ((pathData: PathData, assetInfo?: AssetInfo) => string)} TemplatePath */ /** * @param {TemplatePath} path the raw path diff --git a/lib/asset/RawDataUrlModule.js b/lib/asset/RawDataUrlModule.js index 509efa516..fd5af3d75 100644 --- a/lib/asset/RawDataUrlModule.js +++ b/lib/asset/RawDataUrlModule.js @@ -15,8 +15,10 @@ const makeSerializable = require("../util/makeSerializable"); /** @typedef {import("../../declarations/WebpackOptions").WebpackOptionsNormalized} WebpackOptions */ /** @typedef {import("../Compilation")} Compilation */ /** @typedef {import("../Dependency").UpdateHashContext} UpdateHashContext */ +/** @typedef {import("../Module").BuildCallback} BuildCallback */ /** @typedef {import("../Module").CodeGenerationContext} CodeGenerationContext */ /** @typedef {import("../Module").CodeGenerationResult} CodeGenerationResult */ +/** @typedef {import("../Module").NeedBuildCallback} NeedBuildCallback */ /** @typedef {import("../Module").NeedBuildContext} NeedBuildContext */ /** @typedef {import("../Module").SourceTypes} SourceTypes */ /** @typedef {import("../RequestShortener")} RequestShortener */ @@ -77,7 +79,7 @@ class RawDataUrlModule extends Module { /** * @param {NeedBuildContext} context context info - * @param {function((WebpackError | null)=, boolean=): void} callback callback function, returns true, if the module needs a rebuild + * @param {NeedBuildCallback} callback callback function, returns true, if the module needs a rebuild * @returns {void} */ needBuild(context, callback) { @@ -89,7 +91,7 @@ class RawDataUrlModule extends Module { * @param {Compilation} compilation the compilation * @param {ResolverWithOptions} resolver the resolver * @param {InputFileSystem} fs the file system - * @param {function(WebpackError=): void} callback callback function + * @param {BuildCallback} callback callback function * @returns {void} */ build(options, compilation, resolver, fs, callback) { diff --git a/lib/cache/PackFileCacheStrategy.js b/lib/cache/PackFileCacheStrategy.js index b40c88e5f..23f56a2d4 100644 --- a/lib/cache/PackFileCacheStrategy.js +++ b/lib/cache/PackFileCacheStrategy.js @@ -394,7 +394,7 @@ class Pack { const mergedItems = new Set(); /** @type {Items} */ const mergedUsedItems = new Set(); - /** @type {(function(Map): Promise)[]} */ + /** @type {((map: Map) => Promise)[]} */ const addToMergedMap = []; for (const content of mergedContent) { for (const identifier of content.items) { @@ -795,7 +795,7 @@ makeSerializable( "PackContentItems" ); -/** @typedef {(function(): Promise | PackContentItems)} LazyFunction */ +/** @typedef {(() => Promise | PackContentItems)} LazyFunction */ class PackContent { /* @@ -820,7 +820,7 @@ class PackContent { /** * @param {Items} items keys * @param {Items} usedItems used keys - * @param {PackContentItems | function(): Promise} dataOrFn sync or async content + * @param {PackContentItems | (() => Promise)} dataOrFn sync or async content * @param {Logger=} logger logger for logging * @param {string=} lazyName name of dataOrFn for logging */ @@ -961,7 +961,7 @@ class PackContent { /** * @template T - * @param {function(any): function(): Promise | PackContentItems} write write function + * @param {(item: any) => (() => Promise | PackContentItems)} write write function * @returns {void} */ writeLazy(write) { diff --git a/lib/cache/ResolverCachePlugin.js b/lib/cache/ResolverCachePlugin.js index 84618ebc4..3baaa2c9b 100644 --- a/lib/cache/ResolverCachePlugin.js +++ b/lib/cache/ResolverCachePlugin.js @@ -130,7 +130,7 @@ class ResolverCachePlugin { }); }); - /** @typedef {function((Error | null)=, (ResolveRequest | null)=): void} Callback */ + /** @typedef {(err?: Error | null, resolveRequest?: ResolveRequest | null) => void} Callback */ /** @typedef {ResolveRequest & { _ResolverCachePluginCacheMiss: true }} ResolveRequestWithCacheMiss */ /** @@ -250,9 +250,10 @@ class ResolverCachePlugin { }; compiler.resolverFactory.hooks.resolver.intercept({ factory(type, _hook) { - /** @type {Map} */ + /** @typedef {(err?: Error, resolveRequest?: ResolveRequest) => void} ActiveRequest */ + /** @type {Map} */ const activeRequests = new Map(); - /** @type {Map][]>} */ + /** @type {Map][]>} */ const activeRequestsWithYield = new Map(); const hook = /** @type {SyncHook<[Resolver, ResolveOptions, ResolveOptionsWithDependencyType]>} */ @@ -306,7 +307,7 @@ class ResolverCachePlugin { let yields; /** - * @type {function((Error | null)=, (ResolveRequest | ResolveRequest[] | null)=): void} + * @type {(err?: Error | null, result?: ResolveRequest | ResolveRequest[] | null) => void} */ const done = withYield ? (err, result) => { diff --git a/lib/cache/getLazyHashedEtag.js b/lib/cache/getLazyHashedEtag.js index 7fa918b4a..2f651e70f 100644 --- a/lib/cache/getLazyHashedEtag.js +++ b/lib/cache/getLazyHashedEtag.js @@ -12,7 +12,7 @@ const createHash = require("../util/createHash"); /** * @typedef {object} HashableObject - * @property {function(Hash): void} updateHash + * @property {(hash: Hash) => void} updateHash */ class LazyHashedEtag { diff --git a/lib/config/defaults.js b/lib/config/defaults.js index ef305edf3..4d3d3dffa 100644 --- a/lib/config/defaults.js +++ b/lib/config/defaults.js @@ -100,7 +100,7 @@ const D = (obj, prop, value) => { * @template {keyof T} P * @param {T} obj an object * @param {P} prop a property of this object - * @param {function(): T[P]} factory a default value factory for the property + * @param {() => T[P]} factory a default value factory for the property * @returns {void} */ const F = (obj, prop, factory) => { @@ -118,7 +118,7 @@ const F = (obj, prop, factory) => { * @template {keyof T} P * @param {T} obj an object * @param {P} prop a property of this object - * @param {function(): T[P]} factory a default value factory for the property + * @param {() => T[P]} factory a default value factory for the property * @returns {void} */ const A = (obj, prop, factory) => { @@ -1281,7 +1281,7 @@ const applyOutputDefaults = ( } /** - * @param {function(EntryDescription): void} fn iterator + * @param {(entryDescription: EntryDescription) => void} fn iterator * @returns {void} */ const forEachEntry = fn => { @@ -1600,14 +1600,14 @@ const getResolveDefaults = ({ const browserField = tp && tp.web && (!tp.node || (tp.electron && tp.electronRenderer)); - /** @type {function(): ResolveOptions} */ + /** @type {() => ResolveOptions} */ const cjsDeps = () => ({ aliasFields: browserField ? ["browser"] : [], mainFields: browserField ? ["browser", "module", "..."] : ["module", "..."], conditionNames: ["require", "module", "..."], extensions: [...jsExtensions] }); - /** @type {function(): ResolveOptions} */ + /** @type {() => ResolveOptions} */ const esmDeps = () => ({ aliasFields: browserField ? ["browser"] : [], mainFields: browserField ? ["browser", "module", "..."] : ["module", "..."], diff --git a/lib/config/normalization.js b/lib/config/normalization.js index 3ed0c8132..3cfdfea70 100644 --- a/lib/config/normalization.js +++ b/lib/config/normalization.js @@ -44,8 +44,8 @@ const handledDeprecatedNoEmitOnErrors = util.deprecate( /** * @template T * @template R - * @param {T|undefined} value value or not - * @param {function(T): R} fn nested handler + * @param {T | undefined} value value or not + * @param {(value: T) => R} fn nested handler * @returns {R} result value */ const nestedConfig = (value, fn) => @@ -60,9 +60,9 @@ const cloneObject = value => /** @type {T} */ ({ ...value }); /** * @template T * @template R - * @param {T|undefined} value value or not - * @param {function(T): R} fn nested handler - * @returns {R|undefined} result value + * @param {T | undefined} value value or not + * @param {(value: T) => R} fn nested handler + * @returns {R | undefined} result value */ const optionalNestedConfig = (value, fn) => value === undefined ? undefined : fn(value); @@ -70,18 +70,18 @@ const optionalNestedConfig = (value, fn) => /** * @template T * @template R - * @param {T[]|undefined} value array or not - * @param {function(T[]): R[]} fn nested handler - * @returns {R[]|undefined} cloned value + * @param {T[] | undefined} value array or not + * @param {(value: T[]) => R[]} fn nested handler + * @returns {R[] | undefined} cloned value */ const nestedArray = (value, fn) => (Array.isArray(value) ? fn(value) : fn([])); /** * @template T * @template R - * @param {T[]|undefined} value array or not - * @param {function(T[]): R[]} fn nested handler - * @returns {R[]|undefined} cloned value + * @param {T[] | undefined} value array or not + * @param {(value: T[]) => R[]} fn nested handler + * @returns {R[] | undefined} cloned value */ const optionalNestedArray = (value, fn) => Array.isArray(value) ? fn(value) : undefined; @@ -90,8 +90,8 @@ const optionalNestedArray = (value, fn) => * @template T * @template R * @param {Record|undefined} value value or not - * @param {function(T): R} fn nested handler - * @param {Record=} customKeys custom nested handler for some keys + * @param {(value: T) => R} fn nested handler + * @param {Record R>=} customKeys custom nested handler for some keys * @returns {Record} result value */ const keyedNestedConfig = (value, fn, customKeys) => { diff --git a/lib/container/ContainerEntryModule.js b/lib/container/ContainerEntryModule.js index 3b22c7123..0395372e8 100644 --- a/lib/container/ContainerEntryModule.js +++ b/lib/container/ContainerEntryModule.js @@ -20,9 +20,11 @@ const ContainerExposedDependency = require("./ContainerExposedDependency"); /** @typedef {import("../ChunkGraph")} ChunkGraph */ /** @typedef {import("../ChunkGroup")} ChunkGroup */ /** @typedef {import("../Compilation")} Compilation */ +/** @typedef {import("../Module").BuildCallback} BuildCallback */ /** @typedef {import("../Module").CodeGenerationContext} CodeGenerationContext */ /** @typedef {import("../Module").CodeGenerationResult} CodeGenerationResult */ /** @typedef {import("../Module").LibIdentOptions} LibIdentOptions */ +/** @typedef {import("../Module").NeedBuildCallback} NeedBuildCallback */ /** @typedef {import("../Module").NeedBuildContext} NeedBuildContext */ /** @typedef {import("../Module").SourceTypes} SourceTypes */ /** @typedef {import("../RequestShortener")} RequestShortener */ @@ -91,7 +93,7 @@ class ContainerEntryModule extends Module { /** * @param {NeedBuildContext} context context info - * @param {function((WebpackError | null)=, boolean=): void} callback callback function, returns true, if the module needs a rebuild + * @param {NeedBuildCallback} callback callback function, returns true, if the module needs a rebuild * @returns {void} */ needBuild(context, callback) { @@ -103,7 +105,7 @@ class ContainerEntryModule extends Module { * @param {Compilation} compilation the compilation * @param {ResolverWithOptions} resolver the resolver * @param {InputFileSystem} fs the file system - * @param {function(WebpackError=): void} callback callback function + * @param {BuildCallback} callback callback function * @returns {void} */ build(options, compilation, resolver, fs, callback) { diff --git a/lib/container/ContainerEntryModuleFactory.js b/lib/container/ContainerEntryModuleFactory.js index 4febfebe0..cff347bfd 100644 --- a/lib/container/ContainerEntryModuleFactory.js +++ b/lib/container/ContainerEntryModuleFactory.js @@ -8,14 +8,14 @@ const ModuleFactory = require("../ModuleFactory"); const ContainerEntryModule = require("./ContainerEntryModule"); +/** @typedef {import("../ModuleFactory").ModuleFactoryCallback} ModuleFactoryCallback */ /** @typedef {import("../ModuleFactory").ModuleFactoryCreateData} ModuleFactoryCreateData */ -/** @typedef {import("../ModuleFactory").ModuleFactoryResult} ModuleFactoryResult */ /** @typedef {import("./ContainerEntryDependency")} ContainerEntryDependency */ module.exports = class ContainerEntryModuleFactory extends ModuleFactory { /** * @param {ModuleFactoryCreateData} data data object - * @param {function((Error | null)=, ModuleFactoryResult=): void} callback callback + * @param {ModuleFactoryCallback} callback callback * @returns {void} */ create({ dependencies: [dependency] }, callback) { diff --git a/lib/container/FallbackModule.js b/lib/container/FallbackModule.js index 50ea21b7e..079633829 100644 --- a/lib/container/FallbackModule.js +++ b/lib/container/FallbackModule.js @@ -19,9 +19,11 @@ const FallbackItemDependency = require("./FallbackItemDependency"); /** @typedef {import("../ChunkGraph")} ChunkGraph */ /** @typedef {import("../ChunkGroup")} ChunkGroup */ /** @typedef {import("../Compilation")} Compilation */ +/** @typedef {import("../Module").BuildCallback} BuildCallback */ /** @typedef {import("../Module").CodeGenerationContext} CodeGenerationContext */ /** @typedef {import("../Module").CodeGenerationResult} CodeGenerationResult */ /** @typedef {import("../Module").LibIdentOptions} LibIdentOptions */ +/** @typedef {import("../Module").NeedBuildCallback} NeedBuildCallback */ /** @typedef {import("../Module").NeedBuildContext} NeedBuildContext */ /** @typedef {import("../Module").SourceTypes} SourceTypes */ /** @typedef {import("../RequestShortener")} RequestShortener */ @@ -80,7 +82,7 @@ class FallbackModule extends Module { /** * @param {NeedBuildContext} context context info - * @param {function((WebpackError | null)=, boolean=): void} callback callback function, returns true, if the module needs a rebuild + * @param {NeedBuildCallback} callback callback function, returns true, if the module needs a rebuild * @returns {void} */ needBuild(context, callback) { @@ -92,7 +94,7 @@ class FallbackModule extends Module { * @param {Compilation} compilation the compilation * @param {ResolverWithOptions} resolver the resolver * @param {InputFileSystem} fs the file system - * @param {function(WebpackError=): void} callback callback function + * @param {BuildCallback} callback callback function * @returns {void} */ build(options, compilation, resolver, fs, callback) { diff --git a/lib/container/FallbackModuleFactory.js b/lib/container/FallbackModuleFactory.js index 6a9eaeca0..9ae5d427f 100644 --- a/lib/container/FallbackModuleFactory.js +++ b/lib/container/FallbackModuleFactory.js @@ -8,14 +8,14 @@ const ModuleFactory = require("../ModuleFactory"); const FallbackModule = require("./FallbackModule"); +/** @typedef {import("../ModuleFactory").ModuleFactoryCallback} ModuleFactoryCallback */ /** @typedef {import("../ModuleFactory").ModuleFactoryCreateData} ModuleFactoryCreateData */ -/** @typedef {import("../ModuleFactory").ModuleFactoryResult} ModuleFactoryResult */ /** @typedef {import("./FallbackDependency")} FallbackDependency */ module.exports = class FallbackModuleFactory extends ModuleFactory { /** * @param {ModuleFactoryCreateData} data data object - * @param {function((Error | null)=, ModuleFactoryResult=): void} callback callback + * @param {ModuleFactoryCallback} callback callback * @returns {void} */ create({ dependencies: [dependency] }, callback) { diff --git a/lib/container/RemoteModule.js b/lib/container/RemoteModule.js index 4a2cf128d..9ff13fcfc 100644 --- a/lib/container/RemoteModule.js +++ b/lib/container/RemoteModule.js @@ -20,9 +20,11 @@ const RemoteToExternalDependency = require("./RemoteToExternalDependency"); /** @typedef {import("../ChunkGraph")} ChunkGraph */ /** @typedef {import("../ChunkGroup")} ChunkGroup */ /** @typedef {import("../Compilation")} Compilation */ +/** @typedef {import("../Module").BuildCallback} BuildCallback */ /** @typedef {import("../Module").CodeGenerationContext} CodeGenerationContext */ /** @typedef {import("../Module").CodeGenerationResult} CodeGenerationResult */ /** @typedef {import("../Module").LibIdentOptions} LibIdentOptions */ +/** @typedef {import("../Module").NeedBuildCallback} NeedBuildCallback */ /** @typedef {import("../Module").NeedBuildContext} NeedBuildContext */ /** @typedef {import("../Module").SourceTypes} SourceTypes */ /** @typedef {import("../RequestShortener")} RequestShortener */ @@ -80,7 +82,7 @@ class RemoteModule extends Module { /** * @param {NeedBuildContext} context context info - * @param {function((WebpackError | null)=, boolean=): void} callback callback function, returns true, if the module needs a rebuild + * @param {NeedBuildCallback} callback callback function, returns true, if the module needs a rebuild * @returns {void} */ needBuild(context, callback) { @@ -92,7 +94,7 @@ class RemoteModule extends Module { * @param {Compilation} compilation the compilation * @param {ResolverWithOptions} resolver the resolver * @param {InputFileSystem} fs the file system - * @param {function(WebpackError=): void} callback callback function + * @param {BuildCallback} callback callback function * @returns {void} */ build(options, compilation, resolver, fs, callback) { diff --git a/lib/container/options.js b/lib/container/options.js index cb7df0d55..367d62261 100644 --- a/lib/container/options.js +++ b/lib/container/options.js @@ -19,9 +19,9 @@ * @template T * @template N * @param {ContainerOptionsFormat} options options passed by the user - * @param {function(string | string[], string) : N} normalizeSimple normalize a simple item - * @param {function(T, string) : N} normalizeOptions normalize a complex item - * @param {function(string, N): void} fn processing function + * @param {(item: string | string[], itemOrKey: string) => N} normalizeSimple normalize a simple item + * @param {(value: T, key: string) => N} normalizeOptions normalize a complex item + * @param {(item: string, normalized: N) => void} fn processing function * @returns {void} */ const process = (options, normalizeSimple, normalizeOptions, fn) => { @@ -66,8 +66,8 @@ const process = (options, normalizeSimple, normalizeOptions, fn) => { * @template T * @template R * @param {ContainerOptionsFormat} options options passed by the user - * @param {function(string | string[], string) : R} normalizeSimple normalize a simple item - * @param {function(T, string) : R} normalizeOptions normalize a complex item + * @param {(item: string | string[], itemOrKey: string) => R} normalizeSimple normalize a simple item + * @param {(value: T, key: string) => R} normalizeOptions normalize a complex item * @returns {[string, R][]} parsed options */ const parseOptions = (options, normalizeSimple, normalizeOptions) => { diff --git a/lib/css/CssModulesPlugin.js b/lib/css/CssModulesPlugin.js index 3544ca0eb..830cd7eac 100644 --- a/lib/css/CssModulesPlugin.js +++ b/lib/css/CssModulesPlugin.js @@ -95,7 +95,7 @@ const getCssLoadingRuntimeModule = memoize(() => /** * @param {string} name name - * @returns {{oneOf: [{$ref: string}], definitions: *}} schema + * @returns {{ oneOf: [{ $ref: string }], definitions: import("../../schemas/WebpackOptions.json")["definitions"] }} schema */ const getSchema = name => { const { definitions } = require("../../schemas/WebpackOptions.json"); @@ -740,7 +740,7 @@ class CssModulesPlugin { } /** - * @param {CssModule} module css module + * @param {CssModule} module css module * @param {ChunkRenderContext} renderContext options object * @param {CompilationHooks} hooks hooks * @returns {Source} css module source diff --git a/lib/css/walkCssTokens.js b/lib/css/walkCssTokens.js index abef4f01e..ea019b3e4 100644 --- a/lib/css/walkCssTokens.js +++ b/lib/css/walkCssTokens.js @@ -7,25 +7,25 @@ /** * @typedef {object} CssTokenCallbacks - * @property {(function(string, number, number, number, number): number)=} url - * @property {(function(string, number, number): number)=} comment - * @property {(function(string, number, number): number)=} string - * @property {(function(string, number, number): number)=} leftParenthesis - * @property {(function(string, number, number): number)=} rightParenthesis - * @property {(function(string, number, number): number)=} function - * @property {(function(string, number, number): number)=} colon - * @property {(function(string, number, number): number)=} atKeyword - * @property {(function(string, number, number): number)=} delim - * @property {(function(string, number, number): number)=} identifier - * @property {(function(string, number, number, boolean): number)=} hash - * @property {(function(string, number, number): number)=} leftCurlyBracket - * @property {(function(string, number, number): number)=} rightCurlyBracket - * @property {(function(string, number, number): number)=} semicolon - * @property {(function(string, number, number): number)=} comma - * @property {(function(): boolean)=} needTerminate + * @property {((input: string, start: number, end: number, innerStart: number, innerEnd: number) => number)=} url + * @property {((input: string, start: number, end: number) => number)=} comment + * @property {((input: string, start: number, end: number) => number)=} string + * @property {((input: string, start: number, end: number) => number)=} leftParenthesis + * @property {((input: string, start: number, end: number) => number)=} rightParenthesis + * @property {((input: string, start: number, end: number) => number)=} function + * @property {((input: string, start: number, end: number) => number)=} colon + * @property {((input: string, start: number, end: number) => number)=} atKeyword + * @property {((input: string, start: number, end: number) => number)=} delim + * @property {((input: string, start: number, end: number) => number)=} identifier + * @property {((input: string, start: number, end: number, isId: boolean) => number)=} hash + * @property {((input: string, start: number, end: number) => number)=} leftCurlyBracket + * @property {((input: string, start: number, end: number) => number)=} rightCurlyBracket + * @property {((input: string, start: number, end: number) => number)=} semicolon + * @property {((input: string, start: number, end: number) => number)=} comma + * @property {(() => boolean)=} needTerminate */ -/** @typedef {function(string, number, CssTokenCallbacks): number} CharHandler */ +/** @typedef {(input: string, pos: number, callbacks: CssTokenCallbacks) => number} CharHandler */ // spec: https://drafts.csswg.org/css-syntax/ diff --git a/lib/dependencies/AMDPlugin.js b/lib/dependencies/AMDPlugin.js index 2ae03b78b..c48636164 100644 --- a/lib/dependencies/AMDPlugin.js +++ b/lib/dependencies/AMDPlugin.js @@ -140,7 +140,7 @@ class AMDPlugin { /** * @param {string} optionExpr option expression * @param {string} rootName root name - * @param {function(): TODO} getMembers callback + * @param {() => TODO} getMembers callback */ const tapOptionsHooks = (optionExpr, rootName, getMembers) => { parser.hooks.expression diff --git a/lib/dependencies/LoaderPlugin.js b/lib/dependencies/LoaderPlugin.js index 3612cbeac..d39acc9e6 100644 --- a/lib/dependencies/LoaderPlugin.js +++ b/lib/dependencies/LoaderPlugin.js @@ -271,8 +271,7 @@ class LoaderPlugin { ); }; - // eslint-disable-next-line no-warning-comments - // @ts-ignore Overloading doesn't work + // @ts-expect-error overloading doesn't work loaderContext.importModule = (request, options, callback) => { if (!callback) { return new Promise((resolve, reject) => { diff --git a/lib/hmr/LazyCompilationPlugin.js b/lib/hmr/LazyCompilationPlugin.js index 8f528f921..d6ca2e305 100644 --- a/lib/hmr/LazyCompilationPlugin.js +++ b/lib/hmr/LazyCompilationPlugin.js @@ -23,14 +23,16 @@ const { registerNotSerializable } = require("../util/serialization"); /** @typedef {import("../Compilation")} Compilation */ /** @typedef {import("../Compiler")} Compiler */ /** @typedef {import("../Dependency").UpdateHashContext} UpdateHashContext */ +/** @typedef {import("../Module").BuildCallback} BuildCallback */ /** @typedef {import("../Module").BuildMeta} BuildMeta */ /** @typedef {import("../Module").CodeGenerationContext} CodeGenerationContext */ /** @typedef {import("../Module").CodeGenerationResult} CodeGenerationResult */ /** @typedef {import("../Module").LibIdentOptions} LibIdentOptions */ +/** @typedef {import("../Module").NeedBuildCallback} NeedBuildCallback */ /** @typedef {import("../Module").NeedBuildContext} NeedBuildContext */ /** @typedef {import("../Module").SourceTypes} SourceTypes */ +/** @typedef {import("../ModuleFactory").ModuleFactoryCallback} ModuleFactoryCallback */ /** @typedef {import("../ModuleFactory").ModuleFactoryCreateData} ModuleFactoryCreateData */ -/** @typedef {import("../ModuleFactory").ModuleFactoryResult} ModuleFactoryResult */ /** @typedef {import("../RequestShortener")} RequestShortener */ /** @typedef {import("../ResolverFactory").ResolverWithOptions} ResolverWithOptions */ /** @typedef {import("../WebpackError")} WebpackError */ @@ -42,8 +44,8 @@ const { registerNotSerializable } = require("../util/serialization"); /** * @typedef {object} BackendApi - * @property {function(function((Error | null)=) : void): void} dispose - * @property {function(Module): ModuleResult} module + * @property {(callback: (err?: (Error | null)) => void) => void} dispose + * @property {(module: Module) => ModuleResult} module */ const HMR_DEPENDENCY_TYPES = new Set([ @@ -169,7 +171,7 @@ class LazyCompilationProxyModule extends Module { /** * @param {NeedBuildContext} context context info - * @param {function((WebpackError | null)=, boolean=): void} callback callback function, returns true, if the module needs a rebuild + * @param {NeedBuildCallback} callback callback function, returns true, if the module needs a rebuild * @returns {void} */ needBuild(context, callback) { @@ -181,7 +183,7 @@ class LazyCompilationProxyModule extends Module { * @param {Compilation} compilation the compilation * @param {ResolverWithOptions} resolver the resolver * @param {InputFileSystem} fs the file system - * @param {function(WebpackError=): void} callback callback function + * @param {BuildCallback} callback callback function * @returns {void} */ build(options, compilation, resolver, fs, callback) { @@ -315,7 +317,7 @@ class LazyCompilationDependencyFactory extends ModuleFactory { /** * @param {ModuleFactoryCreateData} data data object - * @param {function((Error | null)=, ModuleFactoryResult=): void} callback callback + * @param {ModuleFactoryCallback} callback callback * @returns {void} */ create(data, callback) { @@ -331,7 +333,7 @@ class LazyCompilationDependencyFactory extends ModuleFactory { /** * @callback BackendHandler * @param {Compiler} compiler compiler - * @param {function(Error | null, BackendApi=): void} callback callback + * @param {(err: Error | null, backendApi?: BackendApi) => void} callback callback * @returns {void} */ @@ -347,7 +349,7 @@ class LazyCompilationPlugin { * @param {BackendHandler | PromiseBackendHandler} options.backend the backend * @param {boolean} options.entries true, when entries are lazy compiled * @param {boolean} options.imports true, when import() modules are lazy compiled - * @param {RegExp | string | (function(Module): boolean) | undefined} options.test additional filter for lazy compiled entrypoint modules + * @param {RegExp | string | ((module: Module) => boolean) | undefined} options.test additional filter for lazy compiled entrypoint modules */ constructor({ backend, entries, imports, test }) { this.backend = backend; diff --git a/lib/hmr/lazyCompilationBackend.js b/lib/hmr/lazyCompilationBackend.js index 383a16dd4..479e3cd59 100644 --- a/lib/hmr/lazyCompilationBackend.js +++ b/lib/hmr/lazyCompilationBackend.js @@ -43,7 +43,7 @@ module.exports = options => (compiler, callback) => { (options.server) ); })(); - /** @type {function(Server): void} */ + /** @type {(server: Server) => void} */ const listen = typeof options.listen === "function" ? options.listen diff --git a/lib/ids/DeterministicModuleIdsPlugin.js b/lib/ids/DeterministicModuleIdsPlugin.js index 8cf07e082..72d0b6deb 100644 --- a/lib/ids/DeterministicModuleIdsPlugin.js +++ b/lib/ids/DeterministicModuleIdsPlugin.js @@ -20,7 +20,7 @@ const { /** * @typedef {object} DeterministicModuleIdsPluginOptions * @property {string=} context context relative to which module identifiers are computed - * @property {function(Module): boolean=} test selector function for modules + * @property {((module: Module) => boolean)=} test selector function for modules * @property {number=} maxLength maximum id length in digits (used as starting point) * @property {number=} salt hash salt for ids * @property {boolean=} fixedLength do not increase the maxLength to find an optimal id space size diff --git a/lib/ids/IdHelpers.js b/lib/ids/IdHelpers.js index 78cdaef05..ddbdd19b6 100644 --- a/lib/ids/IdHelpers.js +++ b/lib/ids/IdHelpers.js @@ -226,7 +226,7 @@ const addToMapOfItems = (map, key, value) => { /** * @param {Compilation} compilation the compilation - * @param {function(Module): boolean=} filter filter modules + * @param {((module: Module) => boolean)=} filter filter modules * @returns {[Set, Module[]]} used module ids as strings and modules without id matching the filter */ const getUsedModuleIdsAndModules = (compilation, filter) => { @@ -286,11 +286,11 @@ module.exports.getUsedChunkIds = getUsedChunkIds; /** * @template T * @param {Iterable} items list of items to be named - * @param {function(T): string} getShortName get a short name for an item - * @param {function(T, string): string} getLongName get a long name for an item - * @param {function(T, T): -1|0|1} comparator order of items + * @param {(item: T) => string} getShortName get a short name for an item + * @param {(item: T, name: string) => string} getLongName get a long name for an item + * @param {(a: T, b: T) => -1 | 0 | 1} comparator order of items * @param {Set} usedIds already used ids, will not be assigned - * @param {function(T, string): void} assignName assign a name to an item + * @param {(item: T, name: string) => void} assignName assign a name to an item * @returns {T[]} list of items without a name */ const assignNames = ( @@ -354,9 +354,9 @@ module.exports.assignNames = assignNames; /** * @template T * @param {T[]} items list of items to be named - * @param {function(T): string} getName get a name for an item - * @param {function(T, T): -1|0|1} comparator order of items - * @param {function(T, number): boolean} assignId assign an id to an item + * @param {(item: T) => string} getName get a name for an item + * @param {(a: T, n: T) => -1 | 0 | 1} comparator order of items + * @param {(item: T, id: number) => boolean} assignId assign an id to an item * @param {number[]} ranges usable ranges for ids * @param {number} expandFactor factor to create more ranges * @param {number} extraSpace extra space to allocate, i. e. when some ids are already used diff --git a/lib/ids/SyncModuleIdsPlugin.js b/lib/ids/SyncModuleIdsPlugin.js index aa837624e..7154a8bcd 100644 --- a/lib/ids/SyncModuleIdsPlugin.js +++ b/lib/ids/SyncModuleIdsPlugin.js @@ -19,7 +19,7 @@ class SyncModuleIdsPlugin { * @param {object} options options * @param {string} options.path path to file * @param {string=} options.context context for module names - * @param {function(Module): boolean} options.test selector for modules + * @param {((module: Module) => boolean)=} options.test selector for modules * @param {"read" | "create" | "merge" | "update"=} options.mode operation mode (defaults to merge) */ constructor({ path, context, test, mode }) { diff --git a/lib/index.js b/lib/index.js index 1e6b8bfd4..9db18d41e 100644 --- a/lib/index.js +++ b/lib/index.js @@ -65,7 +65,7 @@ const memoize = require("./util/memoize"); /** * @template {Function} T - * @param {function(): T} factory factory function + * @param {() => T} factory factory function * @returns {T} function */ const lazyFunction = factory => { @@ -120,13 +120,13 @@ module.exports = mergeExports(fn, { return require("./webpack"); }, /** - * @returns {function(Configuration | Configuration[]): void} validate fn + * @returns {(configuration: Configuration | Configuration[]) => void} validate fn */ get validate() { const webpackOptionsSchemaCheck = require("../schemas/WebpackOptions.check.js"); const getRealValidate = memoize( /** - * @returns {function(Configuration | Configuration[]): void} validate fn + * @returns {(configuration: Configuration | Configuration[]) => void} validate fn */ () => { const validateSchema = require("./validateSchema"); diff --git a/lib/javascript/JavascriptGenerator.js b/lib/javascript/JavascriptGenerator.js index 6bba9756b..8468b3928 100644 --- a/lib/javascript/JavascriptGenerator.js +++ b/lib/javascript/JavascriptGenerator.js @@ -36,7 +36,7 @@ const deprecatedGetInitFragments = util.deprecate( * @returns {InitFragment[]} init fragments */ (template, dependency, templateContext) => - /** @type {DependencyTemplate & { getInitFragments: function(Dependency, DependencyTemplateContext): InitFragment[] }} */ + /** @type {DependencyTemplate & { getInitFragments: (dependency: Dependency, dependencyTemplateContext: DependencyTemplateContext) => InitFragment[] }} */ (template).getInitFragments(dependency, templateContext), "DependencyTemplate.getInitFragment is deprecated (use apply(dep, source, { initFragments }) instead)", "DEP_WEBPACK_JAVASCRIPT_GENERATOR_GET_INIT_FRAGMENTS" diff --git a/lib/javascript/JavascriptModulesPlugin.js b/lib/javascript/JavascriptModulesPlugin.js index f2f0dcd0b..89defcf0a 100644 --- a/lib/javascript/JavascriptModulesPlugin.js +++ b/lib/javascript/JavascriptModulesPlugin.js @@ -1000,7 +1000,7 @@ class JavascriptModulesPlugin { const lastEntryModule = /** @type {Module} */ (last(chunkGraph.getChunkEntryModulesIterable(chunk))); - /** @type {function(string[], string): Source} */ + /** @type {(content: string[], name: string) => Source} */ const toSource = useSourceMap ? (content, name) => new OriginalSource(Template.asString(content), name) diff --git a/lib/javascript/JavascriptParser.js b/lib/javascript/JavascriptParser.js index 4a4b6bd57..5ca33084b 100644 --- a/lib/javascript/JavascriptParser.js +++ b/lib/javascript/JavascriptParser.js @@ -94,8 +94,8 @@ const BasicEvaluatedExpression = require("./BasicEvaluatedExpression"); /** @typedef {import("../Parser").PreparsedAst} PreparsedAst */ /** @typedef {{ name: string | VariableInfo, rootInfo: string | VariableInfo, getMembers: () => string[], getMembersOptionals: () => boolean[], getMemberRanges: () => Range[] }} GetInfoResult */ /** @typedef {Statement | ModuleDeclaration | Expression} StatementPathItem */ -/** @typedef {function(string): void} OnIdentString */ -/** @typedef {function(string, Identifier): void} OnIdent */ +/** @typedef {(ident: string) => void} OnIdentString */ +/** @typedef {(ident: string, identifier: Identifier) => void} OnIdent */ /** @typedef {StatementPathItem[]} StatementPath */ // TODO remove cast when @types/estree has been updated to import assertions @@ -1361,7 +1361,7 @@ class JavascriptParser extends Parser { }); /** * @param {"Identifier" | "ThisExpression" | "MemberExpression"} exprType expression type name - * @param {function(Expression | SpreadElement): GetInfoResult | undefined} getInfo get info + * @param {(node: Expression | SpreadElement) => GetInfoResult | undefined} getInfo get info * @returns {void} */ const tapEvaluateWithVariableInfo = (exprType, getInfo) => { @@ -3637,13 +3637,13 @@ class JavascriptParser extends Parser { expression.callee.type === "MemberExpression" && expression.callee.object.type.endsWith("FunctionExpression") && !expression.callee.computed && - // eslint-disable-next-line no-warning-comments - // @ts-ignore - // TODO check me and handle more cases - (expression.callee.property.name === "call" || - // eslint-disable-next-line no-warning-comments - // @ts-ignore - expression.callee.property.name === "bind") && + /** @type {boolean} */ + ( + /** @type {TODO} */ + (expression.callee.property).name === "call" || + /** @type {TODO} */ + (expression.callee.property).name === "bind" + ) && expression.arguments.length > 0 && isSimpleFunction( /** @type {FunctionExpression | ArrowFunctionExpression} */ @@ -3881,8 +3881,8 @@ class JavascriptParser extends Parser { * @template R * @param {HookMap>} hookMap hooks the should be called * @param {Expression | Super} expr expression info - * @param {(function(string, string | ScopeInfo | VariableInfo, function(): string[]): any) | undefined} fallback callback when variable in not handled by hooks - * @param {(function(string): any) | undefined} defined callback when variable is defined + * @param {((name: string, rootInfo: string | ScopeInfo | VariableInfo, getMembers: () => string[]) => any) | undefined} fallback callback when variable in not handled by hooks + * @param {((result?: string) => any) | undefined} defined callback when variable is defined * @param {AsArray} args args for the hook * @returns {R | undefined} result of hook */ @@ -3933,7 +3933,7 @@ class JavascriptParser extends Parser { * @template R * @param {HookMap>} hookMap hooks that should be called * @param {ExportedVariableInfo} info variable info - * @param {AsArray} args args for the hook + * @param {AsArray} args args for the hook * @returns {R | undefined} result of hook */ callHooksForInfo(hookMap, info, ...args) { @@ -3951,8 +3951,8 @@ class JavascriptParser extends Parser { * @template R * @param {HookMap>} hookMap hooks the should be called * @param {ExportedVariableInfo} info variable info - * @param {(function(string): any) | undefined} fallback callback when variable in not handled by hooks - * @param {(function(string=): any) | undefined} defined callback when variable is defined + * @param {((name: string) => any) | undefined} fallback callback when variable in not handled by hooks + * @param {((result?: string) => any) | undefined} defined callback when variable is defined * @param {AsArray} args args for the hook * @returns {R | undefined} result of hook */ @@ -4001,8 +4001,8 @@ class JavascriptParser extends Parser { * @template R * @param {HookMap>} hookMap hooks the should be called * @param {string} name key in map - * @param {(function(string): any) | undefined} fallback callback when variable in not handled by hooks - * @param {(function(): any) | undefined} defined callback when variable is defined + * @param {((value: string) => any) | undefined} fallback callback when variable in not handled by hooks + * @param {(() => any) | undefined} defined callback when variable is defined * @param {AsArray} args args for the hook * @returns {R | undefined} result of hook */ @@ -4019,7 +4019,7 @@ class JavascriptParser extends Parser { /** * @deprecated * @param {(string | Pattern | Property)[]} params scope params - * @param {function(): void} fn inner function + * @param {() => void} fn inner function * @returns {void} */ inScope(params, fn) { @@ -4049,7 +4049,7 @@ class JavascriptParser extends Parser { /** * @param {boolean} state executed state - * @param {function(): void} fn inner function + * @param {() => void} fn inner function */ inExecutedPath(state, fn) { const oldState = this.scope.inExecutedPath; @@ -4067,7 +4067,7 @@ class JavascriptParser extends Parser { /** * @param {boolean} hasThis true, when this is defined * @param {Identifier[]} params scope params - * @param {function(): void} fn inner function + * @param {() => void} fn inner function * @returns {void} */ inClassScope(hasThis, params, fn) { @@ -4100,7 +4100,7 @@ class JavascriptParser extends Parser { /** * @param {boolean} hasThis true, when this is defined * @param {(Pattern | string)[]} params scope params - * @param {function(): void} fn inner function + * @param {() => void} fn inner function * @returns {void} */ inFunctionScope(hasThis, params, fn) { @@ -4131,7 +4131,7 @@ class JavascriptParser extends Parser { } /** - * @param {function(): void} fn inner function + * @param {() => void} fn inner function * @param {boolean} inExecutedPath executed state * @returns {void} */ diff --git a/lib/javascript/JavascriptParserHelpers.js b/lib/javascript/JavascriptParserHelpers.js index 7028c4dd1..ebd912c02 100644 --- a/lib/javascript/JavascriptParserHelpers.js +++ b/lib/javascript/JavascriptParserHelpers.js @@ -19,13 +19,14 @@ const BasicEvaluatedExpression = require("./BasicEvaluatedExpression"); * @param {JavascriptParser} parser the parser * @param {string} value the const value * @param {(string[] | null)=} runtimeRequirements runtime requirements - * @returns {function(Expression): true} plugin function + * @returns {(expression: Expression) => true} plugin function */ module.exports.toConstantDependency = (parser, value, runtimeRequirements) => function constDependency(expr) { const dep = new ConstDependency( value, - /** @type {Range} */ (expr.range), + /** @type {Range} */ + (expr.range), runtimeRequirements ); dep.loc = /** @type {SourceLocation} */ (expr.loc); @@ -35,7 +36,7 @@ module.exports.toConstantDependency = (parser, value, runtimeRequirements) => /** * @param {string} value the string value - * @returns {function(Expression): BasicEvaluatedExpression} plugin function + * @returns {(expression: Expression) => BasicEvaluatedExpression} plugin function */ module.exports.evaluateToString = value => function stringExpression(expr) { @@ -46,7 +47,7 @@ module.exports.evaluateToString = value => /** * @param {number} value the number value - * @returns {function(Expression): BasicEvaluatedExpression} plugin function + * @returns {(expression: Expression) => BasicEvaluatedExpression} plugin function */ module.exports.evaluateToNumber = value => function stringExpression(expr) { @@ -57,7 +58,7 @@ module.exports.evaluateToNumber = value => /** * @param {boolean} value the boolean value - * @returns {function(Expression): BasicEvaluatedExpression} plugin function + * @returns {(expression: Expression) => BasicEvaluatedExpression} plugin function */ module.exports.evaluateToBoolean = value => function booleanExpression(expr) { @@ -69,9 +70,9 @@ module.exports.evaluateToBoolean = value => /** * @param {string} identifier identifier * @param {string} rootInfo rootInfo - * @param {function(): string[]} getMembers getMembers - * @param {boolean|null=} truthy is truthy, null if nullish - * @returns {function(Expression): BasicEvaluatedExpression} callback + * @param {() => string[]} getMembers getMembers + * @param {boolean | null=} truthy is truthy, null if nullish + * @returns {(expression: Expression) => BasicEvaluatedExpression} callback */ module.exports.evaluateToIdentifier = ( identifier, @@ -102,7 +103,7 @@ module.exports.evaluateToIdentifier = ( /** * @param {JavascriptParser} parser the parser * @param {string} message the message - * @returns {function(Expression): boolean | undefined} callback to handle unsupported expression + * @returns {(expression: Expression) => boolean | undefined} callback to handle unsupported expression */ module.exports.expressionIsUnsupported = (parser, message) => function unsupportedExpression(expr) { diff --git a/lib/javascript/StartupHelpers.js b/lib/javascript/StartupHelpers.js index f15492ee3..fe6a05c4a 100644 --- a/lib/javascript/StartupHelpers.js +++ b/lib/javascript/StartupHelpers.js @@ -165,7 +165,7 @@ module.exports.updateHashForEntryStartup = ( /** * @param {Chunk} chunk the chunk * @param {ChunkGraph} chunkGraph the chunk graph - * @param {function(Chunk, ChunkGraph): boolean} filterFn filter function + * @param {(chunk: Chunk, chunkGraph: ChunkGraph) => boolean} filterFn filter function * @returns {Set} initially fulfilled chunk ids */ module.exports.getInitialChunkIds = (chunk, chunkGraph, filterFn) => { diff --git a/lib/logging/Logger.js b/lib/logging/Logger.js index 910b16f78..d785e0c00 100644 --- a/lib/logging/Logger.js +++ b/lib/logging/Logger.js @@ -37,8 +37,8 @@ const TIMERS_AGGREGATES_SYMBOL = Symbol("webpack logger aggregated times"); class WebpackLogger { /** - * @param {function(LogTypeEnum, EXPECTED_ANY[]=): void} log log function - * @param {function(string | function(): string): WebpackLogger} getChildLogger function to create child logger + * @param {(type: LogTypeEnum, args?: EXPECTED_ANY[]) => void} log log function + * @param {(name: string | (() => string)) => WebpackLogger} getChildLogger function to create child logger */ constructor(log, getChildLogger) { this[LOG_SYMBOL] = log; diff --git a/lib/logging/createConsoleLogger.js b/lib/logging/createConsoleLogger.js index 3b8ffd838..b28aa337f 100644 --- a/lib/logging/createConsoleLogger.js +++ b/lib/logging/createConsoleLogger.js @@ -11,13 +11,13 @@ const { LogType } = require("./Logger"); /** @typedef {import("../../declarations/WebpackOptions").FilterTypes} FilterTypes */ /** @typedef {import("./Logger").LogTypeEnum} LogTypeEnum */ -/** @typedef {function(string): boolean} FilterFunction */ -/** @typedef {function(string, LogTypeEnum, EXPECTED_ANY[]=): void} LoggingFunction */ +/** @typedef {(item: string) => boolean} FilterFunction */ +/** @typedef {(value: string, type: LogTypeEnum, args?: EXPECTED_ANY[]) => void} LoggingFunction */ /** * @typedef {object} LoggerConsole - * @property {function(): void} clear - * @property {function(): void} trace + * @property {() => void} clear + * @property {() => void} trace * @property {(...args: EXPECTED_ANY[]) => void} info * @property {(...args: EXPECTED_ANY[]) => void} log * @property {(...args: EXPECTED_ANY[]) => void} warn diff --git a/lib/node/nodeConsole.js b/lib/node/nodeConsole.js index 8b157c4d1..3a2307bbd 100644 --- a/lib/node/nodeConsole.js +++ b/lib/node/nodeConsole.js @@ -69,7 +69,7 @@ module.exports = ({ colors, appendOnly, stream }) => { * @param {string} prefix prefix * @param {string} colorPrefix color prefix * @param {string} colorSuffix color suffix - * @returns {(function(...EXPECTED_ANY[]): void)} function to write with colors + * @returns {(...args: EXPECTED_ANY[]) => void} function to write with colors */ const writeColored = (prefix, colorPrefix, colorSuffix) => diff --git a/lib/optimize/AggressiveSplittingPlugin.js b/lib/optimize/AggressiveSplittingPlugin.js index f17ec2529..fa08420b1 100644 --- a/lib/optimize/AggressiveSplittingPlugin.js +++ b/lib/optimize/AggressiveSplittingPlugin.js @@ -44,7 +44,7 @@ const moveModuleBetween = (chunkGraph, oldChunk, newChunk) => module => { /** * @param {ChunkGraph} chunkGraph the chunk graph * @param {Chunk} chunk the chunk - * @returns {function(Module): boolean} filter for entry module + * @returns {(module: Module) => boolean} filter for entry module */ const isNotAEntryModule = (chunkGraph, chunk) => module => !chunkGraph.isEntryModuleInChunk(module, chunk); diff --git a/lib/optimize/ConcatenatedModule.js b/lib/optimize/ConcatenatedModule.js index 8055859ac..13fbfba99 100644 --- a/lib/optimize/ConcatenatedModule.js +++ b/lib/optimize/ConcatenatedModule.js @@ -60,6 +60,7 @@ const { /** @typedef {import("../DependencyTemplate").DependencyTemplateContext} DependencyTemplateContext */ /** @typedef {import("../DependencyTemplates")} DependencyTemplates */ /** @typedef {import("../ExportsInfo").ExportInfo} ExportInfo */ +/** @typedef {import("../Module").BuildCallback} BuildCallback */ /** @typedef {import("../Module").BuildInfo} BuildInfo */ /** @typedef {import("../Module").BuildMeta} BuildMeta */ /** @typedef {import("../Module").CodeGenerationContext} CodeGenerationContext */ @@ -745,7 +746,7 @@ class ConcatenatedModule extends Module { * @param {Compilation} compilation the compilation * @param {ResolverWithOptions} resolver the resolver * @param {InputFileSystem} fs the file system - * @param {function(WebpackError=): void} callback callback function + * @param {BuildCallback} callback callback function * @returns {void} */ build(options, compilation, resolver, fs, callback) { @@ -1418,7 +1419,7 @@ class ConcatenatedModule extends Module { } // Map with all root exposed used exports - /** @type {Map} */ + /** @type {Map string>} */ const exportsMap = new Map(); // Set with all root exposed unused exports diff --git a/lib/optimize/InnerGraph.js b/lib/optimize/InnerGraph.js index 099c5eb18..b5c836fb8 100644 --- a/lib/optimize/InnerGraph.js +++ b/lib/optimize/InnerGraph.js @@ -9,6 +9,7 @@ const { UsageState } = require("../ExportsInfo"); /** @typedef {import("estree").Node} AnyNode */ /** @typedef {import("../Dependency")} Dependency */ +/** @typedef {import("../Dependency").GetConditionFn} GetConditionFn */ /** @typedef {import("../Module")} Module */ /** @typedef {import("../ModuleGraph")} ModuleGraph */ /** @typedef {import("../ModuleGraphConnection")} ModuleGraphConnection */ @@ -18,7 +19,7 @@ const { UsageState } = require("../ExportsInfo"); /** @typedef {import("../util/runtime").RuntimeSpec} RuntimeSpec */ /** @typedef {Map | true | undefined>} InnerGraph */ -/** @typedef {function(boolean | Set | undefined): void} UsageCallback */ +/** @typedef {(value: boolean | Set | undefined) => void} UsageCallback */ /** * @typedef {object} StateObject @@ -314,7 +315,7 @@ module.exports.isDependencyUsedByExports = ( * @param {Dependency} dependency the dependency * @param {Set | boolean | undefined} usedByExports usedByExports info * @param {ModuleGraph} moduleGraph moduleGraph - * @returns {null | false | function(ModuleGraphConnection, RuntimeSpec): ConnectionState} function to determine if the connection is active + * @returns {null | false | GetConditionFn} function to determine if the connection is active */ module.exports.getDependencyUsedByExportsCondition = ( dependency, diff --git a/lib/optimize/ModuleConcatenationPlugin.js b/lib/optimize/ModuleConcatenationPlugin.js index 1dc33af9d..1644bd0b6 100644 --- a/lib/optimize/ModuleConcatenationPlugin.js +++ b/lib/optimize/ModuleConcatenationPlugin.js @@ -101,7 +101,7 @@ class ModuleConcatenationPlugin { /** * @param {Module} module the module - * @param {Module | function(RequestShortener): string} problem the problem + * @param {Module | ((requestShortener: RequestShortener) => string)} problem the problem * @returns {(requestShortener: RequestShortener) => string} the reason */ const formatBailoutWarning = (module, problem) => requestShortener => { @@ -543,11 +543,11 @@ class ModuleConcatenationPlugin { * @param {RuntimeSpec} activeRuntime the runtime scope of the root module * @param {Set} possibleModules modules that are candidates * @param {Set} candidates list of potential candidates (will be added to) - * @param {Map} failureCache cache for problematic modules to be more performant + * @param {Map string)>} failureCache cache for problematic modules to be more performant * @param {ChunkGraph} chunkGraph the chunk graph * @param {boolean} avoidMutateOnFailure avoid mutating the config when adding fails * @param {Statistics} statistics gathering metrics - * @returns {null | Module | function(RequestShortener): string} the problematic module + * @returns {null | Module | ((requestShortener: RequestShortener) => string)} the problematic module */ _tryToAdd( compilation, @@ -846,6 +846,8 @@ class ModuleConcatenationPlugin { } } +/** @typedef {Module | ((requestShortener: RequestShortener) => string)} Problem */ + class ConcatConfiguration { /** * @param {Module} rootModule the root module @@ -857,7 +859,7 @@ class ConcatConfiguration { /** @type {Set} */ this.modules = new Set(); this.modules.add(rootModule); - /** @type {Map} */ + /** @type {Map} */ this.warnings = new Map(); } @@ -882,14 +884,14 @@ class ConcatConfiguration { /** * @param {Module} module the module - * @param {Module | function(RequestShortener): string} problem the problem + * @param {Problem} problem the problem */ addWarning(module, problem) { this.warnings.set(module, problem); } /** - * @returns {Map} warnings + * @returns {Map} warnings */ getWarningsSorted() { return new Map( diff --git a/lib/optimize/RealContentHashPlugin.js b/lib/optimize/RealContentHashPlugin.js index 8b0ab0565..c62e2c07f 100644 --- a/lib/optimize/RealContentHashPlugin.js +++ b/lib/optimize/RealContentHashPlugin.js @@ -38,7 +38,7 @@ const addToList = (itemOrItems, list) => { /** * @template T * @param {T[]} input list - * @param {function(T): Buffer} fn map function + * @param {(item: T) => Buffer} fn map function * @returns {Buffer[]} buffers without duplicates */ const mapAndDeduplicateBuffers = (input, fn) => { diff --git a/lib/optimize/SplitChunksPlugin.js b/lib/optimize/SplitChunksPlugin.js index 6b58f67f6..7772e0a23 100644 --- a/lib/optimize/SplitChunksPlugin.js +++ b/lib/optimize/SplitChunksPlugin.js @@ -167,7 +167,7 @@ const MinMaxSizeWarning = require("./MinMaxSizeWarning"); const defaultGetName = /** @type {GetName} */ (() => {}); const deterministicGroupingForModules = - /** @type {function(DeterministicGroupingOptionsForModule): DeterministicGroupingGroupedItemsForModule[]} */ + /** @type {(options: DeterministicGroupingOptionsForModule) => DeterministicGroupingGroupedItemsForModule[]} */ (deterministicGrouping); /** @type {WeakMap} */ @@ -451,7 +451,7 @@ const normalizeCacheGroups = (cacheGroups, defaultSizeTypes) => { return cacheGroups; } if (typeof cacheGroups === "object" && cacheGroups !== null) { - /** @type {(function(Module, CacheGroupsContext, CacheGroupSource[]): void)[]} */ + /** @type {((module: Module, context: CacheGroupsContext, results: CacheGroupSource[]) => void)[]} */ const handlers = []; for (const key of Object.keys(cacheGroups)) { const option = cacheGroups[key]; diff --git a/lib/rules/RuleSetCompiler.js b/lib/rules/RuleSetCompiler.js index 5e32e1339..862686dc3 100644 --- a/lib/rules/RuleSetCompiler.js +++ b/lib/rules/RuleSetCompiler.js @@ -10,7 +10,7 @@ const { SyncHook } = require("tapable"); /** @typedef {import("../../declarations/WebpackOptions").RuleSetRule} RuleSetRule */ /** @typedef {import("../../declarations/WebpackOptions").RuleSetRules} RuleSetRules */ -/** @typedef {function(string | EffectData): boolean} RuleConditionFunction */ +/** @typedef {(value: string | EffectData) => boolean} RuleConditionFunction */ /** * @typedef {object} RuleCondition @@ -32,7 +32,7 @@ const { SyncHook } = require("tapable"); /** * @typedef {object} CompiledRule * @property {RuleCondition[]} conditions - * @property {(Effect|function(EffectData): Effect[])[]} effects + * @property {(Effect | ((effectData: EffectData) => Effect[]))[]} effects * @property {CompiledRule[]=} rules * @property {CompiledRule[]=} oneOf */ @@ -46,10 +46,10 @@ const { SyncHook } = require("tapable"); /** * @typedef {object} RuleSet * @property {Map} references map of references in the rule set (may grow over time) - * @property {function(EffectData): Effect[]} exec execute the rule set + * @property {(effectData: EffectData) => Effect[]} exec execute the rule set */ -/** @typedef {{ apply: (function(RuleSetCompiler): void) }} RuleSetPlugin */ +/** @typedef {{ apply: (ruleSetCompiler: RuleSetCompiler) => void }} RuleSetPlugin */ class RuleSetCompiler { /** diff --git a/lib/rules/UseEffectRulePlugin.js b/lib/rules/UseEffectRulePlugin.js index 56f2423de..023ff476e 100644 --- a/lib/rules/UseEffectRulePlugin.js +++ b/lib/rules/UseEffectRulePlugin.js @@ -52,7 +52,7 @@ class UseEffectRulePlugin { * @param {string} path options path * @param {string} defaultIdent default ident when none is provided * @param {object} item user provided use value - * @returns {Effect|function(any): Effect[]} effect + * @returns {Effect | ((value: TODO) => Effect[])} effect */ const useToEffect = (path, defaultIdent, item) => { if (typeof item === "function") { @@ -104,7 +104,7 @@ class UseEffectRulePlugin { /** * @param {string} path options path - * @param {any} items user provided use value + * @param {TODO} items user provided use value * @returns {Effect[]} effects */ const useToEffectsWithoutIdent = (path, items) => { @@ -120,8 +120,8 @@ class UseEffectRulePlugin { /** * @param {string} path current path - * @param {any} items user provided use value - * @returns {(Effect|function(any): Effect[])[]} effects + * @param {TODO} items user provided use value + * @returns {(Effect | ((value: TODO) => Effect[]))[]} effects */ const useToEffects = (path, items) => { if (Array.isArray(items)) { diff --git a/lib/runtime/GetChunkFilenameRuntimeModule.js b/lib/runtime/GetChunkFilenameRuntimeModule.js index 3d9b26599..1b42f5c64 100644 --- a/lib/runtime/GetChunkFilenameRuntimeModule.js +++ b/lib/runtime/GetChunkFilenameRuntimeModule.js @@ -20,7 +20,7 @@ class GetChunkFilenameRuntimeModule extends RuntimeModule { * @param {string} contentType the contentType to use the content hash for * @param {string} name kind of filename * @param {string} global function name to be assigned - * @param {function(Chunk): TemplatePath | false} getFilenameForChunk functor to get the filename or function + * @param {(chunk: Chunk) => TemplatePath | false} getFilenameForChunk functor to get the filename or function * @param {boolean} allChunks when false, only async chunks are included */ constructor(contentType, name, global, getFilenameForChunk, allChunks) { @@ -138,7 +138,7 @@ class GetChunkFilenameRuntimeModule extends RuntimeModule { }; /** * @param {string} value string - * @returns {function(number): string} string to put in quotes with length + * @returns {(length: number) => string} string to put in quotes with length */ const unquotedStringifyWithLength = value => length => unquotedStringify(`${value}`.slice(0, length)); @@ -191,7 +191,7 @@ class GetChunkFilenameRuntimeModule extends RuntimeModule { } /** - * @param {function(Chunk): string | number} fn function from chunk to value + * @param {(chunk: Chunk) => string | number} fn function from chunk to value * @returns {string} code with static mapping of results of fn */ const createMap = fn => { @@ -225,14 +225,14 @@ class GetChunkFilenameRuntimeModule extends RuntimeModule { }; /** - * @param {function(Chunk): string | number} fn function from chunk to value + * @param {(chunk: Chunk) => string | number} fn function from chunk to value * @returns {string} code with static mapping of results of fn for including in quoted string */ const mapExpr = fn => `" + ${createMap(fn)} + "`; /** - * @param {function(Chunk): string | number} fn function from chunk to value - * @returns {function(number): string} function which generates code with static mapping of results of fn for including in quoted string for specific length + * @param {(chunk: Chunk) => string | number} fn function from chunk to value + * @returns {(length: number) => string} function which generates code with static mapping of results of fn for including in quoted string for specific length */ const mapExprWithLength = fn => length => `" + ${createMap(c => `${fn(c)}`.slice(0, length))} + "`; diff --git a/lib/schemes/HttpUriPlugin.js b/lib/schemes/HttpUriPlugin.js index 510b189f2..d3cb2f12a 100644 --- a/lib/schemes/HttpUriPlugin.js +++ b/lib/schemes/HttpUriPlugin.js @@ -32,7 +32,7 @@ const getHttps = memoize(() => require("https")); /** * @param {typeof import("http") | typeof import("https")} request request * @param {string | { toString: () => string } | undefined} proxy proxy - * @returns {function(URL, RequestOptions, function(IncomingMessage): void): EventEmitter} fn + * @returns {(url: URL, requestOptions: RequestOptions, callback: (incomingMessage: IncomingMessage) => void) => EventEmitter} fn */ const proxyFetch = (request, proxy) => (url, options, callback) => { const eventEmitter = new EventEmitter(); @@ -255,8 +255,18 @@ class Lockfile { /** * @template R - * @param {function(function(Error | null, R=): void): void} fn function - * @returns {function(function(Error | null, R=): void): void} cached function + * @typedef {(err: Error | null, result?: R) => void} FnWithoutKeyCallback + */ + +/** + * @template R + * @typedef {(callback: FnWithoutKeyCallback) => void} FnWithoutKey + */ + +/** + * @template R + * @param {FnWithoutKey} fn function + * @returns {FnWithoutKey} cached function */ const cachedWithoutKey = fn => { let inFlight = false; @@ -264,7 +274,7 @@ const cachedWithoutKey = fn => { let cachedError; /** @type {R | undefined} */ let cachedResult; - /** @type {(function(Error| null, R=): void)[] | undefined} */ + /** @type {FnWithoutKeyCallback[] | undefined} */ let cachedCallbacks; return callback => { if (inFlight) { @@ -286,23 +296,34 @@ const cachedWithoutKey = fn => { }; }; +/** + * @template R + * @typedef {(err: Error | null, result?: R) => void} FnWithKeyCallback + */ + /** * @template T * @template R - * @param {function(T, function(Error | null, R=): void): void} fn function - * @param {function(T, function(Error | null, R=): void): void=} forceFn function for the second try - * @returns {(function(T, function(Error | null, R=): void): void) & { force: function(T, function(Error | null, R=): void): void }} cached function + * @typedef {(item: T, callback: FnWithKeyCallback) => void} FnWithKey + */ + +/** + * @template T + * @template R + * @param {FnWithKey} fn function + * @param {FnWithKey=} forceFn function for the second try + * @returns {(FnWithKey) & { force: FnWithKey }} cached function */ const cachedWithKey = (fn, forceFn = fn) => { /** * @template R - * @typedef {{ result?: R, error?: Error, callbacks?: (function(Error | null, R=): void)[], force?: true }} CacheEntry + * @typedef {{ result?: R, error?: Error, callbacks?: FnWithKeyCallback[], force?: true }} CacheEntry */ /** @type {Map>} */ const cache = new Map(); /** * @param {T} arg arg - * @param {function(Error | null, R=): void} callback callback + * @param {FnWithKeyCallback} callback callback * @returns {void} */ const resultFn = (arg, callback) => { @@ -333,7 +354,7 @@ const cachedWithKey = (fn, forceFn = fn) => { }; /** * @param {T} arg arg - * @param {function(Error | null, R=): void} callback callback + * @param {FnWithKeyCallback} callback callback * @returns {void} */ resultFn.force = (arg, callback) => { @@ -487,7 +508,7 @@ class HttpUriPlugin { const getLockfile = cachedWithoutKey( /** - * @param {function(Error | null, Lockfile=): void} callback callback + * @param {(err: Error | null, lockfile?: Lockfile) => void} callback callback * @returns {void} */ callback => { @@ -581,7 +602,7 @@ class HttpUriPlugin { * @param {Lockfile} lockfile lockfile * @param {string} url url * @param {ResolveContentResult} result result - * @param {function(Error | null, ResolveContentResult=): void} callback callback + * @param {(err: Error | null, result?: ResolveContentResult) => void} callback callback * @returns {void} */ const storeResult = (lockfile, url, result, callback) => { @@ -608,7 +629,7 @@ class HttpUriPlugin { /** * @param {string} url URL * @param {string | null} integrity integrity - * @param {function(Error | null, ResolveContentResult=): void} callback callback + * @param {(err: Error | null, resolveContentResult?: ResolveContentResult) => void} callback callback */ const resolveContent = (url, integrity, callback) => { /** @@ -654,7 +675,7 @@ class HttpUriPlugin { /** * @param {string} url URL * @param {FetchResult | RedirectFetchResult | undefined} cachedResult result from cache - * @param {function(Error | null, FetchResult=): void} callback callback + * @param {(err: Error | null, fetchResult?: FetchResult) => void} callback callback * @returns {void} */ const fetchContentRaw = (url, cachedResult, callback) => { @@ -826,7 +847,7 @@ class HttpUriPlugin { const fetchContent = cachedWithKey( /** * @param {string} url URL - * @param {function(Error | null, { validUntil: number, etag?: string, entry: LockfileEntry, content: Buffer, fresh: boolean } | { validUntil: number, etag?: string, location: string, fresh: boolean }=): void} callback callback + * @param {(err: Error | null, result?: { validUntil: number, etag?: string, entry: LockfileEntry, content: Buffer, fresh: boolean } | { validUntil: number, etag?: string, location: string, fresh: boolean }) => void} callback callback * @returns {void} */ (url, callback) => { @@ -864,7 +885,7 @@ class HttpUriPlugin { const getInfo = cachedWithKey( /** * @param {string} url the url - * @param {function(Error | null, Info=): void} callback callback + * @param {(err: Error | null, info?: Info) => void} callback callback * @returns {void} */ // eslint-disable-next-line no-loop-func @@ -1113,7 +1134,7 @@ Run build with un-frozen lockfile to automatically fix lockfile.` /** * @param {URL} url url * @param {ResourceDataWithData} resourceData resource data - * @param {function(Error | null, true | void): void} callback callback + * @param {(err: Error | null, result: true | void) => void} callback callback */ const respondWithUrlModule = (url, resourceData, callback) => { getInfo(url.href, (err, _result) => { diff --git a/lib/serialization/FileMiddleware.js b/lib/serialization/FileMiddleware.js index 671ea1234..be9772866 100644 --- a/lib/serialization/FileMiddleware.js +++ b/lib/serialization/FileMiddleware.js @@ -64,7 +64,7 @@ const hashForName = (buffers, hashFunction) => { const COMPRESSION_CHUNK_SIZE = 100 * 1024 * 1024; const DECOMPRESSION_CHUNK_SIZE = 100 * 1024 * 1024; -/** @type {function(Buffer, number, number): void} */ +/** @type {(buffer: Buffer, value: number, offset: number) => void} */ const writeUInt64LE = Buffer.prototype.writeBigUInt64LE ? (buf, value, offset) => { buf.writeBigUInt64LE(BigInt(value), offset); @@ -76,7 +76,7 @@ const writeUInt64LE = Buffer.prototype.writeBigUInt64LE buf.writeUInt32LE(high, offset + 4); }; -/** @type {function(Buffer, number): void} */ +/** @type {(buffer: Buffer, offset: number) => void} */ const readUInt64LE = Buffer.prototype.readBigUInt64LE ? (buf, offset) => Number(buf.readBigUInt64LE(offset)) : (buf, offset) => { @@ -98,7 +98,7 @@ const readUInt64LE = Buffer.prototype.readBigUInt64LE * @param {FileMiddleware} middleware this * @param {BufferSerializableType[] | Promise} data data to be serialized * @param {string | boolean} name file base name - * @param {function(string | false, Buffer[], number): Promise} writeFile writes a file + * @param {(name: string | false, buffers: Buffer[], size: number) => Promise} writeFile writes a file * @param {string | Hash} hashFunction hash function to use * @returns {Promise} resulting file pointer and promise */ @@ -248,7 +248,7 @@ const serialize = async ( /** * @param {FileMiddleware} middleware this * @param {string | false} name filename - * @param {function(string | false): Promise} readFile read content of a file + * @param {(name: string | false) => Promise} readFile read content of a file * @returns {Promise} deserialized data */ const deserialize = async (middleware, name, readFile) => { diff --git a/lib/serialization/ObjectMiddleware.js b/lib/serialization/ObjectMiddleware.js index d55834dd2..453693a66 100644 --- a/lib/serialization/ObjectMiddleware.js +++ b/lib/serialization/ObjectMiddleware.js @@ -61,24 +61,24 @@ Technically any value can be used. /** * @typedef {object} ObjectSerializerContext - * @property {function(any): void} write - * @property {function(any): void} setCircularReference - * @property {function(): ObjectSerializerSnapshot} snapshot - * @property {function(ObjectSerializerSnapshot): void} rollback - * @property {(function(any): void)=} writeLazy - * @property {(function(any, object=): (() => Promise | any))=} writeSeparate + * @property {(value: any) => void} write + * @property {(value: any) => void} setCircularReference + * @property {() => ObjectSerializerSnapshot} snapshot + * @property {(snapshot: ObjectSerializerSnapshot) => void} rollback + * @property {((item: any) => void)=} writeLazy + * @property {((item: any, obj?: object) => (() => Promise | any))=} writeSeparate */ /** * @typedef {object} ObjectDeserializerContext - * @property {function(): any} read - * @property {function(any): void} setCircularReference + * @property {() => any} read + * @property {(value: any) => void} setCircularReference */ /** * @typedef {object} ObjectSerializer - * @property {function(any, ObjectSerializerContext): void} serialize - * @property {function(ObjectDeserializerContext): any} deserialize + * @property {(value: any, context: ObjectSerializerContext) => void} serialize + * @property {(context: ObjectDeserializerContext) => any} deserialize */ /** @@ -201,7 +201,7 @@ const loaders = new Map(); */ class ObjectMiddleware extends SerializerMiddleware { /** - * @param {function(ObjectSerializerContext | ObjectDeserializerContext): void} extendContext context extensions + * @param {(context: ObjectSerializerContext | ObjectDeserializerContext) => void} extendContext context extensions * @param {string | Hash} hashFunction hash function to use */ constructor(extendContext, hashFunction = "md4") { @@ -212,7 +212,7 @@ class ObjectMiddleware extends SerializerMiddleware { /** * @param {RegExp} regExp RegExp for which the request is tested - * @param {function(string): boolean} loader loader to load the request, returns true when successful + * @param {(request: string) => boolean} loader loader to load the request, returns true when successful * @returns {void} */ static registerLoader(regExp, loader) { diff --git a/lib/serialization/SerializerMiddleware.js b/lib/serialization/SerializerMiddleware.js index 032a4a670..656de0469 100644 --- a/lib/serialization/SerializerMiddleware.js +++ b/lib/serialization/SerializerMiddleware.js @@ -13,7 +13,7 @@ const LAZY_SERIALIZED_VALUE = Symbol("lazy serialization data"); /** * @template LazyResult - * @typedef {function(): LazyResult | Promise} InternalLazyFunction + * @typedef {() => LazyResult | Promise} InternalLazyFunction */ /** @typedef {Record} LazyOptions */ @@ -115,7 +115,7 @@ class SerializerMiddleware { /** * @template LazyResult, R * @param {LazyFunction} lazy lazy function - * @param {function(LazyResult): Promise | R} serialize serialize function + * @param {(lazyResult: LazyResult) => Promise | R} serialize serialize function * @returns {LazyFunction} new lazy */ static serializeLazy(lazy, serialize) { @@ -143,7 +143,7 @@ class SerializerMiddleware { /** * @template LazyResult, R * @param {LazyFunction} lazy lazy function - * @param {function(LazyResult): Promise | R} deserialize deserialize function + * @param {(lazyResult: LazyResult) => Promise | R} deserialize deserialize function * @returns {LazyFunction} new lazy */ static deserializeLazy(lazy, deserialize) { diff --git a/lib/sharing/ConsumeSharedModule.js b/lib/sharing/ConsumeSharedModule.js index f9a745e31..20f8fda1e 100644 --- a/lib/sharing/ConsumeSharedModule.js +++ b/lib/sharing/ConsumeSharedModule.js @@ -22,9 +22,11 @@ const ConsumeSharedFallbackDependency = require("./ConsumeSharedFallbackDependen /** @typedef {import("../ChunkGroup")} ChunkGroup */ /** @typedef {import("../Compilation")} Compilation */ /** @typedef {import("../Dependency").UpdateHashContext} UpdateHashContext */ +/** @typedef {import("../Module").BuildCallback} BuildCallback */ /** @typedef {import("../Module").CodeGenerationContext} CodeGenerationContext */ /** @typedef {import("../Module").CodeGenerationResult} CodeGenerationResult */ /** @typedef {import("../Module").LibIdentOptions} LibIdentOptions */ +/** @typedef {import("../Module").NeedBuildCallback} NeedBuildCallback */ /** @typedef {import("../Module").NeedBuildContext} NeedBuildContext */ /** @typedef {import("../Module").SourceTypes} SourceTypes */ /** @typedef {import("../RequestShortener")} RequestShortener */ @@ -115,7 +117,7 @@ class ConsumeSharedModule extends Module { /** * @param {NeedBuildContext} context context info - * @param {function((WebpackError | null)=, boolean=): void} callback callback function, returns true, if the module needs a rebuild + * @param {NeedBuildCallback} callback callback function, returns true, if the module needs a rebuild * @returns {void} */ needBuild(context, callback) { @@ -127,7 +129,7 @@ class ConsumeSharedModule extends Module { * @param {Compilation} compilation the compilation * @param {ResolverWithOptions} resolver the resolver * @param {InputFileSystem} fs the file system - * @param {function(WebpackError=): void} callback callback function + * @param {BuildCallback} callback callback function * @returns {void} */ build(options, compilation, resolver, fs, callback) { diff --git a/lib/sharing/ProvideSharedModule.js b/lib/sharing/ProvideSharedModule.js index a0c1d0fd8..1e67f79f4 100644 --- a/lib/sharing/ProvideSharedModule.js +++ b/lib/sharing/ProvideSharedModule.js @@ -18,9 +18,11 @@ const ProvideForSharedDependency = require("./ProvideForSharedDependency"); /** @typedef {import("../ChunkGraph")} ChunkGraph */ /** @typedef {import("../ChunkGroup")} ChunkGroup */ /** @typedef {import("../Compilation")} Compilation */ +/** @typedef {import("../Module").BuildCallback} BuildCallback */ /** @typedef {import("../Module").CodeGenerationContext} CodeGenerationContext */ /** @typedef {import("../Module").CodeGenerationResult} CodeGenerationResult */ /** @typedef {import("../Module").LibIdentOptions} LibIdentOptions */ +/** @typedef {import("../Module").NeedBuildCallback} NeedBuildCallback */ /** @typedef {import("../Module").NeedBuildContext} NeedBuildContext */ /** @typedef {import("../Module").SourceTypes} SourceTypes */ /** @typedef {import("../RequestShortener")} RequestShortener */ @@ -77,7 +79,7 @@ class ProvideSharedModule extends Module { /** * @param {NeedBuildContext} context context info - * @param {function((WebpackError | null)=, boolean=): void} callback callback function, returns true, if the module needs a rebuild + * @param {NeedBuildCallback} callback callback function, returns true, if the module needs a rebuild * @returns {void} */ needBuild(context, callback) { @@ -89,7 +91,7 @@ class ProvideSharedModule extends Module { * @param {Compilation} compilation the compilation * @param {ResolverWithOptions} resolver the resolver * @param {InputFileSystem} fs the file system - * @param {function(WebpackError=): void} callback callback function + * @param {BuildCallback} callback callback function * @returns {void} */ build(options, compilation, resolver, fs, callback) { diff --git a/lib/sharing/ProvideSharedModuleFactory.js b/lib/sharing/ProvideSharedModuleFactory.js index d5bcc829f..b10b8f399 100644 --- a/lib/sharing/ProvideSharedModuleFactory.js +++ b/lib/sharing/ProvideSharedModuleFactory.js @@ -8,18 +8,20 @@ const ModuleFactory = require("../ModuleFactory"); const ProvideSharedModule = require("./ProvideSharedModule"); +/** @typedef {import("../ModuleFactory").ModuleFactoryCallback} ModuleFactoryCallback */ /** @typedef {import("../ModuleFactory").ModuleFactoryCreateData} ModuleFactoryCreateData */ -/** @typedef {import("../ModuleFactory").ModuleFactoryResult} ModuleFactoryResult */ /** @typedef {import("./ProvideSharedDependency")} ProvideSharedDependency */ class ProvideSharedModuleFactory extends ModuleFactory { /** * @param {ModuleFactoryCreateData} data data object - * @param {function((Error | null)=, ModuleFactoryResult=): void} callback callback + * @param {ModuleFactoryCallback} callback callback * @returns {void} */ create(data, callback) { - const dep = /** @type {ProvideSharedDependency} */ (data.dependencies[0]); + const dep = + /** @type {ProvideSharedDependency} */ + (data.dependencies[0]); callback(null, { module: new ProvideSharedModule( dep.shareScope, diff --git a/lib/sharing/utils.js b/lib/sharing/utils.js index bdeba0045..037fcb176 100644 --- a/lib/sharing/utils.js +++ b/lib/sharing/utils.js @@ -326,8 +326,8 @@ module.exports.normalizeVersion = normalizeVersion; * @param {InputFileSystem} fs file system * @param {string} directory directory to start looking into * @param {string[]} descriptionFiles possible description filenames - * @param {function((Error | null)=, DescriptionFile=, string[]=): void} callback callback - * @param {function(DescriptionFile=): boolean} satisfiesDescriptionFileData file data compliance check + * @param {(err?: Error | null, descriptionFile?: DescriptionFile, paths?: string[]) => void} callback callback + * @param {(descriptionFile?: DescriptionFile) => boolean} satisfiesDescriptionFileData file data compliance check * @param {Set} checkedFilePaths set of file paths that have been checked */ const getDescriptionFile = ( diff --git a/lib/stats/DefaultStatsFactoryPlugin.js b/lib/stats/DefaultStatsFactoryPlugin.js index 52c8bd260..1adb83eb0 100644 --- a/lib/stats/DefaultStatsFactoryPlugin.js +++ b/lib/stats/DefaultStatsFactoryPlugin.js @@ -328,7 +328,7 @@ const { makePathsRelative, parseResource } = require("../util/identifier"); * @template T * @template I * @param {Iterable} items items to select from - * @param {function(T): Iterable} selector selector function to select values from item + * @param {(item: T) => Iterable} selector selector function to select values from item * @returns {I[]} array of values */ const uniqueArray = (items, selector) => { @@ -346,7 +346,7 @@ const uniqueArray = (items, selector) => { * @template T * @template I * @param {Iterable} items items to select from - * @param {function(T): Iterable} selector selector function to select values from item + * @param {(item: T) => Iterable} selector selector function to select values from item * @param {Comparator} comparator comparator function * @returns {I[]} array of values */ @@ -375,7 +375,7 @@ const mapObject = (obj, fn) => { /** * @param {Compilation} compilation the compilation - * @param {function(Compilation, string): any[]} getItems get items + * @param {(compilation: Compilation, name: string) => any[]} getItems get items * @returns {number} total number */ const countWithChildren = (compilation, getItems) => { @@ -2152,7 +2152,7 @@ const ASSETS_GROUPERS = { /** @typedef {Record[], context: StatsFactoryContext, options: NormalizedStatsOptions) => void>} ModulesGroupers */ -/** @type {function("module" | "chunk" | "root-of-chunk" | "nested"): ModulesGroupers} */ +/** @type {(type: "module" | "chunk" | "root-of-chunk" | "nested") => ModulesGroupers} */ const MODULES_GROUPERS = type => ({ _: (groupConfigs, context, options) => { /** @@ -2369,7 +2369,7 @@ const sortOrderRegular = field => { /** * @template T * @param {string} field field name - * @returns {function(T, T): 0 | 1 | -1} comparators + * @returns {(a: T, b: T) => 0 | 1 | -1} comparators */ const sortByField = field => { if (!field) { @@ -2436,7 +2436,7 @@ const RESULT_SORTERS = { /** * @param {Record>} config the config see above * @param {NormalizedStatsOptions} options stats options - * @param {function(string, Function): void} fn handler function called for every active line in config + * @param {(hookFor: string, fn: Function) => void} fn handler function called for every active line in config * @returns {void} */ const iterateConfig = (config, options, fn) => { diff --git a/lib/stats/DefaultStatsPresetPlugin.js b/lib/stats/DefaultStatsPresetPlugin.js index 70e56b8cb..99675ace2 100644 --- a/lib/stats/DefaultStatsPresetPlugin.js +++ b/lib/stats/DefaultStatsPresetPlugin.js @@ -274,8 +274,8 @@ const DEFAULTS = { }; /** - * @param {string | ({ test: function(string): boolean }) | (function(string): boolean) | boolean} item item to normalize - * @returns {(function(string): boolean) | undefined} normalize fn + * @param {string | ({ test: (value: string) => boolean }) | ((value: string) => boolean) | boolean} item item to normalize + * @returns {((value: string) => boolean) | undefined} normalize fn */ const normalizeFilter = item => { if (typeof item === "string") { @@ -295,7 +295,7 @@ const normalizeFilter = item => { } }; -/** @type {Record} */ +/** @type {Record any[]>} */ const NORMALIZER = { excludeModules: value => { if (!Array.isArray(value)) { diff --git a/lib/stats/DefaultStatsPrinterPlugin.js b/lib/stats/DefaultStatsPrinterPlugin.js index 47b05be4b..71a7882c3 100644 --- a/lib/stats/DefaultStatsPrinterPlugin.js +++ b/lib/stats/DefaultStatsPrinterPlugin.js @@ -79,7 +79,7 @@ const getModuleName = name => { /** * @param {string} str string - * @param {function(string): string} fn function to apply to each line + * @param {(item: string) => string} fn function to apply to each line * @returns {string} joined string */ const mapLines = (str, fn) => str.split("\n").map(fn).join("\n"); @@ -726,7 +726,7 @@ const MODULE_TRACE_DEPENDENCY_PRINTERS = { "moduleTraceDependency.loc": loc => loc }; -/** @type {Record} */ +/** @type {Record string)>} */ const ITEM_NAMES = { "compilation.assets[]": "asset", "compilation.modules[]": "module", @@ -969,7 +969,7 @@ const itemsJoinComma = items => items.filter(Boolean).join(", "); /** @type {SimpleItemsJoiner} */ const itemsJoinCommaBrackets = items => items.length > 0 ? `(${items.filter(Boolean).join(", ")})` : undefined; -/** @type {function(string): SimpleItemsJoiner} */ +/** @type {(item: string) => SimpleItemsJoiner} */ const itemsJoinCommaBracketsWithName = name => items => items.length > 0 ? `(${name}: ${items.filter(Boolean).join(", ")})` @@ -1300,7 +1300,7 @@ const AVAILABLE_COLORS = { magenta: "\u001B[1m\u001B[35m" }; -/** @type {Record & StatsPrinterContext, ...any): string>} */ +/** @type {Record & StatsPrinterContext, ...args: any) => string>} */ const AVAILABLE_FORMATS = { formatChunkId: (id, { yellow }, direction) => { switch (direction) { @@ -1391,7 +1391,7 @@ const AVAILABLE_FORMATS = { } }; -/** @typedef {function(string): string} ResultModifierFn */ +/** @typedef {(result: string) => string} ResultModifierFn */ /** @type {Record} */ const RESULT_MODIFIER = { "module.modules": result => indent(result, "| ") diff --git a/lib/stats/StatsFactory.js b/lib/stats/StatsFactory.js index b668369ea..89654112b 100644 --- a/lib/stats/StatsFactory.js +++ b/lib/stats/StatsFactory.js @@ -21,14 +21,14 @@ const smartGrouping = require("../util/smartGrouping"); /** * @typedef {object} KnownStatsFactoryContext * @property {string} type - * @property {function(string): string} makePathsRelative + * @property {(path: string) => string} makePathsRelative * @property {Compilation} compilation * @property {Set} rootModules - * @property {Map} compilationFileToChunks - * @property {Map} compilationAuxiliaryFileToChunks + * @property {Map} compilationFileToChunks + * @property {Map} compilationAuxiliaryFileToChunks * @property {RuntimeSpec} runtime - * @property {function(Compilation): WebpackError[]} cachedGetErrors - * @property {function(Compilation): WebpackError[]} cachedGetWarnings + * @property {(compilation: Compilation) => WebpackError[]} cachedGetErrors + * @property {(compilation: Compilation) => WebpackError[]} cachedGetWarnings */ /** @typedef {Record & KnownStatsFactoryContext} StatsFactoryContext */ @@ -128,7 +128,7 @@ class StatsFactory { * @param {HM} hookMap hook map * @param {Caches} cache cache * @param {string} type type - * @param {function(H): R | void} fn fn + * @param {(hook: H) => R | void} fn fn * @returns {R | void} hook * @private */ @@ -146,7 +146,7 @@ class StatsFactory { * @param {Caches} cache cache * @param {string} type type * @param {FactoryData} data data - * @param {function(H, FactoryData): FactoryData} fn fn + * @param {(hook: H, factoryData: FactoryData) => FactoryData} fn fn * @returns {FactoryData} data * @private */ @@ -165,7 +165,7 @@ class StatsFactory { * @param {Caches} cache cache * @param {string} type type * @param {Array} items items - * @param {function(H, R, number, number): R | undefined} fn fn + * @param {(hook: H, item: R, idx: number, i: number) => R | undefined} fn fn * @param {boolean} forceClone force clone * @returns {R[]} result for each level * @private diff --git a/lib/stats/StatsPrinter.js b/lib/stats/StatsPrinter.js index f5a105a63..068cd8a14 100644 --- a/lib/stats/StatsPrinter.js +++ b/lib/stats/StatsPrinter.js @@ -147,7 +147,7 @@ class StatsPrinter { * @template {H extends import("tapable").Hook ? R : never} R * @param {HM} hookMap hook map * @param {string} type type - * @param {function(H): R | void} fn fn + * @param {(hooK: H) => R | void} fn fn * @returns {R | void} hook */ _forEachLevel(hookMap, type, fn) { @@ -165,7 +165,7 @@ class StatsPrinter { * @param {HM} hookMap hook map * @param {string} type type * @param {string} data data - * @param {function(H, string): string} fn fn + * @param {(hook: H, data: string) => string} fn fn * @returns {string} result of `fn` */ _forEachLevelWaterfall(hookMap, type, data, fn) { diff --git a/lib/util/ArrayQueue.js b/lib/util/ArrayQueue.js index 522abf93d..80ded0c28 100644 --- a/lib/util/ArrayQueue.js +++ b/lib/util/ArrayQueue.js @@ -10,7 +10,7 @@ */ class ArrayQueue { /** - * @param {Iterable=} items The initial elements. + * @param {Iterable} [items] The initial elements. */ constructor(items) { /** diff --git a/lib/util/AsyncQueue.js b/lib/util/AsyncQueue.js index fb01d49e9..ab004693f 100644 --- a/lib/util/AsyncQueue.js +++ b/lib/util/AsyncQueue.js @@ -50,12 +50,12 @@ class AsyncQueueEntry { /** * @template T, K - * @typedef {function(T): K} getKey + * @typedef {(item: T) => K} getKey */ /** * @template T, R - * @typedef {function(T, Callback): void} Processor + * @typedef {(item: T, callback: Callback) => void} Processor */ /** diff --git a/lib/util/IterableHelpers.js b/lib/util/IterableHelpers.js index 73d02c667..b981eca88 100644 --- a/lib/util/IterableHelpers.js +++ b/lib/util/IterableHelpers.js @@ -19,7 +19,7 @@ const last = set => { /** * @template T * @param {Iterable} iterable iterable - * @param {function(T): boolean | null | undefined} filter predicate + * @param {(value: T) => boolean | null | undefined} filter predicate * @returns {boolean} true, if some items match the filter predicate */ const someInIterable = (iterable, filter) => { diff --git a/lib/util/LazyBucketSortedSet.js b/lib/util/LazyBucketSortedSet.js index 546901089..53ec13219 100644 --- a/lib/util/LazyBucketSortedSet.js +++ b/lib/util/LazyBucketSortedSet.js @@ -15,7 +15,7 @@ const SortableSet = require("./SortableSet"); /** * @template T - * @typedef {(function(T): any) | (function(any, any): number)} Arg + * @typedef {((value: T) => any) | ((value: any, value1: any) => number)} Arg */ /** @@ -32,9 +32,9 @@ const SortableSet = require("./SortableSet"); */ class LazyBucketSortedSet { /** - * @param {function(T): K} getKey function to get key from item - * @param {function(K, K): number} comparator comparator to sort keys - * @param {...Arg} args more pairs of getKey and comparator plus optional final comparator for the last layer + * @param {(item: T) => K} getKey function to get key from item + * @param {(a: K, b: K) => number} comparator comparator to sort keys + * @param {...Arg} args more pairs of getKey and comparator plus optional final comparator for the last layer */ constructor(getKey, comparator, ...args) { this._getKey = getKey; @@ -142,7 +142,7 @@ class LazyBucketSortedSet { /** * @param {T} item to be updated item - * @returns {function(true=): void} finish update + * @returns {(remove?: true) => void} finish update */ startUpdate(item) { if (this._unsortedItems.has(item)) { diff --git a/lib/util/LazySet.js b/lib/util/LazySet.js index 392b379da..1ab56167e 100644 --- a/lib/util/LazySet.js +++ b/lib/util/LazySet.js @@ -149,7 +149,7 @@ class LazySet { /** * @template K - * @param {function(T, T, Set): void} callbackFn function called for each entry + * @param {(value: T, value2: T, set: Set) => void} callbackFn function called for each entry * @param {K} thisArg this argument for the callbackFn * @returns {void} */ diff --git a/lib/util/MapHelpers.js b/lib/util/MapHelpers.js index 259f621d8..533436e23 100644 --- a/lib/util/MapHelpers.js +++ b/lib/util/MapHelpers.js @@ -13,7 +13,7 @@ * @template V * @param {Map} map The map object to check * @param {K} key The key to check - * @param {function(): V} computer function which will compute the value if it doesn't exist + * @param {() => V} computer function which will compute the value if it doesn't exist * @returns {V} The value from the map, or the computed value * @example * ```js diff --git a/lib/util/ParallelismFactorCalculator.js b/lib/util/ParallelismFactorCalculator.js index d7725b7bf..bfb9688f1 100644 --- a/lib/util/ParallelismFactorCalculator.js +++ b/lib/util/ParallelismFactorCalculator.js @@ -7,7 +7,7 @@ const binarySearchBounds = require("./binarySearchBounds"); -/** @typedef {function(number): void} Callback */ +/** @typedef {(value: number) => void} Callback */ class ParallelismFactorCalculator { constructor() { diff --git a/lib/util/Semaphore.js b/lib/util/Semaphore.js index 5277fedb6..66b9ad938 100644 --- a/lib/util/Semaphore.js +++ b/lib/util/Semaphore.js @@ -13,14 +13,14 @@ class Semaphore { */ constructor(available) { this.available = available; - /** @type {(function(): void)[]} */ + /** @type {(() => void)[]} */ this.waiters = []; /** @private */ this._continue = this._continue.bind(this); } /** - * @param {function(): void} callback function block to capture and run + * @param {() => void} callback function block to capture and run * @returns {void} */ acquire(callback) { @@ -42,7 +42,7 @@ class Semaphore { _continue() { if (this.available > 0 && this.waiters.length > 0) { this.available--; - const callback = /** @type {(function(): void)} */ (this.waiters.pop()); + const callback = /** @type {(() => void)} */ (this.waiters.pop()); callback(); } } diff --git a/lib/util/SetHelpers.js b/lib/util/SetHelpers.js index 5908cce93..5876f1cb7 100644 --- a/lib/util/SetHelpers.js +++ b/lib/util/SetHelpers.js @@ -54,7 +54,7 @@ const isSubset = (bigSet, smallSet) => { /** * @template T * @param {Set} set a set - * @param {function(T): boolean} fn selector function + * @param {(set: T) => boolean} fn selector function * @returns {T | undefined} found item */ const find = (set, fn) => { diff --git a/lib/util/SortableSet.js b/lib/util/SortableSet.js index 9260c163a..c6758322e 100644 --- a/lib/util/SortableSet.js +++ b/lib/util/SortableSet.js @@ -16,8 +16,8 @@ class SortableSet extends Set { /** * Create a new sortable set * @template T + * @typedef {(a: T, b: T) => number} SortFunction * @param {Iterable=} initialIterable The initial iterable value - * @typedef {function(T, T): number} SortFunction * @param {SortFunction=} defaultSort Default sorting function */ constructor(initialIterable, defaultSort) { @@ -29,7 +29,7 @@ class SortableSet extends Set { this._sortFn = defaultSort; /** * @private - * @type {typeof NONE | undefined | function(T, T): number}} + * @type {typeof NONE | undefined | ((a: T, b: T) => number)}} */ this._lastActiveSortFn = NONE; /** @@ -103,7 +103,7 @@ class SortableSet extends Set { /** * Get data from cache * @template R - * @param {function(SortableSet): R} fn function to calculate value + * @param {(set: SortableSet) => R} fn function to calculate value * @returns {R} returns result of fn(this), cached until set changes */ getFromCache(fn) { @@ -124,7 +124,7 @@ class SortableSet extends Set { /** * Get data from cache (ignoring sorting) * @template R - * @param {function(SortableSet): R} fn function to calculate value + * @param {(set: SortableSet) => R} fn function to calculate value * @returns {R} returns result of fn(this), cached until set changes */ getFromUnorderedCache(fn) { diff --git a/lib/util/TupleSet.js b/lib/util/TupleSet.js index 803ae194e..cb7846a63 100644 --- a/lib/util/TupleSet.js +++ b/lib/util/TupleSet.js @@ -24,7 +24,7 @@ class TupleSet { } /** - * @param {T} args tuple + * @param {T} args tuple * @returns {void} */ add(...args) { @@ -52,7 +52,7 @@ class TupleSet { } /** - * @param {T} args tuple + * @param {T} args tuple * @returns {boolean} true, if the tuple is in the Set */ has(...args) { diff --git a/lib/util/WeakTupleMap.js b/lib/util/WeakTupleMap.js index e0e318436..20790d986 100644 --- a/lib/util/WeakTupleMap.js +++ b/lib/util/WeakTupleMap.js @@ -89,7 +89,7 @@ class WeakTupleMap { } /** - * @param {[...T, function(): V]} args tuple + * @param {[...T, () => V]} args tuple * @returns {V} the value */ provide(...args) { diff --git a/lib/util/cleverMerge.js b/lib/util/cleverMerge.js index d18e6f7bc..7439cf7e5 100644 --- a/lib/util/cleverMerge.js +++ b/lib/util/cleverMerge.js @@ -576,7 +576,7 @@ const removeOperations = (obj, keysToKeepOriginalValue = []) => { * @template {string} P * @param {T} obj the object * @param {P} byProperty the by description - * @param {...any} values values + * @param {...any} values values * @returns {Omit} object with merged byProperty */ const resolveByProperty = (obj, byProperty, ...values) => { @@ -586,7 +586,7 @@ const resolveByProperty = (obj, byProperty, ...values) => { const { [byProperty]: _byValue, ..._remaining } = obj; const remaining = /** @type {T} */ (_remaining); const byValue = - /** @type {Record | function(...any[]): T} */ + /** @type {Record | ((...args: any[]) => T)} */ (_byValue); if (typeof byValue === "object") { const key = values[0]; diff --git a/lib/util/comparators.js b/lib/util/comparators.js index 8d228026e..02fd539f6 100644 --- a/lib/util/comparators.js +++ b/lib/util/comparators.js @@ -18,17 +18,17 @@ const { compareRuntime } = require("./runtime"); /** * @template T - * @typedef {function(T, T): -1|0|1} Comparator + * @typedef {(a: T, b: T) => -1 | 0 | 1} Comparator */ /** * @template TArg * @template T - * @typedef {function(TArg, T, T): -1|0|1} RawParameterizedComparator + * @typedef {(tArg: TArg, a: T, b: T) => -1 | 0 | 1} RawParameterizedComparator */ /** * @template TArg * @template T - * @typedef {function(TArg): Comparator} ParameterizedComparator + * @typedef {(tArg: TArg) => Comparator} ParameterizedComparator */ /** diff --git a/lib/util/compileBooleanMatcher.js b/lib/util/compileBooleanMatcher.js index e388602f2..88b7883c5 100644 --- a/lib/util/compileBooleanMatcher.js +++ b/lib/util/compileBooleanMatcher.js @@ -23,8 +23,8 @@ const toSimpleString = str => { }; /** - * @param {Record} map value map - * @returns {boolean|(function(string): string)} true/false, when unconditionally true/false, or a template function to determine the value at runtime + * @param {Record} map value map + * @returns {boolean | ((value: string) => string)} true/false, when unconditionally true/false, or a template function to determine the value at runtime */ const compileBooleanMatcher = map => { const positiveItems = Object.keys(map).filter(i => map[i]); @@ -37,7 +37,7 @@ const compileBooleanMatcher = map => { /** * @param {string[]} positiveItems positive items * @param {string[]} negativeItems negative items - * @returns {function(string): string} a template function to determine the value at runtime + * @returns {(value: string) => string} a template function to determine the value at runtime */ const compileBooleanMatcherFromLists = (positiveItems, negativeItems) => { if (positiveItems.length === 0) return () => "false"; diff --git a/lib/util/create-schema-validation.js b/lib/util/create-schema-validation.js index 4f12c8e69..c57bae3b4 100644 --- a/lib/util/create-schema-validation.js +++ b/lib/util/create-schema-validation.js @@ -14,10 +14,10 @@ const getValidate = memoize(() => require("schema-utils").validate); /** * @template {object | object[]} T - * @param {(function(T): boolean) | undefined} check check + * @param {((value: T) => boolean) | undefined} check check * @param {() => JsonObject} getSchema get schema fn * @param {ValidationErrorConfiguration} options options - * @returns {function(T=): void} validate + * @returns {(value?: T) => void} validate */ const createSchemaValidation = (check, getSchema, options) => { getSchema = memoize(getSchema); diff --git a/lib/util/createHash.js b/lib/util/createHash.js index 991a1a2db..3e11ce62b 100644 --- a/lib/util/createHash.js +++ b/lib/util/createHash.js @@ -14,12 +14,12 @@ const BULK_SIZE = 2000; /** @type {{[key: string]: Map}} */ const digestCaches = {}; -/** @typedef {function(): Hash} HashFactory */ +/** @typedef {() => Hash} HashFactory */ class BulkUpdateDecorator extends Hash { /** * @param {Hash | HashFactory} hashOrFactory function to create a hash - * @param {string=} hashKey key for caching + * @param {string} [hashKey] key for caching */ constructor(hashOrFactory, hashKey) { super(); diff --git a/lib/util/deterministicGrouping.js b/lib/util/deterministicGrouping.js index 6a7a0dc3a..6978ef301 100644 --- a/lib/util/deterministicGrouping.js +++ b/lib/util/deterministicGrouping.js @@ -212,7 +212,7 @@ class Group { } /** - * @param {function(Node): boolean} filter filter function + * @param {(node: Node) => boolean} filter filter function * @returns {Node[] | undefined} removed nodes */ popNodes(filter) { @@ -277,8 +277,8 @@ const getSimilarities = nodes => { * @property {Record} maxSize maximum size of a group * @property {Record} minSize minimum size of a group (preferred over maximum size) * @property {Iterable} items a list of items - * @property {function(T): Record} getSize function to get size of an item - * @property {function(T): string} getKey function to get the key of an item + * @property {(item: T) => Record} getSize function to get size of an item + * @property {(item: T) => string} getKey function to get the key of an item */ /** diff --git a/lib/util/findGraphRoots.js b/lib/util/findGraphRoots.js index 795f99055..3db4c146b 100644 --- a/lib/util/findGraphRoots.js +++ b/lib/util/findGraphRoots.js @@ -49,7 +49,7 @@ class Cycle { /** * @template T * @param {Iterable} items list of items - * @param {function(T): Iterable} getDependencies function to get dependencies of an item (items that are not in list are ignored) + * @param {(item: T) => Iterable} getDependencies function to get dependencies of an item (items that are not in list are ignored) * @returns {Iterable} graph roots of the items */ module.exports = (items, getDependencies) => { diff --git a/lib/util/fs.js b/lib/util/fs.js index 8e7e2032d..a0babb0c3 100644 --- a/lib/util/fs.js +++ b/lib/util/fs.js @@ -66,19 +66,19 @@ const path = require("path"); /** @typedef {JsonPrimitive | JsonObject | JsonArray} JsonValue */ /** @typedef {{[Key in string]: JsonValue} & {[Key in string]?: JsonValue | undefined}} JsonObject */ -/** @typedef {function(NodeJS.ErrnoException | null): void} NoParamCallback */ -/** @typedef {function(NodeJS.ErrnoException | null, string=): void} StringCallback */ -/** @typedef {function(NodeJS.ErrnoException | null, Buffer=): void} BufferCallback */ -/** @typedef {function(NodeJS.ErrnoException | null, (string | Buffer)=): void} StringOrBufferCallback */ -/** @typedef {function(NodeJS.ErrnoException | null, (string[])=): void} ReaddirStringCallback */ -/** @typedef {function(NodeJS.ErrnoException | null, (Buffer[])=): void} ReaddirBufferCallback */ -/** @typedef {function(NodeJS.ErrnoException | null, (string[] | Buffer[])=): void} ReaddirStringOrBufferCallback */ -/** @typedef {function(NodeJS.ErrnoException | null, (Dirent[])=): void} ReaddirDirentCallback */ -/** @typedef {function(NodeJS.ErrnoException | null, IStats=): void} StatsCallback */ -/** @typedef {function(NodeJS.ErrnoException | null, IBigIntStats=): void} BigIntStatsCallback */ -/** @typedef {function(NodeJS.ErrnoException | null, (IStats | IBigIntStats)=): void} StatsOrBigIntStatsCallback */ -/** @typedef {function(NodeJS.ErrnoException | null, number=): void} NumberCallback */ -/** @typedef {function(NodeJS.ErrnoException | Error | null, JsonObject=): void} ReadJsonCallback */ +/** @typedef {(err: NodeJS.ErrnoException | null) => void} NoParamCallback */ +/** @typedef {(err: NodeJS.ErrnoException | null, result?: string) => void} StringCallback */ +/** @typedef {(err: NodeJS.ErrnoException | null, result?: Buffer) => void} BufferCallback */ +/** @typedef {(err: NodeJS.ErrnoException | null, result?: string | Buffer) => void} StringOrBufferCallback */ +/** @typedef {(err: NodeJS.ErrnoException | null, result?: string[]) => void} ReaddirStringCallback */ +/** @typedef {(err: NodeJS.ErrnoException | null, result?: Buffer[]) => void} ReaddirBufferCallback */ +/** @typedef {(err: NodeJS.ErrnoException | null, result?: string[] | Buffer[]) => void} ReaddirStringOrBufferCallback */ +/** @typedef {(err: NodeJS.ErrnoException | null, result?: Dirent[]) => void} ReaddirDirentCallback */ +/** @typedef {(err: NodeJS.ErrnoException | null, result?: IStats) => void} StatsCallback */ +/** @typedef {(err: NodeJS.ErrnoException | null, result?: IBigIntStats) => void} BigIntStatsCallback */ +/** @typedef {(err: NodeJS.ErrnoException | null, result?: IStats | IBigIntStats) => void} StatsOrBigIntStatsCallback */ +/** @typedef {(err: NodeJS.ErrnoException | null, result?: number) => void} NumberCallback */ +/** @typedef {(err: NodeJS.ErrnoException | Error | null, result?: JsonObject) => void} ReadJsonCallback */ /** @typedef {Map} TimeInfoEntries */ @@ -96,13 +96,13 @@ const path = require("path"); // TODO webpack 6 deprecate missing getInfo /** * @typedef {object} Watcher - * @property {function(): void} close closes the watcher and all underlying file watchers - * @property {function(): void} pause closes the watcher, but keeps underlying file watchers alive until the next watch call - * @property {(function(): Changes | null)=} getAggregatedChanges get current aggregated changes that have not yet send to callback - * @property {(function(): Removals | null)=} getAggregatedRemovals get current aggregated removals that have not yet send to callback - * @property {function(): TimeInfoEntries} getFileTimeInfoEntries get info about files - * @property {function(): TimeInfoEntries} getContextTimeInfoEntries get info about directories - * @property {function(): WatcherInfo=} getInfo get info about timestamps and changes + * @property {() => void} close closes the watcher and all underlying file watchers + * @property {() => void} pause closes the watcher, but keeps underlying file watchers alive until the next watch call + * @property {(() => Changes | null)=} getAggregatedChanges get current aggregated changes that have not yet send to callback + * @property {(() => Removals | null)=} getAggregatedRemovals get current aggregated removals that have not yet send to callback + * @property {() => TimeInfoEntries} getFileTimeInfoEntries get info about files + * @property {() => TimeInfoEntries} getContextTimeInfoEntries get info about directories + * @property {() => WatcherInfo=} getInfo get info about timestamps and changes */ /** @@ -112,8 +112,8 @@ const path = require("path"); * @param {Iterable} missing watched existence entries * @param {number} startTime timestamp of start time * @param {WatchOptions} options options object - * @param {function(Error | null, TimeInfoEntries=, TimeInfoEntries=, Changes=, Removals=): void} callback aggregated callback - * @param {function(string, number): void} callbackUndelayed callback when the first change was detected + * @param {(err: Error | null, timeInfoEntries1?: TimeInfoEntries, timeInfoEntries2?: TimeInfoEntries, canges?: Changes, removals?: Removals) => void} callback aggregated callback + * @param {(value: string, num: number) => void} callbackUndelayed callback when the first change was detected * @returns {Watcher} a watcher */ @@ -264,15 +264,15 @@ const path = require("path"); */ /** - * @typedef {function(PathOrFileDescriptor, ReadJsonCallback): void} ReadJson + * @typedef {(pathOrFileDescriptor: PathOrFileDescriptor, callback: ReadJsonCallback) => void} ReadJson */ /** - * @typedef {function(PathOrFileDescriptor): JsonObject} ReadJsonSync + * @typedef {(pathOrFileDescriptor: PathOrFileDescriptor) => JsonObject} ReadJsonSync */ /** - * @typedef {function((string | string[] | Set)=): void} Purge + * @typedef {(value?: string | string[] | Set) => void} Purge */ /** @@ -292,9 +292,9 @@ const path = require("path"); * @property {ReadJson=} readJson * @property {ReadJsonSync=} readJsonSync * @property {Purge=} purge - * @property {(function(string, string): string)=} join - * @property {(function(string, string): string)=} relative - * @property {(function(string): string)=} dirname + * @property {((path1: string, path2: string) => string)=} join + * @property {((from: string, to: string) => string)=} relative + * @property {((dirname: string) => string)=} dirname */ /** @@ -337,7 +337,7 @@ const path = require("path"); */ /** - * @typedef {function(PathLike, NoParamCallback): void} Unlink + * @typedef {(pathLike: PathLike, callback: NoParamCallback) => void} Unlink */ /** @@ -350,9 +350,9 @@ const path = require("path"); * @property {Stat} stat * @property {LStat=} lstat * @property {ReadFile} readFile - * @property {(function(string, string): string)=} join - * @property {(function(string, string): string)=} relative - * @property {(function(string): string)=} dirname + * @property {((path1: string, path2: string) => string)=} join + * @property {((from: string, to: string) => string)=} relative + * @property {((dirname: string) => string)=} dirname */ /** @@ -395,7 +395,7 @@ const path = require("path"); */ /** - * @typedef {function(PathLike, (BufferEncoding | WriteStreamOptions)=): NodeJS.WritableStream} CreateWriteStream + * @typedef {(pathLike: PathLike, result?: BufferEncoding | WriteStreamOptions) => NodeJS.WritableStream} CreateWriteStream */ /** @@ -439,9 +439,9 @@ const path = require("path"); * }} Read */ -/** @typedef {function(number, NoParamCallback): void} Close */ +/** @typedef {(df: number, callback: NoParamCallback) => void} Close */ -/** @typedef {function(PathLike, PathLike, NoParamCallback): void} Rename */ +/** @typedef {(a: PathLike, b: PathLike, callback: NoParamCallback) => void} Rename */ /** * @typedef {object} IntermediateFileSystemExtras @@ -517,7 +517,7 @@ module.exports.dirname = dirname; /** * @param {OutputFileSystem} fs a file system * @param {string} p an absolute path - * @param {function(Error=): void} callback callback function for the error + * @param {(err?: Error) => void} callback callback function for the error * @returns {void} */ const mkdirp = (fs, p, callback) => { @@ -613,7 +613,7 @@ module.exports.readJson = readJson; /** * @param {InputFileSystem} fs a file system * @param {string} p an absolute path - * @param {function(NodeJS.ErrnoException | Error | null, (IStats | string)=): void} callback callback + * @param {(err: NodeJS.ErrnoException | Error | null, stats?: IStats | string) => void} callback callback * @returns {void} */ const lstatReadlinkAbsolute = (fs, p, callback) => { diff --git a/lib/util/identifier.js b/lib/util/identifier.js index e94a63b50..99bff981b 100644 --- a/lib/util/identifier.js +++ b/lib/util/identifier.js @@ -10,11 +10,6 @@ const WINDOWS_ABS_PATH_REGEXP = /^[a-zA-Z]:[\\/]/; const SEGMENTS_SPLIT_REGEXP = /([|!])/; const WINDOWS_PATH_SEPARATOR_REGEXP = /\\/g; -/** - * @typedef {object} MakeRelativePathsCache - * @property {Map>=} relativePaths - */ - /** * @param {string} relativePath relative path * @returns {string} request @@ -85,24 +80,26 @@ const requestToAbsolute = (context, relativePath) => { return relativePath; }; +/** @typedef {EXPECTED_OBJECT} AssociatedObjectForCache */ + /** * @template T - * @typedef {function(string, object=): T} MakeCacheableResult + * @typedef {(value: string, cache?: AssociatedObjectForCache) => T} MakeCacheableResult */ /** * @template T - * @typedef {function(string): T} BindCacheResultFn + * @typedef {(value: string) => T} BindCacheResultFn */ /** * @template T - * @typedef {function(object): BindCacheResultFn} BindCache + * @typedef {(cache: AssociatedObjectForCache) => BindCacheResultFn} BindCache */ /** * @template T - * @param {(function(string): T)} realFn real function + * @param {((value: string) => T)} realFn real function * @returns {MakeCacheableResult & { bindCache: BindCache }} cacheable function */ const makeCacheable = realFn => { @@ -110,11 +107,11 @@ const makeCacheable = realFn => { * @template T * @typedef {Map} CacheItem */ - /** @type {WeakMap>} */ + /** @type {WeakMap>} */ const cache = new WeakMap(); /** - * @param {object} associatedObjectForCache an object to which the cache will be attached + * @param {AssociatedObjectForCache} associatedObjectForCache an object to which the cache will be attached * @returns {CacheItem} cache item */ const getCache = associatedObjectForCache => { @@ -156,18 +153,18 @@ const makeCacheable = realFn => { return fn; }; -/** @typedef {function(string, string, object=): string} MakeCacheableWithContextResult */ -/** @typedef {function(string, string): string} BindCacheForContextResultFn */ -/** @typedef {function(string): string} BindContextCacheForContextResultFn */ -/** @typedef {function(object=): BindCacheForContextResultFn} BindCacheForContext */ -/** @typedef {function(string, object=): BindContextCacheForContextResultFn} BindContextCacheForContext */ +/** @typedef {(context: string, value: string, associatedObjectForCache?: AssociatedObjectForCache) => string} MakeCacheableWithContextResult */ +/** @typedef {(context: string, value: string) => string} BindCacheForContextResultFn */ +/** @typedef {(value: string) => string} BindContextCacheForContextResultFn */ +/** @typedef {(associatedObjectForCache?: AssociatedObjectForCache) => BindCacheForContextResultFn} BindCacheForContext */ +/** @typedef {(value: string, associatedObjectForCache?: AssociatedObjectForCache) => BindContextCacheForContextResultFn} BindContextCacheForContext */ /** - * @param {function(string, string): string} fn function + * @param {(context: string, identifier: string) => string} fn function * @returns {MakeCacheableWithContextResult & { bindCache: BindCacheForContext, bindContextCache: BindContextCacheForContext }} cacheable function with context */ const makeCacheableWithContext = fn => { - /** @type {WeakMap>>} */ + /** @type {WeakMap>>} */ const cache = new WeakMap(); /** @type {MakeCacheableWithContextResult & { bindCache: BindCacheForContext, bindContextCache: BindContextCacheForContext }} */ diff --git a/lib/util/memoize.js b/lib/util/memoize.js index 74d5d6200..5c58015f9 100644 --- a/lib/util/memoize.js +++ b/lib/util/memoize.js @@ -6,7 +6,7 @@ /** * @template T - * @typedef {function(): T} FunctionReturning + * @typedef {() => T} FunctionReturning */ /** diff --git a/lib/util/processAsyncTree.js b/lib/util/processAsyncTree.js index 382538652..98ed0745e 100644 --- a/lib/util/processAsyncTree.js +++ b/lib/util/processAsyncTree.js @@ -10,8 +10,8 @@ * @template {Error} E * @param {Iterable} items initial items * @param {number} concurrency number of items running in parallel - * @param {function(T, function(T): void, function(E=): void): void} processor worker which pushes more items - * @param {function(E=): void} callback all items processed + * @param {(item: T, push: (item: T) => void, callback: (err?: E) => void) => void} processor worker which pushes more items + * @param {(err?: E) => void} callback all items processed * @returns {void} */ const processAsyncTree = (items, concurrency, processor, callback) => { diff --git a/lib/util/runtime.js b/lib/util/runtime.js index 021f799d4..e35fc912f 100644 --- a/lib/util/runtime.js +++ b/lib/util/runtime.js @@ -52,7 +52,7 @@ module.exports.getEntryRuntime = (compilation, name, options) => { /** * @param {RuntimeSpec} runtime runtime - * @param {function(string | undefined): void} fn functor + * @param {(runtime: string | undefined) => void} fn functor * @param {boolean} deterministicOrder enforce a deterministic order * @returns {void} */ @@ -394,7 +394,7 @@ module.exports.subtractRuntimeCondition = (a, b, runtime) => { /** * @param {RuntimeSpec} runtime runtime - * @param {function(RuntimeSpec=): boolean} filter filter function + * @param {(runtime?: RuntimeSpec) => boolean} filter filter function * @returns {boolean | RuntimeSpec} true/false if filter is constant for all runtimes, otherwise runtimes that are active */ module.exports.filterRuntime = (runtime, filter) => { @@ -567,7 +567,7 @@ class RuntimeSpecMap { /** * @param {RuntimeSpec} runtime the runtimes - * @param {function(T | undefined): T} fn function to update the value + * @param {(value: T | undefined) => T} fn function to update the value */ update(runtime, fn) { switch (this._mode) { diff --git a/lib/util/smartGrouping.js b/lib/util/smartGrouping.js index f75648c45..7be36a5c6 100644 --- a/lib/util/smartGrouping.js +++ b/lib/util/smartGrouping.js @@ -16,9 +16,9 @@ * @template T * @template R * @typedef {object} GroupConfig - * @property {function(T): string[] | undefined} getKeys - * @property {function(string, (R | T)[], T[]): R} createGroup - * @property {function(string, T[]): GroupOptions=} getOptions + * @property {(item: T) => string[] | undefined} getKeys + * @property {(key: string, children: (R | T)[], items: T[]) => R} createGroup + * @property {(name: string, items: T[]) => GroupOptions=} getOptions */ /** diff --git a/lib/wasm-async/AsyncWasmLoadingRuntimeModule.js b/lib/wasm-async/AsyncWasmLoadingRuntimeModule.js index e1f1c3a4b..472b7513e 100644 --- a/lib/wasm-async/AsyncWasmLoadingRuntimeModule.js +++ b/lib/wasm-async/AsyncWasmLoadingRuntimeModule.js @@ -14,9 +14,9 @@ const Template = require("../Template"); /** * @typedef {object} AsyncWasmLoadingRuntimeModuleOptions - * @property {(function(string): string)=} generateBeforeLoadBinaryCode - * @property {function(string): string} generateLoadBinaryCode - * @property {(function(): string)=} generateBeforeInstantiateStreaming + * @property {((wasmModuleSrcPath: string) => string)=} generateBeforeLoadBinaryCode + * @property {(wasmModuleSrcPath: string) => string} generateLoadBinaryCode + * @property {(() => string)=} generateBeforeInstantiateStreaming * @property {boolean} supportsStreaming */ diff --git a/setup/setup.js b/setup/setup.js index 44dae38e2..1e9c973de 100644 --- a/setup/setup.js +++ b/setup/setup.js @@ -6,6 +6,9 @@ const root = process.cwd(); const nodeModulesFolder = path.resolve(root, "node_modules"); const webpackDependencyFolder = path.resolve(root, "node_modules/webpack"); +/** + * @returns {Promise} result + */ function setup() { return Promise.all([ checkSymlinkExistsAsync().then(async hasSymlink => { @@ -27,12 +30,18 @@ function setup() { }); } +/** + * @returns {Promise} result + */ async function runSetupSymlinkAsync() { await exec("yarn", ["install"], "Install dependencies"); await exec("yarn", ["link"], "Create webpack symlink"); await exec("yarn", ["link", "webpack"], "Link webpack into itself"); } +/** + * @returns {Promise} result + */ function checkSymlinkExistsAsync() { return new Promise((resolve, reject) => { if ( @@ -47,6 +56,9 @@ function checkSymlinkExistsAsync() { }); } +/** + * @returns {Promise} result + */ async function ensureYarnInstalledAsync() { const semverPattern = /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(-(0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(\.(0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*)?(\+[0-9a-zA-Z-]+(\.[0-9a-zA-Z-]+)*)?$/; @@ -60,10 +72,19 @@ async function ensureYarnInstalledAsync() { if (!hasYarn) await installYarnAsync(); } +/** + * @returns {Promise} result + */ function installYarnAsync() { return exec("npm", ["install", "-g", "yarn"], "Install yarn"); } +/** + * @param {string} command command + * @param {string[]} args args + * @param {string} description description + * @returns {Promise} result + */ function exec(command, args, description) { console.log(`Setup: ${description}`); return new Promise((resolve, reject) => { @@ -85,6 +106,12 @@ function exec(command, args, description) { }); } +/** + * @param {string} command command + * @param {string[]} args args + * @param {string} description description + * @returns {Promise} result + */ function execGetOutput(command, args, description) { console.log(`Setup: ${description}`); return new Promise((resolve, reject) => { @@ -103,6 +130,7 @@ function execGetOutput(command, args, description) { resolve(Buffer.concat(buffers).toString("utf-8").trim()); } }); + /** @type {Buffer[]} */ const buffers = []; cp.stdout.on("data", data => buffers.push(data)); }); diff --git a/test/FileSystemInfo.unittest.js b/test/FileSystemInfo.unittest.js index 72860f131..ec6716bd6 100644 --- a/test/FileSystemInfo.unittest.js +++ b/test/FileSystemInfo.unittest.js @@ -397,7 +397,7 @@ ${details(snapshot)}`) const options = { timestamp: true }; /** - * @param {function((WebpackError | null)=, (Snapshot | null)=): void} callback callback function + * @param {(err?: WebpackError | null, snapshot?: Snapshot | null) => void} callback callback function */ function getSnapshot(callback) { const fs = createFs(); diff --git a/test/configCases/async-library/1-use-library/webpack.config.js b/test/configCases/async-library/1-use-library/webpack.config.js index 1d8496ba4..4d886ae8e 100644 --- a/test/configCases/async-library/1-use-library/webpack.config.js +++ b/test/configCases/async-library/1-use-library/webpack.config.js @@ -1,6 +1,6 @@ var path = require("path"); -/** @type {function(any, any): import("../../../../types").Configuration} */ +/** @type {(env: any, options: any) => import("../../../../types").Configuration} */ module.exports = (env, { testPath }) => ({ target: "node14", output: { diff --git a/test/configCases/css/css-modules-broken-keyframes/webpack.config.js b/test/configCases/css/css-modules-broken-keyframes/webpack.config.js index b952b563c..7b18417aa 100644 --- a/test/configCases/css/css-modules-broken-keyframes/webpack.config.js +++ b/test/configCases/css/css-modules-broken-keyframes/webpack.config.js @@ -1,7 +1,7 @@ const webpack = require("../../../../"); const path = require("path"); -/** @type {function(any, any): import("../../../../").Configuration} */ +/** @type {(env: any, options: any) => import("../../../../").Configuration} */ module.exports = (env, { testPath }) => ({ target: "web", mode: "production", diff --git a/test/configCases/css/css-modules-in-node/webpack.config.js b/test/configCases/css/css-modules-in-node/webpack.config.js index 6de693f81..1d9a1b638 100644 --- a/test/configCases/css/css-modules-in-node/webpack.config.js +++ b/test/configCases/css/css-modules-in-node/webpack.config.js @@ -1,7 +1,7 @@ const path = require("path"); const webpack = require("../../../../"); -/** @type {function(any, any): import("../../../../").Configuration[]} */ +/** @type {(env: any, options: any) => import("../../../../").Configuration[]} */ module.exports = (env, { testPath }) => [ { context: path.join(__dirname, "../css-modules"), diff --git a/test/configCases/css/css-modules-no-space/webpack.config.js b/test/configCases/css/css-modules-no-space/webpack.config.js index 4304aad28..2ad6bea19 100644 --- a/test/configCases/css/css-modules-no-space/webpack.config.js +++ b/test/configCases/css/css-modules-no-space/webpack.config.js @@ -1,4 +1,4 @@ -/** @type {function(any, any): import("../../../../").Configuration} */ +/** @type {(env: any, options: any) => import("../../../../").Configuration} */ module.exports = (env, { testPath }) => ({ target: "web", mode: "development", diff --git a/test/configCases/css/css-modules/webpack.config.js b/test/configCases/css/css-modules/webpack.config.js index a8404dd91..057399a2e 100644 --- a/test/configCases/css/css-modules/webpack.config.js +++ b/test/configCases/css/css-modules/webpack.config.js @@ -1,7 +1,7 @@ const webpack = require("../../../../"); const path = require("path"); -/** @type {function(any, any): import("../../../../").Configuration[]} */ +/** @type {(env: any, options: any) => import("../../../../").Configuration[]} */ module.exports = (env, { testPath }) => [ { target: "web", diff --git a/test/configCases/library/0-create-library/webpack.config.js b/test/configCases/library/0-create-library/webpack.config.js index 649755437..fcdb6bab4 100644 --- a/test/configCases/library/0-create-library/webpack.config.js +++ b/test/configCases/library/0-create-library/webpack.config.js @@ -1,6 +1,7 @@ const path = require("path"); const webpack = require("../../../../"); -/** @type {function(any, any): import("../../../../").Configuration[]} */ + +/** @type {(env: any, options: any) => import("../../../../").Configuration[]} */ module.exports = (env, { testPath }) => [ { output: { diff --git a/test/configCases/library/1-use-library/webpack.config.js b/test/configCases/library/1-use-library/webpack.config.js index a6068a0cc..6865d7fee 100644 --- a/test/configCases/library/1-use-library/webpack.config.js +++ b/test/configCases/library/1-use-library/webpack.config.js @@ -1,9 +1,10 @@ /** @typedef {import("../../../../").Compiler} Compiler */ /** @typedef {import("../../../../").Compilation} Compilation */ -var webpack = require("../../../../"); -var path = require("path"); -/** @type {function(any, any): import("../../../../").Configuration[]} */ +const webpack = require("../../../../"); +const path = require("path"); + +/** @type {(env: any, options: any) => import("../../../../").Configuration[]} */ module.exports = (env, { testPath }) => [ { resolve: { diff --git a/test/configCases/plugins/lib-manifest-plugin/webpack.config.js b/test/configCases/plugins/lib-manifest-plugin/webpack.config.js index 53f2f5a3d..6727fa887 100644 --- a/test/configCases/plugins/lib-manifest-plugin/webpack.config.js +++ b/test/configCases/plugins/lib-manifest-plugin/webpack.config.js @@ -1,7 +1,7 @@ var path = require("path"); var LibManifestPlugin = require("../../../../").LibManifestPlugin; -/** @type {function(any, any): import("../../../../").Configuration} */ +/** @type {(env: any, options: any) => import("../../../../").Configuration} */ module.exports = (env, { testPath }) => ({ entry: { bundle0: ["./"] diff --git a/test/configCases/records/issue-295/webpack.config.js b/test/configCases/records/issue-295/webpack.config.js index aab67f1c1..3a6f1ccf7 100644 --- a/test/configCases/records/issue-295/webpack.config.js +++ b/test/configCases/records/issue-295/webpack.config.js @@ -1,6 +1,6 @@ var path = require("path"); -/** @type {function(any, any): import("../../../../").Configuration} */ +/** @type {(env: any, options: any) => import("../../../../").Configuration} */ module.exports = (env, { testPath }) => ({ entry: "./test", recordsPath: path.resolve(testPath, "records.json"), diff --git a/test/configCases/records/issue-2991/webpack.config.js b/test/configCases/records/issue-2991/webpack.config.js index f28441965..b351d4a0f 100644 --- a/test/configCases/records/issue-2991/webpack.config.js +++ b/test/configCases/records/issue-2991/webpack.config.js @@ -1,6 +1,6 @@ var path = require("path"); -/** @type {function(any, any): import("../../../../").Configuration} */ +/** @type {(env: any, options: any) => import("../../../../").Configuration} */ module.exports = (env, { testPath }) => ({ entry: "./test", recordsOutputPath: path.resolve(testPath, "records.json"), diff --git a/test/configCases/records/issue-7339/webpack.config.js b/test/configCases/records/issue-7339/webpack.config.js index 42ffa9f5f..68dd2ca14 100644 --- a/test/configCases/records/issue-7339/webpack.config.js +++ b/test/configCases/records/issue-7339/webpack.config.js @@ -1,6 +1,6 @@ var path = require("path"); -/** @type {function(any, any): import("../../../../").Configuration} */ +/** @type {(env: any, options: any) => import("../../../../").Configuration} */ module.exports = (env, { testPath }) => ({ entry: "./test", recordsOutputPath: path.resolve(testPath, "records.json"), diff --git a/test/configCases/records/stable-sort/webpack.config.js b/test/configCases/records/stable-sort/webpack.config.js index 77b7d7b13..7cb98b5cc 100644 --- a/test/configCases/records/stable-sort/webpack.config.js +++ b/test/configCases/records/stable-sort/webpack.config.js @@ -1,6 +1,6 @@ var path = require("path"); -/** @type {function(any, any): import("../../../../").Configuration} */ +/** @type {(env: any, options: any) => import("../../../../").Configuration} */ module.exports = (env, { testPath }) => ({ mode: "development", entry: "./test", diff --git a/test/watchCases/cache/managedPath/webpack.config.js b/test/watchCases/cache/managedPath/webpack.config.js index dee8c6da2..d4f93e9da 100644 --- a/test/watchCases/cache/managedPath/webpack.config.js +++ b/test/watchCases/cache/managedPath/webpack.config.js @@ -1,6 +1,6 @@ const path = require("path"); -/** @type {function(any, any): import("../../../../").Configuration} */ +/** @type {(env: any, options: any) => import("../../../../").Configuration} */ module.exports = (env, { srcPath }) => ({ mode: "development", cache: { diff --git a/test/watchCases/cache/unsafe-cache-managed-paths/webpack.config.js b/test/watchCases/cache/unsafe-cache-managed-paths/webpack.config.js index a984cb9ae..adaad15c8 100644 --- a/test/watchCases/cache/unsafe-cache-managed-paths/webpack.config.js +++ b/test/watchCases/cache/unsafe-cache-managed-paths/webpack.config.js @@ -1,4 +1,4 @@ -/** @type {function(): import("../../../../").Configuration} */ +/** @type {(env: any, options: any) => import("../../../../").Configuration} */ module.exports = (env, { srcPath }) => ({ mode: "development", cache: { diff --git a/test/watchCases/plugins/define-plugin/webpack.config.js b/test/watchCases/plugins/define-plugin/webpack.config.js index 2d4256e65..82a24719b 100644 --- a/test/watchCases/plugins/define-plugin/webpack.config.js +++ b/test/watchCases/plugins/define-plugin/webpack.config.js @@ -1,7 +1,7 @@ const path = require("path"); const fs = require("fs"); const webpack = require("../../../../"); -/** @type {function(any, any): import("../../../../").Configuration} */ +/** @type {(env: any, options: any) => import("../../../../").Configuration} */ module.exports = (env, { srcPath }) => { const valueFile = path.resolve(srcPath, "value.txt"); return { diff --git a/test/watchCases/snapshot/unable-to-snapshot/webpack.config.js b/test/watchCases/snapshot/unable-to-snapshot/webpack.config.js index 8021c4c8d..be622c5ce 100644 --- a/test/watchCases/snapshot/unable-to-snapshot/webpack.config.js +++ b/test/watchCases/snapshot/unable-to-snapshot/webpack.config.js @@ -1,5 +1,5 @@ const path = require("path"); -/** @type {function(any, any): import("../../../../").Configuration} */ +/** @type {(env: any, options: any) => import("../../../../").Configuration} */ module.exports = (env, { srcPath }) => ({ cache: { type: "memory" diff --git a/tsconfig.json b/tsconfig.json index f815caa3a..48e5022d9 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -17,6 +17,7 @@ "schemas/**/*.json", "bin/*.js", "lib/**/*.js", - "tooling/**/*.js" + "tooling/**/*.js", + "setup/**/*.js" ] } diff --git a/types.d.ts b/types.d.ts index dd4a462a4..35e2666db 100644 --- a/types.d.ts +++ b/types.d.ts @@ -463,8 +463,8 @@ declare class AutomaticPrefetchPlugin { } type AuxiliaryComment = string | LibraryCustomUmdCommentObject; declare interface BackendApi { - dispose: (arg0: (arg0?: null | Error) => void) => void; - module: (arg0: Module) => ModuleResult; + dispose: (callback: (err?: null | Error) => void) => void; + module: (module: Module) => ModuleResult; } declare class BannerPlugin { constructor(options: BannerPluginArgument); @@ -895,7 +895,7 @@ declare class Cache { [ string, null | Etag, - ((result: any, callback: (arg0?: Error) => void) => void)[] + ((result: any, callback: (err?: Error) => void) => void)[] ], any >; @@ -957,7 +957,7 @@ declare abstract class CacheFacade { provide( identifier: string, etag: null | Etag, - computer: (arg0: CallbackNormalErrorCache) => void, + computer: (callback: CallbackNormalErrorCache) => void, callback: CallbackNormalErrorCache ): void; providePromise( @@ -985,7 +985,7 @@ declare interface CacheGroupSource { minChunks?: number; maxAsyncRequests?: number; maxInitialRequests?: number; - filename?: string | ((arg0: PathData, arg1?: AssetInfo) => string); + filename?: string | ((pathData: PathData, assetInfo?: AssetInfo) => string); idHint?: string; automaticNameDelimiter?: string; reuseExistingChunk?: boolean; @@ -1048,8 +1048,12 @@ declare class Chunk { name?: null | string; idNameHints: SortableSet; preventIntegration: boolean; - filenameTemplate?: string | ((arg0: PathData, arg1?: AssetInfo) => string); - cssFilenameTemplate?: string | ((arg0: PathData, arg1?: AssetInfo) => string); + filenameTemplate?: + | string + | ((pathData: PathData, assetInfo?: AssetInfo) => string); + cssFilenameTemplate?: + | string + | ((pathData: PathData, assetInfo?: AssetInfo) => string); runtime: RuntimeSpec; files: Set; auxiliaryFiles: Set; @@ -1139,7 +1143,7 @@ declare class ChunkGraph { getModuleChunksIterable(module: Module): Iterable; getOrderedModuleChunksIterable( module: Module, - sortFn: (arg0: Chunk, arg1: Chunk) => 0 | 1 | -1 + sortFn: (a: Chunk, b: Chunk) => 0 | 1 | -1 ): Iterable; getModuleChunks(module: Module): Chunk[]; getNumberOfModuleChunks(module: Module): number; @@ -1160,17 +1164,17 @@ declare class ChunkGraph { getModuleSourceTypes(module: Module): ReadonlySet; getOrderedChunkModulesIterable( chunk: Chunk, - comparator: (arg0: Module, arg1: Module) => 0 | 1 | -1 + comparator: (a: Module, b: Module) => 0 | 1 | -1 ): Iterable; getOrderedChunkModulesIterableBySourceType( chunk: Chunk, sourceType: string, - comparator: (arg0: Module, arg1: Module) => 0 | 1 | -1 + comparator: (a: Module, b: Module) => 0 | 1 | -1 ): undefined | Iterable; getChunkModules(chunk: Chunk): Module[]; getOrderedChunkModules( chunk: Chunk, - comparator: (arg0: Module, arg1: Module) => 0 | 1 | -1 + comparator: (a: Module, b: Module) => 0 | 1 | -1 ): Module[]; getChunkModuleIdMap( chunk: Chunk, @@ -1466,7 +1470,7 @@ declare interface ChunkPathData { id: string | number; name?: string; hash: string; - hashWithLength?: (arg0: number) => string; + hashWithLength?: (length: number) => string; contentHash?: Record; contentHashWithLength?: Record string>; } @@ -1560,8 +1564,8 @@ declare abstract class ChunkTemplate { | string | (TapOptions & { name: string } & IfSet), fn: ( - arg0: RenderManifestEntry[], - arg1: RenderManifestOptions + renderManifestEntries: RenderManifestEntry[], + renderManifestOptions: RenderManifestOptions ) => RenderManifestEntry[] ) => void; }; @@ -1571,9 +1575,9 @@ declare abstract class ChunkTemplate { | string | (TapOptions & { name: string } & IfSet), fn: ( - arg0: Source, - arg1: ModuleTemplate, - arg2: RenderContextJavascriptModulesPlugin + source: Source, + moduleTemplate: ModuleTemplate, + renderContext: RenderContextJavascriptModulesPlugin ) => Source ) => void; }; @@ -1583,9 +1587,9 @@ declare abstract class ChunkTemplate { | string | (TapOptions & { name: string } & IfSet), fn: ( - arg0: Source, - arg1: ModuleTemplate, - arg2: RenderContextJavascriptModulesPlugin + source: Source, + moduleTemplate: ModuleTemplate, + renderContext: RenderContextJavascriptModulesPlugin ) => Source ) => void; }; @@ -1594,7 +1598,7 @@ declare abstract class ChunkTemplate { options: | string | (TapOptions & { name: string } & IfSet), - fn: (arg0: Source, arg1: Chunk) => Source + fn: (source: Source, chunk: Chunk) => Source ) => void; }; hash: { @@ -1602,7 +1606,7 @@ declare abstract class ChunkTemplate { options: | string | (TapOptions & { name: string } & IfSet), - fn: (arg0: Hash) => void + fn: (hash: Hash) => void ) => void; }; hashForChunk: { @@ -1610,7 +1614,11 @@ declare abstract class ChunkTemplate { options: | string | (TapOptions & { name: string } & IfSet), - fn: (arg0: Hash, arg1: Chunk, arg2: ChunkHashContext) => void + fn: ( + hash: Hash, + chunk: Chunk, + chunkHashContext: ChunkHashContext + ) => void ) => void; }; }>; @@ -1788,7 +1796,7 @@ type CodeValuePrimitive = | Function | RegExp; declare interface Comparator { - (arg0: T, arg1: T): 0 | 1 | -1; + (a: T, b: T): 0 | 1 | -1; } declare class CompatSource extends Source { constructor(sourceLike: SourceLike); @@ -1931,7 +1939,7 @@ declare class Compilation { chunkHash: SyncHook<[Chunk, Hash, ChunkHashContext]>; moduleAsset: SyncHook<[Module, string]>; chunkAsset: SyncHook<[Chunk, string]>; - assetPath: SyncWaterfallHook<[string, object, undefined | AssetInfo]>; + assetPath: SyncWaterfallHook<[string, PathData, undefined | AssetInfo]>; needAdditionalPass: SyncBailHook<[], boolean | void>; childCompiler: SyncHook<[Compiler, string, number]>; log: SyncBailHook<[string, LogEntry], boolean | void>; @@ -2180,8 +2188,10 @@ declare class Compilation { emitAsset(file: string, source: Source, assetInfo?: AssetInfo): void; updateAsset( file: string, - newSourceOrFunction: Source | ((arg0: Source) => Source), - assetInfoUpdateOrFunction?: AssetInfo | ((arg0?: AssetInfo) => AssetInfo) + newSourceOrFunction: Source | ((source: Source) => Source), + assetInfoUpdateOrFunction?: + | AssetInfo + | ((assetInfo?: AssetInfo) => AssetInfo) ): void; renameAsset(file: string, newFile: string): void; deleteAsset(file: string): void; @@ -2443,9 +2453,9 @@ declare class Compiler { fsStartTime?: number; resolverFactory: ResolverFactory; infrastructureLogger?: ( - arg0: string, - arg1: LogTypeEnum, - arg2?: any[] + value: string, + type: LogTypeEnum, + args?: any[] ) => void; platform: Readonly; options: WebpackOptionsNormalized; @@ -3373,7 +3383,7 @@ declare class DefinePlugin { */ apply(compiler: Compiler): void; static runtimeValue( - fn: (arg0: { + fn: (value: { module: NormalModule; key: string; readonly version: ValueCacheVersion; @@ -3453,7 +3463,10 @@ declare class Dependency { ): | null | false - | ((arg0: ModuleGraphConnection, arg1: RuntimeSpec) => ConnectionState); + | (( + moduleGraphConnection: ModuleGraphConnection, + runtime: RuntimeSpec + ) => ConnectionState); /** * Returns the exported names @@ -3618,7 +3631,7 @@ declare interface DeterministicModuleIdsPluginOptions { /** * selector function for modules */ - test?: (arg0: Module) => boolean; + test?: (module: Module) => boolean; /** * maximum id length in digits (used as starting point) @@ -4487,7 +4500,7 @@ declare abstract class ExportInfo { setUsedWithoutInfo(runtime: RuntimeSpec): boolean; setHasUseInfo(): void; setUsedConditionally( - condition: (arg0: UsageStateType) => boolean, + condition: (condition: UsageStateType) => boolean, newValue: UsageStateType, runtime: RuntimeSpec ): boolean; @@ -4516,16 +4529,16 @@ declare abstract class ExportInfo { setUsedName(name: string): void; getTerminalBinding( moduleGraph: ModuleGraph, - resolveTargetFilter?: (arg0: TargetItemWithConnection) => boolean + resolveTargetFilter?: (target: TargetItemWithConnection) => boolean ): undefined | ExportsInfo | ExportInfo; isReexport(): undefined | boolean; findTarget( moduleGraph: ModuleGraph, - validTargetModuleFilter: (arg0: Module) => boolean + validTargetModuleFilter: (module: Module) => boolean ): undefined | null | false | TargetItemWithoutConnection; getTarget( moduleGraph: ModuleGraph, - resolveTargetFilter?: (arg0: TargetItemWithConnection) => boolean + resolveTargetFilter?: (target: TargetItemWithConnection) => boolean ): undefined | TargetItemWithConnection; /** @@ -4533,9 +4546,9 @@ declare abstract class ExportInfo { */ moveTarget( moduleGraph: ModuleGraph, - resolveTargetFilter: (arg0: TargetItemWithConnection) => boolean, + resolveTargetFilter: (target: TargetItemWithConnection) => boolean, updateOriginalConnection?: ( - arg0: TargetItemWithConnection + target: TargetItemWithConnection ) => ModuleGraphConnection ): undefined | TargetItemWithConnection; createNestedExportsInfo(): ExportsInfo; @@ -5144,43 +5157,46 @@ declare abstract class FileSystemInfo { getFileTimestamp( path: string, callback: ( - arg0?: null | WebpackError, - arg1?: null | FileSystemInfoEntry | "ignore" + err?: null | WebpackError, + fileTimestamp?: null | FileSystemInfoEntry | "ignore" ) => void ): void; getContextTimestamp( path: string, callback: ( - arg0?: null | WebpackError, - arg1?: null | "ignore" | ResolvedContextFileSystemInfoEntry + err?: null | WebpackError, + resolvedContextTimestamp?: + | null + | "ignore" + | ResolvedContextFileSystemInfoEntry ) => void ): void; getFileHash( path: string, - callback: (arg0?: null | WebpackError, arg1?: null | string) => void + callback: (err?: null | WebpackError, hash?: null | string) => void ): void; getContextHash( path: string, - callback: (arg0?: null | WebpackError, arg1?: string) => void + callback: (err?: null | WebpackError, contextHash?: string) => void ): void; getContextTsh( path: string, callback: ( - arg0?: null | WebpackError, - arg1?: null | ResolvedContextTimestampAndHash + err?: null | WebpackError, + resolvedContextTimestampAndHash?: null | ResolvedContextTimestampAndHash ) => void ): void; resolveBuildDependencies( context: string, deps: Iterable, callback: ( - arg0?: null | Error, - arg1?: ResolveBuildDependenciesResult + err?: null | Error, + resolveBuildDependenciesResult?: ResolveBuildDependenciesResult ) => void ): void; checkResolveResultsValid( resolveResults: Map, - callback: (arg0?: null | Error, arg1?: boolean) => void + callback: (err?: null | Error, result?: boolean) => void ): void; createSnapshot( startTime: undefined | null | number, @@ -5188,12 +5204,12 @@ declare abstract class FileSystemInfo { directories: null | Iterable, missing: null | Iterable, options: undefined | null | SnapshotOptionsFileSystemInfo, - callback: (arg0: null | WebpackError, arg1: null | Snapshot) => void + callback: (err: null | WebpackError, snapshot: null | Snapshot) => void ): void; mergeSnapshots(snapshot1: Snapshot, snapshot2: Snapshot): Snapshot; checkSnapshotValid( snapshot: Snapshot, - callback: (arg0?: null | WebpackError, arg1?: boolean) => void + callback: (err?: null | WebpackError, result?: boolean) => void ): void; getDeprecatedFileTimestamps(): Map; getDeprecatedContextTimestamps(): Map; @@ -5348,15 +5364,18 @@ declare class GetChunkFilenameRuntimeModule extends RuntimeModule { name: string, global: string, getFilenameForChunk: ( - arg0: Chunk - ) => string | false | ((arg0: PathData, arg1?: AssetInfo) => string), + chunk: Chunk + ) => + | string + | false + | ((pathData: PathData, assetInfo?: AssetInfo) => string), allChunks: boolean ); contentType: string; global: string; getFilenameForChunk: ( - arg0: Chunk - ) => string | false | ((arg0: PathData, arg1?: AssetInfo) => string); + chunk: Chunk + ) => string | false | ((pathData: PathData, assetInfo?: AssetInfo) => string); allChunks: boolean; /** @@ -5380,9 +5399,9 @@ declare class GetChunkFilenameRuntimeModule extends RuntimeModule { static STAGE_TRIGGER: number; } declare interface GroupConfig { - getKeys: (arg0?: any) => undefined | string[]; - createGroup: (arg0: string, arg1: any[], arg2: any[]) => object; - getOptions?: (arg0: string, arg1: any[]) => GroupOptions; + getKeys: (item?: any) => undefined | string[]; + createGroup: (key: string, children: any[], items: any[]) => object; + getOptions?: (name: string, items: any[]) => GroupOptions; } declare interface GroupOptions { groupChildren?: boolean; @@ -5501,7 +5520,7 @@ declare class Hash { } type HashFunction = string | typeof Hash; declare interface HashableObject { - updateHash: (arg0: Hash) => void; + updateHash: (hash: Hash) => void; } declare class HashedModuleIdsPlugin { constructor(options?: HashedModuleIdsPluginOptions); @@ -5840,17 +5859,17 @@ declare interface InputFileSystem { realpath?: RealPathFs; realpathSync?: RealPathSync; readJson?: ( - arg0: PathOrFileDescriptorFs, - arg1: ( - arg0: null | Error | NodeJS.ErrnoException, - arg1?: JsonObjectFs + pathOrFileDescriptor: PathOrFileDescriptorFs, + callback: ( + err: null | Error | NodeJS.ErrnoException, + result?: JsonObjectFs ) => void ) => void; - readJsonSync?: (arg0: PathOrFileDescriptorFs) => JsonObjectFs; - purge?: (arg0?: string | string[] | Set) => void; - join?: (arg0: string, arg1: string) => string; - relative?: (arg0: string, arg1: string) => string; - dirname?: (arg0: string) => string; + readJsonSync?: (pathOrFileDescriptor: PathOrFileDescriptorFs) => JsonObjectFs; + purge?: (value?: string | string[] | Set) => void; + join?: (path1: string, path2: string) => string; + relative?: (from: string, to: string) => string; + dirname?: (dirname: string) => string; } type IntermediateFileSystem = InputFileSystem & OutputFileSystem & @@ -5858,8 +5877,8 @@ type IntermediateFileSystem = InputFileSystem & declare interface IntermediateFileSystemExtras { mkdirSync: MkdirSync; createWriteStream: ( - arg0: PathLikeFs, - arg1?: + pathLike: PathLikeFs, + result?: | "ascii" | "utf8" | "utf-8" @@ -5877,13 +5896,13 @@ declare interface IntermediateFileSystemExtras { open: Open; read: Read; close: ( - arg0: number, - arg1: (arg0: null | NodeJS.ErrnoException) => void + df: number, + callback: (err: null | NodeJS.ErrnoException) => void ) => void; rename: ( - arg0: PathLikeFs, - arg1: PathLikeFs, - arg2: (arg0: null | NodeJS.ErrnoException) => void + a: PathLikeFs, + b: PathLikeFs, + callback: (err: null | NodeJS.ErrnoException) => void ) => void; } type InternalCell = T | typeof TOMBSTONE | typeof UNDEFINED_MARKER; @@ -5900,7 +5919,7 @@ declare abstract class ItemCacheFacade { store(data: T, callback: CallbackCacheCacheFacade): void; storePromise(data: T): Promise; provide( - computer: (arg0: CallbackNormalErrorCache) => void, + computer: (callback: CallbackNormalErrorCache) => void, callback: CallbackNormalErrorCache ): void; providePromise(computer: () => T | Promise): Promise; @@ -6689,7 +6708,7 @@ declare class JavascriptParser extends Parser { ): void; enterDeclaration( declaration: Declaration, - onIdent: (arg0: string, arg1: Identifier) => void + onIdent: (ident: string, identifier: Identifier) => void ): void; blockPreWalkExportNamedDeclaration( statement: ExportNamedDeclarationJavascriptParser @@ -6854,11 +6873,11 @@ declare class JavascriptParser extends Parser { fallback: | undefined | (( - arg0: string, - arg1: string | VariableInfo | ScopeInfo, - arg2: () => string[] + name: string, + rootInfo: string | VariableInfo | ScopeInfo, + getMembers: () => string[] ) => any), - defined: undefined | ((arg0: string) => any), + defined: undefined | ((result?: string) => any), ...args: AsArray ): undefined | R; callHooksForName( @@ -6874,14 +6893,14 @@ declare class JavascriptParser extends Parser { callHooksForInfoWithFallback( hookMap: HookMap>, info: ExportedVariableInfo, - fallback: undefined | ((arg0: string) => any), - defined: undefined | ((arg0?: string) => any), + fallback: undefined | ((name: string) => any), + defined: undefined | ((result?: string) => any), ...args: AsArray ): undefined | R; callHooksForNameWithFallback( hookMap: HookMap>, name: string, - fallback: undefined | ((arg0: string) => any), + fallback: undefined | ((value: string) => any), defined: undefined | (() => any), ...args: AsArray ): undefined | R; @@ -6956,7 +6975,7 @@ declare class JavascriptParser extends Parser { | AssignmentPattern | Property )[], - onIdent: (arg0: string) => void + onIdent: (ident: string) => void ): void; enterPattern( pattern: @@ -6967,27 +6986,27 @@ declare class JavascriptParser extends Parser { | RestElement | AssignmentPattern | Property, - onIdent: (arg0: string, arg1: Identifier) => void + onIdent: (ident: string, identifier: Identifier) => void ): void; enterIdentifier( pattern: Identifier, - onIdent: (arg0: string, arg1: Identifier) => void + onIdent: (ident: string, identifier: Identifier) => void ): void; enterObjectPattern( pattern: ObjectPattern, - onIdent: (arg0: string, arg1: Identifier) => void + onIdent: (ident: string, identifier: Identifier) => void ): void; enterArrayPattern( pattern: ArrayPattern, - onIdent: (arg0: string, arg1: Identifier) => void + onIdent: (ident: string, identifier: Identifier) => void ): void; enterRestElement( pattern: RestElement, - onIdent: (arg0: string, arg1: Identifier) => void + onIdent: (ident: string, identifier: Identifier) => void ): void; enterAssignmentPattern( pattern: AssignmentPattern, - onIdent: (arg0: string, arg1: Identifier) => void + onIdent: (ident: string, identifier: Identifier) => void ): void; evaluateExpression( expression: @@ -7728,14 +7747,14 @@ declare interface KnownStatsError { } declare interface KnownStatsFactoryContext { type: string; - makePathsRelative: (arg0: string) => string; + makePathsRelative: (path: string) => string; compilation: Compilation; rootModules: Set; compilationFileToChunks: Map; compilationAuxiliaryFileToChunks: Map; runtime: RuntimeSpec; - cachedGetErrors: (arg0: Compilation) => WebpackError[]; - cachedGetWarnings: (arg0: Compilation) => WebpackError[]; + cachedGetErrors: (compilation: Compilation) => WebpackError[]; + cachedGetWarnings: (compilation: Compilation) => WebpackError[]; } declare interface KnownStatsLogging { entries: StatsLoggingEntry[]; @@ -7889,24 +7908,24 @@ declare interface KnownUnsafeCacheData { declare interface LStatFs { ( path: PathLikeFs, - callback: (arg0: null | NodeJS.ErrnoException, arg1?: IStats) => void + callback: (err: null | NodeJS.ErrnoException, result?: IStats) => void ): void; ( path: PathLikeFs, options: undefined | (StatOptions & { bigint?: false }), - callback: (arg0: null | NodeJS.ErrnoException, arg1?: IStats) => void + callback: (err: null | NodeJS.ErrnoException, result?: IStats) => void ): void; ( path: PathLikeFs, options: StatOptions & { bigint: true }, - callback: (arg0: null | NodeJS.ErrnoException, arg1?: IBigIntStats) => void + callback: (err: null | NodeJS.ErrnoException, result?: IBigIntStats) => void ): void; ( path: PathLikeFs, options: undefined | StatOptions, callback: ( - arg0: null | NodeJS.ErrnoException, - arg1?: IStats | IBigIntStats + err: null | NodeJS.ErrnoException, + result?: IStats | IBigIntStats ) => void ): void; } @@ -8023,7 +8042,7 @@ declare class LazySet { delete(value: T): boolean; entries(): IterableIterator<[T, T]>; forEach( - callbackFn: (arg0: T, arg1: T, arg2: Set) => void, + callbackFn: (value: T, value2: T, set: Set) => void, thisArg: K ): void; has(item: T): boolean; @@ -8580,8 +8599,8 @@ declare abstract class MainTemplate { | string | (TapOptions & { name: string } & IfSet), fn: ( - arg0: RenderManifestEntry[], - arg1: RenderManifestOptions + renderManifestEntries: RenderManifestEntry[], + renderManifestOptions: RenderManifestOptions ) => RenderManifestEntry[] ) => void; }; @@ -8592,7 +8611,10 @@ declare abstract class MainTemplate { options: | string | (TapOptions & { name: string } & IfSet), - fn: (arg0: string, arg1: RenderBootstrapContext) => string + fn: ( + value: string, + renderBootstrapContext: RenderBootstrapContext + ) => string ) => void; }; beforeStartup: { tap: () => never }; @@ -8604,11 +8626,11 @@ declare abstract class MainTemplate { | string | (TapOptions & { name: string } & IfSet), fn: ( - arg0: Source, - arg1: Chunk, - arg2: undefined | string, - arg3: ModuleTemplate, - arg4: DependencyTemplates + source: Source, + chunk: Chunk, + hash: undefined | string, + moduleTemplate: ModuleTemplate, + dependencyTemplates: DependencyTemplates ) => Source ) => void; }; @@ -8617,7 +8639,7 @@ declare abstract class MainTemplate { options: | string | (TapOptions & { name: string } & IfSet), - fn: (arg0: Source, arg1: Chunk, arg2?: string) => Source + fn: (source: Source, chunk: Chunk, hash?: string) => Source ) => void; }; assetPath: { @@ -8625,7 +8647,7 @@ declare abstract class MainTemplate { options: | string | (TapOptions & { name: string } & IfSet), - fn: (arg0: string, arg1: object, arg2?: AssetInfo) => string + fn: (value: string, path: PathData, assetInfo?: AssetInfo) => string ) => void; call: (filename: TemplatePath, options: PathData) => string; }; @@ -8634,7 +8656,7 @@ declare abstract class MainTemplate { options: | string | (TapOptions & { name: string } & IfSet), - fn: (arg0: Hash) => void + fn: (hash: Hash) => void ) => void; }; hashForChunk: { @@ -8642,7 +8664,7 @@ declare abstract class MainTemplate { options: | string | (TapOptions & { name: string } & IfSet), - fn: (arg0: Hash, arg1: Chunk) => void + fn: (hash: Hash, chunk: Chunk) => void ) => void; }; globalHashPaths: { tap: () => void }; @@ -8751,7 +8773,7 @@ declare interface Mkdir { ( file: PathLikeFs, options: MakeDirectoryOptions & { recursive: true }, - callback: (arg0: null | NodeJS.ErrnoException, arg1?: string) => void + callback: (err: null | NodeJS.ErrnoException, result?: string) => void ): void; ( file: PathLikeFs, @@ -8761,16 +8783,16 @@ declare interface Mkdir { | string | number | (MakeDirectoryOptions & { recursive?: false }), - callback: (arg0: null | NodeJS.ErrnoException) => void + callback: (err: null | NodeJS.ErrnoException) => void ): void; ( file: PathLikeFs, options: undefined | null | string | number | MakeDirectoryOptions, - callback: (arg0: null | NodeJS.ErrnoException, arg1?: string) => void + callback: (err: null | NodeJS.ErrnoException, result?: string) => void ): void; ( file: PathLikeFs, - callback: (arg0: null | NodeJS.ErrnoException) => void + callback: (err: null | NodeJS.ErrnoException) => void ): void; } declare interface MkdirSync { @@ -8867,7 +8889,7 @@ declare class Module extends DependenciesBlock { hasReasons(moduleGraph: ModuleGraph, runtime: RuntimeSpec): boolean; needBuild( context: NeedBuildContext, - callback: (arg0?: null | WebpackError, arg1?: boolean) => void + callback: (err?: null | WebpackError, needBuild?: boolean) => void ): void; needRebuild( fileTimestamps: Map, @@ -8881,7 +8903,7 @@ declare class Module extends DependenciesBlock { compilation: Compilation, resolver: ResolverWithOptions, fs: InputFileSystem, - callback: (arg0?: WebpackError) => void + callback: (err?: WebpackError) => void ): void; getSourceTypes(): ReadonlySet; source( @@ -8978,7 +9000,7 @@ declare class ModuleDependency extends Dependency { declare abstract class ModuleFactory { create( data: ModuleFactoryCreateData, - callback: (arg0?: null | Error, arg1?: ModuleFactoryResult) => void + callback: (err?: null | Error, result?: ModuleFactoryResult) => void ): void; } declare interface ModuleFactoryCreateData { @@ -9122,12 +9144,12 @@ declare class ModuleGraph { moveModuleConnections( oldModule: Module, newModule: Module, - filterConnection: (arg0: ModuleGraphConnection) => boolean + filterConnection: (moduleGraphConnection: ModuleGraphConnection) => boolean ): void; copyOutgoingModuleConnections( oldModule: Module, newModule: Module, - filterConnection: (arg0: ModuleGraphConnection) => boolean + filterConnection: (moduleGraphConnection: ModuleGraphConnection) => boolean ): void; addExtraReason(module: Module, explanation: string): void; getResolvedModule(dependency: Dependency): null | Module; @@ -9208,7 +9230,10 @@ declare class ModuleGraphConnection { condition?: | null | false - | ((arg0: ModuleGraphConnection, arg1: RuntimeSpec) => ConnectionState) + | (( + moduleGraphConnection: ModuleGraphConnection, + runtime: RuntimeSpec + ) => ConnectionState) ); originModule: null | Module; resolvedOriginModule: null | Module; @@ -9218,15 +9243,15 @@ declare class ModuleGraphConnection { weak: boolean; conditional: boolean; condition?: ( - arg0: ModuleGraphConnection, - arg1: RuntimeSpec + moduleGraphConnection: ModuleGraphConnection, + runtime: RuntimeSpec ) => ConnectionState; explanations?: Set; clone(): ModuleGraphConnection; addCondition( condition: ( - arg0: ModuleGraphConnection, - arg1: RuntimeSpec + moduleGraphConnection: ModuleGraphConnection, + runtime: RuntimeSpec ) => ConnectionState ): void; addExplanation(explanation: string): void; @@ -9388,7 +9413,7 @@ declare interface ModuleOptionsNormalized { declare interface ModulePathData { id: string | number; hash: string; - hashWithLength?: (arg0: number) => string; + hashWithLength?: (length: number) => string; } declare abstract class ModuleProfile { startTime: number; @@ -9498,10 +9523,10 @@ declare abstract class ModuleTemplate { | string | (TapOptions & { name: string } & IfSet), fn: ( - arg0: Source, - arg1: Module, - arg2: ChunkRenderContextJavascriptModulesPlugin, - arg3: DependencyTemplates + source: Source, + module: Module, + chunkRenderContext: ChunkRenderContextJavascriptModulesPlugin, + dependencyTemplates: DependencyTemplates ) => Source ) => void; }; @@ -9511,10 +9536,10 @@ declare abstract class ModuleTemplate { | string | (TapOptions & { name: string } & IfSet), fn: ( - arg0: Source, - arg1: Module, - arg2: ChunkRenderContextJavascriptModulesPlugin, - arg3: DependencyTemplates + source: Source, + module: Module, + chunkRenderContext: ChunkRenderContextJavascriptModulesPlugin, + dependencyTemplates: DependencyTemplates ) => Source ) => void; }; @@ -9524,10 +9549,10 @@ declare abstract class ModuleTemplate { | string | (TapOptions & { name: string } & IfSet), fn: ( - arg0: Source, - arg1: Module, - arg2: ChunkRenderContextJavascriptModulesPlugin, - arg3: DependencyTemplates + source: Source, + module: Module, + chunkRenderContext: ChunkRenderContextJavascriptModulesPlugin, + dependencyTemplates: DependencyTemplates ) => Source ) => void; }; @@ -9537,10 +9562,10 @@ declare abstract class ModuleTemplate { | string | (TapOptions & { name: string } & IfSet), fn: ( - arg0: Source, - arg1: Module, - arg2: ChunkRenderContextJavascriptModulesPlugin, - arg3: DependencyTemplates + source: Source, + module: Module, + chunkRenderContext: ChunkRenderContextJavascriptModulesPlugin, + dependencyTemplates: DependencyTemplates ) => Source ) => void; }; @@ -9549,7 +9574,7 @@ declare abstract class ModuleTemplate { options: | string | (TapOptions & { name: string } & IfSet), - fn: (arg0: Hash) => void + fn: (hash: Hash) => void ) => void; }; }>; @@ -10028,10 +10053,10 @@ declare class NormalModuleReplacementPlugin { */ constructor( resourceRegExp: RegExp, - newResource: string | ((arg0: ResolveData) => void) + newResource: string | ((resolveData: ResolveData) => void) ); resourceRegExp: RegExp; - newResource: string | ((arg0: ResolveData) => void); + newResource: string | ((resolveData: ResolveData) => void); /** * Apply the plugin @@ -10093,7 +10118,7 @@ declare class NullDependencyTemplate extends DependencyTemplate { } declare interface ObjectDeserializerContext { read: () => any; - setCircularReference: (arg0?: any) => void; + setCircularReference: (value?: any) => void; } declare interface ObjectEncodingOptions { encoding?: @@ -10115,16 +10140,16 @@ declare interface ObjectForExtract { [index: string]: any; } declare interface ObjectSerializer { - serialize: (arg0: any, arg1: ObjectSerializerContext) => void; - deserialize: (arg0: ObjectDeserializerContext) => any; + serialize: (value: any, context: ObjectSerializerContext) => void; + deserialize: (context: ObjectDeserializerContext) => any; } declare interface ObjectSerializerContext { - write: (arg0?: any) => void; - setCircularReference: (arg0?: any) => void; + write: (value?: any) => void; + setCircularReference: (value?: any) => void; snapshot: () => ObjectSerializerSnapshot; - rollback: (arg0: ObjectSerializerSnapshot) => void; - writeLazy?: (arg0?: any) => void; - writeSeparate?: (arg0: any, arg1?: object) => () => any; + rollback: (snapshot: ObjectSerializerSnapshot) => void; + writeLazy?: (item?: any) => void; + writeSeparate?: (item?: any, obj?: object) => () => any; } declare interface ObjectSerializerSnapshot { length: number; @@ -10169,16 +10194,16 @@ declare interface Open { file: PathLikeFs, flags: undefined | string | number, mode: undefined | null | string | number, - callback: (arg0: null | NodeJS.ErrnoException, arg1?: number) => void + callback: (err: null | NodeJS.ErrnoException, result?: number) => void ): void; ( file: PathLikeFs, flags: undefined | string | number, - callback: (arg0: null | NodeJS.ErrnoException, arg1?: number) => void + callback: (err: null | NodeJS.ErrnoException, result?: number) => void ): void; ( file: PathLikeFs, - callback: (arg0: null | NodeJS.ErrnoException, arg1?: number) => void + callback: (err: null | NodeJS.ErrnoException, result?: number) => void ): void; } @@ -10926,15 +10951,15 @@ declare interface OutputFileSystem { readdir?: ReaddirFs; rmdir?: Rmdir; unlink?: ( - arg0: PathLikeFs, - arg1: (arg0: null | NodeJS.ErrnoException) => void + pathLike: PathLikeFs, + callback: (err: null | NodeJS.ErrnoException) => void ) => void; stat: StatFs; lstat?: LStatFs; readFile: ReadFileFs; - join?: (arg0: string, arg1: string) => string; - relative?: (arg0: string, arg1: string) => string; - dirname?: (arg0: string) => string; + join?: (path1: string, path2: string) => string; + relative?: (from: string, to: string) => string; + dirname?: (dirname: string) => string; } /** @@ -11200,7 +11225,7 @@ declare interface OutputNormalized { workerWasmLoading?: string | false; } declare interface ParameterizedComparator { - (arg0: TArg): Comparator; + (tArg: TArg): Comparator; } declare interface ParsedIdentifier { request: string; @@ -11306,7 +11331,7 @@ declare interface ParserStateBase { declare interface PathData { chunkGraph?: ChunkGraph; hash?: string; - hashWithLength?: (arg0: number) => string; + hashWithLength?: (length: number) => string; chunk?: Chunk | ChunkPathData; module?: Module | ModulePathData; runtime?: RuntimeSpec; @@ -11315,7 +11340,7 @@ declare interface PathData { query?: string; contentHashType?: string; contentHash?: string; - contentHashWithLength?: (arg0: number) => string; + contentHashWithLength?: (length: number) => string; noChunkHash?: boolean; url?: string; } @@ -11751,7 +11776,7 @@ declare interface ReadFileFs { | undefined | null | ({ encoding?: null; flag?: string } & Abortable), - callback: (arg0: null | NodeJS.ErrnoException, arg1?: Buffer) => void + callback: (err: null | NodeJS.ErrnoException, result?: Buffer) => void ): void; ( path: PathOrFileDescriptorFs, @@ -11769,7 +11794,7 @@ declare interface ReadFileFs { | "base64" | "base64url" | "hex", - callback: (arg0: null | NodeJS.ErrnoException, arg1?: string) => void + callback: (err: null | NodeJS.ErrnoException, result?: string) => void ): void; ( path: PathOrFileDescriptorFs, @@ -11790,13 +11815,13 @@ declare interface ReadFileFs { | "hex" | (ObjectEncodingOptions & { flag?: string } & Abortable), callback: ( - arg0: null | NodeJS.ErrnoException, - arg1?: string | Buffer + err: null | NodeJS.ErrnoException, + result?: string | Buffer ) => void ): void; ( path: PathOrFileDescriptorFs, - callback: (arg0: null | NodeJS.ErrnoException, arg1?: Buffer) => void + callback: (err: null | NodeJS.ErrnoException, result?: Buffer) => void ): void; } declare interface ReadFileSync { @@ -11931,18 +11956,18 @@ declare interface ReaddirFs { withFileTypes?: false; recursive?: boolean; }, - callback: (arg0: null | NodeJS.ErrnoException, arg1?: string[]) => void + callback: (err: null | NodeJS.ErrnoException, result?: string[]) => void ): void; ( path: PathLikeFs, options: | "buffer" | { encoding: "buffer"; withFileTypes?: false; recursive?: boolean }, - callback: (arg0: null | NodeJS.ErrnoException, arg1?: Buffer[]) => void + callback: (err: null | NodeJS.ErrnoException, result?: Buffer[]) => void ): void; ( path: PathLikeFs, - callback: (arg0: null | NodeJS.ErrnoException, arg1?: string[]) => void + callback: (err: null | NodeJS.ErrnoException, result?: string[]) => void ): void; ( path: PathLikeFs, @@ -11966,8 +11991,8 @@ declare interface ReaddirFs { recursive?: boolean; }), callback: ( - arg0: null | NodeJS.ErrnoException, - arg1?: string[] | Buffer[] + err: null | NodeJS.ErrnoException, + result?: string[] | Buffer[] ) => void ): void; ( @@ -11976,7 +12001,7 @@ declare interface ReaddirFs { withFileTypes: true; recursive?: boolean; }, - callback: (arg0: null | NodeJS.ErrnoException, arg1?: Dirent[]) => void + callback: (err: null | NodeJS.ErrnoException, result?: Dirent[]) => void ): void; } declare interface ReaddirSync { @@ -12135,24 +12160,24 @@ declare interface ReadlinkFs { ( path: PathLikeFs, options: EncodingOption, - callback: (arg0: null | NodeJS.ErrnoException, arg1?: string) => void + callback: (err: null | NodeJS.ErrnoException, result?: string) => void ): void; ( path: PathLikeFs, options: BufferEncodingOption, - callback: (arg0: null | NodeJS.ErrnoException, arg1?: Buffer) => void + callback: (err: null | NodeJS.ErrnoException, result?: Buffer) => void ): void; ( path: PathLikeFs, options: EncodingOption, callback: ( - arg0: null | NodeJS.ErrnoException, - arg1?: string | Buffer + err: null | NodeJS.ErrnoException, + result?: string | Buffer ) => void ): void; ( path: PathLikeFs, - callback: (arg0: null | NodeJS.ErrnoException, arg1?: string) => void + callback: (err: null | NodeJS.ErrnoException, result?: string) => void ): void; } declare interface ReadlinkSync { @@ -12213,24 +12238,24 @@ declare interface RealPathFs { ( path: PathLikeFs, options: EncodingOption, - callback: (arg0: null | NodeJS.ErrnoException, arg1?: string) => void + callback: (err: null | NodeJS.ErrnoException, result?: string) => void ): void; ( path: PathLikeFs, options: BufferEncodingOption, - callback: (arg0: null | NodeJS.ErrnoException, arg1?: Buffer) => void + callback: (err: null | NodeJS.ErrnoException, result?: Buffer) => void ): void; ( path: PathLikeFs, options: EncodingOption, callback: ( - arg0: null | NodeJS.ErrnoException, - arg1?: string | Buffer + err: null | NodeJS.ErrnoException, + result?: string | Buffer ) => void ): void; ( path: PathLikeFs, - callback: (arg0: null | NodeJS.ErrnoException, arg1?: string) => void + callback: (err: null | NodeJS.ErrnoException, result?: string) => void ): void; } declare interface RealPathSync { @@ -12459,7 +12484,7 @@ declare interface RequestRecord { [index: string]: string | string[]; } declare abstract class RequestShortener { - contextify: (arg0: string) => string; + contextify: (value: string) => string; shorten(request?: null | string): undefined | null | string; } declare interface ResolveBuildDependenciesResult { @@ -13053,12 +13078,12 @@ declare interface RmDirOptions { declare interface Rmdir { ( file: PathLikeFs, - callback: (arg0: null | NodeJS.ErrnoException) => void + callback: (err: null | NodeJS.ErrnoException) => void ): void; ( file: PathLikeFs, options: RmDirOptions, - callback: (arg0: null | NodeJS.ErrnoException) => void + callback: (err: null | NodeJS.ErrnoException) => void ): void; } type Rule = string | RegExp; @@ -13071,7 +13096,7 @@ declare interface RuleSet { /** * execute the rule set */ - exec: (arg0: EffectData) => Effect[]; + exec: (effectData: EffectData) => Effect[]; } type RuleSetCondition = | string @@ -13563,7 +13588,7 @@ declare class RuntimeSpecMap { set(runtime: RuntimeSpec, value: T): void; provide(runtime: RuntimeSpec, computer: () => any): any; delete(runtime: RuntimeSpec): void; - update(runtime: RuntimeSpec, fn: (arg0?: T) => T): void; + update(runtime: RuntimeSpec, fn: (value?: T) => T): void; keys(): RuntimeSpec[]; values(): IterableIterator; get size(): number; @@ -13976,7 +14001,7 @@ declare abstract class RuntimeTemplate { }): string; } declare abstract class RuntimeValue { - fn: (arg0: { + fn: (value: { module: NormalModule; key: string; readonly version: ValueCacheVersion; @@ -14280,7 +14305,7 @@ declare interface SnapshotOptionsWebpackOptions { unmanagedPaths?: (string | RegExp)[]; } declare interface SortFunction { - (arg0: T, arg1: T): number; + (a: T, b: T): number; } declare abstract class SortableSet extends Set { /** @@ -14292,12 +14317,12 @@ declare abstract class SortableSet extends Set { /** * Get data from cache */ - getFromCache(fn: (arg0: SortableSet) => R): R; + getFromCache(fn: (set: SortableSet) => R): R; /** * Get data from cache (ignoring sorting) */ - getFromUnorderedCache(fn: (arg0: SortableSet) => R): R; + getFromUnorderedCache(fn: (set: SortableSet) => R): R; toJSON(): T[]; } declare class Source { @@ -14328,7 +14353,7 @@ declare class SourceMapDevToolPlugin { sourceMappingURLComment: | string | false - | ((arg0: PathData, arg1?: AssetInfo) => string); + | ((pathData: PathData, assetInfo?: AssetInfo) => string); moduleFilenameTemplate: string | Function; fallbackModuleFilenameTemplate: string | Function; namespace: string; @@ -14454,7 +14479,7 @@ declare interface SplitChunksOptions { maxAsyncRequests: number; maxInitialRequests: number; hidePathInfo: boolean; - filename?: string | ((arg0: PathData, arg1?: AssetInfo) => string); + filename?: string | ((pathData: PathData, assetInfo?: AssetInfo) => string); automaticNameDelimiter: string; getCacheGroups: ( module: Module, @@ -14500,24 +14525,24 @@ type StartupRenderContext = RenderContextJavascriptModulesPlugin & { declare interface StatFs { ( path: PathLikeFs, - callback: (arg0: null | NodeJS.ErrnoException, arg1?: IStats) => void + callback: (err: null | NodeJS.ErrnoException, result?: IStats) => void ): void; ( path: PathLikeFs, options: undefined | (StatOptions & { bigint?: false }), - callback: (arg0: null | NodeJS.ErrnoException, arg1?: IStats) => void + callback: (err: null | NodeJS.ErrnoException, result?: IStats) => void ): void; ( path: PathLikeFs, options: StatOptions & { bigint: true }, - callback: (arg0: null | NodeJS.ErrnoException, arg1?: IBigIntStats) => void + callback: (err: null | NodeJS.ErrnoException, result?: IBigIntStats) => void ): void; ( path: PathLikeFs, options: undefined | StatOptions, callback: ( - arg0: null | NodeJS.ErrnoException, - arg1?: IStats | IBigIntStats + err: null | NodeJS.ErrnoException, + result?: IStats | IBigIntStats ) => void ): void; } @@ -14685,7 +14710,7 @@ declare interface StatsFactoryHooks { >; sort: HookMap< SyncBailHook< - [((arg0?: any, arg1?: any) => 0 | 1 | -1)[], StatsFactoryContext], + [((a?: any, b?: any) => 0 | 1 | -1)[], StatsFactoryContext], void > >; @@ -14697,7 +14722,7 @@ declare interface StatsFactoryHooks { >; sortResults: HookMap< SyncBailHook< - [((arg0?: any, arg1?: any) => 0 | 1 | -1)[], StatsFactoryContext], + [((a?: any, b?: any) => 0 | 1 | -1)[], StatsFactoryContext], void > >; @@ -15216,7 +15241,7 @@ declare class SyncModuleIdsPlugin { /** * selector for modules */ - test: (arg0: Module) => boolean; + test?: (module: Module) => boolean; /** * operation mode (defaults to merge) */ @@ -15274,7 +15299,7 @@ declare class Template { static renderChunkModules( renderContext: ChunkRenderContextJavascriptModulesPlugin, modules: Module[], - renderModule: (arg0: Module) => null | Source, + renderModule: (module: Module) => null | Source, prefix?: string ): null | Source; static renderRuntimeModules( @@ -15290,7 +15315,9 @@ declare class Template { static NUMBER_OF_IDENTIFIER_START_CHARS: number; static NUMBER_OF_IDENTIFIER_CONTINUATION_CHARS: number; } -type TemplatePath = string | ((arg0: PathData, arg1?: AssetInfo) => string); +type TemplatePath = + | string + | ((pathData: PathData, assetInfo?: AssetInfo) => string); declare interface TimestampAndHash { safeTime: number; timestamp?: number; @@ -15363,13 +15390,13 @@ declare interface WatchFileSystem { startTime: number, options: WatchOptions, callback: ( - arg0: null | Error, - arg1?: Map, - arg2?: Map, - arg3?: Set, - arg4?: Set + err: null | Error, + timeInfoEntries1?: Map, + timeInfoEntries2?: Map, + canges?: Set, + removals?: Set ) => void, - callbackUndelayed: (arg0: string, arg1: number) => void + callbackUndelayed: (value: string, num: number) => void ) => Watcher; } declare class WatchIgnorePlugin { @@ -15578,7 +15605,7 @@ declare class WebpackError extends Error { static stackTraceLimit: number; } declare abstract class WebpackLogger { - getChildLogger: (arg0: string | (() => string)) => WebpackLogger; + getChildLogger: (name: string | (() => string)) => WebpackLogger; error(...args: any[]): void; warn(...args: any[]): void; info(...args: any[]): void; @@ -15840,7 +15867,7 @@ declare interface WithOptions { * create a resolver with additional/different options */ withOptions: ( - arg0: Partial + options: Partial ) => ResolverWithOptions; } declare interface WriteFile { @@ -15861,7 +15888,7 @@ declare interface WriteFile { | Float64Array | DataView, options: WriteFileOptions, - callback: (arg0: null | NodeJS.ErrnoException) => void + callback: (err: null | NodeJS.ErrnoException) => void ): void; ( file: PathOrFileDescriptorFs, @@ -15879,7 +15906,7 @@ declare interface WriteFile { | Float32Array | Float64Array | DataView, - callback: (arg0: null | NodeJS.ErrnoException) => void + callback: (err: null | NodeJS.ErrnoException) => void ): void; } type WriteFileOptions = @@ -15997,7 +16024,9 @@ declare namespace exports { callback?: CallbackWebpack ): MultiCompiler; }; - export const validate: (arg0: Configuration | Configuration[]) => void; + export const validate: ( + configuration: Configuration | Configuration[] + ) => void; export const validateSchema: ( schema: Parameters[0], options: Parameters[1], @@ -16207,7 +16236,7 @@ declare namespace exports { export let inferDependencyUsage: (state: ParserState) => void; export let onUsage: ( state: ParserState, - onUsageCallback: (arg0?: boolean | Set) => void + onUsageCallback: (value?: boolean | Set) => void ) => void; export let setTopLevelSymbol: ( state: ParserState, @@ -16233,7 +16262,10 @@ declare namespace exports { ) => | null | false - | ((arg0: ModuleGraphConnection, arg1: RuntimeSpec) => ConnectionState); + | (( + moduleGraphConnection: ModuleGraphConnection, + runtime: RuntimeSpec + ) => ConnectionState); export { TopLevelSymbol, topLevelSymbolTag }; } export { @@ -16378,7 +16410,7 @@ declare namespace exports { ) => RuntimeSpec; export let forEachRuntime: ( runtime: RuntimeSpec, - fn: (arg0?: string) => void, + fn: (runtime?: string) => void, deterministicOrder?: boolean ) => void; export let getRuntimeKey: (runtime: RuntimeSpec) => string; @@ -16419,7 +16451,7 @@ declare namespace exports { ) => RuntimeCondition; export let filterRuntime: ( runtime: RuntimeSpec, - filter: (arg0: RuntimeSpec) => boolean + filter: (runtime?: RuntimeSpec) => boolean ) => undefined | string | boolean | SortableSet; export { RuntimeSpecMap, RuntimeSpecSet }; } @@ -16432,7 +16464,7 @@ declare namespace exports { ) => void; export const registerLoader: ( regExp: RegExp, - loader: (arg0: string) => boolean + loader: (request: string) => boolean ) => void; export const registerNotSerializable: (Constructor: Constructor) => void; export const NOT_SERIALIZABLE: object; @@ -16449,12 +16481,12 @@ declare namespace exports { ) => T | O | (T & O); export function compileBooleanMatcher( map: Record - ): boolean | ((arg0: string) => string); + ): boolean | ((value: string) => string); export namespace compileBooleanMatcher { export let fromLists: ( positiveItems: string[], negativeItems: string[] - ) => (arg0: string) => string; + ) => (value: string) => string; export let itemsToRegexp: (itemsArr: string[]) => string; } export { LazySet };