@node-minify/utils 10.3.0 → 10.4.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 (45) hide show
  1. package/dist/buildArgs.js +1 -1
  2. package/dist/buildArgs.js.map +1 -1
  3. package/dist/compressSingleFile.d.ts +1 -1
  4. package/dist/compressor-resolver.d.ts +32 -2
  5. package/dist/compressor-resolver.d.ts.map +1 -1
  6. package/dist/compressor-resolver.js +64 -36
  7. package/dist/compressor-resolver.js.map +1 -1
  8. package/dist/deleteFile.js +1 -1
  9. package/dist/{error-Ctspysdk.js → error-CUgKxOvI.js} +1 -1
  10. package/dist/{error-Ctspysdk.js.map → error-CUgKxOvI.js.map} +1 -1
  11. package/dist/error.js +1 -1
  12. package/dist/errors.d.ts +27 -0
  13. package/dist/errors.d.ts.map +1 -0
  14. package/dist/errors.js +32 -0
  15. package/dist/errors.js.map +1 -0
  16. package/dist/getContentFromFiles.js +2 -2
  17. package/dist/getContentFromFiles.js.map +1 -1
  18. package/dist/getFilesizeBrotliInBytes.d.ts +17 -1
  19. package/dist/getFilesizeBrotliInBytes.d.ts.map +1 -1
  20. package/dist/getFilesizeBrotliInBytes.js +40 -6
  21. package/dist/getFilesizeBrotliInBytes.js.map +1 -1
  22. package/dist/getFilesizeGzippedInBytes.d.ts +13 -7
  23. package/dist/getFilesizeGzippedInBytes.d.ts.map +1 -1
  24. package/dist/getFilesizeGzippedInBytes.js +40 -17
  25. package/dist/getFilesizeGzippedInBytes.js.map +1 -1
  26. package/dist/index.d.ts +5 -4
  27. package/dist/index.js +7 -6
  28. package/dist/{isValidFile-BW5AgBWb.js → isValidFile-COstpeyW.js} +2 -2
  29. package/dist/isValidFile-COstpeyW.js.map +1 -0
  30. package/dist/isValidFile.js +1 -1
  31. package/dist/prettyBytes.js +1 -1
  32. package/dist/readFile.js +1 -1
  33. package/dist/run.d.ts +1 -1
  34. package/dist/run.js +11 -7
  35. package/dist/run.js.map +1 -1
  36. package/dist/setFileNameMin.js +1 -1
  37. package/dist/{types-CzkB7gxg.d.ts → types-CWBFD3au.d.ts} +9 -1
  38. package/dist/{types-CzkB7gxg.d.ts.map → types-CWBFD3au.d.ts.map} +1 -1
  39. package/dist/{writeFile-DgV8EbFP.js → writeFile-mfUS3rMz.js} +4 -31
  40. package/dist/writeFile-mfUS3rMz.js.map +1 -0
  41. package/dist/writeFile.d.ts.map +1 -1
  42. package/dist/writeFile.js +1 -1
  43. package/package.json +2 -2
  44. package/dist/isValidFile-BW5AgBWb.js.map +0 -1
  45. package/dist/writeFile-DgV8EbFP.js.map +0 -1
package/dist/buildArgs.js CHANGED
@@ -1,4 +1,4 @@
1
- import { n as ValidationError } from "./error-Ctspysdk.js";
1
+ import { n as ValidationError } from "./error-CUgKxOvI.js";
2
2
 
3
3
  //#region src/buildArgs.ts
4
4
  /*!
@@ -1 +1 @@
1
- {"version":3,"file":"buildArgs.js","names":["result: BuildArgsOptions","args: string[]"],"sources":["../src/buildArgs.ts"],"sourcesContent":["/*!\n * node-minify\n * Copyright (c) 2011-2026 Rodolphe Stoclin\n * MIT Licensed\n */\n\nimport { ValidationError } from \"./error.ts\";\nimport type { BuildArgsOptions } from \"./types.ts\";\n\n/**\n * Converts a generic options object to BuildArgsOptions by filtering out non-primitive values.\n * Only keeps string, number, boolean, and undefined values.\n * @param options - Generic options object\n * @returns Filtered options compatible with buildArgs\n */\nexport function toBuildArgsOptions(\n options: Record<string, unknown>\n): BuildArgsOptions {\n const result: BuildArgsOptions = {};\n for (const [key, value] of Object.entries(options)) {\n if (\n typeof value === \"string\" ||\n typeof value === \"number\" ||\n typeof value === \"boolean\" ||\n value === undefined\n ) {\n result[key] = value;\n }\n }\n return result;\n}\n\n/**\n * Builds arguments array based on an object.\n * @param options Object containing command line arguments\n * @returns Array of command line arguments\n * @throws {ValidationError} If options is null or undefined\n * @example\n * buildArgs({ compress: true, output: 'file.min.js' })\n * // returns ['--compress', '--output', 'file.min.js']\n */\nexport function buildArgs(options: BuildArgsOptions): string[] {\n if (!options || typeof options !== \"object\") {\n throw new ValidationError(\"Options must be a valid object\");\n }\n\n const args: string[] = [];\n Object.entries(options).forEach(([key, value]) => {\n if (value !== undefined && value !== false) {\n args.push(`--${key}`);\n if (value !== true) {\n args.push(String(value));\n }\n }\n });\n\n return args;\n}\n"],"mappings":";;;;;;;;;;;;;;AAeA,SAAgB,mBACZ,SACgB;CAChB,MAAMA,SAA2B,EAAE;AACnC,MAAK,MAAM,CAAC,KAAK,UAAU,OAAO,QAAQ,QAAQ,CAC9C,KACI,OAAO,UAAU,YACjB,OAAO,UAAU,YACjB,OAAO,UAAU,aACjB,UAAU,OAEV,QAAO,OAAO;AAGtB,QAAO;;;;;;;;;;;AAYX,SAAgB,UAAU,SAAqC;AAC3D,KAAI,CAAC,WAAW,OAAO,YAAY,SAC/B,OAAM,IAAI,gBAAgB,iCAAiC;CAG/D,MAAMC,OAAiB,EAAE;AACzB,QAAO,QAAQ,QAAQ,CAAC,SAAS,CAAC,KAAK,WAAW;AAC9C,MAAI,UAAU,UAAa,UAAU,OAAO;AACxC,QAAK,KAAK,KAAK,MAAM;AACrB,OAAI,UAAU,KACV,MAAK,KAAK,OAAO,MAAM,CAAC;;GAGlC;AAEF,QAAO"}
1
+ {"version":3,"file":"buildArgs.js","names":[],"sources":["../src/buildArgs.ts"],"sourcesContent":["/*!\n * node-minify\n * Copyright (c) 2011-2026 Rodolphe Stoclin\n * MIT Licensed\n */\n\nimport { ValidationError } from \"./error.ts\";\nimport type { BuildArgsOptions } from \"./types.ts\";\n\n/**\n * Converts a generic options object to BuildArgsOptions by filtering out non-primitive values.\n * Only keeps string, number, boolean, and undefined values.\n * @param options - Generic options object\n * @returns Filtered options compatible with buildArgs\n */\nexport function toBuildArgsOptions(\n options: Record<string, unknown>\n): BuildArgsOptions {\n const result: BuildArgsOptions = {};\n for (const [key, value] of Object.entries(options)) {\n if (\n typeof value === \"string\" ||\n typeof value === \"number\" ||\n typeof value === \"boolean\" ||\n value === undefined\n ) {\n result[key] = value;\n }\n }\n return result;\n}\n\n/**\n * Builds arguments array based on an object.\n * @param options Object containing command line arguments\n * @returns Array of command line arguments\n * @throws {ValidationError} If options is null or undefined\n * @example\n * buildArgs({ compress: true, output: 'file.min.js' })\n * // returns ['--compress', '--output', 'file.min.js']\n */\nexport function buildArgs(options: BuildArgsOptions): string[] {\n if (!options || typeof options !== \"object\") {\n throw new ValidationError(\"Options must be a valid object\");\n }\n\n const args: string[] = [];\n Object.entries(options).forEach(([key, value]) => {\n if (value !== undefined && value !== false) {\n args.push(`--${key}`);\n if (value !== true) {\n args.push(String(value));\n }\n }\n });\n\n return args;\n}\n"],"mappings":";;;;;;;;;;;;;;AAeA,SAAgB,mBACZ,SACgB;CAChB,MAAM,SAA2B,EAAE;AACnC,MAAK,MAAM,CAAC,KAAK,UAAU,OAAO,QAAQ,QAAQ,CAC9C,KACI,OAAO,UAAU,YACjB,OAAO,UAAU,YACjB,OAAO,UAAU,aACjB,UAAU,OAEV,QAAO,OAAO;AAGtB,QAAO;;;;;;;;;;;AAYX,SAAgB,UAAU,SAAqC;AAC3D,KAAI,CAAC,WAAW,OAAO,YAAY,SAC/B,OAAM,IAAI,gBAAgB,iCAAiC;CAG/D,MAAM,OAAiB,EAAE;AACzB,QAAO,QAAQ,QAAQ,CAAC,SAAS,CAAC,KAAK,WAAW;AAC9C,MAAI,UAAU,UAAa,UAAU,OAAO;AACxC,QAAK,KAAK,KAAK,MAAM;AACrB,OAAI,UAAU,KACV,MAAK,KAAK,OAAO,MAAM,CAAC;;GAGlC;AAEF,QAAO"}
@@ -1,4 +1,4 @@
1
- import { i as Settings, n as CompressorOptions } from "./types-CzkB7gxg.js";
1
+ import { i as Settings, n as CompressorOptions } from "./types-CWBFD3au.js";
2
2
 
3
3
  //#region src/compressSingleFile.d.ts
4
4
 
@@ -1,4 +1,4 @@
1
- import { t as Compressor } from "./types-CzkB7gxg.js";
1
+ import { t as Compressor } from "./types-CWBFD3au.js";
2
2
 
3
3
  //#region src/compressor-resolver.d.ts
4
4
 
@@ -19,6 +19,36 @@ type CompressorResolution = {
19
19
  */
20
20
  isBuiltIn: boolean;
21
21
  };
22
+ /**
23
+ * Determines whether a string represents a local file path.
24
+ *
25
+ * @param name - The path string to test
26
+ * @returns `true` if `name` appears to be a local file path, `false` otherwise
27
+ */
28
+ declare function isLocalPath(name: string): boolean;
29
+ /**
30
+ * Try to resolve a compressor from a built-in @node-minify package.
31
+ *
32
+ * @param name - The compressor name (e.g., "terser", "esbuild")
33
+ * @returns The resolved CompressorResolution if found, or `null` if not installed/available
34
+ */
35
+ declare function tryResolveBuiltIn(name: string): Promise<CompressorResolution | null>;
36
+ /**
37
+ * Try to resolve a compressor from an npm package.
38
+ *
39
+ * @param name - The npm package name
40
+ * @returns The resolved CompressorResolution if found, or `null` if not resolvable
41
+ * @throws Error if the package is found but doesn't export a valid compressor
42
+ */
43
+ declare function tryResolveNpmPackage(name: string): Promise<CompressorResolution | null>;
44
+ /**
45
+ * Try to resolve a compressor from a local file path.
46
+ *
47
+ * @param name - The local file path (e.g., "./my-compressor.js")
48
+ * @returns The resolved CompressorResolution if found, or `null` if not a local path
49
+ * @throws Error if the file is found but doesn't export a valid compressor
50
+ */
51
+ declare function tryResolveLocalFile(name: string): Promise<CompressorResolution | null>;
22
52
  /**
23
53
  * Resolve a compressor by name from a built-in @node-minify package, an installed npm package, or a local file path.
24
54
  *
@@ -42,5 +72,5 @@ declare function isBuiltInCompressor(name: string): boolean;
42
72
  */
43
73
  declare function getKnownExportName(name: string): string | undefined;
44
74
  //#endregion
45
- export { CompressorResolution, getKnownExportName, isBuiltInCompressor, resolveCompressor };
75
+ export { CompressorResolution, getKnownExportName, isBuiltInCompressor, isLocalPath, resolveCompressor, tryResolveBuiltIn, tryResolveLocalFile, tryResolveNpmPackage };
46
76
  //# sourceMappingURL=compressor-resolver.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"compressor-resolver.d.ts","names":[],"sources":["../src/compressor-resolver.ts"],"sourcesContent":[],"mappings":";;;;AAkRA;;;KAzOY,oBAAA;;;;cAII;;;;;;;;;;;;;;;;;iBAqHM,iBAAA,gBAEnB,QAAQ;;;;;;;iBAoGK,mBAAA;;;;;;;iBAUA,kBAAA"}
1
+ {"version":3,"file":"compressor-resolver.d.ts","names":[],"sources":["../src/compressor-resolver.ts"],"sourcesContent":[],"mappings":";;;;AAmLA;AAsCA;AA8CA;AAsCgB,KAnQJ,oBAAA,GAmQuB;EAUnB;;;cAzQA;;;;;;;;;;;;;;;;iBAmBA,WAAA;;;;;;;iBA+EM,iBAAA,gBAEnB,QAAQ;;;;;;;;iBAiCW,oBAAA,gBAEnB,QAAQ;;;;;;;;iBAoCW,mBAAA,gBAEnB,QAAQ;;;;;;;;iBA4CW,iBAAA,gBAEnB,QAAQ;;;;;;;iBAoCK,mBAAA;;;;;;;iBAUA,kBAAA"}
@@ -28,6 +28,7 @@ const KNOWN_COMPRESSOR_EXPORTS = {
28
28
  crass: "crass",
29
29
  sqwish: "sqwish",
30
30
  "html-minifier": "htmlMinifier",
31
+ "minify-html": "minifyHtml",
31
32
  jsonminify: "jsonMinify",
32
33
  imagemin: "imagemin",
33
34
  sharp: "sharp",
@@ -37,21 +38,17 @@ const KNOWN_COMPRESSOR_EXPORTS = {
37
38
  /**
38
39
  * Determines whether a string represents a local file path.
39
40
  *
40
- * Recognizes POSIX-style relative or absolute paths starting with "./", "../", or "/",
41
- * and Windows absolute paths like "C:\\" or "C:/".
42
- *
43
41
  * @param name - The path string to test
44
42
  * @returns `true` if `name` appears to be a local file path, `false` otherwise
45
43
  */
46
44
  function isLocalPath(name) {
47
- return name.startsWith("./") || name.startsWith("../") || name.startsWith("/") || /^[a-zA-Z]:[\\/]/.test(name);
45
+ return name.startsWith("./") || name.startsWith("../") || name.startsWith("/") || /^[a-zA-Z]:[/\\]/.test(name);
48
46
  }
49
47
  /**
50
48
  * Converts a package name to camelCase for export lookup.
51
49
  *
52
- * Examples: "my-tool" -> "myTool", "some_pkg" -> "somePkg"
53
- *
54
- * @returns The input `name` converted to camelCase where characters following `-` or `_` are uppercased
50
+ * @param name - The package or file name to convert
51
+ * @returns The input `name` converted to camelCase
55
52
  */
56
53
  function toCamelCase(name) {
57
54
  return name.replace(/[-_](.)/g, (_, char) => char.toUpperCase());
@@ -59,13 +56,6 @@ function toCamelCase(name) {
59
56
  /**
60
57
  * Resolve a compressor function exported by a loaded module.
61
58
  *
62
- * Searches the module's exports in this priority order to locate a usable compressor:
63
- * 1. Known built-in export for the given name
64
- * 2. CamelCase export derived from the package/base name
65
- * 3. Named export `compressor`
66
- * 4. Default export
67
- * 5. First export whose value is a function
68
- *
69
59
  * @param mod - The imported module object to inspect for exports
70
60
  * @param name - The package or file name used to derive known and camelCase export names
71
61
  * @returns The resolved `Compressor` function if found, or `null` if no suitable function export exists
@@ -83,22 +73,22 @@ function extractCompressor(mod, name) {
83
73
  /**
84
74
  * Create a display label from a compressor package name or a local file path.
85
75
  *
86
- * @param name - Compressor npm package name or a local file path (./, ../, /, or Windows absolute).
87
- * @returns The package name for npm compressors, or the local file's basename without its .js/.ts/.mjs/.cjs extension.
76
+ * @param name - Compressor npm package name or a local file path
77
+ * @returns The package name for npm compressors, or the local file's basename without extension
88
78
  */
89
79
  function generateLabel(name) {
90
80
  if (isLocalPath(name)) return path.basename(name).replace(/\.(js|ts|mjs|cjs)$/, "");
91
81
  return name;
92
82
  }
93
83
  /**
94
- * Resolve a compressor by name from a built-in @node-minify package, an installed npm package, or a local file path.
84
+ * Try to resolve a compressor from a built-in @node-minify package.
95
85
  *
96
- * @param name - Compressor identifier: a built-in name (e.g., "terser"), an npm package name, or a local path (e.g., "./compressor.js")
97
- * @returns The resolved CompressorResolution containing the compressor function, a display `label`, and `isBuiltIn` flag
98
- * @throws Error if the compressor cannot be found or the module does not export a valid compressor function
86
+ * @param name - The compressor name (e.g., "terser", "esbuild")
87
+ * @returns The resolved CompressorResolution if found, or `null` if not installed/available
99
88
  */
100
- async function resolveCompressor(name) {
101
- if (name in KNOWN_COMPRESSOR_EXPORTS) try {
89
+ async function tryResolveBuiltIn(name) {
90
+ if (!(name in KNOWN_COMPRESSOR_EXPORTS)) return null;
91
+ try {
102
92
  const compressor = extractCompressor(await import(`@node-minify/${name}`), name);
103
93
  if (compressor) return {
104
94
  compressor,
@@ -106,6 +96,16 @@ async function resolveCompressor(name) {
106
96
  isBuiltIn: true
107
97
  };
108
98
  } catch {}
99
+ return null;
100
+ }
101
+ /**
102
+ * Try to resolve a compressor from an npm package.
103
+ *
104
+ * @param name - The npm package name
105
+ * @returns The resolved CompressorResolution if found, or `null` if not resolvable
106
+ * @throws Error if the package is found but doesn't export a valid compressor
107
+ */
108
+ async function tryResolveNpmPackage(name) {
109
109
  try {
110
110
  const compressor = extractCompressor(await import(name), name);
111
111
  if (compressor) return {
@@ -116,20 +116,48 @@ async function resolveCompressor(name) {
116
116
  throw new Error(`Package '${name}' doesn't export a valid compressor function. Expected a function as default export, named export 'compressor', or named export '${toCamelCase(name)}'.`);
117
117
  } catch (error) {
118
118
  if (error instanceof Error && error.message.includes("doesn't export a valid compressor")) throw error;
119
- if (isLocalPath(name)) try {
120
- const compressor = extractCompressor(await import(pathToFileURL(path.resolve(process.cwd(), name)).href), name);
121
- if (compressor) return {
122
- compressor,
123
- label: generateLabel(name),
124
- isBuiltIn: false
125
- };
126
- throw new Error(`Local file '${name}' doesn't export a valid compressor function. Expected a function as default export or named export 'compressor'.`);
127
- } catch (localError) {
128
- if (localError instanceof Error && localError.message.includes("doesn't export a valid compressor")) throw localError;
129
- throw new Error(`Could not load local compressor '${name}'. File not found or failed to import: ${localError instanceof Error ? localError.message : String(localError)}`);
130
- }
131
- throw new Error(`Could not resolve compressor '${name}'. Is it installed? For local files, use a path starting with './' or '/'.`);
119
+ return null;
120
+ }
121
+ }
122
+ /**
123
+ * Try to resolve a compressor from a local file path.
124
+ *
125
+ * @param name - The local file path (e.g., "./my-compressor.js")
126
+ * @returns The resolved CompressorResolution if found, or `null` if not a local path
127
+ * @throws Error if the file is found but doesn't export a valid compressor
128
+ */
129
+ async function tryResolveLocalFile(name) {
130
+ if (!isLocalPath(name)) return null;
131
+ try {
132
+ const compressor = extractCompressor(await import(pathToFileURL(path.resolve(process.cwd(), name)).href), name);
133
+ if (compressor) return {
134
+ compressor,
135
+ label: generateLabel(name),
136
+ isBuiltIn: false
137
+ };
138
+ throw new Error(`Local file '${name}' doesn't export a valid compressor function. Expected a function as default export or named export 'compressor'.`);
139
+ } catch (error) {
140
+ if (error instanceof Error && error.message.includes("doesn't export a valid compressor")) throw error;
141
+ throw new Error(`Could not load local compressor '${name}'. File not found or failed to import: ${error instanceof Error ? error.message : String(error)}`);
142
+ }
143
+ }
144
+ /**
145
+ * Resolve a compressor by name from a built-in @node-minify package, an installed npm package, or a local file path.
146
+ *
147
+ * @param name - Compressor identifier: a built-in name (e.g., "terser"), an npm package name, or a local path (e.g., "./compressor.js")
148
+ * @returns The resolved CompressorResolution containing the compressor function, a display `label`, and `isBuiltIn` flag
149
+ * @throws Error if the compressor cannot be found or the module does not export a valid compressor function
150
+ */
151
+ async function resolveCompressor(name) {
152
+ const builtIn = await tryResolveBuiltIn(name);
153
+ if (builtIn) return builtIn;
154
+ const npmPackage = await tryResolveNpmPackage(name);
155
+ if (npmPackage) return npmPackage;
156
+ if (isLocalPath(name)) {
157
+ const localFile = await tryResolveLocalFile(name);
158
+ if (localFile) return localFile;
132
159
  }
160
+ throw new Error(`Could not resolve compressor '${name}'. Is it installed? For local files, use a path starting with './' or '/'.`);
133
161
  }
134
162
  /**
135
163
  * Determines whether a compressor name corresponds to a known built-in compressor.
@@ -151,5 +179,5 @@ function getKnownExportName(name) {
151
179
  }
152
180
 
153
181
  //#endregion
154
- export { getKnownExportName, isBuiltInCompressor, resolveCompressor };
182
+ export { getKnownExportName, isBuiltInCompressor, isLocalPath, resolveCompressor, tryResolveBuiltIn, tryResolveLocalFile, tryResolveNpmPackage };
155
183
  //# sourceMappingURL=compressor-resolver.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"compressor-resolver.js","names":["KNOWN_COMPRESSOR_EXPORTS: Record<string, string>"],"sources":["../src/compressor-resolver.ts"],"sourcesContent":["/*!\n * node-minify\n * Copyright (c) 2011-2026 Rodolphe Stoclin\n * MIT Licensed\n */\n\nimport path from \"node:path\";\nimport { pathToFileURL } from \"node:url\";\nimport type { Compressor } from \"@node-minify/types\";\n\n/**\n * Known compressor exports for built-in @node-minify packages.\n * Maps package name to the exported function name.\n */\nconst KNOWN_COMPRESSOR_EXPORTS: Record<string, string> = {\n esbuild: \"esbuild\",\n \"google-closure-compiler\": \"gcc\",\n oxc: \"oxc\",\n swc: \"swc\",\n terser: \"terser\",\n \"uglify-js\": \"uglifyJs\",\n \"babel-minify\": \"babelMinify\",\n \"uglify-es\": \"uglifyEs\",\n yui: \"yui\",\n \"clean-css\": \"cleanCss\",\n cssnano: \"cssnano\",\n csso: \"csso\",\n lightningcss: \"lightningCss\",\n crass: \"crass\",\n sqwish: \"sqwish\",\n \"html-minifier\": \"htmlMinifier\",\n jsonminify: \"jsonMinify\",\n imagemin: \"imagemin\",\n sharp: \"sharp\",\n svgo: \"svgo\",\n \"no-compress\": \"noCompress\",\n};\n\n/**\n * Result from resolving a compressor.\n */\nexport type CompressorResolution = {\n /**\n * The resolved compressor function.\n */\n compressor: Compressor;\n\n /**\n * Label for the compressor (used in logs/reports).\n */\n label: string;\n\n /**\n * Whether this is a built-in @node-minify compressor.\n */\n isBuiltIn: boolean;\n};\n\n/**\n * Determines whether a string represents a local file path.\n *\n * Recognizes POSIX-style relative or absolute paths starting with \"./\", \"../\", or \"/\",\n * and Windows absolute paths like \"C:\\\\\" or \"C:/\".\n *\n * @param name - The path string to test\n * @returns `true` if `name` appears to be a local file path, `false` otherwise\n */\nfunction isLocalPath(name: string): boolean {\n return (\n name.startsWith(\"./\") ||\n name.startsWith(\"../\") ||\n name.startsWith(\"/\") ||\n /^[a-zA-Z]:[\\\\/]/.test(name) // Windows absolute path\n );\n}\n\n/**\n * Converts a package name to camelCase for export lookup.\n *\n * Examples: \"my-tool\" -> \"myTool\", \"some_pkg\" -> \"somePkg\"\n *\n * @returns The input `name` converted to camelCase where characters following `-` or `_` are uppercased\n */\nfunction toCamelCase(name: string): string {\n return name.replace(/[-_](.)/g, (_, char) => char.toUpperCase());\n}\n\n/**\n * Resolve a compressor function exported by a loaded module.\n *\n * Searches the module's exports in this priority order to locate a usable compressor:\n * 1. Known built-in export for the given name\n * 2. CamelCase export derived from the package/base name\n * 3. Named export `compressor`\n * 4. Default export\n * 5. First export whose value is a function\n *\n * @param mod - The imported module object to inspect for exports\n * @param name - The package or file name used to derive known and camelCase export names\n * @returns The resolved `Compressor` function if found, or `null` if no suitable function export exists\n */\nfunction extractCompressor(\n mod: Record<string, unknown>,\n name: string\n): Compressor | null {\n // 1. Check known exports first\n const knownExport = KNOWN_COMPRESSOR_EXPORTS[name];\n if (knownExport && typeof mod[knownExport] === \"function\") {\n return mod[knownExport] as Compressor;\n }\n\n // 2. Try camelCase of package name\n const baseName = name.includes(\"/\")\n ? (name.split(\"/\").pop() ?? name)\n : name;\n const camelName = toCamelCase(baseName);\n if (typeof mod[camelName] === \"function\") {\n return mod[camelName] as Compressor;\n }\n\n // 3. Try \"compressor\" named export\n if (typeof mod.compressor === \"function\") {\n return mod.compressor as Compressor;\n }\n\n // 4. Try default export\n if (typeof mod.default === \"function\") {\n return mod.default as Compressor;\n }\n\n // 5. Find first function export\n for (const value of Object.values(mod)) {\n if (typeof value === \"function\") {\n return value as Compressor;\n }\n }\n\n return null;\n}\n\n/**\n * Create a display label from a compressor package name or a local file path.\n *\n * @param name - Compressor npm package name or a local file path (./, ../, /, or Windows absolute).\n * @returns The package name for npm compressors, or the local file's basename without its .js/.ts/.mjs/.cjs extension.\n */\nfunction generateLabel(name: string): string {\n if (isLocalPath(name)) {\n // For local paths, use the filename without extension\n return path.basename(name).replace(/\\.(js|ts|mjs|cjs)$/, \"\");\n }\n // For npm packages, use as-is\n return name;\n}\n\n/**\n * Resolve a compressor by name from a built-in @node-minify package, an installed npm package, or a local file path.\n *\n * @param name - Compressor identifier: a built-in name (e.g., \"terser\"), an npm package name, or a local path (e.g., \"./compressor.js\")\n * @returns The resolved CompressorResolution containing the compressor function, a display `label`, and `isBuiltIn` flag\n * @throws Error if the compressor cannot be found or the module does not export a valid compressor function\n */\nexport async function resolveCompressor(\n name: string\n): Promise<CompressorResolution> {\n const isKnown = name in KNOWN_COMPRESSOR_EXPORTS;\n\n // 1. Try built-in @node-minify package\n if (isKnown) {\n try {\n const mod = (await import(`@node-minify/${name}`)) as Record<\n string,\n unknown\n >;\n const compressor = extractCompressor(mod, name);\n\n if (compressor) {\n return {\n compressor,\n label: name,\n isBuiltIn: true,\n };\n }\n } catch {\n // Built-in package not installed, will try as external\n }\n }\n\n // 2. Try as npm package\n try {\n const mod = (await import(name)) as Record<string, unknown>;\n const compressor = extractCompressor(mod, name);\n\n if (compressor) {\n return {\n compressor,\n label: generateLabel(name),\n isBuiltIn: false,\n };\n }\n\n throw new Error(\n `Package '${name}' doesn't export a valid compressor function. ` +\n `Expected a function as default export, named export 'compressor', or ` +\n `named export '${toCamelCase(name)}'.`\n );\n } catch (error) {\n // If it's our error about invalid exports, rethrow\n if (\n error instanceof Error &&\n error.message.includes(\"doesn't export a valid compressor\")\n ) {\n throw error;\n }\n\n // 3. Try as local file path\n if (isLocalPath(name)) {\n try {\n const absolutePath = path.resolve(process.cwd(), name);\n const fileUrl = pathToFileURL(absolutePath).href;\n const mod = (await import(fileUrl)) as Record<string, unknown>;\n const compressor = extractCompressor(mod, name);\n\n if (compressor) {\n return {\n compressor,\n label: generateLabel(name),\n isBuiltIn: false,\n };\n }\n\n throw new Error(\n `Local file '${name}' doesn't export a valid compressor function. ` +\n `Expected a function as default export or named export 'compressor'.`\n );\n } catch (localError) {\n if (\n localError instanceof Error &&\n localError.message.includes(\n \"doesn't export a valid compressor\"\n )\n ) {\n throw localError;\n }\n throw new Error(\n `Could not load local compressor '${name}'. ` +\n `File not found or failed to import: ${localError instanceof Error ? localError.message : String(localError)}`\n );\n }\n }\n\n throw new Error(\n `Could not resolve compressor '${name}'. ` +\n `Is it installed? For local files, use a path starting with './' or '/'.`\n );\n }\n}\n\n/**\n * Determines whether a compressor name corresponds to a known built-in compressor.\n *\n * @param name - The compressor identifier (e.g., built-in package name or alias)\n * @returns `true` if the name corresponds to a known built-in compressor, `false` otherwise.\n */\nexport function isBuiltInCompressor(name: string): boolean {\n return name in KNOWN_COMPRESSOR_EXPORTS;\n}\n\n/**\n * Return the known exported symbol name for a built-in compressor package.\n *\n * @param name - The compressor package name (for example, `\"esbuild\"`, `\"terser\"`)\n * @returns The export name used by the built-in package, or `undefined` if the compressor is not a known built-in\n */\nexport function getKnownExportName(name: string): string | undefined {\n return KNOWN_COMPRESSOR_EXPORTS[name];\n}\n"],"mappings":";;;;;;;;;;;;;AAcA,MAAMA,2BAAmD;CACrD,SAAS;CACT,2BAA2B;CAC3B,KAAK;CACL,KAAK;CACL,QAAQ;CACR,aAAa;CACb,gBAAgB;CAChB,aAAa;CACb,KAAK;CACL,aAAa;CACb,SAAS;CACT,MAAM;CACN,cAAc;CACd,OAAO;CACP,QAAQ;CACR,iBAAiB;CACjB,YAAY;CACZ,UAAU;CACV,OAAO;CACP,MAAM;CACN,eAAe;CAClB;;;;;;;;;;AA+BD,SAAS,YAAY,MAAuB;AACxC,QACI,KAAK,WAAW,KAAK,IACrB,KAAK,WAAW,MAAM,IACtB,KAAK,WAAW,IAAI,IACpB,kBAAkB,KAAK,KAAK;;;;;;;;;AAWpC,SAAS,YAAY,MAAsB;AACvC,QAAO,KAAK,QAAQ,aAAa,GAAG,SAAS,KAAK,aAAa,CAAC;;;;;;;;;;;;;;;;AAiBpE,SAAS,kBACL,KACA,MACiB;CAEjB,MAAM,cAAc,yBAAyB;AAC7C,KAAI,eAAe,OAAO,IAAI,iBAAiB,WAC3C,QAAO,IAAI;CAOf,MAAM,YAAY,YAHD,KAAK,SAAS,IAAI,GAC5B,KAAK,MAAM,IAAI,CAAC,KAAK,IAAI,OAC1B,KACiC;AACvC,KAAI,OAAO,IAAI,eAAe,WAC1B,QAAO,IAAI;AAIf,KAAI,OAAO,IAAI,eAAe,WAC1B,QAAO,IAAI;AAIf,KAAI,OAAO,IAAI,YAAY,WACvB,QAAO,IAAI;AAIf,MAAK,MAAM,SAAS,OAAO,OAAO,IAAI,CAClC,KAAI,OAAO,UAAU,WACjB,QAAO;AAIf,QAAO;;;;;;;;AASX,SAAS,cAAc,MAAsB;AACzC,KAAI,YAAY,KAAK,CAEjB,QAAO,KAAK,SAAS,KAAK,CAAC,QAAQ,sBAAsB,GAAG;AAGhE,QAAO;;;;;;;;;AAUX,eAAsB,kBAClB,MAC6B;AAI7B,KAHgB,QAAQ,yBAIpB,KAAI;EAKA,MAAM,aAAa,kBAJN,MAAM,OAAO,gBAAgB,SAIA,KAAK;AAE/C,MAAI,WACA,QAAO;GACH;GACA,OAAO;GACP,WAAW;GACd;SAED;AAMZ,KAAI;EAEA,MAAM,aAAa,kBADN,MAAM,OAAO,OACgB,KAAK;AAE/C,MAAI,WACA,QAAO;GACH;GACA,OAAO,cAAc,KAAK;GAC1B,WAAW;GACd;AAGL,QAAM,IAAI,MACN,YAAY,KAAK,mIAEI,YAAY,KAAK,CAAC,IAC1C;UACI,OAAO;AAEZ,MACI,iBAAiB,SACjB,MAAM,QAAQ,SAAS,oCAAoC,CAE3D,OAAM;AAIV,MAAI,YAAY,KAAK,CACjB,KAAI;GAIA,MAAM,aAAa,kBADN,MAAM,OADH,cADK,KAAK,QAAQ,QAAQ,KAAK,EAAE,KAAK,CACX,CAAC,OAEF,KAAK;AAE/C,OAAI,WACA,QAAO;IACH;IACA,OAAO,cAAc,KAAK;IAC1B,WAAW;IACd;AAGL,SAAM,IAAI,MACN,eAAe,KAAK,mHAEvB;WACI,YAAY;AACjB,OACI,sBAAsB,SACtB,WAAW,QAAQ,SACf,oCACH,CAED,OAAM;AAEV,SAAM,IAAI,MACN,oCAAoC,KAAK,yCACE,sBAAsB,QAAQ,WAAW,UAAU,OAAO,WAAW,GACnH;;AAIT,QAAM,IAAI,MACN,iCAAiC,KAAK,4EAEzC;;;;;;;;;AAUT,SAAgB,oBAAoB,MAAuB;AACvD,QAAO,QAAQ;;;;;;;;AASnB,SAAgB,mBAAmB,MAAkC;AACjE,QAAO,yBAAyB"}
1
+ {"version":3,"file":"compressor-resolver.js","names":[],"sources":["../src/compressor-resolver.ts"],"sourcesContent":["/*!\n * node-minify\n * Copyright (c) 2011-2026 Rodolphe Stoclin\n * MIT Licensed\n */\n\nimport path from \"node:path\";\nimport { pathToFileURL } from \"node:url\";\nimport type { Compressor } from \"@node-minify/types\";\n\n/**\n * Known compressor exports for built-in @node-minify packages.\n * Maps package name to the exported function name.\n */\nconst KNOWN_COMPRESSOR_EXPORTS: Record<string, string> = {\n esbuild: \"esbuild\",\n \"google-closure-compiler\": \"gcc\",\n oxc: \"oxc\",\n swc: \"swc\",\n terser: \"terser\",\n \"uglify-js\": \"uglifyJs\",\n \"babel-minify\": \"babelMinify\",\n \"uglify-es\": \"uglifyEs\",\n yui: \"yui\",\n \"clean-css\": \"cleanCss\",\n cssnano: \"cssnano\",\n csso: \"csso\",\n lightningcss: \"lightningCss\",\n crass: \"crass\",\n sqwish: \"sqwish\",\n \"html-minifier\": \"htmlMinifier\",\n \"minify-html\": \"minifyHtml\",\n jsonminify: \"jsonMinify\",\n imagemin: \"imagemin\",\n sharp: \"sharp\",\n svgo: \"svgo\",\n \"no-compress\": \"noCompress\",\n};\n\n/**\n * Result from resolving a compressor.\n */\nexport type CompressorResolution = {\n /**\n * The resolved compressor function.\n */\n compressor: Compressor;\n\n /**\n * Label for the compressor (used in logs/reports).\n */\n label: string;\n\n /**\n * Whether this is a built-in @node-minify compressor.\n */\n isBuiltIn: boolean;\n};\n\n/**\n * Determines whether a string represents a local file path.\n *\n * @param name - The path string to test\n * @returns `true` if `name` appears to be a local file path, `false` otherwise\n */\nexport function isLocalPath(name: string): boolean {\n return (\n name.startsWith(\"./\") ||\n name.startsWith(\"../\") ||\n name.startsWith(\"/\") ||\n /^[a-zA-Z]:[/\\\\]/.test(name)\n );\n}\n\n/**\n * Converts a package name to camelCase for export lookup.\n *\n * @param name - The package or file name to convert\n * @returns The input `name` converted to camelCase\n */\nfunction toCamelCase(name: string): string {\n return name.replace(/[-_](.)/g, (_, char) => char.toUpperCase());\n}\n\n/**\n * Resolve a compressor function exported by a loaded module.\n *\n * @param mod - The imported module object to inspect for exports\n * @param name - The package or file name used to derive known and camelCase export names\n * @returns The resolved `Compressor` function if found, or `null` if no suitable function export exists\n */\nfunction extractCompressor(\n mod: Record<string, unknown>,\n name: string\n): Compressor | null {\n const knownExport = KNOWN_COMPRESSOR_EXPORTS[name];\n if (knownExport && typeof mod[knownExport] === \"function\") {\n return mod[knownExport] as Compressor;\n }\n\n const baseName = name.includes(\"/\")\n ? (name.split(\"/\").pop() ?? name)\n : name;\n const camelName = toCamelCase(baseName);\n if (typeof mod[camelName] === \"function\") {\n return mod[camelName] as Compressor;\n }\n\n if (typeof mod.compressor === \"function\") {\n return mod.compressor as Compressor;\n }\n\n if (typeof mod.default === \"function\") {\n return mod.default as Compressor;\n }\n\n for (const value of Object.values(mod)) {\n if (typeof value === \"function\") {\n return value as Compressor;\n }\n }\n\n return null;\n}\n\n/**\n * Create a display label from a compressor package name or a local file path.\n *\n * @param name - Compressor npm package name or a local file path\n * @returns The package name for npm compressors, or the local file's basename without extension\n */\nfunction generateLabel(name: string): string {\n if (isLocalPath(name)) {\n return path.basename(name).replace(/\\.(js|ts|mjs|cjs)$/, \"\");\n }\n return name;\n}\n\n/**\n * Try to resolve a compressor from a built-in @node-minify package.\n *\n * @param name - The compressor name (e.g., \"terser\", \"esbuild\")\n * @returns The resolved CompressorResolution if found, or `null` if not installed/available\n */\nexport async function tryResolveBuiltIn(\n name: string\n): Promise<CompressorResolution | null> {\n if (!(name in KNOWN_COMPRESSOR_EXPORTS)) {\n return null;\n }\n\n try {\n const mod = (await import(`@node-minify/${name}`)) as Record<\n string,\n unknown\n >;\n const compressor = extractCompressor(mod, name);\n\n if (compressor) {\n return {\n compressor,\n label: name,\n isBuiltIn: true,\n };\n }\n } catch {\n // Built-in package not installed\n }\n\n return null;\n}\n\n/**\n * Try to resolve a compressor from an npm package.\n *\n * @param name - The npm package name\n * @returns The resolved CompressorResolution if found, or `null` if not resolvable\n * @throws Error if the package is found but doesn't export a valid compressor\n */\nexport async function tryResolveNpmPackage(\n name: string\n): Promise<CompressorResolution | null> {\n try {\n const mod = (await import(name)) as Record<string, unknown>;\n const compressor = extractCompressor(mod, name);\n\n if (compressor) {\n return {\n compressor,\n label: generateLabel(name),\n isBuiltIn: false,\n };\n }\n\n throw new Error(\n `Package '${name}' doesn't export a valid compressor function. ` +\n `Expected a function as default export, named export 'compressor', or ` +\n `named export '${toCamelCase(name)}'.`\n );\n } catch (error) {\n if (\n error instanceof Error &&\n error.message.includes(\"doesn't export a valid compressor\")\n ) {\n throw error;\n }\n return null;\n }\n}\n\n/**\n * Try to resolve a compressor from a local file path.\n *\n * @param name - The local file path (e.g., \"./my-compressor.js\")\n * @returns The resolved CompressorResolution if found, or `null` if not a local path\n * @throws Error if the file is found but doesn't export a valid compressor\n */\nexport async function tryResolveLocalFile(\n name: string\n): Promise<CompressorResolution | null> {\n if (!isLocalPath(name)) {\n return null;\n }\n\n try {\n const absolutePath = path.resolve(process.cwd(), name);\n const fileUrl = pathToFileURL(absolutePath).href;\n const mod = (await import(fileUrl)) as Record<string, unknown>;\n const compressor = extractCompressor(mod, name);\n\n if (compressor) {\n return {\n compressor,\n label: generateLabel(name),\n isBuiltIn: false,\n };\n }\n\n throw new Error(\n `Local file '${name}' doesn't export a valid compressor function. ` +\n `Expected a function as default export or named export 'compressor'.`\n );\n } catch (error) {\n if (\n error instanceof Error &&\n error.message.includes(\"doesn't export a valid compressor\")\n ) {\n throw error;\n }\n throw new Error(\n `Could not load local compressor '${name}'. ` +\n `File not found or failed to import: ${error instanceof Error ? error.message : String(error)}`\n );\n }\n}\n\n/**\n * Resolve a compressor by name from a built-in @node-minify package, an installed npm package, or a local file path.\n *\n * @param name - Compressor identifier: a built-in name (e.g., \"terser\"), an npm package name, or a local path (e.g., \"./compressor.js\")\n * @returns The resolved CompressorResolution containing the compressor function, a display `label`, and `isBuiltIn` flag\n * @throws Error if the compressor cannot be found or the module does not export a valid compressor function\n */\nexport async function resolveCompressor(\n name: string\n): Promise<CompressorResolution> {\n // 1. Try built-in @node-minify package\n const builtIn = await tryResolveBuiltIn(name);\n if (builtIn) {\n return builtIn;\n }\n\n // 2. Try as npm package\n const npmPackage = await tryResolveNpmPackage(name);\n if (npmPackage) {\n return npmPackage;\n }\n\n // 3. Try as local file path (throws if file exists but has invalid exports)\n if (isLocalPath(name)) {\n const localFile = await tryResolveLocalFile(name);\n if (localFile) {\n return localFile;\n }\n // tryResolveLocalFile throws for local paths that can't be loaded,\n // so reaching here means it returned null (which shouldn't happen\n // after the isLocalPath guard, but we handle it defensively)\n }\n\n throw new Error(\n `Could not resolve compressor '${name}'. ` +\n `Is it installed? For local files, use a path starting with './' or '/'.`\n );\n}\n\n/**\n * Determines whether a compressor name corresponds to a known built-in compressor.\n *\n * @param name - The compressor identifier (e.g., built-in package name or alias)\n * @returns `true` if the name corresponds to a known built-in compressor, `false` otherwise.\n */\nexport function isBuiltInCompressor(name: string): boolean {\n return name in KNOWN_COMPRESSOR_EXPORTS;\n}\n\n/**\n * Return the known exported symbol name for a built-in compressor package.\n *\n * @param name - The compressor package name (for example, `\"esbuild\"`, `\"terser\"`)\n * @returns The export name used by the built-in package, or `undefined` if the compressor is not a known built-in\n */\nexport function getKnownExportName(name: string): string | undefined {\n return KNOWN_COMPRESSOR_EXPORTS[name];\n}\n"],"mappings":"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"}
@@ -1,4 +1,4 @@
1
- import { t as FileOperationError } from "./error-Ctspysdk.js";
1
+ import { t as FileOperationError } from "./error-CUgKxOvI.js";
2
2
  import { existsSync, unlinkSync } from "node:fs";
3
3
 
4
4
  //#region src/deleteFile.ts
@@ -29,4 +29,4 @@ var ValidationError = class extends Error {
29
29
 
30
30
  //#endregion
31
31
  export { ValidationError as n, FileOperationError as t };
32
- //# sourceMappingURL=error-Ctspysdk.js.map
32
+ //# sourceMappingURL=error-CUgKxOvI.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"error-Ctspysdk.js","names":[],"sources":["../src/error.ts"],"sourcesContent":["/*!\n * node-minify\n * Copyright (c) 2011-2026 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 override cause?: Error;\n\n constructor(operation: string, path: string, originalError?: Error) {\n super(\n `Failed to ${operation} file ${path}: ${originalError?.message || \"\"}`,\n originalError ? { cause: originalError } : undefined\n );\n this.name = \"FileOperationError\";\n // For older runtimes that don't support the cause option\n if (originalError && !this.cause) {\n this.cause = originalError;\n }\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,AAAS;CAET,YAAY,WAAmB,MAAc,eAAuB;AAChE,QACI,aAAa,UAAU,QAAQ,KAAK,IAAI,eAAe,WAAW,MAClE,gBAAgB,EAAE,OAAO,eAAe,GAAG,OAC9C;AACD,OAAK,OAAO;AAEZ,MAAI,iBAAiB,CAAC,KAAK,MACvB,MAAK,QAAQ;;;;;;;AASzB,IAAa,kBAAb,cAAqC,MAAM;CACvC,YAAY,SAAiB;AACzB,QAAM,QAAQ;AACd,OAAK,OAAO"}
1
+ {"version":3,"file":"error-CUgKxOvI.js","names":[],"sources":["../src/error.ts"],"sourcesContent":["/*!\n * node-minify\n * Copyright (c) 2011-2026 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 override cause?: Error;\n\n constructor(operation: string, path: string, originalError?: Error) {\n super(\n `Failed to ${operation} file ${path}: ${originalError?.message || \"\"}`,\n originalError ? { cause: originalError } : undefined\n );\n this.name = \"FileOperationError\";\n // For older runtimes that don't support the cause option\n if (originalError && !this.cause) {\n this.cause = originalError;\n }\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,AAAS;CAET,YAAY,WAAmB,MAAc,eAAuB;AAChE,QACI,aAAa,UAAU,QAAQ,KAAK,IAAI,eAAe,WAAW,MAClE,gBAAgB,EAAE,OAAO,eAAe,GAAG,OAC9C;AACD,OAAK,OAAO;AAEZ,MAAI,iBAAiB,CAAC,KAAK,MACvB,MAAK,QAAQ;;;;;;;AASzB,IAAa,kBAAb,cAAqC,MAAM;CACvC,YAAY,SAAiB;AACzB,QAAM,QAAQ;AACd,OAAK,OAAO"}
package/dist/error.js CHANGED
@@ -1,3 +1,3 @@
1
- import { n as ValidationError, t as FileOperationError } from "./error-Ctspysdk.js";
1
+ import { n as ValidationError, t as FileOperationError } from "./error-CUgKxOvI.js";
2
2
 
3
3
  export { FileOperationError, ValidationError };
@@ -0,0 +1,27 @@
1
+ //#region src/errors.d.ts
2
+ /*!
3
+ * node-minify
4
+ * Copyright (c) 2011-2026 Rodolphe Stoclin
5
+ * MIT Licensed
6
+ */
7
+ /**
8
+ * Wraps an error thrown during minification with a consistent, descriptive message.
9
+ *
10
+ * @param compressorName - The name of the compressor that failed
11
+ * @param error - The original error (unknown type for proper catch handling)
12
+ * @returns A new Error with a standardized message format
13
+ */
14
+ declare function wrapMinificationError(compressorName: string, error: unknown): Error;
15
+ /**
16
+ * Validates that a minification result contains valid output.
17
+ *
18
+ * @param result - The result object to validate
19
+ * @param compressorName - The name of the compressor (for error messages)
20
+ * @throws Error if result is falsy or result.code is not a string
21
+ */
22
+ declare function validateMinifyResult(result: unknown, compressorName: string): asserts result is {
23
+ code: string;
24
+ };
25
+ //#endregion
26
+ export { validateMinifyResult, wrapMinificationError };
27
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.ts","names":[],"sources":["../src/errors.ts"],"sourcesContent":[],"mappings":";;AAaA;AAkBA;;;;;;;;;;iBAlBgB,qBAAA,0CAGb;;;;;;;;iBAea,oBAAA"}
package/dist/errors.js ADDED
@@ -0,0 +1,32 @@
1
+ //#region src/errors.ts
2
+ /*!
3
+ * node-minify
4
+ * Copyright (c) 2011-2026 Rodolphe Stoclin
5
+ * MIT Licensed
6
+ */
7
+ /**
8
+ * Wraps an error thrown during minification with a consistent, descriptive message.
9
+ *
10
+ * @param compressorName - The name of the compressor that failed
11
+ * @param error - The original error (unknown type for proper catch handling)
12
+ * @returns A new Error with a standardized message format
13
+ */
14
+ function wrapMinificationError(compressorName, error) {
15
+ const message = error instanceof Error ? error.message : String(error);
16
+ const cause = error instanceof Error ? error : void 0;
17
+ return new Error(`${compressorName} minification failed: ${message}`, { cause });
18
+ }
19
+ /**
20
+ * Validates that a minification result contains valid output.
21
+ *
22
+ * @param result - The result object to validate
23
+ * @param compressorName - The name of the compressor (for error messages)
24
+ * @throws Error if result is falsy or result.code is not a string
25
+ */
26
+ function validateMinifyResult(result, compressorName) {
27
+ if (!result || typeof result !== "object" || !("code" in result) || typeof result.code !== "string") throw new Error(`${compressorName} failed: empty or invalid result`);
28
+ }
29
+
30
+ //#endregion
31
+ export { validateMinifyResult, wrapMinificationError };
32
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.js","names":[],"sources":["../src/errors.ts"],"sourcesContent":["/*!\n * node-minify\n * Copyright (c) 2011-2026 Rodolphe Stoclin\n * MIT Licensed\n */\n\n/**\n * Wraps an error thrown during minification with a consistent, descriptive message.\n *\n * @param compressorName - The name of the compressor that failed\n * @param error - The original error (unknown type for proper catch handling)\n * @returns A new Error with a standardized message format\n */\nexport function wrapMinificationError(\n compressorName: string,\n error: unknown\n): Error {\n const message = error instanceof Error ? error.message : String(error);\n const cause = error instanceof Error ? error : undefined;\n return new Error(`${compressorName} minification failed: ${message}`, {\n cause,\n });\n}\n\n/**\n * Validates that a minification result contains valid output.\n *\n * @param result - The result object to validate\n * @param compressorName - The name of the compressor (for error messages)\n * @throws Error if result is falsy or result.code is not a string\n */\nexport function validateMinifyResult(\n result: unknown,\n compressorName: string\n): asserts result is { code: string } {\n if (\n !result ||\n typeof result !== \"object\" ||\n !(\"code\" in result) ||\n typeof (result as { code: unknown }).code !== \"string\"\n ) {\n throw new Error(`${compressorName} failed: empty or invalid result`);\n }\n}\n"],"mappings":";;;;;;;;;;;;;AAaA,SAAgB,sBACZ,gBACA,OACK;CACL,MAAM,UAAU,iBAAiB,QAAQ,MAAM,UAAU,OAAO,MAAM;CACtE,MAAM,QAAQ,iBAAiB,QAAQ,QAAQ;AAC/C,QAAO,IAAI,MAAM,GAAG,eAAe,wBAAwB,WAAW,EAClE,OACH,CAAC;;;;;;;;;AAUN,SAAgB,qBACZ,QACA,gBACkC;AAClC,KACI,CAAC,UACD,OAAO,WAAW,YAClB,EAAE,UAAU,WACZ,OAAQ,OAA6B,SAAS,SAE9C,OAAM,IAAI,MAAM,GAAG,eAAe,kCAAkC"}
@@ -1,5 +1,5 @@
1
- import { t as FileOperationError } from "./error-Ctspysdk.js";
2
- import { t as isValidFile } from "./isValidFile-BW5AgBWb.js";
1
+ import { t as FileOperationError } from "./error-CUgKxOvI.js";
2
+ import { t as isValidFile } from "./isValidFile-COstpeyW.js";
3
3
  import { existsSync, readFileSync } from "node:fs";
4
4
  import { readFile } from "node:fs/promises";
5
5
 
@@ -1 +1 @@
1
- {"version":3,"file":"getContentFromFiles.js","names":["error: unknown"],"sources":["../src/getContentFromFiles.ts"],"sourcesContent":["/*!\n * node-minify\n * Copyright (c) 2011-2026 Rodolphe Stoclin\n * MIT Licensed\n */\n\nimport { existsSync, readFileSync } from \"node:fs\";\nimport { readFile } from \"node:fs/promises\";\nimport { FileOperationError } from \"./error.ts\";\nimport { isValidFile } from \"./isValidFile.ts\";\n\n/**\n * Read content from a single file with error handling.\n * @param path Path to the file\n * @returns Content of the file\n * @throws {FileOperationError} If file doesn't exist or reading fails\n */\nfunction readFileContent(path: string): string {\n try {\n if (!existsSync(path)) {\n throw new Error(\"File does not exist\");\n }\n if (!isValidFile(path)) {\n throw new Error(\"Path is not a valid file\");\n }\n return readFileSync(path, \"utf8\");\n } catch (error) {\n throw new FileOperationError(\"read\", path, error as Error);\n }\n}\n\n/**\n * Read the UTF-8 content of a single file.\n *\n * @param path - Filesystem path to the file\n * @returns The file content as a string\n * @throws FileOperationError if the file does not exist, the path is a directory, or reading the file fails\n */\nasync function readFileContentAsync(path: string): Promise<string> {\n try {\n return await readFile(path, \"utf8\");\n } catch (error) {\n throw new FileOperationError(\"read\", path, error as Error);\n }\n}\n\n/**\n * Concatenate all input files and get the data.\n * @param input Single file path or array of file paths\n * @returns Concatenated content of all files\n * @throws {FileOperationError} If any file operation fails\n * @example\n * getContentFromFiles('file.js')\n * getContentFromFiles(['file1.js', 'file2.js'])\n */\nexport function getContentFromFiles(input: string | string[]): string {\n try {\n if (!input) {\n throw new Error(\"Input must be a string or array of strings\");\n }\n\n if (!Array.isArray(input)) {\n return readFileContent(input);\n }\n\n if (input.length === 0) {\n return \"\";\n }\n\n return input.map(readFileContent).join(\"\\n\");\n } catch (error: unknown) {\n if (error instanceof FileOperationError) {\n throw error;\n }\n throw new Error(\n `Failed to process input files: ${error instanceof Error ? error.message : String(error)}`\n );\n }\n}\n\n/**\n * Concatenate contents of one or more files asynchronously.\n *\n * @param input - A file path or an array of file paths to read\n * @returns The files' contents joined with newline characters\n * @throws {FileOperationError} If an underlying file operation fails for any path\n * @throws {Error} If `input` is missing or processing of the provided input fails\n */\nexport async function getContentFromFilesAsync(\n input: string | string[]\n): Promise<string> {\n try {\n if (!input) {\n throw new Error(\"Input must be a string or array of strings\");\n }\n\n if (!Array.isArray(input)) {\n return await readFileContentAsync(input);\n }\n\n if (input.length === 0) {\n return \"\";\n }\n\n // Read files in parallel\n const contents = await Promise.all(input.map(readFileContentAsync));\n return contents.join(\"\\n\");\n } catch (error: unknown) {\n if (error instanceof FileOperationError) {\n throw error;\n }\n throw new Error(\n `Failed to process input files: ${error instanceof Error ? error.message : String(error)}`\n );\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAiBA,SAAS,gBAAgB,MAAsB;AAC3C,KAAI;AACA,MAAI,CAAC,WAAW,KAAK,CACjB,OAAM,IAAI,MAAM,sBAAsB;AAE1C,MAAI,CAAC,YAAY,KAAK,CAClB,OAAM,IAAI,MAAM,2BAA2B;AAE/C,SAAO,aAAa,MAAM,OAAO;UAC5B,OAAO;AACZ,QAAM,IAAI,mBAAmB,QAAQ,MAAM,MAAe;;;;;;;;;;AAWlE,eAAe,qBAAqB,MAA+B;AAC/D,KAAI;AACA,SAAO,MAAM,SAAS,MAAM,OAAO;UAC9B,OAAO;AACZ,QAAM,IAAI,mBAAmB,QAAQ,MAAM,MAAe;;;;;;;;;;;;AAalE,SAAgB,oBAAoB,OAAkC;AAClE,KAAI;AACA,MAAI,CAAC,MACD,OAAM,IAAI,MAAM,6CAA6C;AAGjE,MAAI,CAAC,MAAM,QAAQ,MAAM,CACrB,QAAO,gBAAgB,MAAM;AAGjC,MAAI,MAAM,WAAW,EACjB,QAAO;AAGX,SAAO,MAAM,IAAI,gBAAgB,CAAC,KAAK,KAAK;UACvCA,OAAgB;AACrB,MAAI,iBAAiB,mBACjB,OAAM;AAEV,QAAM,IAAI,MACN,kCAAkC,iBAAiB,QAAQ,MAAM,UAAU,OAAO,MAAM,GAC3F;;;;;;;;;;;AAYT,eAAsB,yBAClB,OACe;AACf,KAAI;AACA,MAAI,CAAC,MACD,OAAM,IAAI,MAAM,6CAA6C;AAGjE,MAAI,CAAC,MAAM,QAAQ,MAAM,CACrB,QAAO,MAAM,qBAAqB,MAAM;AAG5C,MAAI,MAAM,WAAW,EACjB,QAAO;AAKX,UADiB,MAAM,QAAQ,IAAI,MAAM,IAAI,qBAAqB,CAAC,EACnD,KAAK,KAAK;UACrBA,OAAgB;AACrB,MAAI,iBAAiB,mBACjB,OAAM;AAEV,QAAM,IAAI,MACN,kCAAkC,iBAAiB,QAAQ,MAAM,UAAU,OAAO,MAAM,GAC3F"}
1
+ {"version":3,"file":"getContentFromFiles.js","names":[],"sources":["../src/getContentFromFiles.ts"],"sourcesContent":["/*!\n * node-minify\n * Copyright (c) 2011-2026 Rodolphe Stoclin\n * MIT Licensed\n */\n\nimport { existsSync, readFileSync } from \"node:fs\";\nimport { readFile } from \"node:fs/promises\";\nimport { FileOperationError } from \"./error.ts\";\nimport { isValidFile } from \"./isValidFile.ts\";\n\n/**\n * Read content from a single file with error handling.\n * @param path Path to the file\n * @returns Content of the file\n * @throws {FileOperationError} If file doesn't exist or reading fails\n */\nfunction readFileContent(path: string): string {\n try {\n if (!existsSync(path)) {\n throw new Error(\"File does not exist\");\n }\n if (!isValidFile(path)) {\n throw new Error(\"Path is not a valid file\");\n }\n return readFileSync(path, \"utf8\");\n } catch (error) {\n throw new FileOperationError(\"read\", path, error as Error);\n }\n}\n\n/**\n * Read the UTF-8 content of a single file.\n *\n * @param path - Filesystem path to the file\n * @returns The file content as a string\n * @throws FileOperationError if the file does not exist, the path is a directory, or reading the file fails\n */\nasync function readFileContentAsync(path: string): Promise<string> {\n try {\n return await readFile(path, \"utf8\");\n } catch (error) {\n throw new FileOperationError(\"read\", path, error as Error);\n }\n}\n\n/**\n * Concatenate all input files and get the data.\n * @param input Single file path or array of file paths\n * @returns Concatenated content of all files\n * @throws {FileOperationError} If any file operation fails\n * @example\n * getContentFromFiles('file.js')\n * getContentFromFiles(['file1.js', 'file2.js'])\n */\nexport function getContentFromFiles(input: string | string[]): string {\n try {\n if (!input) {\n throw new Error(\"Input must be a string or array of strings\");\n }\n\n if (!Array.isArray(input)) {\n return readFileContent(input);\n }\n\n if (input.length === 0) {\n return \"\";\n }\n\n return input.map(readFileContent).join(\"\\n\");\n } catch (error: unknown) {\n if (error instanceof FileOperationError) {\n throw error;\n }\n throw new Error(\n `Failed to process input files: ${error instanceof Error ? error.message : String(error)}`\n );\n }\n}\n\n/**\n * Concatenate contents of one or more files asynchronously.\n *\n * @param input - A file path or an array of file paths to read\n * @returns The files' contents joined with newline characters\n * @throws {FileOperationError} If an underlying file operation fails for any path\n * @throws {Error} If `input` is missing or processing of the provided input fails\n */\nexport async function getContentFromFilesAsync(\n input: string | string[]\n): Promise<string> {\n try {\n if (!input) {\n throw new Error(\"Input must be a string or array of strings\");\n }\n\n if (!Array.isArray(input)) {\n return await readFileContentAsync(input);\n }\n\n if (input.length === 0) {\n return \"\";\n }\n\n // Read files in parallel\n const contents = await Promise.all(input.map(readFileContentAsync));\n return contents.join(\"\\n\");\n } catch (error: unknown) {\n if (error instanceof FileOperationError) {\n throw error;\n }\n throw new Error(\n `Failed to process input files: ${error instanceof Error ? error.message : String(error)}`\n );\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAiBA,SAAS,gBAAgB,MAAsB;AAC3C,KAAI;AACA,MAAI,CAAC,WAAW,KAAK,CACjB,OAAM,IAAI,MAAM,sBAAsB;AAE1C,MAAI,CAAC,YAAY,KAAK,CAClB,OAAM,IAAI,MAAM,2BAA2B;AAE/C,SAAO,aAAa,MAAM,OAAO;UAC5B,OAAO;AACZ,QAAM,IAAI,mBAAmB,QAAQ,MAAM,MAAe;;;;;;;;;;AAWlE,eAAe,qBAAqB,MAA+B;AAC/D,KAAI;AACA,SAAO,MAAM,SAAS,MAAM,OAAO;UAC9B,OAAO;AACZ,QAAM,IAAI,mBAAmB,QAAQ,MAAM,MAAe;;;;;;;;;;;;AAalE,SAAgB,oBAAoB,OAAkC;AAClE,KAAI;AACA,MAAI,CAAC,MACD,OAAM,IAAI,MAAM,6CAA6C;AAGjE,MAAI,CAAC,MAAM,QAAQ,MAAM,CACrB,QAAO,gBAAgB,MAAM;AAGjC,MAAI,MAAM,WAAW,EACjB,QAAO;AAGX,SAAO,MAAM,IAAI,gBAAgB,CAAC,KAAK,KAAK;UACvC,OAAgB;AACrB,MAAI,iBAAiB,mBACjB,OAAM;AAEV,QAAM,IAAI,MACN,kCAAkC,iBAAiB,QAAQ,MAAM,UAAU,OAAO,MAAM,GAC3F;;;;;;;;;;;AAYT,eAAsB,yBAClB,OACe;AACf,KAAI;AACA,MAAI,CAAC,MACD,OAAM,IAAI,MAAM,6CAA6C;AAGjE,MAAI,CAAC,MAAM,QAAQ,MAAM,CACrB,QAAO,MAAM,qBAAqB,MAAM;AAG5C,MAAI,MAAM,WAAW,EACjB,QAAO;AAKX,UADiB,MAAM,QAAQ,IAAI,MAAM,IAAI,qBAAqB,CAAC,EACnD,KAAK,KAAK;UACrB,OAAgB;AACrB,MAAI,iBAAiB,mBACjB,OAAM;AAEV,QAAM,IAAI,MACN,kCAAkC,iBAAiB,QAAQ,MAAM,UAAU,OAAO,MAAM,GAC3F"}
@@ -4,7 +4,23 @@
4
4
  * Copyright (c) 2011-2026 Rodolphe Stoclin
5
5
  * MIT Licensed
6
6
  */
7
+ /**
8
+ * Get the brotli-compressed size of a file as a human-readable string.
9
+ *
10
+ * @param file - Path to the file
11
+ * @returns The brotli-compressed size formatted for display (for example, "1.5 kB")
12
+ */
7
13
  declare function getFilesizeBrotliInBytes(file: string): Promise<string>;
14
+ /**
15
+ * Get the brotli-compressed file size in bytes.
16
+ *
17
+ * @param file - Path to the file
18
+ * @returns Brotli-compressed file size in bytes
19
+ * @example
20
+ * const bytes = await getFilesizeBrotliRaw('bundle.js')
21
+ * console.log(bytes) // 12583
22
+ */
23
+ declare function getFilesizeBrotliRaw(file: string): Promise<number>;
8
24
  //#endregion
9
- export { getFilesizeBrotliInBytes };
25
+ export { getFilesizeBrotliInBytes, getFilesizeBrotliRaw };
10
26
  //# sourceMappingURL=getFilesizeBrotliInBytes.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"getFilesizeBrotliInBytes.d.ts","names":[],"sources":["../src/getFilesizeBrotliInBytes.ts"],"sourcesContent":[],"mappings":";;AAgBA;;;;iBAAsB,wBAAA,gBAAwC"}
1
+ {"version":3,"file":"getFilesizeBrotliInBytes.d.ts","names":[],"sources":["../src/getFilesizeBrotliInBytes.ts"],"sourcesContent":[],"mappings":";;AAyDA;AAyBA;;;;;;;;;iBAzBsB,wBAAA,gBAAwC;;;;;;;;;;iBAyBxC,oBAAA,gBAAoC"}
@@ -1,5 +1,5 @@
1
- import { t as FileOperationError } from "./error-Ctspysdk.js";
2
- import { t as isValidFile } from "./isValidFile-BW5AgBWb.js";
1
+ import { t as FileOperationError } from "./error-CUgKxOvI.js";
2
+ import { t as isValidFile } from "./isValidFile-COstpeyW.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"],"sourcesContent":[],"mappings":";;AAgDA;AAwBA;;;;;;;;;iBAxBsB,yBAAA,gBAAyC;;;;;;;;;iBAwBzC,qBAAA,gBAAqC"}
@@ -1,7 +1,7 @@
1
- import { t as FileOperationError } from "./error-Ctspysdk.js";
2
- import { t as isValidFile } from "./isValidFile-BW5AgBWb.js";
1
+ import { t as FileOperationError } from "./error-CUgKxOvI.js";
2
+ import { t as isValidFile } from "./isValidFile-COstpeyW.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"}
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";
@@ -18,4 +19,4 @@ import { setFileNameMin } from "./setFileNameMin.js";
18
19
  import { setPublicFolder } from "./setPublicFolder.js";
19
20
  import { wildcards } from "./wildcards.js";
20
21
  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 };
22
+ export { type BuildArgsOptions, type CompressorResolution, buildArgs, compressSingleFile, deleteFile, ensureStringContent, getContentFromFiles, getContentFromFilesAsync, getFilesizeBrotliInBytes, getFilesizeBrotliRaw, getFilesizeGzippedInBytes, getFilesizeGzippedRaw, getFilesizeInBytes, getKnownExportName, 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,22 @@
1
1
  import { buildArgs, toBuildArgsOptions } from "./buildArgs.js";
2
- import { n as isValidFileAsync, t as isValidFile } from "./isValidFile-BW5AgBWb.js";
2
+ import { n as isValidFileAsync, t as isValidFile } from "./isValidFile-COstpeyW.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 { n as writeFileAsync, t as writeFile } from "./writeFile-mfUS3rMz.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
20
  import { wildcards } from "./wildcards.js";
20
21
 
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 };
22
+ export { buildArgs, compressSingleFile, deleteFile, ensureStringContent, getContentFromFiles, getContentFromFilesAsync, getFilesizeBrotliInBytes, getFilesizeBrotliRaw, getFilesizeGzippedInBytes, getFilesizeGzippedRaw, getFilesizeInBytes, getKnownExportName, isBuiltInCompressor, isImageFile, isLocalPath, isValidFile, isValidFileAsync, prettyBytes, readFile, readFileAsync, resetDeprecationWarnings, resolveCompressor, run, setFileNameMin, setPublicFolder, toBuildArgsOptions, tryResolveBuiltIn, tryResolveLocalFile, tryResolveNpmPackage, validateMinifyResult, warnDeprecation, wildcards, wrapMinificationError, writeFile, writeFileAsync };
@@ -1,4 +1,4 @@
1
- import { t as FileOperationError } from "./error-Ctspysdk.js";
1
+ import { t as FileOperationError } from "./error-CUgKxOvI.js";
2
2
  import { existsSync, lstatSync } from "node:fs";
3
3
  import { lstat } from "node:fs/promises";
4
4
 
@@ -43,4 +43,4 @@ async function isValidFileAsync(path) {
43
43
 
44
44
  //#endregion
45
45
  export { isValidFileAsync as n, isValidFile as t };
46
- //# sourceMappingURL=isValidFile-BW5AgBWb.js.map
46
+ //# sourceMappingURL=isValidFile-COstpeyW.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"isValidFile-COstpeyW.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,3 +1,3 @@
1
- import { n as isValidFileAsync, t as isValidFile } from "./isValidFile-BW5AgBWb.js";
1
+ import { n as isValidFileAsync, t as isValidFile } from "./isValidFile-COstpeyW.js";
2
2
 
3
3
  export { isValidFile, isValidFileAsync };
@@ -1,4 +1,4 @@
1
- import { n as ValidationError } from "./error-Ctspysdk.js";
1
+ import { n as ValidationError } from "./error-CUgKxOvI.js";
2
2
 
3
3
  //#region src/prettyBytes.ts
4
4
  /*!
package/dist/readFile.js CHANGED
@@ -1,4 +1,4 @@
1
- import { t as FileOperationError } from "./error-Ctspysdk.js";
1
+ import { t as FileOperationError } from "./error-CUgKxOvI.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,4 +1,4 @@
1
- import { n as CompressorOptions, r as MinifierOptions } from "./types-CzkB7gxg.js";
1
+ import { n as CompressorOptions, r as MinifierOptions } from "./types-CWBFD3au.js";
2
2
 
3
3
  //#region src/run.d.ts
4
4
 
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 { n as ValidationError } from "./error-CUgKxOvI.js";
2
+ import { n as writeFileAsync } from "./writeFile-mfUS3rMz.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
54
  if (Boolean(settings.content) || !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;
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 = Boolean(settings.content);\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 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,4 +1,4 @@
1
- import { n as ValidationError } from "./error-Ctspysdk.js";
1
+ import { n as ValidationError } from "./error-CUgKxOvI.js";
2
2
 
3
3
  //#region src/setFileNameMin.ts
4
4
  /*!
@@ -167,6 +167,14 @@ type Settings<TOptions extends CompressorOptions = CompressorOptions> = {
167
167
  * @default false
168
168
  */
169
169
  replaceInPlace?: boolean;
170
+
171
+ /**
172
+ * Allow empty output without throwing an error.
173
+ * When true, if minification results in empty content, the output file will not be written.
174
+ * Useful for CSS files containing only comments that get stripped.
175
+ * @default false
176
+ */
177
+ allowEmptyOutput?: boolean;
170
178
  };
171
179
  /**
172
180
  * Options passed to compressor functions internally.
@@ -193,4 +201,4 @@ type MinifierOptions<TOptions extends CompressorOptions = CompressorOptions> = {
193
201
  };
194
202
  //#endregion
195
203
  export { Settings as i, CompressorOptions as n, MinifierOptions as r, Compressor as t };
196
- //# sourceMappingURL=types-CzkB7gxg.d.ts.map
204
+ //# sourceMappingURL=types-CWBFD3au.d.ts.map
@@ -1 +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"}
1
+ {"version":3,"file":"types-CWBFD3au.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 * Allow empty output without throwing an error.\n * When true, if minification results in empty content, the output file will not be written.\n * Useful for CSS files containing only comments that get stripped.\n * @default false\n */\n allowEmptyOutput?: 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":";;;;;AAmOsC,KAtM1BE,gBAAAA,GAsM0B;;;;;;;;;oBA7LhBC;;;;;KAMVC,gBAAAA;;;;;;;;;;;;;;;;WAgBCD;;;;;;;;YAQCD;;;;;;KAOFG,iBAAAA,GAAoBC;;;;;;KAOpBC,4BAA4BF,oBAAoBA,4BACjDI,gBAAgBD,cAAcE,QAAQN;;;;KAKrCO,QAAAA;;;;;;;;;;;;;;;;;;KAmBAC,0BAA0BP,oBAAoBA;;;;cAI1CE,WAAWC;;;;;;;;;;;;;qBAaJL;;;;;;;;;;;;;;;;;;;;;;;;;;;;;YA6BTK;;;;;;;;;;;;;;;;;;;;;;;;SAwBHG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KAoCCF,iCACSJ,oBAAoBA;;;;YAK3BO,SAASJ;;;;;;;;qBAQAL,SAASA"}
@@ -1,6 +1,6 @@
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";
1
+ import { n as ValidationError, t as FileOperationError } from "./error-CUgKxOvI.js";
2
+ import { writeFileSync } from "node:fs";
3
+ import { writeFile } from "node:fs/promises";
4
4
 
5
5
  //#region src/writeFile.ts
6
6
  /*!
@@ -24,7 +24,6 @@ function writeFile$1({ file, content, index }) {
24
24
  try {
25
25
  const targetFile = resolveTargetFile(file, index);
26
26
  validateContent(content);
27
- if (isDirectory(targetFile)) throw new Error("Target path exists and is a directory");
28
27
  writeFileSync(targetFile, content, Buffer.isBuffer(content) ? void 0 : "utf8");
29
28
  return content;
30
29
  } catch (error) {
@@ -49,7 +48,6 @@ async function writeFileAsync({ file, content, index }) {
49
48
  try {
50
49
  const targetFile = resolveTargetFile(file, index);
51
50
  validateContent(content);
52
- if (await isDirectoryAsync(targetFile)) throw new Error("Target path exists and is a directory");
53
51
  await writeFile(targetFile, content, Buffer.isBuffer(content) ? void 0 : "utf8");
54
52
  return content;
55
53
  } catch (error) {
@@ -81,31 +79,6 @@ function validateContent(content) {
81
79
  if (!content) throw new ValidationError("No content provided");
82
80
  }
83
81
  /**
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
82
  * Normalize and rethrow errors that occur while attempting to write to one or more files.
110
83
  *
111
84
  * @param error - The original error thrown during the write attempt
@@ -120,4 +93,4 @@ function handleWriteError(error, file) {
120
93
 
121
94
  //#endregion
122
95
  export { writeFileAsync as n, writeFile$1 as t };
123
- //# sourceMappingURL=writeFile-DgV8EbFP.js.map
96
+ //# sourceMappingURL=writeFile-mfUS3rMz.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"writeFile-mfUS3rMz.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 { writeFileSync } from \"node:fs\";\nimport { 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 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 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 * 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,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,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;;;;;;;;;;AAYxD,SAAS,iBAAiB,OAAgB,MAAgC;AACtE,KAAI,iBAAiB,gBACjB,OAAM;AAEV,OAAM,IAAI,mBACN,YACA,OAAO,SAAS,WAAW,OAAO,kBAClC,MACH"}
@@ -1 +1 @@
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"}
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;AA8BpC;;;;;;;;;;;;;iBAlCgB,SAAA;;;;GAIb,2BAA2B;;;;;;;;;;;;;;iBA8BR,cAAA;;;;GAInB,kBAAkB,iBAAiB"}
package/dist/writeFile.js CHANGED
@@ -1,3 +1,3 @@
1
- import { n as writeFileAsync, t as writeFile } from "./writeFile-DgV8EbFP.js";
1
+ import { n as writeFileAsync, t as writeFile } from "./writeFile-mfUS3rMz.js";
2
2
 
3
3
  export { writeFile, writeFileAsync };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@node-minify/utils",
3
- "version": "10.3.0",
3
+ "version": "10.4.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.3.0"
59
+ "@node-minify/types": "10.4.0"
60
60
  }
61
61
  }
@@ -1 +0,0 @@
1
- {"version":3,"file":"isValidFile-BW5AgBWb.js","names":["error: unknown"],"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;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":"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"}