@rushstack/module-minifier 0.4.16 → 0.4.18
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/dist/tsdoc-metadata.json +1 -1
- package/lib/LocalMinifier.js.map +1 -1
- package/lib/MessagePortMinifier.js.map +1 -1
- package/lib/MinifiedIdentifier.js.map +1 -1
- package/lib/MinifierWorker.js.map +1 -1
- package/lib/MinifySingleFile.js.map +1 -1
- package/lib/WorkerPoolMinifier.js.map +1 -1
- package/package.json +3 -3
package/dist/tsdoc-metadata.json
CHANGED
package/lib/LocalMinifier.js.map
CHANGED
|
@@ -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,Y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AM,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;IAEM,KAAK,CAAC,OAAO;QAClB,OAAO;YACL,UAAU,EAAE,IAAI,CAAC,WAAW;YAC5B,UAAU,EAAE,KAAK,IAAI,EAAE;gBACrB,cAAc;YAChB,CAAC;SACF,CAAC;IACJ,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.\n }\n };\n }\n}\n"]}
|
|
@@ -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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AAE,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 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MinifiedIdentifier.js","sourceRoot":"","sources":["../src/MinifiedIdentifier.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;;AAE3D,4EAA4E;AAC5E,2CAAoF;AAEpF,4IAA4I;AAC5I,MAAM,iBAAiB,GAAa;IAClC,UAAU;IACV,WAAW;IACX,SAAS;IACT,OAAO;IACP,MAAM;IACN,MAAM;IACN,OAAO;IACP,MAAM;IACN,OAAO;IACP,OAAO;IACP,UAAU;IACV,UAAU;IACV,SAAS;IACT,QAAQ;IACR,IAAI;IACJ,QAAQ;IACR,MAAM;IACN,MAAM;IACN,QAAQ;IACR,SAAS;IACT,OAAO;IACP,OAAO;IACP,SAAS;IACT,OAAO;IACP,KAAK;IACL,UAAU;IACV,KAAK;IACL,MAAM;IACN,IAAI;IACJ,YAAY;IACZ,QAAQ;IACR,IAAI;IACJ,YAAY;IACZ,KAAK;IACL,WAAW;IACX,KAAK;IACL,MAAM;IACN,QAAQ;IACR,KAAK;IACL,MAAM;IACN,SAAS;IACT,SAAS;IACT,WAAW;IACX,QAAQ;IACR,QAAQ;IACR,KAAK;IACL,OAAO;IACP,QAAQ;IACR,OAAO;IACP,QAAQ;IACR,cAAc;IACd,MAAM;IACN,OAAO;IACP,QAAQ;IACR,WAAW;IACX,MAAM;IACN,KAAK;IACL,QAAQ;IACR,KAAK;IACL,MAAM;IACN,UAAU;IACV,OAAO;IACP,MAAM;IACN,OAAO;CACR,CAAC;AAEF;;;GAGG;AACH,SAAgB,qBAAqB,CAAC,OAAe;IACnD,IAAI,GAAG,GAAW,qCAAyB,CAAC,OAAO,GAAG,EAAE,CAAC,CAAC;IAE1D,OAAO,GAAG,CAAC,OAAO,GAAG,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,iCAAiC;IAC/D,OAAO,OAAO,GAAG,CAAC,EAAE;
|
|
1
|
+
{"version":3,"file":"MinifiedIdentifier.js","sourceRoot":"","sources":["../src/MinifiedIdentifier.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;;AAE3D,4EAA4E;AAC5E,2CAAoF;AAEpF,4IAA4I;AAC5I,MAAM,iBAAiB,GAAa;IAClC,UAAU;IACV,WAAW;IACX,SAAS;IACT,OAAO;IACP,MAAM;IACN,MAAM;IACN,OAAO;IACP,MAAM;IACN,OAAO;IACP,OAAO;IACP,UAAU;IACV,UAAU;IACV,SAAS;IACT,QAAQ;IACR,IAAI;IACJ,QAAQ;IACR,MAAM;IACN,MAAM;IACN,QAAQ;IACR,SAAS;IACT,OAAO;IACP,OAAO;IACP,SAAS;IACT,OAAO;IACP,KAAK;IACL,UAAU;IACV,KAAK;IACL,MAAM;IACN,IAAI;IACJ,YAAY;IACZ,QAAQ;IACR,IAAI;IACJ,YAAY;IACZ,KAAK;IACL,WAAW;IACX,KAAK;IACL,MAAM;IACN,QAAQ;IACR,KAAK;IACL,MAAM;IACN,SAAS;IACT,SAAS;IACT,WAAW;IACX,QAAQ;IACR,QAAQ;IACR,KAAK;IACL,OAAO;IACP,QAAQ;IACR,OAAO;IACP,QAAQ;IACR,cAAc;IACd,MAAM;IACN,OAAO;IACP,QAAQ;IACR,WAAW;IACX,MAAM;IACN,KAAK;IACL,QAAQ;IACR,KAAK;IACL,MAAM;IACN,UAAU;IACV,OAAO;IACP,MAAM;IACN,OAAO;CACR,CAAC;AAEF;;;GAGG;AACH,SAAgB,qBAAqB,CAAC,OAAe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BAAiB,CAAC,GAAG,CAAC,UAAU,CAAC,UAAU,CAAC,CAAC,CAAC,CAAE,GAAG,CAAC,CAAC;IAClE,CAAC;IAED,IAAI,OAAO,IAAI,SAAS,EAAE,CAAC;QACzB,OAAO,GAAG,CAAC;IACb,CAAC;IAED,OAAO,IAAI,EAAE,CAAC;IACd,OAAO,IAAI,gBAAgB,CAAC,GAAG,CAAC,UAAU,CAAC,UAAU,CAAC,CAAC,CAAC,CAAE,CAAC;IAC3D,OAAO,OAAO,CAAC;AACjB,CAAC;AAnBD,4EAmBC;AAED;;GAEG;AACH,MAAM,iBAAiB,GAAa,CAAC,GAAa,EAAE;IAClD,MAAM,QAAQ,GAAa,EAAE,CAAC;IAC9B,KAAK,MAAM,OAAO,IAAI,iBAAiB,EAAE,CAAC;QACxC,MAAM,OAAO,GAAW,gCAAgC,CAAC,OAAO,CAAC,CAAC;QAClE,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,EAAE,CAAC;YACpB,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QACzB,CAAC;IACH,CAAC;IACD,OAAO,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAS,EAAE,CAAS,EAAE,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;AACxD,CAAC,CAAC,EAAE,CAAC;AAEL;;;;;;GAMG;AACH,SAAgB,aAAa,CAAC,OAAe;IAC3C,sCAAsC;IACtC,KACE,IAAI,CAAC,GAAW,CAAC,EAAE,GAAG,GAAW,iBAAiB,CAAC,MAAM,EACzD,CAAC,GAAG,GAAG,IAAI,OAAO,IAAI,iBAAiB,CAAC,CAAC,CAAC,EAC1C,CAAC,EAAE,EACH,CAAC;QACD,EAAE,OAAO,CAAC;IACZ,CAAC;IAED,OAAO,qBAAqB,CAAC,OAAO,CAAC,CAAC;AACxC,CAAC;AAXD,sCAWC","sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.\n// See LICENSE in the project root for license information.\n\n// TODO: Allow dynamic override of these values in the input to the minifier\nimport { IDENTIFIER_LEADING_DIGITS, IDENTIFIER_TRAILING_DIGITS } from './constants';\n\n// Set of ECMAScript reserved keywords (past and present): https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Lexical_grammar\nconst RESERVED_KEYWORDS: string[] = [\n 'abstract',\n 'arguments',\n 'boolean',\n 'break',\n 'byte',\n 'case',\n 'catch',\n 'char',\n 'class',\n 'const',\n 'continue',\n 'debugger',\n 'default',\n 'delete',\n 'do',\n 'double',\n 'else',\n 'enum',\n 'export',\n 'extends',\n 'false',\n 'final',\n 'finally',\n 'float',\n 'for',\n 'function',\n 'get',\n 'goto',\n 'if',\n 'implements',\n 'import',\n 'in',\n 'instanceof',\n 'int',\n 'interface',\n 'let',\n 'long',\n 'native',\n 'new',\n 'null',\n 'package',\n 'private',\n 'protected',\n 'public',\n 'return',\n 'set',\n 'short',\n 'static',\n 'super',\n 'switch',\n 'synchronized',\n 'this',\n 'throw',\n 'throws',\n 'transient',\n 'true',\n 'try',\n 'typeof',\n 'var',\n 'void',\n 'volatile',\n 'while',\n 'with',\n 'yield'\n];\n\n/**\n * Gets a base54 string suitable for use as a JavaScript identifier, not accounting for reserved keywords\n * @param ordinal - The number to convert to a base54 identifier\n */\nexport function getIdentifierInternal(ordinal: number): string {\n let ret: string = IDENTIFIER_LEADING_DIGITS[ordinal % 54];\n\n ordinal = (ordinal / 54) | 0; // eslint-disable-line no-bitwise\n while (ordinal > 0) {\n --ordinal;\n ret += IDENTIFIER_TRAILING_DIGITS[ordinal & 0x3f]; // eslint-disable-line no-bitwise\n ordinal >>>= 6; // eslint-disable-line no-bitwise\n }\n\n return ret;\n}\n\nconst leadingCharIndex: Map<number, number> = new Map();\nfor (let i: number = 0; i < 64; i++) {\n leadingCharIndex.set(IDENTIFIER_LEADING_DIGITS.charCodeAt(i), i);\n}\n\nconst trailingCharIndex: Map<number, number> = new Map();\nfor (let i: number = 0; i < 64; i++) {\n trailingCharIndex.set(IDENTIFIER_TRAILING_DIGITS.charCodeAt(i), i);\n}\n\n/**\n * Converts an identifier into the ordinal that would produce it, not accounting for reserved keywords\n * Returns NaN if the result would exceed 31 bits\n * @param identifier - The identifier to convert to a numeric value\n */\nexport function getOrdinalFromIdentifierInternal(identifier: string): number {\n let ordinal: number = 0;\n\n for (let i: number = identifier.length - 1; i > 0; i--) {\n if (ordinal >= 0x2000000) {\n return NaN;\n }\n\n ordinal <<= 6; // eslint-disable-line no-bitwise\n ordinal += trailingCharIndex.get(identifier.charCodeAt(i))! + 1;\n }\n\n if (ordinal >= 0x2000000) {\n return NaN;\n }\n\n ordinal *= 54;\n ordinal += leadingCharIndex.get(identifier.charCodeAt(0))!;\n return ordinal;\n}\n\n/**\n * getIdentifier(n) would otherwise return each of these specified ECMAScript reserved keywords, which are not legal identifiers.\n */\nconst RESERVED_ORDINALS: number[] = ((): number[] => {\n const reserved: number[] = [];\n for (const keyword of RESERVED_KEYWORDS) {\n const ordinal: number = getOrdinalFromIdentifierInternal(keyword);\n if (!isNaN(ordinal)) {\n reserved.push(ordinal);\n }\n }\n return reserved.sort((x: number, y: number) => x - y);\n})();\n\n/**\n * Gets a base54 string suitable for use as a JavaScript identifier, omitting those that are valid ECMAScript keywords\n *\n * @param ordinal - The number to convert to a base54 identifier\n *\n * @public\n */\nexport function getIdentifier(ordinal: number): string {\n // Need to skip over reserved keywords\n for (\n let i: number = 0, len: number = RESERVED_ORDINALS.length;\n i < len && ordinal >= RESERVED_ORDINALS[i];\n i++\n ) {\n ++ordinal;\n }\n\n return getIdentifierInternal(ordinal);\n}\n"]}
|
|
@@ -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,2BAAW,CAAC,EAAE,CAAC,SAAS,EAAE,KAAK,EAAE,OAAmC,EAAE,EAAE;IACtE,IAAI,CAAC,OAAO,EAAE;
|
|
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,2BAAW,CAAC,EAAE,CAAC,SAAS,EAAE,KAAK,EAAE,OAAmC,EAAE,EAAE;IACtE,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC;IAED,MAAM,MAAM,GAA8B,MAAM,IAAA,wCAAqB,EAAC,OAAO,EAAE,aAAa,CAAC,CAAC;IAE9F,2BAAW,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC;AAClC,CAAC,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\nparentPort!.on('message', async (message: IModuleMinificationRequest) => {\n if (!message) {\n process.exit(0);\n }\n\n const result: IModuleMinificationResult = await minifySingleFileAsync(message, terserOptions);\n\n parentPort!.postMessage(result);\n});\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MinifySingleFile.js","sourceRoot":"","sources":["../src/MinifySingleFile.ts"],"names":[],"mappings":";AAAA,4FAA4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zC,CAAC;QAED,IAAI,MAAM,IAAI,SAAS,EAAE,CAAC;YACxB,MAAM,CAAC,QAAQ,GAAG,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,SAAS,CAAC,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;QACpF,CAAC;QAED,YAAY,CAAC,SAAS,GAAG,UAAU;YACjC,CAAC,CAAC;gBACE,QAAQ,EAAE,IAAI;aACf;YACH,CAAC,CAAC,KAAK,CAAC;QAEV,MAAM,QAAQ,GAAiB,MAAM,IAAA,eAAM,EACzC;YACE,CAAC,UAAU,IAAI,MAAM,CAAC,EAAE,IAAI;SAC7B,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;IACJ,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,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;IACJ,CAAC;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.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;QA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pD,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"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rushstack/module-minifier",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.18",
|
|
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.
|
|
17
|
+
"@rushstack/worker-pool": "0.4.18"
|
|
18
18
|
},
|
|
19
19
|
"devDependencies": {
|
|
20
20
|
"@types/serialize-javascript": "5.0.2",
|
|
21
|
-
"@rushstack/heft": "0.
|
|
21
|
+
"@rushstack/heft": "0.64.1",
|
|
22
22
|
"local-node-rig": "1.0.0"
|
|
23
23
|
},
|
|
24
24
|
"peerDependencies": {
|