@node-minify/utils 10.2.0 → 10.3.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 (81) hide show
  1. package/LICENSE +1 -1
  2. package/dist/buildArgs.js +2 -2
  3. package/dist/buildArgs.js.map +1 -1
  4. package/dist/compressSingleFile.d.ts +1 -1
  5. package/dist/compressSingleFile.d.ts.map +1 -1
  6. package/dist/compressSingleFile.js +6 -32
  7. package/dist/compressSingleFile.js.map +1 -1
  8. package/dist/compressor-resolver.d.ts +46 -0
  9. package/dist/compressor-resolver.d.ts.map +1 -0
  10. package/dist/compressor-resolver.js +155 -0
  11. package/dist/compressor-resolver.js.map +1 -0
  12. package/dist/deleteFile.d.ts +1 -1
  13. package/dist/deleteFile.js +2 -2
  14. package/dist/deleteFile.js.map +1 -1
  15. package/dist/deprecation.d.ts +1 -1
  16. package/dist/deprecation.js +1 -1
  17. package/dist/deprecation.js.map +1 -1
  18. package/dist/ensureStringContent.d.ts +1 -1
  19. package/dist/ensureStringContent.js +1 -1
  20. package/dist/ensureStringContent.js.map +1 -1
  21. package/dist/{error-Ck87RwDD.js → error-Ctspysdk.js} +5 -3
  22. package/dist/error-Ctspysdk.js.map +1 -0
  23. package/dist/error.d.ts +2 -1
  24. package/dist/error.d.ts.map +1 -1
  25. package/dist/error.js +1 -1
  26. package/dist/getContentFromFiles.d.ts +1 -1
  27. package/dist/getContentFromFiles.js +4 -4
  28. package/dist/getContentFromFiles.js.map +1 -1
  29. package/dist/getFilesizeBrotliInBytes.d.ts +10 -0
  30. package/dist/getFilesizeBrotliInBytes.d.ts.map +1 -0
  31. package/dist/getFilesizeBrotliInBytes.js +29 -0
  32. package/dist/getFilesizeBrotliInBytes.js.map +1 -0
  33. package/dist/getFilesizeGzippedInBytes.d.ts +1 -1
  34. package/dist/getFilesizeGzippedInBytes.js +3 -3
  35. package/dist/getFilesizeGzippedInBytes.js.map +1 -1
  36. package/dist/getFilesizeInBytes.d.ts +1 -1
  37. package/dist/getFilesizeInBytes.js +1 -1
  38. package/dist/getFilesizeInBytes.js.map +1 -1
  39. package/dist/index.d.ts +6 -3
  40. package/dist/index.js +7 -4
  41. package/dist/isImageFile.d.ts +16 -0
  42. package/dist/isImageFile.d.ts.map +1 -0
  43. package/dist/isImageFile.js +35 -0
  44. package/dist/isImageFile.js.map +1 -0
  45. package/dist/{isValidFile-DnWJtlKA.js → isValidFile-BW5AgBWb.js} +4 -4
  46. package/dist/isValidFile-BW5AgBWb.js.map +1 -0
  47. package/dist/isValidFile.d.ts +1 -1
  48. package/dist/isValidFile.js +1 -1
  49. package/dist/prettyBytes.d.ts +1 -1
  50. package/dist/prettyBytes.js +2 -2
  51. package/dist/prettyBytes.js.map +1 -1
  52. package/dist/readFile.d.ts +13 -2
  53. package/dist/readFile.d.ts.map +1 -1
  54. package/dist/readFile.js +19 -3
  55. package/dist/readFile.js.map +1 -1
  56. package/dist/run.d.ts +4 -4
  57. package/dist/run.js +39 -32
  58. package/dist/run.js.map +1 -1
  59. package/dist/setFileNameMin.d.ts +1 -1
  60. package/dist/setFileNameMin.js +2 -2
  61. package/dist/setFileNameMin.js.map +1 -1
  62. package/dist/setPublicFolder.d.ts +1 -1
  63. package/dist/setPublicFolder.js +1 -1
  64. package/dist/setPublicFolder.js.map +1 -1
  65. package/dist/{types-BUlX1Zbb.d.ts → types-CzkB7gxg.d.ts} +8 -2
  66. package/dist/types-CzkB7gxg.d.ts.map +1 -0
  67. package/dist/types.d.ts +1 -1
  68. package/dist/wildcards.d.ts +1 -1
  69. package/dist/wildcards.js +1 -1
  70. package/dist/wildcards.js.map +1 -1
  71. package/dist/writeFile-DgV8EbFP.js +123 -0
  72. package/dist/writeFile-DgV8EbFP.js.map +1 -0
  73. package/dist/writeFile.d.ts +20 -2
  74. package/dist/writeFile.d.ts.map +1 -1
  75. package/dist/writeFile.js +2 -2
  76. package/package.json +2 -2
  77. package/dist/error-Ck87RwDD.js.map +0 -1
  78. package/dist/isValidFile-DnWJtlKA.js.map +0 -1
  79. package/dist/types-BUlX1Zbb.d.ts.map +0 -1
  80. package/dist/writeFile-BRfs9FqY.js +0 -39
  81. package/dist/writeFile-BRfs9FqY.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"setFileNameMin.js","names":[],"sources":["../src/setFileNameMin.ts"],"sourcesContent":["/*!\n * node-minify\n * Copyright(c) 2011-2025 Rodolphe Stoclin\n * MIT Licensed\n */\n\nimport { ValidationError } from \"./error.ts\";\n\n/**\n * Set the file name as minified.\n * @param file Original file path\n * @param output Output pattern (use $1 as placeholder for filename)\n * @param publicFolder Optional public folder prefix\n * @param replaceInPlace Whether to keep original path\n * @returns Minified file path\n * @throws {ValidationError} If input parameters are invalid\n * @example\n * setFileNameMin('src/file.js', '$1.min.js') // 'src/file.min.js'\n * setFileNameMin('file.js', '$1.min.js', 'public/') // 'public/file.min.js'\n */\nexport function setFileNameMin(\n file: string,\n output: string,\n publicFolder?: string,\n replaceInPlace?: boolean\n): string {\n if (!file || typeof file !== \"string\") {\n throw new ValidationError(\"File path must be a non-empty string\");\n }\n\n if (!output || typeof output !== \"string\" || !output.includes(\"$1\")) {\n throw new ValidationError(\n 'Output pattern must be a string containing \"$1\"'\n );\n }\n\n try {\n const lastSlashIndex = file.lastIndexOf(\"/\");\n const filePath = file.substring(0, lastSlashIndex + 1);\n const fileWithoutPath = file.substring(lastSlashIndex + 1);\n const lastDotIndex = fileWithoutPath.lastIndexOf(\".\");\n\n if (lastDotIndex === -1) {\n throw new ValidationError(\"File must have an extension\");\n }\n\n let fileWithoutExtension = fileWithoutPath.substring(0, lastDotIndex);\n\n if (publicFolder) {\n if (typeof publicFolder !== \"string\") {\n throw new ValidationError(\"Public folder must be a string\");\n }\n fileWithoutExtension = publicFolder + fileWithoutExtension;\n }\n\n if (replaceInPlace) {\n fileWithoutExtension = filePath + fileWithoutExtension;\n }\n\n return output.replace(\"$1\", fileWithoutExtension);\n } catch (error) {\n if (error instanceof ValidationError) {\n throw error;\n }\n throw new ValidationError(\n `Failed to process file name: ${error instanceof Error ? error.message : String(error)}`\n );\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAoBA,SAAgB,eACZ,MACA,QACA,cACA,gBACM;AACN,KAAI,CAAC,QAAQ,OAAO,SAAS,SACzB,OAAM,IAAI,gBAAgB,uCAAuC;AAGrE,KAAI,CAAC,UAAU,OAAO,WAAW,YAAY,CAAC,OAAO,SAAS,KAAK,CAC/D,OAAM,IAAI,gBACN,oDACH;AAGL,KAAI;EACA,MAAM,iBAAiB,KAAK,YAAY,IAAI;EAC5C,MAAM,WAAW,KAAK,UAAU,GAAG,iBAAiB,EAAE;EACtD,MAAM,kBAAkB,KAAK,UAAU,iBAAiB,EAAE;EAC1D,MAAM,eAAe,gBAAgB,YAAY,IAAI;AAErD,MAAI,iBAAiB,GACjB,OAAM,IAAI,gBAAgB,8BAA8B;EAG5D,IAAI,uBAAuB,gBAAgB,UAAU,GAAG,aAAa;AAErE,MAAI,cAAc;AACd,OAAI,OAAO,iBAAiB,SACxB,OAAM,IAAI,gBAAgB,iCAAiC;AAE/D,0BAAuB,eAAe;;AAG1C,MAAI,eACA,wBAAuB,WAAW;AAGtC,SAAO,OAAO,QAAQ,MAAM,qBAAqB;UAC5C,OAAO;AACZ,MAAI,iBAAiB,gBACjB,OAAM;AAEV,QAAM,IAAI,gBACN,gCAAgC,iBAAiB,QAAQ,MAAM,UAAU,OAAO,MAAM,GACzF"}
1
+ {"version":3,"file":"setFileNameMin.js","names":[],"sources":["../src/setFileNameMin.ts"],"sourcesContent":["/*!\n * node-minify\n * Copyright (c) 2011-2026 Rodolphe Stoclin\n * MIT Licensed\n */\n\nimport { ValidationError } from \"./error.ts\";\n\n/**\n * Set the file name as minified.\n * @param file Original file path\n * @param output Output pattern (use $1 as placeholder for filename)\n * @param publicFolder Optional public folder prefix\n * @param replaceInPlace Whether to keep original path\n * @returns Minified file path\n * @throws {ValidationError} If input parameters are invalid\n * @example\n * setFileNameMin('src/file.js', '$1.min.js') // 'src/file.min.js'\n * setFileNameMin('file.js', '$1.min.js', 'public/') // 'public/file.min.js'\n */\nexport function setFileNameMin(\n file: string,\n output: string,\n publicFolder?: string,\n replaceInPlace?: boolean\n): string {\n if (!file || typeof file !== \"string\") {\n throw new ValidationError(\"File path must be a non-empty string\");\n }\n\n if (!output || typeof output !== \"string\" || !output.includes(\"$1\")) {\n throw new ValidationError(\n 'Output pattern must be a string containing \"$1\"'\n );\n }\n\n try {\n const lastSlashIndex = file.lastIndexOf(\"/\");\n const filePath = file.substring(0, lastSlashIndex + 1);\n const fileWithoutPath = file.substring(lastSlashIndex + 1);\n const lastDotIndex = fileWithoutPath.lastIndexOf(\".\");\n\n if (lastDotIndex === -1) {\n throw new ValidationError(\"File must have an extension\");\n }\n\n let fileWithoutExtension = fileWithoutPath.substring(0, lastDotIndex);\n\n if (publicFolder) {\n if (typeof publicFolder !== \"string\") {\n throw new ValidationError(\"Public folder must be a string\");\n }\n fileWithoutExtension = publicFolder + fileWithoutExtension;\n }\n\n if (replaceInPlace) {\n fileWithoutExtension = filePath + fileWithoutExtension;\n }\n\n return output.replace(\"$1\", fileWithoutExtension);\n } catch (error) {\n if (error instanceof ValidationError) {\n throw error;\n }\n throw new ValidationError(\n `Failed to process file name: ${error instanceof Error ? error.message : String(error)}`\n );\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAoBA,SAAgB,eACZ,MACA,QACA,cACA,gBACM;AACN,KAAI,CAAC,QAAQ,OAAO,SAAS,SACzB,OAAM,IAAI,gBAAgB,uCAAuC;AAGrE,KAAI,CAAC,UAAU,OAAO,WAAW,YAAY,CAAC,OAAO,SAAS,KAAK,CAC/D,OAAM,IAAI,gBACN,oDACH;AAGL,KAAI;EACA,MAAM,iBAAiB,KAAK,YAAY,IAAI;EAC5C,MAAM,WAAW,KAAK,UAAU,GAAG,iBAAiB,EAAE;EACtD,MAAM,kBAAkB,KAAK,UAAU,iBAAiB,EAAE;EAC1D,MAAM,eAAe,gBAAgB,YAAY,IAAI;AAErD,MAAI,iBAAiB,GACjB,OAAM,IAAI,gBAAgB,8BAA8B;EAG5D,IAAI,uBAAuB,gBAAgB,UAAU,GAAG,aAAa;AAErE,MAAI,cAAc;AACd,OAAI,OAAO,iBAAiB,SACxB,OAAM,IAAI,gBAAgB,iCAAiC;AAE/D,0BAAuB,eAAe;;AAG1C,MAAI,eACA,wBAAuB,WAAW;AAGtC,SAAO,OAAO,QAAQ,MAAM,qBAAqB;UAC5C,OAAO;AACZ,MAAI,iBAAiB,gBACjB,OAAM;AAEV,QAAM,IAAI,gBACN,gCAAgC,iBAAiB,QAAQ,MAAM,UAAU,OAAO,MAAM,GACzF"}
@@ -1,7 +1,7 @@
1
1
  //#region src/setPublicFolder.d.ts
2
2
  /*!
3
3
  * node-minify
4
- * Copyright(c) 2011-2025 Rodolphe Stoclin
4
+ * Copyright (c) 2011-2026 Rodolphe Stoclin
5
5
  * MIT Licensed
6
6
  */
7
7
  /**
@@ -3,7 +3,7 @@ import path from "node:path";
3
3
  //#region src/setPublicFolder.ts
4
4
  /*!
5
5
  * node-minify
6
- * Copyright(c) 2011-2025 Rodolphe Stoclin
6
+ * Copyright (c) 2011-2026 Rodolphe Stoclin
7
7
  * MIT Licensed
8
8
  */
9
9
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"setPublicFolder.js","names":[],"sources":["../src/setPublicFolder.ts"],"sourcesContent":["/*!\n * node-minify\n * Copyright(c) 2011-2025 Rodolphe Stoclin\n * MIT Licensed\n */\n\nimport path from \"node:path\";\n\n/**\n * Prepend the public folder to each file.\n * @param input Path to file(s)\n * @param publicFolder Path to the public folder\n */\nexport function setPublicFolder(\n input: string | string[],\n publicFolder: string\n) {\n if (typeof publicFolder !== \"string\") {\n return {};\n }\n\n const normalizedPublicFolder = path.normalize(publicFolder);\n\n const addPublicFolder = (item: string) => {\n const normalizedPath = path.normalize(item);\n return normalizedPath.includes(normalizedPublicFolder)\n ? normalizedPath\n : path.normalize(normalizedPublicFolder + item);\n };\n\n return {\n input: Array.isArray(input)\n ? input.map(addPublicFolder)\n : addPublicFolder(input),\n };\n}\n"],"mappings":";;;;;;;;;;;;;AAaA,SAAgB,gBACZ,OACA,cACF;AACE,KAAI,OAAO,iBAAiB,SACxB,QAAO,EAAE;CAGb,MAAM,yBAAyB,KAAK,UAAU,aAAa;CAE3D,MAAM,mBAAmB,SAAiB;EACtC,MAAM,iBAAiB,KAAK,UAAU,KAAK;AAC3C,SAAO,eAAe,SAAS,uBAAuB,GAChD,iBACA,KAAK,UAAU,yBAAyB,KAAK;;AAGvD,QAAO,EACH,OAAO,MAAM,QAAQ,MAAM,GACrB,MAAM,IAAI,gBAAgB,GAC1B,gBAAgB,MAAM,EAC/B"}
1
+ {"version":3,"file":"setPublicFolder.js","names":[],"sources":["../src/setPublicFolder.ts"],"sourcesContent":["/*!\n * node-minify\n * Copyright (c) 2011-2026 Rodolphe Stoclin\n * MIT Licensed\n */\n\nimport path from \"node:path\";\n\n/**\n * Prepend the public folder to each file.\n * @param input Path to file(s)\n * @param publicFolder Path to the public folder\n */\nexport function setPublicFolder(\n input: string | string[],\n publicFolder: string\n) {\n if (typeof publicFolder !== \"string\") {\n return {};\n }\n\n const normalizedPublicFolder = path.normalize(publicFolder);\n\n const addPublicFolder = (item: string) => {\n const normalizedPath = path.normalize(item);\n return normalizedPath.includes(normalizedPublicFolder)\n ? normalizedPath\n : path.normalize(normalizedPublicFolder + item);\n };\n\n return {\n input: Array.isArray(input)\n ? input.map(addPublicFolder)\n : addPublicFolder(input),\n };\n}\n"],"mappings":";;;;;;;;;;;;;AAaA,SAAgB,gBACZ,OACA,cACF;AACE,KAAI,OAAO,iBAAiB,SACxB,QAAO,EAAE;CAGb,MAAM,yBAAyB,KAAK,UAAU,aAAa;CAE3D,MAAM,mBAAmB,SAAiB;EACtC,MAAM,iBAAiB,KAAK,UAAU,KAAK;AAC3C,SAAO,eAAe,SAAS,uBAAuB,GAChD,iBACA,KAAK,UAAU,yBAAyB,KAAK;;AAGvD,QAAO,EACH,OAAO,MAAM,QAAQ,MAAM,GACrB,MAAM,IAAI,gBAAgB,GAC1B,gBAAgB,MAAM,EAC/B"}
@@ -135,6 +135,12 @@ type Settings<TOptions extends CompressorOptions = CompressorOptions> = {
135
135
  */
136
136
  buffer?: number;
137
137
 
138
+ /**
139
+ * Timeout for the compressor process (in milliseconds).
140
+ * If execution exceeds this limit, the process will be killed.
141
+ */
142
+ timeout?: number;
143
+
138
144
  /**
139
145
  * File type for compressors that support multiple types.
140
146
  * Required for YUI compressor.
@@ -186,5 +192,5 @@ type MinifierOptions<TOptions extends CompressorOptions = CompressorOptions> = {
186
192
  index?: number;
187
193
  };
188
194
  //#endregion
189
- export { MinifierOptions as n, Settings as r, CompressorOptions as t };
190
- //# sourceMappingURL=types-BUlX1Zbb.d.ts.map
195
+ export { Settings as i, CompressorOptions as n, MinifierOptions as r, Compressor as t };
196
+ //# sourceMappingURL=types-CzkB7gxg.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types-CzkB7gxg.d.ts","names":["CompressorReturnType","ImageFormat","CompressorOutput","Buffer","CompressorResult","CompressorOptions","Record","Compressor","TOptions","MinifierOptions","Promise","FileType","Settings","Result","MinifyOptions"],"sources":["../../types/src/types.d.ts"],"sourcesContent":["/*!\n * node-minify\n * Copyright (c) 2011-2026 Rodolphe Stoclin\n * MIT Licensed\n */\n\n/**\n * The return type of a compressor function.\n * @deprecated Use `CompressorResult` instead. Will be removed in v11.\n */\nexport type CompressorReturnType = string;\n\n/**\n * Supported image formats for image compression.\n */\nexport type ImageFormat =\n | \"webp\"\n | \"avif\"\n | \"png\"\n | \"jpeg\"\n | \"jpg\"\n | \"gif\"\n | \"tiff\"\n | \"heif\"\n | \"heic\";\n\n/**\n * Output result for multi-format image compression.\n */\nexport type CompressorOutput = {\n /**\n * Format of the output (e.g., 'webp', 'avif').\n */\n format?: string;\n\n /**\n * Output content as string or Buffer.\n */\n content: string | Buffer;\n};\n\n/**\n * Result returned by a compressor function.\n */\nexport type CompressorResult = {\n /**\n * Minified content as string (for text-based formats like JS, CSS, HTML, SVG).\n */\n code: string;\n\n /**\n * Source map (for JS/CSS compressors).\n */\n map?: string;\n\n /**\n * Minified content as Buffer (for binary formats like images).\n * @example\n * When using sharp for PNG/WebP compression\n */\n buffer?: Buffer;\n\n /**\n * Multiple outputs for multi-format image compression.\n * Used when converting to multiple formats simultaneously.\n * @example\n * [{ format: 'webp', content: <Buffer> }, { format: 'avif', content: <Buffer> }]\n */\n outputs?: CompressorOutput[];\n};\n\n/**\n * Base options that all compressors can accept.\n * Specific compressors may extend this with their own options.\n */\nexport type CompressorOptions = Record<string, unknown>;\n\n/**\n * A compressor function that minifies content.\n * @param args - The minifier options including settings and content\n * @returns A promise resolving to the compression result\n */\nexport type Compressor<TOptions extends CompressorOptions = CompressorOptions> =\n (args: MinifierOptions<TOptions>) => Promise<CompressorResult>;\n\n/**\n * File type for compressors that support multiple types (e.g., YUI).\n */\nexport type FileType = \"js\" | \"css\";\n\n/**\n * User-facing settings for the minify function.\n * This is what users pass when calling minify().\n *\n * @example\n * ```ts\n * import { minify } from '@node-minify/core';\n * import { terser } from '@node-minify/terser';\n *\n * await minify({\n * compressor: terser,\n * input: 'src/*.js',\n * output: 'dist/bundle.min.js',\n * options: { mangle: true }\n * });\n * ```\n */\nexport type Settings<TOptions extends CompressorOptions = CompressorOptions> = {\n /**\n * The compressor function to use for minification.\n */\n compressor: Compressor<TOptions>;\n\n /**\n * Optional label for the compressor (used in logging).\n */\n compressorLabel?: string;\n\n /**\n * Content to minify (for in-memory minification).\n * If provided, input/output are not required.\n * For text-based formats (JS, CSS, HTML, SVG): string\n * For binary formats (images): Buffer (handled internally by image compressors)\n */\n content?: string | Buffer;\n\n /**\n * Input file path(s) or glob pattern.\n * Can be a single file, array of files, or wildcard pattern.\n *\n * @example\n * - 'src/app.js'\n * - ['src/a.js', 'src/b.js']\n * - 'src/**\\/*.js'\n */\n input?: string | string[];\n\n /**\n * Output file path.\n * Use $1 as placeholder for input filename in multi-file scenarios.\n * Can be a single file, array of files, or pattern with $1.\n *\n * @example\n * - 'dist/bundle.min.js'\n * - ['file1.min.js', 'file2.min.js']\n * - '$1.min.js' (creates app.min.js from app.js)\n */\n output?: string | string[];\n\n /**\n * Compressor-specific options.\n * See individual compressor documentation for available options.\n */\n options?: TOptions;\n\n /**\n * CLI option string (used by CLI only).\n * @internal\n */\n option?: string;\n\n /**\n * Buffer size for file operations (in bytes).\n * @default 1024000 (1MB)\n */\n buffer?: number;\n\n /**\n * Timeout for the compressor process (in milliseconds).\n * If execution exceeds this limit, the process will be killed.\n */\n timeout?: number;\n\n /**\n * File type for compressors that support multiple types.\n * Required for YUI compressor.\n */\n type?: FileType;\n\n /**\n * Suppress console output.\n * @default false\n */\n silence?: boolean;\n\n /**\n * Public folder to prepend to input paths.\n *\n * @example\n * With publicFolder: 'public/js/' and input: 'app.js',\n * the actual path becomes 'public/js/app.js'\n */\n publicFolder?: string;\n\n /**\n * Replace files in place instead of creating new output files.\n * @default false\n */\n replaceInPlace?: boolean;\n};\n\n/**\n * Options passed to compressor functions internally.\n * This is what compressors receive, not what users pass.\n */\nexport type MinifierOptions<\n TOptions extends CompressorOptions = CompressorOptions,\n> = {\n /**\n * The full settings object.\n */\n settings: Settings<TOptions>;\n\n /**\n * The content to minify.\n * For text-based formats (JS, CSS, HTML, SVG): string\n * For binary formats (images): Buffer\n * For multiple binary files: Buffer[]\n */\n content?: string | Buffer | Buffer[];\n\n /**\n * Index of current file when processing multiple files.\n */\n index?: number;\n};\n\n/**\n * Result returned after compression (used by CLI).\n */\nexport type Result = {\n /**\n * Label of the compressor used.\n */\n compressorLabel: string;\n\n /**\n * Size of minified content (formatted string, e.g., \"1.5 KB\").\n */\n size: string;\n\n /**\n * Gzipped size of minified content (formatted string).\n */\n sizeGzip: string;\n};\n\n/**\n * Type alias for user convenience.\n * @deprecated Use `Settings` instead. Will be removed in v11.\n */\nexport type MinifyOptions<\n TOptions extends CompressorOptions = CompressorOptions,\n> = Settings<TOptions>;\n"],"mappings":";;;;;AA2NsC,KA9L1BE,gBAAAA,GA8L0B;;;;;;;;;oBArLhBC;;;;;KAMVC,gBAAAA;;;;;;;;;;;;;;;;WAgBCD;;;;;;;;YAQCD;;;;;;KAOFG,iBAAAA,GAAoBC;;;;;;KAOpBC,4BAA4BF,oBAAoBA,4BACjDI,gBAAgBD,cAAcE,QAAQN;;;;KAKrCO,QAAAA;;;;;;;;;;;;;;;;;;KAmBAC,0BAA0BP,oBAAoBA;;;;cAI1CE,WAAWC;;;;;;;;;;;;;qBAaJL;;;;;;;;;;;;;;;;;;;;;;;;;;;;;YA6BTK;;;;;;;;;;;;;;;;;;;;;;;;SAwBHG;;;;;;;;;;;;;;;;;;;;;;;;;;;KA4BCF,iCACSJ,oBAAoBA;;;;YAK3BO,SAASJ;;;;;;;;qBAQAL,SAASA"}
package/dist/types.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  //#region src/types.d.ts
2
2
  /*!
3
3
  * node-minify
4
- * Copyright(c) 2011-2025 Rodolphe Stoclin
4
+ * Copyright (c) 2011-2026 Rodolphe Stoclin
5
5
  * MIT Licensed
6
6
  */
7
7
  interface BuildArgsOptions {
@@ -1,7 +1,7 @@
1
1
  //#region src/wildcards.d.ts
2
2
  /*!
3
3
  * node-minify
4
- * Copyright(c) 2011-2025 Rodolphe Stoclin
4
+ * Copyright (c) 2011-2026 Rodolphe Stoclin
5
5
  * MIT Licensed
6
6
  */
7
7
  /**
package/dist/wildcards.js CHANGED
@@ -4,7 +4,7 @@ import fg from "fast-glob";
4
4
  //#region src/wildcards.ts
5
5
  /*!
6
6
  * node-minify
7
- * Copyright(c) 2011-2025 Rodolphe Stoclin
7
+ * Copyright (c) 2011-2026 Rodolphe Stoclin
8
8
  * MIT Licensed
9
9
  */
10
10
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"wildcards.js","names":[],"sources":["../src/wildcards.ts"],"sourcesContent":["/*!\n * node-minify\n * Copyright(c) 2011-2025 Rodolphe Stoclin\n * MIT Licensed\n */\n\nimport os from \"node:os\";\nimport fg from \"fast-glob\";\n\n/**\n * Check if the platform is Windows\n */\nfunction isWindows() {\n return os.platform() === \"win32\";\n}\n\n/**\n * Handle wildcards in a path, get the real path of each file.\n * @param input - Path with wildcards\n * @param publicFolder - Path to the public folder\n */\nexport function wildcards(input: string | string[], publicFolder?: string) {\n if (Array.isArray(input)) {\n return wildcardsArray(input, publicFolder);\n }\n\n return wildcardsString(input, publicFolder);\n}\n\n/**\n * Handle wildcards in a path (string only), get the real path of each file.\n * @param input - Path with wildcards\n * @param publicFolder - Path to the public folder\n */\nfunction wildcardsString(input: string, publicFolder?: string) {\n if (!input.includes(\"*\")) {\n return {};\n }\n\n const files = getFilesFromWildcards(input, publicFolder);\n const finalPaths = files.filter((path: string) => !path.includes(\"*\"));\n\n return {\n input: finalPaths,\n };\n}\n\n/**\n * Handle wildcards in a path (array only), get the real path of each file.\n * @param input - Array of paths with wildcards\n * @param publicFolder - Path to the public folder\n */\nfunction wildcardsArray(input: string[], publicFolder?: string) {\n // Convert input paths to patterns with public folder prefix\n const inputWithPublicFolder = input.map((item) => {\n const input2 = publicFolder ? publicFolder + item : item;\n return isWindows() ? fg.convertPathToPattern(input2) : input2;\n });\n\n // Check if any wildcards exist\n const hasWildcards = inputWithPublicFolder.some((item) =>\n item.includes(\"*\")\n );\n\n // Process paths based on whether wildcards exist\n const processedPaths = hasWildcards\n ? fg.globSync(inputWithPublicFolder)\n : input;\n\n // Filter out any remaining paths with wildcards\n const finalPaths = processedPaths.filter(\n (path: string) => !path.includes(\"*\")\n );\n\n return { input: finalPaths };\n}\n\n/**\n * Get the real path of each file.\n * @param input - Path with wildcards\n * @param publicFolder - Path to the public folder\n */\nfunction getFilesFromWildcards(input: string, publicFolder?: string) {\n const fullPath = publicFolder ? `${publicFolder}${input}` : input;\n return fg.globSync(\n isWindows() ? fg.convertPathToPattern(fullPath) : fullPath\n );\n}\n"],"mappings":";;;;;;;;;;;;AAYA,SAAS,YAAY;AACjB,QAAO,GAAG,UAAU,KAAK;;;;;;;AAQ7B,SAAgB,UAAU,OAA0B,cAAuB;AACvE,KAAI,MAAM,QAAQ,MAAM,CACpB,QAAO,eAAe,OAAO,aAAa;AAG9C,QAAO,gBAAgB,OAAO,aAAa;;;;;;;AAQ/C,SAAS,gBAAgB,OAAe,cAAuB;AAC3D,KAAI,CAAC,MAAM,SAAS,IAAI,CACpB,QAAO,EAAE;AAMb,QAAO,EACH,OAJU,sBAAsB,OAAO,aAAa,CAC/B,QAAQ,SAAiB,CAAC,KAAK,SAAS,IAAI,CAAC,EAIrE;;;;;;;AAQL,SAAS,eAAe,OAAiB,cAAuB;CAE5D,MAAM,wBAAwB,MAAM,KAAK,SAAS;EAC9C,MAAM,SAAS,eAAe,eAAe,OAAO;AACpD,SAAO,WAAW,GAAG,GAAG,qBAAqB,OAAO,GAAG;GACzD;AAiBF,QAAO,EAAE,QAdY,sBAAsB,MAAM,SAC7C,KAAK,SAAS,IAAI,CACrB,GAIK,GAAG,SAAS,sBAAsB,GAClC,OAG4B,QAC7B,SAAiB,CAAC,KAAK,SAAS,IAAI,CACxC,EAE2B;;;;;;;AAQhC,SAAS,sBAAsB,OAAe,cAAuB;CACjE,MAAM,WAAW,eAAe,GAAG,eAAe,UAAU;AAC5D,QAAO,GAAG,SACN,WAAW,GAAG,GAAG,qBAAqB,SAAS,GAAG,SACrD"}
1
+ {"version":3,"file":"wildcards.js","names":[],"sources":["../src/wildcards.ts"],"sourcesContent":["/*!\n * node-minify\n * Copyright (c) 2011-2026 Rodolphe Stoclin\n * MIT Licensed\n */\n\nimport os from \"node:os\";\nimport fg from \"fast-glob\";\n\n/**\n * Check if the platform is Windows\n */\nfunction isWindows() {\n return os.platform() === \"win32\";\n}\n\n/**\n * Handle wildcards in a path, get the real path of each file.\n * @param input - Path with wildcards\n * @param publicFolder - Path to the public folder\n */\nexport function wildcards(input: string | string[], publicFolder?: string) {\n if (Array.isArray(input)) {\n return wildcardsArray(input, publicFolder);\n }\n\n return wildcardsString(input, publicFolder);\n}\n\n/**\n * Handle wildcards in a path (string only), get the real path of each file.\n * @param input - Path with wildcards\n * @param publicFolder - Path to the public folder\n */\nfunction wildcardsString(input: string, publicFolder?: string) {\n if (!input.includes(\"*\")) {\n return {};\n }\n\n const files = getFilesFromWildcards(input, publicFolder);\n const finalPaths = files.filter((path: string) => !path.includes(\"*\"));\n\n return {\n input: finalPaths,\n };\n}\n\n/**\n * Handle wildcards in a path (array only), get the real path of each file.\n * @param input - Array of paths with wildcards\n * @param publicFolder - Path to the public folder\n */\nfunction wildcardsArray(input: string[], publicFolder?: string) {\n // Convert input paths to patterns with public folder prefix\n const inputWithPublicFolder = input.map((item) => {\n const input2 = publicFolder ? publicFolder + item : item;\n return isWindows() ? fg.convertPathToPattern(input2) : input2;\n });\n\n // Check if any wildcards exist\n const hasWildcards = inputWithPublicFolder.some((item) =>\n item.includes(\"*\")\n );\n\n // Process paths based on whether wildcards exist\n const processedPaths = hasWildcards\n ? fg.globSync(inputWithPublicFolder)\n : input;\n\n // Filter out any remaining paths with wildcards\n const finalPaths = processedPaths.filter(\n (path: string) => !path.includes(\"*\")\n );\n\n return { input: finalPaths };\n}\n\n/**\n * Get the real path of each file.\n * @param input - Path with wildcards\n * @param publicFolder - Path to the public folder\n */\nfunction getFilesFromWildcards(input: string, publicFolder?: string) {\n const fullPath = publicFolder ? `${publicFolder}${input}` : input;\n return fg.globSync(\n isWindows() ? fg.convertPathToPattern(fullPath) : fullPath\n );\n}\n"],"mappings":";;;;;;;;;;;;AAYA,SAAS,YAAY;AACjB,QAAO,GAAG,UAAU,KAAK;;;;;;;AAQ7B,SAAgB,UAAU,OAA0B,cAAuB;AACvE,KAAI,MAAM,QAAQ,MAAM,CACpB,QAAO,eAAe,OAAO,aAAa;AAG9C,QAAO,gBAAgB,OAAO,aAAa;;;;;;;AAQ/C,SAAS,gBAAgB,OAAe,cAAuB;AAC3D,KAAI,CAAC,MAAM,SAAS,IAAI,CACpB,QAAO,EAAE;AAMb,QAAO,EACH,OAJU,sBAAsB,OAAO,aAAa,CAC/B,QAAQ,SAAiB,CAAC,KAAK,SAAS,IAAI,CAAC,EAIrE;;;;;;;AAQL,SAAS,eAAe,OAAiB,cAAuB;CAE5D,MAAM,wBAAwB,MAAM,KAAK,SAAS;EAC9C,MAAM,SAAS,eAAe,eAAe,OAAO;AACpD,SAAO,WAAW,GAAG,GAAG,qBAAqB,OAAO,GAAG;GACzD;AAiBF,QAAO,EAAE,QAdY,sBAAsB,MAAM,SAC7C,KAAK,SAAS,IAAI,CACrB,GAIK,GAAG,SAAS,sBAAsB,GAClC,OAG4B,QAC7B,SAAiB,CAAC,KAAK,SAAS,IAAI,CACxC,EAE2B;;;;;;;AAQhC,SAAS,sBAAsB,OAAe,cAAuB;CACjE,MAAM,WAAW,eAAe,GAAG,eAAe,UAAU;AAC5D,QAAO,GAAG,SACN,WAAW,GAAG,GAAG,qBAAqB,SAAS,GAAG,SACrD"}
@@ -0,0 +1,123 @@
1
+ import { n as ValidationError, t as FileOperationError } from "./error-Ctspysdk.js";
2
+ import { lstatSync, writeFileSync } from "node:fs";
3
+ import { lstat, writeFile } from "node:fs/promises";
4
+
5
+ //#region src/writeFile.ts
6
+ /*!
7
+ * node-minify
8
+ * Copyright (c) 2011-2026 Rodolphe Stoclin
9
+ * MIT Licensed
10
+ */
11
+ /**
12
+ * Write provided content to a target file.
13
+ *
14
+ * When `file` is an array and `index` is provided, the file at that index is used; otherwise `file` is used directly.
15
+ *
16
+ * @param file - Target path or array of target paths
17
+ * @param content - Content to write; may be a `string` or `Buffer`
18
+ * @param index - Optional index to select a file when `file` is an array
19
+ * @returns The same `content` value that was written
20
+ * @throws ValidationError If no target file, no content, or the resolved target path is invalid
21
+ * @throws FileOperationError If the underlying filesystem write fails (wraps the original error)
22
+ */
23
+ function writeFile$1({ file, content, index }) {
24
+ try {
25
+ const targetFile = resolveTargetFile(file, index);
26
+ validateContent(content);
27
+ if (isDirectory(targetFile)) throw new Error("Target path exists and is a directory");
28
+ writeFileSync(targetFile, content, Buffer.isBuffer(content) ? void 0 : "utf8");
29
+ return content;
30
+ } catch (error) {
31
+ handleWriteError(error, file);
32
+ return content;
33
+ }
34
+ }
35
+ /**
36
+ * Write content to a resolved target file path.
37
+ *
38
+ * Resolves the target from `file` (string or array) using `index` when provided, validates the content,
39
+ * ensures the target is not a directory, and writes the content to disk.
40
+ *
41
+ * @param file - Target path or array of target paths; when `file` is an array, `index` selects the entry
42
+ * @param content - Content to write; a `string` or `Buffer`
43
+ * @param index - Optional index used to select a file when `file` is an array
44
+ * @returns The same `content` value that was written
45
+ * @throws ValidationError If no target file, no content, or the resolved target path is invalid
46
+ * @throws FileOperationError If the underlying filesystem write fails (wraps the original error)
47
+ */
48
+ async function writeFileAsync({ file, content, index }) {
49
+ try {
50
+ const targetFile = resolveTargetFile(file, index);
51
+ validateContent(content);
52
+ if (await isDirectoryAsync(targetFile)) throw new Error("Target path exists and is a directory");
53
+ await writeFile(targetFile, content, Buffer.isBuffer(content) ? void 0 : "utf8");
54
+ return content;
55
+ } catch (error) {
56
+ handleWriteError(error, file);
57
+ return content;
58
+ }
59
+ }
60
+ /**
61
+ * Resolve a target file path from a string or an array of paths, optionally selecting by index.
62
+ *
63
+ * @param file - A file path or an array of file paths to resolve from.
64
+ * @param index - Optional index to select an entry when `file` is an array; ignored if not provided.
65
+ * @returns The resolved file path.
66
+ * @throws ValidationError if no file is provided or the resolved target is not a string.
67
+ */
68
+ function resolveTargetFile(file, index) {
69
+ if (!file) throw new ValidationError("No target file provided");
70
+ const targetFile = index !== void 0 ? Array.isArray(file) ? file[index] : file : file;
71
+ if (typeof targetFile !== "string") throw new ValidationError("Invalid target file path");
72
+ return targetFile;
73
+ }
74
+ /**
75
+ * Ensure content is present before writing.
76
+ *
77
+ * @param content - The data to write; a string or Buffer
78
+ * @throws ValidationError if `content` is empty or otherwise falsy
79
+ */
80
+ function validateContent(content) {
81
+ if (!content) throw new ValidationError("No content provided");
82
+ }
83
+ /**
84
+ * Checks whether the given filesystem path refers to a directory.
85
+ *
86
+ * @returns `true` if the path exists and is a directory, `false` otherwise.
87
+ */
88
+ function isDirectory(path) {
89
+ try {
90
+ return lstatSync(path).isDirectory();
91
+ } catch {
92
+ return false;
93
+ }
94
+ }
95
+ /**
96
+ * Determine whether a filesystem path refers to a directory.
97
+ *
98
+ * @param path - The filesystem path to check
99
+ * @returns `true` if the path exists and is a directory, `false` otherwise
100
+ */
101
+ async function isDirectoryAsync(path) {
102
+ try {
103
+ return (await lstat(path)).isDirectory();
104
+ } catch {
105
+ return false;
106
+ }
107
+ }
108
+ /**
109
+ * Normalize and rethrow errors that occur while attempting to write to one or more files.
110
+ *
111
+ * @param error - The original error thrown during the write attempt
112
+ * @param file - The target file path or an array of paths that were the intended write targets
113
+ * @throws ValidationError - rethrows the provided ValidationError without modification
114
+ * @throws FileOperationError - thrown for any other error, wrapping the original error with context about the write operation and the target file(s)
115
+ */
116
+ function handleWriteError(error, file) {
117
+ if (error instanceof ValidationError) throw error;
118
+ throw new FileOperationError("write to", typeof file === "string" ? file : "multiple files", error);
119
+ }
120
+
121
+ //#endregion
122
+ export { writeFileAsync as n, writeFile$1 as t };
123
+ //# sourceMappingURL=writeFile-DgV8EbFP.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"writeFile-DgV8EbFP.js","names":["writeFile","writeFileFs"],"sources":["../src/writeFile.ts"],"sourcesContent":["/*!\n * node-minify\n * Copyright (c) 2011-2026 Rodolphe Stoclin\n * MIT Licensed\n */\n\nimport { lstatSync, writeFileSync } from \"node:fs\";\nimport { lstat, writeFile as writeFileFs } from \"node:fs/promises\";\nimport { FileOperationError, ValidationError } from \"./error.ts\";\n\ninterface WriteFileParams {\n file: string | string[];\n content: string | Buffer;\n index?: number;\n}\n\n/**\n * Write provided content to a target file.\n *\n * When `file` is an array and `index` is provided, the file at that index is used; otherwise `file` is used directly.\n *\n * @param file - Target path or array of target paths\n * @param content - Content to write; may be a `string` or `Buffer`\n * @param index - Optional index to select a file when `file` is an array\n * @returns The same `content` value that was written\n * @throws ValidationError If no target file, no content, or the resolved target path is invalid\n * @throws FileOperationError If the underlying filesystem write fails (wraps the original error)\n */\nexport function writeFile({\n file,\n content,\n index,\n}: WriteFileParams): string | Buffer {\n try {\n const targetFile = resolveTargetFile(file, index);\n validateContent(content);\n\n if (isDirectory(targetFile)) {\n throw new Error(\"Target path exists and is a directory\");\n }\n\n writeFileSync(\n targetFile,\n content,\n Buffer.isBuffer(content) ? undefined : \"utf8\"\n );\n return content;\n } catch (error) {\n handleWriteError(error, file);\n return content; // Should be unreachable due to handleWriteError throwing\n }\n}\n\n/**\n * Write content to a resolved target file path.\n *\n * Resolves the target from `file` (string or array) using `index` when provided, validates the content,\n * ensures the target is not a directory, and writes the content to disk.\n *\n * @param file - Target path or array of target paths; when `file` is an array, `index` selects the entry\n * @param content - Content to write; a `string` or `Buffer`\n * @param index - Optional index used to select a file when `file` is an array\n * @returns The same `content` value that was written\n * @throws ValidationError If no target file, no content, or the resolved target path is invalid\n * @throws FileOperationError If the underlying filesystem write fails (wraps the original error)\n */\nexport async function writeFileAsync({\n file,\n content,\n index,\n}: WriteFileParams): Promise<string | Buffer> {\n try {\n const targetFile = resolveTargetFile(file, index);\n validateContent(content);\n\n if (await isDirectoryAsync(targetFile)) {\n throw new Error(\"Target path exists and is a directory\");\n }\n\n await writeFileFs(\n targetFile,\n content,\n Buffer.isBuffer(content) ? undefined : \"utf8\"\n );\n return content;\n } catch (error) {\n handleWriteError(error, file);\n return content; // Should be unreachable due to handleWriteError throwing\n }\n}\n\n/**\n * Resolve a target file path from a string or an array of paths, optionally selecting by index.\n *\n * @param file - A file path or an array of file paths to resolve from.\n * @param index - Optional index to select an entry when `file` is an array; ignored if not provided.\n * @returns The resolved file path.\n * @throws ValidationError if no file is provided or the resolved target is not a string.\n */\nfunction resolveTargetFile(file: string | string[], index?: number): string {\n if (!file) {\n throw new ValidationError(\"No target file provided\");\n }\n\n const targetFile =\n index !== undefined ? (Array.isArray(file) ? file[index] : file) : file;\n\n if (typeof targetFile !== \"string\") {\n throw new ValidationError(\"Invalid target file path\");\n }\n\n return targetFile;\n}\n\n/**\n * Ensure content is present before writing.\n *\n * @param content - The data to write; a string or Buffer\n * @throws ValidationError if `content` is empty or otherwise falsy\n */\nfunction validateContent(content: string | Buffer): void {\n if (!content) {\n throw new ValidationError(\"No content provided\");\n }\n}\n\n/**\n * Checks whether the given filesystem path refers to a directory.\n *\n * @returns `true` if the path exists and is a directory, `false` otherwise.\n */\nfunction isDirectory(path: string): boolean {\n try {\n return lstatSync(path).isDirectory();\n } catch {\n return false;\n }\n}\n\n/**\n * Determine whether a filesystem path refers to a directory.\n *\n * @param path - The filesystem path to check\n * @returns `true` if the path exists and is a directory, `false` otherwise\n */\nasync function isDirectoryAsync(path: string): Promise<boolean> {\n try {\n const stats = await lstat(path);\n return stats.isDirectory();\n } catch {\n return false;\n }\n}\n\n/**\n * Normalize and rethrow errors that occur while attempting to write to one or more files.\n *\n * @param error - The original error thrown during the write attempt\n * @param file - The target file path or an array of paths that were the intended write targets\n * @throws ValidationError - rethrows the provided ValidationError without modification\n * @throws FileOperationError - thrown for any other error, wrapping the original error with context about the write operation and the target file(s)\n */\nfunction handleWriteError(error: unknown, file: string | string[]): never {\n if (error instanceof ValidationError) {\n throw error;\n }\n throw new FileOperationError(\n \"write to\",\n typeof file === \"string\" ? file : \"multiple files\",\n error as Error\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AA4BA,SAAgBA,YAAU,EACtB,MACA,SACA,SACiC;AACjC,KAAI;EACA,MAAM,aAAa,kBAAkB,MAAM,MAAM;AACjD,kBAAgB,QAAQ;AAExB,MAAI,YAAY,WAAW,CACvB,OAAM,IAAI,MAAM,wCAAwC;AAG5D,gBACI,YACA,SACA,OAAO,SAAS,QAAQ,GAAG,SAAY,OAC1C;AACD,SAAO;UACF,OAAO;AACZ,mBAAiB,OAAO,KAAK;AAC7B,SAAO;;;;;;;;;;;;;;;;AAiBf,eAAsB,eAAe,EACjC,MACA,SACA,SAC0C;AAC1C,KAAI;EACA,MAAM,aAAa,kBAAkB,MAAM,MAAM;AACjD,kBAAgB,QAAQ;AAExB,MAAI,MAAM,iBAAiB,WAAW,CAClC,OAAM,IAAI,MAAM,wCAAwC;AAG5D,QAAMC,UACF,YACA,SACA,OAAO,SAAS,QAAQ,GAAG,SAAY,OAC1C;AACD,SAAO;UACF,OAAO;AACZ,mBAAiB,OAAO,KAAK;AAC7B,SAAO;;;;;;;;;;;AAYf,SAAS,kBAAkB,MAAyB,OAAwB;AACxE,KAAI,CAAC,KACD,OAAM,IAAI,gBAAgB,0BAA0B;CAGxD,MAAM,aACF,UAAU,SAAa,MAAM,QAAQ,KAAK,GAAG,KAAK,SAAS,OAAQ;AAEvE,KAAI,OAAO,eAAe,SACtB,OAAM,IAAI,gBAAgB,2BAA2B;AAGzD,QAAO;;;;;;;;AASX,SAAS,gBAAgB,SAAgC;AACrD,KAAI,CAAC,QACD,OAAM,IAAI,gBAAgB,sBAAsB;;;;;;;AASxD,SAAS,YAAY,MAAuB;AACxC,KAAI;AACA,SAAO,UAAU,KAAK,CAAC,aAAa;SAChC;AACJ,SAAO;;;;;;;;;AAUf,eAAe,iBAAiB,MAAgC;AAC5D,KAAI;AAEA,UADc,MAAM,MAAM,KAAK,EAClB,aAAa;SACtB;AACJ,SAAO;;;;;;;;;;;AAYf,SAAS,iBAAiB,OAAgB,MAAgC;AACtE,KAAI,iBAAiB,gBACjB,OAAM;AAEV,OAAM,IAAI,mBACN,YACA,OAAO,SAAS,WAAW,OAAO,kBAClC,MACH"}
@@ -1,7 +1,7 @@
1
1
  //#region src/writeFile.d.ts
2
2
  /*!
3
3
  * node-minify
4
- * Copyright(c) 2011-2025 Rodolphe Stoclin
4
+ * Copyright (c) 2011-2026 Rodolphe Stoclin
5
5
  * MIT Licensed
6
6
  */
7
7
  interface WriteFileParams {
@@ -26,6 +26,24 @@ declare function writeFile({
26
26
  content,
27
27
  index
28
28
  }: WriteFileParams): string | Buffer;
29
+ /**
30
+ * Write content to a resolved target file path.
31
+ *
32
+ * Resolves the target from `file` (string or array) using `index` when provided, validates the content,
33
+ * ensures the target is not a directory, and writes the content to disk.
34
+ *
35
+ * @param file - Target path or array of target paths; when `file` is an array, `index` selects the entry
36
+ * @param content - Content to write; a `string` or `Buffer`
37
+ * @param index - Optional index used to select a file when `file` is an array
38
+ * @returns The same `content` value that was written
39
+ * @throws ValidationError If no target file, no content, or the resolved target path is invalid
40
+ * @throws FileOperationError If the underlying filesystem write fails (wraps the original error)
41
+ */
42
+ declare function writeFileAsync({
43
+ file,
44
+ content,
45
+ index
46
+ }: WriteFileParams): Promise<string | Buffer>;
29
47
  //#endregion
30
- export { writeFile };
48
+ export { writeFile, writeFileAsync };
31
49
  //# sourceMappingURL=writeFile.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"writeFile.d.ts","names":[],"sources":["../src/writeFile.ts"],"sourcesContent":[],"mappings":";;;AA2BA;;;UAlBU,eAAA,CAqBN;EACD,IAAA,EAAA,MAAA,GAAA,MAAA,EAAA;EAA2B,OAAA,EAAA,MAAA,GApBR,MAoBQ;EAAM,KAAA,CAAA,EAAA,MAAA;;;;;;;;;;;;;;iBAJpB,SAAA;;;;GAIb,2BAA2B"}
1
+ {"version":3,"file":"writeFile.d.ts","names":[],"sources":["../src/writeFile.ts"],"sourcesContent":[],"mappings":";;;AA4BA;;;UAlBU,eAAA,CAqBN;EACD,IAAA,EAAA,MAAA,GAAA,MAAA,EAAA;EAA2B,OAAA,EAAA,MAAA,GApBR,MAoBQ;EAAM,KAAA,CAAA,EAAA,MAAA;AAkCpC;;;;;;;;;;;;;iBAtCgB,SAAA;;;;GAIb,2BAA2B;;;;;;;;;;;;;;iBAkCR,cAAA;;;;GAInB,kBAAkB,iBAAiB"}
package/dist/writeFile.js CHANGED
@@ -1,3 +1,3 @@
1
- import { t as writeFile } from "./writeFile-BRfs9FqY.js";
1
+ import { n as writeFileAsync, t as writeFile } from "./writeFile-DgV8EbFP.js";
2
2
 
3
- export { writeFile };
3
+ export { writeFile, writeFileAsync };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@node-minify/utils",
3
- "version": "10.2.0",
3
+ "version": "10.3.0",
4
4
  "description": "utils for @node-minify",
5
5
  "keywords": [
6
6
  "compressor",
@@ -56,6 +56,6 @@
56
56
  "gzip-size": "7.0.0"
57
57
  },
58
58
  "devDependencies": {
59
- "@node-minify/types": "10.2.0"
59
+ "@node-minify/types": "10.3.0"
60
60
  }
61
61
  }
@@ -1 +0,0 @@
1
- {"version":3,"file":"error-Ck87RwDD.js","names":[],"sources":["../src/error.ts"],"sourcesContent":["/*!\n * node-minify\n * Copyright(c) 2011-2025 Rodolphe Stoclin\n * MIT Licensed\n */\n\n/**\n * Error class for file operation failures.\n * @extends Error\n */\nexport class FileOperationError extends Error {\n constructor(operation: string, path: string, originalError?: Error) {\n super(\n `Failed to ${operation} file ${path}: ${originalError?.message || \"\"}`\n );\n this.name = \"FileOperationError\";\n }\n}\n\n/**\n * Error class for validation failures.\n * @extends Error\n */\nexport class ValidationError extends Error {\n constructor(message: string) {\n super(message);\n this.name = \"ValidationError\";\n }\n}\n"],"mappings":";;;;;;;;;;AAUA,IAAa,qBAAb,cAAwC,MAAM;CAC1C,YAAY,WAAmB,MAAc,eAAuB;AAChE,QACI,aAAa,UAAU,QAAQ,KAAK,IAAI,eAAe,WAAW,KACrE;AACD,OAAK,OAAO;;;;;;;AAQpB,IAAa,kBAAb,cAAqC,MAAM;CACvC,YAAY,SAAiB;AACzB,QAAM,QAAQ;AACd,OAAK,OAAO"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"isValidFile-DnWJtlKA.js","names":["error: unknown"],"sources":["../src/isValidFile.ts"],"sourcesContent":["/*!\n * node-minify\n * Copyright(c) 2011-2025 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;UACtBA,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 +0,0 @@
1
- {"version":3,"file":"types-BUlX1Zbb.d.ts","names":["CompressorReturnType","ImageFormat","CompressorOutput","Buffer","CompressorResult","CompressorOptions","Record","Compressor","TOptions","MinifierOptions","Promise","FileType","Settings","Result","MinifyOptions"],"sources":["../../types/src/types.d.ts"],"sourcesContent":["/*!\n * node-minify\n * Copyright(c) 2011-2025 Rodolphe Stoclin\n * MIT Licensed\n */\n\n/**\n * The return type of a compressor function.\n * @deprecated Use `CompressorResult` instead. Will be removed in v11.\n */\nexport type CompressorReturnType = string;\n\n/**\n * Supported image formats for image compression.\n */\nexport type ImageFormat =\n | \"webp\"\n | \"avif\"\n | \"png\"\n | \"jpeg\"\n | \"jpg\"\n | \"gif\"\n | \"tiff\"\n | \"heif\"\n | \"heic\";\n\n/**\n * Output result for multi-format image compression.\n */\nexport type CompressorOutput = {\n /**\n * Format of the output (e.g., 'webp', 'avif').\n */\n format?: string;\n\n /**\n * Output content as string or Buffer.\n */\n content: string | Buffer;\n};\n\n/**\n * Result returned by a compressor function.\n */\nexport type CompressorResult = {\n /**\n * Minified content as string (for text-based formats like JS, CSS, HTML, SVG).\n */\n code: string;\n\n /**\n * Source map (for JS/CSS compressors).\n */\n map?: string;\n\n /**\n * Minified content as Buffer (for binary formats like images).\n * @example\n * When using sharp for PNG/WebP compression\n */\n buffer?: Buffer;\n\n /**\n * Multiple outputs for multi-format image compression.\n * Used when converting to multiple formats simultaneously.\n * @example\n * [{ format: 'webp', content: <Buffer> }, { format: 'avif', content: <Buffer> }]\n */\n outputs?: CompressorOutput[];\n};\n\n/**\n * Base options that all compressors can accept.\n * Specific compressors may extend this with their own options.\n */\nexport type CompressorOptions = Record<string, unknown>;\n\n/**\n * A compressor function that minifies content.\n * @param args - The minifier options including settings and content\n * @returns A promise resolving to the compression result\n */\nexport type Compressor<TOptions extends CompressorOptions = CompressorOptions> =\n (args: MinifierOptions<TOptions>) => Promise<CompressorResult>;\n\n/**\n * File type for compressors that support multiple types (e.g., YUI).\n */\nexport type FileType = \"js\" | \"css\";\n\n/**\n * User-facing settings for the minify function.\n * This is what users pass when calling minify().\n *\n * @example\n * ```ts\n * import { minify } from '@node-minify/core';\n * import { terser } from '@node-minify/terser';\n *\n * await minify({\n * compressor: terser,\n * input: 'src/*.js',\n * output: 'dist/bundle.min.js',\n * options: { mangle: true }\n * });\n * ```\n */\nexport type Settings<TOptions extends CompressorOptions = CompressorOptions> = {\n /**\n * The compressor function to use for minification.\n */\n compressor: Compressor<TOptions>;\n\n /**\n * Optional label for the compressor (used in logging).\n */\n compressorLabel?: string;\n\n /**\n * Content to minify (for in-memory minification).\n * If provided, input/output are not required.\n * For text-based formats (JS, CSS, HTML, SVG): string\n * For binary formats (images): Buffer (handled internally by image compressors)\n */\n content?: string | Buffer;\n\n /**\n * Input file path(s) or glob pattern.\n * Can be a single file, array of files, or wildcard pattern.\n *\n * @example\n * - 'src/app.js'\n * - ['src/a.js', 'src/b.js']\n * - 'src/**\\/*.js'\n */\n input?: string | string[];\n\n /**\n * Output file path.\n * Use $1 as placeholder for input filename in multi-file scenarios.\n * Can be a single file, array of files, or pattern with $1.\n *\n * @example\n * - 'dist/bundle.min.js'\n * - ['file1.min.js', 'file2.min.js']\n * - '$1.min.js' (creates app.min.js from app.js)\n */\n output?: string | string[];\n\n /**\n * Compressor-specific options.\n * See individual compressor documentation for available options.\n */\n options?: TOptions;\n\n /**\n * CLI option string (used by CLI only).\n * @internal\n */\n option?: string;\n\n /**\n * Buffer size for file operations (in bytes).\n * @default 1024000 (1MB)\n */\n buffer?: number;\n\n /**\n * File type for compressors that support multiple types.\n * Required for YUI compressor.\n */\n type?: FileType;\n\n /**\n * Suppress console output.\n * @default false\n */\n silence?: boolean;\n\n /**\n * Public folder to prepend to input paths.\n *\n * @example\n * With publicFolder: 'public/js/' and input: 'app.js',\n * the actual path becomes 'public/js/app.js'\n */\n publicFolder?: string;\n\n /**\n * Replace files in place instead of creating new output files.\n * @default false\n */\n replaceInPlace?: boolean;\n};\n\n/**\n * Options passed to compressor functions internally.\n * This is what compressors receive, not what users pass.\n */\nexport type MinifierOptions<\n TOptions extends CompressorOptions = CompressorOptions,\n> = {\n /**\n * The full settings object.\n */\n settings: Settings<TOptions>;\n\n /**\n * The content to minify.\n * For text-based formats (JS, CSS, HTML, SVG): string\n * For binary formats (images): Buffer\n * For multiple binary files: Buffer[]\n */\n content?: string | Buffer | Buffer[];\n\n /**\n * Index of current file when processing multiple files.\n */\n index?: number;\n};\n\n/**\n * Result returned after compression (used by CLI).\n */\nexport type Result = {\n /**\n * Label of the compressor used.\n */\n compressorLabel: string;\n\n /**\n * Size of minified content (formatted string, e.g., \"1.5 KB\").\n */\n size: string;\n\n /**\n * Gzipped size of minified content (formatted string).\n */\n sizeGzip: string;\n};\n\n/**\n * Type alias for user convenience.\n * @deprecated Use `Settings` instead. Will be removed in v11.\n */\nexport type MinifyOptions<\n TOptions extends CompressorOptions = CompressorOptions,\n> = Settings<TOptions>;\n"],"mappings":";;;;;AAqNsC,KAxL1BE,gBAAAA,GAwL0B;;;;;;;;;oBA/KhBC;;;;;KAMVC,gBAAAA;;;;;;;;;;;;;;;;WAgBCD;;;;;;;;YAQCD;;;;;;KAOFG,iBAAAA,GAAoBC;;;;;;KAOpBC,4BAA4BF,oBAAoBA,4BACjDI,gBAAgBD,cAAcE,QAAQN;;;;KAKrCO,QAAAA;;;;;;;;;;;;;;;;;;KAmBAC,0BAA0BP,oBAAoBA;;;;cAI1CE,WAAWC;;;;;;;;;;;;;qBAaJL;;;;;;;;;;;;;;;;;;;;;;;;;;;;;YA6BTK;;;;;;;;;;;;;;;;;;SAkBHG;;;;;;;;;;;;;;;;;;;;;;;;;;;KA4BCF,iCACSJ,oBAAoBA;;;;YAK3BO,SAASJ;;;;;;;;qBAQAL,SAASA"}
@@ -1,39 +0,0 @@
1
- import { n as ValidationError, t as FileOperationError } from "./error-Ck87RwDD.js";
2
- import { existsSync, lstatSync, writeFileSync } from "node:fs";
3
-
4
- //#region src/writeFile.ts
5
- /*!
6
- * node-minify
7
- * Copyright(c) 2011-2025 Rodolphe Stoclin
8
- * MIT Licensed
9
- */
10
- /**
11
- * Write provided content to a target file.
12
- *
13
- * When `file` is an array and `index` is provided, the file at that index is used; otherwise `file` is used directly.
14
- *
15
- * @param file - Target path or array of target paths
16
- * @param content - Content to write; may be a `string` or `Buffer`
17
- * @param index - Optional index to select a file when `file` is an array
18
- * @returns The same `content` value that was written
19
- * @throws ValidationError If no target file, no content, or the resolved target path is invalid
20
- * @throws FileOperationError If the underlying filesystem write fails (wraps the original error)
21
- */
22
- function writeFile({ file, content, index }) {
23
- try {
24
- if (!file) throw new ValidationError("No target file provided");
25
- if (!content) throw new ValidationError("No content provided");
26
- const targetFile = index !== void 0 ? Array.isArray(file) ? file[index] : file : file;
27
- if (typeof targetFile !== "string") throw new ValidationError("Invalid target file path");
28
- if (!(!existsSync(targetFile) || !lstatSync(targetFile).isDirectory())) throw new Error("Target path exists and is a directory");
29
- writeFileSync(targetFile, content, Buffer.isBuffer(content) ? void 0 : "utf8");
30
- return content;
31
- } catch (error) {
32
- if (error instanceof ValidationError) throw error;
33
- throw new FileOperationError("write to", typeof file === "string" ? file : "multiple files", error);
34
- }
35
- }
36
-
37
- //#endregion
38
- export { writeFile as t };
39
- //# sourceMappingURL=writeFile-BRfs9FqY.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"writeFile-BRfs9FqY.js","names":[],"sources":["../src/writeFile.ts"],"sourcesContent":["/*!\n * node-minify\n * Copyright(c) 2011-2025 Rodolphe Stoclin\n * MIT Licensed\n */\n\nimport { existsSync, lstatSync, writeFileSync } from \"node:fs\";\nimport { FileOperationError, ValidationError } from \"./error.ts\";\n\ninterface WriteFileParams {\n file: string | string[];\n content: string | Buffer;\n index?: number;\n}\n\n/**\n * Write provided content to a target file.\n *\n * When `file` is an array and `index` is provided, the file at that index is used; otherwise `file` is used directly.\n *\n * @param file - Target path or array of target paths\n * @param content - Content to write; may be a `string` or `Buffer`\n * @param index - Optional index to select a file when `file` is an array\n * @returns The same `content` value that was written\n * @throws ValidationError If no target file, no content, or the resolved target path is invalid\n * @throws FileOperationError If the underlying filesystem write fails (wraps the original error)\n */\nexport function writeFile({\n file,\n content,\n index,\n}: WriteFileParams): string | Buffer {\n try {\n if (!file) {\n throw new ValidationError(\"No target file provided\");\n }\n\n if (!content) {\n throw new ValidationError(\"No content provided\");\n }\n\n const targetFile =\n index !== undefined\n ? Array.isArray(file)\n ? file[index]\n : file\n : file;\n\n if (typeof targetFile !== \"string\") {\n throw new ValidationError(\"Invalid target file path\");\n }\n\n const shouldWrite =\n !existsSync(targetFile) || !lstatSync(targetFile).isDirectory();\n\n if (!shouldWrite) {\n throw new Error(\"Target path exists and is a directory\");\n }\n\n writeFileSync(\n targetFile,\n content,\n Buffer.isBuffer(content) ? undefined : \"utf8\"\n );\n return content;\n } catch (error) {\n if (error instanceof ValidationError) {\n throw error;\n }\n throw new FileOperationError(\n \"write to\",\n typeof file === \"string\" ? file : \"multiple files\",\n error as Error\n );\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AA2BA,SAAgB,UAAU,EACtB,MACA,SACA,SACiC;AACjC,KAAI;AACA,MAAI,CAAC,KACD,OAAM,IAAI,gBAAgB,0BAA0B;AAGxD,MAAI,CAAC,QACD,OAAM,IAAI,gBAAgB,sBAAsB;EAGpD,MAAM,aACF,UAAU,SACJ,MAAM,QAAQ,KAAK,GACf,KAAK,SACL,OACJ;AAEV,MAAI,OAAO,eAAe,SACtB,OAAM,IAAI,gBAAgB,2BAA2B;AAMzD,MAAI,EAFA,CAAC,WAAW,WAAW,IAAI,CAAC,UAAU,WAAW,CAAC,aAAa,EAG/D,OAAM,IAAI,MAAM,wCAAwC;AAG5D,gBACI,YACA,SACA,OAAO,SAAS,QAAQ,GAAG,SAAY,OAC1C;AACD,SAAO;UACF,OAAO;AACZ,MAAI,iBAAiB,gBACjB,OAAM;AAEV,QAAM,IAAI,mBACN,YACA,OAAO,SAAS,WAAW,OAAO,kBAClC,MACH"}