@rushstack/module-minifier 0.4.3 → 0.4.4

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.
@@ -8,7 +8,7 @@
8
8
 
9
9
  /// <reference types="node" />
10
10
 
11
- import { MessagePort as MessagePort_2 } from 'worker_threads';
11
+ import type { MessagePort as MessagePort_2 } from 'worker_threads';
12
12
  import { MinifyOptions } from 'terser';
13
13
  import type { RawSourceMap } from 'source-map';
14
14
 
@@ -1,5 +1,5 @@
1
1
  /// <reference types="node" />
2
- import { MessagePort } from 'worker_threads';
2
+ import type { MessagePort } from 'worker_threads';
3
3
  import type { IMinifierConnection, IModuleMinificationCallback, IModuleMinificationRequest, IModuleMinifier } from './types';
4
4
  /**
5
5
  * 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,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAE7C,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,WAAW,CAAC;IAElC,OAAO,CAAC,QAAQ,CAAC,UAAU,CAA6C;gBAErD,IAAI,EAAE,WAAW;IAKpC;;;;OAIG;IACI,MAAM,CAAC,OAAO,EAAE,0BAA0B,EAAE,QAAQ,EAAE,2BAA2B,GAAG,IAAI;IAclF,OAAO,IAAI,OAAO,CAAC,mBAAmB,CAAC;CA0BrD"}
1
+ {"version":3,"file":"MessagePortMinifier.d.ts","sourceRoot":"","sources":["../src/MessagePortMinifier.ts"],"names":[],"mappings":";AAIA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAElD,OAAO,KAAK,EACV,mBAAmB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,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;gBAC/B,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;oBAC1C,QAAQ,CAAC,OAAO,CAAC,CAAC;iBACnB;aACF;QACH,CAAC;QAED,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC;QACjC,OAAO;YACL,UAAU;YACV,UAAU,EAAE,KAAK,IAAI,EAAE;gBACrB,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC;gBAClC,IAAI,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC;YACpB,CAAC;SACF,CAAC;IACJ,CAAC;CACF;AAvDD,kDAuDC","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 { MessagePort } 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: MessagePort;\n\n private readonly _callbacks: Map<string, IModuleMinificationCallback[]>;\n\n public constructor(port: 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 public async connect(): 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 return {\n configHash,\n disconnect: async () => {\n this.port.off('message', handler);\n this.port.close();\n }\n };\n }\n}\n"]}
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,IAAiB;QAClC,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;YACb,SAAS,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;YACzB,OAAO;SACR;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;IAEM,KAAK,CAAC,OAAO;QAClB,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;gBAC/B,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;oBAC1C,QAAQ,CAAC,OAAO,CAAC,CAAC;iBACnB;aACF;QACH,CAAC;QAED,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC;QACjC,OAAO;YACL,UAAU;YACV,UAAU,EAAE,KAAK,IAAI,EAAE;gBACrB,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC;gBAClC,IAAI,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC;YACpB,CAAC;SACF,CAAC;IACJ,CAAC;CACF;AAvDD,kDAuDC","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 { MessagePort } 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: MessagePort;\n\n private readonly _callbacks: Map<string, IModuleMinificationCallback[]>;\n\n public constructor(port: 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 public async connect(): 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 return {\n configHash,\n disconnect: async () => {\n this.port.off('message', handler);\n this.port.close();\n }\n };\n }\n}\n"]}
@@ -1,4 +1,4 @@
1
- import { MinifyOptions } from 'terser';
1
+ import { type MinifyOptions } from 'terser';
2
2
  declare module 'terser' {
3
3
  interface SourceMapOptions {
4
4
  asObject?: boolean;
@@ -1 +1 @@
1
- {"version":3,"file":"MinifySingleFile.d.ts","sourceRoot":"","sources":["../src/MinifySingleFile.ts"],"names":[],"mappings":"AAGA,OAAO,EAAU,aAAa,EAAyC,MAAM,QAAQ,CAAC;AAGtF,OAAO,QAAQ,QAAQ,CAAC;IAEtB,UAAU,gBAAgB;QACxB,QAAQ,CAAC,EAAE,OAAO,CAAC;KACpB;CACF;AAGD,OAAO,KAAK,EAAE,0BAA0B,EAAE,yBAAyB,EAAE,MAAM,SAAS,CAAC;AAMrF;;;GAGG;AACH,wBAAsB,qBAAqB,CACzC,OAAO,EAAE,0BAA0B,EACnC,aAAa,EAAE,aAAa,GAC3B,OAAO,CAAC,yBAAyB,CAAC,CA2DpC"}
1
+ {"version":3,"file":"MinifySingleFile.d.ts","sourceRoot":"","sources":["../src/MinifySingleFile.ts"],"names":[],"mappings":"AAGA,OAAO,EAAU,KAAK,aAAa,EAAmD,MAAM,QAAQ,CAAC;AAGrG,OAAO,QAAQ,QAAQ,CAAC;IAEtB,UAAU,gBAAgB;QACxB,QAAQ,CAAC,EAAE,OAAO,CAAC;KACpB;CACF;AAGD,OAAO,KAAK,EAAE,0BAA0B,EAAE,yBAAyB,EAAE,MAAM,SAAS,CAAC;AAMrF;;;GAGG;AACH,wBAAsB,qBAAqB,CACzC,OAAO,EAAE,0BAA0B,EACnC,aAAa,EAAE,aAAa,GAC3B,OAAO,CAAC,yBAAyB,CAAC,CA4DpC"}
@@ -46,6 +46,7 @@ async function minifySingleFileAsync(request, terserOptions) {
46
46
  };
47
47
  }
48
48
  catch (error) {
49
+ // eslint-disable-next-line no-console
49
50
  console.error(error);
50
51
  return {
51
52
  error: error,
@@ -1 +1 @@
1
- {"version":3,"file":"MinifySingleFile.js","sourceRoot":"","sources":["../src/MinifySingleFile.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;;AAE3D,mCAAsF;AAUtF,6DAAqD;AAGrD,MAAM,cAAc,GAA4B;IAC9C,GAAG,EAAE,kCAAa;CACnB,CAAC;AAEF;;;GAGG;AACI,KAAK,UAAU,qBAAqB,CACzC,OAAmC,EACnC,aAA4B;IAE5B,MAAM,EAAE,IAAI,EAAE,UAAU,EAAE,IAAI,EAAE,SAAS,EAAE,GAAG,OAAO,CAAC;IAEtD,IAAI;QACF,MAAM,EACJ,MAAM,EAAE,SAAS,EACjB,MAAM,EAAE,SAAS,EACjB,MAAM,EAAE,cAAc,EACtB,GAAG,gBAAgB,EACpB,GAAG,aAA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c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.\n// See LICENSE in the project root for license information.\n\nimport { minify, MinifyOptions, MinifyOutput, SimpleIdentifierMangler } from 'terser';\nimport type { RawSourceMap } from 'source-map';\n\ndeclare module 'terser' {\n // eslint-disable-next-line @typescript-eslint/naming-convention\n interface SourceMapOptions {\n asObject?: boolean;\n }\n}\n\nimport { getIdentifier } from './MinifiedIdentifier';\nimport type { IModuleMinificationRequest, IModuleMinificationResult } from './types';\n\nconst nth_identifier: SimpleIdentifierMangler = {\n get: getIdentifier\n};\n\n/**\n * Minifies a single chunk of code. Factored out for reuse between WorkerPoolMinifier and LocalMinifier\n * @internal\n */\nexport async function minifySingleFileAsync(\n request: IModuleMinificationRequest,\n terserOptions: MinifyOptions\n): Promise<IModuleMinificationResult> {\n const { code, nameForMap, hash, externals } = request;\n\n try {\n const {\n format: rawFormat,\n output: rawOutput,\n mangle: originalMangle,\n ...remainingOptions\n } = terserOptions;\n\n const format: MinifyOptions['format'] = rawFormat || rawOutput || {};\n\n const mangle: MinifyOptions['mangle'] =\n originalMangle === false ? false : typeof originalMangle === 'object' ? { ...originalMangle } : {};\n\n const finalOptions: MinifyOptions = {\n ...remainingOptions,\n format,\n mangle\n };\n format.comments = false;\n\n if (mangle) {\n mangle.nth_identifier = nth_identifier;\n }\n\n if (mangle && externals) {\n mangle.reserved = mangle.reserved ? externals.concat(mangle.reserved) : externals;\n }\n\n finalOptions.sourceMap = nameForMap\n ? {\n asObject: true\n }\n : false;\n\n const minified: MinifyOutput = await minify(\n {\n [nameForMap || 'code']: code\n },\n finalOptions\n );\n\n return {\n error: undefined,\n code: minified.code!,\n map: minified.map as unknown as RawSourceMap,\n hash\n };\n } catch (error) {\n console.error(error);\n return {\n error: error as Error,\n code: undefined,\n map: undefined,\n hash\n };\n }\n}\n"]}
1
+ {"version":3,"file":"MinifySingleFile.js","sourceRoot":"","sources":["../src/MinifySingleFile.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DA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7B,EACD,YAAY,CACb,CAAC;QAEF,OAAO;YACL,KAAK,EAAE,SAAS;YAChB,IAAI,EAAE,QAAQ,CAAC,IAAK;YACpB,GAAG,EAAE,QAAQ,CAAC,GAA8B;YAC5C,IAAI;SACL,CAAC;KACH;IAAC,OAAO,KAAK,EAAE;QACd,sCAAsC;QACtC,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;QACrB,OAAO;YACL,KAAK,EAAE,KAAc;YACrB,IAAI,EAAE,SAAS;YACf,GAAG,EAAE,SAAS;YACd,IAAI;SACL,CAAC;KACH;AACH,CAAC;AA/DD,sDA+DC","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 { minify, type MinifyOptions, type MinifyOutput, type SimpleIdentifierMangler } from 'terser';\nimport type { RawSourceMap } from 'source-map';\n\ndeclare module 'terser' {\n // eslint-disable-next-line @typescript-eslint/naming-convention\n interface SourceMapOptions {\n asObject?: boolean;\n }\n}\n\nimport { getIdentifier } from './MinifiedIdentifier';\nimport type { IModuleMinificationRequest, IModuleMinificationResult } from './types';\n\nconst nth_identifier: SimpleIdentifierMangler = {\n get: getIdentifier\n};\n\n/**\n * Minifies a single chunk of code. Factored out for reuse between WorkerPoolMinifier and LocalMinifier\n * @internal\n */\nexport async function minifySingleFileAsync(\n request: IModuleMinificationRequest,\n terserOptions: MinifyOptions\n): Promise<IModuleMinificationResult> {\n const { code, nameForMap, hash, externals } = request;\n\n try {\n const {\n format: rawFormat,\n output: rawOutput,\n mangle: originalMangle,\n ...remainingOptions\n } = terserOptions;\n\n const format: MinifyOptions['format'] = rawFormat || rawOutput || {};\n\n const mangle: MinifyOptions['mangle'] =\n originalMangle === false ? false : typeof originalMangle === 'object' ? { ...originalMangle } : {};\n\n const finalOptions: MinifyOptions = {\n ...remainingOptions,\n format,\n mangle\n };\n format.comments = false;\n\n if (mangle) {\n mangle.nth_identifier = nth_identifier;\n }\n\n if (mangle && externals) {\n mangle.reserved = mangle.reserved ? externals.concat(mangle.reserved) : externals;\n }\n\n finalOptions.sourceMap = nameForMap\n ? {\n asObject: true\n }\n : false;\n\n const minified: MinifyOutput = await minify(\n {\n [nameForMap || 'code']: code\n },\n finalOptions\n );\n\n return {\n error: undefined,\n code: minified.code!,\n map: minified.map as unknown as RawSourceMap,\n hash\n };\n } catch (error) {\n // eslint-disable-next-line no-console\n console.error(error);\n return {\n error: error as Error,\n code: undefined,\n map: undefined,\n hash\n };\n }\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"WorkerPoolMinifier.d.ts","sourceRoot":"","sources":["../src/WorkerPoolMinifier.ts"],"names":[],"mappings":"AAOA,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;CACnB;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;IA8BtD,IAAW,UAAU,IAAI,MAAM,CAE9B;IAED,IAAW,UAAU,CAAC,OAAO,E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@@ -71,11 +71,11 @@ class WorkerPoolMinifier {
71
71
  .then((worker) => {
72
72
  const cb = (message) => {
73
73
  worker.off('message', cb);
74
- const callbacks = activeRequests.get(message.hash);
74
+ const workerCallbacks = activeRequests.get(message.hash);
75
75
  activeRequests.delete(message.hash);
76
76
  this._resultCache.set(message.hash, message);
77
- for (const callback of callbacks) {
78
- callback(message);
77
+ for (const workerCallback of workerCallbacks) {
78
+ workerCallback(message);
79
79
  }
80
80
  // This should always be the last thing done with the worker
81
81
  this._pool.checkinWorker(worker);
@@ -104,12 +104,14 @@ class WorkerPoolMinifier {
104
104
  disconnect: async () => {
105
105
  if (--this._refCount === 0) {
106
106
  if (this._verbose) {
107
+ // eslint-disable-next-line no-console
107
108
  console.log(`Shutting down minifier worker pool`);
108
109
  }
109
110
  await this._pool.finishAsync();
110
111
  this._resultCache.clear();
111
112
  this._activeRequests.clear();
112
113
  if (this._verbose) {
114
+ // eslint-disable-next-line no-console
113
115
  console.log(`Module minification: ${this._deduped} Deduped, ${this._minified} Processed`);
114
116
  }
115
117
  }
@@ -1 +1 @@
1
- {"version":3,"file":"WorkerPoolMinifier.js","sourceRoot":"","sources":["../src/WorkerPoolMinifier.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;;;;;AAE3D,mCAAoC;AACpC,2BAA0B;AAE1B,gFAA6C;AAE7C,wDAAoD;AAgCpD;;;GAGG;AACH,MAAa,kBAAkB;IAY7B,YAAmB,OAAmC;QACpD,MAAM,EAAE,UAAU,GAAG,IAAA,SAAI,GAAE,CAAC,MAAM,EAAE,aAAa,GAAG,EAAE,EAAE,OAAO,GAAG,KAAK,EAAE,GAAG,OAAO,IAAI,EAAE,CAAC;QAE1F,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,UA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,aAAa,IAAI,cAAc,EAAE;gBAC1C,aAAa,CAAC;oBACZ,IAAI;oBACJ,KAAK;oBACL,IAAI,EAAE,SAAS;oBACf,GAAG,EAAE,SAAS;iBACf,CAAC,CAAC;aACJ;QACH,CAAC,CAAC,CAAC;IACP,CAAC;IAEM,KAAK,CAAC,OAAO;QAClB,IAAI,EAAE,IAAI,CAAC,SAAS,KAAK,CAAC,EAAE;YAC1B,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC;SACpB;QAED,OAAO;YACL,UAAU,EAAE,IAAI,CAAC,WAAW;YAE5B,UAAU,EAAE,KAAK,IAAI,EAAE;gBACrB,IAAI,EAAE,IAAI,CAAC,SAAS,KAAK,CAAC,EAAE;oBAC1B,IAAI,IAAI,CAAC,QAAQ,EAAE;wBACjB,OAAO,CAAC,GAAG,CAAC,oCAAoC,CAAC,CAAC;qBACnD;oBACD,MAAM,IAAI,CAAC,KAAK,CAAC,WAAW,EAAE,CAAC;oBAC/B,IAAI,CAAC,YAAY,CAAC,KAAK,EAAE,CAAC;oBAC1B,IAAI,CAAC,eAAe,CAAC,KAAK,EAAE,CAAC;oBAC7B,IAAI,IAAI,CAAC,QAAQ,EAAE;wBACjB,OAAO,CAAC,GAAG,CAAC,wBAAwB,IAAI,CAAC,QAAQ,aAAa,IAAI,CAAC,SAAS,YAAY,CAAC,CAAC;qBAC3F;iBACF;gBACD,IAAI,CAAC,QAAQ,GAAG,CAAC,CAAC;gBAClB,IAAI,CAAC,SAAS,GAAG,CAAC,CAAC;YACrB,CAAC;SACF,CAAC;IACJ,CAAC;CACF;AArID,gDAqIC","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 callbacks: IModuleMinificationCallback[] | undefined = activeRequests.get(message.hash)!;\n activeRequests.delete(message.hash);\n this._resultCache.set(message.hash, message);\n for (const callback of callbacks) {\n callback(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 public async connect(): Promise<IMinifierConnection> {\n if (++this._refCount === 1) {\n this._pool.reset();\n }\n\n return {\n configHash: this._configHash,\n\n disconnect: async () => {\n if (--this._refCount === 0) {\n if (this._verbose) {\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 console.log(`Module minification: ${this._deduped} Deduped, ${this._minified} Processed`);\n }\n }\n this._deduped = 0;\n this._minified = 0;\n }\n };\n }\n}\n"]}
1
+ {"version":3,"file":"WorkerPoolMinifier.js","sourceRoot":"","sources":["../src/WorkerPoolMinifier.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;;;;;AAE3D,mCAAoC;AACpC,2BAA0B;AAE1B,gFAA6C;AAE7C,wDAAoD;AAgCpD;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AAC,CAAC;qBAC3F;iBACF;gBACD,IAAI,CAAC,QAAQ,GAAG,CAAC,CAAC;gBAClB,IAAI,CAAC,SAAS,GAAG,CAAC,CAAC;YACrB,CAAC;SACF,CAAC;IACJ,CAAC;CACF;AAzID,gDAyIC","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 public async connect(): Promise<IMinifierConnection> {\n if (++this._refCount === 1) {\n this._pool.reset();\n }\n\n return {\n configHash: this._configHash,\n\n disconnect: 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 }\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rushstack/module-minifier",
3
- "version": "0.4.3",
3
+ "version": "0.4.4",
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,11 @@
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.4.3"
17
+ "@rushstack/worker-pool": "0.4.4"
18
18
  },
19
19
  "devDependencies": {
20
20
  "@types/serialize-javascript": "5.0.2",
21
- "@rushstack/eslint-config": "3.3.4",
22
- "@rushstack/heft": "0.61.1",
21
+ "@rushstack/heft": "0.61.2",
23
22
  "local-node-rig": "1.0.0"
24
23
  },
25
24
  "peerDependencies": {