@rushstack/module-minifier 0.5.4 → 0.6.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.
@@ -39,9 +39,13 @@ export declare interface IMinifierConnection {
39
39
  */
40
40
  configHash: string;
41
41
  /**
42
- * Callback to be invoked when done with the minifier
42
+ * @deprecated Use {@link IMinifierConnection.disconnectAsync} instead.
43
43
  */
44
44
  disconnect(): Promise<void>;
45
+ /**
46
+ * Callback to be invoked when done with the minifier
47
+ */
48
+ disconnectAsync(): Promise<void>;
45
49
  }
46
50
 
47
51
  /**
@@ -136,12 +140,16 @@ export declare interface IModuleMinifier {
136
140
  * Asynchronously minify a module
137
141
  */
138
142
  minify: IModuleMinifierFunction;
143
+ /**
144
+ * @deprecated Use {@link IModuleMinifier.connectAsync} instead.
145
+ */
146
+ connect(): Promise<IMinifierConnection>;
139
147
  /**
140
148
  * Prevents the minifier from shutting down until the returned `disconnect()` callback is invoked.
141
149
  * The callback may be used to surface errors encountered by the minifier that may not be relevant to a specific file.
142
150
  * It should be called to allow the minifier to cleanup
143
151
  */
144
- connect(): Promise<IMinifierConnection>;
152
+ connectAsync(): Promise<IMinifierConnection>;
145
153
  }
146
154
 
147
155
  /**
@@ -188,6 +196,13 @@ export declare class LocalMinifier implements IModuleMinifier {
188
196
  * @param callback - The callback to invoke
189
197
  */
190
198
  minify(request: IModuleMinificationRequest, callback: IModuleMinificationCallback): void;
199
+ /**
200
+ * {@inheritdoc IModuleMinifier.connectAsync}
201
+ */
202
+ connectAsync(): Promise<IMinifierConnection>;
203
+ /**
204
+ * @deprecated Use {@link LocalMinifier.connectAsync} instead.
205
+ */
191
206
  connect(): Promise<IMinifierConnection>;
192
207
  }
193
208
 
@@ -205,6 +220,13 @@ export declare class MessagePortMinifier implements IModuleMinifier {
205
220
  * @param callback - The callback to invoke
206
221
  */
207
222
  minify(request: IModuleMinificationRequest, callback: IModuleMinificationCallback): void;
223
+ /**
224
+ * {@inheritdoc IModuleMinifier.connectAsync}
225
+ */
226
+ connectAsync(): Promise<IMinifierConnection>;
227
+ /**
228
+ * @deprecated Use {@link MessagePortMinifier.connectAsync} instead
229
+ */
208
230
  connect(): Promise<IMinifierConnection>;
209
231
  }
210
232
 
@@ -227,6 +249,13 @@ export declare class NoopMinifier implements IModuleMinifier {
227
249
  * @param callback - The callback to invoke
228
250
  */
229
251
  minify(request: IModuleMinificationRequest, callback: IModuleMinificationCallback): void;
252
+ /**
253
+ * {@inheritdoc IModuleMinifier.connectAsync}
254
+ */
255
+ connectAsync(): Promise<IMinifierConnection>;
256
+ /**
257
+ * @deprecated Use {@link NoopMinifier.connectAsync} instead
258
+ */
230
259
  connect(): Promise<IMinifierConnection>;
231
260
  }
232
261
 
@@ -252,6 +281,13 @@ export declare class WorkerPoolMinifier implements IModuleMinifier {
252
281
  * @param callback - The callback to invoke
253
282
  */
254
283
  minify(request: IModuleMinificationRequest, callback: IModuleMinificationCallback): void;
284
+ /**
285
+ * {@inheritdoc IModuleMinifier.connectAsync}
286
+ */
287
+ connectAsync(): Promise<IMinifierConnection>;
288
+ /**
289
+ * @deprecated Use {@link WorkerPoolMinifier.connectAsync} instead
290
+ */
255
291
  connect(): Promise<IMinifierConnection>;
256
292
  }
257
293
 
@@ -5,7 +5,7 @@
5
5
  "toolPackages": [
6
6
  {
7
7
  "packageName": "@microsoft/api-extractor",
8
- "packageVersion": "7.43.3"
8
+ "packageVersion": "7.43.4"
9
9
  }
10
10
  ]
11
11
  }
@@ -22,6 +22,13 @@ export declare class LocalMinifier implements IModuleMinifier {
22
22
  * @param callback - The callback to invoke
23
23
  */
24
24
  minify(request: IModuleMinificationRequest, callback: IModuleMinificationCallback): void;
25
+ /**
26
+ * {@inheritdoc IModuleMinifier.connectAsync}
27
+ */
28
+ connectAsync(): Promise<IMinifierConnection>;
29
+ /**
30
+ * @deprecated Use {@link LocalMinifier.connectAsync} instead.
31
+ */
25
32
  connect(): Promise<IMinifierConnection>;
26
33
  }
27
34
  //# sourceMappingURL=LocalMinifier.d.ts.map
@@ -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;IAwBlF,OAAO,IAAI,OAAO,CAAC,mBAAmB,CAAC;CAQrD"}
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"}
@@ -58,14 +58,26 @@ class LocalMinifier {
58
58
  });
59
59
  });
60
60
  }
61
- async connect() {
61
+ /**
62
+ * {@inheritdoc IModuleMinifier.connectAsync}
63
+ */
64
+ async connectAsync() {
65
+ const disconnectAsync = async () => {
66
+ // Do nothing.
67
+ };
62
68
  return {
63
69
  configHash: this._configHash,
64
- disconnect: async () => {
65
- // Do nothing.
66
- }
70
+ disconnectAsync,
71
+ disconnect: disconnectAsync
67
72
  };
68
73
  }
74
+ /**
75
+ * @deprecated Use {@link LocalMinifier.connectAsync} instead.
76
+ */
77
+ // eslint-disable-next-line @typescript-eslint/naming-convention
78
+ async connect() {
79
+ return await this.connectAsync();
80
+ }
69
81
  }
70
82
  exports.LocalMinifier = LocalMinifier;
71
83
  //# sourceMappingURL=LocalMinifier.js.map
@@ -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,EA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CAAC;CACF;AAlED,sCAkEC","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 public async connect(): Promise<IMinifierConnection> {\n return {\n configHash: this._configHash,\n disconnect: async () => {\n // Do nothing.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AC,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"]}
@@ -15,6 +15,13 @@ export declare class MessagePortMinifier implements IModuleMinifier {
15
15
  * @param callback - The callback to invoke
16
16
  */
17
17
  minify(request: IModuleMinificationRequest, callback: IModuleMinificationCallback): void;
18
+ /**
19
+ * {@inheritdoc IModuleMinifier.connectAsync}
20
+ */
21
+ connectAsync(): Promise<IMinifierConnection>;
22
+ /**
23
+ * @deprecated Use {@link MessagePortMinifier.connectAsync} instead
24
+ */
18
25
  connect(): Promise<IMinifierConnection>;
19
26
  }
20
27
  //# sourceMappingURL=MessagePortMinifier.d.ts.map
@@ -1 +1 @@
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,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,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;IAc/F;;OAEG;IACU,YAAY,IAAI,OAAO,CAAC,mBAAmB,CAAC;IA6BzD;;OAEG;IAEU,OAAO,IAAI,OAAO,CAAC,mBAAmB,CAAC;CAGrD"}
@@ -28,7 +28,10 @@ class MessagePortMinifier {
28
28
  this._callbacks.set(hash, [callback]);
29
29
  this.port.postMessage(request);
30
30
  }
31
- async connect() {
31
+ /**
32
+ * {@inheritdoc IModuleMinifier.connectAsync}
33
+ */
34
+ async connectAsync() {
32
35
  const configHashPromise = (0, events_1.once)(this.port, 'message');
33
36
  this.port.postMessage('initialize');
34
37
  const configHash = await configHashPromise;
@@ -43,14 +46,23 @@ class MessagePortMinifier {
43
46
  }
44
47
  }
45
48
  this.port.on('message', handler);
49
+ const disconnectAsync = async () => {
50
+ this.port.off('message', handler);
51
+ this.port.close();
52
+ };
46
53
  return {
47
54
  configHash,
48
- disconnect: async () => {
49
- this.port.off('message', handler);
50
- this.port.close();
51
- }
55
+ disconnectAsync,
56
+ disconnect: disconnectAsync
52
57
  };
53
58
  }
59
+ /**
60
+ * @deprecated Use {@link MessagePortMinifier.connectAsync} instead
61
+ */
62
+ // eslint-disable-next-line @typescript-eslint/naming-convention
63
+ async connect() {
64
+ return await this.connectAsync();
65
+ }
54
66
  }
55
67
  exports.MessagePortMinifier = MessagePortMinifier;
56
68
  //# sourceMappingURL=MessagePortMinifier.js.map
@@ -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,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,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;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,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,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
+ {"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,CA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C,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 { 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 /**\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"]}
@@ -10,6 +10,13 @@ export declare class NoopMinifier implements IModuleMinifier {
10
10
  * @param callback - The callback to invoke
11
11
  */
12
12
  minify(request: IModuleMinificationRequest, callback: IModuleMinificationCallback): void;
13
+ /**
14
+ * {@inheritdoc IModuleMinifier.connectAsync}
15
+ */
16
+ connectAsync(): Promise<IMinifierConnection>;
17
+ /**
18
+ * @deprecated Use {@link NoopMinifier.connectAsync} instead
19
+ */
13
20
  connect(): Promise<IMinifierConnection>;
14
21
  }
15
22
  //# sourceMappingURL=NoopMinifier.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"NoopMinifier.d.ts","sourceRoot":"","sources":["../src/NoopMinifier.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EACV,mBAAmB,EACnB,2BAA2B,EAC3B,0BAA0B,EAC1B,eAAe,EAChB,MAAM,SAAS,CAAC;AAEjB;;;GAGG;AACH,qBAAa,YAAa,YAAW,eAAe;IAClD;;;;OAIG;IACI,MAAM,CAAC,OAAO,EAAE,0BAA0B,EAAE,QAAQ,EAAE,2BAA2B,GAAG,IAAI;IAsBlF,OAAO,IAAI,OAAO,CAAC,mBAAmB,CAAC;CASrD"}
1
+ {"version":3,"file":"NoopMinifier.d.ts","sourceRoot":"","sources":["../src/NoopMinifier.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EACV,mBAAmB,EACnB,2BAA2B,EAC3B,0BAA0B,EAC1B,eAAe,EAChB,MAAM,SAAS,CAAC;AAEjB;;;GAGG;AACH,qBAAa,YAAa,YAAW,eAAe;IAClD;;;;OAIG;IACI,MAAM,CAAC,OAAO,EAAE,0BAA0B,EAAE,QAAQ,EAAE,2BAA2B,GAAG,IAAI;IAsB/F;;OAEG;IACU,YAAY,IAAI,OAAO,CAAC,mBAAmB,CAAC;IAYzD;;OAEG;IAEU,OAAO,IAAI,OAAO,CAAC,mBAAmB,CAAC;CAGrD"}
@@ -33,14 +33,26 @@ class NoopMinifier {
33
33
  : undefined
34
34
  });
35
35
  }
36
- async connect() {
36
+ /**
37
+ * {@inheritdoc IModuleMinifier.connectAsync}
38
+ */
39
+ async connectAsync() {
40
+ const disconnectAsync = async () => {
41
+ // Do nothing.
42
+ };
37
43
  return {
38
44
  configHash: NoopMinifier.name,
39
- disconnect: async () => {
40
- // Do nothing.
41
- }
45
+ disconnectAsync,
46
+ disconnect: disconnectAsync
42
47
  };
43
48
  }
49
+ /**
50
+ * @deprecated Use {@link NoopMinifier.connectAsync} instead
51
+ */
52
+ // eslint-disable-next-line @typescript-eslint/naming-convention
53
+ async connect() {
54
+ return await this.connectAsync();
55
+ }
44
56
  }
45
57
  exports.NoopMinifier = NoopMinifier;
46
58
  //# sourceMappingURL=NoopMinifier.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"NoopMinifier.js","sourceRoot":"","sources":["../src/NoopMinifier.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;;AAS3D;;;GAGG;AACH,MAAa,YAAY;IACvB;;;;OAIG;IACI,MAAM,CAAC,OAAmC,EAAE,QAAqC;QACtF,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,UAAU,EAAE,GAAG,OAAO,CAAC;QAE3C,QAAQ,CAAC;YACP,IAAI;YACJ,KAAK,EAAE,SAAS;YAChB,IAAI;YACJ,4DAA4D;YAC5D,GAAG,EAAE,UAAU;gBACb,CAAC,CAAC;oBACE,OAAO,EAAE,CAAC;oBACV,KAAK,EAAE,EAAE;oBACT,IAAI,EAAE,UAAU;oBAChB,OAAO,EAAE,CAAC,UAAU,CAAC;oBACrB,cAAc,EAAE,CAAC,IAAI,CAAC;oBACtB,+GAA+G;oBAC/G,QAAQ,EAAE,MAAM;iBACjB;gBACH,CAAC,CAAC,SAAS;SACd,CAAC,CAAC;IACL,CAAC;IAEM,KAAK,CAAC,OAAO;QAClB,OAAO;YACL,UAAU,EAAE,YAAY,CAAC,IAAI;YAE7B,UAAU,EAAE,KAAK,IAAI,EAAE;gBACrB,cAAc;YAChB,CAAC;SACF,CAAC;IACJ,CAAC;CACF;AArCD,oCAqCC","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 {\n IMinifierConnection,\n IModuleMinificationCallback,\n IModuleMinificationRequest,\n IModuleMinifier\n} from './types';\n\n/**\n * Minifier implementation that does not actually transform the code, for debugging.\n * @public\n */\nexport class NoopMinifier implements IModuleMinifier {\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 { code, hash, nameForMap } = request;\n\n callback({\n hash,\n error: undefined,\n code,\n // If source maps are requested, provide an empty source map\n map: nameForMap\n ? {\n version: 3,\n names: [],\n file: nameForMap,\n sources: [nameForMap],\n sourcesContent: [code],\n // In source mapping parlance, this means \"map line 0, column 0 to the input file at index 0, line 0, column 0\"\n mappings: 'AAAA'\n }\n : undefined\n });\n }\n\n public async connect(): Promise<IMinifierConnection> {\n return {\n configHash: NoopMinifier.name,\n\n disconnect: async () => {\n // Do nothing.\n }\n };\n }\n}\n"]}
1
+ {"version":3,"file":"NoopMinifier.js","sourceRoot":"","sources":["../src/NoopMinifier.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;;AAS3D;;;GAGG;AACH,MAAa,YAAY;IACvB;;;;OAIG;IACI,MAAM,CAAC,OAAmC,EAAE,QAAqC;QACtF,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,UAAU,EAAE,GAAG,OAAO,CAAC;QAE3C,QAAQ,CAAC;YACP,IAAI;YACJ,KAAK,EAAE,SAAS;YAChB,IAAI;YACJ,4DAA4D;YAC5D,GAAG,EAAE,UAAU;gBACb,CAAC,CAAC;oBACE,OAAO,EAAE,CAAC;oBACV,KAAK,EAAE,EAAE;oBACT,IAAI,EAAE,UAAU;oBAChB,OAAO,EAAE,CAAC,UAAU,CAAC;oBACrB,cAAc,EAAE,CAAC,IAAI,CAAC;oBACtB,+GAA+G;oBAC/G,QAAQ,EAAE,MAAM;iBACjB;gBACH,CAAC,CAAC,SAAS;SACd,CAAC,CAAC;IACL,CAAC;IAED;;OAEG;IACI,KAAK,CAAC,YAAY;QACvB,MAAM,eAAe,GAA2C,KAAK,IAAI,EAAE;YACzE,cAAc;QAChB,CAAC,CAAC;QAEF,OAAO;YACL,UAAU,EAAE,YAAY,CAAC,IAAI;YAC7B,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;AAlDD,oCAkDC","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 {\n IMinifierConnection,\n IModuleMinificationCallback,\n IModuleMinificationRequest,\n IModuleMinifier\n} from './types';\n\n/**\n * Minifier implementation that does not actually transform the code, for debugging.\n * @public\n */\nexport class NoopMinifier implements IModuleMinifier {\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 { code, hash, nameForMap } = request;\n\n callback({\n hash,\n error: undefined,\n code,\n // If source maps are requested, provide an empty source map\n map: nameForMap\n ? {\n version: 3,\n names: [],\n file: nameForMap,\n sources: [nameForMap],\n sourcesContent: [code],\n // In source mapping parlance, this means \"map line 0, column 0 to the input file at index 0, line 0, column 0\"\n mappings: 'AAAA'\n }\n : undefined\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\n return {\n configHash: NoopMinifier.name,\n disconnectAsync,\n disconnect: disconnectAsync\n };\n }\n\n /**\n * @deprecated Use {@link NoopMinifier.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"]}
@@ -42,6 +42,13 @@ export declare class WorkerPoolMinifier implements IModuleMinifier {
42
42
  * @param callback - The callback to invoke
43
43
  */
44
44
  minify(request: IModuleMinificationRequest, callback: IModuleMinificationCallback): void;
45
+ /**
46
+ * {@inheritdoc IModuleMinifier.connectAsync}
47
+ */
48
+ connectAsync(): Promise<IMinifierConnection>;
49
+ /**
50
+ * @deprecated Use {@link WorkerPoolMinifier.connectAsync} instead
51
+ */
45
52
  connect(): Promise<IMinifierConnection>;
46
53
  }
47
54
  //# sourceMappingURL=WorkerPoolMinifier.d.ts.map
@@ -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,CA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,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,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"}
@@ -95,30 +95,42 @@ class WorkerPoolMinifier {
95
95
  }
96
96
  });
97
97
  }
98
- async connect() {
98
+ /**
99
+ * {@inheritdoc IModuleMinifier.connectAsync}
100
+ */
101
+ async connectAsync() {
99
102
  if (++this._refCount === 1) {
100
103
  this._pool.reset();
101
104
  }
102
- return {
103
- configHash: this._configHash,
104
- disconnect: async () => {
105
- if (--this._refCount === 0) {
106
- if (this._verbose) {
107
- // eslint-disable-next-line no-console
108
- console.log(`Shutting down minifier worker pool`);
109
- }
110
- await this._pool.finishAsync();
111
- this._resultCache.clear();
112
- this._activeRequests.clear();
113
- if (this._verbose) {
114
- // eslint-disable-next-line no-console
115
- console.log(`Module minification: ${this._deduped} Deduped, ${this._minified} Processed`);
116
- }
105
+ const disconnectAsync = async () => {
106
+ if (--this._refCount === 0) {
107
+ if (this._verbose) {
108
+ // eslint-disable-next-line no-console
109
+ console.log(`Shutting down minifier worker pool`);
110
+ }
111
+ await this._pool.finishAsync();
112
+ this._resultCache.clear();
113
+ this._activeRequests.clear();
114
+ if (this._verbose) {
115
+ // eslint-disable-next-line no-console
116
+ console.log(`Module minification: ${this._deduped} Deduped, ${this._minified} Processed`);
117
117
  }
118
- this._deduped = 0;
119
- this._minified = 0;
120
118
  }
119
+ this._deduped = 0;
120
+ this._minified = 0;
121
121
  };
122
+ return {
123
+ configHash: this._configHash,
124
+ disconnectAsync,
125
+ disconnect: disconnectAsync
126
+ };
127
+ }
128
+ /**
129
+ * @deprecated Use {@link WorkerPoolMinifier.connectAsync} instead
130
+ */
131
+ // eslint-disable-next-line @typescript-eslint/naming-convention
132
+ async connect() {
133
+ return await this.connectAsync();
122
134
  }
123
135
  }
124
136
  exports.WorkerPoolMinifier = WorkerPoolMinifier;
@@ -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,UAAU,EAAE,UAAU;YACtB,UAAU,EAAE,aAAa;YACzB,gBAAgB,EAAE,OAAO,CAAC,OAAO,CAAC,kBAAkB,CAAC;SACtD,CAAC,CAAC;QAEH,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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,SAAS,KAAK,CAAC,EAAE,CAAC;YAC3B,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC;QACrB,CAAC;QAED,OAAO;YACL,UAAU,EAAE,IAAI,CAAC,WAAW;YAE5B,UAAU,EAAE,KAAK,IAAI,EAAE;gBACrB,IAAI,EAAE,IAAI,CAAC,SAAS,KAAK,CAAC,EAAE,CAAC;oBAC3B,IAAI,IAAI,CAAC,QAAQ,EAAE,CAAC;wBAClB,sCAAsC;wBACtC,OAAO,CAAC,GAAG,CAAC,oCAAoC,CAAC,CAAC;oBACpD,CAAC;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,CAAC;wBAClB,sCAAsC;wBACtC,OAAO,CAAC,GAAG,CAAC,wBAAwB,IAAI,CAAC,QAAQ,aAAa,IAAI,CAAC,SAAS,YAAY,CAAC,CAAC;oBAC5F,CAAC;gBACH,CAAC;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"]}
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,G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D,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"]}
package/lib/types.d.ts CHANGED
@@ -94,9 +94,13 @@ export interface IMinifierConnection {
94
94
  */
95
95
  configHash: string;
96
96
  /**
97
- * Callback to be invoked when done with the minifier
97
+ * @deprecated Use {@link IMinifierConnection.disconnectAsync} instead.
98
98
  */
99
99
  disconnect(): Promise<void>;
100
+ /**
101
+ * Callback to be invoked when done with the minifier
102
+ */
103
+ disconnectAsync(): Promise<void>;
100
104
  }
101
105
  /**
102
106
  * Object that can be invoked to minify code.
@@ -107,11 +111,15 @@ export interface IModuleMinifier {
107
111
  * Asynchronously minify a module
108
112
  */
109
113
  minify: IModuleMinifierFunction;
114
+ /**
115
+ * @deprecated Use {@link IModuleMinifier.connectAsync} instead.
116
+ */
117
+ connect(): Promise<IMinifierConnection>;
110
118
  /**
111
119
  * Prevents the minifier from shutting down until the returned `disconnect()` callback is invoked.
112
120
  * The callback may be used to surface errors encountered by the minifier that may not be relevant to a specific file.
113
121
  * It should be called to allow the minifier to cleanup
114
122
  */
115
- connect(): Promise<IMinifierConnection>;
123
+ connectAsync(): Promise<IMinifierConnection>;
116
124
  }
117
125
  //# sourceMappingURL=types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAE/C;;;GAGG;AACH,MAAM,WAAW,0BAA0B;IACzC;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC;IACb;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC;IACb;;OAEG;IACH,UAAU,EAAE,MAAM,GAAG,SAAS,CAAC;IAC/B;;OAEG;IACH,SAAS,EAAE,MAAM,EAAE,GAAG,SAAS,CAAC;CACjC;AAED;;;GAGG;AACH,MAAM,WAAW,8BAA8B;IAC7C;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC;IACb;;OAEG;IACH,KAAK,EAAE,KAAK,CAAC;IACb;;OAEG;IACH,IAAI,CAAC,EAAE,SAAS,CAAC;IACjB;;OAEG;IACH,GAAG,CAAC,EAAE,SAAS,CAAC;CACjB;AAED;;;GAGG;AACH,MAAM,WAAW,gCAAgC;IAC/C;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC;IACb;;OAEG;IACH,KAAK,EAAE,SAAS,CAAC;IACjB;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC;IACb;;OAEG;IACH,GAAG,CAAC,EAAE,YAAY,CAAC;CACpB;AAED;;;GAGG;AACH,MAAM,MAAM,yBAAyB,GAAG,8BAA8B,GAAG,gCAAgC,CAAC;AAE1G;;;GAGG;AACH,MAAM,WAAW,2BAA2B;IAC1C,CAAC,MAAM,EAAE,yBAAyB,GAAG,IAAI,CAAC;CAC3C;AAED;;;GAGG;AACH,MAAM,WAAW,uBAAuB;IACtC,CAAC,OAAO,EAAE,0BAA0B,EAAE,QAAQ,EAAE,2BAA2B,GAA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AW,2BAA2B;IAC1C,CAAC,MAAM,EAAE,yBAAyB,GAAG,IAAI,CAAC;CAC3C;AAED;;;GAGG;AACH,MAAM,WAAW,uBAAuB;IACtC,CAAC,OAAO,EAAE,0BAA0B,EAAE,QAAQ,EAAE,2BAA2B,GAAG,IAAI,CAAC;CACpF;AAED;;;GAGG;AACH,MAAM,WAAW,mBAAmB;IAClC;;OAEG;IACH,UAAU,EAAE,MAAM,CAAC;IAEnB;;OAEG;IACH,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IAE5B;;OAEG;IACH,eAAe,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CAClC;AAED;;;GAGG;AACH,MAAM,WAAW,eAAe;IAC9B;;OAEG;IACH,MAAM,EAAE,uBAAuB,CAAC;IAEhC;;OAEG;IACH,OAAO,IAAI,OAAO,CAAC,mBAAmB,CAAC,CAAC;IAExC;;;;OAIG;IACH,YAAY,IAAI,OAAO,CAAC,mBAAmB,CAAC,CAAC;CAC9C"}
package/lib/types.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D","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 { RawSourceMap } from 'source-map';\n\n/**\n * Request to the minifier\n * @public\n */\nexport interface IModuleMinificationRequest {\n /**\n * Identity of the request. Will be included in the response.\n */\n hash: string;\n /**\n * The raw code fragment\n */\n code: string;\n /**\n * File name to show for the source code in the source map\n */\n nameForMap: string | undefined;\n /**\n * Reserved variable names, e.g. __WEBPACK_EXTERNAL_MODULE_1__\n */\n externals: string[] | undefined;\n}\n\n/**\n * Result from the minifier function when an error is encountered.\n * @public\n */\nexport interface IModuleMinificationErrorResult {\n /**\n * Identity of the request\n */\n hash: string;\n /**\n * The error encountered, to be added to the current compilation's error collection.\n */\n error: Error;\n /**\n * Marker property to always return the same result shape.\n */\n code?: undefined;\n /**\n * Marker property to always return the same result shape.\n */\n map?: undefined;\n}\n\n/**\n * Result from the minifier on a successful minification.\n * @public\n */\nexport interface IModuleMinificationSuccessResult {\n /**\n * Identity of the request\n */\n hash: string;\n /**\n * The error property being `undefined` indicates success.\n */\n error: undefined;\n /**\n * The minified code.\n */\n code: string;\n /**\n * Marker property to always return the same result shape.\n */\n map?: RawSourceMap;\n}\n\n/**\n * Result from the minifier.\n * @public\n */\nexport type IModuleMinificationResult = IModuleMinificationErrorResult | IModuleMinificationSuccessResult;\n\n/**\n * Callback passed to a minifier function\n * @public\n */\nexport interface IModuleMinificationCallback {\n (result: IModuleMinificationResult): void;\n}\n\n/**\n * An async function called to minify a chunk of code\n * @public\n */\nexport interface IModuleMinifierFunction {\n (request: IModuleMinificationRequest, callback: IModuleMinificationCallback): void;\n}\n\n/**\n * Metadata from the minifier for the plugin\n * @public\n */\nexport interface IMinifierConnection {\n /**\n * Hash of the configuration of this minifier, for cache busting.\n */\n configHash: string;\n /**\n * Callback to be invoked when done with the minifier\n */\n disconnect(): Promise<void>;\n}\n\n/**\n * Object that can be invoked to minify code.\n * @public\n */\nexport interface IModuleMinifier {\n /**\n * Asynchronously minify a module\n */\n minify: IModuleMinifierFunction;\n\n /**\n * Prevents the minifier from shutting down until the returned `disconnect()` callback is invoked.\n * The callback may be used to surface errors encountered by the minifier that may not be relevant to a specific file.\n * It should be called to allow the minifier to cleanup\n */\n connect(): Promise<IMinifierConnection>;\n}\n"]}
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D","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 { RawSourceMap } from 'source-map';\n\n/**\n * Request to the minifier\n * @public\n */\nexport interface IModuleMinificationRequest {\n /**\n * Identity of the request. Will be included in the response.\n */\n hash: string;\n /**\n * The raw code fragment\n */\n code: string;\n /**\n * File name to show for the source code in the source map\n */\n nameForMap: string | undefined;\n /**\n * Reserved variable names, e.g. __WEBPACK_EXTERNAL_MODULE_1__\n */\n externals: string[] | undefined;\n}\n\n/**\n * Result from the minifier function when an error is encountered.\n * @public\n */\nexport interface IModuleMinificationErrorResult {\n /**\n * Identity of the request\n */\n hash: string;\n /**\n * The error encountered, to be added to the current compilation's error collection.\n */\n error: Error;\n /**\n * Marker property to always return the same result shape.\n */\n code?: undefined;\n /**\n * Marker property to always return the same result shape.\n */\n map?: undefined;\n}\n\n/**\n * Result from the minifier on a successful minification.\n * @public\n */\nexport interface IModuleMinificationSuccessResult {\n /**\n * Identity of the request\n */\n hash: string;\n /**\n * The error property being `undefined` indicates success.\n */\n error: undefined;\n /**\n * The minified code.\n */\n code: string;\n /**\n * Marker property to always return the same result shape.\n */\n map?: RawSourceMap;\n}\n\n/**\n * Result from the minifier.\n * @public\n */\nexport type IModuleMinificationResult = IModuleMinificationErrorResult | IModuleMinificationSuccessResult;\n\n/**\n * Callback passed to a minifier function\n * @public\n */\nexport interface IModuleMinificationCallback {\n (result: IModuleMinificationResult): void;\n}\n\n/**\n * An async function called to minify a chunk of code\n * @public\n */\nexport interface IModuleMinifierFunction {\n (request: IModuleMinificationRequest, callback: IModuleMinificationCallback): void;\n}\n\n/**\n * Metadata from the minifier for the plugin\n * @public\n */\nexport interface IMinifierConnection {\n /**\n * Hash of the configuration of this minifier, for cache busting.\n */\n configHash: string;\n\n /**\n * @deprecated Use {@link IMinifierConnection.disconnectAsync} instead.\n */\n disconnect(): Promise<void>;\n\n /**\n * Callback to be invoked when done with the minifier\n */\n disconnectAsync(): Promise<void>;\n}\n\n/**\n * Object that can be invoked to minify code.\n * @public\n */\nexport interface IModuleMinifier {\n /**\n * Asynchronously minify a module\n */\n minify: IModuleMinifierFunction;\n\n /**\n * @deprecated Use {@link IModuleMinifier.connectAsync} instead.\n */\n connect(): Promise<IMinifierConnection>;\n\n /**\n * Prevents the minifier from shutting down until the returned `disconnect()` callback is invoked.\n * The callback may be used to surface errors encountered by the minifier that may not be relevant to a specific file.\n * It should be called to allow the minifier to cleanup\n */\n connectAsync(): Promise<IMinifierConnection>;\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rushstack/module-minifier",
3
- "version": "0.5.4",
3
+ "version": "0.6.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,11 +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.44"
17
+ "@rushstack/worker-pool": "0.4.45"
18
18
  },
19
19
  "devDependencies": {
20
20
  "@types/serialize-javascript": "5.0.2",
21
- "@rushstack/heft": "0.66.6",
21
+ "@rushstack/heft": "0.66.7",
22
22
  "local-node-rig": "1.0.0"
23
23
  },
24
24
  "peerDependencies": {