@node-minify/utils 10.3.0 → 10.5.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.
Files changed (78) hide show
  1. package/dist/buildArgs.d.ts +0 -1
  2. package/dist/buildArgs.d.ts.map +1 -1
  3. package/dist/buildArgs.js +1 -1
  4. package/dist/buildArgs.js.map +1 -1
  5. package/dist/compressSingleFile.d.ts +1 -2
  6. package/dist/compressSingleFile.d.ts.map +1 -1
  7. package/dist/compressSingleFile.js +1 -1
  8. package/dist/compressSingleFile.js.map +1 -1
  9. package/dist/compressor-resolver.d.ts +32 -3
  10. package/dist/compressor-resolver.d.ts.map +1 -1
  11. package/dist/compressor-resolver.js +64 -36
  12. package/dist/compressor-resolver.js.map +1 -1
  13. package/dist/deleteFile.d.ts.map +1 -1
  14. package/dist/deleteFile.js +1 -1
  15. package/dist/deprecation.d.ts.map +1 -1
  16. package/dist/ensureStringContent.d.ts.map +1 -1
  17. package/dist/error.d.ts.map +1 -1
  18. package/dist/error.js +31 -2
  19. package/dist/error.js.map +1 -0
  20. package/dist/errors.d.ts +27 -0
  21. package/dist/errors.d.ts.map +1 -0
  22. package/dist/errors.js +32 -0
  23. package/dist/errors.js.map +1 -0
  24. package/dist/getContentFromFiles.d.ts.map +1 -1
  25. package/dist/getContentFromFiles.js +2 -2
  26. package/dist/getContentFromFiles.js.map +1 -1
  27. package/dist/getFilesizeBrotliInBytes.d.ts +17 -1
  28. package/dist/getFilesizeBrotliInBytes.d.ts.map +1 -1
  29. package/dist/getFilesizeBrotliInBytes.js +40 -6
  30. package/dist/getFilesizeBrotliInBytes.js.map +1 -1
  31. package/dist/getFilesizeGzippedInBytes.d.ts +13 -7
  32. package/dist/getFilesizeGzippedInBytes.d.ts.map +1 -1
  33. package/dist/getFilesizeGzippedInBytes.js +40 -17
  34. package/dist/getFilesizeGzippedInBytes.js.map +1 -1
  35. package/dist/getFilesizeInBytes.d.ts.map +1 -1
  36. package/dist/index.d.ts +7 -5
  37. package/dist/index.js +9 -7
  38. package/dist/isImageFile.d.ts.map +1 -1
  39. package/dist/isValidFile.d.ts.map +1 -1
  40. package/dist/isValidFile.js +45 -2
  41. package/dist/isValidFile.js.map +1 -0
  42. package/dist/prettyBytes.d.ts.map +1 -1
  43. package/dist/prettyBytes.js +1 -1
  44. package/dist/readFile.d.ts.map +1 -1
  45. package/dist/readFile.js +1 -1
  46. package/dist/run.d.ts +1 -2
  47. package/dist/run.d.ts.map +1 -1
  48. package/dist/run.js +34 -29
  49. package/dist/run.js.map +1 -1
  50. package/dist/setFileNameMin.d.ts.map +1 -1
  51. package/dist/setFileNameMin.js +15 -9
  52. package/dist/setFileNameMin.js.map +1 -1
  53. package/dist/setPublicFolder.d.ts +1 -0
  54. package/dist/setPublicFolder.d.ts.map +1 -1
  55. package/dist/setPublicFolder.js +6 -1
  56. package/dist/setPublicFolder.js.map +1 -1
  57. package/dist/sourceMap.d.ts +27 -0
  58. package/dist/sourceMap.d.ts.map +1 -0
  59. package/dist/sourceMap.js +37 -0
  60. package/dist/sourceMap.js.map +1 -0
  61. package/dist/{types-CzkB7gxg.d.ts → types-D10QejTN.d.ts} +8 -20
  62. package/dist/types-D10QejTN.d.ts.map +1 -0
  63. package/dist/types.d.ts.map +1 -1
  64. package/dist/wildcards.d.ts +21 -3
  65. package/dist/wildcards.d.ts.map +1 -1
  66. package/dist/wildcards.js +40 -16
  67. package/dist/wildcards.js.map +1 -1
  68. package/dist/writeFile.d.ts.map +1 -1
  69. package/dist/writeFile.js +95 -2
  70. package/dist/writeFile.js.map +1 -0
  71. package/package.json +2 -2
  72. package/dist/error-Ctspysdk.js +0 -32
  73. package/dist/error-Ctspysdk.js.map +0 -1
  74. package/dist/isValidFile-BW5AgBWb.js +0 -46
  75. package/dist/isValidFile-BW5AgBWb.js.map +0 -1
  76. package/dist/types-CzkB7gxg.d.ts.map +0 -1
  77. package/dist/writeFile-DgV8EbFP.js +0 -123
  78. package/dist/writeFile-DgV8EbFP.js.map +0 -1
@@ -1,5 +1,5 @@
1
- import { t as FileOperationError } from "./error-Ctspysdk.js";
2
- import { t as isValidFile } from "./isValidFile-BW5AgBWb.js";
1
+ import { FileOperationError } from "./error.js";
2
+ import { isValidFile } from "./isValidFile.js";
3
3
  import { prettyBytes } from "./prettyBytes.js";
4
4
  import { existsSync } from "node:fs";
5
5
  import { readFile } from "node:fs/promises";
@@ -13,11 +13,45 @@ import { brotliCompress, constants } from "node:zlib";
13
13
  * MIT Licensed
14
14
  */
15
15
  const brotliCompressAsync = promisify(brotliCompress);
16
+ /**
17
+ * Compute the brotli-compressed size of a file in bytes.
18
+ *
19
+ * @param file - Path to the file to measure
20
+ * @returns The brotli-compressed size in bytes
21
+ * @throws FileOperationError if the file does not exist or the path is not a valid file
22
+ * @internal
23
+ */
24
+ async function getBrotliSize(file) {
25
+ if (!existsSync(file)) throw new FileOperationError("access", file, /* @__PURE__ */ new Error("File does not exist"));
26
+ if (!isValidFile(file)) throw new FileOperationError("access", file, /* @__PURE__ */ new Error("Path is not a valid file"));
27
+ return (await brotliCompressAsync(await readFile(file), { params: { [constants.BROTLI_PARAM_QUALITY]: constants.BROTLI_MAX_QUALITY } })).length;
28
+ }
29
+ /**
30
+ * Get the brotli-compressed size of a file as a human-readable string.
31
+ *
32
+ * @param file - Path to the file
33
+ * @returns The brotli-compressed size formatted for display (for example, "1.5 kB")
34
+ */
16
35
  async function getFilesizeBrotliInBytes(file) {
17
36
  try {
18
- if (!existsSync(file)) throw new FileOperationError("access", file, /* @__PURE__ */ new Error("File does not exist"));
19
- if (!isValidFile(file)) throw new FileOperationError("access", file, /* @__PURE__ */ new Error("Path is not a valid file"));
20
- return prettyBytes((await brotliCompressAsync(await readFile(file), { params: { [constants.BROTLI_PARAM_QUALITY]: constants.BROTLI_MAX_QUALITY } })).length);
37
+ return prettyBytes(await getBrotliSize(file));
38
+ } catch (error) {
39
+ if (error instanceof FileOperationError) throw error;
40
+ throw new FileOperationError("get brotli size of", file, error);
41
+ }
42
+ }
43
+ /**
44
+ * Get the brotli-compressed file size in bytes.
45
+ *
46
+ * @param file - Path to the file
47
+ * @returns Brotli-compressed file size in bytes
48
+ * @example
49
+ * const bytes = await getFilesizeBrotliRaw('bundle.js')
50
+ * console.log(bytes) // 12583
51
+ */
52
+ async function getFilesizeBrotliRaw(file) {
53
+ try {
54
+ return await getBrotliSize(file);
21
55
  } catch (error) {
22
56
  if (error instanceof FileOperationError) throw error;
23
57
  throw new FileOperationError("get brotli size of", file, error);
@@ -25,5 +59,5 @@ async function getFilesizeBrotliInBytes(file) {
25
59
  }
26
60
 
27
61
  //#endregion
28
- export { getFilesizeBrotliInBytes };
62
+ export { getFilesizeBrotliInBytes, getFilesizeBrotliRaw };
29
63
  //# sourceMappingURL=getFilesizeBrotliInBytes.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"getFilesizeBrotliInBytes.js","names":[],"sources":["../src/getFilesizeBrotliInBytes.ts"],"sourcesContent":["/*!\n * node-minify\n * Copyright (c) 2011-2026 Rodolphe Stoclin\n * MIT Licensed\n */\n\nimport { existsSync } from \"node:fs\";\nimport { readFile } from \"node:fs/promises\";\nimport { promisify } from \"node:util\";\nimport { brotliCompress, constants } from \"node:zlib\";\nimport { FileOperationError } from \"./error.ts\";\nimport { isValidFile } from \"./isValidFile.ts\";\nimport { prettyBytes } from \"./prettyBytes.ts\";\n\nconst brotliCompressAsync = promisify(brotliCompress);\n\nexport async function getFilesizeBrotliInBytes(file: string): Promise<string> {\n try {\n if (!existsSync(file)) {\n throw new FileOperationError(\n \"access\",\n file,\n new Error(\"File does not exist\")\n );\n }\n\n if (!isValidFile(file)) {\n throw new FileOperationError(\n \"access\",\n file,\n new Error(\"Path is not a valid file\")\n );\n }\n\n const content = await readFile(file);\n const compressed = await brotliCompressAsync(content, {\n params: {\n [constants.BROTLI_PARAM_QUALITY]: constants.BROTLI_MAX_QUALITY,\n },\n });\n\n return prettyBytes(compressed.length);\n } catch (error) {\n if (error instanceof FileOperationError) {\n throw error;\n }\n throw new FileOperationError(\n \"get brotli size of\",\n file,\n error as Error\n );\n }\n}\n"],"mappings":";;;;;;;;;;;;;;AAcA,MAAM,sBAAsB,UAAU,eAAe;AAErD,eAAsB,yBAAyB,MAA+B;AAC1E,KAAI;AACA,MAAI,CAAC,WAAW,KAAK,CACjB,OAAM,IAAI,mBACN,UACA,sBACA,IAAI,MAAM,sBAAsB,CACnC;AAGL,MAAI,CAAC,YAAY,KAAK,CAClB,OAAM,IAAI,mBACN,UACA,sBACA,IAAI,MAAM,2BAA2B,CACxC;AAUL,SAAO,aANY,MAAM,oBADT,MAAM,SAAS,KAAK,EACkB,EAClD,QAAQ,GACH,UAAU,uBAAuB,UAAU,oBAC/C,EACJ,CAAC,EAE4B,OAAO;UAChC,OAAO;AACZ,MAAI,iBAAiB,mBACjB,OAAM;AAEV,QAAM,IAAI,mBACN,sBACA,MACA,MACH"}
1
+ {"version":3,"file":"getFilesizeBrotliInBytes.js","names":[],"sources":["../src/getFilesizeBrotliInBytes.ts"],"sourcesContent":["/*!\n * node-minify\n * Copyright (c) 2011-2026 Rodolphe Stoclin\n * MIT Licensed\n */\n\nimport { existsSync } from \"node:fs\";\nimport { readFile } from \"node:fs/promises\";\nimport { promisify } from \"node:util\";\nimport { brotliCompress, constants } from \"node:zlib\";\nimport { FileOperationError } from \"./error.ts\";\nimport { isValidFile } from \"./isValidFile.ts\";\nimport { prettyBytes } from \"./prettyBytes.ts\";\n\nconst brotliCompressAsync = promisify(brotliCompress);\n\n/**\n * Compute the brotli-compressed size of a file in bytes.\n *\n * @param file - Path to the file to measure\n * @returns The brotli-compressed size in bytes\n * @throws FileOperationError if the file does not exist or the path is not a valid file\n * @internal\n */\nasync function getBrotliSize(file: string): Promise<number> {\n if (!existsSync(file)) {\n throw new FileOperationError(\n \"access\",\n file,\n new Error(\"File does not exist\")\n );\n }\n\n if (!isValidFile(file)) {\n throw new FileOperationError(\n \"access\",\n file,\n new Error(\"Path is not a valid file\")\n );\n }\n\n const content = await readFile(file);\n const compressed = await brotliCompressAsync(content, {\n params: {\n [constants.BROTLI_PARAM_QUALITY]: constants.BROTLI_MAX_QUALITY,\n },\n });\n\n return compressed.length;\n}\n\n/**\n * Get the brotli-compressed size of a file as a human-readable string.\n *\n * @param file - Path to the file\n * @returns The brotli-compressed size formatted for display (for example, \"1.5 kB\")\n */\nexport async function getFilesizeBrotliInBytes(file: string): Promise<string> {\n try {\n const size = await getBrotliSize(file);\n return prettyBytes(size);\n } catch (error) {\n if (error instanceof FileOperationError) {\n throw error;\n }\n throw new FileOperationError(\n \"get brotli size of\",\n file,\n error as Error\n );\n }\n}\n\n/**\n * Get the brotli-compressed file size in bytes.\n *\n * @param file - Path to the file\n * @returns Brotli-compressed file size in bytes\n * @example\n * const bytes = await getFilesizeBrotliRaw('bundle.js')\n * console.log(bytes) // 12583\n */\nexport async function getFilesizeBrotliRaw(file: string): Promise<number> {\n try {\n return await getBrotliSize(file);\n } catch (error) {\n if (error instanceof FileOperationError) {\n throw error;\n }\n throw new FileOperationError(\n \"get brotli size of\",\n file,\n error as Error\n );\n }\n}\n"],"mappings":";;;;;;;;;;;;;;AAcA,MAAM,sBAAsB,UAAU,eAAe;;;;;;;;;AAUrD,eAAe,cAAc,MAA+B;AACxD,KAAI,CAAC,WAAW,KAAK,CACjB,OAAM,IAAI,mBACN,UACA,sBACA,IAAI,MAAM,sBAAsB,CACnC;AAGL,KAAI,CAAC,YAAY,KAAK,CAClB,OAAM,IAAI,mBACN,UACA,sBACA,IAAI,MAAM,2BAA2B,CACxC;AAUL,SANmB,MAAM,oBADT,MAAM,SAAS,KAAK,EACkB,EAClD,QAAQ,GACH,UAAU,uBAAuB,UAAU,oBAC/C,EACJ,CAAC,EAEgB;;;;;;;;AAStB,eAAsB,yBAAyB,MAA+B;AAC1E,KAAI;AAEA,SAAO,YADM,MAAM,cAAc,KAAK,CACd;UACnB,OAAO;AACZ,MAAI,iBAAiB,mBACjB,OAAM;AAEV,QAAM,IAAI,mBACN,sBACA,MACA,MACH;;;;;;;;;;;;AAaT,eAAsB,qBAAqB,MAA+B;AACtE,KAAI;AACA,SAAO,MAAM,cAAc,KAAK;UAC3B,OAAO;AACZ,MAAI,iBAAiB,mBACjB,OAAM;AAEV,QAAM,IAAI,mBACN,sBACA,MACA,MACH"}
@@ -5,15 +5,21 @@
5
5
  * MIT Licensed
6
6
  */
7
7
  /**
8
- * Get the gzipped file size as a human-readable string.
8
+ * Get the gzipped size of a file as a human-readable string.
9
+ *
9
10
  * @param file - Path to the file
10
- * @returns Formatted gzipped file size string (e.g., "1.5 kB")
11
- * @throws {FileOperationError} If file doesn't exist or operation fails
12
- * @example
13
- * const size = await getFilesizeGzippedInBytes('file.js')
14
- * console.log(size) // '1.5 kB'
11
+ * @returns The gzipped size formatted for display (for example, "1.5 kB")
15
12
  */
16
13
  declare function getFilesizeGzippedInBytes(file: string): Promise<string>;
14
+ /**
15
+ * Get the gzipped file size in bytes.
16
+ * @param file - Path to the file
17
+ * @returns Gzipped file size in bytes
18
+ * @example
19
+ * const bytes = await getFilesizeGzippedRaw('bundle.js')
20
+ * console.log(bytes) // 12583
21
+ */
22
+ declare function getFilesizeGzippedRaw(file: string): Promise<number>;
17
23
  //#endregion
18
- export { getFilesizeGzippedInBytes };
24
+ export { getFilesizeGzippedInBytes, getFilesizeGzippedRaw };
19
25
  //# sourceMappingURL=getFilesizeGzippedInBytes.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"getFilesizeGzippedInBytes.d.ts","names":[],"sources":["../src/getFilesizeGzippedInBytes.ts"],"sourcesContent":[],"mappings":";;AAoBA;;;;;;;;;;;;;iBAAsB,yBAAA,gBAAyC"}
1
+ {"version":3,"file":"getFilesizeGzippedInBytes.d.ts","names":[],"sources":["../src/getFilesizeGzippedInBytes.ts"],"mappings":";;AAgDA;;;;;AAwBA;;;;;iBAxBsB,yBAAA,CAA0B,IAAA,WAAe,OAAA;;;;;;;;;iBAwBzC,qBAAA,CAAsB,IAAA,WAAe,OAAA"}
@@ -1,7 +1,7 @@
1
- import { t as FileOperationError } from "./error-Ctspysdk.js";
2
- import { t as isValidFile } from "./isValidFile-BW5AgBWb.js";
1
+ import { FileOperationError } from "./error.js";
2
+ import { isValidFile } from "./isValidFile.js";
3
3
  import { prettyBytes } from "./prettyBytes.js";
4
- import { createReadStream, existsSync } from "node:fs";
4
+ import { existsSync } from "node:fs";
5
5
 
6
6
  //#region src/getFilesizeGzippedInBytes.ts
7
7
  /*!
@@ -10,28 +10,51 @@ import { createReadStream, existsSync } from "node:fs";
10
10
  * MIT Licensed
11
11
  */
12
12
  /**
13
- * Get the gzipped file size as a human-readable string.
13
+ * Compute the gzipped size of a file in bytes.
14
+ *
15
+ * @param file - Path to the file to measure
16
+ * @returns The gzipped size in bytes
17
+ * @throws FileOperationError if the file does not exist or the path is not a valid file
18
+ * @internal
19
+ */
20
+ async function getGzipSize(file) {
21
+ if (!existsSync(file)) throw new FileOperationError("access", file, /* @__PURE__ */ new Error("File does not exist"));
22
+ if (!isValidFile(file)) throw new FileOperationError("access", file, /* @__PURE__ */ new Error("Path is not a valid file"));
23
+ const { gzipSize } = await import("gzip-size");
24
+ const { readFile } = await import("node:fs/promises");
25
+ return gzipSize(await readFile(file));
26
+ }
27
+ /**
28
+ * Get the gzipped size of a file as a human-readable string.
29
+ *
14
30
  * @param file - Path to the file
15
- * @returns Formatted gzipped file size string (e.g., "1.5 kB")
16
- * @throws {FileOperationError} If file doesn't exist or operation fails
17
- * @example
18
- * const size = await getFilesizeGzippedInBytes('file.js')
19
- * console.log(size) // '1.5 kB'
31
+ * @returns The gzipped size formatted for display (for example, "1.5 kB")
20
32
  */
21
33
  async function getFilesizeGzippedInBytes(file) {
22
34
  try {
23
- if (!existsSync(file)) throw new FileOperationError("access", file, /* @__PURE__ */ new Error("File does not exist"));
24
- if (!isValidFile(file)) throw new FileOperationError("access", file, /* @__PURE__ */ new Error("Path is not a valid file"));
25
- const { gzipSizeStream } = await import("gzip-size");
26
- const source = createReadStream(file);
27
- return prettyBytes(await new Promise((resolve, reject) => {
28
- source.pipe(gzipSizeStream()).on("gzip-size", resolve).on("error", reject);
29
- }));
35
+ return prettyBytes(await getGzipSize(file));
36
+ } catch (error) {
37
+ if (error instanceof FileOperationError) throw error;
38
+ throw new FileOperationError("get gzipped size of", file, error);
39
+ }
40
+ }
41
+ /**
42
+ * Get the gzipped file size in bytes.
43
+ * @param file - Path to the file
44
+ * @returns Gzipped file size in bytes
45
+ * @example
46
+ * const bytes = await getFilesizeGzippedRaw('bundle.js')
47
+ * console.log(bytes) // 12583
48
+ */
49
+ async function getFilesizeGzippedRaw(file) {
50
+ try {
51
+ return await getGzipSize(file);
30
52
  } catch (error) {
53
+ if (error instanceof FileOperationError) throw error;
31
54
  throw new FileOperationError("get gzipped size of", file, error);
32
55
  }
33
56
  }
34
57
 
35
58
  //#endregion
36
- export { getFilesizeGzippedInBytes };
59
+ export { getFilesizeGzippedInBytes, getFilesizeGzippedRaw };
37
60
  //# sourceMappingURL=getFilesizeGzippedInBytes.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"getFilesizeGzippedInBytes.js","names":[],"sources":["../src/getFilesizeGzippedInBytes.ts"],"sourcesContent":["/*!\n * node-minify\n * Copyright (c) 2011-2026 Rodolphe Stoclin\n * MIT Licensed\n */\n\nimport { createReadStream, existsSync } from \"node:fs\";\nimport { FileOperationError } from \"./error.ts\";\nimport { isValidFile } from \"./isValidFile.ts\";\nimport { prettyBytes } from \"./prettyBytes.ts\";\n\n/**\n * Get the gzipped file size as a human-readable string.\n * @param file - Path to the file\n * @returns Formatted gzipped file size string (e.g., \"1.5 kB\")\n * @throws {FileOperationError} If file doesn't exist or operation fails\n * @example\n * const size = await getFilesizeGzippedInBytes('file.js')\n * console.log(size) // '1.5 kB'\n */\nexport async function getFilesizeGzippedInBytes(file: string): Promise<string> {\n try {\n if (!existsSync(file)) {\n throw new FileOperationError(\n \"access\",\n file,\n new Error(\"File does not exist\")\n );\n }\n\n if (!isValidFile(file)) {\n throw new FileOperationError(\n \"access\",\n file,\n new Error(\"Path is not a valid file\")\n );\n }\n\n const { gzipSizeStream } = await import(\"gzip-size\");\n const source = createReadStream(file);\n\n const size = await new Promise<number>((resolve, reject) => {\n source\n .pipe(gzipSizeStream())\n .on(\"gzip-size\", resolve)\n .on(\"error\", reject);\n });\n\n return prettyBytes(size);\n } catch (error) {\n throw new FileOperationError(\n \"get gzipped size of\",\n file,\n error as Error\n );\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAoBA,eAAsB,0BAA0B,MAA+B;AAC3E,KAAI;AACA,MAAI,CAAC,WAAW,KAAK,CACjB,OAAM,IAAI,mBACN,UACA,sBACA,IAAI,MAAM,sBAAsB,CACnC;AAGL,MAAI,CAAC,YAAY,KAAK,CAClB,OAAM,IAAI,mBACN,UACA,sBACA,IAAI,MAAM,2BAA2B,CACxC;EAGL,MAAM,EAAE,mBAAmB,MAAM,OAAO;EACxC,MAAM,SAAS,iBAAiB,KAAK;AASrC,SAAO,YAPM,MAAM,IAAI,SAAiB,SAAS,WAAW;AACxD,UACK,KAAK,gBAAgB,CAAC,CACtB,GAAG,aAAa,QAAQ,CACxB,GAAG,SAAS,OAAO;IAC1B,CAEsB;UACnB,OAAO;AACZ,QAAM,IAAI,mBACN,uBACA,MACA,MACH"}
1
+ {"version":3,"file":"getFilesizeGzippedInBytes.js","names":[],"sources":["../src/getFilesizeGzippedInBytes.ts"],"sourcesContent":["/*!\n * node-minify\n * Copyright (c) 2011-2026 Rodolphe Stoclin\n * MIT Licensed\n */\n\nimport { existsSync } from \"node:fs\";\nimport { FileOperationError } from \"./error.ts\";\nimport { isValidFile } from \"./isValidFile.ts\";\nimport { prettyBytes } from \"./prettyBytes.ts\";\n\n/**\n * Compute the gzipped size of a file in bytes.\n *\n * @param file - Path to the file to measure\n * @returns The gzipped size in bytes\n * @throws FileOperationError if the file does not exist or the path is not a valid file\n * @internal\n */\nasync function getGzipSize(file: string): Promise<number> {\n if (!existsSync(file)) {\n throw new FileOperationError(\n \"access\",\n file,\n new Error(\"File does not exist\")\n );\n }\n\n if (!isValidFile(file)) {\n throw new FileOperationError(\n \"access\",\n file,\n new Error(\"Path is not a valid file\")\n );\n }\n\n const { gzipSize } = await import(\"gzip-size\");\n const { readFile } = await import(\"node:fs/promises\");\n const content = await readFile(file);\n return gzipSize(content);\n}\n\n/**\n * Get the gzipped size of a file as a human-readable string.\n *\n * @param file - Path to the file\n * @returns The gzipped size formatted for display (for example, \"1.5 kB\")\n */\nexport async function getFilesizeGzippedInBytes(file: string): Promise<string> {\n try {\n const size = await getGzipSize(file);\n return prettyBytes(size);\n } catch (error) {\n if (error instanceof FileOperationError) {\n throw error;\n }\n throw new FileOperationError(\n \"get gzipped size of\",\n file,\n error as Error\n );\n }\n}\n\n/**\n * Get the gzipped file size in bytes.\n * @param file - Path to the file\n * @returns Gzipped file size in bytes\n * @example\n * const bytes = await getFilesizeGzippedRaw('bundle.js')\n * console.log(bytes) // 12583\n */\nexport async function getFilesizeGzippedRaw(file: string): Promise<number> {\n try {\n return await getGzipSize(file);\n } catch (error) {\n if (error instanceof FileOperationError) {\n throw error;\n }\n throw new FileOperationError(\n \"get gzipped size of\",\n file,\n error as Error\n );\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAmBA,eAAe,YAAY,MAA+B;AACtD,KAAI,CAAC,WAAW,KAAK,CACjB,OAAM,IAAI,mBACN,UACA,sBACA,IAAI,MAAM,sBAAsB,CACnC;AAGL,KAAI,CAAC,YAAY,KAAK,CAClB,OAAM,IAAI,mBACN,UACA,sBACA,IAAI,MAAM,2BAA2B,CACxC;CAGL,MAAM,EAAE,aAAa,MAAM,OAAO;CAClC,MAAM,EAAE,aAAa,MAAM,OAAO;AAElC,QAAO,SADS,MAAM,SAAS,KAAK,CACZ;;;;;;;;AAS5B,eAAsB,0BAA0B,MAA+B;AAC3E,KAAI;AAEA,SAAO,YADM,MAAM,YAAY,KAAK,CACZ;UACnB,OAAO;AACZ,MAAI,iBAAiB,mBACjB,OAAM;AAEV,QAAM,IAAI,mBACN,uBACA,MACA,MACH;;;;;;;;;;;AAYT,eAAsB,sBAAsB,MAA+B;AACvE,KAAI;AACA,SAAO,MAAM,YAAY,KAAK;UACzB,OAAO;AACZ,MAAI,iBAAiB,mBACjB,OAAM;AAEV,QAAM,IAAI,mBACN,uBACA,MACA,MACH"}
@@ -1 +1 @@
1
- {"version":3,"file":"getFilesizeInBytes.d.ts","names":[],"sources":["../src/getFilesizeInBytes.ts"],"sourcesContent":[],"mappings":";;AAgBA;;;;;;;;;;;cAAa"}
1
+ {"version":3,"file":"getFilesizeInBytes.d.ts","names":[],"sources":["../src/getFilesizeInBytes.ts"],"mappings":";;AAgBA;;;;;;;;;;;cAAa,kBAAA,GAAsB,IAAA"}
package/dist/index.d.ts CHANGED
@@ -1,13 +1,14 @@
1
1
  import { BuildArgsOptions } from "./types.js";
2
2
  import { buildArgs, toBuildArgsOptions } from "./buildArgs.js";
3
3
  import { compressSingleFile } from "./compressSingleFile.js";
4
- import { CompressorResolution, getKnownExportName, isBuiltInCompressor, resolveCompressor } from "./compressor-resolver.js";
4
+ import { CompressorResolution, getKnownExportName, isBuiltInCompressor, isLocalPath, resolveCompressor, tryResolveBuiltIn, tryResolveLocalFile, tryResolveNpmPackage } from "./compressor-resolver.js";
5
5
  import { deleteFile } from "./deleteFile.js";
6
6
  import { resetDeprecationWarnings, warnDeprecation } from "./deprecation.js";
7
7
  import { ensureStringContent } from "./ensureStringContent.js";
8
+ import { validateMinifyResult, wrapMinificationError } from "./errors.js";
8
9
  import { getContentFromFiles, getContentFromFilesAsync } from "./getContentFromFiles.js";
9
- import { getFilesizeBrotliInBytes } from "./getFilesizeBrotliInBytes.js";
10
- import { getFilesizeGzippedInBytes } from "./getFilesizeGzippedInBytes.js";
10
+ import { getFilesizeBrotliInBytes, getFilesizeBrotliRaw } from "./getFilesizeBrotliInBytes.js";
11
+ import { getFilesizeGzippedInBytes, getFilesizeGzippedRaw } from "./getFilesizeGzippedInBytes.js";
11
12
  import { getFilesizeInBytes } from "./getFilesizeInBytes.js";
12
13
  import { isImageFile } from "./isImageFile.js";
13
14
  import { isValidFile, isValidFileAsync } from "./isValidFile.js";
@@ -16,6 +17,7 @@ import { readFile, readFileAsync } from "./readFile.js";
16
17
  import { run } from "./run.js";
17
18
  import { setFileNameMin } from "./setFileNameMin.js";
18
19
  import { setPublicFolder } from "./setPublicFolder.js";
19
- import { wildcards } from "./wildcards.js";
20
+ import { extractSourceMapOption, getSourceMapBoolean } from "./sourceMap.js";
21
+ import { DEFAULT_IGNORES, WildcardOptions, wildcards } from "./wildcards.js";
20
22
  import { writeFile, writeFileAsync } from "./writeFile.js";
21
- export { type BuildArgsOptions, type CompressorResolution, buildArgs, compressSingleFile, deleteFile, ensureStringContent, getContentFromFiles, getContentFromFilesAsync, getFilesizeBrotliInBytes, getFilesizeGzippedInBytes, getFilesizeInBytes, getKnownExportName, isBuiltInCompressor, isImageFile, isValidFile, isValidFileAsync, prettyBytes, readFile, readFileAsync, resetDeprecationWarnings, resolveCompressor, run, setFileNameMin, setPublicFolder, toBuildArgsOptions, warnDeprecation, wildcards, writeFile, writeFileAsync };
23
+ export { type BuildArgsOptions, type CompressorResolution, DEFAULT_IGNORES, type WildcardOptions, buildArgs, compressSingleFile, deleteFile, ensureStringContent, extractSourceMapOption, getContentFromFiles, getContentFromFilesAsync, getFilesizeBrotliInBytes, getFilesizeBrotliRaw, getFilesizeGzippedInBytes, getFilesizeGzippedRaw, getFilesizeInBytes, getKnownExportName, getSourceMapBoolean, isBuiltInCompressor, isImageFile, isLocalPath, isValidFile, isValidFileAsync, prettyBytes, readFile, readFileAsync, resetDeprecationWarnings, resolveCompressor, run, setFileNameMin, setPublicFolder, toBuildArgsOptions, tryResolveBuiltIn, tryResolveLocalFile, tryResolveNpmPackage, validateMinifyResult, warnDeprecation, wildcards, wrapMinificationError, writeFile, writeFileAsync };
package/dist/index.js CHANGED
@@ -1,21 +1,23 @@
1
1
  import { buildArgs, toBuildArgsOptions } from "./buildArgs.js";
2
- import { n as isValidFileAsync, t as isValidFile } from "./isValidFile-BW5AgBWb.js";
2
+ import { isValidFile, isValidFileAsync } from "./isValidFile.js";
3
3
  import { getContentFromFiles, getContentFromFilesAsync } from "./getContentFromFiles.js";
4
4
  import { isImageFile } from "./isImageFile.js";
5
5
  import { readFile, readFileAsync } from "./readFile.js";
6
- import { n as writeFileAsync, t as writeFile } from "./writeFile-DgV8EbFP.js";
6
+ import { writeFile, writeFileAsync } from "./writeFile.js";
7
7
  import { run } from "./run.js";
8
8
  import { compressSingleFile } from "./compressSingleFile.js";
9
- import { getKnownExportName, isBuiltInCompressor, resolveCompressor } from "./compressor-resolver.js";
9
+ import { getKnownExportName, isBuiltInCompressor, isLocalPath, resolveCompressor, tryResolveBuiltIn, tryResolveLocalFile, tryResolveNpmPackage } from "./compressor-resolver.js";
10
10
  import { deleteFile } from "./deleteFile.js";
11
11
  import { resetDeprecationWarnings, warnDeprecation } from "./deprecation.js";
12
12
  import { ensureStringContent } from "./ensureStringContent.js";
13
+ import { validateMinifyResult, wrapMinificationError } from "./errors.js";
13
14
  import { prettyBytes } from "./prettyBytes.js";
14
- import { getFilesizeBrotliInBytes } from "./getFilesizeBrotliInBytes.js";
15
- import { getFilesizeGzippedInBytes } from "./getFilesizeGzippedInBytes.js";
15
+ import { getFilesizeBrotliInBytes, getFilesizeBrotliRaw } from "./getFilesizeBrotliInBytes.js";
16
+ import { getFilesizeGzippedInBytes, getFilesizeGzippedRaw } from "./getFilesizeGzippedInBytes.js";
16
17
  import { getFilesizeInBytes } from "./getFilesizeInBytes.js";
17
18
  import { setFileNameMin } from "./setFileNameMin.js";
18
19
  import { setPublicFolder } from "./setPublicFolder.js";
19
- import { wildcards } from "./wildcards.js";
20
+ import { extractSourceMapOption, getSourceMapBoolean } from "./sourceMap.js";
21
+ import { DEFAULT_IGNORES, wildcards } from "./wildcards.js";
20
22
 
21
- export { buildArgs, compressSingleFile, deleteFile, ensureStringContent, getContentFromFiles, getContentFromFilesAsync, getFilesizeBrotliInBytes, getFilesizeGzippedInBytes, getFilesizeInBytes, getKnownExportName, isBuiltInCompressor, isImageFile, isValidFile, isValidFileAsync, prettyBytes, readFile, readFileAsync, resetDeprecationWarnings, resolveCompressor, run, setFileNameMin, setPublicFolder, toBuildArgsOptions, warnDeprecation, wildcards, writeFile, writeFileAsync };
23
+ export { DEFAULT_IGNORES, buildArgs, compressSingleFile, deleteFile, ensureStringContent, extractSourceMapOption, getContentFromFiles, getContentFromFilesAsync, getFilesizeBrotliInBytes, getFilesizeBrotliRaw, getFilesizeGzippedInBytes, getFilesizeGzippedRaw, getFilesizeInBytes, getKnownExportName, getSourceMapBoolean, isBuiltInCompressor, isImageFile, isLocalPath, isValidFile, isValidFileAsync, prettyBytes, readFile, readFileAsync, resetDeprecationWarnings, resolveCompressor, run, setFileNameMin, setPublicFolder, toBuildArgsOptions, tryResolveBuiltIn, tryResolveLocalFile, tryResolveNpmPackage, validateMinifyResult, warnDeprecation, wildcards, wrapMinificationError, writeFile, writeFileAsync };
@@ -1 +1 @@
1
- {"version":3,"file":"isImageFile.d.ts","names":[],"sources":["../src/isImageFile.ts"],"sourcesContent":[],"mappings":";;AA0BA;;;;;;;;;;iBAAgB,WAAA"}
1
+ {"version":3,"file":"isImageFile.d.ts","names":[],"sources":["../src/isImageFile.ts"],"mappings":";;AA0BA;;;;;;;;;;iBAAgB,WAAA,CAAY,QAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"isValidFile.d.ts","names":[],"sources":["../src/isValidFile.ts"],"sourcesContent":[],"mappings":";;AAoBA;AAeA;;;;;;;;;;;;;iBAfgB,WAAA;;;;;;;;iBAeM,gBAAA,gBAAgC"}
1
+ {"version":3,"file":"isValidFile.d.ts","names":[],"sources":["../src/isValidFile.ts"],"mappings":";;AAoBA;;;;;AAeA;;;;;;;;;iBAfgB,WAAA,CAAY,IAAA;;;;;;;;iBAeN,gBAAA,CAAiB,IAAA,WAAe,OAAA"}
@@ -1,3 +1,46 @@
1
- import { n as isValidFileAsync, t as isValidFile } from "./isValidFile-BW5AgBWb.js";
1
+ import { FileOperationError } from "./error.js";
2
+ import { existsSync, lstatSync } from "node:fs";
3
+ import { lstat } from "node:fs/promises";
2
4
 
3
- export { isValidFile, isValidFileAsync };
5
+ //#region src/isValidFile.ts
6
+ /*!
7
+ * node-minify
8
+ * Copyright (c) 2011-2026 Rodolphe Stoclin
9
+ * MIT Licensed
10
+ */
11
+ /**
12
+ * Check if the path is a valid file.
13
+ * @param path Path to check
14
+ * @returns true if path exists and is a file, false otherwise
15
+ * @throws {FileOperationError} If filesystem operations fail
16
+ * @example
17
+ * if (isValidFile('path/to/file.js')) {
18
+ * // do something
19
+ * }
20
+ */
21
+ function isValidFile(path) {
22
+ try {
23
+ return existsSync(path) && !lstatSync(path).isDirectory();
24
+ } catch (error) {
25
+ throw new FileOperationError("validate", path, error);
26
+ }
27
+ }
28
+ /**
29
+ * Determine whether a filesystem path refers to an existing file (not a directory).
30
+ *
31
+ * @param path - Path to check
32
+ * @returns `true` if the path exists and is a file, `false` otherwise.
33
+ * @throws {FileOperationError} If a filesystem error other than `ENOENT` occurs while validating the path.
34
+ */
35
+ async function isValidFileAsync(path) {
36
+ try {
37
+ return !(await lstat(path)).isDirectory();
38
+ } catch (error) {
39
+ if (error && typeof error === "object" && "code" in error && error.code === "ENOENT") return false;
40
+ throw new FileOperationError("validate", path, error instanceof Error ? error : new Error(String(error)));
41
+ }
42
+ }
43
+
44
+ //#endregion
45
+ export { isValidFile, isValidFileAsync };
46
+ //# sourceMappingURL=isValidFile.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"isValidFile.js","names":[],"sources":["../src/isValidFile.ts"],"sourcesContent":["/*!\n * node-minify\n * Copyright (c) 2011-2026 Rodolphe Stoclin\n * MIT Licensed\n */\n\nimport { existsSync, lstatSync } from \"node:fs\";\nimport { lstat } from \"node:fs/promises\";\nimport { FileOperationError } from \"./error.ts\";\n\n/**\n * Check if the path is a valid file.\n * @param path Path to check\n * @returns true if path exists and is a file, false otherwise\n * @throws {FileOperationError} If filesystem operations fail\n * @example\n * if (isValidFile('path/to/file.js')) {\n * // do something\n * }\n */\nexport function isValidFile(path: string): boolean {\n try {\n return existsSync(path) && !lstatSync(path).isDirectory();\n } catch (error) {\n throw new FileOperationError(\"validate\", path, error as Error);\n }\n}\n\n/**\n * Determine whether a filesystem path refers to an existing file (not a directory).\n *\n * @param path - Path to check\n * @returns `true` if the path exists and is a file, `false` otherwise.\n * @throws {FileOperationError} If a filesystem error other than `ENOENT` occurs while validating the path.\n */\nexport async function isValidFileAsync(path: string): Promise<boolean> {\n try {\n const stats = await lstat(path);\n return !stats.isDirectory();\n } catch (error: unknown) {\n if (\n error &&\n typeof error === \"object\" &&\n \"code\" in error &&\n error.code === \"ENOENT\"\n ) {\n return false;\n }\n throw new FileOperationError(\n \"validate\",\n path,\n error instanceof Error ? error : new Error(String(error))\n );\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAoBA,SAAgB,YAAY,MAAuB;AAC/C,KAAI;AACA,SAAO,WAAW,KAAK,IAAI,CAAC,UAAU,KAAK,CAAC,aAAa;UACpD,OAAO;AACZ,QAAM,IAAI,mBAAmB,YAAY,MAAM,MAAe;;;;;;;;;;AAWtE,eAAsB,iBAAiB,MAAgC;AACnE,KAAI;AAEA,SAAO,EADO,MAAM,MAAM,KAAK,EACjB,aAAa;UACtB,OAAgB;AACrB,MACI,SACA,OAAO,UAAU,YACjB,UAAU,SACV,MAAM,SAAS,SAEf,QAAO;AAEX,QAAM,IAAI,mBACN,YACA,MACA,iBAAiB,QAAQ,QAAQ,IAAI,MAAM,OAAO,MAAM,CAAC,CAC5D"}
@@ -1 +1 @@
1
- {"version":3,"file":"prettyBytes.d.ts","names":[],"sources":["../src/prettyBytes.ts"],"sourcesContent":[],"mappings":";;AAoBA;;;;;;;;;;;;;;iBAAgB,WAAA"}
1
+ {"version":3,"file":"prettyBytes.d.ts","names":[],"sources":["../src/prettyBytes.ts"],"mappings":";;AAoBA;;;;;;;;;;;;;;iBAAgB,WAAA,CAAY,GAAA"}
@@ -1,4 +1,4 @@
1
- import { n as ValidationError } from "./error-Ctspysdk.js";
1
+ import { ValidationError } from "./error.js";
2
2
 
3
3
  //#region src/prettyBytes.ts
4
4
  /*!
@@ -1 +1 @@
1
- {"version":3,"file":"readFile.d.ts","names":[],"sources":["../src/readFile.ts"],"sourcesContent":[],"mappings":";;AAuBA;AACA;AACA;AACA;AA4BA;AACA;AAIA;AAIA;;;;;;;;;;iBAxCgB,QAAA;iBACA,QAAA,gCAAwC;iBACxC,QAAA;iBACA,QAAA,6CAAqD;;;;;;;;iBA4B/C,aAAA,gBAA6B;iBAC7B,aAAA,gCAGnB,QAAQ;iBACW,aAAA,iCAGnB;iBACmB,aAAA,oCAGnB,iBAAiB"}
1
+ {"version":3,"file":"readFile.d.ts","names":[],"sources":["../src/readFile.ts"],"mappings":";;AAuBA;;;;;AACA;;;;;;;;;AACA;;;iBAFgB,QAAA,CAAS,IAAA;AAAA,iBACT,QAAA,CAAS,IAAA,UAAc,QAAA,SAAiB,MAAA;AAAA,iBACxC,QAAA,CAAS,IAAA,UAAc,QAAA;AAAA,iBACvB,QAAA,CAAS,IAAA,UAAc,QAAA,sBAA8B,MAAA;;;;;;;;iBA4B/C,aAAA,CAAc,IAAA,WAAe,OAAA;AAAA,iBAC7B,aAAA,CAClB,IAAA,UACA,QAAA,SACD,OAAA,CAAQ,MAAA;AAAA,iBACW,aAAA,CAClB,IAAA,UACA,QAAA,UACD,OAAA;AAAA,iBACmB,aAAA,CAClB,IAAA,UACA,QAAA,aACD,OAAA,UAAiB,MAAA"}
package/dist/readFile.js CHANGED
@@ -1,4 +1,4 @@
1
- import { t as FileOperationError } from "./error-Ctspysdk.js";
1
+ import { FileOperationError } from "./error.js";
2
2
  import { readFileSync } from "node:fs";
3
3
  import { readFile as readFile$1 } from "node:fs/promises";
4
4
 
package/dist/run.d.ts CHANGED
@@ -1,7 +1,6 @@
1
- import { n as CompressorOptions, r as MinifierOptions } from "./types-CzkB7gxg.js";
1
+ import { n as CompressorOptions, r as MinifierOptions } from "./types-D10QejTN.js";
2
2
 
3
3
  //#region src/run.d.ts
4
-
5
4
  /**
6
5
  * Execute the configured compressor and persist its outputs according to the provided settings.
7
6
  *
package/dist/run.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"run.d.ts","names":[],"sources":["../src/run.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;;;;iBAyBsB,cAAc,oBAAoB;;;;GAIrD,gBAAgB,KAAK"}
1
+ {"version":3,"file":"run.d.ts","names":[],"sources":["../src/run.ts"],"mappings":";;;;;;;;;;;;iBAyBsB,GAAA,WAAc,iBAAA,GAAoB,iBAAA,CAAA,CAAA;EACpD,QAAA;EACA,OAAA;EACA;AAAA,GACD,eAAA,CAAgB,CAAA,IAAK,OAAA"}
package/dist/run.js CHANGED
@@ -1,5 +1,5 @@
1
- import { n as ValidationError } from "./error-Ctspysdk.js";
2
- import { n as writeFileAsync } from "./writeFile-DgV8EbFP.js";
1
+ import { ValidationError } from "./error.js";
2
+ import { writeFileAsync } from "./writeFile.js";
3
3
  import { join, parse } from "node:path";
4
4
 
5
5
  //#region src/run.ts
@@ -42,16 +42,20 @@ function validateCompressorResult(result, settings) {
42
42
  if (!("code" in obj) || typeof obj.code !== "string") throw new ValidationError(`Compressor '${settings.compressorLabel || "compressor"}' must return { code: string }. Got: ${JSON.stringify(Object.keys(obj))}`);
43
43
  }
44
44
  /**
45
- * Write compressor result outputs to disk unless the operation is in-memory.
45
+ * Write compressor outputs to configured output paths unless execution is in-memory.
46
46
  *
47
- * Writes multiple output files when `result.outputs` is provided, writes a binary `result.buffer` to the configured output when present, otherwise writes `result.code`. If a source map is available and a source map URL can be resolved from `settings`, the map is written alongside the main output.
47
+ * Writes multiple outputs when `result.outputs` is present, writes `result.buffer` if provided, otherwise writes `result.code`. If `result.map` exists and a source map URL can be resolved from `settings`, the map file is written alongside the main output. The function returns without writing when `settings.output` is not set, when `settings.content` is provided (in-memory mode), or when `settings.allowEmptyOutput` is true and `result.code` is an empty string.
48
48
  *
49
- * @param result - The compressor result containing `code`, optional `buffer`, `map`, or `outputs` describing one or more outputs
50
- * @param settings - Settings that include output destination(s) and optional in-memory `content` which disables disk writes
51
- * @param index - Optional index used when writing to multiple targets or when tracking a particular input within a batch
49
+ * @param result - Compressor result containing `code` and optional `buffer`, `map`, or `outputs`
50
+ * @param settings - Settings that determine output destinations and in-memory mode
51
+ * @param index - Optional batch/index marker forwarded to underlying write operations
52
52
  */
53
53
  async function writeOutput(result, settings, index) {
54
- if (Boolean(settings.content) || !settings.output) return;
54
+ if (settings.content !== void 0 || !settings.output) return;
55
+ const hasBuffer = result.buffer && result.buffer.length > 0;
56
+ const hasOutputs = result.outputs && result.outputs.length > 0;
57
+ const isCompletelyEmpty = !(result.code !== "") && !hasBuffer && !hasOutputs;
58
+ if (settings.allowEmptyOutput && isCompletelyEmpty) return;
55
59
  if (result.outputs && result.outputs.length > 0) {
56
60
  await writeMultipleOutputs(result.outputs, settings, index);
57
61
  return;
@@ -80,14 +84,18 @@ async function writeOutput(result, settings, index) {
80
84
  await Promise.all(writePromises);
81
85
  }
82
86
  /**
83
- * Extract the first input file path from the input configuration.
87
+ * Extract an input file path from the input configuration.
84
88
  *
85
89
  * @param input - A single file path, an array of paths, or undefined
86
- * @returns The first input file path, or an empty string if none available
90
+ * @param index - Optional index of the current input being processed when `input` is an array
91
+ * @returns The indexed input file path when available, otherwise the first input file path or an empty string
87
92
  */
88
- function getFirstInputFile(input) {
93
+ function getInputFile(input, index) {
89
94
  if (typeof input === "string") return input;
90
- if (Array.isArray(input) && input.length > 0) return input[0] ?? "";
95
+ if (Array.isArray(input) && input.length > 0) {
96
+ if (index !== void 0) return input[index] ?? "";
97
+ return input[0] ?? "";
98
+ }
91
99
  return "";
92
100
  }
93
101
  /**
@@ -101,28 +109,25 @@ function getFirstInputFile(input) {
101
109
  */
102
110
  async function writeMultipleOutputs(outputs, settings, index) {
103
111
  const output = settings.output;
104
- const isArrayOutput = Array.isArray(output);
105
- const outputsArray = isArrayOutput ? output : [output];
106
- const inputFile = getFirstInputFile(settings.input);
112
+ const perFormatOutputs = Array.isArray(output) && index === void 0;
113
+ const inputFile = getInputFile(settings.input, index);
107
114
  const inputDir = parse(inputFile).dir;
108
- const inputBase = parse(inputFile).name;
115
+ const baseName = parse(inputFile).name || "output";
116
+ const currentOutput = Array.isArray(output) && index !== void 0 ? output[index] : output;
117
+ const withFormatExtension = (file, format) => file.endsWith(`.${format}`) ? file : `${file}.${format}`;
109
118
  const promises = outputs.map(async (outputResult, i) => {
110
119
  if (!outputResult) return;
111
120
  const format = outputResult.format || "out";
112
121
  let targetFile;
113
- const arrayItem = outputsArray[i];
114
- if (isArrayOutput && arrayItem !== void 0 && arrayItem !== "$1" && arrayItem.trim() !== "") targetFile = arrayItem;
115
- else if (typeof output === "string" && output === "$1") {
116
- const baseName = inputBase || "output";
117
- targetFile = inputDir ? join(inputDir, `${baseName}.${format}`) : `${baseName}.${format}`;
118
- } else if (typeof output === "string" && output.includes("$1")) {
119
- const extensionlessName = inputBase || "output";
120
- targetFile = `${output.replace(/\$1/g, extensionlessName)}.${format}`;
121
- } else if (typeof output === "string") targetFile = `${output}.${format}`;
122
- else {
123
- const baseName = inputBase || "output";
124
- targetFile = inputDir ? join(inputDir, `${baseName}.${format}`) : `${baseName}.${format}`;
125
- }
122
+ const arrayItem = perFormatOutputs ? output[i] : void 0;
123
+ if (perFormatOutputs && arrayItem !== void 0 && arrayItem !== "$1" && arrayItem.trim() !== "") if (arrayItem.includes("$1")) {
124
+ const outputFile = arrayItem.replace(/\$1/g, baseName);
125
+ targetFile = parse(outputFile).ext ? outputFile : withFormatExtension(outputFile, format);
126
+ } else targetFile = parse(arrayItem).ext ? arrayItem : withFormatExtension(arrayItem, format);
127
+ else if (typeof currentOutput === "string" && currentOutput === "$1") targetFile = inputDir ? join(inputDir, `${baseName}.${format}`) : `${baseName}.${format}`;
128
+ else if (typeof currentOutput === "string" && currentOutput.includes("$1")) targetFile = withFormatExtension(currentOutput.replace(/\$1/g, baseName), format);
129
+ else if (typeof currentOutput === "string" && currentOutput.trim() !== "") targetFile = withFormatExtension(currentOutput, format);
130
+ else targetFile = inputDir ? join(inputDir, `${baseName}.${format}`) : `${baseName}.${format}`;
126
131
  await writeFileAsync({
127
132
  file: targetFile,
128
133
  content: outputResult.content,
package/dist/run.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"run.js","names":["targetFile: string"],"sources":["../src/run.ts"],"sourcesContent":["/*!\n * node-minify\n * Copyright (c) 2011-2026 Rodolphe Stoclin\n * MIT Licensed\n */\n\nimport { join, parse } from \"node:path\";\nimport type {\n CompressorOptions,\n CompressorResult,\n MinifierOptions,\n Settings,\n} from \"@node-minify/types\";\nimport { ValidationError } from \"./error.ts\";\nimport { writeFileAsync } from \"./writeFile.ts\";\n\n/**\n * Execute the configured compressor and persist its outputs according to the provided settings.\n *\n * @param settings - Compressor settings including output targets, options, and the `compressor` implementation\n * @param content - The input content to be compressed\n * @param index - Optional index used when processing multiple inputs\n * @returns The minified code produced by the compressor\n * @throws ValidationError If `settings` is missing, `settings.compressor` is not provided, or the compressor returns an invalid result\n */\nexport async function run<T extends CompressorOptions = CompressorOptions>({\n settings,\n content,\n index,\n}: MinifierOptions<T>): Promise<string> {\n if (!settings) {\n throw new ValidationError(\"Settings must be provided\");\n }\n\n if (!settings.compressor) {\n throw new ValidationError(\"Compressor must be provided in settings\");\n }\n\n const result = await settings.compressor({\n settings,\n content,\n index,\n });\n\n validateCompressorResult(result, settings);\n\n await writeOutput(result, settings, index);\n\n return result.code;\n}\n\n/**\n * Verify that a compressor result is an object containing a string `code` property and narrow its type to `CompressorResult`.\n *\n * @param result - The value returned by the compressor to validate.\n * @param settings - Minifier settings (used to derive the compressor label for error messages).\n * @throws ValidationError - If `result` is not an object with a string `code` property.\n */\nfunction validateCompressorResult<\n T extends CompressorOptions = CompressorOptions,\n>(result: unknown, settings: Settings<T>): asserts result is CompressorResult {\n if (!result || typeof result !== \"object\") {\n const label = settings.compressorLabel || \"compressor\";\n throw new ValidationError(\n `Compressor '${label}' returned invalid result. Expected an object with { code: string }.`\n );\n }\n\n const obj = result as Record<string, unknown>;\n if (!(\"code\" in obj) || typeof obj.code !== \"string\") {\n const label = settings.compressorLabel || \"compressor\";\n throw new ValidationError(\n `Compressor '${label}' must return { code: string }. Got: ${JSON.stringify(Object.keys(obj))}`\n );\n }\n}\n\n/**\n * Write compressor result outputs to disk unless the operation is in-memory.\n *\n * Writes multiple output files when `result.outputs` is provided, writes a binary `result.buffer` to the configured output when present, otherwise writes `result.code`. If a source map is available and a source map URL can be resolved from `settings`, the map is written alongside the main output.\n *\n * @param result - The compressor result containing `code`, optional `buffer`, `map`, or `outputs` describing one or more outputs\n * @param settings - Settings that include output destination(s) and optional in-memory `content` which disables disk writes\n * @param index - Optional index used when writing to multiple targets or when tracking a particular input within a batch\n */\nasync function writeOutput<T extends CompressorOptions = CompressorOptions>(\n result: CompressorResult,\n settings: Settings<T>,\n index?: number\n): Promise<void> {\n const isInMemoryMode = Boolean(settings.content);\n if (isInMemoryMode || !settings.output) {\n return;\n }\n\n // Handle multi-output (for image conversion to multiple formats)\n if (result.outputs && result.outputs.length > 0) {\n await writeMultipleOutputs(result.outputs, settings, index);\n return;\n }\n\n // Handle single buffer output (for binary images)\n if (result.buffer) {\n await writeFileAsync({\n file: settings.output,\n content: result.buffer,\n index,\n });\n return;\n }\n\n // Default: write code (string) output\n const writePromises = [\n writeFileAsync({\n file: settings.output,\n content: result.code,\n index,\n }),\n ];\n\n if (result.map) {\n const sourceMapUrl = getSourceMapUrl(settings);\n if (sourceMapUrl) {\n writePromises.push(\n writeFileAsync({\n file: sourceMapUrl,\n content: result.map,\n index,\n })\n );\n }\n }\n\n await Promise.all(writePromises);\n}\n\n/**\n * Extract the first input file path from the input configuration.\n *\n * @param input - A single file path, an array of paths, or undefined\n * @returns The first input file path, or an empty string if none available\n */\nfunction getFirstInputFile(input: string | string[] | undefined): string {\n if (typeof input === \"string\") {\n return input;\n }\n if (Array.isArray(input) && input.length > 0) {\n return input[0] ?? \"\";\n }\n return \"\";\n}\n\n/**\n * Write compressor outputs to files resolved from the provided settings.\n *\n * Resolves a target path for each output entry based on settings.output and settings.input, then writes each entry's content to its resolved file location.\n *\n * @param outputs - Array of compressor output entries (each entry typically contains `content` and optional `format`) to be written.\n * @param settings - Settings used to resolve target paths (may supply `output` pattern/array and `input` for deriving names).\n * @param index - Optional numeric index forwarded to the file writer for each write operation.\n */\nasync function writeMultipleOutputs<\n T extends CompressorOptions = CompressorOptions,\n>(\n outputs: NonNullable<CompressorResult[\"outputs\"]>,\n settings: Settings<T>,\n index?: number\n): Promise<void> {\n const output = settings.output;\n const isArrayOutput = Array.isArray(output);\n const outputsArray = isArrayOutput ? output : [output];\n const inputFile = getFirstInputFile(settings.input);\n const inputDir = parse(inputFile).dir;\n const inputBase = parse(inputFile).name;\n\n const promises = outputs.map(async (outputResult, i) => {\n if (!outputResult) {\n return;\n }\n\n // Write outputs in parallel to improve performance\n const format = outputResult.format || \"out\";\n let targetFile: string;\n\n const arrayItem = outputsArray[i];\n\n if (\n isArrayOutput &&\n arrayItem !== undefined &&\n arrayItem !== \"$1\" &&\n arrayItem.trim() !== \"\"\n ) {\n // Explicit output path provided in array - use as-is\n targetFile = arrayItem;\n } else if (typeof output === \"string\" && output === \"$1\") {\n // $1 only: auto-generate from input filename in input directory\n const baseName = inputBase || \"output\";\n targetFile = inputDir\n ? join(inputDir, `${baseName}.${format}`)\n : `${baseName}.${format}`;\n } else if (typeof output === \"string\" && output.includes(\"$1\")) {\n // $1 pattern in path: replace and append format\n const extensionlessName = inputBase || \"output\";\n const outputFile = output.replace(/\\$1/g, extensionlessName);\n targetFile = `${outputFile}.${format}`;\n } else if (typeof output === \"string\") {\n // Single string output: append format extension\n targetFile = `${output}.${format}`;\n } else {\n // Fallback\n const baseName = inputBase || \"output\";\n targetFile = inputDir\n ? join(inputDir, `${baseName}.${format}`)\n : `${baseName}.${format}`;\n }\n\n await writeFileAsync({\n file: targetFile,\n content: outputResult.content,\n index,\n });\n });\n\n await Promise.all(promises);\n}\n\n/**\n * Resolve the configured source map path or URL from the provided settings.\n *\n * @param settings - Minifier settings that may include `options.sourceMap` or `options._sourceMap`\n * @returns The source map URL or filename when configured, `undefined` otherwise.\n */\nfunction getSourceMapUrl<T extends CompressorOptions = CompressorOptions>(\n settings: Settings<T>\n): string | undefined {\n const options = settings.options as Record<string, unknown> | undefined;\n if (!options) {\n return undefined;\n }\n\n const sourceMap = options.sourceMap as Record<string, unknown> | undefined;\n if (sourceMap) {\n if (typeof sourceMap.url === \"string\") {\n return sourceMap.url;\n }\n if (typeof sourceMap.filename === \"string\") {\n return sourceMap.filename;\n }\n }\n\n const _sourceMap = options._sourceMap as\n | Record<string, unknown>\n | undefined;\n if (_sourceMap && typeof _sourceMap.url === \"string\") {\n return _sourceMap.url;\n }\n\n return undefined;\n}\n"],"mappings":"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"}
1
+ {"version":3,"file":"run.js","names":[],"sources":["../src/run.ts"],"sourcesContent":["/*!\n * node-minify\n * Copyright (c) 2011-2026 Rodolphe Stoclin\n * MIT Licensed\n */\n\nimport { join, parse } from \"node:path\";\nimport type {\n CompressorOptions,\n CompressorResult,\n MinifierOptions,\n Settings,\n} from \"@node-minify/types\";\nimport { ValidationError } from \"./error.ts\";\nimport { writeFileAsync } from \"./writeFile.ts\";\n\n/**\n * Execute the configured compressor and persist its outputs according to the provided settings.\n *\n * @param settings - Compressor settings including output targets, options, and the `compressor` implementation\n * @param content - The input content to be compressed\n * @param index - Optional index used when processing multiple inputs\n * @returns The minified code produced by the compressor\n * @throws ValidationError If `settings` is missing, `settings.compressor` is not provided, or the compressor returns an invalid result\n */\nexport async function run<T extends CompressorOptions = CompressorOptions>({\n settings,\n content,\n index,\n}: MinifierOptions<T>): Promise<string> {\n if (!settings) {\n throw new ValidationError(\"Settings must be provided\");\n }\n\n if (!settings.compressor) {\n throw new ValidationError(\"Compressor must be provided in settings\");\n }\n\n const result = await settings.compressor({\n settings,\n content,\n index,\n });\n\n validateCompressorResult(result, settings);\n\n await writeOutput(result, settings, index);\n\n return result.code;\n}\n\n/**\n * Verify that a compressor result is an object containing a string `code` property and narrow its type to `CompressorResult`.\n *\n * @param result - The value returned by the compressor to validate.\n * @param settings - Minifier settings (used to derive the compressor label for error messages).\n * @throws ValidationError - If `result` is not an object with a string `code` property.\n */\nfunction validateCompressorResult<\n T extends CompressorOptions = CompressorOptions,\n>(result: unknown, settings: Settings<T>): asserts result is CompressorResult {\n if (!result || typeof result !== \"object\") {\n const label = settings.compressorLabel || \"compressor\";\n throw new ValidationError(\n `Compressor '${label}' returned invalid result. Expected an object with { code: string }.`\n );\n }\n\n const obj = result as Record<string, unknown>;\n if (!(\"code\" in obj) || typeof obj.code !== \"string\") {\n const label = settings.compressorLabel || \"compressor\";\n throw new ValidationError(\n `Compressor '${label}' must return { code: string }. Got: ${JSON.stringify(Object.keys(obj))}`\n );\n }\n}\n\n/**\n * Write compressor outputs to configured output paths unless execution is in-memory.\n *\n * Writes multiple outputs when `result.outputs` is present, writes `result.buffer` if provided, otherwise writes `result.code`. If `result.map` exists and a source map URL can be resolved from `settings`, the map file is written alongside the main output. The function returns without writing when `settings.output` is not set, when `settings.content` is provided (in-memory mode), or when `settings.allowEmptyOutput` is true and `result.code` is an empty string.\n *\n * @param result - Compressor result containing `code` and optional `buffer`, `map`, or `outputs`\n * @param settings - Settings that determine output destinations and in-memory mode\n * @param index - Optional batch/index marker forwarded to underlying write operations\n */\nasync function writeOutput<T extends CompressorOptions = CompressorOptions>(\n result: CompressorResult,\n settings: Settings<T>,\n index?: number\n): Promise<void> {\n const isInMemoryMode = settings.content !== undefined;\n if (isInMemoryMode || !settings.output) {\n return;\n }\n\n const hasBuffer = result.buffer && result.buffer.length > 0;\n const hasOutputs = result.outputs && result.outputs.length > 0;\n const hasCode = result.code !== \"\";\n const isCompletelyEmpty = !hasCode && !hasBuffer && !hasOutputs;\n if (settings.allowEmptyOutput && isCompletelyEmpty) {\n return;\n }\n\n // Handle multi-output (for image conversion to multiple formats)\n if (result.outputs && result.outputs.length > 0) {\n await writeMultipleOutputs(result.outputs, settings, index);\n return;\n }\n\n // Handle single buffer output (for binary images)\n if (result.buffer) {\n await writeFileAsync({\n file: settings.output,\n content: result.buffer,\n index,\n });\n return;\n }\n\n // Default: write code (string) output\n const writePromises = [\n writeFileAsync({\n file: settings.output,\n content: result.code,\n index,\n }),\n ];\n\n if (result.map) {\n const sourceMapUrl = getSourceMapUrl(settings);\n if (sourceMapUrl) {\n writePromises.push(\n writeFileAsync({\n file: sourceMapUrl,\n content: result.map,\n index,\n })\n );\n }\n }\n\n await Promise.all(writePromises);\n}\n\n/**\n * Extract an input file path from the input configuration.\n *\n * @param input - A single file path, an array of paths, or undefined\n * @param index - Optional index of the current input being processed when `input` is an array\n * @returns The indexed input file path when available, otherwise the first input file path or an empty string\n */\nfunction getInputFile(\n input: string | string[] | undefined,\n index?: number\n): string {\n if (typeof input === \"string\") {\n return input;\n }\n if (Array.isArray(input) && input.length > 0) {\n if (index !== undefined) {\n return input[index] ?? \"\";\n }\n return input[0] ?? \"\";\n }\n return \"\";\n}\n\n/**\n * Write compressor outputs to files resolved from the provided settings.\n *\n * Resolves a target path for each output entry based on settings.output and settings.input, then writes each entry's content to its resolved file location.\n *\n * @param outputs - Array of compressor output entries (each entry typically contains `content` and optional `format`) to be written.\n * @param settings - Settings used to resolve target paths (may supply `output` pattern/array and `input` for deriving names).\n * @param index - Optional numeric index forwarded to the file writer for each write operation.\n */\nasync function writeMultipleOutputs<\n T extends CompressorOptions = CompressorOptions,\n>(\n outputs: NonNullable<CompressorResult[\"outputs\"]>,\n settings: Settings<T>,\n index?: number\n): Promise<void> {\n const output = settings.output;\n const perFormatOutputs = Array.isArray(output) && index === undefined;\n const inputFile = getInputFile(settings.input, index);\n const inputDir = parse(inputFile).dir;\n const inputBase = parse(inputFile).name;\n const baseName = inputBase || \"output\";\n const currentOutput =\n Array.isArray(output) && index !== undefined ? output[index] : output;\n const withFormatExtension = (file: string, format: string): string =>\n file.endsWith(`.${format}`) ? file : `${file}.${format}`;\n\n const promises = outputs.map(async (outputResult, i) => {\n if (!outputResult) {\n return;\n }\n\n // Write outputs in parallel to improve performance\n const format = outputResult.format || \"out\";\n let targetFile: string;\n\n const arrayItem = perFormatOutputs ? output[i] : undefined;\n\n if (\n perFormatOutputs &&\n arrayItem !== undefined &&\n arrayItem !== \"$1\" &&\n arrayItem.trim() !== \"\"\n ) {\n if (arrayItem.includes(\"$1\")) {\n const outputFile = arrayItem.replace(/\\$1/g, baseName);\n targetFile = parse(outputFile).ext\n ? outputFile\n : withFormatExtension(outputFile, format);\n } else {\n targetFile = parse(arrayItem).ext\n ? arrayItem\n : withFormatExtension(arrayItem, format);\n }\n } else if (\n typeof currentOutput === \"string\" &&\n currentOutput === \"$1\"\n ) {\n // $1 only: auto-generate from input filename in input directory\n targetFile = inputDir\n ? join(inputDir, `${baseName}.${format}`)\n : `${baseName}.${format}`;\n } else if (\n typeof currentOutput === \"string\" &&\n currentOutput.includes(\"$1\")\n ) {\n // $1 pattern in path: replace and append format\n const outputFile = currentOutput.replace(/\\$1/g, baseName);\n targetFile = withFormatExtension(outputFile, format);\n } else if (\n typeof currentOutput === \"string\" &&\n currentOutput.trim() !== \"\"\n ) {\n // Single string output: append format extension\n targetFile = withFormatExtension(currentOutput, format);\n } else {\n // Fallback\n targetFile = inputDir\n ? join(inputDir, `${baseName}.${format}`)\n : `${baseName}.${format}`;\n }\n\n await writeFileAsync({\n file: targetFile,\n content: outputResult.content,\n index,\n });\n });\n\n await Promise.all(promises);\n}\n\n/**\n * Resolve the configured source map path or URL from the provided settings.\n *\n * @param settings - Minifier settings that may include `options.sourceMap` or `options._sourceMap`\n * @returns The source map URL or filename when configured, `undefined` otherwise.\n */\nfunction getSourceMapUrl<T extends CompressorOptions = CompressorOptions>(\n settings: Settings<T>\n): string | undefined {\n const options = settings.options as Record<string, unknown> | undefined;\n if (!options) {\n return undefined;\n }\n\n const sourceMap = options.sourceMap as Record<string, unknown> | undefined;\n if (sourceMap) {\n if (typeof sourceMap.url === \"string\") {\n return sourceMap.url;\n }\n if (typeof sourceMap.filename === \"string\") {\n return sourceMap.filename;\n }\n }\n\n const _sourceMap = options._sourceMap as\n | Record<string, unknown>\n | undefined;\n if (_sourceMap && typeof _sourceMap.url === \"string\") {\n return _sourceMap.url;\n }\n\n return undefined;\n}\n"],"mappings":"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"}
@@ -1 +1 @@
1
- {"version":3,"file":"setFileNameMin.d.ts","names":[],"sources":["../src/setFileNameMin.ts"],"sourcesContent":[],"mappings":";;AAoBA;;;;;;;;;;;;;;;;iBAAgB,cAAA"}
1
+ {"version":3,"file":"setFileNameMin.d.ts","names":[],"sources":["../src/setFileNameMin.ts"],"mappings":";;AA8BA;;;;;;;;;;;;;;;;iBAAgB,cAAA,CACZ,IAAA,UACA,MAAA,UACA,YAAA,WACA,cAAA"}
@@ -1,4 +1,5 @@
1
- import { n as ValidationError } from "./error-Ctspysdk.js";
1
+ import { ValidationError } from "./error.js";
2
+ import path from "node:path";
2
3
 
3
4
  //#region src/setFileNameMin.ts
4
5
  /*!
@@ -7,6 +8,14 @@ import { n as ValidationError } from "./error-Ctspysdk.js";
7
8
  * MIT Licensed
8
9
  */
9
10
  /**
11
+ * Normalize any Windows path separators to POSIX separators.
12
+ * @param value Path-like string
13
+ * @returns Path string using `/` separators
14
+ */
15
+ function toPosixPath(value) {
16
+ return value.replaceAll("\\", "/");
17
+ }
18
+ /**
10
19
  * Set the file name as minified.
11
20
  * @param file Original file path
12
21
  * @param output Output pattern (use $1 as placeholder for filename)
@@ -22,17 +31,14 @@ function setFileNameMin(file, output, publicFolder, replaceInPlace) {
22
31
  if (!file || typeof file !== "string") throw new ValidationError("File path must be a non-empty string");
23
32
  if (!output || typeof output !== "string" || !output.includes("$1")) throw new ValidationError("Output pattern must be a string containing \"$1\"");
24
33
  try {
25
- const lastSlashIndex = file.lastIndexOf("/");
26
- const filePath = file.substring(0, lastSlashIndex + 1);
27
- const fileWithoutPath = file.substring(lastSlashIndex + 1);
28
- const lastDotIndex = fileWithoutPath.lastIndexOf(".");
29
- if (lastDotIndex === -1) throw new ValidationError("File must have an extension");
30
- let fileWithoutExtension = fileWithoutPath.substring(0, lastDotIndex);
34
+ const parsedFile = path.posix.parse(toPosixPath(file));
35
+ if (!parsedFile.ext) throw new ValidationError("File must have an extension");
36
+ let fileWithoutExtension = parsedFile.name;
31
37
  if (publicFolder) {
32
38
  if (typeof publicFolder !== "string") throw new ValidationError("Public folder must be a string");
33
- fileWithoutExtension = publicFolder + fileWithoutExtension;
39
+ fileWithoutExtension = path.posix.join(toPosixPath(publicFolder), fileWithoutExtension);
34
40
  }
35
- if (replaceInPlace) fileWithoutExtension = filePath + fileWithoutExtension;
41
+ if (replaceInPlace) fileWithoutExtension = path.posix.join(parsedFile.dir, fileWithoutExtension);
36
42
  return output.replace("$1", fileWithoutExtension);
37
43
  } catch (error) {
38
44
  if (error instanceof ValidationError) throw error;