Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2,277 changes: 1,413 additions & 864 deletions package-lock.json

Large diffs are not rendered by default.

12 changes: 0 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,6 @@
"@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",
"bootstrap": "^4.6.2",
"cross-env": "^7.0.3",
Expand All @@ -73,16 +70,8 @@
"del-cli": "^4.0.0",
"es-check": "^7.1.0",
"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": "^62.0.0",
"eslint-plugin-n": "^17.21.0",
"eslint-plugin-prettier": "^5.5.3",
"eslint-plugin-unicorn": "^62.0.0",
"file-loader": "^6.2.0",
"globals": "^17.0.0",
"husky": "^7.0.0",
"jest": "^28.1.3",
"jest-environment-jsdom": "^28.1.3",
Expand All @@ -96,7 +85,6 @@
"sass-loader": "^12.6.0",
"standard-version": "^9.3.0",
"typescript": "^5.8.0",
"typescript-eslint": "^8.38.0",
"webpack": "^5.102.0",
"webpack-cli": "^4.9.2",
"webpack-dev-server": "^5.2.1"
Expand Down
12 changes: 6 additions & 6 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ const {
* @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 {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
*/
Expand All @@ -61,15 +61,15 @@ const {
* @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 {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)=} insert a link insert place or a custom insert function
* @property {string | false | 'text/css'} linkType value of a link type attribute
* @property {string | false | "text/css"} linkType value of a link type attribute
* @property {Record<string, string>=} attributes link attributes
*/

Expand All @@ -90,12 +90,12 @@ const CODE_GENERATION_RESULT = {
};

// eslint-disable-next-line jsdoc/reject-any-type
/** @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 {{ 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 */
/** @typedef {{ new (dependency: CssModuleDependency): CssModule }} CssModuleConstructor */
/** @typedef {Dependency & CssModuleDependency} CssDependency */
/** @typedef {Omit<LoaderDependency, "context">} CssDependencyOptions */
/** @typedef {{ new(loaderDependency: CssDependencyOptions, context: string | null, identifierIndex: number): CssDependency }} CssDependencyConstructor */
/** @typedef {{ new (loaderDependency: CssDependencyOptions, context: string | null, identifierIndex: number): CssDependency }} CssDependencyConstructor */

/**
* @typedef {object} VarNames
Expand Down
2 changes: 1 addition & 1 deletion src/loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const MiniCssExtractPlugin = require("./index");
/** @typedef {import("./index.js").LoaderOptions} LoaderOptions */

// eslint-disable-next-line jsdoc/reject-function-type
/** @typedef {{[key: string]: string | Function }} Locals */
/** @typedef {{ [key: string]: string | Function }} Locals */

// eslint-disable-next-line jsdoc/reject-any-type
/** @typedef {any} EXPECTED_ANY */
Expand Down
18 changes: 9 additions & 9 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ const toSimpleString = (str) => {
const quoteMeta = (str) => str.replace(/[-[\]\\/{}()*+?.^$|]/g, "\\$&");

/**
* @param {Array<string>} items items
* @param {string[]} items items
* @returns {string} common prefix
*/
const getCommonPrefix = (items) => {
Expand All @@ -253,7 +253,7 @@ const getCommonPrefix = (items) => {
};

/**
* @param {Array<string>} items items
* @param {string[]} items items
* @returns {string} common suffix
*/
const getCommonSuffix = (items) => {
Expand All @@ -279,27 +279,27 @@ const getCommonSuffix = (items) => {
/**
* @param {Set<string>} itemsSet items set
* @param {(str: string) => string | false} getKey get key function
* @param {(str: Array<string>) => boolean} condition condition
* @returns {Array<Array<string>>} list of common items
* @param {(str: string[]) => boolean} condition condition
* @returns {string[][]} list of common items
*/
const popCommonItems = (itemsSet, getKey, condition) => {
/** @type {Map<string, Array<string>>} */
/** @type {Map<string, string[]>} */
const map = new Map();

for (const item of itemsSet) {
const key = getKey(item);
if (key) {
let list = map.get(key);
if (list === undefined) {
/** @type {Array<string>} */
/** @type {string[]} */
list = [];
map.set(key, list);
}
list.push(item);
}
}

/** @type {Array<Array<string>>} */
/** @type {string[][]} */
const result = [];

for (const list of map.values()) {
Expand All @@ -315,15 +315,15 @@ const popCommonItems = (itemsSet, getKey, condition) => {
};

/**
* @param {Array<string>} itemsArr array of items
* @param {string[]} itemsArr array of items
* @returns {string} regexp
*/
const itemsToRegexp = (itemsArr) => {
if (itemsArr.length === 1) {
return quoteMeta(itemsArr[0]);
}

/** @type {Array<string>} */
/** @type {string[]} */
const finishedItems = [];

// merge single char items: (a|b|c|d|ef) => ([abcd]|ef)
Expand Down
7 changes: 3 additions & 4 deletions test/HMR.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/**
* @jest-environment jsdom
*/
/* global document */

import hotModuleReplacement from "../src/hmr/hotModuleReplacement";
import { hotLoader } from "../src/loader";
Expand All @@ -26,9 +25,9 @@ describe("HMR", () => {
let consoleMock = null;

beforeEach(() => {
consoleMock = jest.spyOn(console, "log").mockImplementation(() => () => {});
consoleMock = jest.spyOn(console, "log").mockReturnValue(() => {});

jest.spyOn(Date, "now").mockImplementation(() => 1479427200000);
jest.spyOn(Date, "now").mockReturnValue(1479427200000);

document.head.innerHTML = '<link rel="stylesheet" href="/dist/main.css" />';
document.body.innerHTML = '<script src="/dist/main.js"></script>';
Expand Down Expand Up @@ -80,7 +79,7 @@ describe("HMR", () => {

expect(links[1].isLoaded).toBe(true);

jest.spyOn(Date, "now").mockImplementation(() => 1479427200001);
jest.spyOn(Date, "now").mockReturnValue(1479427200001);

const update2 = hotModuleReplacement("./src/style.css", {});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ __webpack_require__.r(__webpack_exports__);
/******/
/******/ /* webpack/runtime/getFullHash */
/******/ (() => {
/******/ __webpack_require__.h = () => ("656f51af10a65a287c7e")
/******/ __webpack_require__.h = () => ("0ca34a06508c170bc52a")
/******/ })();
/******/
/******/ /* webpack/runtime/global */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ __webpack_require__.r(__webpack_exports__);
/******/
/******/ /* webpack/runtime/getFullHash */
/******/ (() => {
/******/ __webpack_require__.h = () => ("ff368441c28faebc6a1c")
/******/ __webpack_require__.h = () => ("605c3e6592e34107bde4")
/******/ })();
/******/
/******/ /* webpack/runtime/global */
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion test/cases/devtool-source-map/expected/main.css.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions test/cases/hmr-locals/expected/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -421,12 +421,6 @@ __webpack_require__.r(__webpack_exports__);
/******/ if (cachedModule.error !== undefined) throw cachedModule.error;
/******/ return cachedModule.exports;
/******/ }
/******/ // Check if module exists (development only)
/******/ if (__webpack_modules__[moduleId] === undefined) {
/******/ var e = new Error("Cannot find module '" + moduleId + "'");
/******/ e.code = 'MODULE_NOT_FOUND';
/******/ throw e;
/******/ }
/******/ // Create a new module (and put it into the cache)
/******/ var module = __webpack_module_cache__[moduleId] = {
/******/ id: moduleId,
Expand All @@ -438,6 +432,12 @@ __webpack_require__.r(__webpack_exports__);
/******/ try {
/******/ var execOptions = { id: moduleId, module: module, factory: __webpack_modules__[moduleId], require: __webpack_require__ };
/******/ __webpack_require__.i.forEach(function(handler) { handler(execOptions); });
/******/ if (!execOptions.factory) {
/******/ delete __webpack_module_cache__[moduleId];
/******/ var e = new Error("Cannot find module '" + moduleId + "'");
/******/ e.code = 'MODULE_NOT_FOUND';
/******/ throw e;
/******/ }
/******/ module = execOptions.module;
/******/ execOptions.factory.call(module.exports, module, module.exports, execOptions.require);
/******/ } catch(e) {
Expand Down
12 changes: 6 additions & 6 deletions test/cases/hmr/expected/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -418,12 +418,6 @@ __webpack_require__.r(__webpack_exports__);
/******/ if (cachedModule.error !== undefined) throw cachedModule.error;
/******/ return cachedModule.exports;
/******/ }
/******/ // Check if module exists (development only)
/******/ if (__webpack_modules__[moduleId] === undefined) {
/******/ var e = new Error("Cannot find module '" + moduleId + "'");
/******/ e.code = 'MODULE_NOT_FOUND';
/******/ throw e;
/******/ }
/******/ // Create a new module (and put it into the cache)
/******/ var module = __webpack_module_cache__[moduleId] = {
/******/ id: moduleId,
Expand All @@ -435,6 +429,12 @@ __webpack_require__.r(__webpack_exports__);
/******/ try {
/******/ var execOptions = { id: moduleId, module: module, factory: __webpack_modules__[moduleId], require: __webpack_require__ };
/******/ __webpack_require__.i.forEach(function(handler) { handler(execOptions); });
/******/ if (!execOptions.factory) {
/******/ delete __webpack_module_cache__[moduleId];
/******/ var e = new Error("Cannot find module '" + moduleId + "'");
/******/ e.code = 'MODULE_NOT_FOUND';
/******/ throw e;
/******/ }
/******/ module = execOptions.module;
/******/ execOptions.factory.call(module.exports, module, module.exports, execOptions.require);
/******/ } catch(e) {
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion test/cases/simple-async-source-map/expected/1.css.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion test/cases/simple-async-source-map/expected/2.css.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion test/cases/simple-async-source-map/expected/main.css.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions test/hooks.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ describe("hooks", () => {
}),
{
/**
* @param {import('webpack').Compiler} compiler compiler
* @param {import("webpack").Compiler} compiler compiler
*/
apply: (compiler) => {
compiler.hooks.compilation.tap("sri", (compilation) => {
Expand All @@ -42,7 +42,7 @@ describe("hooks", () => {
},
{
/**
* @param {import('webpack').Compiler} compiler compiler
* @param {import("webpack").Compiler} compiler compiler
*/
apply: (compiler) => {
compiler.hooks.compilation.tap("href", (compilation) => {
Expand Down
3 changes: 1 addition & 2 deletions test/insert-option.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* global document */
import path from "path";

import MiniCssExtractPlugin from "../src";
Expand Down Expand Up @@ -83,7 +82,7 @@ describe("insert option", () => {
plugins: [
new MiniCssExtractPlugin({
filename: "[name].css",
// eslint-disable-next-line
// eslint-disable-next-line object-shorthand
insert: function (linkTag) {
const reference = document.querySelector("#existing-style");
if (reference) {
Expand Down
6 changes: 3 additions & 3 deletions types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ declare namespace MiniCssExtractPlugin {
* @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 {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
*/
Expand All @@ -147,14 +147,14 @@ declare namespace MiniCssExtractPlugin {
* @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 {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)=} insert a link insert place or a custom insert function
* @property {string | false | 'text/css'} linkType value of a link type attribute
* @property {string | false | "text/css"} linkType value of a link type attribute
* @property {Record<string, string>=} attributes link attributes
*/
declare const pluginName: "mini-css-extract-plugin";
Expand Down
2 changes: 1 addition & 1 deletion types/loader.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import MiniCssExtractPlugin = require("./index");
/** @typedef {import("webpack").AssetInfo} AssetInfo */
/** @typedef {import("webpack").NormalModule} NormalModule */
/** @typedef {import("./index.js").LoaderOptions} LoaderOptions */
/** @typedef {{[key: string]: string | Function }} Locals */
/** @typedef {{ [key: string]: string | Function }} Locals */
/** @typedef {any} EXPECTED_ANY */
/**
* @typedef {object} Dependency
Expand Down
Loading