@rushstack/module-minifier 0.7.1 → 0.7.3
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
CHANGED
|
@@ -1,6 +1,46 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rushstack/module-minifier",
|
|
3
3
|
"entries": [
|
|
4
|
+
{
|
|
5
|
+
"version": "0.7.3",
|
|
6
|
+
"tag": "@rushstack/module-minifier_v0.7.3",
|
|
7
|
+
"date": "Wed, 12 Feb 2025 01:10:52 GMT",
|
|
8
|
+
"comments": {
|
|
9
|
+
"patch": [
|
|
10
|
+
{
|
|
11
|
+
"comment": "Bump the `serialize-javascript` dependency."
|
|
12
|
+
}
|
|
13
|
+
],
|
|
14
|
+
"dependency": [
|
|
15
|
+
{
|
|
16
|
+
"comment": "Updating dependency \"@rushstack/worker-pool\" to `0.5.3`"
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
"comment": "Updating dependency \"@rushstack/heft\" to `0.68.16`"
|
|
20
|
+
}
|
|
21
|
+
]
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
"version": "0.7.2",
|
|
26
|
+
"tag": "@rushstack/module-minifier_v0.7.2",
|
|
27
|
+
"date": "Thu, 30 Jan 2025 16:10:36 GMT",
|
|
28
|
+
"comments": {
|
|
29
|
+
"patch": [
|
|
30
|
+
{
|
|
31
|
+
"comment": "Prefer `os.availableParallelism()` to `os.cpus().length`."
|
|
32
|
+
}
|
|
33
|
+
],
|
|
34
|
+
"dependency": [
|
|
35
|
+
{
|
|
36
|
+
"comment": "Updating dependency \"@rushstack/worker-pool\" to `0.5.2`"
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
"comment": "Updating dependency \"@rushstack/heft\" to `0.68.15`"
|
|
40
|
+
}
|
|
41
|
+
]
|
|
42
|
+
}
|
|
43
|
+
},
|
|
4
44
|
{
|
|
5
45
|
"version": "0.7.1",
|
|
6
46
|
"tag": "@rushstack/module-minifier_v0.7.1",
|
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,20 @@
|
|
|
1
1
|
# Change Log - @rushstack/module-minifier
|
|
2
2
|
|
|
3
|
-
This log was last generated on
|
|
3
|
+
This log was last generated on Wed, 12 Feb 2025 01:10:52 GMT and should not be manually modified.
|
|
4
|
+
|
|
5
|
+
## 0.7.3
|
|
6
|
+
Wed, 12 Feb 2025 01:10:52 GMT
|
|
7
|
+
|
|
8
|
+
### Patches
|
|
9
|
+
|
|
10
|
+
- Bump the `serialize-javascript` dependency.
|
|
11
|
+
|
|
12
|
+
## 0.7.2
|
|
13
|
+
Thu, 30 Jan 2025 16:10:36 GMT
|
|
14
|
+
|
|
15
|
+
### Patches
|
|
16
|
+
|
|
17
|
+
- Prefer `os.availableParallelism()` to `os.cpus().length`.
|
|
4
18
|
|
|
5
19
|
## 0.7.1
|
|
6
20
|
Thu, 30 Jan 2025 01:11:42 GMT
|
|
@@ -168,7 +168,7 @@ export declare interface IModuleMinifierFunction {
|
|
|
168
168
|
export declare interface IWorkerPoolMinifierOptions {
|
|
169
169
|
/**
|
|
170
170
|
* Maximum number of worker threads to use. Will never use more than there are modules to process.
|
|
171
|
-
* Defaults to os.
|
|
171
|
+
* Defaults to os.availableParallelism()
|
|
172
172
|
*/
|
|
173
173
|
maxThreads?: number;
|
|
174
174
|
/**
|
package/dist/tsdoc-metadata.json
CHANGED
|
@@ -9,7 +9,7 @@ import type { IMinifierConnection, IModuleMinificationCallback, IModuleMinificat
|
|
|
9
9
|
export interface IWorkerPoolMinifierOptions {
|
|
10
10
|
/**
|
|
11
11
|
* Maximum number of worker threads to use. Will never use more than there are modules to process.
|
|
12
|
-
* Defaults to os.
|
|
12
|
+
* Defaults to os.availableParallelism()
|
|
13
13
|
*/
|
|
14
14
|
maxThreads?: number;
|
|
15
15
|
/**
|
|
@@ -7,7 +7,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
7
7
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
8
|
exports.WorkerPoolMinifier = void 0;
|
|
9
9
|
const crypto_1 = require("crypto");
|
|
10
|
-
const os_1 = require("os");
|
|
10
|
+
const os_1 = __importDefault(require("os"));
|
|
11
11
|
const serialize_javascript_1 = __importDefault(require("serialize-javascript"));
|
|
12
12
|
const worker_pool_1 = require("@rushstack/worker-pool");
|
|
13
13
|
/**
|
|
@@ -16,7 +16,8 @@ const worker_pool_1 = require("@rushstack/worker-pool");
|
|
|
16
16
|
*/
|
|
17
17
|
class WorkerPoolMinifier {
|
|
18
18
|
constructor(options) {
|
|
19
|
-
|
|
19
|
+
var _a, _b;
|
|
20
|
+
const { maxThreads = (_b = (_a = os_1.default.availableParallelism) === null || _a === void 0 ? void 0 : _a.call(os_1.default)) !== null && _b !== void 0 ? _b : os_1.default.cpus().length, terserOptions = {}, verbose = false, workerResourceLimits } = options || {};
|
|
20
21
|
const activeRequests = new Map();
|
|
21
22
|
const resultCache = new Map();
|
|
22
23
|
const terserPool = new worker_pool_1.WorkerPool({
|
|
@@ -1 +1 @@
|
|
|
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,GAAE,CAAC,MAAM,EAC1B,aAAa,GAAG,EAAE,EAClB,OAAO,GAAG,KAAK,EACf,oBAAoB,EACrB,GAAG,OAAO,IAAI,EAAE,CAAC;QAElB,MAAM,cAAc,GAA+C,IAAI,GAAG,EAAE,CAAC;QAC7E,MAAM,WAAW,GAA2C,IAAI,GAAG,EAAE,CAAC;QACtE,MAAM,UAAU,GAAe,IAAI,wBAAU,C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EAAgE;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"]}
|
|
1
|
+
{"version":3,"file":"WorkerPoolMinifier.js","sourceRoot":"","sources":["../src/WorkerPoolMinifier.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;;;;;AAE3D,mCAAoC;AACpC,4CAAoB;AAGpB,gFAA6C;AAE7C,wDAAoD;AAqCpD;;;GAGG;AACH,MAAa,kBAAkB;IAY7B,YAAmB,OAAmC;;QACpD,MAAM,EACJ,UAAU,GAAG,MAAA,MAAA,YAAE,CAAC,oBAAoB,4DAAI,mCAAI,YAAE,CAAC,IAAI,EAAE,CAAC,MAAM,EAC5D,aAAa,GAAG,EAAE,EAClB,OAAO,GAAG,KAAK,EACf,oBAAoB,EACrB,GAAG,OAAO,IAAI,EAAE,CAAC;QAElB,MAAM,cAAc,GAA+C,IAAI,GAAG,EAAE,CAAC;QAC7E,MAAM,WAAW,GAA2C,IAAI,GAAG,EAAE,CAAC;QACtE,MAAM,UAAU,GAAe,IAAI,wBAAU,CAAC;YAC5C,EAAE,EAAE,UAAU;YACd,UAAU,EAAE,UAAU;YACtB,UAAU,EAAE,aAAa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AC;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 os 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.availableParallelism()\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 = os.availableParallelism?.() ?? os.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.7.
|
|
3
|
+
"version": "0.7.3",
|
|
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",
|
|
@@ -11,15 +11,15 @@
|
|
|
11
11
|
"directory": "libraries/module-minifier"
|
|
12
12
|
},
|
|
13
13
|
"dependencies": {
|
|
14
|
-
"serialize-javascript": "6.0.
|
|
14
|
+
"serialize-javascript": "6.0.2",
|
|
15
15
|
"source-map": "~0.7.3",
|
|
16
16
|
"terser": "^5.9.0",
|
|
17
|
-
"@rushstack/worker-pool": "0.5.
|
|
17
|
+
"@rushstack/worker-pool": "0.5.3"
|
|
18
18
|
},
|
|
19
19
|
"devDependencies": {
|
|
20
20
|
"@types/serialize-javascript": "5.0.2",
|
|
21
|
-
"
|
|
22
|
-
"
|
|
21
|
+
"@rushstack/heft": "0.68.16",
|
|
22
|
+
"local-node-rig": "1.0.0"
|
|
23
23
|
},
|
|
24
24
|
"peerDependencies": {
|
|
25
25
|
"@types/node": "*"
|