Feat: Multiplayer sessions added using CRUD database.

This commit is contained in:
2026-02-10 11:49:38 +00:00
parent bbbd21d4ad
commit fa81fddbd4
6850 changed files with 808827 additions and 8 deletions

20
node_modules/terser-webpack-plugin/LICENSE generated vendored Normal file
View File

@@ -0,0 +1,20 @@
Copyright JS Foundation and other contributors
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
'Software'), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

934
node_modules/terser-webpack-plugin/README.md generated vendored Normal file
View File

@@ -0,0 +1,934 @@
<div align="center">
<a href="https://github.com/webpack/webpack">
<img width="200" height="200" src="https://webpack.js.org/assets/icon-square-big.svg">
</a>
</div>
[![npm][npm]][npm-url]
[![node][node]][node-url]
[![tests][tests]][tests-url]
[![cover][cover]][cover-url]
[![discussion][discussion]][discussion-url]
[![size][size]][size-url]
# terser-webpack-plugin
This plugin uses [terser](https://github.com/terser/terser) to minify/minimize your JavaScript.
## Getting Started
Webpack v5 comes with the latest `terser-webpack-plugin` out of the box.
If you are using Webpack v5 or above and wish to customize the options, you will still need to install `terser-webpack-plugin`.
Using Webpack v4, you have to install `terser-webpack-plugin` v4.
To begin, you'll need to install `terser-webpack-plugin`:
```console
npm install terser-webpack-plugin --save-dev
```
or
```console
yarn add -D terser-webpack-plugin
```
or
```console
pnpm add -D terser-webpack-plugin
```
Then add the plugin to your `webpack` configuration. For example:
**webpack.config.js**
```js
const TerserPlugin = require("terser-webpack-plugin");
module.exports = {
optimization: {
minimize: true,
minimizer: [new TerserPlugin()],
},
};
```
Finally, run `webpack` using the method you normally use (e.g., via CLI or an npm script).
## Note about source maps
**Works only with `source-map`, `inline-source-map`, `hidden-source-map` and `nosources-source-map` values for the [`devtool`](https://webpack.js.org/configuration/devtool/) option.**
Why?
- `eval` wraps modules in `eval("string")` and the minimizer does not handle strings.
- `cheap` has no column information and the minimizer generates only a single line, which leaves only a single mapping.
Using supported `devtool` values enable source map generation.
## Options
- **[`test`](#test)**
- **[`include`](#include)**
- **[`exclude`](#exclude)**
- **[`parallel`](#parallel)**
- **[`minify`](#minify)**
- **[`terserOptions`](#terseroptions)**
- **[`extractComments`](#extractcomments)**
### `test`
Type:
```ts
type test = string | RegExp | (string | RegExp)[];
```
Default: `/\.m?js(\?.*)?$/i`
Test to match files against.
**webpack.config.js**
```js
module.exports = {
optimization: {
minimize: true,
minimizer: [
new TerserPlugin({
test: /\.js(\?.*)?$/i,
}),
],
},
};
```
### `include`
Type:
```ts
type include = string | RegExp | (string | RegExp)[];
```
Default: `undefined`
Files to include.
**webpack.config.js**
```js
module.exports = {
optimization: {
minimize: true,
minimizer: [
new TerserPlugin({
include: /\/includes/,
}),
],
},
};
```
### `exclude`
Type:
```ts
type exclude = string | RegExp | (string | RegExp)[];
```
Default: `undefined`
Files to exclude.
**webpack.config.js**
```js
module.exports = {
optimization: {
minimize: true,
minimizer: [
new TerserPlugin({
exclude: /\/excludes/,
}),
],
},
};
```
### `parallel`
Type:
```ts
type parallel = boolean | number;
```
Default: `true`
Use multi-process parallel running to improve the build speed.
Default number of concurrent runs: `os.cpus().length - 1` or `os.availableParallelism() - 1` (if this function is supported).
> **Note**
>
> Parallelization can speedup your build significantly and is therefore **highly recommended**.
> **Warning**
>
> If you use **Circle CI** or any other environment that doesn't provide the real available count of CPUs then you need to explicitly set up the number of CPUs to avoid `Error: Call retries were exceeded` (see [#143](https://github.com/webpack/terser-webpack-plugin/issues/143), [#202](https://github.com/webpack/terser-webpack-plugin/issues/202)).
#### `boolean`
Enable/disable multi-process parallel running.
**webpack.config.js**
```js
module.exports = {
optimization: {
minimize: true,
minimizer: [
new TerserPlugin({
parallel: true,
}),
],
},
};
```
#### `number`
Enable multi-process parallel running and set number of concurrent runs.
**webpack.config.js**
```js
module.exports = {
optimization: {
minimize: true,
minimizer: [
new TerserPlugin({
parallel: 4,
}),
],
},
};
```
### `minify`
Type:
```ts
type minify = (
input: Record<string, string>,
sourceMap: import("@jridgewell/trace-mapping").SourceMapInput | undefined,
minifyOptions: {
module?: boolean | undefined;
ecma?: import("terser").ECMA | undefined;
},
extractComments:
| boolean
| "all"
| "some"
| RegExp
| ((
astNode: any,
comment: {
value: string;
type: "comment1" | "comment2" | "comment3" | "comment4";
pos: number;
line: number;
col: number;
},
) => boolean)
| {
condition?:
| boolean
| "all"
| "some"
| RegExp
| ((
astNode: any,
comment: {
value: string;
type: "comment1" | "comment2" | "comment3" | "comment4";
pos: number;
line: number;
col: number;
},
) => boolean)
| undefined;
filename?: string | ((fileData: any) => string) | undefined;
banner?:
| string
| boolean
| ((commentsFile: string) => string)
| undefined;
}
| undefined,
) => Promise<{
code: string;
map?: import("@jridgewell/trace-mapping").SourceMapInput | undefined;
errors?: (string | Error)[] | undefined;
warnings?: (string | Error)[] | undefined;
extractedComments?: string[] | undefined;
}>;
```
Default: `TerserPlugin.terserMinify`
Allows you to override the default minify function.
By default plugin uses [terser](https://github.com/terser/terser) package.
Useful for using and testing unpublished versions or forks.
> **Warning**
>
> **Always use `require` inside `minify` function when `parallel` option enabled**.
**webpack.config.js**
```js
// Can be async
const minify = (input, sourceMap, minimizerOptions, extractsComments) => {
// The `minimizerOptions` option contains option from the `terserOptions` option
// You can use `minimizerOptions.myCustomOption`
// Custom logic for extract comments
const { map, code } = require("uglify-module") // Or require('./path/to/uglify-module')
.minify(input, {
/* Your options for minification */
});
return { map, code, warnings: [], errors: [], extractedComments: [] };
};
// Used to regenerate `fullhash`/`chunkhash` between different implementation
// Example: you fix a bug in custom minimizer/custom function, but unfortunately webpack doesn't know about it, so you will get the same fullhash/chunkhash
// to avoid this you can provide version of your custom minimizer
// You don't need if you use only `contenthash`
minify.getMinimizerVersion = () => {
let packageJson;
try {
packageJson = require("uglify-module/package.json");
} catch (error) {
// Ignore
}
return packageJson && packageJson.version;
};
module.exports = {
optimization: {
minimize: true,
minimizer: [
new TerserPlugin({
terserOptions: {
myCustomOption: true,
},
minify,
}),
],
},
};
```
### `terserOptions`
Type:
```ts
interface terserOptions {
compress?: boolean | CompressOptions;
ecma?: ECMA;
enclose?: boolean | string;
ie8?: boolean;
keep_classnames?: boolean | RegExp;
keep_fnames?: boolean | RegExp;
mangle?: boolean | MangleOptions;
module?: boolean;
nameCache?: object;
format?: FormatOptions;
/** @deprecated */
output?: FormatOptions;
parse?: ParseOptions;
safari10?: boolean;
sourceMap?: boolean | SourceMapOptions;
toplevel?: boolean;
}
```
Default: [default](https://github.com/terser/terser#minify-options)
Terser [options](https://github.com/terser/terser#minify-options).
**webpack.config.js**
```js
module.exports = {
optimization: {
minimize: true,
minimizer: [
new TerserPlugin({
terserOptions: {
ecma: undefined,
parse: {},
compress: {},
mangle: true, // Note `mangle.properties` is `false` by default.
module: false,
// Deprecated
output: null,
format: null,
toplevel: false,
nameCache: null,
ie8: false,
keep_classnames: undefined,
keep_fnames: false,
safari10: false,
},
}),
],
},
};
```
### `extractComments`
Type:
```ts
type extractComments =
| boolean
| string
| RegExp
| ((
astNode: any,
comment: {
value: string;
type: "comment1" | "comment2" | "comment3" | "comment4";
pos: number;
line: number;
col: number;
},
) => boolean)
| {
condition?:
| boolean
| "all"
| "some"
| RegExp
| ((
astNode: any,
comment: {
value: string;
type: "comment1" | "comment2" | "comment3" | "comment4";
pos: number;
line: number;
col: number;
},
) => boolean)
| undefined;
filename?: string | ((fileData: any) => string) | undefined;
banner?:
| string
| boolean
| ((commentsFile: string) => string)
| undefined;
};
```
Default: `true`
Whether comments shall be extracted to a separate file, (see [details](https://github.com/webpack/webpack/commit/71933e979e51c533b432658d5e37917f9e71595a)).
By default, extract only comments using `/^\**!|@preserve|@license|@cc_on/i` RegExp condition and remove remaining comments.
If the original file is named `foo.js`, then the comments will be stored to `foo.js.LICENSE.txt`.
The `terserOptions.format.comments` option specifies whether the comment will be preserved - i.e., it is possible to preserve some comments (e.g. annotations) while extracting others, or even preserve comments that have already been extracted.
#### `boolean`
Enable/disable extracting comments.
**webpack.config.js**
```js
module.exports = {
optimization: {
minimize: true,
minimizer: [
new TerserPlugin({
extractComments: true,
}),
],
},
};
```
#### `string`
Extract `all` or `some` (use the `/^\**!|@preserve|@license|@cc_on/i` RegExp) comments.
**webpack.config.js**
```js
module.exports = {
optimization: {
minimize: true,
minimizer: [
new TerserPlugin({
extractComments: "all",
}),
],
},
};
```
#### `RegExp`
All comments that match the given expression will be extracted to a separate file.
**webpack.config.js**
```js
module.exports = {
optimization: {
minimize: true,
minimizer: [
new TerserPlugin({
extractComments: /@extract/i,
}),
],
},
};
```
#### `function`
All comments that match the given expression will be extracted to a separate file.
**webpack.config.js**
```js
module.exports = {
optimization: {
minimize: true,
minimizer: [
new TerserPlugin({
extractComments: (astNode, comment) => {
if (/@extract/i.test(comment.value)) {
return true;
}
return false;
},
}),
],
},
};
```
#### `object`
Allows you to customize condition for extracting comments, and specify the extracted file name and banner.
**webpack.config.js**
```js
module.exports = {
optimization: {
minimize: true,
minimizer: [
new TerserPlugin({
extractComments: {
condition: /^\**!|@preserve|@license|@cc_on/i,
filename: (fileData) =>
// The "fileData" argument contains object with "filename", "basename", "query" and "hash"
`${fileData.filename}.LICENSE.txt${fileData.query}`,
banner: (licenseFile) =>
`License information can be found in ${licenseFile}`,
},
}),
],
},
};
```
##### `condition`
Type:
```ts
type condition =
| boolean
| "all"
| "some"
| RegExp
| ((
astNode: any,
comment: {
value: string;
type: "comment1" | "comment2" | "comment3" | "comment4";
pos: number;
line: number;
col: number;
},
) => boolean)
| undefined;
```
The condition that determines which comments should be extracted.
**webpack.config.js**
```js
module.exports = {
optimization: {
minimize: true,
minimizer: [
new TerserPlugin({
extractComments: {
condition: "some",
filename: (fileData) =>
// The "fileData" argument contains object with "filename", "basename", "query" and "hash"
`${fileData.filename}.LICENSE.txt${fileData.query}`,
banner: (licenseFile) =>
`License information can be found in ${licenseFile}`,
},
}),
],
},
};
```
##### `filename`
Type:
```ts
type filename = string | ((fileData: any) => string) | undefined;
```
Default: `[file].LICENSE.txt[query]`
Available placeholders: `[file]`, `[query]` and `[filebase]` (`[base]` for webpack 5).
The file where the extracted comments will be stored.
Default is to append the suffix `.LICENSE.txt` to the original filename.
> **Warning**
>
> We highly recommend using the `.txt` extension. Using `.js`/`.cjs`/`.mjs` extensions may conflict with existing assets, which leads to broken code.
**webpack.config.js**
```js
module.exports = {
optimization: {
minimize: true,
minimizer: [
new TerserPlugin({
extractComments: {
condition: /^\**!|@preserve|@license|@cc_on/i,
filename: "extracted-comments.js",
banner: (licenseFile) =>
`License information can be found in ${licenseFile}`,
},
}),
],
},
};
```
##### `banner`
Type:
```ts
type banner = string | boolean | ((commentsFile: string) => string) | undefined;
```
Default: `/*! For license information please see ${commentsFile} */`
The banner text that points to the extracted file and will be added at the top of the original file.
It can be `false` (no banner), a `String`, or a `function<(string) -> String>` that will be called with the filename where the extracted comments have been stored.
The banner will be wrapped in a comment.
**webpack.config.js**
```js
module.exports = {
optimization: {
minimize: true,
minimizer: [
new TerserPlugin({
extractComments: {
condition: true,
filename: (fileData) =>
// The "fileData" argument contains object with "filename", "basename", "query" and "hash"
`${fileData.filename}.LICENSE.txt${fileData.query}`,
banner: (commentsFile) =>
`My custom banner about license information ${commentsFile}`,
},
}),
],
},
};
```
## Examples
### Preserve Comments
Extract all legal comments (i.e. `/^\**!|@preserve|@license|@cc_on/i`) and preserve `/@license/i` comments.
**webpack.config.js**
```js
module.exports = {
optimization: {
minimize: true,
minimizer: [
new TerserPlugin({
terserOptions: {
format: {
comments: /@license/i,
},
},
extractComments: true,
}),
],
},
};
```
### Remove Comments
If you want to build without comments, use this config:
**webpack.config.js**
```js
module.exports = {
optimization: {
minimize: true,
minimizer: [
new TerserPlugin({
terserOptions: {
format: {
comments: false,
},
},
extractComments: false,
}),
],
},
};
```
### [`uglify-js`](https://github.com/mishoo/UglifyJS)
[`UglifyJS`](https://github.com/mishoo/UglifyJS) is a JavaScript parser, minifier, compressor and beautifier toolkit.
**webpack.config.js**
```js
module.exports = {
optimization: {
minimize: true,
minimizer: [
new TerserPlugin({
minify: TerserPlugin.uglifyJsMinify,
// `terserOptions` options will be passed to `uglify-js`
// Link to options - https://github.com/mishoo/UglifyJS#minify-options
terserOptions: {},
}),
],
},
};
```
### [`swc`](https://github.com/swc-project/swc)
[`swc`](https://github.com/swc-project/swc) is a super-fast compiler written in `Rust`, producing widely supported JavaScript from modern standards and TypeScript.
> **Warning**
>
> The `extractComments` option is not supported, and all comments will be removed by default. This will be fixed in future
**webpack.config.js**
```js
module.exports = {
optimization: {
minimize: true,
minimizer: [
new TerserPlugin({
minify: TerserPlugin.swcMinify,
// `terserOptions` options will be passed to `swc` (`@swc/core`)
// Link to options - https://swc.rs/docs/config-js-minify
terserOptions: {},
}),
],
},
};
```
### [`esbuild`](https://github.com/evanw/esbuild)
[`esbuild`](https://github.com/evanw/esbuild) is an extremely fast JavaScript bundler and minifier.
> **Warning**
>
> The `extractComments` option is not supported, and all legal comments (i.e. copyright, licenses and etc) will be preserved.
**webpack.config.js**
```js
module.exports = {
optimization: {
minimize: true,
minimizer: [
new TerserPlugin({
minify: TerserPlugin.esbuildMinify,
// `terserOptions` options will be passed to `esbuild`
// Link to options - https://esbuild.github.io/api/#minify
// Note: the `minify` options is true by default (and override other `minify*` options), so if you want to disable the `minifyIdentifiers` option (or other `minify*` options) please use:
// terserOptions: {
// minify: false,
// minifyWhitespace: true,
// minifyIdentifiers: false,
// minifySyntax: true,
// },
terserOptions: {},
}),
],
},
};
```
### Custom Minify Function
Override the default minify function - use `uglify-js` for minification.
**webpack.config.js**
```js
module.exports = {
optimization: {
minimize: true,
minimizer: [
new TerserPlugin({
minify: (file, sourceMap) => {
// https://github.com/mishoo/UglifyJS2#minify-options
const uglifyJsOptions = {
/* your `uglify-js` package options */
};
if (sourceMap) {
uglifyJsOptions.sourceMap = {
content: sourceMap,
};
}
return require("uglify-js").minify(file, uglifyJsOptions);
},
}),
],
},
};
```
### Typescript
With default Terser minify function:
```ts
module.exports = {
optimization: {
minimize: true,
minimizer: [
new TerserPlugin({
terserOptions: {
compress: true,
},
}),
],
},
};
```
With built-in minify functions:
```ts
import { type JsMinifyOptions as SwcOptions } from "@swc/core";
import { type TransformOptions as EsbuildOptions } from "esbuild";
import { type MinifyOptions as TerserOptions } from "terser";
import { type MinifyOptions as UglifyJSOptions } from "uglify-js";
module.exports = {
optimization: {
minimize: true,
minimizer: [
new TerserPlugin<SwcOptions>({
minify: TerserPlugin.swcMinify,
terserOptions: {
// `swc` options
},
}),
new TerserPlugin<UglifyJSOptions>({
minify: TerserPlugin.uglifyJsMinify,
terserOptions: {
// `uglif-js` options
},
}),
new TerserPlugin<EsbuildOptions>({
minify: TerserPlugin.esbuildMinify,
terserOptions: {
// `esbuild` options
},
}),
// Alternative usage:
new TerserPlugin<TerserOptions>({
minify: TerserPlugin.terserMinify,
terserOptions: {
// `terser` options
},
}),
],
},
};
```
## Contributing
We welcome all contributions!
If you're new here, please take a moment to review our contributing guidelines before submitting issues or pull requests.
[CONTRIBUTING](https://github.com/webpack/terser-webpack-plugin?tab=contributing-ov-file#contributing)
## License
[MIT](./LICENSE)
[npm]: https://img.shields.io/npm/v/terser-webpack-plugin.svg
[npm-url]: https://npmjs.com/package/terser-webpack-plugin
[node]: https://img.shields.io/node/v/terser-webpack-plugin.svg
[node-url]: https://nodejs.org
[tests]: https://github.com/webpack/terser-webpack-plugin/workflows/terser-webpack-plugin/badge.svg
[tests-url]: https://github.com/webpack/terser-webpack-plugin/actions
[cover]: https://codecov.io/gh/webpack/terser-webpack-plugin/branch/main/graph/badge.svg
[cover-url]: https://codecov.io/gh/webpack/terser-webpack-plugin
[discussion]: https://img.shields.io/github/discussions/webpack/webpack
[discussion-url]: https://github.com/webpack/webpack/discussions
[size]: https://packagephobia.now.sh/badge?p=terser-webpack-plugin
[size-url]: https://packagephobia.now.sh/result?p=terser-webpack-plugin

706
node_modules/terser-webpack-plugin/dist/index.js generated vendored Normal file
View File

@@ -0,0 +1,706 @@
"use strict";
const os = require("os");
const path = require("path");
const {
validate
} = require("schema-utils");
const {
minify
} = require("./minify");
const schema = require("./options.json");
const {
esbuildMinify,
memoize,
swcMinify,
terserMinify,
throttleAll,
uglifyJsMinify
} = require("./utils");
/** @typedef {import("schema-utils/declarations/validate").Schema} Schema */
/** @typedef {import("webpack").Compiler} Compiler */
/** @typedef {import("webpack").Compilation} Compilation */
/** @typedef {import("webpack").Configuration} Configuration */
/** @typedef {import("webpack").Asset} Asset */
/** @typedef {import("webpack").AssetInfo} AssetInfo */
/** @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
/**
* @callback ExtractCommentsFunction
* @param {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
*/
// eslint-disable-next-line jsdoc/no-restricted-syntax
/**
* @typedef {string | ((fileData: any) => string)} ExtractCommentsFilename
*/
/**
* @typedef {boolean | string | ((commentsFile: string) => string)} ExtractCommentsBanner
*/
/**
* @typedef {object} ExtractCommentsObject
* @property {ExtractCommentsCondition=} condition condition which comments need to be expected
* @property {ExtractCommentsFilename=} filename filename for extracted comments
* @property {ExtractCommentsBanner=} banner banner in filename for extracted comments
*/
/**
* @typedef {ExtractCommentsCondition | ExtractCommentsObject} ExtractCommentsOptions
*/
/**
* @typedef {object} ErrorObject
* @property {string} message message
* @property {number=} line line number
* @property {number=} column column number
* @property {string=} stack error stack trace
*/
/**
* @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
*/
/**
* @typedef {{ [file: string]: string }} Input
*/
// eslint-disable-next-line jsdoc/no-restricted-syntax
/**
* @typedef {{ [key: string]: any }} CustomOptions
*/
/**
* @template T
* @typedef {T extends infer U ? U : CustomOptions} InferDefaultType
*/
/**
* @template T
* @typedef {object} PredefinedOptions
* @property {T extends { module?: infer P } ? P : boolean | string=} module true when code is a EC module, otherwise false
* @property {T extends { ecma?: infer P } ? P : number | string=} ecma ecma version
*/
/**
* @template T
* @typedef {PredefinedOptions<T> & InferDefaultType<T>} MinimizerOptions
*/
/**
* @template T
* @callback BasicMinimizerImplementation
* @param {Input} input
* @param {RawSourceMap | undefined} sourceMap
* @param {MinimizerOptions<T>} minifyOptions
* @param {ExtractCommentsOptions | undefined} extractComments
* @returns {Promise<MinimizedResult> | MinimizedResult}
*/
/**
* @typedef {object} MinimizeFunctionHelpers
* @property {() => string | undefined=} getMinimizerVersion function that returns version of minimizer
* @property {() => boolean | undefined=} supportsWorkerThreads true when minimizer support worker threads, otherwise false
*/
/**
* @template T
* @typedef {BasicMinimizerImplementation<T> & MinimizeFunctionHelpers} MinimizerImplementation
*/
/**
* @template T
* @typedef {object} InternalOptions
* @property {string} name name
* @property {string} input input
* @property {RawSourceMap | undefined} inputSourceMap input source map
* @property {ExtractCommentsOptions | undefined} extractComments extract comments option
* @property {{ implementation: MinimizerImplementation<T>, options: MinimizerOptions<T> }} minimizer minimizer
*/
/**
* @template T
* @typedef {JestWorker & { transform: (options: string) => Promise<MinimizedResult>, minify: (options: InternalOptions<T>) => Promise<MinimizedResult> }} MinimizerWorker
*/
/**
* @typedef {undefined | boolean | number} Parallel
*/
/**
* @typedef {object} BasePluginOptions
* @property {Rules=} test test rule
* @property {Rules=} include include rile
* @property {Rules=} exclude exclude rule
* @property {ExtractCommentsOptions=} extractComments extract comments options
* @property {Parallel=} parallel parallel option
*/
/**
* @template T
* @typedef {T extends import("terser").MinifyOptions ? { minify?: MinimizerImplementation<T> | undefined, terserOptions?: MinimizerOptions<T> | undefined } : { minify: MinimizerImplementation<T>, terserOptions?: MinimizerOptions<T> | undefined }} DefinedDefaultMinimizerAndOptions
*/
/**
* @template T
* @typedef {BasePluginOptions & { minimizer: { implementation: MinimizerImplementation<T>, options: MinimizerOptions<T> } }} InternalPluginOptions
*/
const getTraceMapping = memoize(() => require("@jridgewell/trace-mapping"));
const getSerializeJavascript = memoize(() => require("serialize-javascript"));
/**
* @template [T=import("terser").MinifyOptions]
*/
class TerserPlugin {
/**
* @param {BasePluginOptions & DefinedDefaultMinimizerAndOptions<T>=} options options
*/
constructor(options) {
validate( /** @type {Schema} */schema, options || {}, {
name: "Terser Plugin",
baseDataPath: "options"
});
// TODO make `minimizer` option instead `minify` and `terserOptions` in the next major release, also rename `terserMinify` to `terserMinimize`
const {
minify = ( /** @type {MinimizerImplementation<T>} */terserMinify),
terserOptions = ( /** @type {MinimizerOptions<T>} */{}),
test = /\.[cm]?js(\?.*)?$/i,
extractComments = true,
parallel = true,
include,
exclude
} = options || {};
/**
* @private
* @type {InternalPluginOptions<T>}
*/
this.options = {
test,
extractComments,
parallel,
include,
exclude,
minimizer: {
implementation: minify,
options: terserOptions
}
};
}
/**
* @private
* @param {unknown} input Input to check
* @returns {boolean} Whether input is a source map
*/
static isSourceMap(input) {
// All required options for `new TraceMap(...options)`
// 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");
}
/**
* @private
* @param {unknown} warning warning
* @param {string} file file
* @returns {Error} built warning
*/
static buildWarning(warning, file) {
/**
* @type {Error & { hideStack: true, file: string }}
*/
// @ts-expect-error
const builtWarning = new Error(warning.toString());
builtWarning.name = "Warning";
builtWarning.hideStack = true;
builtWarning.file = file;
return builtWarning;
}
/**
* @private
* @param {Error | ErrorObject | string} error error
* @param {string} file file
* @param {TraceMap=} sourceMap source map
* @param {Compilation["requestShortener"]=} requestShortener request shortener
* @returns {Error} built error
*/
static buildError(error, file, sourceMap, requestShortener) {
/**
* @type {Error & { file?: string }}
*/
let builtError;
if (typeof error === "string") {
builtError = new Error(`${file} from Terser plugin\n${error}`);
builtError.file = file;
return builtError;
}
if ( /** @type {ErrorObject} */error.line) {
const {
line,
column
} = /** @type {ErrorObject & { line: number, column: number }} */error;
const original = sourceMap && getTraceMapping().originalPositionFor(sourceMap, {
line,
column
});
if (original && original.source && requestShortener) {
builtError = new Error(`${file} from Terser plugin\n${error.message} [${requestShortener.shorten(original.source)}:${original.line},${original.column}][${file}:${line},${column}]${error.stack ? `\n${error.stack.split("\n").slice(1).join("\n")}` : ""}`);
builtError.file = file;
return builtError;
}
builtError = new Error(`${file} from Terser plugin\n${error.message} [${file}:${line},${column}]${error.stack ? `\n${error.stack.split("\n").slice(1).join("\n")}` : ""}`);
builtError.file = file;
return builtError;
}
if (error.stack) {
builtError = new Error(`${file} from Terser plugin\n${typeof error.message !== "undefined" ? error.message : ""}\n${error.stack}`);
builtError.file = file;
return builtError;
}
builtError = new Error(`${file} from Terser plugin\n${error.message}`);
builtError.file = file;
return builtError;
}
/**
* @private
* @param {Parallel} parallel value of the `parallel` option
* @returns {number} number of cores for parallelism
*/
static getAvailableNumberOfCores(parallel) {
// In some cases cpus() returns undefined
// https://github.com/nodejs/node/issues/19022
const cpus =
// eslint-disable-next-line n/no-unsupported-features/node-builtins
typeof os.availableParallelism === "function" ?
// eslint-disable-next-line n/no-unsupported-features/node-builtins
{
length: os.availableParallelism()
} : os.cpus() || {
length: 1
};
return parallel === true || typeof parallel === "undefined" ? cpus.length - 1 : Math.min(parallel || 0, cpus.length - 1);
}
/**
* @private
* @param {Compiler} compiler compiler
* @param {Compilation} compilation compilation
* @param {Record<string, import("webpack").sources.Source>} assets assets
* @param {{ availableNumberOfCores: number }} optimizeOptions optimize options
* @returns {Promise<void>}
*/
async optimize(compiler, compilation, assets, optimizeOptions) {
const cache = compilation.getCache("TerserWebpackPlugin");
let numberOfAssets = 0;
const assetsForMinify = await Promise.all(Object.keys(assets).filter(name => {
const {
info
} = /** @type {Asset} */compilation.getAsset(name);
if (
// Skip double minimize assets from child compilation
info.minimized ||
// Skip minimizing for extracted comments assets
info.extractedComments) {
return false;
}
if (!compiler.webpack.ModuleFilenameHelpers.matchObject.bind(undefined, this.options)(name)) {
return false;
}
return true;
}).map(async name => {
const {
info,
source
} = /** @type {Asset} */
compilation.getAsset(name);
const eTag = cache.getLazyHashedEtag(source);
const cacheItem = cache.getItemCache(name, eTag);
const output = await cacheItem.getPromise();
if (!output) {
numberOfAssets += 1;
}
return {
name,
info,
inputSource: source,
output,
cacheItem
};
}));
if (assetsForMinify.length === 0) {
return;
}
/** @type {undefined | (() => MinimizerWorker<T>)} */
let getWorker;
/** @type {undefined | MinimizerWorker<T>} */
let initializedWorker;
/** @type {undefined | number} */
let numberOfWorkers;
if (optimizeOptions.availableNumberOfCores > 0) {
// Do not create unnecessary workers when the number of files is less than the available cores, it saves memory
numberOfWorkers = Math.min(numberOfAssets, optimizeOptions.availableNumberOfCores);
getWorker = () => {
if (initializedWorker) {
return initializedWorker;
}
const {
Worker
} = require("jest-worker");
initializedWorker = /** @type {MinimizerWorker<T>} */
new Worker(require.resolve("./minify"), {
numWorkers: numberOfWorkers,
enableWorkerThreads: typeof this.options.minimizer.implementation.supportsWorkerThreads !== "undefined" ? this.options.minimizer.implementation.supportsWorkerThreads() !== false : true
});
// https://github.com/facebook/jest/issues/8872#issuecomment-524822081
const workerStdout = initializedWorker.getStdout();
if (workerStdout) {
workerStdout.on("data", chunk => process.stdout.write(chunk));
}
const workerStderr = initializedWorker.getStderr();
if (workerStderr) {
workerStderr.on("data", chunk => process.stderr.write(chunk));
}
return initializedWorker;
};
}
const {
SourceMapSource,
ConcatSource,
RawSource
} = compiler.webpack.sources;
/** @typedef {{ extractedCommentsSource : import("webpack").sources.RawSource, commentsFilename: string }} ExtractedCommentsInfo */
/** @type {Map<string, ExtractedCommentsInfo>} */
const allExtractedComments = new Map();
const scheduledTasks = [];
for (const asset of assetsForMinify) {
scheduledTasks.push(async () => {
const {
name,
inputSource,
info,
cacheItem
} = asset;
let {
output
} = asset;
if (!output) {
let input;
/** @type {RawSourceMap | undefined} */
let inputSourceMap;
const {
source: sourceFromInputSource,
map
} = inputSource.sourceAndMap();
input = sourceFromInputSource;
if (map) {
if (!TerserPlugin.isSourceMap(map)) {
compilation.warnings.push(new Error(`${name} contains invalid source map`));
} else {
inputSourceMap = /** @type {RawSourceMap} */map;
}
}
if (Buffer.isBuffer(input)) {
input = input.toString();
}
/**
* @type {InternalOptions<T>}
*/
const options = {
name,
input,
inputSourceMap,
minimizer: {
implementation: this.options.minimizer.implementation,
options: {
...this.options.minimizer.options
}
},
extractComments: this.options.extractComments
};
if (typeof options.minimizer.options.module === "undefined") {
if (typeof info.javascriptModule !== "undefined") {
options.minimizer.options.module = /** @type {PredefinedOptions<T>["module"]} */
info.javascriptModule;
} else if (/\.mjs(\?.*)?$/i.test(name)) {
options.minimizer.options.module = /** @type {PredefinedOptions<T>["module"]} */true;
} else if (/\.cjs(\?.*)?$/i.test(name)) {
options.minimizer.options.module = /** @type {PredefinedOptions<T>["module"]} */false;
}
}
if (typeof options.minimizer.options.ecma === "undefined") {
options.minimizer.options.ecma = /** @type {PredefinedOptions<T>["ecma"]} */
TerserPlugin.getEcmaVersion(compiler.options.output.environment || {});
}
try {
output = await (getWorker ? getWorker().transform(getSerializeJavascript()(options)) : minify(options));
} catch (error) {
const hasSourceMap = inputSourceMap && TerserPlugin.isSourceMap(inputSourceMap);
compilation.errors.push(TerserPlugin.buildError( /** @type {Error | ErrorObject | string} */
error, name, hasSourceMap ? new (getTraceMapping().TraceMap)( /** @type {RawSourceMap} */
inputSourceMap) : undefined, hasSourceMap ? compilation.requestShortener : undefined));
return;
}
if (typeof output.code === "undefined") {
compilation.errors.push(new Error(`${name} from Terser plugin\nMinimizer doesn't return result`));
}
if (output.warnings && output.warnings.length > 0) {
output.warnings = output.warnings.map(
/**
* @param {Error | string} item a warning
* @returns {Error} built warning with extra info
*/
item => TerserPlugin.buildWarning(item, name));
}
if (output.errors && output.errors.length > 0) {
const hasSourceMap = inputSourceMap && TerserPlugin.isSourceMap(inputSourceMap);
output.errors = output.errors.map(
/**
* @param {Error | string} item an error
* @returns {Error} built error with extra info
*/
item => TerserPlugin.buildError(item, name, hasSourceMap ? new (getTraceMapping().TraceMap)( /** @type {RawSourceMap} */
inputSourceMap) : undefined, hasSourceMap ? compilation.requestShortener : undefined));
}
// Custom functions can return `undefined` or `null`
if (typeof output.code !== "undefined" && output.code !== null) {
let shebang;
if ( /** @type {ExtractCommentsObject} */
this.options.extractComments.banner !== false && output.extractedComments && output.extractedComments.length > 0 && output.code.startsWith("#!")) {
const firstNewlinePosition = output.code.indexOf("\n");
shebang = output.code.slice(0, Math.max(0, firstNewlinePosition));
output.code = output.code.slice(Math.max(0, firstNewlinePosition + 1));
}
if (output.map) {
output.source = new SourceMapSource(output.code, name, output.map, input, /** @type {RawSourceMap} */
inputSourceMap, true);
} else {
output.source = new RawSource(output.code);
}
if (output.extractedComments && output.extractedComments.length > 0) {
const commentsFilename = /** @type {ExtractCommentsObject} */
this.options.extractComments.filename || "[file].LICENSE.txt[query]";
let query = "";
let filename = name;
const querySplit = filename.indexOf("?");
if (querySplit >= 0) {
query = filename.slice(querySplit);
filename = filename.slice(0, querySplit);
}
const lastSlashIndex = filename.lastIndexOf("/");
const basename = lastSlashIndex === -1 ? filename : filename.slice(lastSlashIndex + 1);
const data = {
filename,
basename,
query
};
output.commentsFilename = compilation.getPath(commentsFilename, data);
let banner;
// Add a banner to the original file
if ( /** @type {ExtractCommentsObject} */
this.options.extractComments.banner !== false) {
banner = /** @type {ExtractCommentsObject} */
this.options.extractComments.banner || `For license information please see ${path.relative(path.dirname(name), output.commentsFilename).replace(/\\/g, "/")}`;
if (typeof banner === "function") {
banner = banner(output.commentsFilename);
}
if (banner) {
output.source = new ConcatSource(shebang ? `${shebang}\n` : "", `/*! ${banner} */\n`, output.source);
}
}
const extractedCommentsString = output.extractedComments.sort().join("\n\n");
output.extractedCommentsSource = new RawSource(`${extractedCommentsString}\n`);
}
}
await cacheItem.storePromise({
source: output.source,
errors: output.errors,
warnings: output.warnings,
commentsFilename: output.commentsFilename,
extractedCommentsSource: output.extractedCommentsSource
});
}
if (output.warnings && output.warnings.length > 0) {
for (const warning of output.warnings) {
compilation.warnings.push(warning);
}
}
if (output.errors && output.errors.length > 0) {
for (const error of output.errors) {
compilation.errors.push(error);
}
}
if (!output.source) {
return;
}
/** @type {AssetInfo} */
const newInfo = {
minimized: true
};
const {
source,
extractedCommentsSource
} = output;
// Write extracted comments to commentsFilename
if (extractedCommentsSource) {
const {
commentsFilename
} = output;
newInfo.related = {
license: commentsFilename
};
allExtractedComments.set(name, {
extractedCommentsSource,
commentsFilename
});
}
compilation.updateAsset(name, source, newInfo);
});
}
const limit = getWorker && numberOfAssets > 0 ? ( /** @type {number} */numberOfWorkers) : scheduledTasks.length;
await throttleAll(limit, scheduledTasks);
if (initializedWorker) {
await initializedWorker.end();
}
/** @typedef {{ source: import("webpack").sources.Source, commentsFilename: string, from: string }} ExtractedCommentsInfoWithFrom */
await [...allExtractedComments].sort().reduce(
/**
* @param {Promise<unknown>} previousPromise previous result
* @param {[string, ExtractedCommentsInfo]} extractedComments extracted comments
* @returns {Promise<ExtractedCommentsInfoWithFrom>} extract comments with info
*/
async (previousPromise, [from, value]) => {
const previous = /** @type {ExtractedCommentsInfoWithFrom | undefined} * */
await previousPromise;
const {
commentsFilename,
extractedCommentsSource
} = value;
if (previous && previous.commentsFilename === commentsFilename) {
const {
from: previousFrom,
source: prevSource
} = previous;
const mergedName = `${previousFrom}|${from}`;
const name = `${commentsFilename}|${mergedName}`;
const eTag = [prevSource, extractedCommentsSource].map(item => cache.getLazyHashedEtag(item)).reduce((previousValue, currentValue) => cache.mergeEtags(previousValue, currentValue));
let source = await cache.getPromise(name, eTag);
if (!source) {
source = new ConcatSource([...new Set([... /** @type {string} */prevSource.source().split("\n\n"), ... /** @type {string} */extractedCommentsSource.source().split("\n\n")])].join("\n\n"));
await cache.storePromise(name, eTag, source);
}
compilation.updateAsset(commentsFilename, source);
return {
source,
commentsFilename,
from: mergedName
};
}
const existingAsset = compilation.getAsset(commentsFilename);
if (existingAsset) {
return {
source: existingAsset.source,
commentsFilename,
from: commentsFilename
};
}
compilation.emitAsset(commentsFilename, extractedCommentsSource, {
extractedComments: true
});
return {
source: extractedCommentsSource,
commentsFilename,
from
};
}, /** @type {Promise<unknown>} */Promise.resolve());
}
/**
* @private
* @param {NonNullable<NonNullable<Configuration["output"]>["environment"]>} environment environment
* @returns {number} ecma version
*/
static getEcmaVersion(environment) {
// ES 6th
if (environment.arrowFunction || environment.const || environment.destructuring || environment.forOf || environment.module) {
return 2015;
}
// ES 11th
if (environment.bigIntLiteral || environment.dynamicImport) {
return 2020;
}
return 5;
}
/**
* @param {Compiler} compiler compiler
* @returns {void}
*/
apply(compiler) {
const pluginName = this.constructor.name;
const availableNumberOfCores = TerserPlugin.getAvailableNumberOfCores(this.options.parallel);
compiler.hooks.compilation.tap(pluginName, compilation => {
const hooks = compiler.webpack.javascript.JavascriptModulesPlugin.getCompilationHooks(compilation);
const data = getSerializeJavascript()({
minimizer: typeof this.options.minimizer.implementation.getMinimizerVersion !== "undefined" ? this.options.minimizer.implementation.getMinimizerVersion() || "0.0.0" : "0.0.0",
options: this.options.minimizer.options
});
hooks.chunkHash.tap(pluginName, (chunk, hash) => {
hash.update("TerserPlugin");
hash.update(data);
});
compilation.hooks.processAssets.tapPromise({
name: pluginName,
stage: compiler.webpack.Compilation.PROCESS_ASSETS_STAGE_OPTIMIZE_SIZE,
additionalAssets: true
}, assets => this.optimize(compiler, compilation, assets, {
availableNumberOfCores
}));
compilation.hooks.statsPrinter.tap(pluginName, stats => {
stats.hooks.print.for("asset.info.minimized").tap("terser-webpack-plugin", (minimized, {
green,
formatFlag
}) => minimized ? /** @type {(text: string) => string} */green( /** @type {(flag: string) => string} */formatFlag("minimized")) : "");
});
});
}
}
TerserPlugin.terserMinify = terserMinify;
TerserPlugin.uglifyJsMinify = uglifyJsMinify;
TerserPlugin.swcMinify = swcMinify;
TerserPlugin.esbuildMinify = esbuildMinify;
module.exports = TerserPlugin;

49
node_modules/terser-webpack-plugin/dist/minify.js generated vendored Normal file
View File

@@ -0,0 +1,49 @@
"use strict";
/** @typedef {import("./index.js").MinimizedResult} MinimizedResult */
/** @typedef {import("./index.js").CustomOptions} CustomOptions */
/**
* @template T
* @param {import("./index.js").InternalOptions<T>} options options
* @returns {Promise<MinimizedResult>} minified result
*/
async function minify(options) {
const {
name,
input,
inputSourceMap,
extractComments
} = options;
const {
implementation,
options: minimizerOptions
} = options.minimizer;
return implementation({
[name]: input
}, inputSourceMap, minimizerOptions, extractComments);
}
/**
* @param {string} options options
* @returns {Promise<MinimizedResult>} minified result
*/
async function transform(options) {
// 'use strict' => this === undefined (Clean Scope)
// Safer for possible security issues, albeit not critical at all here
const evaluatedOptions =
/**
* @template T
* @type {import("./index.js").InternalOptions<T>}
*/
// eslint-disable-next-line no-new-func
new Function("exports", "require", "module", "__filename", "__dirname", `'use strict'\nreturn ${options}`) // eslint-disable-next-line n/exports-style
(exports, require, module, __filename, __dirname);
return minify(evaluatedOptions);
}
module.exports = {
minify,
transform
};

164
node_modules/terser-webpack-plugin/dist/options.json generated vendored Normal file
View File

@@ -0,0 +1,164 @@
{
"definitions": {
"Rule": {
"description": "Filtering rule as regex or string.",
"anyOf": [
{
"instanceof": "RegExp",
"tsType": "RegExp"
},
{
"type": "string",
"minLength": 1
}
]
},
"Rules": {
"description": "Filtering rules.",
"anyOf": [
{
"type": "array",
"items": {
"description": "A rule condition.",
"oneOf": [
{
"$ref": "#/definitions/Rule"
}
]
}
},
{
"$ref": "#/definitions/Rule"
}
]
}
},
"title": "TerserPluginOptions",
"type": "object",
"additionalProperties": false,
"properties": {
"test": {
"description": "Include all modules that pass test assertion.",
"link": "https://github.com/webpack/terser-webpack-plugin#test",
"oneOf": [
{
"$ref": "#/definitions/Rules"
}
]
},
"include": {
"description": "Include all modules matching any of these conditions.",
"link": "https://github.com/webpack/terser-webpack-plugin#include",
"oneOf": [
{
"$ref": "#/definitions/Rules"
}
]
},
"exclude": {
"description": "Exclude all modules matching any of these conditions.",
"link": "https://github.com/webpack/terser-webpack-plugin#exclude",
"oneOf": [
{
"$ref": "#/definitions/Rules"
}
]
},
"terserOptions": {
"description": "Options for `terser` (by default) or custom `minify` function.",
"link": "https://github.com/webpack/terser-webpack-plugin#terseroptions",
"additionalProperties": true,
"type": "object"
},
"extractComments": {
"description": "Whether comments shall be extracted to a separate file.",
"link": "https://github.com/webpack/terser-webpack-plugin#extractcomments",
"anyOf": [
{
"type": "boolean"
},
{
"type": "string",
"minLength": 1
},
{
"instanceof": "RegExp"
},
{
"instanceof": "Function"
},
{
"additionalProperties": false,
"properties": {
"condition": {
"anyOf": [
{
"type": "boolean"
},
{
"type": "string",
"minLength": 1
},
{
"instanceof": "RegExp"
},
{
"instanceof": "Function"
}
],
"description": "Condition what comments you need extract.",
"link": "https://github.com/webpack/terser-webpack-plugin#condition"
},
"filename": {
"anyOf": [
{
"type": "string",
"minLength": 1
},
{
"instanceof": "Function"
}
],
"description": "The file where the extracted comments will be stored. Default is to append the suffix .LICENSE.txt to the original filename.",
"link": "https://github.com/webpack/terser-webpack-plugin#filename"
},
"banner": {
"anyOf": [
{
"type": "boolean"
},
{
"type": "string",
"minLength": 1
},
{
"instanceof": "Function"
}
],
"description": "The banner text that points to the extracted file and will be added on top of the original file",
"link": "https://github.com/webpack/terser-webpack-plugin#banner"
}
},
"type": "object"
}
]
},
"parallel": {
"description": "Use multi-process parallel running to improve the build speed.",
"link": "https://github.com/webpack/terser-webpack-plugin#parallel",
"anyOf": [
{
"type": "boolean"
},
{
"type": "integer"
}
]
},
"minify": {
"description": "Allows you to override default minify function.",
"link": "https://github.com/webpack/terser-webpack-plugin#number",
"instanceof": "Function"
}
}
}

678
node_modules/terser-webpack-plugin/dist/utils.js generated vendored Normal file
View File

@@ -0,0 +1,678 @@
"use strict";
/** @typedef {import("./index.js").ExtractCommentsOptions} ExtractCommentsOptions */
/** @typedef {import("./index.js").ExtractCommentsFunction} ExtractCommentsFunction */
/** @typedef {import("./index.js").ExtractCommentsCondition} ExtractCommentsCondition */
/** @typedef {import("./index.js").Input} Input */
/** @typedef {import("./index.js").MinimizedResult} MinimizedResult */
/** @typedef {import("./index.js").CustomOptions} CustomOptions */
/** @typedef {import("./index.js").RawSourceMap} RawSourceMap */
/**
* @template T
* @typedef {import("./index.js").PredefinedOptions<T>} PredefinedOptions
*/
/**
* @typedef {Array<string>} ExtractedComments
*/
const notSettled = Symbol("not-settled");
/**
* @template T
* @typedef {() => Promise<T>} Task
*/
/**
* Run tasks with limited concurrency.
* @template T
* @param {number} limit Limit of tasks that run at once.
* @param {Task<T>[]} tasks List of tasks to run.
* @returns {Promise<T[]>} A promise that fulfills to an array of the results
*/
function throttleAll(limit, tasks) {
return new Promise((resolve, reject) => {
const result = Array.from({
length: tasks.length
}).fill(notSettled);
const entries = tasks.entries();
const next = () => {
const {
done,
value
} = entries.next();
if (done) {
const isLast = !result.includes(notSettled);
if (isLast) resolve(result);
return;
}
const [index, task] = value;
/**
* @param {T} resultValue Result value
*/
const onFulfilled = resultValue => {
result[index] = resultValue;
next();
};
task().then(onFulfilled, reject);
};
for (let i = 0; i < limit; i++) {
next();
}
});
}
/* istanbul ignore next */
/**
* @param {Input} input input
* @param {RawSourceMap=} sourceMap source map
* @param {CustomOptions=} minimizerOptions options
* @param {ExtractCommentsOptions=} extractComments extract comments option
* @returns {Promise<MinimizedResult>} minimized result
*/
async function terserMinify(input, sourceMap, minimizerOptions, extractComments) {
// eslint-disable-next-line jsdoc/no-restricted-syntax
/**
* @param {unknown} value value
* @returns {value is object} true when value is object or function
*/
const isObject = value => {
const type = typeof value;
// eslint-disable-next-line no-eq-null, eqeqeq
return value != null && (type === "object" || type === "function");
};
/**
* @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
*/
const buildComments = (terserOptions, extractedComments) => {
/** @type {{ [index: string]: ExtractCommentsCondition }} */
const condition = {};
let comments;
if (terserOptions.format) {
({
comments
} = terserOptions.format);
} else if (terserOptions.output) {
({
comments
} = terserOptions.output);
}
condition.preserve = typeof comments !== "undefined" ? comments : false;
if (typeof extractComments === "boolean" && extractComments) {
condition.extract = "some";
} else if (typeof extractComments === "string" || extractComments instanceof RegExp) {
condition.extract = extractComments;
} else if (typeof extractComments === "function") {
condition.extract = extractComments;
} else if (extractComments && isObject(extractComments)) {
condition.extract = typeof extractComments.condition === "boolean" && extractComments.condition ? "some" : typeof extractComments.condition !== "undefined" ? extractComments.condition : "some";
} else {
// No extract
// Preserve using "commentsOpts" or "some"
condition.preserve = typeof comments !== "undefined" ? comments : "some";
condition.extract = false;
}
// Ensure that both conditions are functions
for (const key of ["preserve", "extract"]) {
/** @type {undefined | string} */
let regexStr;
/** @type {undefined | RegExp} */
let regex;
switch (typeof condition[key]) {
case "boolean":
condition[key] = condition[key] ? () => true : () => false;
break;
case "function":
break;
case "string":
if (condition[key] === "all") {
condition[key] = () => true;
break;
}
if (condition[key] === "some") {
condition[key] = /** @type {ExtractCommentsFunction} */
(astNode, comment) => (comment.type === "comment2" || comment.type === "comment1") && /@preserve|@lic|@cc_on|^\**!/i.test(comment.value);
break;
}
regexStr = /** @type {string} */condition[key];
condition[key] = /** @type {ExtractCommentsFunction} */
(astNode, comment) => new RegExp( /** @type {string} */regexStr).test(comment.value);
break;
default:
regex = /** @type {RegExp} */condition[key];
condition[key] = /** @type {ExtractCommentsFunction} */
(astNode, comment) => /** @type {RegExp} */regex.test(comment.value);
}
}
// Redefine the comments function to extract and preserve
// comments according to the two conditions
return (astNode, comment) => {
if ( /** @type {{ extract: ExtractCommentsFunction }} */
condition.extract(astNode, comment)) {
const commentText = comment.type === "comment2" ? `/*${comment.value}*/` : `//${comment.value}`;
// Don't include duplicate comments
if (!extractedComments.includes(commentText)) {
extractedComments.push(commentText);
}
}
return /** @type {{ preserve: ExtractCommentsFunction }} */condition.preserve(astNode, comment);
};
};
/**
* @param {PredefinedOptions<import("terser").MinifyOptions> & import("terser").MinifyOptions=} terserOptions terser options
* @returns {import("terser").MinifyOptions & { sourceMap: import("terser").SourceMapOptions | undefined } & { compress: import("terser").CompressOptions } & ({ output: import("terser").FormatOptions & { beautify: boolean } } | { format: import("terser").FormatOptions & { beautify: boolean } })} built terser options
*/
const buildTerserOptions = (terserOptions = {}) => (
// Need deep copy objects to avoid https://github.com/terser/terser/issues/366
{
...terserOptions,
compress: typeof terserOptions.compress === "boolean" ? terserOptions.compress ? {} : false : {
...terserOptions.compress
},
// ecma: terserOptions.ecma,
// ie8: terserOptions.ie8,
// keep_classnames: terserOptions.keep_classnames,
// keep_fnames: terserOptions.keep_fnames,
mangle:
// eslint-disable-next-line no-eq-null, eqeqeq
terserOptions.mangle == null ? true : typeof terserOptions.mangle === "boolean" ? terserOptions.mangle : {
...terserOptions.mangle
},
// module: terserOptions.module,
// nameCache: { ...terserOptions.toplevel },
// the `output` option is deprecated
...(terserOptions.format ? {
format: {
beautify: false,
...terserOptions.format
}
} : {
output: {
beautify: false,
...terserOptions.output
}
}),
parse: {
...terserOptions.parse
},
// safari10: terserOptions.safari10,
// Ignoring sourceMap from options
sourceMap: undefined
// toplevel: terserOptions.toplevel
});
let minify;
try {
({
minify
} = require("terser"));
} catch (err) {
return {
errors: [( /** @type {Error} */err)]
};
}
// Copy `terser` options
const terserOptions = buildTerserOptions(minimizerOptions);
// Let terser generate a SourceMap
if (sourceMap) {
terserOptions.sourceMap = {
asObject: true
};
}
/** @type {ExtractedComments} */
const extractedComments = [];
if (terserOptions.output) {
terserOptions.output.comments = buildComments(terserOptions, extractedComments);
} else if (terserOptions.format) {
terserOptions.format.comments = buildComments(terserOptions, extractedComments);
}
if (terserOptions.compress) {
// More optimizations
if (typeof terserOptions.compress.ecma === "undefined") {
terserOptions.compress.ecma = terserOptions.ecma;
}
// https://github.com/webpack/webpack/issues/16135
if (terserOptions.ecma === 5 && typeof terserOptions.compress.arrows === "undefined") {
terserOptions.compress.arrows = false;
}
}
const [[filename, code]] = Object.entries(input);
const result = await minify({
[filename]: code
}, terserOptions);
return {
code: ( /** @type {string} * */result.code),
map: result.map ? ( /** @type {RawSourceMap} * */result.map) : undefined,
extractedComments
};
}
/**
* @returns {string | undefined} the minimizer version
*/
terserMinify.getMinimizerVersion = () => {
let packageJson;
try {
packageJson = require("terser/package.json");
} catch (_err) {
// Ignore
}
return packageJson && packageJson.version;
};
/**
* @returns {boolean | undefined} true if worker thread is supported, false otherwise
*/
terserMinify.supportsWorkerThreads = () => true;
/* istanbul ignore next */
/**
* @param {Input} input input
* @param {RawSourceMap=} sourceMap source map
* @param {CustomOptions=} minimizerOptions options
* @param {ExtractCommentsOptions=} extractComments extract comments option
* @returns {Promise<MinimizedResult>} minimized result
*/
async function uglifyJsMinify(input, sourceMap, minimizerOptions, extractComments) {
// eslint-disable-next-line jsdoc/no-restricted-syntax
/**
* @param {unknown} value value
* @returns {value is object} true when value is object or function
*/
const isObject = value => {
const type = typeof value;
// eslint-disable-next-line no-eq-null, eqeqeq
return value != null && (type === "object" || type === "function");
};
/**
* @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
*/
const buildComments = (uglifyJsOptions, extractedComments) => {
/** @type {{ [index: string]: ExtractCommentsCondition }} */
const condition = {};
const {
comments
} = uglifyJsOptions.output;
condition.preserve = typeof comments !== "undefined" ? comments : false;
if (typeof extractComments === "boolean" && extractComments) {
condition.extract = "some";
} else if (typeof extractComments === "string" || extractComments instanceof RegExp) {
condition.extract = extractComments;
} else if (typeof extractComments === "function") {
condition.extract = extractComments;
} else if (extractComments && isObject(extractComments)) {
condition.extract = typeof extractComments.condition === "boolean" && extractComments.condition ? "some" : typeof extractComments.condition !== "undefined" ? extractComments.condition : "some";
} else {
// No extract
// Preserve using "commentsOpts" or "some"
condition.preserve = typeof comments !== "undefined" ? comments : "some";
condition.extract = false;
}
// Ensure that both conditions are functions
for (const key of ["preserve", "extract"]) {
/** @type {undefined | string} */
let regexStr;
/** @type {undefined | RegExp} */
let regex;
switch (typeof condition[key]) {
case "boolean":
condition[key] = condition[key] ? () => true : () => false;
break;
case "function":
break;
case "string":
if (condition[key] === "all") {
condition[key] = () => true;
break;
}
if (condition[key] === "some") {
condition[key] = /** @type {ExtractCommentsFunction} */
(astNode, comment) => (comment.type === "comment2" || comment.type === "comment1") && /@preserve|@lic|@cc_on|^\**!/i.test(comment.value);
break;
}
regexStr = /** @type {string} */condition[key];
condition[key] = /** @type {ExtractCommentsFunction} */
(astNode, comment) => new RegExp( /** @type {string} */regexStr).test(comment.value);
break;
default:
regex = /** @type {RegExp} */condition[key];
condition[key] = /** @type {ExtractCommentsFunction} */
(astNode, comment) => /** @type {RegExp} */regex.test(comment.value);
}
}
// Redefine the comments function to extract and preserve
// comments according to the two conditions
return (astNode, comment) => {
if ( /** @type {{ extract: ExtractCommentsFunction }} */
condition.extract(astNode, comment)) {
const commentText = comment.type === "comment2" ? `/*${comment.value}*/` : `//${comment.value}`;
// Don't include duplicate comments
if (!extractedComments.includes(commentText)) {
extractedComments.push(commentText);
}
}
return /** @type {{ preserve: ExtractCommentsFunction }} */condition.preserve(astNode, comment);
};
};
/**
* @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
*/
const buildUglifyJsOptions = (uglifyJsOptions = {}) => {
if (typeof uglifyJsOptions.ecma !== "undefined") {
delete uglifyJsOptions.ecma;
}
if (typeof uglifyJsOptions.module !== "undefined") {
delete uglifyJsOptions.module;
}
// Need deep copy objects to avoid https://github.com/terser/terser/issues/366
return {
...uglifyJsOptions,
// warnings: uglifyJsOptions.warnings,
parse: {
...uglifyJsOptions.parse
},
compress: typeof uglifyJsOptions.compress === "boolean" ? uglifyJsOptions.compress : {
...uglifyJsOptions.compress
},
mangle:
// eslint-disable-next-line no-eq-null, eqeqeq
uglifyJsOptions.mangle == null ? true : typeof uglifyJsOptions.mangle === "boolean" ? uglifyJsOptions.mangle : {
...uglifyJsOptions.mangle
},
output: {
beautify: false,
...uglifyJsOptions.output
},
// Ignoring sourceMap from options
sourceMap: undefined
// toplevel: uglifyJsOptions.toplevel
// nameCache: { ...uglifyJsOptions.toplevel },
// ie8: uglifyJsOptions.ie8,
// keep_fnames: uglifyJsOptions.keep_fnames,
};
};
let minify;
try {
({
minify
} = require("uglify-js"));
} catch (err) {
return {
errors: [( /** @type {Error} */err)]
};
}
// Copy `uglify-js` options
const uglifyJsOptions = buildUglifyJsOptions(minimizerOptions);
// Let terser generate a SourceMap
if (sourceMap) {
uglifyJsOptions.sourceMap = true;
}
/** @type {ExtractedComments} */
const extractedComments = [];
// @ts-expect-error wrong types in uglify-js
uglifyJsOptions.output.comments = buildComments(uglifyJsOptions, extractedComments);
const [[filename, code]] = Object.entries(input);
const result = await minify({
[filename]: code
}, uglifyJsOptions);
return {
code: result.code,
map: result.map ? JSON.parse(result.map) : undefined,
errors: result.error ? [result.error] : [],
warnings: result.warnings || [],
extractedComments
};
}
/**
* @returns {string | undefined} the minimizer version
*/
uglifyJsMinify.getMinimizerVersion = () => {
let packageJson;
try {
packageJson = require("uglify-js/package.json");
} catch (_err) {
// Ignore
}
return packageJson && packageJson.version;
};
/**
* @returns {boolean | undefined} true if worker thread is supported, false otherwise
*/
uglifyJsMinify.supportsWorkerThreads = () => true;
/* istanbul ignore next */
/**
* @param {Input} input input
* @param {RawSourceMap=} sourceMap source map
* @param {CustomOptions=} minimizerOptions options
* @returns {Promise<MinimizedResult>} minimized result
*/
async function swcMinify(input, sourceMap, minimizerOptions) {
/**
* @param {PredefinedOptions<import("@swc/core").JsMinifyOptions> & import("@swc/core").JsMinifyOptions=} swcOptions swc options
* @returns {import("@swc/core").JsMinifyOptions & { sourceMap: undefined | boolean } & { compress: import("@swc/core").TerserCompressOptions }} built swc options
*/
const buildSwcOptions = (swcOptions = {}) => (
// Need deep copy objects to avoid https://github.com/terser/terser/issues/366
{
...swcOptions,
compress: typeof swcOptions.compress === "boolean" ? swcOptions.compress ? {} : false : {
...swcOptions.compress
},
mangle:
// eslint-disable-next-line no-eq-null, eqeqeq
swcOptions.mangle == null ? true : typeof swcOptions.mangle === "boolean" ? swcOptions.mangle : {
...swcOptions.mangle
},
// ecma: swcOptions.ecma,
// keep_classnames: swcOptions.keep_classnames,
// keep_fnames: swcOptions.keep_fnames,
// module: swcOptions.module,
// safari10: swcOptions.safari10,
// toplevel: swcOptions.toplevel
sourceMap: undefined
});
let swc;
try {
swc = require("@swc/core");
} catch (err) {
return {
errors: [( /** @type {Error} */err)]
};
}
// Copy `swc` options
const swcOptions = buildSwcOptions(minimizerOptions);
// Let `swc` generate a SourceMap
if (sourceMap) {
swcOptions.sourceMap = true;
}
if (swcOptions.compress) {
// More optimizations
if (typeof swcOptions.compress.ecma === "undefined") {
swcOptions.compress.ecma = swcOptions.ecma;
}
// https://github.com/webpack/webpack/issues/16135
if (swcOptions.ecma === 5 && typeof swcOptions.compress.arrows === "undefined") {
swcOptions.compress.arrows = false;
}
}
const [[filename, code]] = Object.entries(input);
const result = await swc.minify(code, swcOptions);
let map;
if (result.map) {
map = JSON.parse(result.map);
// TODO workaround for swc because `filename` is not preset as in `swc` signature as for `terser`
map.sources = [filename];
delete map.sourcesContent;
}
return {
code: result.code,
map
};
}
/**
* @returns {string | undefined} the minimizer version
*/
swcMinify.getMinimizerVersion = () => {
let packageJson;
try {
packageJson = require("@swc/core/package.json");
} catch (_err) {
// Ignore
}
return packageJson && packageJson.version;
};
/**
* @returns {boolean | undefined} true if worker thread is supported, false otherwise
*/
swcMinify.supportsWorkerThreads = () => false;
/* istanbul ignore next */
/**
* @param {Input} input input
* @param {RawSourceMap=} sourceMap source map
* @param {CustomOptions=} minimizerOptions options
* @returns {Promise<MinimizedResult>} minimized result
*/
async function esbuildMinify(input, sourceMap, minimizerOptions) {
/**
* @param {PredefinedOptions<import("esbuild").TransformOptions> & import("esbuild").TransformOptions=} esbuildOptions esbuild options
* @returns {import("esbuild").TransformOptions} built esbuild options
*/
const buildEsbuildOptions = (esbuildOptions = {}) => {
delete esbuildOptions.ecma;
if (esbuildOptions.module) {
esbuildOptions.format = "esm";
}
delete esbuildOptions.module;
// Need deep copy objects to avoid https://github.com/terser/terser/issues/366
return {
minify: true,
legalComments: "inline",
...esbuildOptions,
sourcemap: false
};
};
let esbuild;
try {
esbuild = require("esbuild");
} catch (err) {
return {
errors: [( /** @type {Error} */err)]
};
}
// Copy `esbuild` options
const esbuildOptions = buildEsbuildOptions(minimizerOptions);
// Let `esbuild` generate a SourceMap
if (sourceMap) {
esbuildOptions.sourcemap = true;
esbuildOptions.sourcesContent = false;
}
const [[filename, code]] = Object.entries(input);
esbuildOptions.sourcefile = filename;
const result = await esbuild.transform(code, esbuildOptions);
return {
code: result.code,
map: result.map ? JSON.parse(result.map) : undefined,
warnings: result.warnings.length > 0 ? result.warnings.map(item => {
const plugin = item.pluginName ? `\nPlugin Name: ${item.pluginName}` : "";
const location = item.location ? `\n\n${item.location.file}:${item.location.line}:${item.location.column}:\n ${item.location.line} | ${item.location.lineText}\n\nSuggestion: ${item.location.suggestion}` : "";
const notes = item.notes.length > 0 ? `\n\nNotes:\n${item.notes.map(note => `${note.location ? `[${note.location.file}:${note.location.line}:${note.location.column}] ` : ""}${note.text}${note.location ? `\nSuggestion: ${note.location.suggestion}` : ""}${note.location ? `\nLine text:\n${note.location.lineText}\n` : ""}`).join("\n")}` : "";
return `${item.text} [${item.id}]${plugin}${location}${item.detail ? `\nDetails:\n${item.detail}` : ""}${notes}`;
}) : []
};
}
/**
* @returns {string | undefined} the minimizer version
*/
esbuildMinify.getMinimizerVersion = () => {
let packageJson;
try {
packageJson = require("esbuild/package.json");
} catch (_err) {
// Ignore
}
return packageJson && packageJson.version;
};
/**
* @returns {boolean | undefined} true if worker thread is supported, false otherwise
*/
esbuildMinify.supportsWorkerThreads = () => false;
/**
* @template T
* @typedef {() => T} FunctionReturning
*/
/**
* @template T
* @param {FunctionReturning<T>} fn memorized function
* @returns {FunctionReturning<T>} new function
*/
function memoize(fn) {
let cache = false;
/** @type {T} */
let result;
return () => {
if (cache) {
return result;
}
result = fn();
cache = true;
// Allow to clean up memory for fn
// and all dependent resources
/** @type {FunctionReturning<T> | undefined} */
fn = undefined;
return /** @type {T} */result;
};
}
module.exports = {
esbuildMinify,
memoize,
swcMinify,
terserMinify,
throttleAll,
uglifyJsMinify
};

129
node_modules/terser-webpack-plugin/package.json generated vendored Normal file
View File

@@ -0,0 +1,129 @@
{
"name": "terser-webpack-plugin",
"version": "5.3.16",
"description": "Terser plugin for webpack",
"keywords": [
"uglify",
"uglify-js",
"uglify-es",
"terser",
"webpack",
"webpack-plugin",
"minification",
"compress",
"compressor",
"min",
"minification",
"minifier",
"minify",
"optimize",
"optimizer"
],
"homepage": "https://github.com/webpack/terser-webpack-plugin",
"bugs": "https://github.com/webpack/terser-webpack-plugin/issues",
"repository": "webpack/terser-webpack-plugin",
"funding": {
"type": "opencollective",
"url": "https://opencollective.com/webpack"
},
"license": "MIT",
"author": "webpack Contrib Team",
"main": "dist/index.js",
"types": "types/index.d.ts",
"files": [
"dist",
"types"
],
"scripts": {
"clean": "del-cli dist types",
"prebuild": "npm run clean",
"build:types": "tsc --declaration --emitDeclarationOnly --outDir types && prettier \"types/**/*.ts\" --write",
"build:code": "cross-env NODE_ENV=production babel src -d dist --copy-files",
"build": "npm-run-all -p \"build:**\"",
"commitlint": "commitlint --from=main",
"security": "npm audit --production",
"lint:prettier": "prettier --list-different .",
"lint:code": "eslint --cache .",
"lint:spelling": "cspell \"**/*.*\"",
"lint:types": "tsc --pretty --noEmit",
"lint": "npm-run-all -l -p \"lint:**\"",
"fix:code": "npm run lint:code -- --fix",
"fix:prettier": "npm run lint:prettier -- --write",
"fix": "npm-run-all -l fix:code fix:prettier",
"test:only": "cross-env NODE_ENV=test jest",
"test:watch": "npm run test:only -- --watch",
"test:coverage": "npm run test:only -- --collectCoverageFrom=\"src/**/*.js\" --coverage",
"pretest": "npm run lint",
"test": "npm run test:coverage",
"prepare": "husky install && npm run build",
"release": "standard-version"
},
"dependencies": {
"@jridgewell/trace-mapping": "^0.3.25",
"jest-worker": "^27.4.5",
"schema-utils": "^4.3.0",
"serialize-javascript": "^6.0.2",
"terser": "^5.31.1"
},
"devDependencies": {
"@babel/cli": "^7.24.7",
"@babel/core": "^7.24.7",
"@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",
"@types/uglify-js": "^3.17.5",
"copy-webpack-plugin": "^9.0.1",
"cross-env": "^7.0.3",
"cspell": "^6.31.2",
"del": "^6.0.0",
"del-cli": "^3.0.1",
"esbuild": "^0.25.0",
"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",
"lint-staged": "^13.2.3",
"memfs": "^3.4.13",
"npm-run-all": "^4.1.5",
"prettier": "^3.6.0",
"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",
"worker-loader": "^3.0.8"
},
"peerDependencies": {
"webpack": "^5.1.0"
},
"peerDependenciesMeta": {
"@swc/core": {
"optional": true
},
"uglify-js": {
"optional": true
},
"esbuild": {
"optional": true
}
},
"engines": {
"node": ">= 10.13.0"
}
}

319
node_modules/terser-webpack-plugin/types/index.d.ts generated vendored Normal file
View File

@@ -0,0 +1,319 @@
export = TerserPlugin;
/**
* @template [T=import("terser").MinifyOptions]
*/
declare class TerserPlugin<T = import("terser").MinifyOptions> {
/**
* @private
* @param {unknown} input Input to check
* @returns {boolean} Whether input is a source map
*/
private static isSourceMap;
/**
* @private
* @param {unknown} warning warning
* @param {string} file file
* @returns {Error} built warning
*/
private static buildWarning;
/**
* @private
* @param {Error | ErrorObject | string} error error
* @param {string} file file
* @param {TraceMap=} sourceMap source map
* @param {Compilation["requestShortener"]=} requestShortener request shortener
* @returns {Error} built error
*/
private static buildError;
/**
* @private
* @param {Parallel} parallel value of the `parallel` option
* @returns {number} number of cores for parallelism
*/
private static getAvailableNumberOfCores;
/**
* @private
* @param {NonNullable<NonNullable<Configuration["output"]>["environment"]>} environment environment
* @returns {number} ecma version
*/
private static getEcmaVersion;
/**
* @param {BasePluginOptions & DefinedDefaultMinimizerAndOptions<T>=} options options
*/
constructor(
options?:
| (BasePluginOptions & DefinedDefaultMinimizerAndOptions<T>)
| undefined,
);
/**
* @private
* @type {InternalPluginOptions<T>}
*/
private options;
/**
* @private
* @param {Compiler} compiler compiler
* @param {Compilation} compilation compilation
* @param {Record<string, import("webpack").sources.Source>} assets assets
* @param {{ availableNumberOfCores: number }} optimizeOptions optimize options
* @returns {Promise<void>}
*/
private optimize;
/**
* @param {Compiler} compiler compiler
* @returns {void}
*/
apply(compiler: Compiler): void;
}
declare namespace TerserPlugin {
export {
terserMinify,
uglifyJsMinify,
swcMinify,
esbuildMinify,
Schema,
Compiler,
Compilation,
Configuration,
Asset,
AssetInfo,
JestWorker,
RawSourceMap,
TraceMap,
Rule,
Rules,
ExtractCommentsFunction,
ExtractCommentsCondition,
ExtractCommentsFilename,
ExtractCommentsBanner,
ExtractCommentsObject,
ExtractCommentsOptions,
ErrorObject,
MinimizedResult,
Input,
CustomOptions,
InferDefaultType,
PredefinedOptions,
MinimizerOptions,
BasicMinimizerImplementation,
MinimizeFunctionHelpers,
MinimizerImplementation,
InternalOptions,
MinimizerWorker,
Parallel,
BasePluginOptions,
DefinedDefaultMinimizerAndOptions,
InternalPluginOptions,
};
}
import { terserMinify } from "./utils";
import { uglifyJsMinify } from "./utils";
import { swcMinify } from "./utils";
import { esbuildMinify } from "./utils";
type Schema = import("schema-utils/declarations/validate").Schema;
type Compiler = import("webpack").Compiler;
type Compilation = import("webpack").Compilation;
type Configuration = import("webpack").Configuration;
type Asset = import("webpack").Asset;
type AssetInfo = import("webpack").AssetInfo;
type JestWorker = import("jest-worker").Worker;
type RawSourceMap = import("@jridgewell/trace-mapping").EncodedSourceMap & {
sources: string[];
sourcesContent?: string[];
file: string;
};
type TraceMap = import("@jridgewell/trace-mapping").TraceMap;
type Rule = RegExp | string;
type Rules = Rule[] | Rule;
type ExtractCommentsFunction = (
astNode: any,
comment: {
value: string;
type: "comment1" | "comment2" | "comment3" | "comment4";
pos: number;
line: number;
col: number;
},
) => boolean;
type ExtractCommentsCondition =
| boolean
| "all"
| "some"
| RegExp
| ExtractCommentsFunction;
type ExtractCommentsFilename = string | ((fileData: any) => string);
type ExtractCommentsBanner =
| boolean
| string
| ((commentsFile: string) => string);
type ExtractCommentsObject = {
/**
* condition which comments need to be expected
*/
condition?: ExtractCommentsCondition | undefined;
/**
* filename for extracted comments
*/
filename?: ExtractCommentsFilename | undefined;
/**
* banner in filename for extracted comments
*/
banner?: ExtractCommentsBanner | undefined;
};
type ExtractCommentsOptions = ExtractCommentsCondition | ExtractCommentsObject;
type ErrorObject = {
/**
* message
*/
message: string;
/**
* line number
*/
line?: number | undefined;
/**
* column number
*/
column?: number | undefined;
/**
* error stack trace
*/
stack?: string | undefined;
};
type MinimizedResult = {
/**
* code
*/
code?: string | undefined;
/**
* source map
*/
map?: RawSourceMap | undefined;
/**
* errors
*/
errors?: Array<Error | string> | undefined;
/**
* warnings
*/
warnings?: Array<Error | string> | undefined;
/**
* extracted comments
*/
extractedComments?: Array<string> | undefined;
};
type Input = {
[file: string]: string;
};
type CustomOptions = {
[key: string]: any;
};
type InferDefaultType<T> = T extends infer U ? U : CustomOptions;
type PredefinedOptions<T> = {
/**
* true when code is a EC module, otherwise false
*/
module?:
| (T extends {
module?: infer P;
}
? P
: boolean | string)
| undefined;
/**
* ecma version
*/
ecma?:
| (T extends {
ecma?: infer P;
}
? P
: number | string)
| undefined;
};
type MinimizerOptions<T> = PredefinedOptions<T> & InferDefaultType<T>;
type BasicMinimizerImplementation<T> = (
input: Input,
sourceMap: RawSourceMap | undefined,
minifyOptions: MinimizerOptions<T>,
extractComments: ExtractCommentsOptions | undefined,
) => Promise<MinimizedResult> | MinimizedResult;
type MinimizeFunctionHelpers = {
/**
* function that returns version of minimizer
*/
getMinimizerVersion?: (() => string | undefined) | undefined;
/**
* true when minimizer support worker threads, otherwise false
*/
supportsWorkerThreads?: (() => boolean | undefined) | undefined;
};
type MinimizerImplementation<T> = BasicMinimizerImplementation<T> &
MinimizeFunctionHelpers;
type InternalOptions<T> = {
/**
* name
*/
name: string;
/**
* input
*/
input: string;
/**
* input source map
*/
inputSourceMap: RawSourceMap | undefined;
/**
* extract comments option
*/
extractComments: ExtractCommentsOptions | undefined;
/**
* minimizer
*/
minimizer: {
implementation: MinimizerImplementation<T>;
options: MinimizerOptions<T>;
};
};
type MinimizerWorker<T> = JestWorker & {
transform: (options: string) => Promise<MinimizedResult>;
minify: (options: InternalOptions<T>) => Promise<MinimizedResult>;
};
type Parallel = undefined | boolean | number;
type BasePluginOptions = {
/**
* test rule
*/
test?: Rules | undefined;
/**
* include rile
*/
include?: Rules | undefined;
/**
* exclude rule
*/
exclude?: Rules | undefined;
/**
* extract comments options
*/
extractComments?: ExtractCommentsOptions | undefined;
/**
* parallel option
*/
parallel?: Parallel | undefined;
};
type DefinedDefaultMinimizerAndOptions<T> =
T extends import("terser").MinifyOptions
? {
minify?: MinimizerImplementation<T> | undefined;
terserOptions?: MinimizerOptions<T> | undefined;
}
: {
minify: MinimizerImplementation<T>;
terserOptions?: MinimizerOptions<T> | undefined;
};
type InternalPluginOptions<T> = BasePluginOptions & {
minimizer: {
implementation: MinimizerImplementation<T>;
options: MinimizerOptions<T>;
};
};

17
node_modules/terser-webpack-plugin/types/minify.d.ts generated vendored Normal file
View File

@@ -0,0 +1,17 @@
export type MinimizedResult = import("./index.js").MinimizedResult;
export type CustomOptions = import("./index.js").CustomOptions;
/** @typedef {import("./index.js").MinimizedResult} MinimizedResult */
/** @typedef {import("./index.js").CustomOptions} CustomOptions */
/**
* @template T
* @param {import("./index.js").InternalOptions<T>} options options
* @returns {Promise<MinimizedResult>} minified result
*/
export function minify<T>(
options: import("./index.js").InternalOptions<T>,
): Promise<MinimizedResult>;
/**
* @param {string} options options
* @returns {Promise<MinimizedResult>} minified result
*/
export function transform(options: string): Promise<MinimizedResult>;

124
node_modules/terser-webpack-plugin/types/utils.d.ts generated vendored Normal file
View File

@@ -0,0 +1,124 @@
export type Task<T> = () => Promise<T>;
export type FunctionReturning<T> = () => T;
export type ExtractCommentsOptions =
import("./index.js").ExtractCommentsOptions;
export type ExtractCommentsFunction =
import("./index.js").ExtractCommentsFunction;
export type ExtractCommentsCondition =
import("./index.js").ExtractCommentsCondition;
export type Input = import("./index.js").Input;
export type MinimizedResult = import("./index.js").MinimizedResult;
export type CustomOptions = import("./index.js").CustomOptions;
export type RawSourceMap = import("./index.js").RawSourceMap;
export type PredefinedOptions<T> = import("./index.js").PredefinedOptions<T>;
export type ExtractedComments = Array<string>;
/**
* @param {Input} input input
* @param {RawSourceMap=} sourceMap source map
* @param {CustomOptions=} minimizerOptions options
* @returns {Promise<MinimizedResult>} minimized result
*/
export function esbuildMinify(
input: Input,
sourceMap?: RawSourceMap | undefined,
minimizerOptions?: CustomOptions | undefined,
): Promise<MinimizedResult>;
export namespace esbuildMinify {
/**
* @returns {string | undefined} the minimizer version
*/
function getMinimizerVersion(): string | undefined;
/**
* @returns {boolean | undefined} true if worker thread is supported, false otherwise
*/
function supportsWorkerThreads(): boolean | undefined;
}
/**
* @template T
* @typedef {() => T} FunctionReturning
*/
/**
* @template T
* @param {FunctionReturning<T>} fn memorized function
* @returns {FunctionReturning<T>} new function
*/
export function memoize<T>(fn: FunctionReturning<T>): FunctionReturning<T>;
/**
* @param {Input} input input
* @param {RawSourceMap=} sourceMap source map
* @param {CustomOptions=} minimizerOptions options
* @returns {Promise<MinimizedResult>} minimized result
*/
export function swcMinify(
input: Input,
sourceMap?: RawSourceMap | undefined,
minimizerOptions?: CustomOptions | undefined,
): Promise<MinimizedResult>;
export namespace swcMinify {
/**
* @returns {string | undefined} the minimizer version
*/
function getMinimizerVersion(): string | undefined;
/**
* @returns {boolean | undefined} true if worker thread is supported, false otherwise
*/
function supportsWorkerThreads(): boolean | undefined;
}
/**
* @param {Input} input input
* @param {RawSourceMap=} sourceMap source map
* @param {CustomOptions=} minimizerOptions options
* @param {ExtractCommentsOptions=} extractComments extract comments option
* @returns {Promise<MinimizedResult>} minimized result
*/
export function terserMinify(
input: Input,
sourceMap?: RawSourceMap | undefined,
minimizerOptions?: CustomOptions | undefined,
extractComments?: ExtractCommentsOptions | undefined,
): Promise<MinimizedResult>;
export namespace terserMinify {
/**
* @returns {string | undefined} the minimizer version
*/
function getMinimizerVersion(): string | undefined;
/**
* @returns {boolean | undefined} true if worker thread is supported, false otherwise
*/
function supportsWorkerThreads(): boolean | undefined;
}
/**
* @template T
* @typedef {() => Promise<T>} Task
*/
/**
* Run tasks with limited concurrency.
* @template T
* @param {number} limit Limit of tasks that run at once.
* @param {Task<T>[]} tasks List of tasks to run.
* @returns {Promise<T[]>} A promise that fulfills to an array of the results
*/
export function throttleAll<T>(limit: number, tasks: Task<T>[]): Promise<T[]>;
/**
* @param {Input} input input
* @param {RawSourceMap=} sourceMap source map
* @param {CustomOptions=} minimizerOptions options
* @param {ExtractCommentsOptions=} extractComments extract comments option
* @returns {Promise<MinimizedResult>} minimized result
*/
export function uglifyJsMinify(
input: Input,
sourceMap?: RawSourceMap | undefined,
minimizerOptions?: CustomOptions | undefined,
extractComments?: ExtractCommentsOptions | undefined,
): Promise<MinimizedResult>;
export namespace uglifyJsMinify {
/**
* @returns {string | undefined} the minimizer version
*/
function getMinimizerVersion(): string | undefined;
/**
* @returns {boolean | undefined} true if worker thread is supported, false otherwise
*/
function supportsWorkerThreads(): boolean | undefined;
}