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 changes: 1 addition & 1 deletion .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
node-version: [18.x, 20.x, 22.x, 24.x]
node-version: [20.x, 22.x, 24.x, 25.x]
webpack-version: [latest]

runs-on: ${{ matrix.os }}
Expand Down
5,860 changes: 3,198 additions & 2,662 deletions package-lock.json

Large diffs are not rendered by default.

30 changes: 9 additions & 21 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,46 +58,34 @@
"html-minifier-terser": "^7.2.0",
"jest-worker": "^30.0.0",
"schema-utils": "^4.2.0",
"serialize-javascript": "^6.0.2"
"serialize-javascript": "^7.0.3"
},
"devDependencies": {
"@babel/cli": "^7.24.8",
"@babel/core": "^7.25.2",
"@babel/preset-env": "^7.25.3",
"@commitlint/cli": "^19.3.0",
"@commitlint/config-conventional": "^19.2.2",
"@eslint/js": "^9.32.0",
"@eslint/markdown": "^7.1.0",
"@minify-html/node": "^0.16.4",
"@stylistic/eslint-plugin": "^5.2.2",
"@commitlint/cli": "^20.4.2",
"@commitlint/config-conventional": "^20.4.2",
"@minify-html/node": "^0.18.1",
"@swc/html": "^1.13.2",
"@types/node": "^20.14.9",
"@types/serialize-javascript": "^5.0.4",
"babel-jest": "^30.0.0",
"copy-webpack-plugin": "^13.0.0",
"copy-webpack-plugin": "^14.0.0",
"cross-env": "^7.0.3",
"cspell": "^8.13.1",
"cspell": "^9.7.0",
"del": "^7.1.0",
"del-cli": "^5.1.0",
"del-cli": "^7.0.0",
"eslint": "^9.31.0",
"eslint-config-prettier": "^10.1.8",
"eslint-config-webpack": "^4.5.0",
"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",
"globals": "^16.3.0",
"husky": "^9.1.4",
"jest": "^30.0.0",
"lint-staged": "^15.2.8",
"lint-staged": "^16.3.1",
"memfs": "^4.11.1",
"npm-run-all": "^4.1.5",
"prettier": "^3.3.3",
"standard-version": "^9.5.0",
"typescript": "^5.5.4",
"typescript-eslint": "^8.38.0",
"webpack": "^5.93.0"
},
"peerDependencies": {
Expand All @@ -109,6 +97,6 @@
}
},
"engines": {
"node": ">= 18.12.0"
"node": ">= 20.9.0"
}
}
22 changes: 11 additions & 11 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ const {

/** @typedef {RegExp | string} Rule */
/** @typedef {Rule[] | Rule} Rules */
// eslint-disable-next-line jsdoc/no-restricted-syntax

// eslint-disable-next-line jsdoc/reject-any-type
/** @typedef {any} EXPECTED_ANY */

/** @typedef {Error & { plugin?: string, text?: string, source?: string } | string} Warning */
Expand All @@ -47,8 +48,8 @@ const {
/**
* @typedef {object} MinimizedResultObj
* @property {string} code The minimized code
* @property {Array<Error | ErrorObject| string>=} errors Array of errors
* @property {Array<Warning | WarningObject | string>=} warnings Array of warnings
* @property {(Error | ErrorObject | string)[]=} errors Array of errors
* @property {(Warning | WarningObject | string)[]=} warnings Array of warnings
*/

/**
Expand All @@ -70,7 +71,7 @@ const {

/**
* @template T
* @typedef {T extends any[] ? { [P in keyof T]?: InferDefaultType<T[P]> } : InferDefaultType<T>} MinimizerOptions
* @typedef {T extends EXPECTED_ANY[] ? { [P in keyof T]?: InferDefaultType<T[P]> } : InferDefaultType<T>} MinimizerOptions
*/

/**
Expand All @@ -88,7 +89,7 @@ const {

/**
* @template T
* @typedef {T extends any[] ? { [P in keyof T]: BasicMinimizerImplementation<T[P]> & MinimizeFunctionHelpers; } : BasicMinimizerImplementation<T> & MinimizeFunctionHelpers} MinimizerImplementation
* @typedef {T extends EXPECTED_ANY[] ? { [P in keyof T]: BasicMinimizerImplementation<T[P]> & MinimizeFunctionHelpers } : BasicMinimizerImplementation<T> & MinimizeFunctionHelpers} MinimizerImplementation
*/

/**
Expand All @@ -101,9 +102,9 @@ const {

/**
* @typedef InternalResult
* @property {Array<{ code: string }>} outputs Array of output objects
* @property {Array<Warning | WarningObject | string>} warnings Array of warnings
* @property {Array<Error | ErrorObject | string>} errors Array of errors
* @property {{ code: string }[]} outputs Array of output objects
* @property {(Warning | WarningObject | string)[]} warnings Array of warnings
* @property {(Error | ErrorObject | string)[]} errors Array of errors
*/

/**
Expand Down Expand Up @@ -249,12 +250,11 @@ class HtmlMinimizerPlugin {
static getAvailableNumberOfCores(parallel) {
// In some cases cpus() returns undefined
// https://github.com/nodejs/node/issues/19022
/* eslint-disable n/no-unsupported-features/node-builtins */

const cpus =
typeof os.availableParallelism === "function"
? { length: /** @type {number} */ (os.availableParallelism()) }
: os.cpus() || { length: 1 };
/* eslint-enable n/no-unsupported-features/node-builtins */

return parallel === true || typeof parallel === "undefined"
? cpus.length - 1
Expand All @@ -278,7 +278,7 @@ class HtmlMinimizerPlugin {
* @param {Compiler} compiler The webpack compiler
* @param {Compilation} compilation The webpack compilation
* @param {Record<string, import("webpack").sources.Source>} assets The assets to optimize
* @param {{availableNumberOfCores: number}} optimizeOptions Optimization options
* @param {{ availableNumberOfCores: number }} optimizeOptions Optimization options
* @returns {Promise<void>} Promise that resolves when optimization is complete
*/
async optimize(compiler, compilation, assets, optimizeOptions) {
Expand Down
7 changes: 3 additions & 4 deletions src/utils.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
/** @typedef {import("./index.js").MinimizedResult} MinimizedResult */
/** @typedef {import("./index.js").CustomOptions} CustomOptions */
/** @typedef {import("./index.js").Input} Input */
// eslint-disable-next-line jsdoc/no-restricted-syntax
/** @typedef {any} EXPECTED_ANY */
/** @typedef {import("./index.js").EXPECTED_ANY} EXPECTED_ANY */

const notSettled = Symbol("not-settled");

Expand Down Expand Up @@ -155,7 +154,7 @@ async function swcMinify(input, minimizerOptions = {}) {
errors: result.errors
? result.errors.map((diagnostic) => {
const error =
/** @type {Error & { span: EXPECTED_ANY; level: EXPECTED_ANY }} */ (
/** @type {Error & { span: EXPECTED_ANY, level: EXPECTED_ANY }} */ (
new Error(diagnostic.message)
);

Expand Down Expand Up @@ -199,7 +198,7 @@ async function swcMinifyFragment(input, minimizerOptions = {}) {
errors: result.errors
? result.errors.map((diagnostic) => {
const error =
/** @type {Error & { span: EXPECTED_ANY; level: EXPECTED_ANY }} */ (
/** @type {Error & { span: EXPECTED_ANY, level: EXPECTED_ANY }} */ (
new Error(diagnostic.message)
);

Expand Down
2 changes: 1 addition & 1 deletion test/__snapshots__/exclude-option.test.js.snap
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing

exports[`exclude option should match snapshot for a single RegExp value exclude: assets 1`] = `
{
Expand Down
2 changes: 1 addition & 1 deletion test/__snapshots__/include-option.test.js.snap
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing

exports[`include option should match snapshot for a single RegExp value include: assets 1`] = `
{
Expand Down
2 changes: 1 addition & 1 deletion test/__snapshots__/parallel-option.test.js.snap
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing

exports[`parallel option should match snapshot for the "2" value: assets 1`] = `
{
Expand Down
2 changes: 1 addition & 1 deletion test/__snapshots__/test-option.test.js.snap
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing

exports[`when applied with "test" option matches snapshot for a single "test" value (RegExp): assets 1`] = `
{
Expand Down
2 changes: 1 addition & 1 deletion test/__snapshots__/worker.test.js.snap
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing

exports[`worker should emit error: error 1`] = `
[
Expand Down
2 changes: 1 addition & 1 deletion test/helpers/getErrors.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import normalizeErrors from "./normalizeErrors";

export default (stats) => normalizeErrors(stats.compilation.errors).sort();
export default (stats) => normalizeErrors(stats.compilation.errors).toSorted();
3 changes: 2 additions & 1 deletion test/helpers/getWarnings.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import normalizeErrors from "./normalizeErrors";

export default (stats) => normalizeErrors(stats.compilation.warnings).sort();
export default (stats) =>
normalizeErrors(stats.compilation.warnings).toSorted();
4 changes: 2 additions & 2 deletions test/helpers/normalizeErrors.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ function removeCWD(str) {
}

/**
* @param {Array<Error>} errors The errors to normalize
* @returns {Array<string>} The normalized error messages
* @param {Error[]} errors The errors to normalize
* @returns {string[]} The normalized error messages
*/
export default (errors) =>
errors.map((error) =>
Expand Down
2 changes: 1 addition & 1 deletion test/parallel-option.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ describe("parallel option", () => {

const stats = await compile(compiler);

expect(Worker).toHaveBeenCalledTimes(0);
expect(Worker).not.toHaveBeenCalled();

expect(readAssets(compiler, stats, /\.html$/i)).toMatchSnapshot("assets");
expect(getErrors(stats)).toMatchSnapshot("errors");
Expand Down
18 changes: 9 additions & 9 deletions types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ declare class HtmlMinimizerPlugin<
* @param {Compiler} compiler The webpack compiler
* @param {Compilation} compilation The webpack compilation
* @param {Record<string, import("webpack").sources.Source>} assets The assets to optimize
* @param {{availableNumberOfCores: number}} optimizeOptions Optimization options
* @param {{ availableNumberOfCores: number }} optimizeOptions Optimization options
* @returns {Promise<void>} Promise that resolves when optimization is complete
*/
private optimize;
Expand Down Expand Up @@ -167,11 +167,11 @@ type MinimizedResultObj = {
/**
* Array of errors
*/
errors?: Array<Error | ErrorObject | string> | undefined;
errors?: (Error | ErrorObject | string)[] | undefined;
/**
* Array of warnings
*/
warnings?: Array<Warning | WarningObject | string> | undefined;
warnings?: (Warning | WarningObject | string)[] | undefined;
};
type MinimizedResult = MinimizedResultObj | string;
type Input = {
Expand All @@ -181,7 +181,7 @@ type CustomOptions = {
[key: string]: EXPECTED_ANY;
};
type InferDefaultType<T> = T extends infer U ? U : CustomOptions;
type MinimizerOptions<T> = T extends any[]
type MinimizerOptions<T> = T extends EXPECTED_ANY[]
? { [P in keyof T]?: InferDefaultType<T[P]> }
: InferDefaultType<T>;
type BasicMinimizerImplementation<T> = (
Expand All @@ -194,7 +194,7 @@ type MinimizeFunctionHelpers = {
*/
supportsWorkerThreads?: (() => boolean | undefined) | undefined;
};
type MinimizerImplementation<T> = T extends any[]
type MinimizerImplementation<T> = T extends EXPECTED_ANY[]
? {
[P in keyof T]: BasicMinimizerImplementation<T[P]> &
MinimizeFunctionHelpers;
Expand All @@ -221,17 +221,17 @@ type InternalResult = {
/**
* Array of output objects
*/
outputs: Array<{
outputs: {
code: string;
}>;
}[];
/**
* Array of warnings
*/
warnings: Array<Warning | WarningObject | string>;
warnings: (Warning | WarningObject | string)[];
/**
* Array of errors
*/
errors: Array<Error | ErrorObject | string>;
errors: (Error | ErrorObject | string)[];
};
type MinimizerWorker<T> = JestWorker & {
transform: (options: string) => Promise<InternalResult>;
Expand Down
2 changes: 1 addition & 1 deletion types/utils.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ export type Task<T> = () => Promise<T>;
export type MinimizedResult = import("./index.js").MinimizedResult;
export type CustomOptions = import("./index.js").CustomOptions;
export type Input = import("./index.js").Input;
export type EXPECTED_ANY = any;
export type EXPECTED_ANY = import("./index.js").EXPECTED_ANY;
/**
* @param {Input} input The input to minify
* @param {CustomOptions=} minimizerOptions The minimizer options
Expand Down
Loading