mini-css-extract-plugin
Advanced tools
| "use strict"; | ||
| /* eslint-env browser */ | ||
| /* global document */ | ||
| /* | ||
@@ -10,4 +10,2 @@ eslint-disable | ||
| /** @typedef {any} TODO */ | ||
| var normalizeUrl = require("./normalize-url"); | ||
@@ -18,6 +16,7 @@ var srcByModuleId = Object.create(null); | ||
| // eslint-disable-next-line jsdoc/no-restricted-syntax | ||
| /** | ||
| * @param {function} fn | ||
| * @param {number} time | ||
| * @returns {(function(): void)|*} | ||
| * @param {Function} fn any function | ||
| * @param {number} time time | ||
| * @returns {() => void} wrapped function | ||
| */ | ||
@@ -27,6 +26,7 @@ function debounce(fn, time) { | ||
| return function () { | ||
| // @ts-ignore | ||
| // @ts-expect-error | ||
| var self = this; | ||
| // eslint-disable-next-line prefer-rest-params | ||
| var args = arguments; | ||
| // eslint-disable-next-line func-style | ||
| var functionCall = function functionCall() { | ||
@@ -37,11 +37,17 @@ return fn.apply(self, args); | ||
| // @ts-ignore | ||
| // @ts-expect-error | ||
| timeout = setTimeout(functionCall, time); | ||
| }; | ||
| } | ||
| /** | ||
| * @returns {void} | ||
| */ | ||
| function noop() {} | ||
| /** @typedef {(filename?: string) => string[]} GetScriptSrc */ | ||
| /** | ||
| * @param {TODO} moduleId | ||
| * @returns {TODO} | ||
| * @param {string | number} moduleId a module id | ||
| * @returns {GetScriptSrc} current script url | ||
| */ | ||
@@ -63,9 +69,6 @@ function getCurrentScriptUrl(moduleId) { | ||
| /** | ||
| * @param {string} fileMap | ||
| * @returns {null | string[]} | ||
| */ | ||
| /** @type {GetScriptSrc} */ | ||
| return function (fileMap) { | ||
| if (!src) { | ||
| return null; | ||
| return []; | ||
| } | ||
@@ -88,5 +91,21 @@ var splitResult = src.split(/([^\\/]+)\.js$/); | ||
| /** | ||
| * @param {TODO} el | ||
| * @param {string} [url] | ||
| * @param {string} url URL | ||
| * @returns {boolean} true when URL can be request, otherwise false | ||
| */ | ||
| function isUrlRequest(url) { | ||
| // An URL is not an request if | ||
| // It is not http or https | ||
| if (!/^[a-zA-Z][a-zA-Z\d+\-.]*:/.test(url)) { | ||
| return false; | ||
| } | ||
| return true; | ||
| } | ||
| /** @typedef {HTMLLinkElement & { isLoaded: boolean, visited: boolean }} HotHTMLLinkElement */ | ||
| /** | ||
| * @param {HotHTMLLinkElement} el html link element | ||
| * @param {string=} url a URL | ||
| */ | ||
| function updateCss(el, url) { | ||
@@ -109,9 +128,10 @@ if (!url) { | ||
| } | ||
| // eslint-disable-next-line unicorn/prefer-includes | ||
| if (!url || !(url.indexOf(".css") > -1)) { | ||
| return; | ||
| } | ||
| // eslint-disable-next-line no-param-reassign | ||
| el.visited = true; | ||
| var newEl = el.cloneNode(); | ||
| var newEl = /** @type {HotHTMLLinkElement} */ | ||
| el.cloneNode(); | ||
| newEl.isLoaded = false; | ||
@@ -123,3 +143,5 @@ newEl.addEventListener("load", function () { | ||
| newEl.isLoaded = true; | ||
| el.parentNode.removeChild(el); | ||
| if (el.parentNode) { | ||
| el.parentNode.removeChild(el); | ||
| } | ||
| }); | ||
@@ -131,9 +153,13 @@ newEl.addEventListener("error", function () { | ||
| newEl.isLoaded = true; | ||
| el.parentNode.removeChild(el); | ||
| if (el.parentNode) { | ||
| el.parentNode.removeChild(el); | ||
| } | ||
| }); | ||
| newEl.href = "".concat(url, "?").concat(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); | ||
| } | ||
| } | ||
@@ -143,17 +169,17 @@ } | ||
| /** | ||
| * @param {string} href | ||
| * @param {TODO} src | ||
| * @returns {TODO} | ||
| * @param {string} href href | ||
| * @param {string[]} src src | ||
| * @returns {undefined | string} a reload url | ||
| */ | ||
| function getReloadUrl(href, src) { | ||
| var ret; | ||
| // eslint-disable-next-line no-param-reassign | ||
| href = normalizeUrl(href); | ||
| src.some( | ||
| /** | ||
| * @param {string} url | ||
| * @param {string} url url | ||
| */ | ||
| // eslint-disable-next-line array-callback-return | ||
| function (url) { | ||
| // @ts-expect-error fix me in the next major release | ||
| // eslint-disable-next-line unicorn/prefer-includes | ||
| if (href.indexOf(src) > -1) { | ||
@@ -167,9 +193,6 @@ ret = url; | ||
| /** | ||
| * @param {string} [src] | ||
| * @returns {boolean} | ||
| * @param {string[]} src source | ||
| * @returns {boolean} true when loaded, otherwise false | ||
| */ | ||
| function reloadStyle(src) { | ||
| if (!src) { | ||
| return false; | ||
| } | ||
| var elements = document.querySelectorAll("link"); | ||
@@ -182,3 +205,3 @@ var loaded = false; | ||
| var url = getReloadUrl(el.href, src); | ||
| if (!isUrlRequest(url)) { | ||
| if (url && !isUrlRequest(url)) { | ||
| return; | ||
@@ -196,2 +219,6 @@ } | ||
| } | ||
| /** | ||
| * @returns {void} | ||
| */ | ||
| function reloadAll() { | ||
@@ -208,20 +235,6 @@ var elements = document.querySelectorAll("link"); | ||
| /** | ||
| * @param {string} url | ||
| * @returns {boolean} | ||
| * @param {number | string} moduleId a module id | ||
| * @param {{ filename?: string, locals?: boolean }} options options | ||
| * @returns {() => void} wrapper function | ||
| */ | ||
| function isUrlRequest(url) { | ||
| // An URL is not an request if | ||
| // It is not http or https | ||
| if (!/^[a-zA-Z][a-zA-Z\d+\-.]*:/.test(url)) { | ||
| return false; | ||
| } | ||
| return true; | ||
| } | ||
| /** | ||
| * @param {TODO} moduleId | ||
| * @param {TODO} options | ||
| * @returns {TODO} | ||
| */ | ||
| module.exports = function (moduleId, options) { | ||
@@ -233,2 +246,6 @@ if (noDocument) { | ||
| var getScriptSrc = getCurrentScriptUrl(moduleId); | ||
| /** | ||
| * @returns {void} | ||
| */ | ||
| function update() { | ||
@@ -235,0 +252,0 @@ var src = getScriptSrc(options.filename); |
| "use strict"; | ||
| /* eslint-disable */ | ||
| /** | ||
| * @param {string[]} pathComponents | ||
| * @returns {string} | ||
| * @param {string[]} pathComponents path components | ||
| * @returns {string} normalized url | ||
| */ | ||
| function normalizeUrl(pathComponents) { | ||
| function normalizeUrlInner(pathComponents) { | ||
| return pathComponents.reduce(function (accumulator, item) { | ||
@@ -25,6 +23,6 @@ switch (item) { | ||
| /** | ||
| * @param {string} urlString | ||
| * @returns {string} | ||
| * @param {string} urlString url string | ||
| * @returns {string} normalized url string | ||
| */ | ||
| module.exports = function (urlString) { | ||
| module.exports = function normalizeUrl(urlString) { | ||
| urlString = urlString.trim(); | ||
@@ -34,8 +32,10 @@ if (/^data:/i.test(urlString)) { | ||
| } | ||
| var protocol = urlString.indexOf("//") !== -1 ? urlString.split("//")[0] + "//" : ""; | ||
| var protocol = | ||
| // eslint-disable-next-line unicorn/prefer-includes | ||
| urlString.indexOf("//") !== -1 ? "".concat(urlString.split("//")[0], "//") : ""; | ||
| var components = urlString.replace(new RegExp(protocol, "i"), "").split("/"); | ||
| var host = components[0].toLowerCase().replace(/\.$/, ""); | ||
| components[0] = ""; | ||
| var path = normalizeUrl(components); | ||
| var path = normalizeUrlInner(components); | ||
| return protocol + host + path; | ||
| }; |
+149
-179
| "use strict"; | ||
| /* eslint-disable class-methods-use-this */ | ||
| const path = require("path"); | ||
@@ -14,11 +12,11 @@ const { | ||
| const { | ||
| trueFn, | ||
| ABSOLUTE_PUBLIC_PATH, | ||
| AUTO_PUBLIC_PATH, | ||
| BASE_URI, | ||
| MODULE_TYPE, | ||
| AUTO_PUBLIC_PATH, | ||
| ABSOLUTE_PUBLIC_PATH, | ||
| SINGLE_DOT_PATH_SEGMENT, | ||
| compareModulesByIdentifier, | ||
| compileBooleanMatcher, | ||
| getUndoPath, | ||
| BASE_URI, | ||
| compileBooleanMatcher | ||
| trueFn | ||
| } = require("./utils"); | ||
@@ -31,3 +29,3 @@ | ||
| /** @typedef {import("webpack").Chunk} Chunk */ | ||
| /** @typedef {Parameters<import("webpack").Chunk["isInGroup"]>[0]} ChunkGroup */ | ||
| /** @typedef {import("webpack").ChunkGroup} ChunkGroup */ | ||
| /** @typedef {import("webpack").Module} Module */ | ||
@@ -41,44 +39,45 @@ /** @typedef {import("webpack").Dependency} Dependency */ | ||
| /** @typedef {NonNullable<Required<Configuration>['output']['filename']>} Filename */ | ||
| /** @typedef {NonNullable<Required<Configuration>['output']['chunkFilename']>} ChunkFilename */ | ||
| /** | ||
| * @typedef {Object} LoaderOptions | ||
| * @property {string | ((resourcePath: string, rootContext: string) => string)} [publicPath] | ||
| * @property {boolean} [emit] | ||
| * @property {boolean} [esModule] | ||
| * @property {string} [layer] | ||
| * @property {boolean} [defaultExport] | ||
| * @typedef {object} LoaderOptions | ||
| * @property {string | ((resourcePath: string, rootContext: string) => string)=} publicPath public path | ||
| * @property {boolean=} emit true when need to emit, otherwise false | ||
| * @property {boolean=} esModule need to generate ES module syntax | ||
| * @property {string=} layer a layer | ||
| * @property {boolean=} defaultExport true when need to use default export, otherwise false | ||
| */ | ||
| /** | ||
| * @typedef {Object} PluginOptions | ||
| * @property {Required<Configuration>['output']['filename']} [filename] | ||
| * @property {Required<Configuration>['output']['chunkFilename']} [chunkFilename] | ||
| * @property {boolean} [ignoreOrder] | ||
| * @property {string | ((linkTag: HTMLLinkElement) => void)} [insert] | ||
| * @property {Record<string, string>} [attributes] | ||
| * @property {string | false | 'text/css'} [linkType] | ||
| * @property {boolean} [runtime] | ||
| * @property {boolean} [experimentalUseImportModule] | ||
| * @typedef {object} PluginOptions | ||
| * @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<string, string>=} attributes link attributes | ||
| * @property {string | false | 'text/css'=} linkType value of a link type attribute | ||
| * @property {boolean=} runtime true when need to generate runtime code, otherwise false | ||
| * @property {boolean=} experimentalUseImportModule true when need to use `experimentalUseImportModule` API, otherwise false | ||
| */ | ||
| /** | ||
| * @typedef {Object} NormalizedPluginOptions | ||
| * @property {Required<Configuration>['output']['filename']} filename | ||
| * @property {Required<Configuration>['output']['chunkFilename']} [chunkFilename] | ||
| * @property {boolean} ignoreOrder | ||
| * @property {string | ((linkTag: HTMLLinkElement) => void)} [insert] | ||
| * @property {Record<string, string>} [attributes] | ||
| * @property {string | false | 'text/css'} [linkType] | ||
| * @property {boolean} runtime | ||
| * @property {boolean} [experimentalUseImportModule] | ||
| * @typedef {object} NormalizedPluginOptions | ||
| * @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<string, string>=} attributes link attributes | ||
| * @property {string | false | 'text/css'=} linkType value of a link type attribute | ||
| * @property {boolean} runtime true when need to generate runtime code, otherwise false | ||
| * @property {boolean=} experimentalUseImportModule true when need to use `experimentalUseImportModule` API, otherwise false | ||
| */ | ||
| /** | ||
| * @typedef {Object} RuntimeOptions | ||
| * @property {string | ((linkTag: HTMLLinkElement) => void) | undefined} insert | ||
| * @property {string | false | 'text/css'} linkType | ||
| * @property {Record<string, string> | undefined} attributes | ||
| * @typedef {object} RuntimeOptions | ||
| * @property {string | ((linkTag: HTMLLinkElement) => void)=} insert a link insert place or a custom insert function | ||
| * @property {string | false | 'text/css'} linkType value of a link type attribute | ||
| * @property {Record<string, string>=} attributes link attributes | ||
| */ | ||
| /** @typedef {any} TODO */ | ||
| const pluginName = "mini-css-extract-plugin"; | ||
@@ -99,4 +98,5 @@ const pluginSymbol = Symbol(pluginName); | ||
| /** @typedef {Module & { content: Buffer, media?: string, sourceMap?: Buffer, supports?: string, layer?: string, assets?: { [key: string]: TODO }, assetsInfo?: Map<string, AssetInfo> }} CssModule */ | ||
| /** @typedef {{ context: string | null, identifier: string, identifierIndex: number, content: Buffer, sourceMap?: Buffer, media?: string, supports?: string, layer?: TODO, assetsInfo?: Map<string, AssetInfo>, 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<string, AssetInfo>, assets?: { [key: string]: Source }}} CssModuleDependency */ | ||
| /** @typedef {Module & { content: Buffer, media?: string, sourceMap?: Buffer, supports?: string, layer?: string, assets?: { [key: string]: Source }, assetsInfo?: Map<string, AssetInfo> }} CssModule */ | ||
| /** @typedef {{ new(dependency: CssModuleDependency): CssModule }} CssModuleConstructor */ | ||
@@ -106,19 +106,20 @@ /** @typedef {Dependency & CssModuleDependency} CssDependency */ | ||
| /** @typedef {{ new(loaderDependency: CssDependencyOptions, context: string | null, identifierIndex: number): CssDependency }} CssDependencyConstructor */ | ||
| /** | ||
| * @typedef {Object} VarNames | ||
| * @property {string} tag | ||
| * @property {string} chunkId | ||
| * @property {string} href | ||
| * @property {string} resolve | ||
| * @property {string} reject | ||
| * @typedef {object} VarNames | ||
| * @property {string} tag tag | ||
| * @property {string} chunkId chunk id | ||
| * @property {string} href href | ||
| * @property {string} resolve resolve | ||
| * @property {string} reject reject | ||
| */ | ||
| /** | ||
| * @typedef {Object} MiniCssExtractPluginCompilationHooks | ||
| * @property {import("tapable").SyncWaterfallHook<[string, VarNames], string>} beforeTagInsert | ||
| * @property {SyncWaterfallHook<[string, Chunk]>} linkPreload | ||
| * @property {SyncWaterfallHook<[string, Chunk]>} linkPrefetch | ||
| * @typedef {object} MiniCssExtractPluginCompilationHooks | ||
| * @property {import("tapable").SyncWaterfallHook<[string, VarNames], string>} beforeTagInsert before tag insert hook | ||
| * @property {SyncWaterfallHook<[string, Chunk]>} linkPreload link preload hook | ||
| * @property {SyncWaterfallHook<[string, Chunk]>} linkPrefetch link prefetch hook | ||
| */ | ||
| /** | ||
| * | ||
| * @type {WeakMap<Compiler["webpack"], CssModuleConstructor>} | ||
@@ -140,4 +141,4 @@ */ | ||
| /** | ||
| * @param {Compiler["webpack"]} webpack | ||
| * @returns {CssModuleConstructor} | ||
| * @param {Compiler["webpack"]} webpack webpack | ||
| * @returns {CssModuleConstructor} CSS module constructor | ||
| */ | ||
@@ -153,3 +154,3 @@ static getCssModule(webpack) { | ||
| /** | ||
| * @param {CssModuleDependency} dependency | ||
| * @param {CssModuleDependency} dependency css module dependency | ||
| */ | ||
@@ -168,3 +169,2 @@ constructor({ | ||
| }) { | ||
| // @ts-ignore | ||
| super(MODULE_TYPE, /** @type {string | undefined} */context); | ||
@@ -195,4 +195,4 @@ this.id = ""; | ||
| /** | ||
| * @param {Parameters<Module["readableIdentifier"]>[0]} requestShortener | ||
| * @returns {ReturnType<Module["readableIdentifier"]>} | ||
| * @param {Parameters<Module["readableIdentifier"]>[0]} requestShortener request shortener | ||
| * @returns {ReturnType<Module["readableIdentifier"]>} readable identifier | ||
| */ | ||
@@ -202,9 +202,5 @@ readableIdentifier(requestShortener) { | ||
| } | ||
| // eslint-disable-next-line class-methods-use-this | ||
| getSourceTypes() { | ||
| return TYPES; | ||
| } | ||
| // eslint-disable-next-line class-methods-use-this | ||
| codeGeneration() { | ||
@@ -218,3 +214,3 @@ return CODE_GENERATION_RESULT; | ||
| if (idx >= 0) { | ||
| return resource.substring(0, idx); | ||
| return resource.slice(0, Math.max(0, idx)); | ||
| } | ||
@@ -225,6 +221,6 @@ return resource; | ||
| /** | ||
| * @param {Module} module | ||
| * @param {Module} module a module | ||
| */ | ||
| updateCacheModule(module) { | ||
| if (!this.content.equals(/** @type {CssModule} */module.content) || this.layer !== /** @type {CssModule} */module.layer || this.supports !== /** @type {CssModule} */module.supports || this.media !== /** @type {CssModule} */module.media || (this.sourceMap ? !this.sourceMap.equals(/** @type {Uint8Array} **/ | ||
| if (!this.content.equals(/** @type {CssModule} */module.content) || this.layer !== /** @type {CssModule} */module.layer || this.supports !== /** @type {CssModule} */module.supports || this.media !== /** @type {CssModule} */module.media || (this.sourceMap ? !this.sourceMap.equals(/** @type {Uint8Array} * */ | ||
| /** @type {CssModule} */module.sourceMap) : false) || this.assets !== /** @type {CssModule} */module.assets || this.assetsInfo !== /** @type {CssModule} */module.assetsInfo) { | ||
@@ -241,4 +237,2 @@ this._needBuild = true; | ||
| } | ||
| // eslint-disable-next-line class-methods-use-this | ||
| needRebuild() { | ||
@@ -248,3 +242,2 @@ return this._needBuild; | ||
| // eslint-disable-next-line class-methods-use-this | ||
| /** | ||
@@ -255,3 +248,2 @@ * @param {Parameters<Module["needBuild"]>[0]} context context info | ||
| needBuild(context, callback) { | ||
| // eslint-disable-next-line no-undefined | ||
| callback(undefined, this._needBuild); | ||
@@ -261,7 +253,7 @@ } | ||
| /** | ||
| * @param {Parameters<Module["build"]>[0]} options | ||
| * @param {Parameters<Module["build"]>[1]} compilation | ||
| * @param {Parameters<Module["build"]>[2]} resolver | ||
| * @param {Parameters<Module["build"]>[3]} fileSystem | ||
| * @param {Parameters<Module["build"]>[4]} callback | ||
| * @param {Parameters<Module["build"]>[0]} options options | ||
| * @param {Parameters<Module["build"]>[1]} compilation compilation | ||
| * @param {Parameters<Module["build"]>[2]} resolver resolver | ||
| * @param {Parameters<Module["build"]>[3]} fileSystem file system | ||
| * @param {Parameters<Module["build"]>[4]} callback callback | ||
| */ | ||
@@ -285,4 +277,4 @@ build(options, compilation, resolver, fileSystem, callback) { | ||
| * @private | ||
| * @param {string} hashFunction | ||
| * @returns {string | Buffer} | ||
| * @param {string} hashFunction hash function | ||
| * @returns {string | Buffer} hash digest | ||
| */ | ||
@@ -302,4 +294,4 @@ _computeHash(hashFunction) { | ||
| /** | ||
| * @param {Parameters<Module["updateHash"]>[0]} hash | ||
| * @param {Parameters<Module["updateHash"]>[1]} context | ||
| * @param {Parameters<Module["updateHash"]>[0]} hash hash | ||
| * @param {Parameters<Module["updateHash"]>[1]} context context | ||
| */ | ||
@@ -314,3 +306,3 @@ updateHash(hash, context) { | ||
| /** | ||
| * @param {Parameters<Module["serialize"]>[0]} context | ||
| * @param {Parameters<Module["serialize"]>[0]} context serializer context | ||
| */ | ||
@@ -336,3 +328,3 @@ serialize(context) { | ||
| /** | ||
| * @param {Parameters<Module["deserialize"]>[0]} context | ||
| * @param {Parameters<Module["deserialize"]>[0]} context deserializer context | ||
| */ | ||
@@ -345,5 +337,3 @@ deserialize(context) { | ||
| cssModuleCache.set(webpack, CssModule); | ||
| webpack.util.serialization.register(CssModule, path.resolve(__dirname, "CssModule"), | ||
| // @ts-ignore | ||
| null, { | ||
| webpack.util.serialization.register(CssModule, path.resolve(__dirname, "CssModule"), null, { | ||
| serialize(instance, context) { | ||
@@ -386,4 +376,4 @@ instance.serialize(context); | ||
| /** | ||
| * @param {Compiler["webpack"]} webpack | ||
| * @returns {CssDependencyConstructor} | ||
| * @param {Compiler["webpack"]} webpack webpack | ||
| * @returns {CssDependencyConstructor} CSS dependency constructor | ||
| */ | ||
@@ -399,5 +389,5 @@ static getCssDependency(webpack) { | ||
| /** | ||
| * @param {CssDependencyOptions} loaderDependency | ||
| * @param {string | null} context | ||
| * @param {number} identifierIndex | ||
| * @param {CssDependencyOptions} loaderDependency loader dependency | ||
| * @param {string | null} context context | ||
| * @param {number} identifierIndex identifier index | ||
| */ | ||
@@ -422,6 +412,4 @@ constructor({ | ||
| /** @type {{ [key: string]: Source } | undefined}} */ | ||
| // eslint-disable-next-line no-undefined | ||
| this.assets = undefined; | ||
| /** @type {Map<string, AssetInfo> | undefined} */ | ||
| // eslint-disable-next-line no-undefined | ||
| this.assetsInfo = undefined; | ||
@@ -431,3 +419,3 @@ } | ||
| /** | ||
| * @returns {ReturnType<Dependency["getResourceIdentifier"]>} | ||
| * @returns {ReturnType<Dependency["getResourceIdentifier"]>} a resource identifier | ||
| */ | ||
@@ -439,5 +427,4 @@ getResourceIdentifier() { | ||
| /** | ||
| * @returns {ReturnType<Dependency["getModuleEvaluationSideEffectsState"]>} | ||
| * @returns {ReturnType<Dependency["getModuleEvaluationSideEffectsState"]>} side effect state | ||
| */ | ||
| // eslint-disable-next-line class-methods-use-this | ||
| getModuleEvaluationSideEffectsState() { | ||
@@ -448,3 +435,3 @@ return webpack.ModuleGraphConnection.TRANSITIVE_ONLY; | ||
| /** | ||
| * @param {Parameters<Dependency["serialize"]>[0]} context | ||
| * @param {Parameters<Dependency["serialize"]>[0]} context serializer context | ||
| */ | ||
@@ -469,3 +456,3 @@ serialize(context) { | ||
| /** | ||
| * @param {Parameters<Dependency["deserialize"]>[0]} context | ||
| * @param {Parameters<Dependency["deserialize"]>[0]} context deserializer context | ||
| */ | ||
@@ -477,5 +464,3 @@ deserialize(context) { | ||
| cssDependencyCache.set(webpack, CssDependency); | ||
| webpack.util.serialization.register(CssDependency, path.resolve(__dirname, "CssDependency"), | ||
| // @ts-ignore | ||
| null, { | ||
| webpack.util.serialization.register(CssDependency, path.resolve(__dirname, "CssDependency"), null, { | ||
| serialize(instance, context) { | ||
@@ -526,3 +511,3 @@ instance.serialize(context); | ||
| /** | ||
| * @param {PluginOptions} [options] | ||
| * @param {PluginOptions=} options options | ||
| */ | ||
@@ -537,3 +522,2 @@ constructor(options = {}) { | ||
| * @type {WeakMap<Chunk, Set<CssModule>>} | ||
| * @private | ||
| */ | ||
@@ -546,10 +530,10 @@ this._sortedModulesCache = new WeakMap(); | ||
| */ | ||
| this.options = Object.assign({ | ||
| this.options = { | ||
| filename: DEFAULT_FILENAME, | ||
| ignoreOrder: false, | ||
| // TODO remove in the next major release | ||
| // eslint-disable-next-line no-undefined | ||
| experimentalUseImportModule: undefined, | ||
| runtime: true | ||
| }, options); | ||
| runtime: true, | ||
| ...options | ||
| }; | ||
@@ -594,3 +578,3 @@ /** | ||
| /** | ||
| * @param {Compiler} compiler | ||
| * @param {Compiler} compiler compiler | ||
| */ | ||
@@ -601,9 +585,8 @@ apply(compiler) { | ||
| } = compiler; | ||
| if (this.options.experimentalUseImportModule) { | ||
| if (typeof (/** @type {Compiler["options"]["experiments"] & { executeModule?: boolean }} */ | ||
| compiler.options.experiments.executeModule) === "undefined") { | ||
| /** @type {Compiler["options"]["experiments"] & { executeModule?: boolean }} */ | ||
| // eslint-disable-next-line no-param-reassign | ||
| compiler.options.experiments.executeModule = true; | ||
| } | ||
| if (this.options.experimentalUseImportModule && typeof (/** @type {Compiler["options"]["experiments"] & { executeModule?: boolean }} */ | ||
| compiler.options.experiments.executeModule) === "undefined") { | ||
| /** @type {Compiler["options"]["experiments"] & { executeModule?: boolean }} */ | ||
| // @ts-expect-error TODO remove in the next major release | ||
| compiler.options.experiments.executeModule = true; | ||
| } | ||
@@ -620,7 +603,5 @@ | ||
| } = compiler.options.optimization; | ||
| if (splitChunks) { | ||
| if (/** @type {string[]} */splitChunks.defaultSizeTypes.includes("...")) { | ||
| /** @type {string[]} */ | ||
| splitChunks.defaultSizeTypes.push(MODULE_TYPE); | ||
| } | ||
| if (splitChunks && /** @type {string[]} */splitChunks.defaultSizeTypes.includes("...")) { | ||
| /** @type {string[]} */ | ||
| splitChunks.defaultSizeTypes.push(MODULE_TYPE); | ||
| } | ||
@@ -638,7 +619,6 @@ const CssModule = MiniCssExtractPlugin.getCssModule(webpack); | ||
| /** | ||
| * @param {object} loaderContext | ||
| * @param {object} loaderContext loader context | ||
| */ | ||
| loaderContext => { | ||
| /** @type {object & { [pluginSymbol]: { experimentalUseImportModule: boolean | undefined } }} */ | ||
| // eslint-disable-next-line no-param-reassign | ||
| loaderContext[pluginSymbol] = { | ||
@@ -653,16 +633,15 @@ experimentalUseImportModule: this.options.experimentalUseImportModule | ||
| * @param {{ dependencies: Dependency[] }} dependencies | ||
| * @param {(arg0?: Error, arg1?: TODO) => void} callback | ||
| * @param {(err?: null | Error, result?: CssModule) => void} callback | ||
| */ | ||
| // eslint-disable-next-line class-methods-use-this | ||
| create({ | ||
| dependencies: [dependency] | ||
| }, callback) { | ||
| callback( | ||
| // eslint-disable-next-line no-undefined | ||
| undefined, new CssModule(/** @type {CssDependency} */dependency)); | ||
| callback(undefined, new CssModule(/** @type {CssDependency} */dependency)); | ||
| } | ||
| } | ||
| compilation.dependencyFactories.set(CssDependency, new CssModuleFactory()); | ||
| compilation.dependencyFactories.set(CssDependency, | ||
| // @ts-expect-error TODO fix in the next major release and fix using `CssModuleFactory extends webpack.ModuleFactory` | ||
| new CssModuleFactory()); | ||
| class CssDependencyTemplate { | ||
| // eslint-disable-next-line class-methods-use-this | ||
| apply() {} | ||
@@ -673,5 +652,5 @@ } | ||
| /** | ||
| * @param {ReturnType<Compilation["getRenderManifest"]>} result | ||
| * @param {Parameters<Compilation["getRenderManifest"]>[0]} chunk | ||
| * @returns {TODO} | ||
| * @param {ReturnType<Compilation["getRenderManifest"]>} result result | ||
| * @param {Parameters<Compilation["getRenderManifest"]>[0]} chunk chunk | ||
| * @returns {ReturnType<Compilation["getRenderManifest"]>} a rendered manifest | ||
| */ | ||
@@ -691,10 +670,7 @@ (result, { | ||
| if (chunk instanceof HotUpdateChunk) { | ||
| return; | ||
| return result; | ||
| } | ||
| const renderedModules = /** @type {CssModule[]} */ | ||
| /** @type {CssModule[]} */ | ||
| const renderedModules = Array.from(/** @type {CssModule[]} */ | ||
| this.getChunkModules(chunk, chunkGraph)).filter(module => | ||
| // @ts-ignore | ||
| module.type === MODULE_TYPE); | ||
| [...this.getChunkModules(chunk, chunkGraph)].filter(module => module.type === MODULE_TYPE); | ||
| const filenameTemplate = /** @type {string} */ | ||
@@ -718,2 +694,3 @@ | ||
| } | ||
| return result; | ||
| }); | ||
@@ -740,6 +717,4 @@ compilation.hooks.contentHash.tap(pluginName, chunk => { | ||
| } | ||
| // eslint-disable-next-line no-param-reassign | ||
| chunk.contentHash[MODULE_TYPE] = /** @type {string} */ | ||
| hash.digest(hashDigest).substring(0, hashDigestLength); | ||
| hash.digest(hashDigest).slice(0, Math.max(0, /** @type {number} */hashDigestLength)); | ||
| } | ||
@@ -764,3 +739,3 @@ }); | ||
| */ | ||
| // eslint-disable-next-line no-shadow | ||
| const getCssChunkObject = (mainChunk, compilation) => { | ||
@@ -775,3 +750,2 @@ /** @type {Record<string, number>} */ | ||
| for (const module of modules) { | ||
| // @ts-ignore | ||
| if (module.type === MODULE_TYPE) { | ||
@@ -794,8 +768,8 @@ obj[(/** @type {string} */chunk.id)] = 1; | ||
| // const chunkHasCss = require("webpack/lib/css/CssModulesPlugin").chunkHasCss; | ||
| return !!chunkGraph.getChunkModulesIterableBySourceType(chunk, "css/mini-extract"); | ||
| return Boolean(chunkGraph.getChunkModulesIterableBySourceType(chunk, "css/mini-extract")); | ||
| } | ||
| class CssLoadingRuntimeModule extends RuntimeModule { | ||
| /** | ||
| * @param {Set<string>} runtimeRequirements | ||
| * @param {RuntimeOptions} runtimeOptions | ||
| * @param {Set<string>} runtimeRequirements runtime Requirements | ||
| * @param {RuntimeOptions} runtimeOptions runtime options | ||
| */ | ||
@@ -838,3 +812,3 @@ constructor(runtimeRequirements, runtimeOptions) { | ||
| // TODO remove `code` in the future major release to align with webpack | ||
| 'err.code = "CSS_CHUNK_LOAD_FAILED";', "err.type = errorType;", "err.request = realHref;", "if (linkTag.parentNode) linkTag.parentNode.removeChild(linkTag)", "reject(err);"]), "}"])}`, "linkTag.onerror = linkTag.onload = onLinkComplete;", "linkTag.href = fullhref;", crossOriginLoading ? Template.asString([`if (linkTag.href.indexOf(window.location.origin + '/') !== 0) {`, Template.indent(`linkTag.crossOrigin = ${JSON.stringify(crossOriginLoading)};`), "}"]) : "", MiniCssExtractPlugin.getCompilationHooks(compilation).beforeTagInsert.call("", { | ||
| 'err.code = "CSS_CHUNK_LOAD_FAILED";', "err.type = errorType;", "err.request = realHref;", "if (linkTag.parentNode) linkTag.parentNode.removeChild(linkTag)", "reject(err);"]), "}"])}`, "linkTag.onerror = linkTag.onload = onLinkComplete;", "linkTag.href = fullhref;", crossOriginLoading ? Template.asString(["if (linkTag.href.indexOf(window.location.origin + '/') !== 0) {", Template.indent(`linkTag.crossOrigin = ${JSON.stringify(crossOriginLoading)};`), "}"]) : "", MiniCssExtractPlugin.getCompilationHooks(compilation).beforeTagInsert.call("", { | ||
| tag: "linkTag", | ||
@@ -845,3 +819,3 @@ chunkId: "chunkId", | ||
| reject: "reject" | ||
| }) || "", typeof this.runtimeOptions.insert !== "undefined" ? typeof this.runtimeOptions.insert === "function" ? `(${this.runtimeOptions.insert.toString()})(linkTag)` : Template.asString([`var target = document.querySelector("${this.runtimeOptions.insert}");`, `target.parentNode.insertBefore(linkTag, target.nextSibling);`]) : Template.asString(["if (oldTag) {", Template.indent(["oldTag.parentNode.insertBefore(linkTag, oldTag.nextSibling);"]), "} else {", Template.indent(["document.head.appendChild(linkTag);"]), "}"]), "return linkTag;"])};`, `var findStylesheet = ${runtimeTemplate.basicFunction("href, fullhref", ['var existingLinkTags = document.getElementsByTagName("link");', "for(var i = 0; i < existingLinkTags.length; i++) {", Template.indent(["var tag = existingLinkTags[i];", 'var dataHref = tag.getAttribute("data-href") || tag.getAttribute("href");', 'if(tag.rel === "stylesheet" && (dataHref === href || dataHref === fullhref)) return tag;']), "}", 'var existingStyleTags = document.getElementsByTagName("style");', "for(var i = 0; i < existingStyleTags.length; i++) {", Template.indent(["var tag = existingStyleTags[i];", 'var dataHref = tag.getAttribute("data-href");', "if(dataHref === href || dataHref === fullhref) return tag;"]), "}"])};`, `var loadStylesheet = ${runtimeTemplate.basicFunction("chunkId", `return new Promise(${runtimeTemplate.basicFunction("resolve, reject", [`var href = ${RuntimeGlobals.require}.miniCssF(chunkId);`, `var fullhref = ${RuntimeGlobals.publicPath} + href;`, "if(findStylesheet(href, fullhref)) return resolve();", "createStylesheet(chunkId, fullhref, null, resolve, reject);"])});`)}`, withLoading ? Template.asString(["// object to store loaded CSS chunks", "var installedCssChunks = {", Template.indent(/** @type {string[]} */ | ||
| }) || "", typeof this.runtimeOptions.insert !== "undefined" ? typeof this.runtimeOptions.insert === "function" ? `(${this.runtimeOptions.insert.toString()})(linkTag)` : Template.asString([`var target = document.querySelector("${this.runtimeOptions.insert}");`, "target.parentNode.insertBefore(linkTag, target.nextSibling);"]) : Template.asString(["if (oldTag) {", Template.indent(["oldTag.parentNode.insertBefore(linkTag, oldTag.nextSibling);"]), "} else {", Template.indent(["document.head.appendChild(linkTag);"]), "}"]), "return linkTag;"])};`, `var findStylesheet = ${runtimeTemplate.basicFunction("href, fullhref", ['var existingLinkTags = document.getElementsByTagName("link");', "for(var i = 0; i < existingLinkTags.length; i++) {", Template.indent(["var tag = existingLinkTags[i];", 'var dataHref = tag.getAttribute("data-href") || tag.getAttribute("href");', 'if(tag.rel === "stylesheet" && (dataHref === href || dataHref === fullhref)) return tag;']), "}", 'var existingStyleTags = document.getElementsByTagName("style");', "for(var i = 0; i < existingStyleTags.length; i++) {", Template.indent(["var tag = existingStyleTags[i];", 'var dataHref = tag.getAttribute("data-href");', "if(dataHref === href || dataHref === fullhref) return tag;"]), "}"])};`, `var loadStylesheet = ${runtimeTemplate.basicFunction("chunkId", `return new Promise(${runtimeTemplate.basicFunction("resolve, reject", [`var href = ${RuntimeGlobals.require}.miniCssF(chunkId);`, `var fullhref = ${RuntimeGlobals.publicPath} + href;`, "if(findStylesheet(href, fullhref)) return resolve();", "createStylesheet(chunkId, fullhref, null, resolve, reject);"])});`)}`, withLoading ? Template.asString(["// object to store loaded CSS chunks", "var installedCssChunks = {", Template.indent(/** @type {string[]} */ | ||
| (/** @type {Chunk} */chunk.ids).map(id => `${JSON.stringify(id)}: 0`).join(",\n")), "};", "", `${RuntimeGlobals.ensureChunkHandlers}.miniCss = ${runtimeTemplate.basicFunction("chunkId, promises", [`var cssChunks = ${JSON.stringify(chunkMap)};`, "if(installedCssChunks[chunkId]) promises.push(installedCssChunks[chunkId]);", "else if(installedCssChunks[chunkId] !== 0 && cssChunks[chunkId]) {", Template.indent([`promises.push(installedCssChunks[chunkId] = loadStylesheet(chunkId).then(${runtimeTemplate.basicFunction("", "installedCssChunks[chunkId] = 0;")}, ${runtimeTemplate.basicFunction("e", ["delete installedCssChunks[chunkId];", "throw e;"])}));`]), "}"])};`]) : "// no chunk loading", "", withHmr ? Template.asString(["var oldTags = [];", "var newTags = [];", `var applyHandler = ${runtimeTemplate.basicFunction("options", [`return { dispose: ${runtimeTemplate.basicFunction("", ["for(var i = 0; i < oldTags.length; i++) {", Template.indent(["var oldTag = oldTags[i];", "if(oldTag.parentNode) oldTag.parentNode.removeChild(oldTag);"]), "}", "oldTags.length = 0;"])}, apply: ${runtimeTemplate.basicFunction("", ['for(var i = 0; i < newTags.length; i++) newTags[i].rel = "stylesheet";', "newTags.length = 0;"])} };`])}`, `${RuntimeGlobals.hmrDownloadUpdateHandlers}.miniCss = ${runtimeTemplate.basicFunction("chunkIds, removedChunks, removedModules, promises, applyHandlers, updatedModulesList", ["applyHandlers.push(applyHandler);", `chunkIds.forEach(${runtimeTemplate.basicFunction("chunkId", [`var href = ${RuntimeGlobals.require}.miniCssF(chunkId);`, `var fullhref = ${RuntimeGlobals.publicPath} + href;`, "var oldTag = findStylesheet(href, fullhref);", "if(!oldTag) return;", `promises.push(new Promise(${runtimeTemplate.basicFunction("resolve, reject", [`var tag = createStylesheet(chunkId, fullhref, oldTag, ${runtimeTemplate.basicFunction("", ['tag.as = "style";', 'tag.rel = "preload";', "resolve();"])}, reject);`, "oldTags.push(oldTag);", "newTags.push(tag);"])}));`])});`])}`]) : "// no hmr", "", withPrefetch && withLoading && hasCssMatcher !== false ? `${RuntimeGlobals.prefetchChunkHandlers}.miniCss = ${runtimeTemplate.basicFunction("chunkId", [`if((!${RuntimeGlobals.hasOwnProperty}(installedCssChunks, chunkId) || installedCssChunks[chunkId] === undefined) && ${hasCssMatcher === true ? "true" : hasCssMatcher("chunkId")}) {`, Template.indent(["installedCssChunks[chunkId] = null;", linkPrefetch.call(Template.asString(["var link = document.createElement('link');", crossOriginLoading ? `link.crossOrigin = ${JSON.stringify(crossOriginLoading)};` : "", `if (${RuntimeGlobals.scriptNonce}) {`, Template.indent(`link.setAttribute("nonce", ${RuntimeGlobals.scriptNonce});`), "}", 'link.rel = "prefetch";', 'link.as = "style";', `link.href = ${RuntimeGlobals.publicPath} + ${RuntimeGlobals.require}.miniCssF(chunkId);`]), /** @type {Chunk} */chunk), "document.head.appendChild(link);"]), "}"])};` : "// no prefetching", "", withPreload && withLoading && hasCssMatcher !== false ? `${RuntimeGlobals.preloadChunkHandlers}.miniCss = ${runtimeTemplate.basicFunction("chunkId", [`if((!${RuntimeGlobals.hasOwnProperty}(installedCssChunks, chunkId) || installedCssChunks[chunkId] === undefined) && ${hasCssMatcher === true ? "true" : hasCssMatcher("chunkId")}) {`, Template.indent(["installedCssChunks[chunkId] = null;", linkPreload.call(Template.asString(["var link = document.createElement('link');", "link.charset = 'utf-8';", `if (${RuntimeGlobals.scriptNonce}) {`, Template.indent(`link.setAttribute("nonce", ${RuntimeGlobals.scriptNonce});`), "}", 'link.rel = "preload";', 'link.as = "style";', `link.href = ${RuntimeGlobals.publicPath} + ${RuntimeGlobals.require}.miniCssF(chunkId);`, crossOriginLoading ? crossOriginLoading === "use-credentials" ? 'link.crossOrigin = "use-credentials";' : Template.asString(["if (link.href.indexOf(window.location.origin + '/') !== 0) {", Template.indent(`link.crossOrigin = ${JSON.stringify(crossOriginLoading)};`), "}"]) : ""]), /** @type {Chunk} */chunk), "document.head.appendChild(link);"]), "}"])};` : "// no preloaded"]); | ||
@@ -853,4 +827,4 @@ } | ||
| /** | ||
| * @param {Chunk} chunk | ||
| * @param {Set<string>} set | ||
| * @param {Chunk} chunk chunk | ||
| * @param {Set<string>} set set with runtime requirement | ||
| */ | ||
@@ -868,4 +842,4 @@ const handler = (chunk, set) => { | ||
| /** | ||
| * @param {Chunk} referencedChunk | ||
| * @returns {TODO} | ||
| * @param {Chunk} referencedChunk a referenced chunk | ||
| * @returns {ReturnType<import("webpack").runtime.GetChunkFilenameRuntimeModule["getFilenameForChunk"]>} a template value | ||
| */ | ||
@@ -876,3 +850,3 @@ referencedChunk => { | ||
| } | ||
| return referencedChunk.canBeInitial() ? this.options.filename : this.options.chunkFilename; | ||
| return referencedChunk.canBeInitial() ? (/** @type {Filename} */this.options.filename) : (/** @type {ChunkFilename} */this.options.chunkFilename); | ||
| }, set.has(RuntimeGlobals.hmrDownloadUpdateHandlers))); | ||
@@ -890,5 +864,5 @@ compilation.addRuntimeModule(chunk, new CssLoadingRuntimeModule(set, this.runtimeOptions)); | ||
| * @private | ||
| * @param {Chunk} chunk | ||
| * @param {ChunkGraph} chunkGraph | ||
| * @returns {Iterable<Module>} | ||
| * @param {Chunk} chunk chunk | ||
| * @param {ChunkGraph} chunkGraph chunk graph | ||
| * @returns {Iterable<Module>} modules | ||
| */ | ||
@@ -901,7 +875,7 @@ getChunkModules(chunk, chunkGraph) { | ||
| * @private | ||
| * @param {Compilation} compilation | ||
| * @param {Chunk} chunk | ||
| * @param {CssModule[]} modules | ||
| * @param {Compilation["requestShortener"]} requestShortener | ||
| * @returns {Set<CssModule>} | ||
| * @param {Compilation} compilation compilation | ||
| * @param {Chunk} chunk chunk | ||
| * @param {CssModule[]} modules modules | ||
| * @param {Compilation["requestShortener"]} requestShortener request shortener | ||
| * @returns {Set<CssModule>} css modules | ||
| */ | ||
@@ -927,10 +901,6 @@ sortModules(compilation, chunk, modules, requestShortener) { | ||
| const modulesByChunkGroup = Array.from(chunk.groupsIterable, chunkGroup => { | ||
| const sortedModules = modulesList.map(module => { | ||
| return { | ||
| module, | ||
| index: chunkGroup.getModulePostOrderIndex(module) | ||
| }; | ||
| }) | ||
| // eslint-disable-next-line no-undefined | ||
| .filter(item => item.index !== undefined).sort((a, b) => /** @type {number} */b.index - (/** @type {number} */a.index)).map(item => item.module); | ||
| const sortedModules = modulesList.map(module => ({ | ||
| module, | ||
| index: chunkGroup.getModulePostOrderIndex(module) | ||
| })).filter(item => item.index !== undefined).sort((a, b) => /** @type {number} */b.index - (/** @type {number} */a.index)).map(item => item.module); | ||
| for (let i = 0; i < sortedModules.length; i++) { | ||
@@ -957,4 +927,4 @@ const set = moduleDependencies.get(sortedModules[i]); | ||
| /** | ||
| * @param {CssModule} m | ||
| * @returns {boolean} | ||
| * @param {CssModule} m a css module | ||
| * @returns {boolean} true when module unused, otherwise false | ||
| */ | ||
@@ -977,6 +947,6 @@ const unusedModulesFilter = m => !(/** @type {Set<CssModule>} */usedModules.has(m)); | ||
| const module = list[list.length - 1]; | ||
| const deps = moduleDependencies.get(module); | ||
| const deps = /** @type {Set<CssModule>} */ | ||
| moduleDependencies.get(module); | ||
| // determine dependencies that are not yet included | ||
| const failedDeps = Array.from(/** @type {Set<CssModule>} */ | ||
| deps).filter(unusedModulesFilter); | ||
| const failedDeps = [...deps].filter(unusedModulesFilter); | ||
@@ -1025,10 +995,10 @@ // store best match for fallback behavior | ||
| * @private | ||
| * @param {Compiler} compiler | ||
| * @param {Compilation} compilation | ||
| * @param {Chunk} chunk | ||
| * @param {CssModule[]} modules | ||
| * @param {Compiler["requestShortener"]} requestShortener | ||
| * @param {string} filenameTemplate | ||
| * @param {Parameters<Exclude<Required<Configuration>['output']['filename'], string | undefined>>[0]} pathData | ||
| * @returns {Source} | ||
| * @param {Compiler} compiler compiler | ||
| * @param {Compilation} compilation compilation | ||
| * @param {Chunk} chunk chunk | ||
| * @param {CssModule[]} modules modules | ||
| * @param {Compiler["requestShortener"]} requestShortener request shortener | ||
| * @param {string} filenameTemplate filename template | ||
| * @param {Parameters<Exclude<Required<Configuration>['output']['filename'], string | undefined>>[0]} pathData path data | ||
| * @returns {Source} source | ||
| */ | ||
@@ -1047,3 +1017,3 @@ renderContentAsset(compiler, compilation, chunk, modules, requestShortener, filenameTemplate, pathData) { | ||
| const readableIdentifier = module.readableIdentifier(requestShortener); | ||
| const startsWithAtRuleImport = /^@import url/.test(content); | ||
| const startsWithAtRuleImport = content.startsWith("@import url"); | ||
| let header; | ||
@@ -1050,0 +1020,0 @@ if (compilation.outputOptions.pathinfo) { |
+73
-84
| "use strict"; | ||
| const path = require("path"); | ||
| const schema = require("./loader-options.json"); | ||
| const { | ||
| findModuleById, | ||
| evalModuleCode, | ||
| ABSOLUTE_PUBLIC_PATH, | ||
| AUTO_PUBLIC_PATH, | ||
| ABSOLUTE_PUBLIC_PATH, | ||
| BASE_URI, | ||
| SINGLE_DOT_PATH_SEGMENT, | ||
| stringifyRequest, | ||
| stringifyLocal | ||
| evalModuleCode, | ||
| findModuleById, | ||
| stringifyLocal, | ||
| stringifyRequest | ||
| } = require("./utils"); | ||
| const schema = require("./loader-options.json"); | ||
| const MiniCssExtractPlugin = require("./index"); | ||
@@ -26,25 +26,28 @@ | ||
| /** @typedef {import("./index.js").LoaderOptions} LoaderOptions */ | ||
| /** @typedef {{ [key: string]: string | function }} Locals */ | ||
| /** @typedef {any} TODO */ | ||
| // eslint-disable-next-line jsdoc/no-restricted-syntax | ||
| /** @typedef {{[key: string]: string | Function }} Locals */ | ||
| // eslint-disable-next-line jsdoc/no-restricted-syntax | ||
| /** @typedef {any} EXPECTED_ANY */ | ||
| /** | ||
| * @typedef {Object} Dependency | ||
| * @property {string} identifier | ||
| * @property {string | null} context | ||
| * @property {Buffer} content | ||
| * @property {string} media | ||
| * @property {string} [supports] | ||
| * @property {string} [layer] | ||
| * @property {Buffer} [sourceMap] | ||
| * @typedef {object} Dependency | ||
| * @property {string} identifier identifier | ||
| * @property {string | null} context context | ||
| * @property {Buffer} content content | ||
| * @property {string=} media media | ||
| * @property {string=} supports supports | ||
| * @property {string=} layer layer | ||
| * @property {Buffer=} sourceMap source map | ||
| */ | ||
| /** | ||
| * @param {string} content | ||
| * @param {{ loaderContext: import("webpack").LoaderContext<LoaderOptions>, options: LoaderOptions, locals: Locals | undefined }} context | ||
| * @returns {string} | ||
| * @param {string} code code | ||
| * @param {{ loaderContext: import("webpack").LoaderContext<LoaderOptions>, options: LoaderOptions, locals: Locals | undefined }} context context | ||
| * @returns {string} code and HMR code | ||
| */ | ||
| function hotLoader(content, context) { | ||
| function hotLoader(code, context) { | ||
| const localsJsonString = JSON.stringify(JSON.stringify(context.locals)); | ||
| return `${content} | ||
| return `${code} | ||
| if(module.hot) { | ||
@@ -76,3 +79,3 @@ (function() { | ||
| * @this {import("webpack").LoaderContext<LoaderOptions>} | ||
| * @param {string} request | ||
| * @param {string} request request | ||
| */ | ||
@@ -84,8 +87,8 @@ function pitch(request) { | ||
| } | ||
| // @ts-ignore | ||
| 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) { | ||
@@ -100,6 +103,6 @@ callback(new Error("You forgot to add 'mini-css-extract-plugin' plugin (i.e. `{ plugins: [new MiniCssExtractPlugin()] }`), please read https://github.com/webpack-contrib/mini-css-extract-plugin#getting-started")); | ||
| /** | ||
| * @param {TODO} originalExports | ||
| * @param {Compilation} [compilation] | ||
| * @param {{ [name: string]: Source }} [assets] | ||
| * @param {Map<string, AssetInfo>} [assetsInfo] | ||
| * @param {EXPECTED_ANY} originalExports original exports | ||
| * @param {Compilation=} compilation compilation | ||
| * @param {{ [name: string]: Source }=} assets assets | ||
| * @param {Map<string, AssetInfo>=} assetsInfo assets info | ||
| * @returns {void} | ||
@@ -114,5 +117,6 @@ */ | ||
| /** | ||
| * @param {Dependency[] | [null, object][]} dependencies | ||
| * @param {Dependency[] | [null, object][]} dependencies dependencies | ||
| */ | ||
| const addDependencies = dependencies => { | ||
| // eslint-disable-next-line no-eq-null, eqeqeq | ||
| if (!Array.isArray(dependencies) && dependencies != null) { | ||
@@ -125,3 +129,2 @@ throw new Error(`Exported value was not extracted as an array: ${JSON.stringify(dependencies)}`); | ||
| if (!(/** @type {Dependency} */dependency.identifier) || !emit) { | ||
| // eslint-disable-next-line no-continue | ||
| continue; | ||
@@ -145,9 +148,6 @@ } | ||
| try { | ||
| // eslint-disable-next-line no-underscore-dangle | ||
| const exports = originalExports.__esModule ? originalExports.default : originalExports; | ||
| namedExport = | ||
| // eslint-disable-next-line no-underscore-dangle | ||
| originalExports.__esModule && (!originalExports.default || !("locals" in originalExports.default)); | ||
| namedExport = originalExports.__esModule && (!originalExports.default || !("locals" in originalExports.default)); | ||
| if (namedExport) { | ||
| Object.keys(originalExports).forEach(key => { | ||
| for (const key of Object.keys(originalExports)) { | ||
| if (key !== "default") { | ||
@@ -161,3 +161,3 @@ if (!locals) { | ||
| } | ||
| }); | ||
| } | ||
| } else { | ||
@@ -167,3 +167,3 @@ locals = exports && exports.locals; | ||
| /** @type {Dependency[] | [null, object][]} */ | ||
| /** @type {Dependency[] | [null, Record<string, string>][]} */ | ||
| let dependencies; | ||
@@ -194,5 +194,3 @@ if (!Array.isArray(exports)) { | ||
| layer, | ||
| sourceMap: sourceMap ? Buffer.from(JSON.stringify(sourceMap)) : | ||
| // eslint-disable-next-line no-undefined | ||
| undefined | ||
| sourceMap: sourceMap ? Buffer.from(JSON.stringify(sourceMap)) : undefined | ||
| }; | ||
@@ -202,4 +200,4 @@ }); | ||
| addDependencies(dependencies); | ||
| } catch (e) { | ||
| callback(/** @type {Error} */e); | ||
| } catch (err) { | ||
| callback(/** @type {Error} */err); | ||
| return; | ||
@@ -211,3 +209,3 @@ } | ||
| if (namedExport) { | ||
| const identifiers = Array.from(function* generateIdentifiers() { | ||
| const identifiers = [...function* generateIdentifiers() { | ||
| let identifierId = 0; | ||
@@ -218,3 +216,3 @@ for (const key of Object.keys(locals)) { | ||
| } | ||
| }()); | ||
| }()]; | ||
| const localsString = identifiers.map(([id, key]) => `\nvar ${id} = ${stringifyLocal(/** @type {Locals} */locals[key])};`).join(""); | ||
@@ -245,3 +243,2 @@ const exportsString = `export { ${identifiers.map(([id, key]) => `${id} as ${JSON.stringify(key)}`).join(", ")} }`; | ||
| if (typeof options.publicPath === "string") { | ||
| // eslint-disable-next-line prefer-destructuring | ||
| publicPath = options.publicPath; | ||
@@ -272,4 +269,4 @@ } else if (typeof options.publicPath === "function") { | ||
| /** | ||
| * @param {Error | null | undefined} error | ||
| * @param {object} exports | ||
| * @param {Error | null | undefined} error error | ||
| * @param {object} exports exports | ||
| */ | ||
@@ -314,5 +311,3 @@ (error, exports) => { | ||
| } = webpack.node; | ||
| // @ts-ignore | ||
| new NodeTemplatePlugin(outputOptions).apply(childCompiler); | ||
| new NodeTemplatePlugin().apply(childCompiler); | ||
| new NodeTargetPlugin().apply(childCompiler); | ||
@@ -347,3 +342,3 @@ const { | ||
| /** | ||
| * @param {Compilation} compilation | ||
| * @param {Compilation} compilation compilation | ||
| */ | ||
@@ -354,11 +349,8 @@ compilation => { | ||
| if (module.request === request) { | ||
| // eslint-disable-next-line no-param-reassign | ||
| module.loaders = loaders.map(loader => { | ||
| return { | ||
| type: null, | ||
| loader: loader.path, | ||
| options: loader.options, | ||
| ident: loader.ident | ||
| }; | ||
| }); | ||
| module.loaders = loaders.map(loader => ({ | ||
| type: null, | ||
| loader: loader.path, | ||
| options: loader.options, | ||
| ident: loader.ident | ||
| })); | ||
| } | ||
@@ -372,3 +364,3 @@ }); | ||
| /** | ||
| * @param {Compilation} compilation | ||
| * @param {Compilation} compilation compilation | ||
| */ | ||
@@ -380,10 +372,10 @@ compilation => { | ||
| // Remove all chunk assets | ||
| compilation.chunks.forEach(chunk => { | ||
| chunk.files.forEach(file => { | ||
| for (const chunk of compilation.chunks) { | ||
| for (const file of chunk.files) { | ||
| compilation.deleteAsset(file); | ||
| }); | ||
| }); | ||
| } | ||
| } | ||
| }); | ||
| }); | ||
| childCompiler.runAsChild((error, entries, compilation) => { | ||
| childCompiler.runAsChild((error, entries, compilation_) => { | ||
| if (error) { | ||
@@ -393,4 +385,5 @@ callback(error); | ||
| } | ||
| if (/** @type {Compilation} */compilation.errors.length > 0) { | ||
| callback(/** @type {Compilation} */compilation.errors[0]); | ||
| const compilation = /** @type {Compilation} */compilation_; | ||
| if (compilation.errors.length > 0) { | ||
| callback(compilation.errors[0]); | ||
| return; | ||
@@ -403,16 +396,12 @@ } | ||
| const assetsInfo = new Map(); | ||
| for (const asset of /** @type {Compilation} */compilation.getAssets()) { | ||
| for (const asset of compilation.getAssets()) { | ||
| assets[asset.name] = asset.source; | ||
| assetsInfo.set(asset.name, asset.info); | ||
| } | ||
| /** @type {Compilation} */ | ||
| compilation.fileDependencies.forEach(dep => { | ||
| for (const dep of compilation.fileDependencies) { | ||
| this.addDependency(dep); | ||
| }, this); | ||
| /** @type {Compilation} */ | ||
| compilation.contextDependencies.forEach(dep => { | ||
| } | ||
| for (const dep of compilation.contextDependencies) { | ||
| this.addContextDependency(dep); | ||
| }, this); | ||
| } | ||
| if (!source) { | ||
@@ -425,4 +414,4 @@ callback(new Error("Didn't get a result from child compiler")); | ||
| originalExports = evalModuleCode(this, source, request); | ||
| } catch (e) { | ||
| callback(/** @type {Error} */e); | ||
| } catch (err) { | ||
| callback(/** @type {Error} */err); | ||
| return; | ||
@@ -436,5 +425,5 @@ } | ||
| * @this {import("webpack").LoaderContext<LoaderOptions>} | ||
| * @param {string} content | ||
| * @param {string} content content | ||
| * @returns {string | undefined} the original content | ||
| */ | ||
| // eslint-disable-next-line consistent-return | ||
| function loader(content) { | ||
@@ -446,3 +435,3 @@ if (this._compiler && this._compiler.options && this._compiler.options.experiments && this._compiler.options.experiments.css && this._module && (this._module.type === "css" || this._module.type === "css/auto" || this._module.type === "css/global" || this._module.type === "css/module")) { | ||
| module.exports = loader; | ||
| module.exports.pitch = pitch; | ||
| module.exports.hotLoader = hotLoader; | ||
| module.exports.hotLoader = hotLoader; | ||
| module.exports.pitch = pitch; |
+58
-63
@@ -8,6 +8,8 @@ "use strict"; | ||
| /** @typedef {import("webpack").Module} Module */ | ||
| // eslint-disable-next-line jsdoc/no-restricted-syntax | ||
| /** @typedef {import("webpack").LoaderContext<any>} LoaderContext */ | ||
| /** | ||
| * @returns {boolean} | ||
| * @returns {boolean} always returns true | ||
| */ | ||
@@ -19,5 +21,5 @@ function trueFn() { | ||
| /** | ||
| * @param {Compilation} compilation | ||
| * @param {string | number} id | ||
| * @returns {null | Module} | ||
| * @param {Compilation} compilation compilation | ||
| * @param {string | number} id module id | ||
| * @returns {null | Module} the found module | ||
| */ | ||
@@ -38,18 +40,17 @@ function findModuleById(compilation, id) { | ||
| // eslint-disable-next-line jsdoc/no-restricted-syntax | ||
| /** | ||
| * @param {LoaderContext} loaderContext | ||
| * @param {string | Buffer} code | ||
| * @param {string} filename | ||
| * @returns {object} | ||
| * @param {LoaderContext} loaderContext loader context | ||
| * @param {string | Buffer} code code | ||
| * @param {string} filename filename | ||
| * @returns {Record<string, any>} exports of a module | ||
| */ | ||
| function evalModuleCode(loaderContext, code, filename) { | ||
| // @ts-ignore | ||
| // @ts-expect-error | ||
| const module = new NativeModule(filename, loaderContext); | ||
| // @ts-ignore | ||
| module.paths = NativeModule._nodeModulePaths(loaderContext.context); // eslint-disable-line no-underscore-dangle | ||
| // @ts-expect-error | ||
| module.paths = NativeModule._nodeModulePaths(loaderContext.context); | ||
| module.filename = filename; | ||
| // @ts-ignore | ||
| module._compile(code, filename); // eslint-disable-line no-underscore-dangle | ||
| // @ts-expect-error | ||
| module._compile(code, filename); | ||
| return module.exports; | ||
@@ -59,5 +60,5 @@ } | ||
| /** | ||
| * @param {string} a | ||
| * @param {string} b | ||
| * @returns {0 | 1 | -1} | ||
| * @param {string} a a | ||
| * @param {string} b b | ||
| * @returns {0 | 1 | -1} result of comparing | ||
| */ | ||
@@ -78,5 +79,5 @@ function compareIds(a, b) { | ||
| /** | ||
| * @param {Module} a | ||
| * @param {Module} b | ||
| * @returns {0 | 1 | -1} | ||
| * @param {Module} a a | ||
| * @param {Module} b b | ||
| * @returns {0 | 1 | -1} result of comparing | ||
| */ | ||
@@ -93,4 +94,4 @@ function compareModulesByIdentifier(a, b) { | ||
| /** | ||
| * @param {string} str | ||
| * @returns {boolean} | ||
| * @param {string} str path | ||
| * @returns {boolean} true when path is absolute, otherwise false | ||
| */ | ||
@@ -103,4 +104,4 @@ function isAbsolutePath(str) { | ||
| /** | ||
| * @param {string} str | ||
| * @returns {boolean} | ||
| * @param {string} str string | ||
| * @returns {boolean} true when path is relative, otherwise false | ||
| */ | ||
@@ -113,5 +114,5 @@ function isRelativePath(str) { | ||
| /** | ||
| * @param {LoaderContext} loaderContext | ||
| * @param {string} request | ||
| * @returns {string} | ||
| * @param {LoaderContext} loaderContext the loader context | ||
| * @param {string} request a request | ||
| * @returns {string} a stringified request | ||
| */ | ||
@@ -149,6 +150,6 @@ function stringifyRequest(loaderContext, request) { | ||
| /** | ||
| * @param {string} filename | ||
| * @param {string} outputPath | ||
| * @param {boolean} enforceRelative | ||
| * @returns {string} | ||
| * @param {string} filename filename | ||
| * @param {string} outputPath output path | ||
| * @param {boolean} enforceRelative true when need to enforce relative path, otherwise false | ||
| * @returns {string} undo path | ||
| */ | ||
@@ -158,4 +159,2 @@ function getUndoPath(filename, outputPath, enforceRelative) { | ||
| let append = ""; | ||
| // eslint-disable-next-line no-param-reassign | ||
| outputPath = outputPath.replace(/[\\/]$/, ""); | ||
@@ -165,3 +164,2 @@ for (const part of filename.split(/[/\\]+/)) { | ||
| if (depth > -1) { | ||
| // eslint-disable-next-line no-plusplus | ||
| depth--; | ||
@@ -176,8 +174,5 @@ } else { | ||
| append = `${outputPath.slice(pos + 1)}/${append}`; | ||
| // eslint-disable-next-line no-param-reassign | ||
| outputPath = outputPath.slice(0, pos); | ||
| } | ||
| } else if (part !== ".") { | ||
| // eslint-disable-next-line no-plusplus | ||
| depth++; | ||
@@ -189,6 +184,6 @@ } | ||
| // eslint-disable-next-line jsdoc/no-restricted-syntax | ||
| /** | ||
| * | ||
| * @param {string | function} value | ||
| * @returns {string} | ||
| * @param {string | Function} value local | ||
| * @returns {string} stringified local | ||
| */ | ||
@@ -204,2 +199,3 @@ function stringifyLocal(value) { | ||
| const toSimpleString = str => { | ||
| // eslint-disable-next-line no-implicit-coercion | ||
| if (`${+str}` === str) { | ||
@@ -222,8 +218,8 @@ return str; | ||
| const getCommonPrefix = items => { | ||
| let prefix = items[0]; | ||
| let [prefix] = items; | ||
| for (let i = 1; i < items.length; i++) { | ||
| const item = items[i]; | ||
| for (let p = 0; p < prefix.length; p++) { | ||
| if (item[p] !== prefix[p]) { | ||
| prefix = prefix.slice(0, p); | ||
| for (let prefixIndex = 0; prefixIndex < prefix.length; prefixIndex++) { | ||
| if (item[prefixIndex] !== prefix[prefixIndex]) { | ||
| prefix = prefix.slice(0, prefixIndex); | ||
| break; | ||
@@ -241,8 +237,8 @@ } | ||
| const getCommonSuffix = items => { | ||
| let suffix = items[0]; | ||
| let [suffix] = items; | ||
| for (let i = 1; i < items.length; i++) { | ||
| const item = items[i]; | ||
| for (let p = item.length - 1, s = suffix.length - 1; s >= 0; p--, s--) { | ||
| if (item[p] !== suffix[s]) { | ||
| suffix = suffix.slice(s + 1); | ||
| for (let itemIndex = item.length - 1, suffixIndex = suffix.length - 1; suffixIndex >= 0; itemIndex--, suffixIndex--) { | ||
| if (item[itemIndex] !== suffix[suffixIndex]) { | ||
| suffix = suffix.slice(suffixIndex + 1); | ||
| break; | ||
@@ -306,3 +302,2 @@ } | ||
| if (item.length === 1) { | ||
| // eslint-disable-next-line no-plusplus | ||
| countOfSingleCharItems++; | ||
@@ -372,3 +367,3 @@ } | ||
| // use ranges: (1|2|3|4|a) => [1-4a] | ||
| const conditional = finishedItems.concat(Array.from(items, quoteMeta)); | ||
| const conditional = [...finishedItems, ...Array.from(items, quoteMeta)]; | ||
| if (conditional.length === 1) return conditional[0]; | ||
@@ -381,3 +376,3 @@ return `(${conditional.join("|")})`; | ||
| * @param {string[]} negativeItems negative items | ||
| * @returns {function(string): string} a template function to determine the value at runtime | ||
| * @returns {(val: string) => string} a template function to determine the value at runtime | ||
| */ | ||
@@ -407,4 +402,4 @@ const compileBooleanMatcherFromLists = (positiveItems, negativeItems) => { | ||
| /** | ||
| * @param {Record<string|number, boolean>} map value map | ||
| * @returns {boolean|(function(string): string)} true/false, when unconditionally true/false, or a template function to determine the value at runtime | ||
| * @param {Record<string | number, boolean>} map value map | ||
| * @returns {boolean | ((value: string) => string)} true/false, when unconditionally true/false, or a template function to determine the value at runtime | ||
| */ | ||
@@ -423,15 +418,15 @@ const compileBooleanMatcher = map => { | ||
| module.exports = { | ||
| trueFn, | ||
| findModuleById, | ||
| evalModuleCode, | ||
| compareModulesByIdentifier, | ||
| MODULE_TYPE, | ||
| ABSOLUTE_PUBLIC_PATH, | ||
| AUTO_PUBLIC_PATH, | ||
| ABSOLUTE_PUBLIC_PATH, | ||
| BASE_URI, | ||
| MODULE_TYPE, | ||
| SINGLE_DOT_PATH_SEGMENT, | ||
| compareModulesByIdentifier, | ||
| compileBooleanMatcher, | ||
| evalModuleCode, | ||
| findModuleById, | ||
| getUndoPath, | ||
| stringifyLocal, | ||
| stringifyRequest, | ||
| stringifyLocal, | ||
| getUndoPath, | ||
| compileBooleanMatcher | ||
| trueFn | ||
| }; |
+41
-32
| { | ||
| "name": "mini-css-extract-plugin", | ||
| "version": "2.9.3", | ||
| "version": "2.9.4", | ||
| "description": "extracts CSS into separate files", | ||
| "license": "MIT", | ||
| "repository": "webpack-contrib/mini-css-extract-plugin", | ||
| "author": "Tobias Koppers @sokra", | ||
| "keywords": [ | ||
| "webpack", | ||
| "css", | ||
| "extract", | ||
| "hmr" | ||
| ], | ||
| "homepage": "https://github.com/webpack-contrib/mini-css-extract-plugin", | ||
| "bugs": "https://github.com/webpack-contrib/mini-css-extract-plugin/issues", | ||
| "repository": "webpack-contrib/mini-css-extract-plugin", | ||
| "funding": { | ||
@@ -14,7 +18,10 @@ "type": "opencollective", | ||
| }, | ||
| "license": "MIT", | ||
| "author": "Tobias Koppers @sokra", | ||
| "main": "dist/index.js", | ||
| "types": "types/index.d.ts", | ||
| "engines": { | ||
| "node": ">= 12.13.0" | ||
| }, | ||
| "files": [ | ||
| "dist", | ||
| "types" | ||
| ], | ||
| "scripts": { | ||
@@ -29,3 +36,3 @@ "start": "npm run build -- -w", | ||
| "lint:prettier": "prettier \"{**/*,*}.{js,json,md,yml,css,ts}\" --list-different", | ||
| "lint:js": "eslint --cache .", | ||
| "lint:code": "eslint --cache .", | ||
| "lint:spelling": "cspell \"**/*.*\"", | ||
@@ -35,5 +42,5 @@ "lint:types": "tsc --pretty --noEmit", | ||
| "lint": "npm-run-all -l -p \"lint:**\"", | ||
| "fix:js": "npm run lint:js -- --fix", | ||
| "fix:code": "npm run lint:code -- --fix", | ||
| "fix:prettier": "npm run lint:prettier -- --write", | ||
| "fix": "npm-run-all -l fix:js fix:prettier", | ||
| "fix": "npm-run-all -l fix:code fix:prettier", | ||
| "prepare": "husky install && npm run build", | ||
@@ -50,9 +57,2 @@ "release": "standard-version", | ||
| }, | ||
| "files": [ | ||
| "dist", | ||
| "types" | ||
| ], | ||
| "peerDependencies": { | ||
| "webpack": "^5.0.0" | ||
| }, | ||
| "dependencies": { | ||
@@ -65,9 +65,9 @@ "schema-utils": "^4.0.0", | ||
| "@babel/core": "^7.24.4", | ||
| "@babel/eslint-parser": "^7.24.1", | ||
| "@babel/preset-env": "^7.24.4", | ||
| "@commitlint/cli": "^17.5.1", | ||
| "@commitlint/config-conventional": "^17.4.4", | ||
| "@eslint/js": "^9.32.0", | ||
| "@eslint/markdown": "^7.0.0", | ||
| "@stylistic/eslint-plugin": "^5.2.2", | ||
| "@types/node": "^18.15.11", | ||
| "@webpack-contrib/eslint-config-webpack": "^3.0.0", | ||
| "babel-jest": "^28.1.3", | ||
| "bootstrap": "^4.6.2", | ||
@@ -80,6 +80,13 @@ "cross-env": "^7.0.3", | ||
| "es-check": "^7.1.0", | ||
| "eslint": "^8.37.0", | ||
| "eslint-config-prettier": "^8.8.0", | ||
| "eslint-plugin-import": "^2.27.5", | ||
| "eslint": "^9.32.0", | ||
| "eslint-config-prettier": "^10.1.8", | ||
| "eslint-config-webpack": "^4.4.2", | ||
| "eslint-plugin-import": "^2.32.0", | ||
| "eslint-plugin-jest": "^29.0.1", | ||
| "eslint-plugin-jsdoc": "^52.0.0", | ||
| "eslint-plugin-n": "^17.21.0", | ||
| "eslint-plugin-prettier": "^5.5.3", | ||
| "eslint-plugin-unicorn": "^60.0.0", | ||
| "file-loader": "^6.2.0", | ||
| "globals": "^16.3.0", | ||
| "husky": "^7.0.0", | ||
@@ -92,17 +99,19 @@ "jest": "^28.1.3", | ||
| "npm-run-all": "^4.1.5", | ||
| "prettier": "^2.8.7", | ||
| "prettier": "^3.6.0", | ||
| "prettier-2": "npm:prettier@^2", | ||
| "sass": "^1.74.1", | ||
| "sass-loader": "^12.6.0", | ||
| "standard-version": "^9.3.0", | ||
| "typescript": "^4.9.5", | ||
| "typescript": "^5.8.0", | ||
| "typescript-eslint": "^8.38.0", | ||
| "webpack": "^5.91.0", | ||
| "webpack-cli": "^4.9.2", | ||
| "webpack-dev-server": "^4.13.2" | ||
| "webpack-dev-server": "^5.2.1" | ||
| }, | ||
| "keywords": [ | ||
| "webpack", | ||
| "css", | ||
| "extract", | ||
| "hmr" | ||
| ] | ||
| "peerDependencies": { | ||
| "webpack": "^5.0.0" | ||
| }, | ||
| "engines": { | ||
| "node": ">= 12.13.0" | ||
| } | ||
| } |
+20
-28
@@ -204,4 +204,4 @@ <div align="center"> | ||
| new MiniCssExtractPlugin({ | ||
| insert: function (linkTag) { | ||
| var reference = document.querySelector("#some-element"); | ||
| insert(linkTag) { | ||
| const reference = document.querySelector("#some-element"); | ||
| if (reference) { | ||
@@ -221,3 +221,3 @@ reference.parentNode.insertBefore(linkTag, reference); | ||
| ```ts | ||
| type attributes = Record<string, string>}; | ||
| type attributes = Record<string, string>; | ||
| ``` | ||
@@ -488,5 +488,4 @@ | ||
| options: { | ||
| publicPath: (resourcePath, context) => { | ||
| return path.relative(path.dirname(resourcePath), context) + "/"; | ||
| }, | ||
| publicPath: (resourcePath, context) => | ||
| `${path.relative(path.dirname(resourcePath), context)}/`, | ||
| }, | ||
@@ -626,2 +625,3 @@ }, | ||
| const MiniCssExtractPlugin = require("mini-css-extract-plugin"); | ||
| const devMode = process.env.NODE_ENV !== "production"; | ||
@@ -645,3 +645,3 @@ | ||
| }, | ||
| plugins: [].concat(devMode ? [] : [new MiniCssExtractPlugin()]), | ||
| plugins: [devMode ? [] : [new MiniCssExtractPlugin()]].flat(), | ||
| }; | ||
@@ -710,3 +710,3 @@ ``` | ||
| ```js | ||
| import { fooBaz, bar } from "./styles.css"; | ||
| import { bar, fooBaz } from "./styles.css"; | ||
@@ -776,8 +776,7 @@ console.log(fooBaz, bar); | ||
| options: { | ||
| publicPath: (resourcePath, context) => { | ||
| publicPath: (resourcePath, context) => | ||
| // publicPath is the relative path of the resource to the context | ||
| // e.g. for ./css/admin/main.css the publicPath will be ../../ | ||
| // while for ./css/main.css the publicPath will be ../ | ||
| return path.relative(path.dirname(resourcePath), context) + "/"; | ||
| }, | ||
| `${path.relative(path.dirname(resourcePath), context)}/`, | ||
| }, | ||
@@ -807,4 +806,5 @@ }, | ||
| ```js | ||
| const MiniCssExtractPlugin = require("mini-css-extract-plugin"); | ||
| const webpack = require("webpack"); | ||
| const MiniCssExtractPlugin = require("mini-css-extract-plugin"); | ||
| const devMode = process.env.NODE_ENV !== "production"; | ||
@@ -859,4 +859,4 @@ | ||
| ```js | ||
| const MiniCssExtractPlugin = require("mini-css-extract-plugin"); | ||
| const webpack = require("webpack"); | ||
| const MiniCssExtractPlugin = require("mini-css-extract-plugin"); | ||
@@ -902,4 +902,4 @@ const plugins = [ | ||
| ```js | ||
| const CssMinimizerPlugin = require("css-minimizer-webpack-plugin"); | ||
| const MiniCssExtractPlugin = require("mini-css-extract-plugin"); | ||
| const CssMinimizerPlugin = require("css-minimizer-webpack-plugin"); | ||
@@ -1005,5 +1005,3 @@ module.exports = { | ||
| name: "styles_foo", | ||
| chunks: (chunk) => { | ||
| return chunk.name === "foo"; | ||
| }, | ||
| chunks: (chunk) => chunk.name === "foo", | ||
| enforce: true, | ||
@@ -1014,5 +1012,3 @@ }, | ||
| name: "styles_bar", | ||
| chunks: (chunk) => { | ||
| return chunk.name === "bar"; | ||
| }, | ||
| chunks: (chunk) => chunk.name === "bar", | ||
| enforce: true, | ||
@@ -1144,3 +1140,3 @@ }, | ||
| options: { | ||
| additionalData: `@use 'dark-theme/vars' as vars;`, | ||
| additionalData: "@use 'dark-theme/vars' as vars;", | ||
| }, | ||
@@ -1157,3 +1153,3 @@ }, | ||
| options: { | ||
| additionalData: `@use 'light-theme/vars' as vars;`, | ||
| additionalData: "@use 'light-theme/vars' as vars;", | ||
| }, | ||
@@ -1180,3 +1176,3 @@ }, | ||
| ```js | ||
| ``` | ||
| import "./style.scss"; | ||
@@ -1190,3 +1186,2 @@ | ||
| async function loadTheme(newTheme) { | ||
| // eslint-disable-next-line no-console | ||
| console.log(`CHANGE THEME - ${newTheme}`); | ||
@@ -1201,3 +1196,2 @@ | ||
| if (themes[newTheme]) { | ||
| // eslint-disable-next-line no-console | ||
| console.log(`THEME ALREADY LOADED - ${newTheme}`); | ||
@@ -1211,3 +1205,2 @@ | ||
| if (newTheme === "dark") { | ||
| // eslint-disable-next-line no-console | ||
| console.log(`LOADING THEME - ${newTheme}`); | ||
@@ -1218,3 +1211,2 @@ | ||
| // eslint-disable-next-line no-console | ||
| console.log(`LOADED - ${newTheme}`); | ||
@@ -1297,3 +1289,3 @@ }); | ||
| `${varNames.tag}.setAttribute("href", "https://github.com/webpack-contrib/mini-css-extract-plugin");`, | ||
| ]) | ||
| ]), | ||
| ); | ||
@@ -1300,0 +1292,0 @@ ``` |
@@ -1,3 +0,16 @@ | ||
| declare function _exports(moduleId: TODO, options: TODO): TODO; | ||
| declare namespace _exports { | ||
| export { GetScriptSrc, HotHTMLLinkElement }; | ||
| } | ||
| declare function _exports( | ||
| moduleId: number | string, | ||
| options: { | ||
| filename?: string; | ||
| locals?: boolean; | ||
| }, | ||
| ): () => void; | ||
| export = _exports; | ||
| export type TODO = any; | ||
| type GetScriptSrc = (filename?: string) => string[]; | ||
| type HotHTMLLinkElement = HTMLLinkElement & { | ||
| isLoaded: boolean; | ||
| visited: boolean; | ||
| }; |
+1
-1
| export function getCompilationHooks( | ||
| compilation: Compilation | ||
| compilation: Compilation, | ||
| ): MiniCssExtractPluginCompilationHooks; | ||
@@ -4,0 +4,0 @@ export type Compilation = import("webpack").Compilation; |
+215
-116
| export = MiniCssExtractPlugin; | ||
| declare class MiniCssExtractPlugin { | ||
| /** | ||
| * @param {Compiler["webpack"]} webpack | ||
| * @returns {CssModuleConstructor} | ||
| * @param {Compiler["webpack"]} webpack webpack | ||
| * @returns {CssModuleConstructor} CSS module constructor | ||
| */ | ||
| static getCssModule(webpack: Compiler["webpack"]): CssModuleConstructor; | ||
| /** | ||
| * @param {Compiler["webpack"]} webpack | ||
| * @returns {CssDependencyConstructor} | ||
| * @param {Compiler["webpack"]} webpack webpack | ||
| * @returns {CssDependencyConstructor} CSS dependency constructor | ||
| */ | ||
| static getCssDependency( | ||
| webpack: Compiler["webpack"] | ||
| webpack: Compiler["webpack"], | ||
| ): CssDependencyConstructor; | ||
@@ -21,6 +21,6 @@ /** | ||
| static getCompilationHooks( | ||
| compilation: Compilation | ||
| compilation: Compilation, | ||
| ): MiniCssExtractPluginCompilationHooks; | ||
| /** | ||
| * @param {PluginOptions} [options] | ||
| * @param {PluginOptions=} options options | ||
| */ | ||
@@ -31,3 +31,2 @@ constructor(options?: PluginOptions | undefined); | ||
| * @type {WeakMap<Chunk, Set<CssModule>>} | ||
| * @private | ||
| */ | ||
@@ -46,3 +45,3 @@ private _sortedModulesCache; | ||
| /** | ||
| * @param {Compiler} compiler | ||
| * @param {Compiler} compiler compiler | ||
| */ | ||
@@ -52,5 +51,5 @@ apply(compiler: Compiler): void; | ||
| * @private | ||
| * @param {Chunk} chunk | ||
| * @param {ChunkGraph} chunkGraph | ||
| * @returns {Iterable<Module>} | ||
| * @param {Chunk} chunk chunk | ||
| * @param {ChunkGraph} chunkGraph chunk graph | ||
| * @returns {Iterable<Module>} modules | ||
| */ | ||
@@ -60,7 +59,7 @@ private getChunkModules; | ||
| * @private | ||
| * @param {Compilation} compilation | ||
| * @param {Chunk} chunk | ||
| * @param {CssModule[]} modules | ||
| * @param {Compilation["requestShortener"]} requestShortener | ||
| * @returns {Set<CssModule>} | ||
| * @param {Compilation} compilation compilation | ||
| * @param {Chunk} chunk chunk | ||
| * @param {CssModule[]} modules modules | ||
| * @param {Compilation["requestShortener"]} requestShortener request shortener | ||
| * @returns {Set<CssModule>} css modules | ||
| */ | ||
@@ -70,10 +69,10 @@ private sortModules; | ||
| * @private | ||
| * @param {Compiler} compiler | ||
| * @param {Compilation} compilation | ||
| * @param {Chunk} chunk | ||
| * @param {CssModule[]} modules | ||
| * @param {Compiler["requestShortener"]} requestShortener | ||
| * @param {string} filenameTemplate | ||
| * @param {Parameters<Exclude<Required<Configuration>['output']['filename'], string | undefined>>[0]} pathData | ||
| * @returns {Source} | ||
| * @param {Compiler} compiler compiler | ||
| * @param {Compilation} compilation compilation | ||
| * @param {Chunk} chunk chunk | ||
| * @param {CssModule[]} modules modules | ||
| * @param {Compiler["requestShortener"]} requestShortener request shortener | ||
| * @param {string} filenameTemplate filename template | ||
| * @param {Parameters<Exclude<Required<Configuration>['output']['filename'], string | undefined>>[0]} pathData path data | ||
| * @returns {Source} source | ||
| */ | ||
@@ -100,2 +99,4 @@ private renderContentAsset; | ||
| LoaderDependency, | ||
| Filename, | ||
| ChunkFilename, | ||
| LoaderOptions, | ||
@@ -105,5 +106,4 @@ PluginOptions, | ||
| RuntimeOptions, | ||
| TODO, | ||
| CssModuleDependency, | ||
| CssModule, | ||
| CssModuleDependency, | ||
| CssModuleConstructor, | ||
@@ -117,28 +117,2 @@ CssDependency, | ||
| } | ||
| type Compiler = import("webpack").Compiler; | ||
| type CssModuleConstructor = new (dependency: CssModuleDependency) => CssModule; | ||
| type CssDependencyConstructor = new ( | ||
| loaderDependency: CssDependencyOptions, | ||
| context: string | null, | ||
| identifierIndex: number | ||
| ) => CssDependency; | ||
| type Compilation = import("webpack").Compilation; | ||
| type MiniCssExtractPluginCompilationHooks = { | ||
| beforeTagInsert: import("tapable").SyncWaterfallHook< | ||
| [string, VarNames], | ||
| string | ||
| >; | ||
| linkPreload: SyncWaterfallHook<[string, Chunk]>; | ||
| linkPrefetch: SyncWaterfallHook<[string, Chunk]>; | ||
| }; | ||
| type PluginOptions = { | ||
| filename?: Required<Configuration>["output"]["filename"]; | ||
| chunkFilename?: Required<Configuration>["output"]["chunkFilename"]; | ||
| ignoreOrder?: boolean | undefined; | ||
| insert?: string | ((linkTag: HTMLLinkElement) => void) | undefined; | ||
| attributes?: Record<string, string> | undefined; | ||
| linkType?: string | false | undefined; | ||
| runtime?: boolean | undefined; | ||
| experimentalUseImportModule?: boolean | undefined; | ||
| }; | ||
| /** @typedef {import("schema-utils/declarations/validate").Schema} Schema */ | ||
@@ -149,3 +123,3 @@ /** @typedef {import("webpack").Compiler} Compiler */ | ||
| /** @typedef {import("webpack").Chunk} Chunk */ | ||
| /** @typedef {Parameters<import("webpack").Chunk["isInGroup"]>[0]} ChunkGroup */ | ||
| /** @typedef {import("webpack").ChunkGroup} ChunkGroup */ | ||
| /** @typedef {import("webpack").Module} Module */ | ||
@@ -158,39 +132,40 @@ /** @typedef {import("webpack").Dependency} Dependency */ | ||
| /** @typedef {import("./loader.js").Dependency} LoaderDependency */ | ||
| /** @typedef {NonNullable<Required<Configuration>['output']['filename']>} Filename */ | ||
| /** @typedef {NonNullable<Required<Configuration>['output']['chunkFilename']>} ChunkFilename */ | ||
| /** | ||
| * @typedef {Object} LoaderOptions | ||
| * @property {string | ((resourcePath: string, rootContext: string) => string)} [publicPath] | ||
| * @property {boolean} [emit] | ||
| * @property {boolean} [esModule] | ||
| * @property {string} [layer] | ||
| * @property {boolean} [defaultExport] | ||
| * @typedef {object} LoaderOptions | ||
| * @property {string | ((resourcePath: string, rootContext: string) => string)=} publicPath public path | ||
| * @property {boolean=} emit true when need to emit, otherwise false | ||
| * @property {boolean=} esModule need to generate ES module syntax | ||
| * @property {string=} layer a layer | ||
| * @property {boolean=} defaultExport true when need to use default export, otherwise false | ||
| */ | ||
| /** | ||
| * @typedef {Object} PluginOptions | ||
| * @property {Required<Configuration>['output']['filename']} [filename] | ||
| * @property {Required<Configuration>['output']['chunkFilename']} [chunkFilename] | ||
| * @property {boolean} [ignoreOrder] | ||
| * @property {string | ((linkTag: HTMLLinkElement) => void)} [insert] | ||
| * @property {Record<string, string>} [attributes] | ||
| * @property {string | false | 'text/css'} [linkType] | ||
| * @property {boolean} [runtime] | ||
| * @property {boolean} [experimentalUseImportModule] | ||
| * @typedef {object} PluginOptions | ||
| * @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<string, string>=} attributes link attributes | ||
| * @property {string | false | 'text/css'=} linkType value of a link type attribute | ||
| * @property {boolean=} runtime true when need to generate runtime code, otherwise false | ||
| * @property {boolean=} experimentalUseImportModule true when need to use `experimentalUseImportModule` API, otherwise false | ||
| */ | ||
| /** | ||
| * @typedef {Object} NormalizedPluginOptions | ||
| * @property {Required<Configuration>['output']['filename']} filename | ||
| * @property {Required<Configuration>['output']['chunkFilename']} [chunkFilename] | ||
| * @property {boolean} ignoreOrder | ||
| * @property {string | ((linkTag: HTMLLinkElement) => void)} [insert] | ||
| * @property {Record<string, string>} [attributes] | ||
| * @property {string | false | 'text/css'} [linkType] | ||
| * @property {boolean} runtime | ||
| * @property {boolean} [experimentalUseImportModule] | ||
| * @typedef {object} NormalizedPluginOptions | ||
| * @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<string, string>=} attributes link attributes | ||
| * @property {string | false | 'text/css'=} linkType value of a link type attribute | ||
| * @property {boolean} runtime true when need to generate runtime code, otherwise false | ||
| * @property {boolean=} experimentalUseImportModule true when need to use `experimentalUseImportModule` API, otherwise false | ||
| */ | ||
| /** | ||
| * @typedef {Object} RuntimeOptions | ||
| * @property {string | ((linkTag: HTMLLinkElement) => void) | undefined} insert | ||
| * @property {string | false | 'text/css'} linkType | ||
| * @property {Record<string, string> | undefined} attributes | ||
| * @typedef {object} RuntimeOptions | ||
| * @property {string | ((linkTag: HTMLLinkElement) => void)=} insert a link insert place or a custom insert function | ||
| * @property {string | false | 'text/css'} linkType value of a link type attribute | ||
| * @property {Record<string, string>=} attributes link attributes | ||
| */ | ||
| /** @typedef {any} TODO */ | ||
| declare const pluginName: "mini-css-extract-plugin"; | ||
@@ -200,5 +175,7 @@ declare const pluginSymbol: unique symbol; | ||
| type Schema = import("schema-utils/declarations/validate").Schema; | ||
| type Compiler = import("webpack").Compiler; | ||
| type Compilation = import("webpack").Compilation; | ||
| type ChunkGraph = import("webpack").ChunkGraph; | ||
| type Chunk = import("webpack").Chunk; | ||
| type ChunkGroup = Parameters<import("webpack").Chunk["isInGroup"]>[0]; | ||
| type ChunkGroup = import("webpack").ChunkGroup; | ||
| type Module = import("webpack").Module; | ||
@@ -211,41 +188,112 @@ type Dependency = import("webpack").Dependency; | ||
| type LoaderDependency = import("./loader.js").Dependency; | ||
| type Filename = NonNullable<Required<Configuration>["output"]["filename"]>; | ||
| type ChunkFilename = NonNullable< | ||
| Required<Configuration>["output"]["chunkFilename"] | ||
| >; | ||
| type LoaderOptions = { | ||
| /** | ||
| * public path | ||
| */ | ||
| publicPath?: | ||
| | string | ||
| | ((resourcePath: string, rootContext: string) => string) | ||
| | (string | ((resourcePath: string, rootContext: string) => string)) | ||
| | undefined; | ||
| /** | ||
| * true when need to emit, otherwise false | ||
| */ | ||
| emit?: boolean | undefined; | ||
| /** | ||
| * need to generate ES module syntax | ||
| */ | ||
| esModule?: boolean | undefined; | ||
| /** | ||
| * a layer | ||
| */ | ||
| layer?: string | undefined; | ||
| /** | ||
| * true when need to use default export, otherwise false | ||
| */ | ||
| defaultExport?: boolean | undefined; | ||
| }; | ||
| type PluginOptions = { | ||
| /** | ||
| * filename | ||
| */ | ||
| filename?: Filename | undefined; | ||
| /** | ||
| * chunk filename | ||
| */ | ||
| chunkFilename?: ChunkFilename | undefined; | ||
| /** | ||
| * true when need to ignore order, otherwise false | ||
| */ | ||
| ignoreOrder?: boolean | undefined; | ||
| /** | ||
| * link insert place or a custom insert function | ||
| */ | ||
| insert?: (string | ((linkTag: HTMLLinkElement) => void)) | undefined; | ||
| /** | ||
| * link attributes | ||
| */ | ||
| attributes?: Record<string, string> | undefined; | ||
| /** | ||
| * value of a link type attribute | ||
| */ | ||
| linkType?: (string | false | "text/css") | undefined; | ||
| /** | ||
| * true when need to generate runtime code, otherwise false | ||
| */ | ||
| runtime?: boolean | undefined; | ||
| /** | ||
| * true when need to use `experimentalUseImportModule` API, otherwise false | ||
| */ | ||
| experimentalUseImportModule?: boolean | undefined; | ||
| }; | ||
| type NormalizedPluginOptions = { | ||
| filename: Required<Configuration>["output"]["filename"]; | ||
| chunkFilename?: Required<Configuration>["output"]["chunkFilename"]; | ||
| /** | ||
| * filename | ||
| */ | ||
| filename: Filename; | ||
| /** | ||
| * chunk filename | ||
| */ | ||
| chunkFilename?: ChunkFilename | undefined; | ||
| /** | ||
| * true when need to ignore order, otherwise false | ||
| */ | ||
| ignoreOrder: boolean; | ||
| insert?: string | ((linkTag: HTMLLinkElement) => void) | undefined; | ||
| /** | ||
| * a link insert place or a custom insert function | ||
| */ | ||
| insert?: (string | ((linkTag: HTMLLinkElement) => void)) | undefined; | ||
| /** | ||
| * link attributes | ||
| */ | ||
| attributes?: Record<string, string> | undefined; | ||
| linkType?: string | false | undefined; | ||
| /** | ||
| * value of a link type attribute | ||
| */ | ||
| linkType?: (string | false | "text/css") | undefined; | ||
| /** | ||
| * true when need to generate runtime code, otherwise false | ||
| */ | ||
| runtime: boolean; | ||
| /** | ||
| * true when need to use `experimentalUseImportModule` API, otherwise false | ||
| */ | ||
| experimentalUseImportModule?: boolean | undefined; | ||
| }; | ||
| type RuntimeOptions = { | ||
| insert: string | ((linkTag: HTMLLinkElement) => void) | undefined; | ||
| /** | ||
| * a link insert place or a custom insert function | ||
| */ | ||
| insert?: (string | ((linkTag: HTMLLinkElement) => void)) | undefined; | ||
| /** | ||
| * value of a link type attribute | ||
| */ | ||
| linkType: string | false | "text/css"; | ||
| attributes: Record<string, string> | undefined; | ||
| /** | ||
| * link attributes | ||
| */ | ||
| attributes?: Record<string, string> | undefined; | ||
| }; | ||
| type TODO = any; | ||
| type CssModule = import("webpack").Module & { | ||
| content: Buffer; | ||
| media?: string | undefined; | ||
| sourceMap?: Buffer | undefined; | ||
| supports?: string | undefined; | ||
| layer?: string | undefined; | ||
| assets?: | ||
| | { | ||
| [key: string]: any; | ||
| } | ||
| | undefined; | ||
| assetsInfo?: Map<string, import("webpack").AssetInfo> | undefined; | ||
| }; | ||
| type CssModuleDependency = { | ||
@@ -256,22 +304,73 @@ context: string | null; | ||
| content: Buffer; | ||
| sourceMap?: Buffer | undefined; | ||
| media?: string | undefined; | ||
| supports?: string | undefined; | ||
| layer?: TODO; | ||
| assetsInfo?: Map<string, import("webpack").AssetInfo> | undefined; | ||
| assets?: | ||
| | { | ||
| [key: string]: any; | ||
| } | ||
| | undefined; | ||
| sourceMap?: Buffer; | ||
| media?: string; | ||
| supports?: string; | ||
| layer?: any; | ||
| assetsInfo?: Map<string, AssetInfo>; | ||
| assets?: { | ||
| [key: string]: Source; | ||
| }; | ||
| }; | ||
| type CssModule = Module & { | ||
| content: Buffer; | ||
| media?: string; | ||
| sourceMap?: Buffer; | ||
| supports?: string; | ||
| layer?: string; | ||
| assets?: { | ||
| [key: string]: Source; | ||
| }; | ||
| assetsInfo?: Map<string, AssetInfo>; | ||
| }; | ||
| type CssModuleConstructor = { | ||
| new (dependency: CssModuleDependency): CssModule; | ||
| }; | ||
| type CssDependency = Dependency & CssModuleDependency; | ||
| type CssDependencyOptions = Omit<LoaderDependency, "context">; | ||
| type CssDependencyConstructor = { | ||
| new ( | ||
| loaderDependency: CssDependencyOptions, | ||
| context: string | null, | ||
| identifierIndex: number, | ||
| ): CssDependency; | ||
| }; | ||
| type VarNames = { | ||
| /** | ||
| * tag | ||
| */ | ||
| tag: string; | ||
| /** | ||
| * chunk id | ||
| */ | ||
| chunkId: string; | ||
| /** | ||
| * href | ||
| */ | ||
| href: string; | ||
| /** | ||
| * resolve | ||
| */ | ||
| resolve: string; | ||
| /** | ||
| * reject | ||
| */ | ||
| reject: string; | ||
| }; | ||
| type MiniCssExtractPluginCompilationHooks = { | ||
| /** | ||
| * before tag insert hook | ||
| */ | ||
| beforeTagInsert: import("tapable").SyncWaterfallHook< | ||
| [string, VarNames], | ||
| string | ||
| >; | ||
| /** | ||
| * link preload hook | ||
| */ | ||
| linkPreload: SyncWaterfallHook<[string, Chunk]>; | ||
| /** | ||
| * link prefetch hook | ||
| */ | ||
| linkPrefetch: SyncWaterfallHook<[string, Chunk]>; | ||
| }; | ||
| import { SyncWaterfallHook } from "tapable"; |
+51
-29
| export = loader; | ||
| /** | ||
| * @this {import("webpack").LoaderContext<LoaderOptions>} | ||
| * @param {string} content | ||
| * @param {string} content content | ||
| * @returns {string | undefined} the original content | ||
| */ | ||
| declare function loader( | ||
| this: import("webpack").LoaderContext<MiniCssExtractPlugin.LoaderOptions>, | ||
| content: string | ||
| content: string, | ||
| ): string | undefined; | ||
| declare namespace loader { | ||
| export { | ||
| hotLoader, | ||
| pitch, | ||
| hotLoader, | ||
| Schema, | ||
@@ -24,3 +25,3 @@ Compiler, | ||
| Locals, | ||
| TODO, | ||
| EXPECTED_ANY, | ||
| Dependency, | ||
@@ -30,10 +31,2 @@ }; | ||
| import MiniCssExtractPlugin = require("./index"); | ||
| /** | ||
| * @this {import("webpack").LoaderContext<LoaderOptions>} | ||
| * @param {string} request | ||
| */ | ||
| declare function pitch( | ||
| this: import("webpack").LoaderContext<MiniCssExtractPlugin.LoaderOptions>, | ||
| request: string | ||
| ): void; | ||
| /** @typedef {import("schema-utils/declarations/validate").Schema} Schema */ | ||
@@ -48,21 +41,21 @@ /** @typedef {import("webpack").Compiler} Compiler */ | ||
| /** @typedef {import("./index.js").LoaderOptions} LoaderOptions */ | ||
| /** @typedef {{ [key: string]: string | function }} Locals */ | ||
| /** @typedef {any} TODO */ | ||
| /** @typedef {{[key: string]: string | Function }} Locals */ | ||
| /** @typedef {any} EXPECTED_ANY */ | ||
| /** | ||
| * @typedef {Object} Dependency | ||
| * @property {string} identifier | ||
| * @property {string | null} context | ||
| * @property {Buffer} content | ||
| * @property {string} media | ||
| * @property {string} [supports] | ||
| * @property {string} [layer] | ||
| * @property {Buffer} [sourceMap] | ||
| * @typedef {object} Dependency | ||
| * @property {string} identifier identifier | ||
| * @property {string | null} context context | ||
| * @property {Buffer} content content | ||
| * @property {string=} media media | ||
| * @property {string=} supports supports | ||
| * @property {string=} layer layer | ||
| * @property {Buffer=} sourceMap source map | ||
| */ | ||
| /** | ||
| * @param {string} content | ||
| * @param {{ loaderContext: import("webpack").LoaderContext<LoaderOptions>, options: LoaderOptions, locals: Locals | undefined }} context | ||
| * @returns {string} | ||
| * @param {string} code code | ||
| * @param {{ loaderContext: import("webpack").LoaderContext<LoaderOptions>, options: LoaderOptions, locals: Locals | undefined }} context context | ||
| * @returns {string} code and HMR code | ||
| */ | ||
| declare function hotLoader( | ||
| content: string, | ||
| code: string, | ||
| context: { | ||
@@ -72,4 +65,12 @@ loaderContext: import("webpack").LoaderContext<LoaderOptions>; | ||
| locals: Locals | undefined; | ||
| } | ||
| }, | ||
| ): string; | ||
| /** | ||
| * @this {import("webpack").LoaderContext<LoaderOptions>} | ||
| * @param {string} request request | ||
| */ | ||
| declare function pitch( | ||
| this: import("webpack").LoaderContext<MiniCssExtractPlugin.LoaderOptions>, | ||
| request: string, | ||
| ): void; | ||
| type Schema = import("schema-utils/declarations/validate").Schema; | ||
@@ -87,11 +88,32 @@ type Compiler = import("webpack").Compiler; | ||
| }; | ||
| type TODO = any; | ||
| type EXPECTED_ANY = any; | ||
| type Dependency = { | ||
| /** | ||
| * identifier | ||
| */ | ||
| identifier: string; | ||
| /** | ||
| * context | ||
| */ | ||
| context: string | null; | ||
| /** | ||
| * content | ||
| */ | ||
| content: Buffer; | ||
| media: string; | ||
| /** | ||
| * media | ||
| */ | ||
| media?: string | undefined; | ||
| /** | ||
| * supports | ||
| */ | ||
| supports?: string | undefined; | ||
| /** | ||
| * layer | ||
| */ | ||
| layer?: string | undefined; | ||
| /** | ||
| * source map | ||
| */ | ||
| sourceMap?: Buffer | undefined; | ||
| }; |
+48
-49
| export type Compilation = import("webpack").Compilation; | ||
| export type Module = import("webpack").Module; | ||
| export type LoaderContext = import("webpack").LoaderContext<any>; | ||
| /** @typedef {import("webpack").Compilation} Compilation */ | ||
| /** @typedef {import("webpack").Module} Module */ | ||
| /** @typedef {import("webpack").LoaderContext<any>} LoaderContext */ | ||
| export const ABSOLUTE_PUBLIC_PATH: "webpack:///mini-css-extract-plugin/"; | ||
| export const AUTO_PUBLIC_PATH: "__mini_css_extract_plugin_public_path_auto__"; | ||
| export const BASE_URI: "webpack://"; | ||
| export const MODULE_TYPE: "css/mini-extract"; | ||
| export const SINGLE_DOT_PATH_SEGMENT: "__mini_css_extract_plugin_single_dot_path_segment__"; | ||
| /** | ||
| * @returns {boolean} | ||
| * @param {Module} a a | ||
| * @param {Module} b b | ||
| * @returns {0 | 1 | -1} result of comparing | ||
| */ | ||
| export function trueFn(): boolean; | ||
| export function compareModulesByIdentifier(a: Module, b: Module): 0 | 1 | -1; | ||
| /** | ||
| * @param {Compilation} compilation | ||
| * @param {string | number} id | ||
| * @returns {null | Module} | ||
| * @param {Record<string | number, boolean>} map value map | ||
| * @returns {boolean | ((value: string) => string)} true/false, when unconditionally true/false, or a template function to determine the value at runtime | ||
| */ | ||
| export function findModuleById( | ||
| compilation: Compilation, | ||
| id: string | number | ||
| ): null | Module; | ||
| export function compileBooleanMatcher( | ||
| map: Record<string | number, boolean>, | ||
| ): boolean | ((value: string) => string); | ||
| /** | ||
| * @param {LoaderContext} loaderContext | ||
| * @param {string | Buffer} code | ||
| * @param {string} filename | ||
| * @returns {object} | ||
| * @param {LoaderContext} loaderContext loader context | ||
| * @param {string | Buffer} code code | ||
| * @param {string} filename filename | ||
| * @returns {Record<string, any>} exports of a module | ||
| */ | ||
@@ -29,47 +31,44 @@ export function evalModuleCode( | ||
| code: string | Buffer, | ||
| filename: string | ||
| ): object; | ||
| filename: string, | ||
| ): Record<string, any>; | ||
| /** | ||
| * @param {Module} a | ||
| * @param {Module} b | ||
| * @returns {0 | 1 | -1} | ||
| * @param {Compilation} compilation compilation | ||
| * @param {string | number} id module id | ||
| * @returns {null | Module} the found module | ||
| */ | ||
| export function compareModulesByIdentifier(a: Module, b: Module): 0 | 1 | -1; | ||
| export const MODULE_TYPE: "css/mini-extract"; | ||
| export const AUTO_PUBLIC_PATH: "__mini_css_extract_plugin_public_path_auto__"; | ||
| export const ABSOLUTE_PUBLIC_PATH: "webpack:///mini-css-extract-plugin/"; | ||
| export const BASE_URI: "webpack://"; | ||
| export const SINGLE_DOT_PATH_SEGMENT: "__mini_css_extract_plugin_single_dot_path_segment__"; | ||
| export function findModuleById( | ||
| compilation: Compilation, | ||
| id: string | number, | ||
| ): null | Module; | ||
| /** | ||
| * @param {LoaderContext} loaderContext | ||
| * @param {string} request | ||
| * @returns {string} | ||
| * @param {string} filename filename | ||
| * @param {string} outputPath output path | ||
| * @param {boolean} enforceRelative true when need to enforce relative path, otherwise false | ||
| * @returns {string} undo path | ||
| */ | ||
| export function stringifyRequest( | ||
| loaderContext: LoaderContext, | ||
| request: string | ||
| export function getUndoPath( | ||
| filename: string, | ||
| outputPath: string, | ||
| enforceRelative: boolean, | ||
| ): string; | ||
| /** | ||
| * | ||
| * @param {string | function} value | ||
| * @returns {string} | ||
| * @param {string | Function} value local | ||
| * @returns {string} stringified local | ||
| */ | ||
| export function stringifyLocal(value: string | Function): string; | ||
| /** | ||
| * @param {string} filename | ||
| * @param {string} outputPath | ||
| * @param {boolean} enforceRelative | ||
| * @returns {string} | ||
| * @param {LoaderContext} loaderContext the loader context | ||
| * @param {string} request a request | ||
| * @returns {string} a stringified request | ||
| */ | ||
| export function getUndoPath( | ||
| filename: string, | ||
| outputPath: string, | ||
| enforceRelative: boolean | ||
| export function stringifyRequest( | ||
| loaderContext: LoaderContext, | ||
| request: string, | ||
| ): string; | ||
| /** @typedef {import("webpack").Compilation} Compilation */ | ||
| /** @typedef {import("webpack").Module} Module */ | ||
| /** @typedef {import("webpack").LoaderContext<any>} LoaderContext */ | ||
| /** | ||
| * @param {Record<string|number, boolean>} map value map | ||
| * @returns {boolean|(function(string): string)} true/false, when unconditionally true/false, or a template function to determine the value at runtime | ||
| * @returns {boolean} always returns true | ||
| */ | ||
| export function compileBooleanMatcher( | ||
| map: Record<string | number, boolean> | ||
| ): boolean | ((arg0: string) => string); | ||
| export function trueFn(): boolean; |
Debug access
Supply chain riskUses debug, reflection and dynamic code execution features.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
Debug access
Supply chain riskUses debug, reflection and dynamic code execution features.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
139828
4.16%2754
4.08%44
25.71%1297
-0.61%