diff --git a/lib/Generator.js b/lib/Generator.js index 10d7cb084..2bcd96869 100644 --- a/lib/Generator.js +++ b/lib/Generator.js @@ -13,6 +13,7 @@ /** @typedef {import("./ConcatenationScope")} ConcatenationScope */ /** @typedef {import("./DependencyTemplate")} DependencyTemplate */ /** @typedef {import("./DependencyTemplates")} DependencyTemplates */ +/** @typedef {import("./Module").CodeGenerationResultData} CodeGenerationResultData */ /** @typedef {import("./Module").ConcatenationBailoutReasonContext} ConcatenationBailoutReasonContext */ /** @typedef {import("./Module").RuntimeRequirements} RuntimeRequirements */ /** @typedef {import("./Module").SourceTypes} SourceTypes */ @@ -22,15 +23,6 @@ /** @typedef {import("./util/Hash")} Hash */ /** @typedef {import("./util/runtime").RuntimeSpec} RuntimeSpec */ -/** - * @template T - * @typedef {import("./InitFragment")} InitFragment - */ - -/** @typedef {Map<"url", { [key: string]: string }> & Map<"fullContentHash", string> & Map<"contentHash", string> & Map<"filename", string> & Map<"assetInfo", AssetInfo> & Map<"chunkInitFragments", InitFragment[]>} KnownGenerateContextData */ - -/** @typedef {KnownGenerateContextData & Record} GenerateContextData */ - /** * @typedef {object} GenerateContext * @property {DependencyTemplates} dependencyTemplates mapping from dependencies to templates @@ -42,7 +34,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 {() => GenerateContextData=} getData get access to the code generation data + * @property {() => CodeGenerationResultData=} getData get access to the code generation data */ /** diff --git a/lib/Module.js b/lib/Module.js index 96838b867..8b7c02313 100644 --- a/lib/Module.js +++ b/lib/Module.js @@ -39,6 +39,10 @@ const makeSerializable = require("./util/makeSerializable"); /** @typedef {import("./RequestShortener")} RequestShortener */ /** @typedef {import("./ResolverFactory").ResolverWithOptions} ResolverWithOptions */ /** @typedef {import("./RuntimeTemplate")} RuntimeTemplate */ +/** + * @template T + * @typedef {import("./InitFragment")} InitFragment + */ /** @typedef {import("./WebpackError")} WebpackError */ /** @typedef {import("./json/JsonData")} JsonData */ /** @typedef {import("./serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */ @@ -94,10 +98,16 @@ const makeSerializable = require("./util/makeSerializable"); /** @typedef {Set} RuntimeRequirements */ /** @typedef {ReadonlySet} ReadOnlyRuntimeRequirements */ +/** @typedef {Map<"topLevelDeclarations", Set> & Map<"chunkInitFragments", InitFragment[]>} KnownCodeGenerationResultDataForJavascriptModules */ +/** @typedef {Map<"url", { ["css-url"]: string }>} KnownCodeGenerationResultDataForCssModules */ +/** @typedef {Map<"filename", string> & Map<"assetInfo", AssetInfo> & Map<"fullContentHash", string>} KnownCodeGenerationResultDataForAssetModules */ + +/** @typedef {KnownCodeGenerationResultDataForJavascriptModules & KnownCodeGenerationResultDataForCssModules & KnownCodeGenerationResultDataForAssetModules & Map} CodeGenerationResultData */ + /** * @typedef {object} CodeGenerationResult * @property {Map} sources the resulting sources for all source types - * @property {Map=} data the resulting data for all source types + * @property {CodeGenerationResultData=} data the resulting data for all source types * @property {ReadOnlyRuntimeRequirements | null} runtimeRequirements the runtime requirements * @property {string=} hash a hash of the code generation result (will be automatically calculated from sources and runtimeRequirements if not provided) */ diff --git a/lib/NormalModule.js b/lib/NormalModule.js index 574ec957a..4e6180d21 100644 --- a/lib/NormalModule.js +++ b/lib/NormalModule.js @@ -65,11 +65,11 @@ const memoize = require("./util/memoize"); /** @typedef {import("./DependencyTemplates")} DependencyTemplates */ /** @typedef {import("./Generator")} Generator */ /** @typedef {import("./Generator").GenerateErrorFn} GenerateErrorFn */ -/** @typedef {import("./Generator").GenerateContextData} GenerateContextData */ /** @typedef {import("./Module").BuildInfo} BuildInfo */ /** @typedef {import("./Module").BuildMeta} BuildMeta */ /** @typedef {import("./Module").CodeGenerationContext} CodeGenerationContext */ /** @typedef {import("./Module").CodeGenerationResult} CodeGenerationResult */ +/** @typedef {import("./Module").CodeGenerationResultData} CodeGenerationResultData */ /** @typedef {import("./Module").ConcatenationBailoutReasonContext} ConcatenationBailoutReasonContext */ /** @typedef {import("./Module").KnownBuildInfo} KnownBuildInfo */ /** @typedef {import("./Module").LibIdentOptions} LibIdentOptions */ @@ -399,7 +399,7 @@ class NormalModule extends Module { this._isEvaluatingSideEffects = false; /** @type {WeakSet | undefined} */ this._addedSideEffectsBailout = undefined; - /** @type {GenerateContextData} */ + /** @type {CodeGenerationResultData} */ this._codeGeneratorData = new Map(); } diff --git a/lib/asset/AssetModulesPlugin.js b/lib/asset/AssetModulesPlugin.js index 7b317cf55..ddd51dd12 100644 --- a/lib/asset/AssetModulesPlugin.js +++ b/lib/asset/AssetModulesPlugin.js @@ -245,10 +245,15 @@ class AssetModulesPlugin { entryInfo = assetInfo; entryHash = fullContentHash; } else { - entryFilename = buildInfo.filename || data.get("filename"); - entryInfo = buildInfo.assetInfo || data.get("assetInfo"); + entryFilename = + /** @type {string} */ + (buildInfo.filename || data.get("filename")); + entryInfo = + /** @type {AssetInfo} */ + (buildInfo.assetInfo || data.get("assetInfo")); entryHash = - buildInfo.fullContentHash || data.get("fullContentHash"); + /** @type {string} */ + (buildInfo.fullContentHash || data.get("fullContentHash")); } result.push({ @@ -280,10 +285,14 @@ class AssetModulesPlugin { const data = /** @type {NonNullable} */ (codeGenerationResult.data); - context.assets.set(data.get("filename"), { - source, - info: data.get("assetInfo") - }); + context.assets.set( + /** @type {string} */ + (data.get("filename")), + { + source, + info: data.get("assetInfo") + } + ); } ); } diff --git a/types.d.ts b/types.d.ts index 15e0ca177..f2a785c24 100644 --- a/types.d.ts +++ b/types.d.ts @@ -1891,7 +1891,7 @@ declare interface CodeGenerationResult { /** * the resulting data for all source types */ - data?: Map; + data?: CodeGenerationResultData; /** * the runtime requirements @@ -1903,6 +1903,13 @@ declare interface CodeGenerationResult { */ hash?: string; } +type CodeGenerationResultData = Map<"topLevelDeclarations", Set> & + Map<"chunkInitFragments", InitFragment[]> & + Map<"url", { "css-url": string }> & + Map<"filename", string> & + Map<"assetInfo", AssetInfo> & + Map<"fullContentHash", string> & + Map; declare abstract class CodeGenerationResults { map: Map>; get(module: Module, runtime: RuntimeSpec): CodeGenerationResult; @@ -5771,15 +5778,8 @@ declare interface GenerateContext { /** * get access to the code generation data */ - getData?: () => GenerateContextData; + getData?: () => CodeGenerationResultData; } -type GenerateContextData = Map<"url", { [index: string]: string }> & - Map<"fullContentHash", string> & - Map<"contentHash", string> & - Map<"filename", string> & - Map<"assetInfo", AssetInfo> & - Map<"chunkInitFragments", InitFragment[]> & - Record; declare interface GeneratedSourceInfo { /** * generated line @@ -10105,57 +10105,57 @@ declare interface ModuleFederationPluginOptions { } declare interface ModuleFilenameTemplateContext { /** - * The identifier of the module. + * the identifier of the module */ identifier: string; /** - * The shortened identifier of the module. + * the shortened identifier of the module */ shortIdentifier: string; /** - * The resource of the module request. + * the resource of the module request */ resource: string; /** - * The resource path of the module request. + * the resource path of the module request */ resourcePath: string; /** - * The absolute resource path of the module request. + * the absolute resource path of the module request */ absoluteResourcePath: string; /** - * The loaders of the module request. + * the loaders of the module request */ loaders: string; /** - * The all loaders of the module request. + * the all loaders of the module request */ allLoaders: string; /** - * The query of the module identifier. + * the query of the module identifier */ query: string; /** - * The module id of the module. + * the module id of the module */ moduleId: string; /** - * The hash of the module identifier. + * the hash of the module identifier */ hash: string; /** - * The module namespace. + * the module namespace */ namespace: string; }