@rushstack/module-minifier 0.7.29 → 0.8.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 CHANGED
@@ -1,6 +1,41 @@
1
1
  {
2
2
  "name": "@rushstack/module-minifier",
3
3
  "entries": [
4
+ {
5
+ "version": "0.8.0",
6
+ "tag": "@rushstack/module-minifier_v0.8.0",
7
+ "date": "Fri, 03 Oct 2025 20:09:59 GMT",
8
+ "comments": {
9
+ "minor": [
10
+ {
11
+ "comment": "Normalize import of builtin modules to use the `node:` protocol."
12
+ }
13
+ ],
14
+ "dependency": [
15
+ {
16
+ "comment": "Updating dependency \"@rushstack/worker-pool\" to `0.6.0`"
17
+ },
18
+ {
19
+ "comment": "Updating dependency \"@rushstack/heft\" to `1.1.0`"
20
+ }
21
+ ]
22
+ }
23
+ },
24
+ {
25
+ "version": "0.7.30",
26
+ "tag": "@rushstack/module-minifier_v0.7.30",
27
+ "date": "Tue, 30 Sep 2025 23:57:45 GMT",
28
+ "comments": {
29
+ "dependency": [
30
+ {
31
+ "comment": "Updating dependency \"@rushstack/worker-pool\" to `0.5.30`"
32
+ },
33
+ {
34
+ "comment": "Updating dependency \"@rushstack/heft\" to `1.0.0`"
35
+ }
36
+ ]
37
+ }
38
+ },
4
39
  {
5
40
  "version": "0.7.29",
6
41
  "tag": "@rushstack/module-minifier_v0.7.29",
package/CHANGELOG.md CHANGED
@@ -1,6 +1,18 @@
1
1
  # Change Log - @rushstack/module-minifier
2
2
 
3
- This log was last generated on Tue, 30 Sep 2025 20:33:51 GMT and should not be manually modified.
3
+ This log was last generated on Fri, 03 Oct 2025 20:09:59 GMT and should not be manually modified.
4
+
5
+ ## 0.8.0
6
+ Fri, 03 Oct 2025 20:09:59 GMT
7
+
8
+ ### Minor changes
9
+
10
+ - Normalize import of builtin modules to use the `node:` protocol.
11
+
12
+ ## 0.7.30
13
+ Tue, 30 Sep 2025 23:57:45 GMT
14
+
15
+ _Version update only_
4
16
 
5
17
  ## 0.7.29
6
18
  Tue, 30 Sep 2025 20:33:51 GMT
@@ -10,8 +10,8 @@
10
10
 
11
11
  import { MinifyOptions } from 'terser';
12
12
  import type { RawSourceMap } from 'source-map';
13
- import type { ResourceLimits } from 'worker_threads';
14
- import type * as WorkerThreads from 'worker_threads';
13
+ import type { ResourceLimits } from 'node:worker_threads';
14
+ import type * as WorkerThreads from 'node:worker_threads';
15
15
 
16
16
  /**
17
17
  * Gets a base54 string suitable for use as a JavaScript identifier, omitting those that are valid ECMAScript keywords
@@ -5,7 +5,7 @@
5
5
  "toolPackages": [
6
6
  {
7
7
  "packageName": "@microsoft/api-extractor",
8
- "packageVersion": "7.52.13"
8
+ "packageVersion": "7.52.15"
9
9
  }
10
10
  ]
11
11
  }
@@ -1 +1 @@
1
- {"version":3,"file":"LocalMinifier.d.ts","sourceRoot":"","sources":["../src/LocalMinifier.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,QAAQ,CAAC;AAE5C,OAAO,KAAK,EACV,mBAAmB,EACnB,2BAA2B,EAC3B,0BAA0B,EAE1B,eAAe,EAChB,MAAM,SAAS,CAAC;AAGjB;;;GAGG;AACH,MAAM,WAAW,qBAAqB;IACpC,aAAa,CAAC,EAAE,aAAa,CAAC;CAC/B;AAED;;;GAGG;AACH,qBAAa,aAAc,YAAW,eAAe;IACnD,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAgB;IAE/C,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAyC;IACtE,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAS;gBAElB,OAAO,EAAE,qBAAqB;IAuBjD;;;;OAIG;IACI,MAAM,CAAC,OAAO,EAAE,0BAA0B,EAAE,QAAQ,EAAE,2BAA2B,GAAG,IAAI;IAwB/F;;OAEG;IACU,YAAY,IAAI,OAAO,CAAC,mBAAmB,CAAC;IAWzD;;OAEG;IAEU,OAAO,IAAI,OAAO,CAAC,mBAAmB,CAAC;CAGrD"}
1
+ {"version":3,"file":"LocalMinifier.d.ts","sourceRoot":"","sources":["../src/LocalMinifier.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,QAAQ,CAAC;AAE5C,OAAO,KAAK,EACV,mBAAmB,EACnB,2BAA2B,EAC3B,0BAA0B,EAE1B,eAAe,EAChB,MAAM,SAAS,CAAC;AAGjB;;;GAGG;AACH,MAAM,WAAW,qBAAqB;IACpC,aAAa,CAAC,EAAE,aAAa,CAAC;CAC/B;AAED;;;GAGG;AACH,qBAAa,aAAc,YAAW,eAAe;IACnD,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAgB;IAE/C,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAyC;IACtE,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAS;gBAElB,OAAO,EAAE,qBAAqB;IAuBjD;;;;OAIG;IACI,MAAM,CAAC,OAAO,EAAE,0BAA0B,EAAE,QAAQ,EAAE,2BAA2B,GAAG,IAAI;IAwB/F;;OAEG;IACU,YAAY,IAAI,OAAO,CAAC,mBAAmB,CAAC;IAWzD;;OAEG;IAEU,OAAO,IAAI,OAAO,CAAC,mBAAmB,CAAC;CAGrD"}
@@ -6,7 +6,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
6
6
  };
7
7
  Object.defineProperty(exports, "__esModule", { value: true });
8
8
  exports.LocalMinifier = void 0;
9
- const crypto_1 = require("crypto");
9
+ const node_crypto_1 = require("node:crypto");
10
10
  const serialize_javascript_1 = __importDefault(require("serialize-javascript"));
11
11
  const MinifySingleFile_1 = require("./MinifySingleFile");
12
12
  /**
@@ -25,7 +25,7 @@ class LocalMinifier {
25
25
  : {}
26
26
  };
27
27
  const { version: terserVersion } = require('terser/package.json');
28
- this._configHash = (0, crypto_1.createHash)('sha256')
28
+ this._configHash = (0, node_crypto_1.createHash)('sha256')
29
29
  .update(LocalMinifier.name, 'utf8')
30
30
  .update(`terser@${terserVersion}`)
31
31
  .update((0, serialize_javascript_1.default)(terserOptions))
@@ -1 +1 @@
1
- {"version":3,"file":"LocalMinifier.js","sourceRoot":"","sources":["../src/LocalMinifier.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;;;;;AAE3D,mCAAoC;AACpC,gFAA6C;AAU7C,yDAA2D;AAU3D;;;GAGG;AACH,MAAa,aAAa;IAMxB,YAAmB,OAA8B;QAC/C,MAAM,EAAE,aAAa,GAAG,EAAE,EAAE,GAAG,OAAO,IAAI,EAAE,CAAC;QAE7C,IAAI,CAAC,cAAc,GAAG;YACpB,GAAG,aAAa;YAChB,MAAM,EAAE,aAAa,CAAC,MAAM;gBAC1B,CAAC,CAAC;oBACE,GAAG,aAAa,CAAC,MAAM;iBACxB;gBACH,CAAC,CAAC,EAAE;SACP,CAAC;QAEF,MAAM,EAAE,OAAO,EAAE,aAAa,EAAE,GAAG,OAAO,CAAC,qBAAqB,CAAC,CAAC;QAElE,IAAI,CAAC,WAAW,GAAG,IAAA,mBAAU,EAAC,QAAQ,CAAC;aACpC,MAAM,CAAC,aAAa,CAAC,IAAI,EAAE,MAAM,CAAC;aAClC,MAAM,CAAC,UAAU,aAAa,EAAE,CAAC;aACjC,MAAM,CAAC,IAAA,8BAAS,EAAC,aAAa,CAAC,CAAC;aAChC,MAAM,CAAC,QAAQ,CAAC,CAAC;QAEpB,IAAI,CAAC,YAAY,GAAG,IAAI,GAAG,EAAE,CAAC;IAChC,CAAC;IAED;;;;OAIG;IACI,MAAM,CAAC,OAAmC,EAAE,QAAqC;QACtF,MAAM,EAAE,IAAI,EAAE,GAAG,OAAO,CAAC;QAEzB,MAAM,MAAM,GAA0C,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QAClF,IAAI,MAAM,EAAE,CAAC;YACX,OAAO,QAAQ,CAAC,MAAM,CAAC,CAAC;QAC1B,CAAC;QAED,IAAA,wCAAqB,EAAC,OAAO,EAAE,IAAI,CAAC,cAAc,CAAC;aAChD,IAAI,CAAC,CAAC,MAAiC,EAAE,EAAE;YAC1C,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;YACpC,QAAQ,CAAC,MAAM,CAAC,CAAC;QACnB,CAAC,CAAC;aACD,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE;YACf,oEAAoE;YACpE,QAAQ,CAAC;gBACP,KAAK,EAAE,KAAc;gBACrB,IAAI,EAAE,SAAS;gBACf,GAAG,EAAE,SAAS;gBACd,IAAI;aACL,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACP,CAAC;IAED;;OAEG;IACI,KAAK,CAAC,YAAY;QACvB,MAAM,eAAe,GAA2C,KAAK,IAAI,EAAE;YACzE,cAAc;QAChB,CAAC,CAAC;QACF,OAAO;YACL,UAAU,EAAE,IAAI,CAAC,WAAW;YAC5B,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;AA/ED,sCA+EC","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 serialize from 'serialize-javascript';\nimport type { MinifyOptions } from 'terser';\n\nimport type {\n IMinifierConnection,\n IModuleMinificationCallback,\n IModuleMinificationRequest,\n IModuleMinificationResult,\n IModuleMinifier\n} from './types';\nimport { minifySingleFileAsync } from './MinifySingleFile';\n\n/**\n * Options for configuring the LocalMinifier\n * @public\n */\nexport interface ILocalMinifierOptions {\n terserOptions?: MinifyOptions;\n}\n\n/**\n * Minifier implementation that minifies code on the main thread.\n * @public\n */\nexport class LocalMinifier implements IModuleMinifier {\n private readonly _terserOptions: MinifyOptions;\n\n private readonly _resultCache: Map<string, IModuleMinificationResult>;\n private readonly _configHash: string;\n\n public constructor(options: ILocalMinifierOptions) {\n const { terserOptions = {} } = options || {};\n\n this._terserOptions = {\n ...terserOptions,\n output: terserOptions.output\n ? {\n ...terserOptions.output\n }\n : {}\n };\n\n const { version: terserVersion } = require('terser/package.json');\n\n this._configHash = createHash('sha256')\n .update(LocalMinifier.name, 'utf8')\n .update(`terser@${terserVersion}`)\n .update(serialize(terserOptions))\n .digest('base64');\n\n this._resultCache = new Map();\n }\n\n /**\n * Transform that invokes Terser on the main thread\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 return callback(cached);\n }\n\n minifySingleFileAsync(request, this._terserOptions)\n .then((result: IModuleMinificationResult) => {\n this._resultCache.set(hash, result);\n callback(result);\n })\n .catch((error) => {\n // This branch is here to satisfy the no-floating-promises lint rule\n callback({\n error: error as Error,\n code: undefined,\n map: undefined,\n hash\n });\n });\n }\n\n /**\n * {@inheritdoc IModuleMinifier.connectAsync}\n */\n public async connectAsync(): Promise<IMinifierConnection> {\n const disconnectAsync: IMinifierConnection['disconnectAsync'] = async () => {\n // Do nothing.\n };\n return {\n configHash: this._configHash,\n disconnectAsync,\n disconnect: disconnectAsync\n };\n }\n\n /**\n * @deprecated Use {@link LocalMinifier.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":"LocalMinifier.js","sourceRoot":"","sources":["../src/LocalMinifier.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;;;;;AAE3D,6CAAyC;AAEzC,gFAA6C;AAU7C,yDAA2D;AAU3D;;;GAGG;AACH,MAAa,aAAa;IAMxB,YAAmB,OAA8B;QAC/C,MAAM,EAAE,aAAa,GAAG,EAAE,EAAE,GAAG,OAAO,IAAI,EAA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gBACd,IAAI;aACL,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACP,CAAC;IAED;;OAEG;IACI,KAAK,CAAC,YAAY;QACvB,MAAM,eAAe,GAA2C,KAAK,IAAI,EAAE;YACzE,cAAc;QAChB,CAAC,CAAC;QACF,OAAO;YACL,UAAU,EAAE,IAAI,CAAC,WAAW;YAC5B,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;AA/ED,sCA+EC","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 'node:crypto';\n\nimport serialize from 'serialize-javascript';\nimport type { MinifyOptions } from 'terser';\n\nimport type {\n IMinifierConnection,\n IModuleMinificationCallback,\n IModuleMinificationRequest,\n IModuleMinificationResult,\n IModuleMinifier\n} from './types';\nimport { minifySingleFileAsync } from './MinifySingleFile';\n\n/**\n * Options for configuring the LocalMinifier\n * @public\n */\nexport interface ILocalMinifierOptions {\n terserOptions?: MinifyOptions;\n}\n\n/**\n * Minifier implementation that minifies code on the main thread.\n * @public\n */\nexport class LocalMinifier implements IModuleMinifier {\n private readonly _terserOptions: MinifyOptions;\n\n private readonly _resultCache: Map<string, IModuleMinificationResult>;\n private readonly _configHash: string;\n\n public constructor(options: ILocalMinifierOptions) {\n const { terserOptions = {} } = options || {};\n\n this._terserOptions = {\n ...terserOptions,\n output: terserOptions.output\n ? {\n ...terserOptions.output\n }\n : {}\n };\n\n const { version: terserVersion } = require('terser/package.json');\n\n this._configHash = createHash('sha256')\n .update(LocalMinifier.name, 'utf8')\n .update(`terser@${terserVersion}`)\n .update(serialize(terserOptions))\n .digest('base64');\n\n this._resultCache = new Map();\n }\n\n /**\n * Transform that invokes Terser on the main thread\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 return callback(cached);\n }\n\n minifySingleFileAsync(request, this._terserOptions)\n .then((result: IModuleMinificationResult) => {\n this._resultCache.set(hash, result);\n callback(result);\n })\n .catch((error) => {\n // This branch is here to satisfy the no-floating-promises lint rule\n callback({\n error: error as Error,\n code: undefined,\n map: undefined,\n hash\n });\n });\n }\n\n /**\n * {@inheritdoc IModuleMinifier.connectAsync}\n */\n public async connectAsync(): Promise<IMinifierConnection> {\n const disconnectAsync: IMinifierConnection['disconnectAsync'] = async () => {\n // Do nothing.\n };\n return {\n configHash: this._configHash,\n disconnectAsync,\n disconnect: disconnectAsync\n };\n }\n\n /**\n * @deprecated Use {@link LocalMinifier.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,4 +1,4 @@
1
- import type * as WorkerThreads from 'worker_threads';
1
+ import type * as WorkerThreads from 'node:worker_threads';
2
2
  import type { IMinifierConnection, IModuleMinificationCallback, IModuleMinificationRequest, IModuleMinifier } from './types';
3
3
  /**
4
4
  * Minifier implementation that outsources requests to the other side of a MessagePort
@@ -1 +1 @@
1
- {"version":3,"file":"MessagePortMinifier.d.ts","sourceRoot":"","sources":["../src/MessagePortMinifier.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,KAAK,aAAa,MAAM,gBAAgB,CAAC;AAErD,OAAO,KAAK,EACV,mBAAmB,EACnB,2BAA2B,EAC3B,0BAA0B,EAE1B,eAAe,EAChB,MAAM,SAAS,CAAC;AAEjB;;;GAGG;AACH,qBAAa,mBAAoB,YAAW,eAAe;IACzD,SAAgB,IAAI,EAAE,aAAa,CAAC,WAAW,CAAC;IAEhD,OAAO,CAAC,QAAQ,CAAC,UAAU,CAA6C;gBAErD,IAAI,EAAE,aAAa,CAAC,WAAW;IAKlD;;;;OAIG;IACI,MAAM,CAAC,OAAO,EAAE,0BAA0B,EAAE,QAAQ,EAAE,2BAA2B,GAAG,IAAI;IAc/F;;OAEG;IACU,YAAY,IAAI,OAAO,CAAC,mBAAmB,CAAC;IA6BzD;;OAEG;IAEU,OAAO,IAAI,OAAO,CAAC,mBAAmB,CAAC;CAGrD"}
1
+ {"version":3,"file":"MessagePortMinifier.d.ts","sourceRoot":"","sources":["../src/MessagePortMinifier.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,KAAK,aAAa,MAAM,qBAAqB,CAAC;AAE1D,OAAO,KAAK,EACV,mBAAmB,EACnB,2BAA2B,EAC3B,0BAA0B,EAE1B,eAAe,EAChB,MAAM,SAAS,CAAC;AAEjB;;;GAGG;AACH,qBAAa,mBAAoB,YAAW,eAAe;IACzD,SAAgB,IAAI,EAAE,aAAa,CAAC,WAAW,CAAC;IAEhD,OAAO,CAAC,QAAQ,CAAC,UAAU,CAA6C;gBAErD,IAAI,EAAE,aAAa,CAAC,WAAW;IAKlD;;;;OAIG;IACI,MAAM,CAAC,OAAO,EAAE,0BAA0B,EAAE,QAAQ,EAAE,2BAA2B,GAAG,IAAI;IAc/F;;OAEG;IACU,YAAY,IAAI,OAAO,CAAC,mBAAmB,CAAC;IA6BzD;;OAEG;IAEU,OAAO,IAAI,OAAO,CAAC,mBAAmB,CAAC;CAGrD"}
@@ -3,7 +3,7 @@
3
3
  // See LICENSE in the project root for license information.
4
4
  Object.defineProperty(exports, "__esModule", { value: true });
5
5
  exports.MessagePortMinifier = void 0;
6
- const events_1 = require("events");
6
+ const node_events_1 = require("node:events");
7
7
  /**
8
8
  * Minifier implementation that outsources requests to the other side of a MessagePort
9
9
  * @public
@@ -32,7 +32,7 @@ class MessagePortMinifier {
32
32
  * {@inheritdoc IModuleMinifier.connectAsync}
33
33
  */
34
34
  async connectAsync() {
35
- const configHashPromise = (0, events_1.once)(this.port, 'message');
35
+ const configHashPromise = (0, node_events_1.once)(this.port, 'message');
36
36
  this.port.postMessage('initialize');
37
37
  const configHash = await configHashPromise;
38
38
  const callbacks = this._callbacks;
@@ -1 +1 @@
1
- {"version":3,"file":"MessagePortMinifier.js","sourceRoot":"","sources":["../src/MessagePortMinifier.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;;AAE3D,mCAA8B;AAW9B;;;GAGG;AACH,MAAa,mBAAmB;IAK9B,YAAmB,IAA+B;QAChD,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,UAAU,GAAG,IAAI,GAAG,EAAE,CAAC;IAC9B,CAAC;IAED;;;;OAIG;IACI,MAAM,CAAC,OAAmC,EAAE,QAAqC;QACtF,MAAM,EAAE,IAAI,EAAE,GAAG,OAAO,CAAC;QAEzB,MAAM,SAAS,GAA8C,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QACvF,IAAI,SAAS,EAAE,CAAC;YACd,SAAS,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;YACzB,OAAO;QACT,CAAC;QAED,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC,QAAQ,CAAC,CAAC,CAAC;QAEtC,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC;IACjC,CAAC;IAED;;OAEG;IACI,KAAK,CAAC,YAAY;QACvB,MAAM,iBAAiB,GAAoB,IAAA,aAAI,EAAC,IAAI,CAAC,IAAI,EAAE,SAAS,CAA+B,CAAC;QACpG,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,YAAY,CAAC,CAAC;QACpC,MAAM,UAAU,GAAW,MAAM,iBAAiB,CAAC;QAEnD,MAAM,SAAS,GAA+C,IAAI,CAAC,UAAU,CAAC;QAE9E,SAAS,OAAO,CAAC,OAAmD;YAClE,IAAI,OAAO,OAAO,KAAK,QAAQ,EAAE,CAAC;gBAChC,MAAM,mBAAmB,GAAkC,SAAS,CAAC,GAAG,CAAC,OAAO,CAAC,IAAI,CAAE,CAAC;gBACxF,SAAS,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;gBAC/B,KAAK,MAAM,QAAQ,IAAI,mBAAmB,EAAE,CAAC;oBAC3C,QAAQ,CAAC,OAAO,CAAC,CAAC;gBACpB,CAAC;YACH,CAAC;QACH,CAAC;QAED,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC;QACjC,MAAM,eAAe,GAA2C,KAAK,IAAI,EAAE;YACzE,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC;YAClC,IAAI,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC;QACpB,CAAC,CAAC;QACF,OAAO;YACL,UAAU;YACV,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;AApED,kDAoEC","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 { once } from 'events';\nimport type * as WorkerThreads from 'worker_threads';\n\nimport type {\n IMinifierConnection,\n IModuleMinificationCallback,\n IModuleMinificationRequest,\n IModuleMinificationResult,\n IModuleMinifier\n} from './types';\n\n/**\n * Minifier implementation that outsources requests to the other side of a MessagePort\n * @public\n */\nexport class MessagePortMinifier implements IModuleMinifier {\n public readonly port: WorkerThreads.MessagePort;\n\n private readonly _callbacks: Map<string, IModuleMinificationCallback[]>;\n\n public constructor(port: WorkerThreads.MessagePort) {\n this.port = port;\n this._callbacks = new Map();\n }\n\n /**\n * No-op code transform.\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 callbacks: IModuleMinificationCallback[] | undefined = this._callbacks.get(hash);\n if (callbacks) {\n callbacks.push(callback);\n return;\n }\n\n this._callbacks.set(hash, [callback]);\n\n this.port.postMessage(request);\n }\n\n /**\n * {@inheritdoc IModuleMinifier.connectAsync}\n */\n public async connectAsync(): Promise<IMinifierConnection> {\n const configHashPromise: Promise<string> = once(this.port, 'message') as unknown as Promise<string>;\n this.port.postMessage('initialize');\n const configHash: string = await configHashPromise;\n\n const callbacks: Map<string, IModuleMinificationCallback[]> = this._callbacks;\n\n function handler(message: IModuleMinificationResult | number | false): void {\n if (typeof message === 'object') {\n const callbacksForRequest: IModuleMinificationCallback[] = callbacks.get(message.hash)!;\n callbacks.delete(message.hash);\n for (const callback of callbacksForRequest) {\n callback(message);\n }\n }\n }\n\n this.port.on('message', handler);\n const disconnectAsync: IMinifierConnection['disconnectAsync'] = async () => {\n this.port.off('message', handler);\n this.port.close();\n };\n return {\n configHash,\n disconnectAsync,\n disconnect: disconnectAsync\n };\n }\n\n /**\n * @deprecated Use {@link MessagePortMinifier.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":"MessagePortMinifier.js","sourceRoot":"","sources":["../src/MessagePortMinifier.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;;AAE3D,6CAAmC;AAWnC;;;GAGG;AACH,MAAa,mBAAmB;IAK9B,YAAmB,IAA+B;QAChD,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,UAAU,GAAG,IAAI,GAAG,EAAE,CAAC;IAC9B,CAAC;IAED;;;;OAIG;IACI,MAAM,CAAC,OAAmC,EAAE,QAAqC;QACtF,MAAM,EAAE,IAAI,EAAE,GAAG,OAAO,CAAC;QAEzB,MAAM,SAAS,GAA8C,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC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;;OAEG;IACH,gEAAgE;IACzD,KAAK,CAAC,OAAO;QAClB,OAAO,MAAM,IAAI,CAAC,YAAY,EAAE,CAAC;IACnC,CAAC;CACF;AApED,kDAoEC","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 { once } from 'node:events';\nimport type * as WorkerThreads from 'node:worker_threads';\n\nimport type {\n IMinifierConnection,\n IModuleMinificationCallback,\n IModuleMinificationRequest,\n IModuleMinificationResult,\n IModuleMinifier\n} from './types';\n\n/**\n * Minifier implementation that outsources requests to the other side of a MessagePort\n * @public\n */\nexport class MessagePortMinifier implements IModuleMinifier {\n public readonly port: WorkerThreads.MessagePort;\n\n private readonly _callbacks: Map<string, IModuleMinificationCallback[]>;\n\n public constructor(port: WorkerThreads.MessagePort) {\n this.port = port;\n this._callbacks = new Map();\n }\n\n /**\n * No-op code transform.\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 callbacks: IModuleMinificationCallback[] | undefined = this._callbacks.get(hash);\n if (callbacks) {\n callbacks.push(callback);\n return;\n }\n\n this._callbacks.set(hash, [callback]);\n\n this.port.postMessage(request);\n }\n\n /**\n * {@inheritdoc IModuleMinifier.connectAsync}\n */\n public async connectAsync(): Promise<IMinifierConnection> {\n const configHashPromise: Promise<string> = once(this.port, 'message') as unknown as Promise<string>;\n this.port.postMessage('initialize');\n const configHash: string = await configHashPromise;\n\n const callbacks: Map<string, IModuleMinificationCallback[]> = this._callbacks;\n\n function handler(message: IModuleMinificationResult | number | false): void {\n if (typeof message === 'object') {\n const callbacksForRequest: IModuleMinificationCallback[] = callbacks.get(message.hash)!;\n callbacks.delete(message.hash);\n for (const callback of callbacksForRequest) {\n callback(message);\n }\n }\n }\n\n this.port.on('message', handler);\n const disconnectAsync: IMinifierConnection['disconnectAsync'] = async () => {\n this.port.off('message', handler);\n this.port.close();\n };\n return {\n configHash,\n disconnectAsync,\n disconnect: disconnectAsync\n };\n }\n\n /**\n * @deprecated Use {@link MessagePortMinifier.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"]}
@@ -2,22 +2,22 @@
2
2
  // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
3
3
  // See LICENSE in the project root for license information.
4
4
  Object.defineProperty(exports, "__esModule", { value: true });
5
- const worker_threads_1 = require("worker_threads");
5
+ const node_worker_threads_1 = require("node:worker_threads");
6
6
  const MinifySingleFile_1 = require("./MinifySingleFile");
7
- const terserOptions = worker_threads_1.workerData;
7
+ const terserOptions = node_worker_threads_1.workerData;
8
8
  // Set to non-zero to help debug unexpected graceful exit
9
9
  process.exitCode = 2;
10
10
  async function handler(message) {
11
11
  if (!message) {
12
- worker_threads_1.parentPort.off('postMessage', handler);
13
- worker_threads_1.parentPort.close();
12
+ node_worker_threads_1.parentPort.off('postMessage', handler);
13
+ node_worker_threads_1.parentPort.close();
14
14
  return;
15
15
  }
16
16
  const result = await (0, MinifySingleFile_1.minifySingleFileAsync)(message, terserOptions);
17
- worker_threads_1.parentPort.postMessage(result);
17
+ node_worker_threads_1.parentPort.postMessage(result);
18
18
  }
19
- worker_threads_1.parentPort.once('close', () => {
19
+ node_worker_threads_1.parentPort.once('close', () => {
20
20
  process.exitCode = 0;
21
21
  });
22
- worker_threads_1.parentPort.on('message', handler);
22
+ node_worker_threads_1.parentPort.on('message', handler);
23
23
  //# sourceMappingURL=MinifierWorker.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"MinifierWorker.js","sourceRoot":"","sources":["../src/MinifierWorker.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;AAG3D,mDAAwD;AAExD,yDAA2D;AAG3D,MAAM,aAAa,GAAkB,2BAAU,CAAC;AAEhD,yDAAyD;AACzD,OAAO,CAAC,QAAQ,GAAG,CAAC,CAAC;AAErB,KAAK,UAAU,OAAO,CAAC,OAAmC;IACxD,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,2BAAW,CAAC,GAAG,CAAC,aAAa,EAAE,OAAO,CAAC,CAAC;QACxC,2BAAW,CAAC,KAAK,EAAE,CAAC;QACpB,OAAO;IACT,CAAC;IAED,MAAM,MAAM,GAA8B,MAAM,IAAA,wCAAqB,EAAC,OAAO,EAAE,aAAa,CAAC,CAAC;IAE9F,2BAAW,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC;AAClC,CAAC;AAED,2BAAW,CAAC,IAAI,CAAC,OAAO,EAAE,GAAG,EAAE;IAC7B,OAAO,CAAC,QAAQ,GAAG,CAAC,CAAC;AACvB,CAAC,CAAC,CAAC;AACH,2BAAW,CAAC,EAAE,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC","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 type { MinifyOptions } from 'terser';\nimport { parentPort, workerData } from 'worker_threads';\n\nimport { minifySingleFileAsync } from './MinifySingleFile';\nimport type { IModuleMinificationRequest, IModuleMinificationResult } from './types';\n\nconst terserOptions: MinifyOptions = workerData;\n\n// Set to non-zero to help debug unexpected graceful exit\nprocess.exitCode = 2;\n\nasync function handler(message: IModuleMinificationRequest): Promise<void> {\n if (!message) {\n parentPort!.off('postMessage', handler);\n parentPort!.close();\n return;\n }\n\n const result: IModuleMinificationResult = await minifySingleFileAsync(message, terserOptions);\n\n parentPort!.postMessage(result);\n}\n\nparentPort!.once('close', () => {\n process.exitCode = 0;\n});\nparentPort!.on('message', handler);\n"]}
1
+ {"version":3,"file":"MinifierWorker.js","sourceRoot":"","sources":["../src/MinifierWorker.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;AAE3D,6DAA6D;AAI7D,yDAA2D;AAG3D,MAAM,aAAa,GAAkB,gCAAU,CAAC;AAEhD,yDAAyD;AACzD,OAAO,CAAC,QAAQ,GAAG,CAAC,CAAC;AAErB,KAAK,UAAU,OAAO,CAAC,OAAmC;IACxD,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,gCAAW,CAAC,GAAG,CAAC,aAAa,EAAE,OAAO,CAAC,CAAC;QACxC,gCAAW,CAAC,KAAK,EAAE,CAAC;QACpB,OAAO;IACT,CAAC;IAED,MAAM,MAAM,GAA8B,MAAM,IAAA,wCAAqB,EAAC,OAAO,EAAE,aAAa,CAAC,CAAC;IAE9F,gCAAW,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC;AAClC,CAAC;AAED,gCAAW,CAAC,IAAI,CAAC,OAAO,EAAE,GAAG,EAAE;IAC7B,OAAO,CAAC,QAAQ,GAAG,CAAC,CAAC;AACvB,CAAC,CAAC,CAAC;AACH,gCAAW,CAAC,EAAE,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC","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 { parentPort, workerData } from 'node:worker_threads';\n\nimport type { MinifyOptions } from 'terser';\n\nimport { minifySingleFileAsync } from './MinifySingleFile';\nimport type { IModuleMinificationRequest, IModuleMinificationResult } from './types';\n\nconst terserOptions: MinifyOptions = workerData;\n\n// Set to non-zero to help debug unexpected graceful exit\nprocess.exitCode = 2;\n\nasync function handler(message: IModuleMinificationRequest): Promise<void> {\n if (!message) {\n parentPort!.off('postMessage', handler);\n parentPort!.close();\n return;\n }\n\n const result: IModuleMinificationResult = await minifySingleFileAsync(message, terserOptions);\n\n parentPort!.postMessage(result);\n}\n\nparentPort!.once('close', () => {\n process.exitCode = 0;\n});\nparentPort!.on('message', handler);\n"]}
@@ -1,4 +1,4 @@
1
- import type { ResourceLimits } from 'worker_threads';
1
+ import type { ResourceLimits } from 'node:worker_threads';
2
2
  import type { MinifyOptions } from 'terser';
3
3
  import type { IMinifierConnection, IModuleMinificationCallback, IModuleMinificationRequest, IModuleMinifier }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AEU,OAAO,IAAI,OAAO,CAAC,mBAAmB,CAAC;CAGrD"}
@@ -6,8 +6,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
6
6
  };
7
7
  Object.defineProperty(exports, "__esModule", { value: true });
8
8
  exports.WorkerPoolMinifier = void 0;
9
- const crypto_1 = require("crypto");
10
- const os_1 = __importDefault(require("os"));
9
+ const node_crypto_1 = require("node:crypto");
10
+ const node_os_1 = __importDefault(require("node:os"));
11
11
  const serialize_javascript_1 = __importDefault(require("serialize-javascript"));
12
12
  const worker_pool_1 = require("@rushstack/worker-pool");
13
13
  /**
@@ -17,7 +17,7 @@ const worker_pool_1 = require("@rushstack/worker-pool");
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
+ const { maxThreads = (_b = (_a = node_os_1.default.availableParallelism) === null || _a === void 0 ? void 0 : _a.call(node_os_1.default)) !== null && _b !== void 0 ? _b : node_os_1.default.cpus().length, terserOptions = {}, verbose = false, workerResourceLimits } = options || {};
21
21
  const activeRequests = new Map();
22
22
  const resultCache = new Map();
23
23
  const terserPool = new worker_pool_1.WorkerPool({
@@ -28,7 +28,7 @@ class WorkerPoolMinifier {
28
28
  workerResourceLimits
29
29
  });
30
30
  const { version: terserVersion } = require('terser/package.json');
31
- this._configHash = (0, crypto_1.createHash)('sha256')
31
+ this._configHash = (0, node_crypto_1.createHash)('sha256')
32
32
  .update(WorkerPoolMinifier.name, 'utf8')
33
33
  .update(`terser@${terserVersion}`)
34
34
  .update((0, serialize_javascript_1.default)(terserOptions))
@@ -1 +1 @@
1
- {"version":3,"file":"WorkerPoolMinifier.js","sourceRoot":"","sources":["../src/WorkerPoolMinifier.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2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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;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"]}
1
+ {"version":3,"file":"WorkerPoolMinifier.js","sourceRoot":"","sources":["../src/WorkerPoolMinifier.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;;;;;AAE3D,6CAAyC;AACzC,sDAAyB;AAGzB,gFAA6C;AAG7C,wDAA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BAC7B,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;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 'node:crypto';\nimport os from 'node:os';\nimport type { ResourceLimits } from 'node:worker_threads';\n\nimport serialize from 'serialize-javascript';\nimport type { MinifyOptions } from 'terser';\n\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.29",
3
+ "version": "0.8.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,14 +14,14 @@
14
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.29"
17
+ "@rushstack/worker-pool": "0.6.0"
18
18
  },
19
19
  "devDependencies": {
20
20
  "@types/node": "20.17.19",
21
21
  "@types/serialize-javascript": "5.0.2",
22
22
  "eslint": "~9.25.1",
23
- "local-node-rig": "1.0.0",
24
- "@rushstack/heft": "0.75.0"
23
+ "@rushstack/heft": "1.1.0",
24
+ "local-node-rig": "1.0.0"
25
25
  },
26
26
  "peerDependencies": {
27
27
  "@types/node": "*"