@rushstack/module-minifier 0.6.35 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.json +32 -0
- package/CHANGELOG.md +13 -1
- package/dist/module-minifier.d.ts +5 -0
- package/dist/tsdoc-metadata.json +1 -1
- package/lib/WorkerPoolMinifier.d.ts +6 -0
- package/lib/WorkerPoolMinifier.d.ts.map +1 -1
- package/lib/WorkerPoolMinifier.js +3 -2
- package/lib/WorkerPoolMinifier.js.map +1 -1
- package/package.json +4 -4
package/CHANGELOG.json
CHANGED
|
@@ -1,6 +1,38 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rushstack/module-minifier",
|
|
3
3
|
"entries": [
|
|
4
|
+
{
|
|
5
|
+
"version": "0.7.0",
|
|
6
|
+
"tag": "@rushstack/module-minifier_v0.7.0",
|
|
7
|
+
"date": "Wed, 22 Jan 2025 03:03:47 GMT",
|
|
8
|
+
"comments": {
|
|
9
|
+
"minor": [
|
|
10
|
+
{
|
|
11
|
+
"comment": "Add a `workerResourceLimits` option to the `WorkerPoolMinifier` constructor to control the available resources to the workers."
|
|
12
|
+
}
|
|
13
|
+
],
|
|
14
|
+
"dependency": [
|
|
15
|
+
{
|
|
16
|
+
"comment": "Updating dependency \"@rushstack/worker-pool\" to `0.5.0`"
|
|
17
|
+
}
|
|
18
|
+
]
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
"version": "0.6.36",
|
|
23
|
+
"tag": "@rushstack/module-minifier_v0.6.36",
|
|
24
|
+
"date": "Thu, 09 Jan 2025 01:10:10 GMT",
|
|
25
|
+
"comments": {
|
|
26
|
+
"dependency": [
|
|
27
|
+
{
|
|
28
|
+
"comment": "Updating dependency \"@rushstack/worker-pool\" to `0.4.81`"
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
"comment": "Updating dependency \"@rushstack/heft\" to `0.68.13`"
|
|
32
|
+
}
|
|
33
|
+
]
|
|
34
|
+
}
|
|
35
|
+
},
|
|
4
36
|
{
|
|
5
37
|
"version": "0.6.35",
|
|
6
38
|
"tag": "@rushstack/module-minifier_v0.6.35",
|
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,18 @@
|
|
|
1
1
|
# Change Log - @rushstack/module-minifier
|
|
2
2
|
|
|
3
|
-
This log was last generated on
|
|
3
|
+
This log was last generated on Wed, 22 Jan 2025 03:03:47 GMT and should not be manually modified.
|
|
4
|
+
|
|
5
|
+
## 0.7.0
|
|
6
|
+
Wed, 22 Jan 2025 03:03:47 GMT
|
|
7
|
+
|
|
8
|
+
### Minor changes
|
|
9
|
+
|
|
10
|
+
- Add a `workerResourceLimits` option to the `WorkerPoolMinifier` constructor to control the available resources to the workers.
|
|
11
|
+
|
|
12
|
+
## 0.6.36
|
|
13
|
+
Thu, 09 Jan 2025 01:10:10 GMT
|
|
14
|
+
|
|
15
|
+
_Version update only_
|
|
4
16
|
|
|
5
17
|
## 0.6.35
|
|
6
18
|
Tue, 07 Jan 2025 22:17:32 GMT
|
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
|
|
11
11
|
import { MinifyOptions } from 'terser';
|
|
12
12
|
import type { RawSourceMap } from 'source-map';
|
|
13
|
+
import type { ResourceLimits } from 'worker_threads';
|
|
13
14
|
import type * as WorkerThreads from 'worker_threads';
|
|
14
15
|
|
|
15
16
|
/**
|
|
@@ -179,6 +180,10 @@ export declare interface IWorkerPoolMinifierOptions {
|
|
|
179
180
|
* If true, log to the console about the minification results.
|
|
180
181
|
*/
|
|
181
182
|
verbose?: boolean;
|
|
183
|
+
/**
|
|
184
|
+
* Optional resource limits for the workers.
|
|
185
|
+
*/
|
|
186
|
+
workerResourceLimits?: ResourceLimits;
|
|
182
187
|
}
|
|
183
188
|
|
|
184
189
|
/**
|
package/dist/tsdoc-metadata.json
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import type { ResourceLimits } from 'worker_threads';
|
|
1
3
|
import type { MinifyOptions } from 'terser';
|
|
2
4
|
import type { IMinifierConnection, IModuleMinificationCallback, IModuleMinificationRequest, IModuleMinifier } from './types';
|
|
3
5
|
/**
|
|
@@ -19,6 +21,10 @@ export interface IWorkerPoolMinifierOptions {
|
|
|
19
21
|
* If true, log to the console about the minification results.
|
|
20
22
|
*/
|
|
21
23
|
verbose?: boolean;
|
|
24
|
+
/**
|
|
25
|
+
* Optional resource limits for the workers.
|
|
26
|
+
*/
|
|
27
|
+
workerResourceLimits?: ResourceLimits;
|
|
22
28
|
}
|
|
23
29
|
/**
|
|
24
30
|
* Minifier implementation that uses a thread pool for minification.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"WorkerPoolMinifier.d.ts","sourceRoot":"","sources":["../src/WorkerPoolMinifier.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"WorkerPoolMinifier.d.ts","sourceRoot":"","sources":["../src/WorkerPoolMinifier.ts"],"names":[],"mappings":";AAKA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAGrD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,QAAQ,CAAC;AAG5C,OAAO,KAAK,EACV,mBAAmB,EACnB,2BAA2B,EAE3B,0BAA0B,EAC1B,eAAe,EAChB,MAAM,SAAS,CAAC;AAEjB;;;GAGG;AACH,MAAM,WAAW,0BAA0B;IACzC;;;OAGG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB;;;OAGG;IACH,aAAa,CAAC,EAAE,aAAa,CAAC;IAE9B;;OAEG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;IAElB;;OAEG;IACH,oBAAoB,CAAC,EAAE,cAAc,CAAC;CACvC;AAED;;;GAGG;AACH,qBAAa,kBAAmB,YAAW,eAAe;IACxD,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAa;IACnC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAU;IACnC,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAS;IAErC,OAAO,CAAC,SAAS,CAAS;IAC1B,OAAO,CAAC,QAAQ,CAAS;IACzB,OAAO,CAAC,SAAS,CAAS;IAE1B,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAyC;IACtE,OAAO,CAAC,QAAQ,CAAC,eAAe,CAA6C;gBAE1D,OAAO,EAAE,0BAA0B;IAoCtD,IAAW,UAAU,IAAI,MAAM,CAE9B;IAED,IAAW,UAAU,CAAC,OAAO,EAAE,MAAM,EAEpC;IAED;;;;OAIG;IACI,MAAM,CAAC,OAAO,EAAE,0BAA0B,EAAE,QAAQ,EAAE,2BAA2B,GAAG,IAAI;IAuD/F;;OAEG;IACU,YAAY,IAAI,OAAO,CAAC,mBAAmB,CAAC;IA+BzD;;OAEG;IAEU,OAAO,IAAI,OAAO,CAAC,mBAAmB,CAAC;CAGrD"}
|
|
@@ -16,14 +16,15 @@ const worker_pool_1 = require("@rushstack/worker-pool");
|
|
|
16
16
|
*/
|
|
17
17
|
class WorkerPoolMinifier {
|
|
18
18
|
constructor(options) {
|
|
19
|
-
const { maxThreads = (0, os_1.cpus)().length, terserOptions = {}, verbose = false } = options || {};
|
|
19
|
+
const { maxThreads = (0, os_1.cpus)().length, terserOptions = {}, verbose = false, workerResourceLimits } = options || {};
|
|
20
20
|
const activeRequests = new Map();
|
|
21
21
|
const resultCache = new Map();
|
|
22
22
|
const terserPool = new worker_pool_1.WorkerPool({
|
|
23
23
|
id: 'Minifier',
|
|
24
24
|
maxWorkers: maxThreads,
|
|
25
25
|
workerData: terserOptions,
|
|
26
|
-
workerScriptPath: require.resolve('./MinifierWorker')
|
|
26
|
+
workerScriptPath: require.resolve('./MinifierWorker'),
|
|
27
|
+
workerResourceLimits
|
|
27
28
|
});
|
|
28
29
|
const { version: terserVersion } = require('terser/package.json');
|
|
29
30
|
this._configHash = (0, crypto_1.createHash)('sha256')
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version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AAC,YAAY,CAAC,KAAK,EAAE,CAAC;gBAC1B,IAAI,CAAC,eAAe,CAAC,KAAK,EAAE,CAAC;gBAC7B,IAAI,IAAI,CAAC,QAAQ,EAAE,CAAC;oBAClB,sCAAsC;oBACtC,OAAO,CAAC,GAAG,CAAC,wBAAwB,IAAI,CAAC,QAAQ,aAAa,IAAI,CAAC,SAAS,YAAY,CAAC,CAAC;gBAC5F,CAAC;YACH,CAAC;YACD,IAAI,CAAC,QAAQ,GAAG,CAAC,CAAC;YAClB,IAAI,CAAC,SAAS,GAAG,CAAC,CAAC;QACrB,CAAC,CAAC;QAEF,OAAO;YACL,UAAU,EAAE,IAAI,CAAC,WAAW;YAE5B,eAAe;YACf,UAAU,EAAE,eAAe;SAC5B,CAAC;IACJ,CAAC;IAED;;OAEG;IACH,gEAAgE;IACzD,KAAK,CAAC,OAAO;QAClB,OAAO,MAAM,IAAI,CAAC,YAAY,EAAE,CAAC;IACnC,CAAC;CACF;AAvJD,gDAuJC","sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.\n// See LICENSE in the project root for license information.\n\nimport { createHash } from 'crypto';\nimport { cpus } from 'os';\n\nimport serialize from 'serialize-javascript';\nimport type { MinifyOptions } from 'terser';\nimport { WorkerPool } from '@rushstack/worker-pool';\n\nimport type {\n IMinifierConnection,\n IModuleMinificationCallback,\n IModuleMinificationResult,\n IModuleMinificationRequest,\n IModuleMinifier\n} from './types';\n\n/**\n * Options for configuring the WorkerPoolMinifier\n * @public\n */\nexport interface IWorkerPoolMinifierOptions {\n /**\n * Maximum number of worker threads to use. Will never use more than there are modules to process.\n * Defaults to os.cpus().length\n */\n maxThreads?: number;\n /**\n * The options to forward to Terser.\n * `output.comments` is currently not configurable and will always extract license comments to a separate file.\n */\n terserOptions?: MinifyOptions;\n\n /**\n * If true, log to the console about the minification results.\n */\n verbose?: boolean;\n}\n\n/**\n * Minifier implementation that uses a thread pool for minification.\n * @public\n */\nexport class WorkerPoolMinifier implements IModuleMinifier {\n private readonly _pool: WorkerPool;\n private readonly _verbose: boolean;\n private readonly _configHash: string;\n\n private _refCount: number;\n private _deduped: number;\n private _minified: number;\n\n private readonly _resultCache: Map<string, IModuleMinificationResult>;\n private readonly _activeRequests: Map<string, IModuleMinificationCallback[]>;\n\n public constructor(options: IWorkerPoolMinifierOptions) {\n const { maxThreads = cpus().length, terserOptions = {}, verbose = false } = options || {};\n\n const activeRequests: Map<string, IModuleMinificationCallback[]> = new Map();\n const resultCache: Map<string, IModuleMinificationResult> = new Map();\n const terserPool: WorkerPool = new WorkerPool({\n id: 'Minifier',\n maxWorkers: maxThreads,\n workerData: terserOptions,\n workerScriptPath: require.resolve('./MinifierWorker')\n });\n\n const { version: terserVersion } = require('terser/package.json');\n\n this._configHash = createHash('sha256')\n .update(WorkerPoolMinifier.name, 'utf8')\n .update(`terser@${terserVersion}`)\n .update(serialize(terserOptions))\n .digest('base64');\n\n this._activeRequests = activeRequests;\n this._refCount = 0;\n this._resultCache = resultCache;\n this._pool = terserPool;\n this._verbose = verbose;\n\n this._deduped = 0;\n this._minified = 0;\n }\n\n public get maxThreads(): number {\n return this._pool.maxWorkers;\n }\n\n public set maxThreads(threads: number) {\n this._pool.maxWorkers = threads;\n }\n\n /**\n * Transform code by farming it out to a worker pool.\n * @param request - The request to process\n * @param callback - The callback to invoke\n */\n public minify(request: IModuleMinificationRequest, callback: IModuleMinificationCallback): void {\n const { hash } = request;\n\n const cached: IModuleMinificationResult | undefined = this._resultCache.get(hash);\n if (cached) {\n ++this._deduped;\n return callback(cached);\n }\n\n const { _activeRequests: activeRequests } = this;\n const callbacks: IModuleMinificationCallback[] | undefined = activeRequests.get(hash);\n if (callbacks) {\n ++this._deduped;\n callbacks.push(callback);\n return;\n }\n\n activeRequests.set(hash, [callback]);\n ++this._minified;\n\n this._pool\n .checkoutWorkerAsync(true)\n .then((worker) => {\n const cb: (message: IModuleMinificationResult) => void = (\n message: IModuleMinificationResult\n ): void => {\n worker.off('message', cb);\n const workerCallbacks: IModuleMinificationCallback[] | undefined = activeRequests.get(\n message.hash\n )!;\n activeRequests.delete(message.hash);\n this._resultCache.set(message.hash, message);\n for (const workerCallback of workerCallbacks) {\n workerCallback(message);\n }\n // This should always be the last thing done with the worker\n this._pool.checkinWorker(worker);\n };\n\n worker.on('message', cb);\n worker.postMessage(request);\n })\n .catch((error: Error) => {\n const errorCallbacks: IModuleMinificationCallback[] = activeRequests.get(hash)!;\n for (const errorCallback of errorCallbacks) {\n errorCallback({\n hash,\n error,\n code: undefined,\n map: undefined\n });\n }\n });\n }\n\n /**\n * {@inheritdoc IModuleMinifier.connectAsync}\n */\n public async connectAsync(): Promise<IMinifierConnection> {\n if (++this._refCount === 1) {\n this._pool.reset();\n }\n\n const disconnectAsync: IMinifierConnection['disconnectAsync'] = async () => {\n if (--this._refCount === 0) {\n if (this._verbose) {\n // eslint-disable-next-line no-console\n console.log(`Shutting down minifier worker pool`);\n }\n await this._pool.finishAsync();\n this._resultCache.clear();\n this._activeRequests.clear();\n if (this._verbose) {\n // eslint-disable-next-line no-console\n console.log(`Module minification: ${this._deduped} Deduped, ${this._minified} Processed`);\n }\n }\n this._deduped = 0;\n this._minified = 0;\n };\n\n return {\n configHash: this._configHash,\n\n disconnectAsync,\n disconnect: disconnectAsync\n };\n }\n\n /**\n * @deprecated Use {@link WorkerPoolMinifier.connectAsync} instead\n */\n // eslint-disable-next-line @typescript-eslint/naming-convention\n public async connect(): Promise<IMinifierConnection> {\n return await this.connectAsync();\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"WorkerPoolMinifier.js","sourceRoot":"","sources":["../src/WorkerPoolMinifier.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;;;;;AAE3D,mCAAoC;AACpC,2BAA0B;AAG1B,gFAA6C;AAE7C,wDAAoD;AAqCpD;;;GAGG;AACH,MAAa,kBAAkB;IAY7B,YAAmB,OAAmC;QACpD,MAAM,EACJ,UAAU,GAAG,IAAA,SAAI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C;gBAC5F,CAAC;YACH,CAAC;YACD,IAAI,CAAC,QAAQ,GAAG,CAAC,CAAC;YAClB,IAAI,CAAC,SAAS,GAAG,CAAC,CAAC;QACrB,CAAC,CAAC;QAEF,OAAO;YACL,UAAU,EAAE,IAAI,CAAC,WAAW;YAE5B,eAAe;YACf,UAAU,EAAE,eAAe;SAC5B,CAAC;IACJ,CAAC;IAED;;OAEG;IACH,gEAAgE;IACzD,KAAK,CAAC,OAAO;QAClB,OAAO,MAAM,IAAI,CAAC,YAAY,EAAE,CAAC;IACnC,CAAC;CACF;AA7JD,gDA6JC","sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.\n// See LICENSE in the project root for license information.\n\nimport { createHash } from 'crypto';\nimport { cpus } from 'os';\nimport type { ResourceLimits } from 'worker_threads';\n\nimport serialize from 'serialize-javascript';\nimport type { MinifyOptions } from 'terser';\nimport { WorkerPool } from '@rushstack/worker-pool';\n\nimport type {\n IMinifierConnection,\n IModuleMinificationCallback,\n IModuleMinificationResult,\n IModuleMinificationRequest,\n IModuleMinifier\n} from './types';\n\n/**\n * Options for configuring the WorkerPoolMinifier\n * @public\n */\nexport interface IWorkerPoolMinifierOptions {\n /**\n * Maximum number of worker threads to use. Will never use more than there are modules to process.\n * Defaults to os.cpus().length\n */\n maxThreads?: number;\n /**\n * The options to forward to Terser.\n * `output.comments` is currently not configurable and will always extract license comments to a separate file.\n */\n terserOptions?: MinifyOptions;\n\n /**\n * If true, log to the console about the minification results.\n */\n verbose?: boolean;\n\n /**\n * Optional resource limits for the workers.\n */\n workerResourceLimits?: ResourceLimits;\n}\n\n/**\n * Minifier implementation that uses a thread pool for minification.\n * @public\n */\nexport class WorkerPoolMinifier implements IModuleMinifier {\n private readonly _pool: WorkerPool;\n private readonly _verbose: boolean;\n private readonly _configHash: string;\n\n private _refCount: number;\n private _deduped: number;\n private _minified: number;\n\n private readonly _resultCache: Map<string, IModuleMinificationResult>;\n private readonly _activeRequests: Map<string, IModuleMinificationCallback[]>;\n\n public constructor(options: IWorkerPoolMinifierOptions) {\n const {\n maxThreads = cpus().length,\n terserOptions = {},\n verbose = false,\n workerResourceLimits\n } = options || {};\n\n const activeRequests: Map<string, IModuleMinificationCallback[]> = new Map();\n const resultCache: Map<string, IModuleMinificationResult> = new Map();\n const terserPool: WorkerPool = new WorkerPool({\n id: 'Minifier',\n maxWorkers: maxThreads,\n workerData: terserOptions,\n workerScriptPath: require.resolve('./MinifierWorker'),\n workerResourceLimits\n });\n\n const { version: terserVersion } = require('terser/package.json');\n\n this._configHash = createHash('sha256')\n .update(WorkerPoolMinifier.name, 'utf8')\n .update(`terser@${terserVersion}`)\n .update(serialize(terserOptions))\n .digest('base64');\n\n this._activeRequests = activeRequests;\n this._refCount = 0;\n this._resultCache = resultCache;\n this._pool = terserPool;\n this._verbose = verbose;\n\n this._deduped = 0;\n this._minified = 0;\n }\n\n public get maxThreads(): number {\n return this._pool.maxWorkers;\n }\n\n public set maxThreads(threads: number) {\n this._pool.maxWorkers = threads;\n }\n\n /**\n * Transform code by farming it out to a worker pool.\n * @param request - The request to process\n * @param callback - The callback to invoke\n */\n public minify(request: IModuleMinificationRequest, callback: IModuleMinificationCallback): void {\n const { hash } = request;\n\n const cached: IModuleMinificationResult | undefined = this._resultCache.get(hash);\n if (cached) {\n ++this._deduped;\n return callback(cached);\n }\n\n const { _activeRequests: activeRequests } = this;\n const callbacks: IModuleMinificationCallback[] | undefined = activeRequests.get(hash);\n if (callbacks) {\n ++this._deduped;\n callbacks.push(callback);\n return;\n }\n\n activeRequests.set(hash, [callback]);\n ++this._minified;\n\n this._pool\n .checkoutWorkerAsync(true)\n .then((worker) => {\n const cb: (message: IModuleMinificationResult) => void = (\n message: IModuleMinificationResult\n ): void => {\n worker.off('message', cb);\n const workerCallbacks: IModuleMinificationCallback[] | undefined = activeRequests.get(\n message.hash\n )!;\n activeRequests.delete(message.hash);\n this._resultCache.set(message.hash, message);\n for (const workerCallback of workerCallbacks) {\n workerCallback(message);\n }\n // This should always be the last thing done with the worker\n this._pool.checkinWorker(worker);\n };\n\n worker.on('message', cb);\n worker.postMessage(request);\n })\n .catch((error: Error) => {\n const errorCallbacks: IModuleMinificationCallback[] = activeRequests.get(hash)!;\n for (const errorCallback of errorCallbacks) {\n errorCallback({\n hash,\n error,\n code: undefined,\n map: undefined\n });\n }\n });\n }\n\n /**\n * {@inheritdoc IModuleMinifier.connectAsync}\n */\n public async connectAsync(): Promise<IMinifierConnection> {\n if (++this._refCount === 1) {\n this._pool.reset();\n }\n\n const disconnectAsync: IMinifierConnection['disconnectAsync'] = async () => {\n if (--this._refCount === 0) {\n if (this._verbose) {\n // eslint-disable-next-line no-console\n console.log(`Shutting down minifier worker pool`);\n }\n await this._pool.finishAsync();\n this._resultCache.clear();\n this._activeRequests.clear();\n if (this._verbose) {\n // eslint-disable-next-line no-console\n console.log(`Module minification: ${this._deduped} Deduped, ${this._minified} Processed`);\n }\n }\n this._deduped = 0;\n this._minified = 0;\n };\n\n return {\n configHash: this._configHash,\n\n disconnectAsync,\n disconnect: disconnectAsync\n };\n }\n\n /**\n * @deprecated Use {@link WorkerPoolMinifier.connectAsync} instead\n */\n // eslint-disable-next-line @typescript-eslint/naming-convention\n public async connect(): Promise<IMinifierConnection> {\n return await this.connectAsync();\n }\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rushstack/module-minifier",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0",
|
|
4
4
|
"description": "Wrapper for terser to support bulk parallel minification.",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"typings": "dist/module-minifier.d.ts",
|
|
@@ -14,12 +14,12 @@
|
|
|
14
14
|
"serialize-javascript": "6.0.0",
|
|
15
15
|
"source-map": "~0.7.3",
|
|
16
16
|
"terser": "^5.9.0",
|
|
17
|
-
"@rushstack/worker-pool": "0.
|
|
17
|
+
"@rushstack/worker-pool": "0.5.0"
|
|
18
18
|
},
|
|
19
19
|
"devDependencies": {
|
|
20
20
|
"@types/serialize-javascript": "5.0.2",
|
|
21
|
-
"
|
|
22
|
-
"
|
|
21
|
+
"@rushstack/heft": "0.68.13",
|
|
22
|
+
"local-node-rig": "1.0.0"
|
|
23
23
|
},
|
|
24
24
|
"peerDependencies": {
|
|
25
25
|
"@types/node": "*"
|