utils.js 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615
  1. "use strict";
  2. /** @typedef {import("@jridgewell/trace-mapping").SourceMapInput} SourceMapInput */
  3. /** @typedef {import("terser").FormatOptions} TerserFormatOptions */
  4. /** @typedef {import("terser").MinifyOptions} TerserOptions */
  5. /** @typedef {import("terser").CompressOptions} TerserCompressOptions */
  6. /** @typedef {import("terser").ECMA} TerserECMA */
  7. /** @typedef {import("./index.js").ExtractCommentsOptions} ExtractCommentsOptions */
  8. /** @typedef {import("./index.js").ExtractCommentsFunction} ExtractCommentsFunction */
  9. /** @typedef {import("./index.js").ExtractCommentsCondition} ExtractCommentsCondition */
  10. /** @typedef {import("./index.js").Input} Input */
  11. /** @typedef {import("./index.js").MinimizedResult} MinimizedResult */
  12. /** @typedef {import("./index.js").PredefinedOptions} PredefinedOptions */
  13. /** @typedef {import("./index.js").CustomOptions} CustomOptions */
  14. /**
  15. * @typedef {Array<string>} ExtractedComments
  16. */
  17. const notSettled = Symbol(`not-settled`);
  18. /**
  19. * @template T
  20. * @typedef {() => Promise<T>} Task
  21. */
  22. /**
  23. * Run tasks with limited concurrency.
  24. * @template T
  25. * @param {number} limit - Limit of tasks that run at once.
  26. * @param {Task<T>[]} tasks - List of tasks to run.
  27. * @returns {Promise<T[]>} A promise that fulfills to an array of the results
  28. */
  29. function throttleAll(limit, tasks) {
  30. if (!Number.isInteger(limit) || limit < 1) {
  31. throw new TypeError(`Expected \`limit\` to be a finite number > 0, got \`${limit}\` (${typeof limit})`);
  32. }
  33. if (!Array.isArray(tasks) || !tasks.every(task => typeof task === `function`)) {
  34. throw new TypeError(`Expected \`tasks\` to be a list of functions returning a promise`);
  35. }
  36. return new Promise((resolve, reject) => {
  37. const result = Array(tasks.length).fill(notSettled);
  38. const entries = tasks.entries();
  39. const next = () => {
  40. const {
  41. done,
  42. value
  43. } = entries.next();
  44. if (done) {
  45. const isLast = !result.includes(notSettled);
  46. if (isLast) resolve( /** @type{T[]} **/result);
  47. return;
  48. }
  49. const [index, task] = value;
  50. /**
  51. * @param {T} x
  52. */
  53. const onFulfilled = x => {
  54. result[index] = x;
  55. next();
  56. };
  57. task().then(onFulfilled, reject);
  58. };
  59. Array(limit).fill(0).forEach(next);
  60. });
  61. }
  62. /* istanbul ignore next */
  63. /**
  64. * @param {Input} input
  65. * @param {SourceMapInput | undefined} sourceMap
  66. * @param {PredefinedOptions & CustomOptions} minimizerOptions
  67. * @param {ExtractCommentsOptions | undefined} extractComments
  68. * @return {Promise<MinimizedResult>}
  69. */
  70. async function terserMinify(input, sourceMap, minimizerOptions, extractComments) {
  71. /**
  72. * @param {any} value
  73. * @returns {boolean}
  74. */
  75. const isObject = value => {
  76. const type = typeof value;
  77. return value != null && (type === "object" || type === "function");
  78. };
  79. /**
  80. * @param {TerserOptions & { sourceMap: undefined } & ({ output: TerserFormatOptions & { beautify: boolean } } | { format: TerserFormatOptions & { beautify: boolean } })} terserOptions
  81. * @param {ExtractedComments} extractedComments
  82. * @returns {ExtractCommentsFunction}
  83. */
  84. const buildComments = (terserOptions, extractedComments) => {
  85. /** @type {{ [index: string]: ExtractCommentsCondition }} */
  86. const condition = {};
  87. let comments;
  88. if (terserOptions.format) {
  89. ({
  90. comments
  91. } = terserOptions.format);
  92. } else if (terserOptions.output) {
  93. ({
  94. comments
  95. } = terserOptions.output);
  96. }
  97. condition.preserve = typeof comments !== "undefined" ? comments : false;
  98. if (typeof extractComments === "boolean" && extractComments) {
  99. condition.extract = "some";
  100. } else if (typeof extractComments === "string" || extractComments instanceof RegExp) {
  101. condition.extract = extractComments;
  102. } else if (typeof extractComments === "function") {
  103. condition.extract = extractComments;
  104. } else if (extractComments && isObject(extractComments)) {
  105. condition.extract = typeof extractComments.condition === "boolean" && extractComments.condition ? "some" : typeof extractComments.condition !== "undefined" ? extractComments.condition : "some";
  106. } else {
  107. // No extract
  108. // Preserve using "commentsOpts" or "some"
  109. condition.preserve = typeof comments !== "undefined" ? comments : "some";
  110. condition.extract = false;
  111. }
  112. // Ensure that both conditions are functions
  113. ["preserve", "extract"].forEach(key => {
  114. /** @type {undefined | string} */
  115. let regexStr;
  116. /** @type {undefined | RegExp} */
  117. let regex;
  118. switch (typeof condition[key]) {
  119. case "boolean":
  120. condition[key] = condition[key] ? () => true : () => false;
  121. break;
  122. case "function":
  123. break;
  124. case "string":
  125. if (condition[key] === "all") {
  126. condition[key] = () => true;
  127. break;
  128. }
  129. if (condition[key] === "some") {
  130. condition[key] = /** @type {ExtractCommentsFunction} */
  131. (astNode, comment) => (comment.type === "comment2" || comment.type === "comment1") && /@preserve|@lic|@cc_on|^\**!/i.test(comment.value);
  132. break;
  133. }
  134. regexStr = /** @type {string} */condition[key];
  135. condition[key] = /** @type {ExtractCommentsFunction} */
  136. (astNode, comment) => new RegExp( /** @type {string} */regexStr).test(comment.value);
  137. break;
  138. default:
  139. regex = /** @type {RegExp} */condition[key];
  140. condition[key] = /** @type {ExtractCommentsFunction} */
  141. (astNode, comment) => /** @type {RegExp} */regex.test(comment.value);
  142. }
  143. });
  144. // Redefine the comments function to extract and preserve
  145. // comments according to the two conditions
  146. return (astNode, comment) => {
  147. if ( /** @type {{ extract: ExtractCommentsFunction }} */
  148. condition.extract(astNode, comment)) {
  149. const commentText = comment.type === "comment2" ? `/*${comment.value}*/` : `//${comment.value}`;
  150. // Don't include duplicate comments
  151. if (!extractedComments.includes(commentText)) {
  152. extractedComments.push(commentText);
  153. }
  154. }
  155. return (/** @type {{ preserve: ExtractCommentsFunction }} */condition.preserve(astNode, comment)
  156. );
  157. };
  158. };
  159. /**
  160. * @param {PredefinedOptions & TerserOptions} [terserOptions={}]
  161. * @returns {TerserOptions & { sourceMap: undefined } & { compress: TerserCompressOptions } & ({ output: TerserFormatOptions & { beautify: boolean } } | { format: TerserFormatOptions & { beautify: boolean } })}
  162. */
  163. const buildTerserOptions = (terserOptions = {}) => {
  164. // Need deep copy objects to avoid https://github.com/terser/terser/issues/366
  165. return {
  166. ...terserOptions,
  167. compress: typeof terserOptions.compress === "boolean" ? terserOptions.compress ? {} : false : {
  168. ...terserOptions.compress
  169. },
  170. // ecma: terserOptions.ecma,
  171. // ie8: terserOptions.ie8,
  172. // keep_classnames: terserOptions.keep_classnames,
  173. // keep_fnames: terserOptions.keep_fnames,
  174. mangle: terserOptions.mangle == null ? true : typeof terserOptions.mangle === "boolean" ? terserOptions.mangle : {
  175. ...terserOptions.mangle
  176. },
  177. // module: terserOptions.module,
  178. // nameCache: { ...terserOptions.toplevel },
  179. // the `output` option is deprecated
  180. ...(terserOptions.format ? {
  181. format: {
  182. beautify: false,
  183. ...terserOptions.format
  184. }
  185. } : {
  186. output: {
  187. beautify: false,
  188. ...terserOptions.output
  189. }
  190. }),
  191. parse: {
  192. ...terserOptions.parse
  193. },
  194. // safari10: terserOptions.safari10,
  195. // Ignoring sourceMap from options
  196. // eslint-disable-next-line no-undefined
  197. sourceMap: undefined
  198. // toplevel: terserOptions.toplevel
  199. };
  200. };
  201. // eslint-disable-next-line global-require
  202. const {
  203. minify
  204. } = require("terser");
  205. // Copy `terser` options
  206. const terserOptions = buildTerserOptions(minimizerOptions);
  207. // Let terser generate a SourceMap
  208. if (sourceMap) {
  209. // @ts-ignore
  210. terserOptions.sourceMap = {
  211. asObject: true
  212. };
  213. }
  214. /** @type {ExtractedComments} */
  215. const extractedComments = [];
  216. if (terserOptions.output) {
  217. terserOptions.output.comments = buildComments(terserOptions, extractedComments);
  218. } else if (terserOptions.format) {
  219. terserOptions.format.comments = buildComments(terserOptions, extractedComments);
  220. }
  221. if (terserOptions.compress) {
  222. // More optimizations
  223. if (typeof terserOptions.compress.ecma === "undefined") {
  224. terserOptions.compress.ecma = terserOptions.ecma;
  225. }
  226. // https://github.com/webpack/webpack/issues/16135
  227. if (terserOptions.ecma === 5 && typeof terserOptions.compress.arrows === "undefined") {
  228. terserOptions.compress.arrows = false;
  229. }
  230. }
  231. const [[filename, code]] = Object.entries(input);
  232. const result = await minify({
  233. [filename]: code
  234. }, terserOptions);
  235. return {
  236. code: /** @type {string} **/result.code,
  237. // @ts-ignore
  238. // eslint-disable-next-line no-undefined
  239. map: result.map ? /** @type {SourceMapInput} **/result.map : undefined,
  240. extractedComments
  241. };
  242. }
  243. /**
  244. * @returns {string | undefined}
  245. */
  246. terserMinify.getMinimizerVersion = () => {
  247. let packageJson;
  248. try {
  249. // eslint-disable-next-line global-require
  250. packageJson = require("terser/package.json");
  251. } catch (error) {
  252. // Ignore
  253. }
  254. return packageJson && packageJson.version;
  255. };
  256. /* istanbul ignore next */
  257. /**
  258. * @param {Input} input
  259. * @param {SourceMapInput | undefined} sourceMap
  260. * @param {PredefinedOptions & CustomOptions} minimizerOptions
  261. * @param {ExtractCommentsOptions | undefined} extractComments
  262. * @return {Promise<MinimizedResult>}
  263. */
  264. async function uglifyJsMinify(input, sourceMap, minimizerOptions, extractComments) {
  265. /**
  266. * @param {any} value
  267. * @returns {boolean}
  268. */
  269. const isObject = value => {
  270. const type = typeof value;
  271. return value != null && (type === "object" || type === "function");
  272. };
  273. /**
  274. * @param {import("uglify-js").MinifyOptions & { sourceMap: undefined } & { output: import("uglify-js").OutputOptions & { beautify: boolean }}} uglifyJsOptions
  275. * @param {ExtractedComments} extractedComments
  276. * @returns {ExtractCommentsFunction}
  277. */
  278. const buildComments = (uglifyJsOptions, extractedComments) => {
  279. /** @type {{ [index: string]: ExtractCommentsCondition }} */
  280. const condition = {};
  281. const {
  282. comments
  283. } = uglifyJsOptions.output;
  284. condition.preserve = typeof comments !== "undefined" ? comments : false;
  285. if (typeof extractComments === "boolean" && extractComments) {
  286. condition.extract = "some";
  287. } else if (typeof extractComments === "string" || extractComments instanceof RegExp) {
  288. condition.extract = extractComments;
  289. } else if (typeof extractComments === "function") {
  290. condition.extract = extractComments;
  291. } else if (extractComments && isObject(extractComments)) {
  292. condition.extract = typeof extractComments.condition === "boolean" && extractComments.condition ? "some" : typeof extractComments.condition !== "undefined" ? extractComments.condition : "some";
  293. } else {
  294. // No extract
  295. // Preserve using "commentsOpts" or "some"
  296. condition.preserve = typeof comments !== "undefined" ? comments : "some";
  297. condition.extract = false;
  298. }
  299. // Ensure that both conditions are functions
  300. ["preserve", "extract"].forEach(key => {
  301. /** @type {undefined | string} */
  302. let regexStr;
  303. /** @type {undefined | RegExp} */
  304. let regex;
  305. switch (typeof condition[key]) {
  306. case "boolean":
  307. condition[key] = condition[key] ? () => true : () => false;
  308. break;
  309. case "function":
  310. break;
  311. case "string":
  312. if (condition[key] === "all") {
  313. condition[key] = () => true;
  314. break;
  315. }
  316. if (condition[key] === "some") {
  317. condition[key] = /** @type {ExtractCommentsFunction} */
  318. (astNode, comment) => (comment.type === "comment2" || comment.type === "comment1") && /@preserve|@lic|@cc_on|^\**!/i.test(comment.value);
  319. break;
  320. }
  321. regexStr = /** @type {string} */condition[key];
  322. condition[key] = /** @type {ExtractCommentsFunction} */
  323. (astNode, comment) => new RegExp( /** @type {string} */regexStr).test(comment.value);
  324. break;
  325. default:
  326. regex = /** @type {RegExp} */condition[key];
  327. condition[key] = /** @type {ExtractCommentsFunction} */
  328. (astNode, comment) => /** @type {RegExp} */regex.test(comment.value);
  329. }
  330. });
  331. // Redefine the comments function to extract and preserve
  332. // comments according to the two conditions
  333. return (astNode, comment) => {
  334. if ( /** @type {{ extract: ExtractCommentsFunction }} */
  335. condition.extract(astNode, comment)) {
  336. const commentText = comment.type === "comment2" ? `/*${comment.value}*/` : `//${comment.value}`;
  337. // Don't include duplicate comments
  338. if (!extractedComments.includes(commentText)) {
  339. extractedComments.push(commentText);
  340. }
  341. }
  342. return (/** @type {{ preserve: ExtractCommentsFunction }} */condition.preserve(astNode, comment)
  343. );
  344. };
  345. };
  346. /**
  347. * @param {PredefinedOptions & import("uglify-js").MinifyOptions} [uglifyJsOptions={}]
  348. * @returns {import("uglify-js").MinifyOptions & { sourceMap: undefined } & { output: import("uglify-js").OutputOptions & { beautify: boolean }}}
  349. */
  350. const buildUglifyJsOptions = (uglifyJsOptions = {}) => {
  351. // eslint-disable-next-line no-param-reassign
  352. delete minimizerOptions.ecma;
  353. // eslint-disable-next-line no-param-reassign
  354. delete minimizerOptions.module;
  355. // Need deep copy objects to avoid https://github.com/terser/terser/issues/366
  356. return {
  357. ...uglifyJsOptions,
  358. // warnings: uglifyJsOptions.warnings,
  359. parse: {
  360. ...uglifyJsOptions.parse
  361. },
  362. compress: typeof uglifyJsOptions.compress === "boolean" ? uglifyJsOptions.compress : {
  363. ...uglifyJsOptions.compress
  364. },
  365. mangle: uglifyJsOptions.mangle == null ? true : typeof uglifyJsOptions.mangle === "boolean" ? uglifyJsOptions.mangle : {
  366. ...uglifyJsOptions.mangle
  367. },
  368. output: {
  369. beautify: false,
  370. ...uglifyJsOptions.output
  371. },
  372. // Ignoring sourceMap from options
  373. // eslint-disable-next-line no-undefined
  374. sourceMap: undefined
  375. // toplevel: uglifyJsOptions.toplevel
  376. // nameCache: { ...uglifyJsOptions.toplevel },
  377. // ie8: uglifyJsOptions.ie8,
  378. // keep_fnames: uglifyJsOptions.keep_fnames,
  379. };
  380. };
  381. // eslint-disable-next-line global-require, import/no-extraneous-dependencies
  382. const {
  383. minify
  384. } = require("uglify-js");
  385. // Copy `uglify-js` options
  386. const uglifyJsOptions = buildUglifyJsOptions(minimizerOptions);
  387. // Let terser generate a SourceMap
  388. if (sourceMap) {
  389. // @ts-ignore
  390. uglifyJsOptions.sourceMap = true;
  391. }
  392. /** @type {ExtractedComments} */
  393. const extractedComments = [];
  394. // @ts-ignore
  395. uglifyJsOptions.output.comments = buildComments(uglifyJsOptions, extractedComments);
  396. const [[filename, code]] = Object.entries(input);
  397. const result = await minify({
  398. [filename]: code
  399. }, uglifyJsOptions);
  400. return {
  401. code: result.code,
  402. // eslint-disable-next-line no-undefined
  403. map: result.map ? JSON.parse(result.map) : undefined,
  404. errors: result.error ? [result.error] : [],
  405. warnings: result.warnings || [],
  406. extractedComments
  407. };
  408. }
  409. /**
  410. * @returns {string | undefined}
  411. */
  412. uglifyJsMinify.getMinimizerVersion = () => {
  413. let packageJson;
  414. try {
  415. // eslint-disable-next-line global-require, import/no-extraneous-dependencies
  416. packageJson = require("uglify-js/package.json");
  417. } catch (error) {
  418. // Ignore
  419. }
  420. return packageJson && packageJson.version;
  421. };
  422. /* istanbul ignore next */
  423. /**
  424. * @param {Input} input
  425. * @param {SourceMapInput | undefined} sourceMap
  426. * @param {PredefinedOptions & CustomOptions} minimizerOptions
  427. * @return {Promise<MinimizedResult>}
  428. */
  429. async function swcMinify(input, sourceMap, minimizerOptions) {
  430. /**
  431. * @param {PredefinedOptions & import("@swc/core").JsMinifyOptions} [swcOptions={}]
  432. * @returns {import("@swc/core").JsMinifyOptions & { sourceMap: undefined } & { compress: import("@swc/core").TerserCompressOptions }}
  433. */
  434. const buildSwcOptions = (swcOptions = {}) => {
  435. // Need deep copy objects to avoid https://github.com/terser/terser/issues/366
  436. return {
  437. ...swcOptions,
  438. compress: typeof swcOptions.compress === "boolean" ? swcOptions.compress ? {} : false : {
  439. ...swcOptions.compress
  440. },
  441. mangle: swcOptions.mangle == null ? true : typeof swcOptions.mangle === "boolean" ? swcOptions.mangle : {
  442. ...swcOptions.mangle
  443. },
  444. // ecma: swcOptions.ecma,
  445. // keep_classnames: swcOptions.keep_classnames,
  446. // keep_fnames: swcOptions.keep_fnames,
  447. // module: swcOptions.module,
  448. // safari10: swcOptions.safari10,
  449. // toplevel: swcOptions.toplevel
  450. // eslint-disable-next-line no-undefined
  451. sourceMap: undefined
  452. };
  453. };
  454. // eslint-disable-next-line import/no-extraneous-dependencies, global-require
  455. const swc = require("@swc/core");
  456. // Copy `swc` options
  457. const swcOptions = buildSwcOptions(minimizerOptions);
  458. // Let `swc` generate a SourceMap
  459. if (sourceMap) {
  460. // @ts-ignore
  461. swcOptions.sourceMap = true;
  462. }
  463. if (swcOptions.compress) {
  464. // More optimizations
  465. if (typeof swcOptions.compress.ecma === "undefined") {
  466. swcOptions.compress.ecma = swcOptions.ecma;
  467. }
  468. // https://github.com/webpack/webpack/issues/16135
  469. if (swcOptions.ecma === 5 && typeof swcOptions.compress.arrows === "undefined") {
  470. swcOptions.compress.arrows = false;
  471. }
  472. }
  473. const [[filename, code]] = Object.entries(input);
  474. const result = await swc.minify(code, swcOptions);
  475. let map;
  476. if (result.map) {
  477. map = JSON.parse(result.map);
  478. // TODO workaround for swc because `filename` is not preset as in `swc` signature as for `terser`
  479. map.sources = [filename];
  480. delete map.sourcesContent;
  481. }
  482. return {
  483. code: result.code,
  484. map
  485. };
  486. }
  487. /**
  488. * @returns {string | undefined}
  489. */
  490. swcMinify.getMinimizerVersion = () => {
  491. let packageJson;
  492. try {
  493. // eslint-disable-next-line global-require, import/no-extraneous-dependencies
  494. packageJson = require("@swc/core/package.json");
  495. } catch (error) {
  496. // Ignore
  497. }
  498. return packageJson && packageJson.version;
  499. };
  500. /* istanbul ignore next */
  501. /**
  502. * @param {Input} input
  503. * @param {SourceMapInput | undefined} sourceMap
  504. * @param {PredefinedOptions & CustomOptions} minimizerOptions
  505. * @return {Promise<MinimizedResult>}
  506. */
  507. async function esbuildMinify(input, sourceMap, minimizerOptions) {
  508. /**
  509. * @param {PredefinedOptions & import("esbuild").TransformOptions} [esbuildOptions={}]
  510. * @returns {import("esbuild").TransformOptions}
  511. */
  512. const buildEsbuildOptions = (esbuildOptions = {}) => {
  513. // eslint-disable-next-line no-param-reassign
  514. delete esbuildOptions.ecma;
  515. if (esbuildOptions.module) {
  516. // eslint-disable-next-line no-param-reassign
  517. esbuildOptions.format = "esm";
  518. }
  519. // eslint-disable-next-line no-param-reassign
  520. delete esbuildOptions.module;
  521. // Need deep copy objects to avoid https://github.com/terser/terser/issues/366
  522. return {
  523. minify: true,
  524. legalComments: "inline",
  525. ...esbuildOptions,
  526. sourcemap: false
  527. };
  528. };
  529. // eslint-disable-next-line import/no-extraneous-dependencies, global-require
  530. const esbuild = require("esbuild");
  531. // Copy `esbuild` options
  532. const esbuildOptions = buildEsbuildOptions(minimizerOptions);
  533. // Let `esbuild` generate a SourceMap
  534. if (sourceMap) {
  535. esbuildOptions.sourcemap = true;
  536. esbuildOptions.sourcesContent = false;
  537. }
  538. const [[filename, code]] = Object.entries(input);
  539. esbuildOptions.sourcefile = filename;
  540. const result = await esbuild.transform(code, esbuildOptions);
  541. return {
  542. code: result.code,
  543. // eslint-disable-next-line no-undefined
  544. map: result.map ? JSON.parse(result.map) : undefined,
  545. warnings: result.warnings.length > 0 ? result.warnings.map(item => {
  546. const plugin = item.pluginName ? `\nPlugin Name: ${item.pluginName}` : "";
  547. const location = item.location ? `\n\n${item.location.file}:${item.location.line}:${item.location.column}:\n ${item.location.line} | ${item.location.lineText}\n\nSuggestion: ${item.location.suggestion}` : "";
  548. const notes = item.notes.length > 0 ? `\n\nNotes:\n${item.notes.map(note => `${note.location ? `[${note.location.file}:${note.location.line}:${note.location.column}] ` : ""}${note.text}${note.location ? `\nSuggestion: ${note.location.suggestion}` : ""}${note.location ? `\nLine text:\n${note.location.lineText}\n` : ""}`).join("\n")}` : "";
  549. return `${item.text} [${item.id}]${plugin}${location}${item.detail ? `\nDetails:\n${item.detail}` : ""}${notes}`;
  550. }) : []
  551. };
  552. }
  553. /**
  554. * @returns {string | undefined}
  555. */
  556. esbuildMinify.getMinimizerVersion = () => {
  557. let packageJson;
  558. try {
  559. // eslint-disable-next-line global-require, import/no-extraneous-dependencies
  560. packageJson = require("esbuild/package.json");
  561. } catch (error) {
  562. // Ignore
  563. }
  564. return packageJson && packageJson.version;
  565. };
  566. module.exports = {
  567. throttleAll,
  568. terserMinify,
  569. uglifyJsMinify,
  570. swcMinify,
  571. esbuildMinify
  572. };