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
1 change: 1 addition & 0 deletions .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ jobs:
- name: Install dependencies (old)
run: |
npm install -D typescript@4 --force
npm install --ignore-scripts
if: matrix.node-version == '10.x' || matrix.node-version == '12.x' || matrix.node-version == '14.x' || matrix.node-version == '16.x' || matrix.node-version == '18.x'

- name: Install dependencies
Expand Down
39,920 changes: 11,196 additions & 28,724 deletions package-lock.json

Large diffs are not rendered by default.

13 changes: 1 addition & 12 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,6 @@
"@babel/preset-env": "^7.24.7",
"@commitlint/cli": "^17.7.1",
"@commitlint/config-conventional": "^17.7.0",
"@eslint/js": "^9.29.0",
"@eslint/markdown": "^7.1.0",
"@stylistic/eslint-plugin": "^5.2.2",
"@swc/core": "^1.3.102",
"@types/node": "^24.2.1",
"@types/serialize-javascript": "^5.0.2",
Expand All @@ -83,16 +80,9 @@
"cspell": "^6.31.2",
"del": "^6.0.0",
"del-cli": "^3.0.1",
"esbuild": "^0.25.0",
"esbuild": "^0.27.3",
"eslint": "^9.29.0",
"eslint-config-prettier": "^10.1.1",
"eslint-config-webpack": "^4.5.1",
"eslint-plugin-import": "^2.32.0",
"eslint-plugin-jest": "^29.0.1",
"eslint-plugin-jsdoc": "^54.0.0",
"eslint-plugin-n": "^17.21.0",
"eslint-plugin-prettier": "^5.5.0",
"eslint-plugin-unicorn": "^60.0.0",
"file-loader": "^6.2.0",
"husky": "^7.0.2",
"jest": "^27.5.1",
Expand All @@ -103,7 +93,6 @@
"prettier-2": "npm:prettier@^2",
"standard-version": "^9.3.1",
"typescript": "^5.9.2",
"typescript-eslint": "^8.39.1",
"uglify-js": "^3.19.3",
"webpack": "^5.101.0",
"webpack-cli": "^4.10.0",
Expand Down
39 changes: 20 additions & 19 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,28 +20,30 @@ const {
/** @typedef {import("webpack").Configuration} Configuration */
/** @typedef {import("webpack").Asset} Asset */
/** @typedef {import("webpack").AssetInfo} AssetInfo */
/** @typedef {import("webpack").TemplatePath} TemplatePath */
/** @typedef {import("jest-worker").Worker} JestWorker */
/** @typedef {import("@jridgewell/trace-mapping").EncodedSourceMap & { sources: string[], sourcesContent?: string[], file: string }} RawSourceMap */
/** @typedef {import("@jridgewell/trace-mapping").TraceMap} TraceMap */

/** @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 */

/**
* @callback ExtractCommentsFunction
* @param {any} astNode ast Node
* @param {{ value: string, type: 'comment1' | 'comment2' | 'comment3' | 'comment4', pos: number, line: number, col: number }} comment comment node
* @param {EXPECTED_ANY} astNode ast Node
* @param {{ value: string, type: "comment1" | "comment2" | "comment3" | "comment4", pos: number, line: number, col: number }} comment comment node
* @returns {boolean} true when need to extract comment, otherwise false
*/

/**
* @typedef {boolean | 'all' | 'some' | RegExp | ExtractCommentsFunction} ExtractCommentsCondition
* @typedef {boolean | "all" | "some" | RegExp | ExtractCommentsFunction} ExtractCommentsCondition
*/

// eslint-disable-next-line jsdoc/no-restricted-syntax
/**
* @typedef {string | ((fileData: any) => string)} ExtractCommentsFilename
* @typedef {TemplatePath} ExtractCommentsFilename
*/

/**
Expand Down Expand Up @@ -71,18 +73,17 @@ const {
* @typedef {object} MinimizedResult
* @property {string=} code code
* @property {RawSourceMap=} map source map
* @property {Array<Error | string>=} errors errors
* @property {Array<Error | string>=} warnings warnings
* @property {Array<string>=} extractedComments extracted comments
* @property {(Error | string)[]=} errors errors
* @property {(Error | string)[]=} warnings warnings
* @property {string[]=} extractedComments extracted comments
*/

/**
* @typedef {{ [file: string]: string }} Input
*/

// eslint-disable-next-line jsdoc/no-restricted-syntax
/**
* @typedef {{ [key: string]: any }} CustomOptions
* @typedef {{ [key: string]: EXPECTED_ANY }} CustomOptions
*/

/**
Expand Down Expand Up @@ -215,13 +216,13 @@ class TerserPlugin {
// https://github.com/jridgewell/trace-mapping#usage
return Boolean(
input &&
typeof input === "object" &&
input !== null &&
"version" in input &&
"sources" in input &&
Array.isArray(input.sources) &&
"mappings" in input &&
typeof input.mappings === "string",
typeof input === "object" &&
input !== null &&
"version" in input &&
"sources" in input &&
Array.isArray(input.sources) &&
"mappings" in input &&
typeof input.mappings === "string",
);
}

Expand Down Expand Up @@ -454,7 +455,7 @@ class TerserPlugin {
const { SourceMapSource, ConcatSource, RawSource } =
compiler.webpack.sources;

/** @typedef {{ extractedCommentsSource : import("webpack").sources.RawSource, commentsFilename: string }} ExtractedCommentsInfo */
/** @typedef {{ extractedCommentsSource: import("webpack").sources.RawSource, commentsFilename: string }} ExtractedCommentsInfo */
/** @type {Map<string, ExtractedCommentsInfo>} */
const allExtractedComments = new Map();
const scheduledTasks = [];
Expand Down
8 changes: 4 additions & 4 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
*/

/**
* @typedef {Array<string>} ExtractedComments
* @typedef {string[]} ExtractedComments
*/

const notSettled = Symbol("not-settled");
Expand Down Expand Up @@ -90,7 +90,7 @@ async function terserMinify(
};

/**
* @param {import("terser").MinifyOptions & { sourceMap: import("terser").SourceMapOptions | undefined } & ({ output: import("terser").FormatOptions & { beautify: boolean } } | { format: import("terser").FormatOptions & { beautify: boolean } })} terserOptions terser options
* @param {import("terser").MinifyOptions & { sourceMap: import("terser").SourceMapOptions | undefined } & ({ output: import("terser").FormatOptions & { beautify: boolean } } | { format: import("terser").FormatOptions & { beautify: boolean } })} terserOptions terser options
* @param {ExtractedComments} extractedComments extracted comments
* @returns {ExtractCommentsFunction} function to extract comments
*/
Expand Down Expand Up @@ -346,7 +346,7 @@ async function uglifyJsMinify(
};

/**
* @param {import("uglify-js").MinifyOptions & { sourceMap: boolean | import("uglify-js").SourceMapOptions | undefined } & { output: import("uglify-js").OutputOptions & { beautify: boolean }}} uglifyJsOptions uglify-js options
* @param {import("uglify-js").MinifyOptions & { sourceMap: boolean | import("uglify-js").SourceMapOptions | undefined } & { output: import("uglify-js").OutputOptions & { beautify: boolean } }} uglifyJsOptions uglify-js options
* @param {ExtractedComments} extractedComments extracted comments
* @returns {ExtractCommentsFunction} extract comments function
*/
Expand Down Expand Up @@ -455,7 +455,7 @@ async function uglifyJsMinify(

/**
* @param {PredefinedOptions<import("uglify-js").MinifyOptions> & import("uglify-js").MinifyOptions=} uglifyJsOptions uglify-js options
* @returns {import("uglify-js").MinifyOptions & { sourceMap: boolean | import("uglify-js").SourceMapOptions | undefined } & { output: import("uglify-js").OutputOptions & { beautify: boolean }}} uglify-js options
* @returns {import("uglify-js").MinifyOptions & { sourceMap: boolean | import("uglify-js").SourceMapOptions | undefined } & { output: import("uglify-js").OutputOptions & { beautify: boolean } }} uglify-js options
*/
const buildUglifyJsOptions = (uglifyJsOptions = {}) => {
if (typeof uglifyJsOptions.ecma !== "undefined") {
Expand Down
Loading
Loading