diff --git a/src/hmr/hotModuleReplacement.js b/src/hmr/hotModuleReplacement.js index 26075537..e94dba9d 100644 --- a/src/hmr/hotModuleReplacement.js +++ b/src/hmr/hotModuleReplacement.js @@ -5,9 +5,6 @@ func-names */ -// eslint-disable-next-line jsdoc/no-restricted-syntax -/** @typedef {any} TODO */ - const normalizeUrl = require("./normalize-url"); const srcByModuleId = Object.create(null); @@ -47,9 +44,11 @@ function debounce(fn, time) { */ function noop() {} +/** @typedef {(filename?: string) => string[]} GetScriptSrc */ + /** * @param {string | number} moduleId a module id - * @returns {TODO} current script url + * @returns {GetScriptSrc} current script url */ function getCurrentScriptUrl(moduleId) { let src = srcByModuleId[moduleId]; @@ -69,13 +68,10 @@ function getCurrentScriptUrl(moduleId) { srcByModuleId[moduleId] = src; } - /** - * @param {string} fileMap file map - * @returns {null | string[]} normalized files - */ + /** @type {GetScriptSrc} */ return function (fileMap) { if (!src) { - return null; + return []; } const splitResult = src.split(/([^\\/]+)\.js$/); @@ -114,8 +110,10 @@ function isUrlRequest(url) { return true; } +/** @typedef {HTMLLinkElement & { isLoaded: boolean, visited: boolean }} HotHTMLLinkElement */ + /** - * @param {TODO} el html link element + * @param {HotHTMLLinkElement} el html link element * @param {string=} url a URL */ function updateCss(el, url) { @@ -145,7 +143,9 @@ function updateCss(el, url) { el.visited = true; - const newEl = el.cloneNode(); + const newEl = + /** @type {HotHTMLLinkElement} */ + (el.cloneNode()); newEl.isLoaded = false; @@ -155,7 +155,10 @@ function updateCss(el, url) { } newEl.isLoaded = true; - el.parentNode.removeChild(el); + + if (el.parentNode) { + el.parentNode.removeChild(el); + } }); newEl.addEventListener("error", () => { @@ -164,21 +167,26 @@ function updateCss(el, url) { } newEl.isLoaded = true; - el.parentNode.removeChild(el); + + if (el.parentNode) { + el.parentNode.removeChild(el); + } }); newEl.href = `${url}?${Date.now()}`; - if (el.nextSibling) { - el.parentNode.insertBefore(newEl, el.nextSibling); - } else { - el.parentNode.appendChild(newEl); + if (el.parentNode) { + if (el.nextSibling) { + el.parentNode.insertBefore(newEl, el.nextSibling); + } else { + el.parentNode.appendChild(newEl); + } } } /** * @param {string} href href - * @param {TODO} src src + * @param {string[]} src src * @returns {undefined | string} a reload url */ function getReloadUrl(href, src) { @@ -192,6 +200,7 @@ function getReloadUrl(href, src) { */ // eslint-disable-next-line array-callback-return (url) => { + // @ts-expect-error fix me in the next major release // eslint-disable-next-line unicorn/prefer-includes if (href.indexOf(src) > -1) { ret = url; @@ -203,14 +212,10 @@ function getReloadUrl(href, src) { } /** - * @param {string=} src source + * @param {string[]} src source * @returns {boolean} true when loaded, otherwise false */ function reloadStyle(src) { - if (!src) { - return false; - } - const elements = document.querySelectorAll("link"); let loaded = false; @@ -256,8 +261,8 @@ function reloadAll() { /** * @param {number | string} moduleId a module id - * @param {TODO} options options - * @returns {TODO} wrapper function + * @param {{ filename?: string, locals?: boolean }} options options + * @returns {() => void} wrapper function */ module.exports = function (moduleId, options) { if (noDocument) { diff --git a/src/index.js b/src/index.js index 19329234..944a33aa 100644 --- a/src/index.js +++ b/src/index.js @@ -21,7 +21,7 @@ const { /** @typedef {import("webpack").Compilation} Compilation */ /** @typedef {import("webpack").ChunkGraph} ChunkGraph */ /** @typedef {import("webpack").Chunk} Chunk */ -/** @typedef {Parameters[0]} ChunkGroup */ +/** @typedef {import("webpack").ChunkGroup} ChunkGroup */ /** @typedef {import("webpack").Module} Module */ /** @typedef {import("webpack").Dependency} Dependency */ /** @typedef {import("webpack").sources.Source} Source */ @@ -30,6 +30,9 @@ const { /** @typedef {import("webpack").AssetInfo} AssetInfo */ /** @typedef {import("./loader.js").Dependency} LoaderDependency */ +/** @typedef {NonNullable['output']['filename']>} Filename */ +/** @typedef {NonNullable['output']['chunkFilename']>} ChunkFilename */ + /** * @typedef {object} LoaderOptions * @property {string | ((resourcePath: string, rootContext: string) => string)=} publicPath public path @@ -41,8 +44,8 @@ const { /** * @typedef {object} PluginOptions - * @property {Required['output']['filename']=} filename filename - * @property {Required['output']['chunkFilename']=} chunkFilename chunk filename + * @property {Filename=} filename filename + * @property {ChunkFilename=} chunkFilename chunk filename * @property {boolean=} ignoreOrder true when need to ignore order, otherwise false * @property {string | ((linkTag: HTMLLinkElement) => void)=} insert link insert place or a custom insert function * @property {Record=} attributes link attributes @@ -53,8 +56,8 @@ const { /** * @typedef {object} NormalizedPluginOptions - * @property {Required['output']['filename']} filename filename - * @property {Required['output']['chunkFilename']=} chunkFilename chunk filename + * @property {Filename} filename filename + * @property {ChunkFilename=} chunkFilename chunk filename * @property {boolean} ignoreOrder true when need to ignore order, otherwise false * @property {string | ((linkTag: HTMLLinkElement) => void)=} insert a link insert place or a custom insert function * @property {Record=} attributes link attributes @@ -70,9 +73,6 @@ const { * @property {Record=} attributes link attributes */ -// eslint-disable-next-line jsdoc/no-restricted-syntax -/** @typedef {any} TODO */ - const pluginName = "mini-css-extract-plugin"; const pluginSymbol = Symbol(pluginName); @@ -89,8 +89,9 @@ const CODE_GENERATION_RESULT = { runtimeRequirements: new Set(), }; -/** @typedef {Module & { content: Buffer, media?: string, sourceMap?: Buffer, supports?: string, layer?: string, assets?: { [key: string]: TODO }, assetsInfo?: Map }} CssModule */ -/** @typedef {{ context: string | null, identifier: string, identifierIndex: number, content: Buffer, sourceMap?: Buffer, media?: string, supports?: string, layer?: TODO, assetsInfo?: Map, assets?: { [key: string]: TODO }}} CssModuleDependency */ +// eslint-disable-next-line jsdoc/no-restricted-syntax +/** @typedef {{ context: string | null, identifier: string, identifierIndex: number, content: Buffer, sourceMap?: Buffer, media?: string, supports?: string, layer?: any, assetsInfo?: Map, assets?: { [key: string]: Source }}} CssModuleDependency */ +/** @typedef {Module & { content: Buffer, media?: string, sourceMap?: Buffer, supports?: string, layer?: string, assets?: { [key: string]: Source }, assetsInfo?: Map }} CssModule */ /** @typedef {{ new(dependency: CssModuleDependency): CssModule }} CssModuleConstructor */ /** @typedef {Dependency & CssModuleDependency} CssDependency */ /** @typedef {Omit} CssDependencyOptions */ @@ -437,10 +438,8 @@ class MiniCssExtractPlugin { this.sourceMap = sourceMap; this.context = context; /** @type {{ [key: string]: Source } | undefined}} */ - this.assets = undefined; /** @type {Map | undefined} */ - this.assetsInfo = undefined; } @@ -486,7 +485,6 @@ class MiniCssExtractPlugin { } } - // @ts-expect-error cssDependencyCache.set(webpack, CssDependency); webpack.util.serialization.register( @@ -525,7 +523,6 @@ class MiniCssExtractPlugin { }, ); - // @ts-expect-error return CssDependency; } @@ -574,7 +571,6 @@ class MiniCssExtractPlugin { filename: DEFAULT_FILENAME, ignoreOrder: false, // TODO remove in the next major release - experimentalUseImportModule: undefined, runtime: true, ...options, @@ -639,7 +635,7 @@ class MiniCssExtractPlugin { ) { /** @type {Compiler["options"]["experiments"] & { executeModule?: boolean }} */ - // @ts-expect-error + // @ts-expect-error TODO remove in the next major release compiler.options.experiments.executeModule = true; } @@ -692,7 +688,7 @@ class MiniCssExtractPlugin { class CssModuleFactory { /** * @param {{ dependencies: Dependency[] }} dependencies - * @param {(arg0?: Error, arg1?: TODO) => void} callback + * @param {(err?: null | Error, result?: CssModule) => void} callback */ create({ dependencies: [dependency] }, callback) { @@ -705,6 +701,7 @@ class MiniCssExtractPlugin { compilation.dependencyFactories.set( CssDependency, + // @ts-expect-error TODO fix in the next major release and fix using `CssModuleFactory extends webpack.ModuleFactory` new CssModuleFactory(), ); @@ -722,7 +719,7 @@ class MiniCssExtractPlugin { /** * @param {ReturnType} result result * @param {Parameters[0]} chunk chunk - * @returns {TODO} a rendered manifest + * @returns {ReturnType} a rendered manifest */ (result, { chunk }) => { const { chunkGraph } = compilation; @@ -731,7 +728,7 @@ class MiniCssExtractPlugin { // We don't need hot update chunks for css // We will use the real asset instead to update if (chunk instanceof HotUpdateChunk) { - return; + return result; } const renderedModules = @@ -774,6 +771,8 @@ class MiniCssExtractPlugin { hash: chunk.contentHash[MODULE_TYPE], }); } + + return result; }, ); @@ -1232,7 +1231,7 @@ class MiniCssExtractPlugin { `${RuntimeGlobals.require}.miniCssF`, /** * @param {Chunk} referencedChunk a referenced chunk - * @returns {TODO} a template value + * @returns {ReturnType} a template value */ (referencedChunk) => { if (!referencedChunk.contentHash[MODULE_TYPE]) { @@ -1240,8 +1239,8 @@ class MiniCssExtractPlugin { } return referencedChunk.canBeInitial() - ? this.options.filename - : this.options.chunkFilename; + ? /** @type {Filename} */ (this.options.filename) + : /** @type {ChunkFilename} */ (this.options.chunkFilename); }, set.has(RuntimeGlobals.hmrDownloadUpdateHandlers), ), diff --git a/src/loader.js b/src/loader.js index 579f0062..4c69bbef 100644 --- a/src/loader.js +++ b/src/loader.js @@ -28,13 +28,13 @@ const MiniCssExtractPlugin = require("./index"); /** @typedef {{[key: string]: string | Function }} Locals */ // eslint-disable-next-line jsdoc/no-restricted-syntax -/** @typedef {any} TODO */ +/** @typedef {any} EXPECTED_ANY */ /** * @typedef {object} Dependency * @property {string} identifier identifier * @property {string | null} context context - * @property {Buffer=} content content + * @property {Buffer} content content * @property {string=} media media * @property {string=} supports supports * @property {string=} layer layer @@ -104,9 +104,9 @@ function pitch(request) { const options = this.getOptions(/** @type {Schema} */ (schema)); const emit = typeof options.emit !== "undefined" ? options.emit : true; const callback = this.async(); - const optionsFromPlugin = /** @type {TODO} */ (this)[ - MiniCssExtractPlugin.pluginSymbol - ]; + const optionsFromPlugin = + // @ts-expect-error + this[MiniCssExtractPlugin.pluginSymbol]; if (!optionsFromPlugin) { callback( @@ -121,7 +121,7 @@ function pitch(request) { const { webpack } = /** @type {Compiler} */ (this._compiler); /** - * @param {TODO} originalExports original exports + * @param {EXPECTED_ANY} originalExports original exports * @param {Compilation=} compilation compilation * @param {{ [name: string]: Source }=} assets assets * @param {Map=} assetsInfo assets info @@ -201,14 +201,15 @@ function pitch(request) { locals = {}; } - /** @type {Locals} */ (locals)[key] = originalExports[key]; + /** @type {Locals} */ + (locals)[key] = originalExports[key]; } } } else { locals = exports && exports.locals; } - /** @type {Dependency[] | [null, TODO][]} */ + /** @type {Dependency[] | [null, Record][]} */ let dependencies; if (!Array.isArray(exports)) { diff --git a/test/cases/hmr-locals/expected/main.js b/test/cases/hmr-locals/expected/main.js index 380fd841..508bacdd 100644 --- a/test/cases/hmr-locals/expected/main.js +++ b/test/cases/hmr-locals/expected/main.js @@ -14,9 +14,6 @@ func-names */ -// eslint-disable-next-line jsdoc/no-restricted-syntax -/** @typedef {any} TODO */ - const normalizeUrl = __webpack_require__(/*! ./normalize-url */ "../../../src/hmr/normalize-url.js"); const srcByModuleId = Object.create(null); @@ -56,9 +53,11 @@ function debounce(fn, time) { */ function noop() {} +/** @typedef {(filename?: string) => string[]} GetScriptSrc */ + /** * @param {string | number} moduleId a module id - * @returns {TODO} current script url + * @returns {GetScriptSrc} current script url */ function getCurrentScriptUrl(moduleId) { let src = srcByModuleId[moduleId]; @@ -78,13 +77,10 @@ function getCurrentScriptUrl(moduleId) { srcByModuleId[moduleId] = src; } - /** - * @param {string} fileMap file map - * @returns {null | string[]} normalized files - */ + /** @type {GetScriptSrc} */ return function (fileMap) { if (!src) { - return null; + return []; } const splitResult = src.split(/([^\\/]+)\.js$/); @@ -123,8 +119,10 @@ function isUrlRequest(url) { return true; } +/** @typedef {HTMLLinkElement & { isLoaded: boolean, visited: boolean }} HotHTMLLinkElement */ + /** - * @param {TODO} el html link element + * @param {HotHTMLLinkElement} el html link element * @param {string=} url a URL */ function updateCss(el, url) { @@ -154,7 +152,9 @@ function updateCss(el, url) { el.visited = true; - const newEl = el.cloneNode(); + const newEl = + /** @type {HotHTMLLinkElement} */ + (el.cloneNode()); newEl.isLoaded = false; @@ -164,7 +164,10 @@ function updateCss(el, url) { } newEl.isLoaded = true; - el.parentNode.removeChild(el); + + if (el.parentNode) { + el.parentNode.removeChild(el); + } }); newEl.addEventListener("error", () => { @@ -173,21 +176,26 @@ function updateCss(el, url) { } newEl.isLoaded = true; - el.parentNode.removeChild(el); + + if (el.parentNode) { + el.parentNode.removeChild(el); + } }); newEl.href = `${url}?${Date.now()}`; - if (el.nextSibling) { - el.parentNode.insertBefore(newEl, el.nextSibling); - } else { - el.parentNode.appendChild(newEl); + if (el.parentNode) { + if (el.nextSibling) { + el.parentNode.insertBefore(newEl, el.nextSibling); + } else { + el.parentNode.appendChild(newEl); + } } } /** * @param {string} href href - * @param {TODO} src src + * @param {string[]} src src * @returns {undefined | string} a reload url */ function getReloadUrl(href, src) { @@ -201,6 +209,7 @@ function getReloadUrl(href, src) { */ // eslint-disable-next-line array-callback-return (url) => { + // @ts-expect-error fix me in the next major release // eslint-disable-next-line unicorn/prefer-includes if (href.indexOf(src) > -1) { ret = url; @@ -212,14 +221,10 @@ function getReloadUrl(href, src) { } /** - * @param {string=} src source + * @param {string[]} src source * @returns {boolean} true when loaded, otherwise false */ function reloadStyle(src) { - if (!src) { - return false; - } - const elements = document.querySelectorAll("link"); let loaded = false; @@ -265,8 +270,8 @@ function reloadAll() { /** * @param {number | string} moduleId a module id - * @param {TODO} options options - * @returns {TODO} wrapper function + * @param {{ filename?: string, locals?: boolean }} options options + * @returns {() => void} wrapper function */ module.exports = function (moduleId, options) { if (noDocument) { diff --git a/test/cases/hmr/expected/main.js b/test/cases/hmr/expected/main.js index d44d58dc..3e706ffb 100644 --- a/test/cases/hmr/expected/main.js +++ b/test/cases/hmr/expected/main.js @@ -14,9 +14,6 @@ func-names */ -// eslint-disable-next-line jsdoc/no-restricted-syntax -/** @typedef {any} TODO */ - const normalizeUrl = __webpack_require__(/*! ./normalize-url */ "../../../src/hmr/normalize-url.js"); const srcByModuleId = Object.create(null); @@ -56,9 +53,11 @@ function debounce(fn, time) { */ function noop() {} +/** @typedef {(filename?: string) => string[]} GetScriptSrc */ + /** * @param {string | number} moduleId a module id - * @returns {TODO} current script url + * @returns {GetScriptSrc} current script url */ function getCurrentScriptUrl(moduleId) { let src = srcByModuleId[moduleId]; @@ -78,13 +77,10 @@ function getCurrentScriptUrl(moduleId) { srcByModuleId[moduleId] = src; } - /** - * @param {string} fileMap file map - * @returns {null | string[]} normalized files - */ + /** @type {GetScriptSrc} */ return function (fileMap) { if (!src) { - return null; + return []; } const splitResult = src.split(/([^\\/]+)\.js$/); @@ -123,8 +119,10 @@ function isUrlRequest(url) { return true; } +/** @typedef {HTMLLinkElement & { isLoaded: boolean, visited: boolean }} HotHTMLLinkElement */ + /** - * @param {TODO} el html link element + * @param {HotHTMLLinkElement} el html link element * @param {string=} url a URL */ function updateCss(el, url) { @@ -154,7 +152,9 @@ function updateCss(el, url) { el.visited = true; - const newEl = el.cloneNode(); + const newEl = + /** @type {HotHTMLLinkElement} */ + (el.cloneNode()); newEl.isLoaded = false; @@ -164,7 +164,10 @@ function updateCss(el, url) { } newEl.isLoaded = true; - el.parentNode.removeChild(el); + + if (el.parentNode) { + el.parentNode.removeChild(el); + } }); newEl.addEventListener("error", () => { @@ -173,21 +176,26 @@ function updateCss(el, url) { } newEl.isLoaded = true; - el.parentNode.removeChild(el); + + if (el.parentNode) { + el.parentNode.removeChild(el); + } }); newEl.href = `${url}?${Date.now()}`; - if (el.nextSibling) { - el.parentNode.insertBefore(newEl, el.nextSibling); - } else { - el.parentNode.appendChild(newEl); + if (el.parentNode) { + if (el.nextSibling) { + el.parentNode.insertBefore(newEl, el.nextSibling); + } else { + el.parentNode.appendChild(newEl); + } } } /** * @param {string} href href - * @param {TODO} src src + * @param {string[]} src src * @returns {undefined | string} a reload url */ function getReloadUrl(href, src) { @@ -201,6 +209,7 @@ function getReloadUrl(href, src) { */ // eslint-disable-next-line array-callback-return (url) => { + // @ts-expect-error fix me in the next major release // eslint-disable-next-line unicorn/prefer-includes if (href.indexOf(src) > -1) { ret = url; @@ -212,14 +221,10 @@ function getReloadUrl(href, src) { } /** - * @param {string=} src source + * @param {string[]} src source * @returns {boolean} true when loaded, otherwise false */ function reloadStyle(src) { - if (!src) { - return false; - } - const elements = document.querySelectorAll("link"); let loaded = false; @@ -265,8 +270,8 @@ function reloadAll() { /** * @param {number | string} moduleId a module id - * @param {TODO} options options - * @returns {TODO} wrapper function + * @param {{ filename?: string, locals?: boolean }} options options + * @returns {() => void} wrapper function */ module.exports = function (moduleId, options) { if (noDocument) { diff --git a/types/hmr/hotModuleReplacement.d.ts b/types/hmr/hotModuleReplacement.d.ts index 8f72d9f8..b8238313 100644 --- a/types/hmr/hotModuleReplacement.d.ts +++ b/types/hmr/hotModuleReplacement.d.ts @@ -1,6 +1,16 @@ declare namespace _exports { - export { TODO }; + export { GetScriptSrc, HotHTMLLinkElement }; } -declare function _exports(moduleId: number | string, options: TODO): TODO; +declare function _exports( + moduleId: number | string, + options: { + filename?: string; + locals?: boolean; + }, +): () => void; export = _exports; -type TODO = any; +type GetScriptSrc = (filename?: string) => string[]; +type HotHTMLLinkElement = HTMLLinkElement & { + isLoaded: boolean; + visited: boolean; +}; diff --git a/types/index.d.ts b/types/index.d.ts index bf2a3d83..ad31d5ee 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -90,13 +90,14 @@ declare namespace MiniCssExtractPlugin { WebpackError, AssetInfo, LoaderDependency, + Filename, + ChunkFilename, LoaderOptions, PluginOptions, NormalizedPluginOptions, RuntimeOptions, - TODO, - CssModule, CssModuleDependency, + CssModule, CssModuleConstructor, CssDependency, CssDependencyOptions, @@ -110,7 +111,7 @@ declare namespace MiniCssExtractPlugin { /** @typedef {import("webpack").Compilation} Compilation */ /** @typedef {import("webpack").ChunkGraph} ChunkGraph */ /** @typedef {import("webpack").Chunk} Chunk */ -/** @typedef {Parameters[0]} ChunkGroup */ +/** @typedef {import("webpack").ChunkGroup} ChunkGroup */ /** @typedef {import("webpack").Module} Module */ /** @typedef {import("webpack").Dependency} Dependency */ /** @typedef {import("webpack").sources.Source} Source */ @@ -118,6 +119,8 @@ declare namespace MiniCssExtractPlugin { /** @typedef {import("webpack").WebpackError} WebpackError */ /** @typedef {import("webpack").AssetInfo} AssetInfo */ /** @typedef {import("./loader.js").Dependency} LoaderDependency */ +/** @typedef {NonNullable['output']['filename']>} Filename */ +/** @typedef {NonNullable['output']['chunkFilename']>} ChunkFilename */ /** * @typedef {object} LoaderOptions * @property {string | ((resourcePath: string, rootContext: string) => string)=} publicPath public path @@ -128,8 +131,8 @@ declare namespace MiniCssExtractPlugin { */ /** * @typedef {object} PluginOptions - * @property {Required['output']['filename']=} filename filename - * @property {Required['output']['chunkFilename']=} chunkFilename chunk filename + * @property {Filename=} filename filename + * @property {ChunkFilename=} chunkFilename chunk filename * @property {boolean=} ignoreOrder true when need to ignore order, otherwise false * @property {string | ((linkTag: HTMLLinkElement) => void)=} insert link insert place or a custom insert function * @property {Record=} attributes link attributes @@ -139,8 +142,8 @@ declare namespace MiniCssExtractPlugin { */ /** * @typedef {object} NormalizedPluginOptions - * @property {Required['output']['filename']} filename filename - * @property {Required['output']['chunkFilename']=} chunkFilename chunk filename + * @property {Filename} filename filename + * @property {ChunkFilename=} chunkFilename chunk filename * @property {boolean} ignoreOrder true when need to ignore order, otherwise false * @property {string | ((linkTag: HTMLLinkElement) => void)=} insert a link insert place or a custom insert function * @property {Record=} attributes link attributes @@ -154,7 +157,6 @@ declare namespace MiniCssExtractPlugin { * @property {string | false | 'text/css'} linkType value of a link type attribute * @property {Record=} attributes link attributes */ -/** @typedef {any} TODO */ declare const pluginName: "mini-css-extract-plugin"; declare const pluginSymbol: unique symbol; declare var loader: string; @@ -163,7 +165,7 @@ type Compiler = import("webpack").Compiler; type Compilation = import("webpack").Compilation; type ChunkGraph = import("webpack").ChunkGraph; type Chunk = import("webpack").Chunk; -type ChunkGroup = Parameters[0]; +type ChunkGroup = import("webpack").ChunkGroup; type Module = import("webpack").Module; type Dependency = import("webpack").Dependency; type Source = import("webpack").sources.Source; @@ -171,6 +173,10 @@ type Configuration = import("webpack").Configuration; type WebpackError = import("webpack").WebpackError; type AssetInfo = import("webpack").AssetInfo; type LoaderDependency = import("./loader.js").Dependency; +type Filename = NonNullable["output"]["filename"]>; +type ChunkFilename = NonNullable< + Required["output"]["chunkFilename"] +>; type LoaderOptions = { /** * public path @@ -199,13 +205,11 @@ type PluginOptions = { /** * filename */ - filename?: Required["output"]["filename"] | undefined; + filename?: Filename | undefined; /** * chunk filename */ - chunkFilename?: - | Required["output"]["chunkFilename"] - | undefined; + chunkFilename?: ChunkFilename | undefined; /** * true when need to ignore order, otherwise false */ @@ -235,13 +239,11 @@ type NormalizedPluginOptions = { /** * filename */ - filename: Required["output"]["filename"]; + filename: Filename; /** * chunk filename */ - chunkFilename?: - | Required["output"]["chunkFilename"] - | undefined; + chunkFilename?: ChunkFilename | undefined; /** * true when need to ignore order, otherwise false */ @@ -281,18 +283,6 @@ type RuntimeOptions = { */ attributes?: Record | undefined; }; -type TODO = any; -type CssModule = Module & { - content: Buffer; - media?: string; - sourceMap?: Buffer; - supports?: string; - layer?: string; - assets?: { - [key: string]: TODO; - }; - assetsInfo?: Map; -}; type CssModuleDependency = { context: string | null; identifier: string; @@ -301,11 +291,22 @@ type CssModuleDependency = { sourceMap?: Buffer; media?: string; supports?: string; - layer?: TODO; + layer?: any; assetsInfo?: Map; assets?: { - [key: string]: TODO; + [key: string]: Source; + }; +}; +type CssModule = Module & { + content: Buffer; + media?: string; + sourceMap?: Buffer; + supports?: string; + layer?: string; + assets?: { + [key: string]: Source; }; + assetsInfo?: Map; }; type CssModuleConstructor = { new (dependency: CssModuleDependency): CssModule; diff --git a/types/loader.d.ts b/types/loader.d.ts index f111cbfc..11c90aa6 100644 --- a/types/loader.d.ts +++ b/types/loader.d.ts @@ -22,7 +22,7 @@ declare namespace loader { NormalModule, LoaderOptions, Locals, - TODO, + EXPECTED_ANY, Dependency, }; } @@ -37,12 +37,12 @@ import MiniCssExtractPlugin = require("./index"); /** @typedef {import("webpack").NormalModule} NormalModule */ /** @typedef {import("./index.js").LoaderOptions} LoaderOptions */ /** @typedef {{[key: string]: string | Function }} Locals */ -/** @typedef {any} TODO */ +/** @typedef {any} EXPECTED_ANY */ /** * @typedef {object} Dependency * @property {string} identifier identifier * @property {string | null} context context - * @property {Buffer=} content content + * @property {Buffer} content content * @property {string=} media media * @property {string=} supports supports * @property {string=} layer layer @@ -81,7 +81,7 @@ type LoaderOptions = import("./index.js").LoaderOptions; type Locals = { [key: string]: string | Function; }; -type TODO = any; +type EXPECTED_ANY = any; type Dependency = { /** * identifier @@ -94,7 +94,7 @@ type Dependency = { /** * content */ - content?: Buffer | undefined; + content: Buffer; /** * media */