diff --git a/lib/Chunk.js b/lib/Chunk.js index 3da64be39..dc69591c2 100644 --- a/lib/Chunk.js +++ b/lib/Chunk.js @@ -66,7 +66,7 @@ let debugId = 1000; */ class Chunk { /** - * @param {string=} name of chunk being created, is optional (for subclasses) + * @param {(string | null)=} name of chunk being created, is optional (for subclasses) * @param {boolean} backCompat enable backward-compatibility */ constructor(name, backCompat = true) { @@ -76,7 +76,7 @@ class Chunk { this.ids = null; /** @type {number} */ this.debugId = debugId++; - /** @type {string | undefined} */ + /** @type {string | null | undefined} */ this.name = name; /** @type {SortableSet} */ this.idNameHints = new SortableSet(); diff --git a/lib/Compilation.js b/lib/Compilation.js index 43defd8a3..fdd326682 100644 --- a/lib/Compilation.js +++ b/lib/Compilation.js @@ -174,7 +174,7 @@ const { isSourceEqual } = require("./util/source"); * @returns {any} */ -/** @typedef {new (...args: any[]) => Dependency} DepConstructor */ +/** @typedef {new (...args: EXPECTED_ANY[]) => Dependency} DepConstructor */ /** @typedef {Record} CompilationAssets */ @@ -220,41 +220,50 @@ const { isSourceEqual } = require("./util/source"); * @property {EntryOptions=} entryOptions */ +/** @typedef {Record} ExecuteModuleExports */ + /** * @typedef {object} ExecuteModuleResult - * @property {any} exports + * @property {ExecuteModuleExports} exports * @property {boolean} cacheable - * @property {Map} assets + * @property {Map} assets * @property {LazySet} fileDependencies * @property {LazySet} contextDependencies * @property {LazySet} missingDependencies * @property {LazySet} buildDependencies */ -/** @typedef {(id: string) => void} WebpackRequire */ - /** - * @typedef {{ id: string | undefined, exports: any, loaded: boolean, error?: Error }} ModuleObject - */ - -/** - * @typedef {{ id: string | undefined, module: ModuleObject, require: WebpackRequire }} ExecuteOptions + * @typedef {object} ExecuteModuleObject + * @property {string} [id] module id + * @property {ExecuteModuleExports} exports exports + * @property {boolean} loaded is loaded + * @property {Error} [error] error */ /** * @typedef {object} ExecuteModuleArgument * @property {Module} module - * @property {ModuleObject=} moduleObject + * @property {ExecuteModuleObject=} moduleObject * @property {any} preparedInfo * @property {CodeGenerationResult} codeGenerationResult */ +/** @typedef {((id: string) => ExecuteModuleExports) & { i?: ((options: ExecuteOptions) => void)[], c?: Record }} WebpackRequire */ + +/** + * @typedef {object} ExecuteOptions + * @property {string} [id] module id + * @property {ExecuteModuleObject} module module + * @property {WebpackRequire} require require function + */ + /** * @typedef {object} ExecuteModuleContext - * @property {Map} assets + * @property {Map} assets * @property {Chunk} chunk * @property {ChunkGraph} chunkGraph - * @property {function(string): any=} __webpack_require__ + * @property {WebpackRequire=} __webpack_require__ */ /** @@ -373,7 +382,7 @@ const { isSourceEqual } = require("./util/source"); * @property {boolean=} forToString */ -/** @typedef {Record & KnownCreateStatsOptionsContext} CreateStatsOptionsContext */ +/** @typedef {KnownCreateStatsOptionsContext & Record} CreateStatsOptionsContext */ /** @typedef {{ module: Module, hash: string, runtime: RuntimeSpec, runtimes: RuntimeSpec[]}} CodeGenerationJob */ @@ -523,11 +532,16 @@ class Compilation { return { ...remainingTap, type: "async", + /** + * @param {CompilationAssets} assets assets + * @param {(err?: Error | null, result?: void) => void} callback callback + * @returns {void} + */ fn: (assets, callback) => { try { fn(assets); } catch (err) { - return callback(err); + return callback(/** @type {Error} */ (err)); } if (processedAssets !== undefined) processedAssets.add(this.assets); @@ -558,21 +572,33 @@ class Compilation { } return { ...remainingTap, + /** + * @param {CompilationAssets} assets assets + * @param {(err?: Error | null, result?: void) => void} callback callback + * @returns {void} + */ fn: (assets, callback) => { - fn(assets, err => { - if (err) return callback(err); - if (processedAssets !== undefined) - processedAssets.add(this.assets); - const newAssets = popNewAssets(assets); - if (newAssets !== undefined) { - this.hooks.processAdditionalAssets.callAsync( - newAssets, - callback - ); - return; + fn( + assets, + /** + * @param {Error} err err + * @returns {void} + */ + err => { + if (err) return callback(err); + if (processedAssets !== undefined) + processedAssets.add(this.assets); + const newAssets = popNewAssets(assets); + if (newAssets !== undefined) { + this.hooks.processAdditionalAssets.callAsync( + newAssets, + callback + ); + return; + } + callback(); } - callback(); - }); + ); } }; case "promise": @@ -588,6 +614,10 @@ class Compilation { } return { ...remainingTap, + /** + * @param {CompilationAssets} assets assets + * @returns {Promise} result + */ fn: assets => { const p = fn(assets); if (!p || !p.then) return p; @@ -619,6 +649,7 @@ class Compilation { * @returns {FakeHook, "tap" | "tapAsync" | "tapPromise" | "name">>} fake hook which redirects */ const createProcessAssetsHook = (name, stage, getArgs, code) => { + // @ts-expect-error For better compatibility we will avoid the optional type if (!this._backCompat && code) return; /** * @param {string} reason reason @@ -627,6 +658,10 @@ class Compilation { const errorMessage = reason => `Can't automatically convert plugin using Compilation.hooks.${name} to Compilation.hooks.processAssets because ${reason}. BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a single Compilation.hooks.processAssets hook.`; + /** + * @param {string | (import("tapable").TapOptions & { name: string; } & ProcessAssetsAdditionalOptions)} options hook options + * @returns {import("tapable").TapOptions & { name: string; } & ProcessAssetsAdditionalOptions} modified options + */ const getOptions = options => { if (typeof options === "string") options = { name: options }; if (options.stage) { @@ -999,9 +1034,9 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si this.moduleMemCaches2 = undefined; this.moduleGraph = new ModuleGraph(); /** @type {ChunkGraph} */ - this.chunkGraph = undefined; + this.chunkGraph = /** @type {TODO} */ (undefined); /** @type {CodeGenerationResults} */ - this.codeGenerationResults = undefined; + this.codeGenerationResults = /** @type {TODO} */ (undefined); /** @type {AsyncQueue} */ this.processDependenciesQueue = new AsyncQueue({ @@ -2017,7 +2052,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si /** * @private - * @param {Module} originModule original module + * @param {Module | null} originModule original module * @param {Module} module module * @param {boolean} recursive true if make it recursive, otherwise false * @param {boolean} checkCycle true if need to check cycle, otherwise false @@ -2034,14 +2069,20 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si // Check for cycles when build is trigger inside another build /** @type {Set | undefined} */ let creatingModuleDuringBuildSet; - if (checkCycle && this.buildQueue.isProcessing(originModule)) { + if ( + checkCycle && + this.buildQueue.isProcessing(/** @type {Module} */ (originModule)) + ) { // Track build dependency - creatingModuleDuringBuildSet = - this.creatingModuleDuringBuild.get(originModule); + creatingModuleDuringBuildSet = this.creatingModuleDuringBuild.get( + /** @type {Module} */ + (originModule) + ); if (creatingModuleDuringBuildSet === undefined) { creatingModuleDuringBuildSet = new Set(); this.creatingModuleDuringBuild.set( - originModule, + /** @type {Module} */ + (originModule), creatingModuleDuringBuildSet ); } @@ -2123,7 +2164,9 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si factory.create( { contextInfo: { - issuer: originModule ? originModule.nameForCondition() : "", + issuer: originModule + ? /** @type {string} */ (originModule.nameForCondition()) + : "", issuerLayer: originModule ? originModule.layer : null, compiler: /** @type {string} */ (this.compiler.name), ...contextInfo @@ -2320,9 +2363,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si continue; } if (entryData.options[key] === undefined) { - entryData.options[/** @type {TODO} */ (key)] = /** @type {TODO} */ ( - options[key] - ); + entryData.options[key] = /** @type {TODO} */ (options[key]); } else { return callback( new WebpackError( @@ -3886,7 +3927,7 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o /** * This method first looks to see if a name is provided for a new chunk, * and first looks to see if any named chunks already exist and reuse that chunk instead. - * @param {string=} name optional chunk name to be provided + * @param {(string | null)=} name optional chunk name to be provided * @returns {Chunk} create a chunk (invoked during seal event) */ addChunk(name) { @@ -5300,6 +5341,7 @@ This prevents using hashes of each other and should be avoided.`); err => { if (err) return callback(err); + /** @type {ExecuteModuleExports | undefined} */ let exports; try { const { @@ -5314,25 +5356,30 @@ This prevents using hashes of each other and should be avoided.`); if (cached.error) throw cached.error; return cached.exports; } - const moduleArgument = - /** @type {TODO} */ - (moduleArgumentsById).get(id); - return __webpack_require_module__(moduleArgument, id); + const moduleArgument = moduleArgumentsById.get(id); + return __webpack_require_module__( + /** @type {ExecuteModuleArgument} */ + (moduleArgument), + id + ); }; - /** @type {((options: ExecuteOptions) => void)[]} */ const interceptModuleExecution = (__webpack_require__[ - RuntimeGlobals.interceptModuleExecution.replace( - `${RuntimeGlobals.require}.`, - "" + /** @type {"i"} */ + ( + RuntimeGlobals.interceptModuleExecution.replace( + `${RuntimeGlobals.require}.`, + "" + ) ) - ] = []); - /** @type {Record} */ + ] = /** @type {NonNullable} */ ([])); const moduleCache = (__webpack_require__[ - RuntimeGlobals.moduleCache.replace( - `${RuntimeGlobals.require}.`, - "" + /** @type {"c"} */ ( + RuntimeGlobals.moduleCache.replace( + `${RuntimeGlobals.require}.`, + "" + ) ) - ] = {}); + ] = /** @type {NonNullable} */ ({})); context.__webpack_require__ = __webpack_require__; @@ -5399,13 +5446,14 @@ This prevents using hashes of each other and should be avoided.`); } exports = __webpack_require__(module.identifier()); } catch (execErr) { - const { message, stack, module } = /** @type {TODO} */ ( - execErr - ); + const { message, stack, module } = + /** @type {WebpackError} */ + (execErr); const err = new WebpackError( - `Execution of module code from module graph (${module.readableIdentifier( - this.requestShortener - )}) failed: ${message}` + `Execution of module code from module graph (${ + /** @type {Module} */ + (module).readableIdentifier(this.requestShortener) + }) failed: ${message}` ); err.stack = stack; err.module = module; @@ -5495,7 +5543,7 @@ Compilation.prototype.factorizeModule = /** (options: FactorizeModuleOptions & { factoryResult: true }, callback: ModuleFactoryResultCallback): void; }} */ ( function (options, callback) { - this.factorizeQueue.add(options, callback); + this.factorizeQueue.add(options, /** @type {TODO} */ (callback)); } ); /* eslint-enable jsdoc/require-asterisk-prefix */ diff --git a/lib/Compiler.js b/lib/Compiler.js index 99d466ec9..1a5a7a005 100644 --- a/lib/Compiler.js +++ b/lib/Compiler.js @@ -42,7 +42,6 @@ const { isSourceEqual } = require("./util/source"); /** @typedef {import("./Chunk")} Chunk */ /** @typedef {import("./Compilation").References} References */ /** @typedef {import("./Dependency")} Dependency */ -/** @typedef {import("./FileSystemInfo").FileSystemInfoEntry} FileSystemInfoEntry */ /** @typedef {import("./Module")} Module */ /** @typedef {import("./Module").BuildInfo} BuildInfo */ /** @typedef {import("./config/target").PlatformTargetProperties} PlatformTargetProperties */ @@ -51,6 +50,7 @@ const { isSourceEqual } = require("./util/source"); /** @typedef {import("./util/fs").InputFileSystem} InputFileSystem */ /** @typedef {import("./util/fs").IntermediateFileSystem} IntermediateFileSystem */ /** @typedef {import("./util/fs").OutputFileSystem} OutputFileSystem */ +/** @typedef {import("./util/fs").TimeInfoEntries} TimeInfoEntries */ /** @typedef {import("./util/fs").WatchFileSystem} WatchFileSystem */ /** @@ -259,9 +259,9 @@ class Compiler { this.modifiedFiles = undefined; /** @type {ReadonlySet | undefined} */ this.removedFiles = undefined; - /** @type {ReadonlyMap | undefined} */ + /** @type {TimeInfoEntries | undefined} */ this.fileTimestamps = undefined; - /** @type {ReadonlyMap | undefined} */ + /** @type {TimeInfoEntries | undefined} */ this.contextTimestamps = undefined; /** @type {number | undefined} */ this.fsStartTime = undefined; diff --git a/lib/EnvironmentPlugin.js b/lib/EnvironmentPlugin.js index eb9e37a6d..9e983e567 100644 --- a/lib/EnvironmentPlugin.js +++ b/lib/EnvironmentPlugin.js @@ -13,7 +13,7 @@ const WebpackError = require("./WebpackError"); class EnvironmentPlugin { /** - * @param {(string | string[] | Record)[]} keys keys + * @param {(string | string[] | Record)[]} keys keys */ constructor(...keys) { if (keys.length === 1 && Array.isArray(keys[0])) { @@ -22,7 +22,9 @@ class EnvironmentPlugin { this.defaultValues = {}; } else if (keys.length === 1 && keys[0] && typeof keys[0] === "object") { this.keys = Object.keys(keys[0]); - this.defaultValues = /** @type {Record} */ (keys[0]); + this.defaultValues = + /** @type {Record} */ + (keys[0]); } else { this.keys = /** @type {string[]} */ (keys); this.defaultValues = {}; diff --git a/lib/ExportsInfo.js b/lib/ExportsInfo.js index fedbb2742..0aac9f7e5 100644 --- a/lib/ExportsInfo.js +++ b/lib/ExportsInfo.js @@ -10,6 +10,7 @@ const SortableSet = require("./util/SortableSet"); const makeSerializable = require("./util/makeSerializable"); const { forEachRuntime } = require("./util/runtime"); +/** @typedef {import("./Dependency")} Dependency */ /** @typedef {import("./Dependency").RuntimeSpec} RuntimeSpec */ /** @typedef {import("./Module")} Module */ /** @typedef {import("./ModuleGraph")} ModuleGraph */ @@ -294,7 +295,7 @@ class ExportsInfo { /** * @param {boolean=} canMangle true, if exports can still be mangled (defaults to false) * @param {Set=} excludeExports list of unaffected exports - * @param {any=} targetKey use this as key for the target + * @param {Dependency=} targetKey use this as key for the target * @param {ModuleGraphConnection=} targetModule set this module as target * @param {number=} priority priority * @returns {boolean} true, if this call changed something @@ -783,7 +784,7 @@ class ExportsInfo { } /** - * @param {{ otherProvided: any, otherCanMangleProvide: any, otherTerminalBinding: any, exports: any }} data data + * @param {RestoreProvidedData} data data */ restoreProvided({ otherProvided, @@ -818,10 +819,10 @@ class ExportsInfo { /** @typedef {Map} UsedInRuntime */ /** @typedef {{ module: Module, export: string[] }} TargetItemWithoutConnection */ +/** @typedef {{ module: Module, connection: ModuleGraphConnection, export: string[] | undefined }} TargetItemWithConnection */ -/** @typedef {{ module: Module, connection: ModuleGraphConnection, export: string[] | undefined }} TargetItem */ - -/** @typedef {Map} Target */ +/** @typedef {{ connection: ModuleGraphConnection, export: string[], priority: number }} TargetItem */ +/** @typedef {Map} Target */ class ExportInfo { /** @@ -1107,7 +1108,7 @@ class ExportInfo { } /** - * @param {any} key the key + * @param {Dependency} key the key * @returns {boolean} true, if something has changed */ unsetTarget(key) { @@ -1120,7 +1121,7 @@ class ExportInfo { } /** - * @param {any} key the key + * @param {Dependency} key the key * @param {ModuleGraphConnection} connection the target module if a single one * @param {(string[] | null)=} exportName the exported name * @param {number=} priority priority @@ -1251,7 +1252,7 @@ class ExportInfo { /** * @param {ModuleGraph} moduleGraph the module graph - * @param {function(TargetItem): boolean} resolveTargetFilter filter function to further resolve target + * @param {function(TargetItemWithConnection): boolean} resolveTargetFilter filter function to further resolve target * @returns {ExportInfo | ExportsInfo | undefined} the terminal binding export(s) info if known */ getTerminalBinding(moduleGraph, resolveTargetFilter = RETURNS_TRUE) { @@ -1344,8 +1345,8 @@ class ExportInfo { /** * @param {ModuleGraph} moduleGraph the module graph - * @param {function(TargetItem): boolean} resolveTargetFilter filter function to further resolve target - * @returns {TargetItem | undefined} the target + * @param {function(TargetItemWithConnection): boolean} resolveTargetFilter filter function to further resolve target + * @returns {TargetItemWithConnection | undefined} the target */ getTarget(moduleGraph, resolveTargetFilter = RETURNS_TRUE) { const result = this._getTarget(moduleGraph, resolveTargetFilter, undefined); @@ -1355,15 +1356,15 @@ class ExportInfo { /** * @param {ModuleGraph} moduleGraph the module graph - * @param {function(TargetItem): boolean} resolveTargetFilter filter function to further resolve target + * @param {function(TargetItemWithConnection): boolean} resolveTargetFilter filter function to further resolve target * @param {Set | undefined} alreadyVisited set of already visited export info to avoid circular references - * @returns {TargetItem | CIRCULAR | undefined} the target + * @returns {TargetItemWithConnection | CIRCULAR | undefined} the target */ _getTarget(moduleGraph, resolveTargetFilter, alreadyVisited) { /** - * @param {TargetItem | null} inputTarget unresolved target + * @param {TargetItem | undefined | null} inputTarget unresolved target * @param {Set} alreadyVisited set of already visited export info to avoid circular references - * @returns {TargetItem | CIRCULAR | null} resolved target + * @returns {TargetItemWithConnection | CIRCULAR | null} resolved target */ const resolveTarget = (inputTarget, alreadyVisited) => { if (!inputTarget) return null; @@ -1374,7 +1375,7 @@ class ExportInfo { export: undefined }; } - /** @type {TargetItem} */ + /** @type {TargetItemWithConnection} */ let target = { module: inputTarget.connection.module, connection: inputTarget.connection, @@ -1385,7 +1386,7 @@ class ExportInfo { for (;;) { const exportsInfo = moduleGraph.getExportsInfo(target.module); const exportInfo = exportsInfo.getExportInfo( - /** @type {NonNullable} */ + /** @type {NonNullable} */ (target.export)[0] ); if (!exportInfo) return target; @@ -1398,7 +1399,7 @@ class ExportInfo { if (newTarget === CIRCULAR) return CIRCULAR; if (!newTarget) return target; if ( - /** @type {NonNullable} */ + /** @type {NonNullable} */ (target.export).length === 1 ) { target = newTarget; @@ -1409,10 +1410,10 @@ class ExportInfo { connection: newTarget.connection, export: newTarget.export ? newTarget.export.concat( - /** @type {NonNullable} */ + /** @type {NonNullable} */ (target.export).slice(1) ) - : /** @type {NonNullable} */ + : /** @type {NonNullable} */ (target.export).slice(1) }; } @@ -1453,18 +1454,20 @@ class ExportInfo { /** * Move the target forward as long resolveTargetFilter is fulfilled * @param {ModuleGraph} moduleGraph the module graph - * @param {function(TargetItem): boolean} resolveTargetFilter filter function to further resolve target - * @param {function(TargetItem): ModuleGraphConnection=} updateOriginalConnection updates the original connection instead of using the target connection - * @returns {TargetItem | undefined} the resolved target when moved + * @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 + * @returns {TargetItemWithConnection | undefined} the resolved target when moved */ moveTarget(moduleGraph, resolveTargetFilter, updateOriginalConnection) { const target = this._getTarget(moduleGraph, resolveTargetFilter, undefined); if (target === CIRCULAR) return; if (!target) return; - const originalTarget = /** @type {TargetItem} */ ( - /** @type {Target} */ - (this._getMaxTarget()).values().next().value - ); + const originalTarget = + /** @type {TargetItem} */ + ( + /** @type {Target} */ + (this._getMaxTarget()).values().next().value + ); if ( originalTarget.connection === target.connection && originalTarget.export === target.export @@ -1478,7 +1481,9 @@ class ExportInfo { connection: updateOriginalConnection ? updateOriginalConnection(target) : target.connection, - export: /** @type {NonNullable} */ (target.export), + export: /** @type {NonNullable} */ ( + target.export + ), priority: 0 }); return target; @@ -1643,3 +1648,4 @@ class ExportInfo { module.exports = ExportsInfo; module.exports.ExportInfo = ExportInfo; module.exports.UsageState = UsageState; +module.exports.RestoreProvidedData = RestoreProvidedData; diff --git a/lib/FileSystemInfo.js b/lib/FileSystemInfo.js index ed7f327a2..3ced1e4f2 100644 --- a/lib/FileSystemInfo.js +++ b/lib/FileSystemInfo.js @@ -73,12 +73,14 @@ const INVALID = Symbol("invalid"); * @property {string=} timestampHash */ +/** @typedef {Set} Symlinks */ + /** * @typedef {object} ContextFileSystemInfoEntry * @property {number} safeTime * @property {string=} timestampHash * @property {ResolvedContextFileSystemInfoEntry=} resolved - * @property {Set=} symlinks + * @property {Symlinks=} symlinks */ /** @@ -95,8 +97,6 @@ const INVALID = Symbol("invalid"); * @property {string} hash */ -/** @typedef {Set} Symlinks */ - /** * @typedef {object} ContextTimestampAndHash * @property {number} safeTime @@ -123,16 +123,26 @@ const INVALID = Symbol("invalid"); * @property {Set | undefined} children */ +/** @typedef {Map} ResolveResults */ + +/** @typedef {Set} Files */ +/** @typedef {Set} Directories */ +/** @typedef {Set} Missing */ + +/** + * @typedef {object} ResolveDependencies + * @property {Files} files list of files + * @property {Directories} directories list of directories + * @property {Missing} missing list of missing entries + */ + /** * @typedef {object} ResolveBuildDependenciesResult - * @property {Set} files list of files - * @property {Set} directories list of directories - * @property {Set} missing list of missing entries - * @property {Map} resolveResults stored resolve results - * @property {object} resolveDependencies dependencies of the resolving - * @property {Set} resolveDependencies.files list of files - * @property {Set} resolveDependencies.directories list of directories - * @property {Set} resolveDependencies.missing list of missing entries + * @property {Files} files list of files + * @property {Directories} directories list of directories + * @property {Missing} missing list of missing entries + * @property {ResolveResults} resolveResults stored resolve results + * @property {ResolveDependencies} resolveDependencies dependencies of the resolving */ /** @@ -1031,6 +1041,10 @@ const addAll = (source, target) => { /** @typedef {Set} LoggedPaths */ +/** @typedef {FileSystemInfoEntry | "ignore" | null} FileTimestamp */ +/** @typedef {ContextFileSystemInfoEntry | "ignore" | null} ContextTimestamp */ +/** @typedef {ResolvedContextFileSystemInfoEntry | "ignore" | null} ResolvedContextTimestamp */ + /** * Used to access information about the filesystem in a cached way */ @@ -1127,13 +1141,13 @@ class FileSystemInfo { false, true ); - /** @type {StackedCacheMap} */ + /** @type {StackedCacheMap} */ this._fileTimestamps = new StackedCacheMap(); /** @type {Map} */ this._fileHashes = new Map(); /** @type {Map} */ this._fileTshs = new Map(); - /** @type {StackedCacheMap} */ + /** @type {StackedCacheMap} */ this._contextTimestamps = new StackedCacheMap(); /** @type {Map} */ this._contextHashes = new Map(); @@ -1184,28 +1198,34 @@ class FileSystemInfo { processor: this._getManagedItemDirectoryInfo.bind(this) }); const _unmanagedPaths = Array.from(unmanagedPaths); - this.unmanagedPathsWithSlash = /** @type {string[]} */ ( - _unmanagedPaths.filter(p => typeof p === "string") - ).map(p => join(fs, p, "_").slice(0, -1)); - this.unmanagedPathsRegExps = /** @type {RegExp[]} */ ( - _unmanagedPaths.filter(p => typeof p !== "string") - ); + this.unmanagedPathsWithSlash = + /** @type {string[]} */ + (_unmanagedPaths.filter(p => typeof p === "string")).map(p => + join(fs, p, "_").slice(0, -1) + ); + this.unmanagedPathsRegExps = + /** @type {RegExp[]} */ + (_unmanagedPaths.filter(p => typeof p !== "string")); this.managedPaths = Array.from(managedPaths); - this.managedPathsWithSlash = /** @type {string[]} */ ( - this.managedPaths.filter(p => typeof p === "string") - ).map(p => join(fs, p, "_").slice(0, -1)); + this.managedPathsWithSlash = + /** @type {string[]} */ + (this.managedPaths.filter(p => typeof p === "string")).map(p => + join(fs, p, "_").slice(0, -1) + ); - this.managedPathsRegExps = /** @type {RegExp[]} */ ( - this.managedPaths.filter(p => typeof p !== "string") - ); + this.managedPathsRegExps = + /** @type {RegExp[]} */ + (this.managedPaths.filter(p => typeof p !== "string")); this.immutablePaths = Array.from(immutablePaths); - this.immutablePathsWithSlash = /** @type {string[]} */ ( - this.immutablePaths.filter(p => typeof p === "string") - ).map(p => join(fs, p, "_").slice(0, -1)); - this.immutablePathsRegExps = /** @type {RegExp[]} */ ( - this.immutablePaths.filter(p => typeof p !== "string") - ); + this.immutablePathsWithSlash = + /** @type {string[]} */ + (this.immutablePaths.filter(p => typeof p === "string")).map(p => + join(fs, p, "_").slice(0, -1) + ); + this.immutablePathsRegExps = + /** @type {RegExp[]} */ + (this.immutablePaths.filter(p => typeof p !== "string")); this._cachedDeprecatedFileTimestamps = undefined; this._cachedDeprecatedContextTimestamps = undefined; @@ -1310,6 +1330,7 @@ class FileSystemInfo { } /** + * @private * @param {string} path path * @param {string} reason reason * @param {any[]} args arguments @@ -1366,7 +1387,7 @@ class FileSystemInfo { } /** - * @param {ReadonlyMap} map timestamps + * @param {ReadonlyMap} map timestamps * @param {boolean=} immutable if 'map' is immutable and FileSystemInfo can keep referencing it * @returns {void} */ @@ -1376,7 +1397,7 @@ class FileSystemInfo { } /** - * @param {ReadonlyMap} map timestamps + * @param {ReadonlyMap} map timestamps * @param {boolean=} immutable if 'map' is immutable and FileSystemInfo can keep referencing it * @returns {void} */ @@ -1387,7 +1408,7 @@ class FileSystemInfo { /** * @param {string} path file path - * @param {function((WebpackError | null)=, (FileSystemInfoEntry | "ignore" | null)=): void} callback callback function + * @param {function((WebpackError | null)=, FileTimestamp=): void} callback callback function * @returns {void} */ getFileTimestamp(path, callback) { @@ -1398,7 +1419,7 @@ class FileSystemInfo { /** * @param {string} path context path - * @param {function((WebpackError | null)=, (ResolvedContextFileSystemInfoEntry | "ignore" | null)=): void} callback callback function + * @param {function((WebpackError | null)=, ResolvedContextTimestamp=): void} callback callback function * @returns {void} */ getContextTimestamp(path, callback) { @@ -1423,8 +1444,9 @@ class FileSystemInfo { } /** + * @private * @param {string} path context path - * @param {function((WebpackError | null)=, (ContextFileSystemInfoEntry | "ignore" | null)=): void} callback callback function + * @param {function((WebpackError | null)=, ContextTimestamp=): void} callback callback function * @returns {void} */ _getUnresolvedContextTimestamp(path, callback) { @@ -1468,6 +1490,7 @@ class FileSystemInfo { } /** + * @private * @param {string} path context path * @param {function((WebpackError | null)=, (ContextHash | null)=): void} callback callback function * @returns {void} @@ -1500,6 +1523,7 @@ class FileSystemInfo { } /** + * @private * @param {string} path context path * @param {function((WebpackError | null)=, (ContextTimestampAndHash | null)=): void} callback callback function * @returns {void} @@ -1548,24 +1572,25 @@ class FileSystemInfo { const { resolveContext, resolveEsm, resolveCjs, resolveCjsAsChild } = this._createBuildDependenciesResolvers(); - /** @type {Set} */ + /** @type {Files} */ const files = new Set(); - /** @type {Set} */ + /** @type {Symlinks} */ const fileSymlinks = new Set(); - /** @type {Set} */ + /** @type {Directories} */ const directories = new Set(); - /** @type {Set} */ + /** @type {Symlinks} */ const directorySymlinks = new Set(); - /** @type {Set} */ + /** @type {Missing} */ const missing = new Set(); - /** @type {Set} */ + /** @type {ResolveDependencies["files"]} */ const resolveFiles = new Set(); - /** @type {Set} */ + /** @type {ResolveDependencies["directories"]} */ const resolveDirectories = new Set(); - /** @type {Set} */ + /** @type {ResolveDependencies["missing"]} */ const resolveMissing = new Set(); - /** @type {Map} */ + /** @type {ResolveResults} */ const resolveResults = new Map(); + /** @type {Set} */ const invalidResolveResults = new Set(); const resolverContext = { fileDependencies: resolveFiles, @@ -2059,7 +2084,7 @@ class FileSystemInfo { } /** - * @param {Map} resolveResults results from resolving + * @param {ResolveResults} resolveResults results from resolving * @param {function((Error | null)=, boolean=): void} callback callback with true when resolveResults resolve the same way * @returns {void} */ @@ -2234,7 +2259,7 @@ class FileSystemInfo { }; /** * @param {string} path path - * @param {Set} managedSet managed set + * @param {ManagedFiles} managedSet managed set * @returns {boolean} true when managed */ const checkManaged = (path, managedSet) => { @@ -2285,6 +2310,7 @@ class FileSystemInfo { * @returns {Set} result */ const captureNonManaged = (items, managedSet) => { + /** @type {Set} */ const capturedItems = new Set(); for (const path of items) { if (!checkManaged(path, managedSet)) capturedItems.add(path); @@ -2292,7 +2318,7 @@ class FileSystemInfo { return capturedItems; }; /** - * @param {Set} capturedFiles captured files + * @param {ManagedFiles} capturedFiles captured files */ const processCapturedFiles = capturedFiles => { switch (mode) { @@ -2380,7 +2406,7 @@ class FileSystemInfo { processCapturedFiles(captureNonManaged(files, managedFiles)); } /** - * @param {Set} capturedDirectories captured directories + * @param {ManagedContexts} capturedDirectories captured directories */ const processCapturedDirectories = capturedDirectories => { switch (mode) { @@ -2485,7 +2511,7 @@ class FileSystemInfo { jobs++; /** * @param {(Error | null)=} err error - * @param {(FileSystemInfoEntry | "ignore" | null)=} entry entry + * @param {FileTimestamp=} entry entry * @returns {void} */ const callback = (err, entry) => { @@ -2525,7 +2551,7 @@ class FileSystemInfo { ); } /** - * @param {Set} capturedMissing captured missing + * @param {ManagedMissing} capturedMissing captured missing */ const processCapturedMissing = capturedMissing => { this._missingExistenceOptimization.optimize(snapshot, capturedMissing); @@ -2716,6 +2742,7 @@ class FileSystemInfo { } /** + * @private * @param {Snapshot} snapshot the snapshot made * @param {function((WebpackError | null)=, boolean=): void} callback callback function * @returns {void} @@ -3019,7 +3046,7 @@ class FileSystemInfo { jobs++; /** * @param {(WebpackError | null)=} err error - * @param {(ResolvedContextFileSystemInfoEntry | "ignore" | null)=} entry entry + * @param {ResolvedContextTimestamp=} entry entry * @returns {void} */ const callback = (err, entry) => { @@ -3123,7 +3150,7 @@ class FileSystemInfo { jobs++; /** * @param {(WebpackError | null)=} err error - * @param {(ResolvedContextFileSystemInfoEntry | "ignore" | null)=} entry entry + * @param {ResolvedContextTimestamp=} entry entry * @returns {void} */ const callback = (err, entry) => { @@ -3222,8 +3249,8 @@ class FileSystemInfo { } /** - * @type {Processor} * @private + * @type {Processor} */ _readFileTimestamp(path, callback) { this.fs.stat(path, (err, _stat) => { @@ -3261,8 +3288,8 @@ class FileSystemInfo { } /** - * @type {Processor} * @private + * @type {Processor} */ _readFileHash(path, callback) { this.fs.readFile(path, (err, content) => { @@ -3297,9 +3324,9 @@ class FileSystemInfo { } /** + * @private * @param {string} path path * @param {function(WebpackError | null, TimestampAndHash=) : void} callback callback - * @private */ _getFileTimestampAndHash(path, callback) { /** @@ -3349,6 +3376,7 @@ class FileSystemInfo { } /** + * @private * @template T * @template ItemType * @param {object} options options @@ -3460,8 +3488,8 @@ class FileSystemInfo { } /** - * @type {Processor} * @private + * @type {Processor} */ _readContextTimestamp(path, callback) { this._readContext( @@ -3575,8 +3603,9 @@ class FileSystemInfo { } /** + * @private * @param {ContextFileSystemInfoEntry} entry entry - * @param {function((WebpackError | null)=, (ResolvedContextFileSystemInfoEntry | "ignore" | null)=): void} callback callback + * @param {function((WebpackError | null)=, ResolvedContextTimestamp=): void} callback callback * @returns {void} */ _resolveContextTimestamp(entry, callback) { @@ -3624,8 +3653,8 @@ class FileSystemInfo { } /** - * @type {Processor} * @private + * @type {Processor} */ _readContextHash(path, callback) { this._readContext( @@ -3694,6 +3723,7 @@ class FileSystemInfo { } /** + * @private * @param {ContextHash} entry context hash * @param {function(WebpackError | null, string=): void} callback callback * @returns {void} @@ -3733,12 +3763,12 @@ class FileSystemInfo { } /** - * @type {Processor} * @private + * @type {Processor} */ _readContextTimestampAndHash(path, callback) { /** - * @param {ContextFileSystemInfoEntry | "ignore" | null} timestamp timestamp + * @param {ContextTimestamp} timestamp timestamp * @param {ContextHash} hash hash */ const finalize = (timestamp, hash) => { @@ -3864,6 +3894,7 @@ class FileSystemInfo { } /** + * @private * @param {ContextTimestampAndHash} entry entry * @param {ProcessorCallback} callback callback * @returns {void} @@ -3923,8 +3954,8 @@ class FileSystemInfo { } /** - * @type {Processor>} * @private + * @type {Processor>} */ _getManagedItemDirectoryInfo(path, callback) { this.fs.readdir(path, (err, elements) => { @@ -3944,8 +3975,8 @@ class FileSystemInfo { } /** - * @type {Processor} * @private + * @type {Processor} */ _getManagedItemInfo(path, callback) { const dir = dirname(this.fs, path); @@ -4019,6 +4050,7 @@ class FileSystemInfo { getDeprecatedFileTimestamps() { if (this._cachedDeprecatedFileTimestamps !== undefined) return this._cachedDeprecatedFileTimestamps; + /** @type {Map} */ const map = new Map(); for (const [path, info] of this._fileTimestamps) { if (info) map.set(path, typeof info === "object" ? info.safeTime : null); @@ -4029,6 +4061,7 @@ class FileSystemInfo { getDeprecatedContextTimestamps() { if (this._cachedDeprecatedContextTimestamps !== undefined) return this._cachedDeprecatedContextTimestamps; + /** @type {Map} */ const map = new Map(); for (const [path, info] of this._contextTimestamps) { if (info) map.set(path, typeof info === "object" ? info.safeTime : null); diff --git a/lib/FlagDependencyExportsPlugin.js b/lib/FlagDependencyExportsPlugin.js index aacbb3d27..c7737d4b4 100644 --- a/lib/FlagDependencyExportsPlugin.js +++ b/lib/FlagDependencyExportsPlugin.js @@ -14,6 +14,7 @@ const Queue = require("./util/Queue"); /** @typedef {import("./Dependency").ExportSpec} ExportSpec */ /** @typedef {import("./Dependency").ExportsSpec} ExportsSpec */ /** @typedef {import("./ExportsInfo")} ExportsInfo */ +/** @typedef {import("./ExportsInfo").RestoreProvidedData} RestoreProvidedData */ /** @typedef {import("./Module")} Module */ /** @typedef {import("./Module").BuildInfo} BuildInfo */ @@ -400,7 +401,7 @@ class FlagDependencyExportsPlugin { } ); - /** @type {WeakMap} */ + /** @type {WeakMap} */ const providedExportsCache = new WeakMap(); compilation.hooks.rebuildModule.tap(PLUGIN_NAME, module => { providedExportsCache.set( @@ -409,9 +410,10 @@ class FlagDependencyExportsPlugin { ); }); compilation.hooks.finishRebuildingModule.tap(PLUGIN_NAME, module => { - moduleGraph - .getExportsInfo(module) - .restoreProvided(providedExportsCache.get(module)); + moduleGraph.getExportsInfo(module).restoreProvided( + /** @type {RestoreProvidedData} */ + (providedExportsCache.get(module)) + ); }); }); } diff --git a/lib/NormalModuleFactory.js b/lib/NormalModuleFactory.js index 51f1a6921..7f14906de 100644 --- a/lib/NormalModuleFactory.js +++ b/lib/NormalModuleFactory.js @@ -455,7 +455,7 @@ class NormalModuleFactory extends ModuleFactory { matchResourceData = { resource: matchResource, - ...cacheParseResource(matchResource) + .../** @type {TODO} */ (cacheParseResource(matchResource)) }; requestWithoutMatchResource = request.slice( matchResourceMatch[0].length @@ -622,10 +622,10 @@ class NormalModuleFactory extends ModuleFactory { ] === "object" && settings[/** @type {keyof ModuleSettings} */ (r.type)] !== null ) { - const type = /** @type {TODO} */ (r.type); + const type = /** @type {keyof ModuleSettings} */ (r.type); settings[type] = cachedCleverMerge(settings[type], r.value); } else { - const type = /** @type {TODO} */ (r.type); + const type = /** @type {keyof ModuleSettings} */ (r.type); settings[type] = r.value; } } @@ -753,7 +753,7 @@ class NormalModuleFactory extends ModuleFactory { resourceData = { resource: unresolvedResource, data: {}, - ...cacheParseResource(unresolvedResource) + .../** @type {TODO} */ (cacheParseResource(unresolvedResource)) }; continueCallback(); } @@ -787,7 +787,8 @@ class NormalModuleFactory extends ModuleFactory { data: /** @type {ResolveRequest} */ (resolvedResourceResolveData), - ...cacheParseResource(resolvedResource) + .../** @type {TODO} */ + (cacheParseResource(resolvedResource)) }; } continueCallback(); diff --git a/lib/cache/PackFileCacheStrategy.js b/lib/cache/PackFileCacheStrategy.js index b5fd33231..b40c88e5f 100644 --- a/lib/cache/PackFileCacheStrategy.js +++ b/lib/cache/PackFileCacheStrategy.js @@ -21,6 +21,7 @@ const { /** @typedef {import("../Cache").Etag} Etag */ /** @typedef {import("../Compiler")} Compiler */ /** @typedef {import("../FileSystemInfo").ResolveBuildDependenciesResult} ResolveBuildDependenciesResult */ +/** @typedef {import("../FileSystemInfo").ResolveResults} ResolveResults */ /** @typedef {import("../FileSystemInfo").Snapshot} Snapshot */ /** @typedef {import("../logging/Logger").Logger} Logger */ /** @typedef {import("../serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */ @@ -28,14 +29,13 @@ const { /** @typedef {typeof import("../util/Hash")} Hash */ /** @typedef {import("../util/fs").IntermediateFileSystem} IntermediateFileSystem */ -/** @typedef {Map} ResolveResults */ /** @typedef {Set} Items */ /** @typedef {Set} BuildDependencies */ /** @typedef {Map} ItemInfo */ class PackContainer { /** - * @param {object} data stored data + * @param {Pack} data stored data * @param {string} version version identifier * @param {Snapshot} buildSnapshot snapshot of all build dependencies * @param {BuildDependencies} buildDependencies list of all unresolved build dependencies captured @@ -1283,7 +1283,7 @@ class PackFileCacheStrategy { logger.timeEnd("check build dependencies"); if (buildSnapshotValid && resolveValid) { logger.time("restore cache content metadata"); - const d = packContainer.data(); + const d = /** @type {TODO} */ (packContainer).data(); logger.timeEnd("restore cache content metadata"); return d; } @@ -1379,104 +1379,110 @@ class PackFileCacheStrategy { newBuildDependencies ).join(", ")})` ); - promise = new Promise((resolve, reject) => { - this.logger.time("resolve build dependencies"); - this.fileSystemInfo.resolveBuildDependencies( - this.context, - newBuildDependencies, - (err, result) => { - this.logger.timeEnd("resolve build dependencies"); - if (err) return reject(err); + promise = new Promise( + /** + * @param {(value?: undefined) => void} resolve resolve + * @param {(reason?: Error) => void} reject reject + */ + (resolve, reject) => { + this.logger.time("resolve build dependencies"); + this.fileSystemInfo.resolveBuildDependencies( + this.context, + newBuildDependencies, + (err, result) => { + this.logger.timeEnd("resolve build dependencies"); + if (err) return reject(err); - this.logger.time("snapshot build dependencies"); - const { - files, - directories, - missing, - resolveResults, - resolveDependencies - } = /** @type {ResolveBuildDependenciesResult} */ (result); - if (this.resolveResults) { - for (const [key, value] of resolveResults) { - this.resolveResults.set(key, value); + this.logger.time("snapshot build dependencies"); + const { + files, + directories, + missing, + resolveResults, + resolveDependencies + } = /** @type {ResolveBuildDependenciesResult} */ (result); + if (this.resolveResults) { + for (const [key, value] of resolveResults) { + this.resolveResults.set(key, value); + } + } else { + this.resolveResults = resolveResults; } - } else { - this.resolveResults = resolveResults; - } - if (reportProgress) { - reportProgress( - 0.6, - "snapshot build dependencies", - "resolving" - ); - } - this.fileSystemInfo.createSnapshot( - undefined, - resolveDependencies.files, - resolveDependencies.directories, - resolveDependencies.missing, - this.snapshot.resolveBuildDependencies, - (err, snapshot) => { - if (err) { - this.logger.timeEnd("snapshot build dependencies"); - return reject(err); - } - if (!snapshot) { - this.logger.timeEnd("snapshot build dependencies"); - return reject( - new Error("Unable to snapshot resolve dependencies") - ); - } - if (this.resolveBuildDependenciesSnapshot) { - this.resolveBuildDependenciesSnapshot = - this.fileSystemInfo.mergeSnapshots( - this.resolveBuildDependenciesSnapshot, - snapshot - ); - } else { - this.resolveBuildDependenciesSnapshot = snapshot; - } - if (reportProgress) { - reportProgress( - 0.7, - "snapshot build dependencies", - "modules" - ); - } - this.fileSystemInfo.createSnapshot( - undefined, - files, - directories, - missing, - this.snapshot.buildDependencies, - (err, snapshot) => { - this.logger.timeEnd("snapshot build dependencies"); - if (err) return reject(err); - if (!snapshot) { - return reject( - new Error("Unable to snapshot build dependencies") - ); - } - this.logger.debug("Captured build dependencies"); - - if (this.buildSnapshot) { - this.buildSnapshot = - this.fileSystemInfo.mergeSnapshots( - this.buildSnapshot, - snapshot - ); - } else { - this.buildSnapshot = snapshot; - } - - resolve(); - } + if (reportProgress) { + reportProgress( + 0.6, + "snapshot build dependencies", + "resolving" ); } - ); - } - ); - }); + this.fileSystemInfo.createSnapshot( + undefined, + resolveDependencies.files, + resolveDependencies.directories, + resolveDependencies.missing, + this.snapshot.resolveBuildDependencies, + (err, snapshot) => { + if (err) { + this.logger.timeEnd("snapshot build dependencies"); + return reject(err); + } + if (!snapshot) { + this.logger.timeEnd("snapshot build dependencies"); + return reject( + new Error("Unable to snapshot resolve dependencies") + ); + } + if (this.resolveBuildDependenciesSnapshot) { + this.resolveBuildDependenciesSnapshot = + this.fileSystemInfo.mergeSnapshots( + this.resolveBuildDependenciesSnapshot, + snapshot + ); + } else { + this.resolveBuildDependenciesSnapshot = snapshot; + } + if (reportProgress) { + reportProgress( + 0.7, + "snapshot build dependencies", + "modules" + ); + } + this.fileSystemInfo.createSnapshot( + undefined, + files, + directories, + missing, + this.snapshot.buildDependencies, + (err, snapshot) => { + this.logger.timeEnd("snapshot build dependencies"); + if (err) return reject(err); + if (!snapshot) { + return reject( + new Error("Unable to snapshot build dependencies") + ); + } + this.logger.debug("Captured build dependencies"); + + if (this.buildSnapshot) { + this.buildSnapshot = + this.fileSystemInfo.mergeSnapshots( + this.buildSnapshot, + snapshot + ); + } else { + this.buildSnapshot = snapshot; + } + + resolve(); + } + ); + } + ); + } + ); + } + ); } else { promise = Promise.resolve(); } diff --git a/lib/dependencies/HarmonyExportImportedSpecifierDependency.js b/lib/dependencies/HarmonyExportImportedSpecifierDependency.js index cee760330..0e94201b3 100644 --- a/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +++ b/lib/dependencies/HarmonyExportImportedSpecifierDependency.js @@ -115,11 +115,14 @@ class ExportMode { } } +/** @typedef {string[]} Names */ +/** @typedef {number[]} DependencyIndices */ + /** * @param {ModuleGraph} moduleGraph module graph * @param {TODO} dependencies dependencies - * @param {TODO=} additionalDependency additional dependency - * @returns {TODO} result + * @param {Dependency=} additionalDependency additional dependency + * @returns {{ names: Names, dependencyIndices: DependencyIndices }} result */ const determineExportAssignments = ( moduleGraph, @@ -157,9 +160,6 @@ const determineExportAssignments = ( return { names: Array.from(names), dependencyIndices }; }; -/** @typedef {string[]} Names */ -/** @typedef {number[]} DependencyIndices */ - /** * @param {object} options options * @param {Names} options.names names diff --git a/lib/hmr/LazyCompilationPlugin.js b/lib/hmr/LazyCompilationPlugin.js index 083cefb31..8f528f921 100644 --- a/lib/hmr/LazyCompilationPlugin.js +++ b/lib/hmr/LazyCompilationPlugin.js @@ -319,9 +319,9 @@ class LazyCompilationDependencyFactory extends ModuleFactory { * @returns {void} */ create(data, callback) { - const dependency = /** @type {LazyCompilationDependency} */ ( - data.dependencies[0] - ); + const dependency = + /** @type {LazyCompilationDependency} */ + (data.dependencies[0]); callback(null, { module: dependency.proxyModule.originalModule }); @@ -386,7 +386,7 @@ class LazyCompilationPlugin { (compilation, { normalModuleFactory }) => { normalModuleFactory.hooks.module.tap( "LazyCompilationPlugin", - (originalModule, createData, resolveData) => { + (module, createData, resolveData) => { if ( resolveData.dependencies.every(dep => HMR_DEPENDENCY_TYPES.has(dep.type) @@ -407,7 +407,7 @@ class LazyCompilationPlugin { hmrDep.request ) ); - if (!isReferringToDynamicImport) return; + if (!isReferringToDynamicImport) return module; } else if ( !resolveData.dependencies.every( dep => @@ -418,21 +418,21 @@ class LazyCompilationPlugin { (this.entries && dep.type === "entry") ) ) - return; + return module; if ( /webpack[/\\]hot[/\\]|webpack-dev-server[/\\]client|webpack-hot-middleware[/\\]client/.test( resolveData.request ) || - !checkTest(this.test, originalModule) + !checkTest(this.test, module) ) - return; - const moduleInfo = backend.module(originalModule); - if (!moduleInfo) return; + return module; + const moduleInfo = backend.module(module); + if (!moduleInfo) return module; const { client, data, active } = moduleInfo; return new LazyCompilationProxyModule( compiler.context, - originalModule, + module, resolveData.request, client, data, diff --git a/lib/javascript/JavascriptModulesPlugin.js b/lib/javascript/JavascriptModulesPlugin.js index 83d07713b..f2f0dcd0b 100644 --- a/lib/javascript/JavascriptModulesPlugin.js +++ b/lib/javascript/JavascriptModulesPlugin.js @@ -56,7 +56,7 @@ const JavascriptParser = require("./JavascriptParser"); /** @typedef {import("../ChunkGraph")} ChunkGraph */ /** @typedef {import("../CodeGenerationResults")} CodeGenerationResults */ /** @typedef {import("../Compilation").ChunkHashContext} ChunkHashContext */ -/** @typedef {import("../Compilation").ModuleObject} ModuleObject */ +/** @typedef {import("../Compilation").ExecuteModuleObject} ExecuteModuleObject */ /** @typedef {import("../Compiler")} Compiler */ /** @typedef {import("../DependencyTemplates")} DependencyTemplates */ /** @typedef {import("../Entrypoint")} Entrypoint */ @@ -250,7 +250,7 @@ class JavascriptModulesPlugin { constructor(options = {}) { this.options = options; - /** @type {WeakMap} */ + /** @type {WeakMap} */ this._moduleFactoryCache = new WeakMap(); } @@ -510,7 +510,7 @@ class JavascriptModulesPlugin { ); const moduleObject = - /** @type {ModuleObject} */ + /** @type {ExecuteModuleObject} */ (options.moduleObject); try { diff --git a/lib/javascript/JavascriptParser.js b/lib/javascript/JavascriptParser.js index a69ced1ed..4a4b6bd57 100644 --- a/lib/javascript/JavascriptParser.js +++ b/lib/javascript/JavascriptParser.js @@ -579,9 +579,9 @@ class JavascriptParser extends Parser { }); this.sourceType = sourceType; /** @type {ScopeInfo} */ - this.scope = undefined; + this.scope = /** @type {TODO} */ (undefined); /** @type {ParserState} */ - this.state = undefined; + this.state = /** @type {TODO} */ (undefined); /** @type {Comment[] | undefined} */ this.comments = undefined; /** @type {Set | undefined} */ diff --git a/lib/optimize/SplitChunksPlugin.js b/lib/optimize/SplitChunksPlugin.js index 8d2606769..6b58f67f6 100644 --- a/lib/optimize/SplitChunksPlugin.js +++ b/lib/optimize/SplitChunksPlugin.js @@ -421,7 +421,7 @@ const normalizeName = name => { /** * @param {OptimizationSplitChunksCacheGroup["chunks"]} chunks the chunk filter option - * @returns {ChunkFilterFunction} the chunk filter function + * @returns {ChunkFilterFunction | undefined} the chunk filter function */ const normalizeChunksFilter = chunks => { if (chunks === "initial") { @@ -650,7 +650,9 @@ module.exports = class SplitChunksPlugin { /** @type {SplitChunksOptions} */ this.options = { - chunksFilter: normalizeChunksFilter(options.chunks || "all"), + chunksFilter: + /** @type {ChunkFilterFunction} */ + (normalizeChunksFilter(options.chunks || "all")), defaultSizeTypes, minSize, minSizeReduction, @@ -685,9 +687,13 @@ module.exports = class SplitChunksPlugin { automaticNameDelimiter: options.automaticNameDelimiter || "-", usedExports: options.usedExports || false, fallbackCacheGroup: { - chunksFilter: normalizeChunksFilter( - fallbackCacheGroup.chunks || options.chunks || "all" - ), + chunksFilter: + /** @type {ChunkFilterFunction} */ + ( + normalizeChunksFilter( + fallbackCacheGroup.chunks || options.chunks || "all" + ) + ), minSize: mergeSizes( normalizeSizes(fallbackCacheGroup.minSize, defaultSizeTypes), minSize diff --git a/lib/serialization/ObjectMiddleware.js b/lib/serialization/ObjectMiddleware.js index 5971e24b4..d55834dd2 100644 --- a/lib/serialization/ObjectMiddleware.js +++ b/lib/serialization/ObjectMiddleware.js @@ -201,7 +201,7 @@ const loaders = new Map(); */ class ObjectMiddleware extends SerializerMiddleware { /** - * @param {function(any): void} extendContext context extensions + * @param {function(ObjectSerializerContext | ObjectDeserializerContext): void} extendContext context extensions * @param {string | Hash} hashFunction hash function to use */ constructor(extendContext, hashFunction = "md4") { diff --git a/lib/stats/DefaultStatsFactoryPlugin.js b/lib/stats/DefaultStatsFactoryPlugin.js index 965e5bc40..52c8bd260 100644 --- a/lib/stats/DefaultStatsFactoryPlugin.js +++ b/lib/stats/DefaultStatsFactoryPlugin.js @@ -396,7 +396,9 @@ const EXTRACT_ERROR = { object.message = error; } else { if (error.chunk) { - object.chunkName = error.chunk.name; + object.chunkName = + /** @type {string | undefined} */ + (error.chunk.name); object.chunkEntry = error.chunk.hasRuntime(); object.chunkInitial = error.chunk.canBeInitial(); } diff --git a/lib/util/cleverMerge.js b/lib/util/cleverMerge.js index 14852011b..d18e6f7bc 100644 --- a/lib/util/cleverMerge.js +++ b/lib/util/cleverMerge.js @@ -91,10 +91,12 @@ const cachedSetProperty = (obj, property, value) => { * @property {ByValues} byValues value depending on selector property, merged with base */ +/** @typedef {(function(...EXPECTED_ANY): object) & { [DYNAMIC_INFO]: [DynamicFunction, object] }} DynamicFunction */ + /** * @typedef {object} ParsedObject * @property {Map} static static properties (key is property name) - * @property {{ byProperty: string, fn: Function } | undefined} dynamic dynamic part + * @property {{ byProperty: string, fn: DynamicFunction } | undefined} dynamic dynamic part */ /** @type {WeakMap} */ @@ -205,7 +207,9 @@ const serializeObject = (info, dynamicInfo) => { // Setup byProperty structure for (const entry of info.values()) { if (entry.byProperty !== undefined) { - const byObj = (obj[entry.byProperty] = obj[entry.byProperty] || {}); + const byProperty = /** @type {keyof T} */ (entry.byProperty); + const byObj = (obj[byProperty] = + obj[byProperty] || /** @type {TODO} */ ({})); for (const byValue of entry.byValues.keys()) { byObj[byValue] = byObj[byValue] || {}; } @@ -217,7 +221,9 @@ const serializeObject = (info, dynamicInfo) => { } // Fill byProperty structure if (entry.byProperty !== undefined) { - const byObj = (obj[entry.byProperty] = obj[entry.byProperty] || {}); + const byProperty = /** @type {keyof T} */ (entry.byProperty); + const byObj = (obj[byProperty] = + obj[byProperty] || /** @type {TODO} */ ({})); for (const byValue of Object.keys(byObj)) { const value = getFromByValues(entry.byValues, byValue); if (value !== undefined) byObj[byValue][key] = value; @@ -225,7 +231,8 @@ const serializeObject = (info, dynamicInfo) => { } } if (dynamicInfo !== undefined) { - obj[dynamicInfo.byProperty] = dynamicInfo.fn; + /** @type {TODO} */ + (obj)[dynamicInfo.byProperty] = dynamicInfo.fn; } return obj; }; @@ -300,6 +307,7 @@ const _cleverMerge = (first, second, internalCaching = false) => { : cleverMerge(fnInfo[1], second); fn = fnInfo[0]; } + /** @type {DynamicFunction} */ const newFn = (...args) => { const fnResult = fn(...args); return internalCaching @@ -524,14 +532,12 @@ const mergeSingleValue = (a, b, internalCaching) => { */ const removeOperations = (obj, keysToKeepOriginalValue = []) => { const newObj = /** @type {T} */ ({}); - for (const key of Object.keys(obj)) { - const value = obj[/** @type {keyof T} */ (key)]; + for (const _key of Object.keys(obj)) { + const key = /** @type {keyof T} */ (_key); + const value = obj[key]; const type = getValueType(value); - if ( - type === VALUE_TYPE_OBJECT && - keysToKeepOriginalValue.includes(/** @type {keyof T} */ (key)) - ) { - newObj[/** @type {keyof T} */ (key)] = value; + if (type === VALUE_TYPE_OBJECT && keysToKeepOriginalValue.includes(key)) { + newObj[key] = value; continue; } switch (type) { @@ -539,25 +545,26 @@ const removeOperations = (obj, keysToKeepOriginalValue = []) => { case VALUE_TYPE_DELETE: break; case VALUE_TYPE_OBJECT: - newObj[/** @type {keyof T} */ (key)] = + newObj[key] = /** @type {T[keyof T]} */ ( removeOperations( - /** @type {TODO} */ (value), + /** @type {T} */ + (value), keysToKeepOriginalValue ) ); break; case VALUE_TYPE_ARRAY_EXTEND: - newObj[/** @type {keyof T} */ (key)] = + newObj[key] = /** @type {T[keyof T]} */ ( - /** @type {any[]} */ + /** @type {EXPECTED_ANY[]} */ (value).filter(i => i !== "...") ); break; default: - newObj[/** @type {keyof T} */ (key)] = value; + newObj[key] = value; break; } } @@ -597,6 +604,7 @@ const resolveByProperty = (obj, byProperty, ...values) => { resolveByProperty(result, byProperty, ...values) ); } + return obj; }; module.exports.cachedSetProperty = cachedSetProperty; diff --git a/lib/util/concatenate.js b/lib/util/concatenate.js index 8d19001c9..06f2673e3 100644 --- a/lib/util/concatenate.js +++ b/lib/util/concatenate.js @@ -139,11 +139,13 @@ function findNewName(oldName, usedNamed1, usedNamed2, extraInfo) { return nameWithNumber; } +/** @typedef {Set} ScopeSet */ + /** * @param {Scope | null} s scope * @param {UsedNames} nameSet name set - * @param {TODO} scopeSet1 scope set 1 - * @param {TODO} scopeSet2 scope set 2 + * @param {ScopeSet} scopeSet1 scope set 1 + * @param {ScopeSet} scopeSet2 scope set 2 */ const addScopeSymbols = (s, nameSet, scopeSet1, scopeSet2) => { let scope = s; @@ -197,10 +199,10 @@ const RESERVED_NAMES = new Set( ); /** - * @param {Map }>} usedNamesInScopeInfo used names in scope info + * @param {Map} usedNamesInScopeInfo used names in scope info * @param {string} module module identifier * @param {string} id export id - * @returns {{ usedNames: UsedNames, alreadyCheckedScopes: Set }} info + * @returns {{ usedNames: UsedNames, alreadyCheckedScopes: ScopeSet }} info */ const getUsedNamesInScopeInfo = (usedNamesInScopeInfo, module, id) => { const key = `${module}-${id}`; diff --git a/lib/util/deterministicGrouping.js b/lib/util/deterministicGrouping.js index b69be0288..6a7a0dc3a 100644 --- a/lib/util/deterministicGrouping.js +++ b/lib/util/deterministicGrouping.js @@ -152,15 +152,15 @@ const getTooSmallTypes = (size, minSize) => { }; /** - * @template T - * @param {TODO} size size + * @template {object} T + * @param {T} size size * @param {Set} types types * @returns {number} number of matching size types */ const getNumberOfMatchingSizeTypes = (size, types) => { let i = 0; for (const key of Object.keys(size)) { - if (size[key] !== 0 && types.has(key)) i++; + if (size[/** @type {keyof T} */ (key)] !== 0 && types.has(key)) i++; } return i; }; diff --git a/lib/util/registerExternalSerializer.js b/lib/util/registerExternalSerializer.js index 711bcfa21..5e20a4325 100644 --- a/lib/util/registerExternalSerializer.js +++ b/lib/util/registerExternalSerializer.js @@ -7,7 +7,7 @@ const { register } = require("./serialization"); -const Position = /** @type {TODO} */ (require("acorn")).Position; +const Position = require("acorn").Position; const SourceLocation = require("acorn").SourceLocation; const ValidationError = require("schema-utils").ValidationError; const { @@ -23,10 +23,8 @@ const { /** @typedef {import("acorn").Position} Position */ /** @typedef {import("../Dependency").RealDependencyLocation} RealDependencyLocation */ /** @typedef {import("../Dependency").SourcePosition} SourcePosition */ -/** @typedef {import("./serialization").ObjectDeserializerContext} ObjectDeserializerContext */ -/** @typedef {import("./serialization").ObjectSerializerContext} ObjectSerializerContext */ - -/** @typedef {ObjectSerializerContext & { writeLazy?: (value: any) => void }} WebpackObjectSerializerContext */ +/** @typedef {import("../serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */ +/** @typedef {import("../serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */ const CURRENT_MODULE = "webpack/lib/util/registerExternalSerializer"; @@ -37,7 +35,7 @@ register( new (class CachedSourceSerializer { /** * @param {CachedSource} source the cached source to be serialized - * @param {WebpackObjectSerializerContext} context context + * @param {ObjectSerializerContext} context context * @returns {void} */ serialize(source, { write, writeLazy }) { @@ -68,7 +66,7 @@ register( new (class RawSourceSerializer { /** * @param {RawSource} source the raw source to be serialized - * @param {WebpackObjectSerializerContext} context context + * @param {ObjectSerializerContext} context context * @returns {void} */ serialize(source, { write }) { @@ -95,7 +93,7 @@ register( new (class ConcatSourceSerializer { /** * @param {ConcatSource} source the concat source to be serialized - * @param {WebpackObjectSerializerContext} context context + * @param {ObjectSerializerContext} context context * @returns {void} */ serialize(source, { write }) { @@ -121,7 +119,7 @@ register( new (class PrefixSourceSerializer { /** * @param {PrefixSource} source the prefix source to be serialized - * @param {WebpackObjectSerializerContext} context context + * @param {ObjectSerializerContext} context context * @returns {void} */ serialize(source, { write }) { @@ -146,7 +144,7 @@ register( new (class ReplaceSourceSerializer { /** * @param {ReplaceSource} source the replace source to be serialized - * @param {WebpackObjectSerializerContext} context context + * @param {ObjectSerializerContext} context context * @returns {void} */ serialize(source, { write }) { @@ -196,7 +194,7 @@ register( new (class OriginalSourceSerializer { /** * @param {OriginalSource} source the original source to be serialized - * @param {WebpackObjectSerializerContext} context context + * @param {ObjectSerializerContext} context context * @returns {void} */ serialize(source, { write }) { @@ -223,7 +221,7 @@ register( new (class SourceLocationSerializer { /** * @param {SourceLocation} loc the location to be serialized - * @param {WebpackObjectSerializerContext} context context + * @param {ObjectSerializerContext} context context * @returns {void} */ serialize(loc, { write }) { @@ -259,7 +257,7 @@ register( new (class PositionSerializer { /** * @param {Position} pos the position to be serialized - * @param {WebpackObjectSerializerContext} context context + * @param {ObjectSerializerContext} context context * @returns {void} */ serialize(pos, { write }) { @@ -287,7 +285,7 @@ register( new (class SourceMapSourceSerializer { /** * @param {SourceMapSource} source the source map source to be serialized - * @param {WebpackObjectSerializerContext} context context + * @param {ObjectSerializerContext} context context * @returns {void} */ serialize(source, { write }) { @@ -310,10 +308,9 @@ register( CURRENT_MODULE, "schema-utils/ValidationError", new (class ValidationErrorSerializer { - // TODO error should be ValidationError, but this fails the type checks /** - * @param {TODO} error the source map source to be serialized - * @param {WebpackObjectSerializerContext} context context + * @param {ValidationError} error the source map source to be serialized + * @param {ObjectSerializerContext} context context * @returns {void} */ serialize(error, { write }) { @@ -328,7 +325,7 @@ register( /** * @param {ObjectDeserializerContext} context context - * @returns {TODO} error + * @returns {ValidationError} error */ deserialize({ read }) { return new ValidationError(read(), read(), read()); diff --git a/lib/util/serialization.js b/lib/util/serialization.js index ed8746f7e..99a029263 100644 --- a/lib/util/serialization.js +++ b/lib/util/serialization.js @@ -8,8 +8,6 @@ const memoize = require("./memoize"); /** @typedef {import("../serialization/BinaryMiddleware").MEASURE_END_OPERATION_TYPE} MEASURE_END_OPERATION */ /** @typedef {import("../serialization/BinaryMiddleware").MEASURE_START_OPERATION_TYPE} MEASURE_START_OPERATION */ -/** @typedef {import("../serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */ -/** @typedef {import("../serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */ /** @typedef {import("../serialization/Serializer")} Serializer */ /** @typedef {typeof import("../util/Hash")} Hash */ /** @typedef {import("../util/fs").IntermediateFileSystem} IntermediateFileSystem */ @@ -92,10 +90,7 @@ module.exports = { return (buffersSerializer = new Serializer([ new SingleItemMiddleware(), new (getObjectMiddleware())(context => { - if (context.write) { - /** - * @param {any} value value - */ + if ("write" in context) { context.writeLazy = value => { context.write( SerializerMiddleware.createLazy(value, binaryMiddleware) @@ -122,20 +117,12 @@ module.exports = { return new Serializer([ new SingleItemMiddleware(), new (getObjectMiddleware())(context => { - if (context.write) { - /** - * @param {any} value value - */ + if ("write" in context) { context.writeLazy = value => { context.write( SerializerMiddleware.createLazy(value, binaryMiddleware) ); }; - /** - * @param {any} value value - * @param {object=} options lazy options - * @returns {function(): Promise | any} lazy function - */ context.writeSeparate = (value, options) => { const lazy = SerializerMiddleware.createLazy( value, diff --git a/tsconfig.json b/tsconfig.json index 84f9de294..f815caa3a 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -6,8 +6,7 @@ "allowJs": true, "checkJs": true, "noEmit": true, - "strict": false, - "noImplicitThis": true, + "strict": true, "alwaysStrict": true, "types": ["node"], "esModuleInterop": true diff --git a/tsconfig.module.test.json b/tsconfig.module.test.json index e59ca0b64..1bf38455d 100644 --- a/tsconfig.module.test.json +++ b/tsconfig.module.test.json @@ -2,12 +2,12 @@ "compilerOptions": { "target": "esnext", "module": "esnext", - "moduleResolution": "node", "lib": ["es2017", "dom"], "allowJs": true, "checkJs": true, "noEmit": true, "strict": true, + "moduleResolution": "node", "types": ["node", "./module"], "esModuleInterop": true }, diff --git a/tsconfig.types.json b/tsconfig.types.json index d372bd6af..ebdd79075 100644 --- a/tsconfig.types.json +++ b/tsconfig.types.json @@ -7,7 +7,6 @@ "checkJs": true, "noEmit": true, "strict": true, - "noImplicitThis": true, "alwaysStrict": true, "types": ["node"], "esModuleInterop": true diff --git a/types.d.ts b/types.d.ts index 67ca066c0..dd4a462a4 100644 --- a/types.d.ts +++ b/types.d.ts @@ -1041,11 +1041,11 @@ declare interface CallbackWebpack { } type Cell = undefined | T; declare class Chunk { - constructor(name?: string, backCompat?: boolean); + constructor(name?: null | string, backCompat?: boolean); id: null | string | number; ids: null | ChunkId[]; debugId: number; - name?: string; + name?: null | string; idNameHints: SortableSet; preventIntegration: boolean; filenameTemplate?: string | ((arg0: PathData, arg1?: AssetInfo) => string); @@ -2157,7 +2157,7 @@ declare class Compilation { * This method first looks to see if a name is provided for a new chunk, * and first looks to see if any named chunks already exist and reuse that chunk instead. */ - addChunk(name?: string): Chunk; + addChunk(name?: null | string): Chunk; assignDepth(module: Module): void; assignDepths(modules: Set): void; getDependencyReferencedExports( @@ -2438,11 +2438,8 @@ declare class Compiler { immutablePaths: Set; modifiedFiles?: ReadonlySet; removedFiles?: ReadonlySet; - fileTimestamps?: ReadonlyMap; - contextTimestamps?: ReadonlyMap< - string, - null | FileSystemInfoEntry | "ignore" - >; + fileTimestamps?: Map; + contextTimestamps?: Map; fsStartTime?: number; resolverFactory: ResolverFactory; infrastructureLogger?: ( @@ -3083,6 +3080,7 @@ declare class ContextReplacementPlugin { */ apply(compiler: Compiler): void; } +type ContextTimestamp = null | ContextFileSystemInfoEntry | "ignore"; declare interface ContextTimestampAndHash { safeTime: number; timestampHash?: string; @@ -3090,8 +3088,8 @@ declare interface ContextTimestampAndHash { resolved?: ResolvedContextTimestampAndHash; symlinks?: Set; } -type CreateStatsOptionsContext = Record & - KnownCreateStatsOptionsContext; +type CreateStatsOptionsContext = KnownCreateStatsOptionsContext & + Record; type CreateWriteStreamFSImplementation = FSImplementation & { write: (...args: any[]) => any; close?: (...args: any[]) => any; @@ -4301,28 +4299,68 @@ declare class EvalSourceMapDevToolPlugin { } declare interface ExecuteModuleArgument { module: Module; - moduleObject?: ModuleObject; + moduleObject?: ExecuteModuleObject; preparedInfo: any; codeGenerationResult: CodeGenerationResult; } declare interface ExecuteModuleContext { - assets: Map; + assets: Map; chunk: Chunk; chunkGraph: ChunkGraph; - __webpack_require__?: (arg0: string) => any; + __webpack_require__?: WebpackRequire; +} +declare interface ExecuteModuleExports { + [index: string]: any; +} +declare interface ExecuteModuleObject { + /** + * module id + */ + id?: string; + + /** + * exports + */ + exports: ExecuteModuleExports; + + /** + * is loaded + */ + loaded: boolean; + + /** + * error + */ + error?: Error; } declare interface ExecuteModuleOptions { entryOptions?: EntryOptions; } declare interface ExecuteModuleResult { - exports: any; + exports: ExecuteModuleExports; cacheable: boolean; - assets: Map; + assets: Map; fileDependencies: LazySet; contextDependencies: LazySet; missingDependencies: LazySet; buildDependencies: LazySet; } +declare interface ExecuteOptions { + /** + * module id + */ + id?: string; + + /** + * module + */ + module: ExecuteModuleObject; + + /** + * require function + */ + require: WebpackRequire; +} type Experiments = ExperimentsCommon & ExperimentsExtra; /** @@ -4454,9 +4492,9 @@ declare abstract class ExportInfo { runtime: RuntimeSpec ): boolean; setUsed(newValue: UsageStateType, runtime: RuntimeSpec): boolean; - unsetTarget(key?: any): boolean; + unsetTarget(key: Dependency): boolean; setTarget( - key: any, + key: Dependency, connection: ModuleGraphConnection, exportName?: null | string[], priority?: number @@ -4478,7 +4516,7 @@ declare abstract class ExportInfo { setUsedName(name: string): void; getTerminalBinding( moduleGraph: ModuleGraph, - resolveTargetFilter?: (arg0: TargetItem) => boolean + resolveTargetFilter?: (arg0: TargetItemWithConnection) => boolean ): undefined | ExportsInfo | ExportInfo; isReexport(): undefined | boolean; findTarget( @@ -4487,17 +4525,19 @@ declare abstract class ExportInfo { ): undefined | null | false | TargetItemWithoutConnection; getTarget( moduleGraph: ModuleGraph, - resolveTargetFilter?: (arg0: TargetItem) => boolean - ): undefined | TargetItem; + resolveTargetFilter?: (arg0: TargetItemWithConnection) => boolean + ): undefined | TargetItemWithConnection; /** * Move the target forward as long resolveTargetFilter is fulfilled */ moveTarget( moduleGraph: ModuleGraph, - resolveTargetFilter: (arg0: TargetItem) => boolean, - updateOriginalConnection?: (arg0: TargetItem) => ModuleGraphConnection - ): undefined | TargetItem; + resolveTargetFilter: (arg0: TargetItemWithConnection) => boolean, + updateOriginalConnection?: ( + arg0: TargetItemWithConnection + ) => ModuleGraphConnection + ): undefined | TargetItemWithConnection; createNestedExportsInfo(): ExportsInfo; getNestedExportsInfo(): undefined | ExportsInfo; hasInfo(baseInfo: ExportInfo, runtime: RuntimeSpec): boolean; @@ -4572,7 +4612,7 @@ declare abstract class ExportsInfo { setUnknownExportsProvided( canMangle?: boolean, excludeExports?: Set, - targetKey?: any, + targetKey?: Dependency, targetModule?: ModuleGraphConnection, priority?: number ): boolean; @@ -4592,12 +4632,7 @@ declare abstract class ExportsInfo { getUsedName(name: string | string[], runtime: RuntimeSpec): UsedName; updateHash(hash: Hash, runtime: RuntimeSpec): void; getRestoreProvidedData(): RestoreProvidedData; - restoreProvided(__0: { - otherProvided: any; - otherCanMangleProvide: any; - otherTerminalBinding: any; - exports: any; - }): void; + restoreProvided(__0: RestoreProvidedData): void; } declare interface ExportsSpec { /** @@ -5099,11 +5134,11 @@ declare abstract class FileSystemInfo { logStatistics(): void; clear(): void; addFileTimestamps( - map: ReadonlyMap, + map: ReadonlyMap, immutable?: boolean ): void; addContextTimestamps( - map: ReadonlyMap, + map: ReadonlyMap, immutable?: boolean ): void; getFileTimestamp( @@ -5144,7 +5179,7 @@ declare abstract class FileSystemInfo { ) => void ): void; checkResolveResultsValid( - resolveResults: Map, + resolveResults: Map, callback: (arg0?: null | Error, arg1?: boolean) => void ): void; createSnapshot( @@ -5160,13 +5195,14 @@ declare abstract class FileSystemInfo { snapshot: Snapshot, callback: (arg0?: null | WebpackError, arg1?: boolean) => void ): void; - getDeprecatedFileTimestamps(): Map; - getDeprecatedContextTimestamps(): Map; + getDeprecatedFileTimestamps(): Map; + getDeprecatedContextTimestamps(): Map; } declare interface FileSystemInfoEntry { safeTime: number; timestamp?: number; } +type FileTimestamp = null | FileSystemInfoEntry | "ignore"; type FilterItemTypes = string | RegExp | ((value: string) => boolean); declare interface Flags { [index: string]: Argument; @@ -9214,12 +9250,6 @@ declare interface ModuleMemCachesItem { references?: WeakMap; memCache: WeakTupleMap; } -declare interface ModuleObject { - id?: string; - exports: any; - loaded: boolean; - error?: Error; -} /** * Options affecting the normal modules (`NormalModuleFactory`). @@ -12456,20 +12486,7 @@ declare interface ResolveBuildDependenciesResult { /** * dependencies of the resolving */ - resolveDependencies: { - /** - * list of files - */ - files: Set; - /** - * list of directories - */ - directories: Set; - /** - * list of missing entries - */ - missing: Set; - }; + resolveDependencies: ResolveDependencies; } declare interface ResolveContext { contextDependencies?: WriteOnlySet; @@ -12518,6 +12535,22 @@ declare interface ResolveData { */ cacheable: boolean; } +declare interface ResolveDependencies { + /** + * list of files + */ + files: Set; + + /** + * list of directories + */ + directories: Set; + + /** + * list of missing entries + */ + missing: Set; +} /** * Options object for resolving requests. @@ -15216,7 +15249,7 @@ declare interface TagInfo { data?: TagData; next?: TagInfo; } -declare interface TargetItem { +declare interface TargetItemWithConnection { module: Module; connection: ModuleGraphConnection; export?: string[]; @@ -15793,6 +15826,12 @@ declare interface WebpackPluginInstance { */ apply: (compiler: Compiler) => void; } + +declare interface WebpackRequire { + (id: string): ExecuteModuleExports; + i?: ((options: ExecuteOptions) => void)[]; + c?: Record; +} declare interface WithId { id: string | number; }