@node-minify/utils 10.4.0 → 10.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (67) hide show
  1. package/dist/buildArgs.d.ts +0 -1
  2. package/dist/buildArgs.d.ts.map +1 -1
  3. package/dist/buildArgs.js +1 -1
  4. package/dist/compressSingleFile.d.ts +1 -2
  5. package/dist/compressSingleFile.d.ts.map +1 -1
  6. package/dist/compressSingleFile.js +1 -1
  7. package/dist/compressSingleFile.js.map +1 -1
  8. package/dist/compressor-resolver.d.ts +1 -2
  9. package/dist/compressor-resolver.d.ts.map +1 -1
  10. package/dist/deleteFile.d.ts.map +1 -1
  11. package/dist/deleteFile.js +1 -1
  12. package/dist/deprecation.d.ts.map +1 -1
  13. package/dist/ensureStringContent.d.ts.map +1 -1
  14. package/dist/error.d.ts.map +1 -1
  15. package/dist/error.js +31 -2
  16. package/dist/error.js.map +1 -0
  17. package/dist/errors.d.ts.map +1 -1
  18. package/dist/getContentFromFiles.d.ts.map +1 -1
  19. package/dist/getContentFromFiles.js +2 -2
  20. package/dist/getFilesizeBrotliInBytes.d.ts.map +1 -1
  21. package/dist/getFilesizeBrotliInBytes.js +2 -2
  22. package/dist/getFilesizeGzippedInBytes.d.ts.map +1 -1
  23. package/dist/getFilesizeGzippedInBytes.js +2 -2
  24. package/dist/getFilesizeInBytes.d.ts.map +1 -1
  25. package/dist/index.d.ts +3 -2
  26. package/dist/index.js +5 -4
  27. package/dist/isImageFile.d.ts.map +1 -1
  28. package/dist/isValidFile.d.ts.map +1 -1
  29. package/dist/isValidFile.js +45 -2
  30. package/dist/isValidFile.js.map +1 -0
  31. package/dist/prettyBytes.d.ts.map +1 -1
  32. package/dist/prettyBytes.js +1 -1
  33. package/dist/readFile.d.ts.map +1 -1
  34. package/dist/readFile.js +1 -1
  35. package/dist/run.d.ts +1 -2
  36. package/dist/run.d.ts.map +1 -1
  37. package/dist/run.js +25 -24
  38. package/dist/run.js.map +1 -1
  39. package/dist/setFileNameMin.d.ts.map +1 -1
  40. package/dist/setFileNameMin.js +15 -9
  41. package/dist/setFileNameMin.js.map +1 -1
  42. package/dist/setPublicFolder.d.ts +1 -0
  43. package/dist/setPublicFolder.d.ts.map +1 -1
  44. package/dist/setPublicFolder.js +6 -1
  45. package/dist/setPublicFolder.js.map +1 -1
  46. package/dist/sourceMap.d.ts +27 -0
  47. package/dist/sourceMap.d.ts.map +1 -0
  48. package/dist/sourceMap.js +37 -0
  49. package/dist/sourceMap.js.map +1 -0
  50. package/dist/{types-CWBFD3au.d.ts → types-D10QejTN.d.ts} +1 -21
  51. package/dist/types-D10QejTN.d.ts.map +1 -0
  52. package/dist/types.d.ts.map +1 -1
  53. package/dist/wildcards.d.ts +21 -3
  54. package/dist/wildcards.d.ts.map +1 -1
  55. package/dist/wildcards.js +40 -16
  56. package/dist/wildcards.js.map +1 -1
  57. package/dist/writeFile.d.ts.map +1 -1
  58. package/dist/writeFile.js +95 -2
  59. package/dist/writeFile.js.map +1 -0
  60. package/package.json +2 -2
  61. package/dist/error-CUgKxOvI.js +0 -32
  62. package/dist/error-CUgKxOvI.js.map +0 -1
  63. package/dist/isValidFile-COstpeyW.js +0 -46
  64. package/dist/isValidFile-COstpeyW.js.map +0 -1
  65. package/dist/types-CWBFD3au.d.ts.map +0 -1
  66. package/dist/writeFile-mfUS3rMz.js +0 -96
  67. package/dist/writeFile-mfUS3rMz.js.map +0 -1
@@ -10,13 +10,18 @@ import path from "node:path";
10
10
  * Prepend the public folder to each file.
11
11
  * @param input Path to file(s)
12
12
  * @param publicFolder Path to the public folder
13
+ * @returns Object containing the updated input path(s), or an empty object if `publicFolder` is invalid
13
14
  */
14
15
  function setPublicFolder(input, publicFolder) {
15
16
  if (typeof publicFolder !== "string") return {};
16
17
  const normalizedPublicFolder = path.normalize(publicFolder);
18
+ const isAlreadyInPublicFolder = (filePath) => {
19
+ const relativePath = path.relative(normalizedPublicFolder, filePath);
20
+ return relativePath === "" || !relativePath.startsWith("..") && !path.isAbsolute(relativePath);
21
+ };
17
22
  const addPublicFolder = (item) => {
18
23
  const normalizedPath = path.normalize(item);
19
- return normalizedPath.includes(normalizedPublicFolder) ? normalizedPath : path.normalize(normalizedPublicFolder + item);
24
+ return isAlreadyInPublicFolder(normalizedPath) ? normalizedPath : path.join(normalizedPublicFolder, normalizedPath);
20
25
  };
21
26
  return { input: Array.isArray(input) ? input.map(addPublicFolder) : addPublicFolder(input) };
22
27
  }
@@ -1 +1 @@
1
- {"version":3,"file":"setPublicFolder.js","names":[],"sources":["../src/setPublicFolder.ts"],"sourcesContent":["/*!\n * node-minify\n * Copyright (c) 2011-2026 Rodolphe Stoclin\n * MIT Licensed\n */\n\nimport path from \"node:path\";\n\n/**\n * Prepend the public folder to each file.\n * @param input Path to file(s)\n * @param publicFolder Path to the public folder\n */\nexport function setPublicFolder(\n input: string | string[],\n publicFolder: string\n) {\n if (typeof publicFolder !== \"string\") {\n return {};\n }\n\n const normalizedPublicFolder = path.normalize(publicFolder);\n\n const addPublicFolder = (item: string) => {\n const normalizedPath = path.normalize(item);\n return normalizedPath.includes(normalizedPublicFolder)\n ? normalizedPath\n : path.normalize(normalizedPublicFolder + item);\n };\n\n return {\n input: Array.isArray(input)\n ? input.map(addPublicFolder)\n : addPublicFolder(input),\n };\n}\n"],"mappings":";;;;;;;;;;;;;AAaA,SAAgB,gBACZ,OACA,cACF;AACE,KAAI,OAAO,iBAAiB,SACxB,QAAO,EAAE;CAGb,MAAM,yBAAyB,KAAK,UAAU,aAAa;CAE3D,MAAM,mBAAmB,SAAiB;EACtC,MAAM,iBAAiB,KAAK,UAAU,KAAK;AAC3C,SAAO,eAAe,SAAS,uBAAuB,GAChD,iBACA,KAAK,UAAU,yBAAyB,KAAK;;AAGvD,QAAO,EACH,OAAO,MAAM,QAAQ,MAAM,GACrB,MAAM,IAAI,gBAAgB,GAC1B,gBAAgB,MAAM,EAC/B"}
1
+ {"version":3,"file":"setPublicFolder.js","names":[],"sources":["../src/setPublicFolder.ts"],"sourcesContent":["/*!\n * node-minify\n * Copyright (c) 2011-2026 Rodolphe Stoclin\n * MIT Licensed\n */\n\nimport path from \"node:path\";\n\n/**\n * Prepend the public folder to each file.\n * @param input Path to file(s)\n * @param publicFolder Path to the public folder\n * @returns Object containing the updated input path(s), or an empty object if `publicFolder` is invalid\n */\nexport function setPublicFolder(\n input: string | string[],\n publicFolder: string\n) {\n if (typeof publicFolder !== \"string\") {\n return {};\n }\n\n const normalizedPublicFolder = path.normalize(publicFolder);\n\n const isAlreadyInPublicFolder = (filePath: string) => {\n const relativePath = path.relative(normalizedPublicFolder, filePath);\n return (\n relativePath === \"\" ||\n (!relativePath.startsWith(\"..\") && !path.isAbsolute(relativePath))\n );\n };\n\n const addPublicFolder = (item: string) => {\n const normalizedPath = path.normalize(item);\n return isAlreadyInPublicFolder(normalizedPath)\n ? normalizedPath\n : path.join(normalizedPublicFolder, normalizedPath);\n };\n\n return {\n input: Array.isArray(input)\n ? input.map(addPublicFolder)\n : addPublicFolder(input),\n };\n}\n"],"mappings":";;;;;;;;;;;;;;AAcA,SAAgB,gBACZ,OACA,cACF;AACE,KAAI,OAAO,iBAAiB,SACxB,QAAO,EAAE;CAGb,MAAM,yBAAyB,KAAK,UAAU,aAAa;CAE3D,MAAM,2BAA2B,aAAqB;EAClD,MAAM,eAAe,KAAK,SAAS,wBAAwB,SAAS;AACpE,SACI,iBAAiB,MAChB,CAAC,aAAa,WAAW,KAAK,IAAI,CAAC,KAAK,WAAW,aAAa;;CAIzE,MAAM,mBAAmB,SAAiB;EACtC,MAAM,iBAAiB,KAAK,UAAU,KAAK;AAC3C,SAAO,wBAAwB,eAAe,GACxC,iBACA,KAAK,KAAK,wBAAwB,eAAe;;AAG3D,QAAO,EACH,OAAO,MAAM,QAAQ,MAAM,GACrB,MAAM,IAAI,gBAAgB,GAC1B,gBAAgB,MAAM,EAC/B"}
@@ -0,0 +1,27 @@
1
+ //#region src/sourceMap.d.ts
2
+ /*!
3
+ * node-minify
4
+ * Copyright (c) 2011-2026 Rodolphe Stoclin
5
+ * MIT Licensed
6
+ */
7
+ /**
8
+ * Normalize sourceMap option to boolean for compressors that only accept boolean.
9
+ *
10
+ * @param options - Compressor options object that may contain a `sourceMap` property
11
+ * @returns `true` if `sourceMap` is truthy, `false` otherwise
12
+ */
13
+ declare function getSourceMapBoolean(options?: Record<string, unknown>): boolean;
14
+ /**
15
+ * Extract sourceMap from options, returning the boolean flag and remaining options separately.
16
+ * Useful for compressors where sourceMap must be handled as a distinct parameter.
17
+ *
18
+ * @param options - Compressor options object that may contain a `sourceMap` property
19
+ * @returns Object with `sourceMap` boolean and `restOptions` without the sourceMap key
20
+ */
21
+ declare function extractSourceMapOption(options?: Record<string, unknown>): {
22
+ sourceMap: boolean;
23
+ restOptions: Record<string, unknown>;
24
+ };
25
+ //#endregion
26
+ export { extractSourceMapOption, getSourceMapBoolean };
27
+ //# sourceMappingURL=sourceMap.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sourceMap.d.ts","names":[],"sources":["../src/sourceMap.ts"],"mappings":";;AAYA;;;;;AAaA;;;;;iBAbgB,mBAAA,CACZ,OAAA,GAAU,MAAA;;;;;;;;iBAYE,sBAAA,CAAuB,OAAA,GAAU,MAAA;EAC7C,SAAA;EACA,WAAA,EAAa,MAAA;AAAA"}
@@ -0,0 +1,37 @@
1
+ //#region src/sourceMap.ts
2
+ /*!
3
+ * node-minify
4
+ * Copyright (c) 2011-2026 Rodolphe Stoclin
5
+ * MIT Licensed
6
+ */
7
+ /**
8
+ * Normalize sourceMap option to boolean for compressors that only accept boolean.
9
+ *
10
+ * @param options - Compressor options object that may contain a `sourceMap` property
11
+ * @returns `true` if `sourceMap` is truthy, `false` otherwise
12
+ */
13
+ function getSourceMapBoolean(options) {
14
+ return !!options?.sourceMap;
15
+ }
16
+ /**
17
+ * Extract sourceMap from options, returning the boolean flag and remaining options separately.
18
+ * Useful for compressors where sourceMap must be handled as a distinct parameter.
19
+ *
20
+ * @param options - Compressor options object that may contain a `sourceMap` property
21
+ * @returns Object with `sourceMap` boolean and `restOptions` without the sourceMap key
22
+ */
23
+ function extractSourceMapOption(options) {
24
+ if (!options) return {
25
+ sourceMap: false,
26
+ restOptions: {}
27
+ };
28
+ const { sourceMap, ...restOptions } = options;
29
+ return {
30
+ sourceMap: !!sourceMap,
31
+ restOptions
32
+ };
33
+ }
34
+
35
+ //#endregion
36
+ export { extractSourceMapOption, getSourceMapBoolean };
37
+ //# sourceMappingURL=sourceMap.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sourceMap.js","names":[],"sources":["../src/sourceMap.ts"],"sourcesContent":["/*!\n * node-minify\n * Copyright (c) 2011-2026 Rodolphe Stoclin\n * MIT Licensed\n */\n\n/**\n * Normalize sourceMap option to boolean for compressors that only accept boolean.\n *\n * @param options - Compressor options object that may contain a `sourceMap` property\n * @returns `true` if `sourceMap` is truthy, `false` otherwise\n */\nexport function getSourceMapBoolean(\n options?: Record<string, unknown>\n): boolean {\n return !!options?.sourceMap;\n}\n\n/**\n * Extract sourceMap from options, returning the boolean flag and remaining options separately.\n * Useful for compressors where sourceMap must be handled as a distinct parameter.\n *\n * @param options - Compressor options object that may contain a `sourceMap` property\n * @returns Object with `sourceMap` boolean and `restOptions` without the sourceMap key\n */\nexport function extractSourceMapOption(options?: Record<string, unknown>): {\n sourceMap: boolean;\n restOptions: Record<string, unknown>;\n} {\n if (!options) {\n return { sourceMap: false, restOptions: {} };\n }\n const { sourceMap, ...restOptions } = options;\n return {\n sourceMap: !!sourceMap,\n restOptions,\n };\n}\n"],"mappings":";;;;;;;;;;;;AAYA,SAAgB,oBACZ,SACO;AACP,QAAO,CAAC,CAAC,SAAS;;;;;;;;;AAUtB,SAAgB,uBAAuB,SAGrC;AACE,KAAI,CAAC,QACD,QAAO;EAAE,WAAW;EAAO,aAAa,EAAE;EAAE;CAEhD,MAAM,EAAE,WAAW,GAAG,gBAAgB;AACtC,QAAO;EACH,WAAW,CAAC,CAAC;EACb;EACH"}
@@ -1,5 +1,4 @@
1
1
  //#region ../types/src/types.d.ts
2
-
3
2
  /**
4
3
  * Output result for multi-format image compression.
5
4
  */
@@ -8,7 +7,6 @@ type CompressorOutput = {
8
7
  * Format of the output (e.g., 'webp', 'avif').
9
8
  */
10
9
  format?: string;
11
-
12
10
  /**
13
11
  * Output content as string or Buffer.
14
12
  */
@@ -22,19 +20,16 @@ type CompressorResult = {
22
20
  * Minified content as string (for text-based formats like JS, CSS, HTML, SVG).
23
21
  */
24
22
  code: string;
25
-
26
23
  /**
27
24
  * Source map (for JS/CSS compressors).
28
25
  */
29
26
  map?: string;
30
-
31
27
  /**
32
28
  * Minified content as Buffer (for binary formats like images).
33
29
  * @example
34
30
  * When using sharp for PNG/WebP compression
35
31
  */
36
32
  buffer?: Buffer;
37
-
38
33
  /**
39
34
  * Multiple outputs for multi-format image compression.
40
35
  * Used when converting to multiple formats simultaneously.
@@ -80,12 +75,10 @@ type Settings<TOptions extends CompressorOptions = CompressorOptions> = {
80
75
  * The compressor function to use for minification.
81
76
  */
82
77
  compressor: Compressor<TOptions>;
83
-
84
78
  /**
85
79
  * Optional label for the compressor (used in logging).
86
80
  */
87
81
  compressorLabel?: string;
88
-
89
82
  /**
90
83
  * Content to minify (for in-memory minification).
91
84
  * If provided, input/output are not required.
@@ -93,7 +86,6 @@ type Settings<TOptions extends CompressorOptions = CompressorOptions> = {
93
86
  * For binary formats (images): Buffer (handled internally by image compressors)
94
87
  */
95
88
  content?: string | Buffer;
96
-
97
89
  /**
98
90
  * Input file path(s) or glob pattern.
99
91
  * Can be a single file, array of files, or wildcard pattern.
@@ -104,7 +96,6 @@ type Settings<TOptions extends CompressorOptions = CompressorOptions> = {
104
96
  * - 'src/**\/*.js'
105
97
  */
106
98
  input?: string | string[];
107
-
108
99
  /**
109
100
  * Output file path.
110
101
  * Use $1 as placeholder for input filename in multi-file scenarios.
@@ -116,43 +107,36 @@ type Settings<TOptions extends CompressorOptions = CompressorOptions> = {
116
107
  * - '$1.min.js' (creates app.min.js from app.js)
117
108
  */
118
109
  output?: string | string[];
119
-
120
110
  /**
121
111
  * Compressor-specific options.
122
112
  * See individual compressor documentation for available options.
123
113
  */
124
114
  options?: TOptions;
125
-
126
115
  /**
127
116
  * CLI option string (used by CLI only).
128
117
  * @internal
129
118
  */
130
119
  option?: string;
131
-
132
120
  /**
133
121
  * Buffer size for file operations (in bytes).
134
122
  * @default 1024000 (1MB)
135
123
  */
136
124
  buffer?: number;
137
-
138
125
  /**
139
126
  * Timeout for the compressor process (in milliseconds).
140
127
  * If execution exceeds this limit, the process will be killed.
141
128
  */
142
129
  timeout?: number;
143
-
144
130
  /**
145
131
  * File type for compressors that support multiple types.
146
132
  * Required for YUI compressor.
147
133
  */
148
134
  type?: FileType;
149
-
150
135
  /**
151
136
  * Suppress console output.
152
137
  * @default false
153
138
  */
154
139
  silence?: boolean;
155
-
156
140
  /**
157
141
  * Public folder to prepend to input paths.
158
142
  *
@@ -161,13 +145,11 @@ type Settings<TOptions extends CompressorOptions = CompressorOptions> = {
161
145
  * the actual path becomes 'public/js/app.js'
162
146
  */
163
147
  publicFolder?: string;
164
-
165
148
  /**
166
149
  * Replace files in place instead of creating new output files.
167
150
  * @default false
168
151
  */
169
152
  replaceInPlace?: boolean;
170
-
171
153
  /**
172
154
  * Allow empty output without throwing an error.
173
155
  * When true, if minification results in empty content, the output file will not be written.
@@ -185,7 +167,6 @@ type MinifierOptions<TOptions extends CompressorOptions = CompressorOptions> = {
185
167
  * The full settings object.
186
168
  */
187
169
  settings: Settings<TOptions>;
188
-
189
170
  /**
190
171
  * The content to minify.
191
172
  * For text-based formats (JS, CSS, HTML, SVG): string
@@ -193,7 +174,6 @@ type MinifierOptions<TOptions extends CompressorOptions = CompressorOptions> = {
193
174
  * For multiple binary files: Buffer[]
194
175
  */
195
176
  content?: string | Buffer | Buffer[];
196
-
197
177
  /**
198
178
  * Index of current file when processing multiple files.
199
179
  */
@@ -201,4 +181,4 @@ type MinifierOptions<TOptions extends CompressorOptions = CompressorOptions> = {
201
181
  };
202
182
  //#endregion
203
183
  export { Settings as i, CompressorOptions as n, MinifierOptions as r, Compressor as t };
204
- //# sourceMappingURL=types-CWBFD3au.d.ts.map
184
+ //# sourceMappingURL=types-D10QejTN.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types-D10QejTN.d.ts","names":["CompressorReturnType","ImageFormat","CompressorOutput","Buffer","format","content","CompressorResult","code","map","buffer","outputs","CompressorOptions","Record","Compressor","TOptions","MinifierOptions","Promise","args","FileType","Settings","compressor","compressorLabel","input","output","options","option","timeout","type","silence","publicFolder","replaceInPlace","allowEmptyOutput","settings","index","Result","size","sizeGzip","MinifyOptions"],"sources":["../../types/src/types.d.ts"],"mappings":";;AAkFA;;KArDYE,gBAAAA;EAqD4BS;;;EAjDpCP,MAAAA;EAkDqCY;;;EA7CrCX,OAAAA,WAAkBF,MAAAA;AAAAA;;;;KAMVG,gBAAAA;EAuCqCA;;;EAnC7CC,IAAAA;;;;EAKAC,GAAAA;EAsDgBM;;;;;EA/ChBL,MAAAA,GAASN,MAAAA;EAqHFe;;;;;;EA7GPR,OAAAA,GAAUR,gBAAAA;AAAAA;;;;;KAOFS,iBAAAA,GAAoBC,MAAAA;;;;;;KAOpBC,UAAAA,kBAA4BF,iBAAAA,GAAoBA,iBAAAA,KACvDM,IAAAA,EAAMF,eAAAA,CAAgBD,QAAAA,MAAcE,OAAAA,CAAQV,gBAAAA;;;;KAKrCY,QAAAA;;;;;;;;;;;;;;;;;;KAmBAC,QAAAA,kBAA0BR,iBAAAA,GAAoBA,iBAAAA;EAwH1BR;;;EApH5BiB,UAAAA,EAAYP,UAAAA,CAAWC,QAAAA;;;;EAKvBO,eAAAA;;;;;;;EAQAhB,OAAAA,YAAmBF,MAAAA;;;;;;;;;;EAWnBmB,KAAAA;;;;;;;;;;;EAYAC,MAAAA;;;;;EAMAC,OAAAA,GAAUV,QAAAA;;;;;EAMVW,MAAAA;;;;;EAMAhB,MAAAA;;;;;EAMAiB,OAAAA;;;;;EAMAC,IAAAA,GAAOT,QAAAA;;;;;EAMPU,OAAAA;;;;;;;;EASAC,YAAAA;;;;;EAMAC,cAAAA;;;;;;;EAQAC,gBAAAA;AAAAA;;;;;KAOQhB,eAAAA,kBACSJ,iBAAAA,GAAoBA,iBAAAA;;;;EAKrCqB,QAAAA,EAAUb,QAAAA,CAASL,QAAAA;;;;;;;EAQnBT,OAAAA,YAAmBF,MAAAA,GAASA,MAAAA;;;;EAK5B8B,KAAAA;AAAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","names":[],"sources":["../src/types.ts"],"sourcesContent":[],"mappings":";;AAMA;;;;UAAiB,gBAAA"}
1
+ {"version":3,"file":"types.d.ts","names":[],"sources":["../src/types.ts"],"mappings":";;AAMA;;;;UAAiB,gBAAA;EAAA,CACZ,GAAA;AAAA"}
@@ -4,16 +4,34 @@
4
4
  * Copyright (c) 2011-2026 Rodolphe Stoclin
5
5
  * MIT Licensed
6
6
  */
7
+ /**
8
+ * Options for wildcards function
9
+ */
10
+ interface WildcardOptions {
11
+ /**
12
+ * Path to the public folder
13
+ */
14
+ publicFolder?: string;
15
+ /**
16
+ * Patterns to ignore when matching files
17
+ */
18
+ ignore?: string[];
19
+ }
20
+ /**
21
+ * Default ignore patterns for common build artifacts and dependencies
22
+ */
23
+ declare const DEFAULT_IGNORES: string[];
7
24
  /**
8
25
  * Handle wildcards in a path, get the real path of each file.
9
26
  * @param input - Path with wildcards
10
- * @param publicFolder - Path to the public folder
27
+ * @param options - Options object or string publicFolder for backward compatibility
28
+ * @returns Object with resolved file paths
11
29
  */
12
- declare function wildcards(input: string | string[], publicFolder?: string): {
30
+ declare function wildcards(input: string | string[], options?: WildcardOptions | string): {
13
31
  input: string[];
14
32
  } | {
15
33
  input?: undefined;
16
34
  };
17
35
  //#endregion
18
- export { wildcards };
36
+ export { DEFAULT_IGNORES, WildcardOptions, wildcards };
19
37
  //# sourceMappingURL=wildcards.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"wildcards.d.ts","names":[],"sources":["../src/wildcards.ts"],"sourcesContent":[],"mappings":";;AAqBA;;;;;;;;;iBAAgB,SAAA"}
1
+ {"version":3,"file":"wildcards.d.ts","names":[],"sources":["../src/wildcards.ts"],"mappings":";;AAaA;;;;;AAcA;;UAdiB,eAAA;EAuBhB;;AAwBD;EA3CI,YAAA;;;;EAIA,MAAA;AAAA;;;;cAMS,eAAA;;;;;;;iBAiCG,SAAA,CACZ,KAAA,qBACA,OAAA,GAAU,eAAA"}
package/dist/wildcards.js CHANGED
@@ -1,3 +1,4 @@
1
+ import path from "node:path";
1
2
  import os from "node:os";
2
3
  import fg from "fast-glob";
3
4
 
@@ -8,51 +9,74 @@ import fg from "fast-glob";
8
9
  * MIT Licensed
9
10
  */
10
11
  /**
12
+ * Default ignore patterns for common build artifacts and dependencies
13
+ */
14
+ const DEFAULT_IGNORES = [
15
+ "**/node_modules/**",
16
+ "**/dist/**",
17
+ "**/build/**",
18
+ "**/.next/**",
19
+ "**/*.min.{js,css}",
20
+ "**/*.d.ts",
21
+ "**/__tests__/**",
22
+ "**/.*"
23
+ ];
24
+ /**
11
25
  * Check if the platform is Windows
12
26
  */
13
27
  function isWindows() {
14
28
  return os.platform() === "win32";
15
29
  }
16
30
  /**
31
+ * Normalize any Windows path separators to POSIX separators.
32
+ * @param value Path-like string
33
+ * @returns Path string using `/` separators
34
+ */
35
+ function toPosixPath(value) {
36
+ return value.replaceAll("\\", "/");
37
+ }
38
+ /**
17
39
  * Handle wildcards in a path, get the real path of each file.
18
40
  * @param input - Path with wildcards
19
- * @param publicFolder - Path to the public folder
41
+ * @param options - Options object or string publicFolder for backward compatibility
42
+ * @returns Object with resolved file paths
20
43
  */
21
- function wildcards(input, publicFolder) {
22
- if (Array.isArray(input)) return wildcardsArray(input, publicFolder);
23
- return wildcardsString(input, publicFolder);
44
+ function wildcards(input, options) {
45
+ const normalizedOptions = typeof options === "string" ? { publicFolder: options } : options ?? {};
46
+ if (Array.isArray(input)) return wildcardsArray(input, normalizedOptions);
47
+ return wildcardsString(input, normalizedOptions);
24
48
  }
25
49
  /**
26
50
  * Handle wildcards in a path (string only), get the real path of each file.
27
51
  * @param input - Path with wildcards
28
- * @param publicFolder - Path to the public folder
52
+ * @param options - Wildcard options
29
53
  */
30
- function wildcardsString(input, publicFolder) {
54
+ function wildcardsString(input, options) {
31
55
  if (!input.includes("*")) return {};
32
- return { input: getFilesFromWildcards(input, publicFolder).filter((path) => !path.includes("*")) };
56
+ return { input: getFilesFromWildcards(input, options).filter((path) => !path.includes("*")) };
33
57
  }
34
58
  /**
35
59
  * Handle wildcards in a path (array only), get the real path of each file.
36
60
  * @param input - Array of paths with wildcards
37
- * @param publicFolder - Path to the public folder
61
+ * @param options - Wildcard options
38
62
  */
39
- function wildcardsArray(input, publicFolder) {
63
+ function wildcardsArray(input, options) {
40
64
  const inputWithPublicFolder = input.map((item) => {
41
- const input2 = publicFolder ? publicFolder + item : item;
65
+ const input2 = options.publicFolder ? path.posix.join(toPosixPath(options.publicFolder), toPosixPath(item)) : item;
42
66
  return isWindows() ? fg.convertPathToPattern(input2) : input2;
43
67
  });
44
- return { input: (inputWithPublicFolder.some((item) => item.includes("*")) ? fg.globSync(inputWithPublicFolder) : input).filter((path) => !path.includes("*")) };
68
+ return { input: (inputWithPublicFolder.some((item) => item.includes("*")) ? fg.globSync(inputWithPublicFolder, { ignore: options.ignore }) : inputWithPublicFolder).filter((path) => !path.includes("*")) };
45
69
  }
46
70
  /**
47
71
  * Get the real path of each file.
48
72
  * @param input - Path with wildcards
49
- * @param publicFolder - Path to the public folder
73
+ * @param options - Wildcard options
50
74
  */
51
- function getFilesFromWildcards(input, publicFolder) {
52
- const fullPath = publicFolder ? `${publicFolder}${input}` : input;
53
- return fg.globSync(isWindows() ? fg.convertPathToPattern(fullPath) : fullPath);
75
+ function getFilesFromWildcards(input, options) {
76
+ const fullPath = options.publicFolder ? path.posix.join(toPosixPath(options.publicFolder), toPosixPath(input)) : input;
77
+ return fg.globSync(isWindows() ? fg.convertPathToPattern(fullPath) : fullPath, { ignore: options.ignore });
54
78
  }
55
79
 
56
80
  //#endregion
57
- export { wildcards };
81
+ export { DEFAULT_IGNORES, wildcards };
58
82
  //# sourceMappingURL=wildcards.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"wildcards.js","names":[],"sources":["../src/wildcards.ts"],"sourcesContent":["/*!\n * node-minify\n * Copyright (c) 2011-2026 Rodolphe Stoclin\n * MIT Licensed\n */\n\nimport os from \"node:os\";\nimport fg from \"fast-glob\";\n\n/**\n * Check if the platform is Windows\n */\nfunction isWindows() {\n return os.platform() === \"win32\";\n}\n\n/**\n * Handle wildcards in a path, get the real path of each file.\n * @param input - Path with wildcards\n * @param publicFolder - Path to the public folder\n */\nexport function wildcards(input: string | string[], publicFolder?: string) {\n if (Array.isArray(input)) {\n return wildcardsArray(input, publicFolder);\n }\n\n return wildcardsString(input, publicFolder);\n}\n\n/**\n * Handle wildcards in a path (string only), get the real path of each file.\n * @param input - Path with wildcards\n * @param publicFolder - Path to the public folder\n */\nfunction wildcardsString(input: string, publicFolder?: string) {\n if (!input.includes(\"*\")) {\n return {};\n }\n\n const files = getFilesFromWildcards(input, publicFolder);\n const finalPaths = files.filter((path: string) => !path.includes(\"*\"));\n\n return {\n input: finalPaths,\n };\n}\n\n/**\n * Handle wildcards in a path (array only), get the real path of each file.\n * @param input - Array of paths with wildcards\n * @param publicFolder - Path to the public folder\n */\nfunction wildcardsArray(input: string[], publicFolder?: string) {\n // Convert input paths to patterns with public folder prefix\n const inputWithPublicFolder = input.map((item) => {\n const input2 = publicFolder ? publicFolder + item : item;\n return isWindows() ? fg.convertPathToPattern(input2) : input2;\n });\n\n // Check if any wildcards exist\n const hasWildcards = inputWithPublicFolder.some((item) =>\n item.includes(\"*\")\n );\n\n // Process paths based on whether wildcards exist\n const processedPaths = hasWildcards\n ? fg.globSync(inputWithPublicFolder)\n : input;\n\n // Filter out any remaining paths with wildcards\n const finalPaths = processedPaths.filter(\n (path: string) => !path.includes(\"*\")\n );\n\n return { input: finalPaths };\n}\n\n/**\n * Get the real path of each file.\n * @param input - Path with wildcards\n * @param publicFolder - Path to the public folder\n */\nfunction getFilesFromWildcards(input: string, publicFolder?: string) {\n const fullPath = publicFolder ? `${publicFolder}${input}` : input;\n return fg.globSync(\n isWindows() ? fg.convertPathToPattern(fullPath) : fullPath\n );\n}\n"],"mappings":";;;;;;;;;;;;AAYA,SAAS,YAAY;AACjB,QAAO,GAAG,UAAU,KAAK;;;;;;;AAQ7B,SAAgB,UAAU,OAA0B,cAAuB;AACvE,KAAI,MAAM,QAAQ,MAAM,CACpB,QAAO,eAAe,OAAO,aAAa;AAG9C,QAAO,gBAAgB,OAAO,aAAa;;;;;;;AAQ/C,SAAS,gBAAgB,OAAe,cAAuB;AAC3D,KAAI,CAAC,MAAM,SAAS,IAAI,CACpB,QAAO,EAAE;AAMb,QAAO,EACH,OAJU,sBAAsB,OAAO,aAAa,CAC/B,QAAQ,SAAiB,CAAC,KAAK,SAAS,IAAI,CAAC,EAIrE;;;;;;;AAQL,SAAS,eAAe,OAAiB,cAAuB;CAE5D,MAAM,wBAAwB,MAAM,KAAK,SAAS;EAC9C,MAAM,SAAS,eAAe,eAAe,OAAO;AACpD,SAAO,WAAW,GAAG,GAAG,qBAAqB,OAAO,GAAG;GACzD;AAiBF,QAAO,EAAE,QAdY,sBAAsB,MAAM,SAC7C,KAAK,SAAS,IAAI,CACrB,GAIK,GAAG,SAAS,sBAAsB,GAClC,OAG4B,QAC7B,SAAiB,CAAC,KAAK,SAAS,IAAI,CACxC,EAE2B;;;;;;;AAQhC,SAAS,sBAAsB,OAAe,cAAuB;CACjE,MAAM,WAAW,eAAe,GAAG,eAAe,UAAU;AAC5D,QAAO,GAAG,SACN,WAAW,GAAG,GAAG,qBAAqB,SAAS,GAAG,SACrD"}
1
+ {"version":3,"file":"wildcards.js","names":[],"sources":["../src/wildcards.ts"],"sourcesContent":["/*!\n * node-minify\n * Copyright (c) 2011-2026 Rodolphe Stoclin\n * MIT Licensed\n */\n\nimport os from \"node:os\";\nimport path from \"node:path\";\nimport fg from \"fast-glob\";\n\n/**\n * Options for wildcards function\n */\nexport interface WildcardOptions {\n /**\n * Path to the public folder\n */\n publicFolder?: string;\n /**\n * Patterns to ignore when matching files\n */\n ignore?: string[];\n}\n\n/**\n * Default ignore patterns for common build artifacts and dependencies\n */\nexport const DEFAULT_IGNORES: string[] = [\n \"**/node_modules/**\",\n \"**/dist/**\",\n \"**/build/**\",\n \"**/.next/**\",\n \"**/*.min.{js,css}\",\n \"**/*.d.ts\",\n \"**/__tests__/**\",\n \"**/.*\",\n];\n\n/**\n * Check if the platform is Windows\n */\nfunction isWindows() {\n return os.platform() === \"win32\";\n}\n\n/**\n * Normalize any Windows path separators to POSIX separators.\n * @param value Path-like string\n * @returns Path string using `/` separators\n */\nfunction toPosixPath(value: string): string {\n return value.replaceAll(\"\\\\\", \"/\");\n}\n\n/**\n * Handle wildcards in a path, get the real path of each file.\n * @param input - Path with wildcards\n * @param options - Options object or string publicFolder for backward compatibility\n * @returns Object with resolved file paths\n */\nexport function wildcards(\n input: string | string[],\n options?: WildcardOptions | string\n) {\n const normalizedOptions: WildcardOptions =\n typeof options === \"string\"\n ? { publicFolder: options }\n : (options ?? {});\n\n if (Array.isArray(input)) {\n return wildcardsArray(input, normalizedOptions);\n }\n\n return wildcardsString(input, normalizedOptions);\n}\n\n/**\n * Handle wildcards in a path (string only), get the real path of each file.\n * @param input - Path with wildcards\n * @param options - Wildcard options\n */\nfunction wildcardsString(input: string, options: WildcardOptions) {\n if (!input.includes(\"*\")) {\n return {};\n }\n\n const files = getFilesFromWildcards(input, options);\n const finalPaths = files.filter((path: string) => !path.includes(\"*\"));\n\n return {\n input: finalPaths,\n };\n}\n\n/**\n * Handle wildcards in a path (array only), get the real path of each file.\n * @param input - Array of paths with wildcards\n * @param options - Wildcard options\n */\nfunction wildcardsArray(input: string[], options: WildcardOptions) {\n const inputWithPublicFolder = input.map((item) => {\n const input2 = options.publicFolder\n ? path.posix.join(\n toPosixPath(options.publicFolder),\n toPosixPath(item)\n )\n : item;\n return isWindows() ? fg.convertPathToPattern(input2) : input2;\n });\n\n const hasWildcards = inputWithPublicFolder.some((item) =>\n item.includes(\"*\")\n );\n\n const processedPaths = hasWildcards\n ? fg.globSync(inputWithPublicFolder, { ignore: options.ignore })\n : inputWithPublicFolder;\n\n const finalPaths = processedPaths.filter(\n (path: string) => !path.includes(\"*\")\n );\n\n return { input: finalPaths };\n}\n\n/**\n * Get the real path of each file.\n * @param input - Path with wildcards\n * @param options - Wildcard options\n */\nfunction getFilesFromWildcards(input: string, options: WildcardOptions) {\n const fullPath = options.publicFolder\n ? path.posix.join(toPosixPath(options.publicFolder), toPosixPath(input))\n : input;\n return fg.globSync(\n isWindows() ? fg.convertPathToPattern(fullPath) : fullPath,\n { ignore: options.ignore }\n );\n}\n"],"mappings":";;;;;;;;;;;;;AA2BA,MAAa,kBAA4B;CACrC;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACH;;;;AAKD,SAAS,YAAY;AACjB,QAAO,GAAG,UAAU,KAAK;;;;;;;AAQ7B,SAAS,YAAY,OAAuB;AACxC,QAAO,MAAM,WAAW,MAAM,IAAI;;;;;;;;AAStC,SAAgB,UACZ,OACA,SACF;CACE,MAAM,oBACF,OAAO,YAAY,WACb,EAAE,cAAc,SAAS,GACxB,WAAW,EAAE;AAExB,KAAI,MAAM,QAAQ,MAAM,CACpB,QAAO,eAAe,OAAO,kBAAkB;AAGnD,QAAO,gBAAgB,OAAO,kBAAkB;;;;;;;AAQpD,SAAS,gBAAgB,OAAe,SAA0B;AAC9D,KAAI,CAAC,MAAM,SAAS,IAAI,CACpB,QAAO,EAAE;AAMb,QAAO,EACH,OAJU,sBAAsB,OAAO,QAAQ,CAC1B,QAAQ,SAAiB,CAAC,KAAK,SAAS,IAAI,CAAC,EAIrE;;;;;;;AAQL,SAAS,eAAe,OAAiB,SAA0B;CAC/D,MAAM,wBAAwB,MAAM,KAAK,SAAS;EAC9C,MAAM,SAAS,QAAQ,eACjB,KAAK,MAAM,KACP,YAAY,QAAQ,aAAa,EACjC,YAAY,KAAK,CACpB,GACD;AACN,SAAO,WAAW,GAAG,GAAG,qBAAqB,OAAO,GAAG;GACzD;AAcF,QAAO,EAAE,QAZY,sBAAsB,MAAM,SAC7C,KAAK,SAAS,IAAI,CACrB,GAGK,GAAG,SAAS,uBAAuB,EAAE,QAAQ,QAAQ,QAAQ,CAAC,GAC9D,uBAE4B,QAC7B,SAAiB,CAAC,KAAK,SAAS,IAAI,CACxC,EAE2B;;;;;;;AAQhC,SAAS,sBAAsB,OAAe,SAA0B;CACpE,MAAM,WAAW,QAAQ,eACnB,KAAK,MAAM,KAAK,YAAY,QAAQ,aAAa,EAAE,YAAY,MAAM,CAAC,GACtE;AACN,QAAO,GAAG,SACN,WAAW,GAAG,GAAG,qBAAqB,SAAS,GAAG,UAClD,EAAE,QAAQ,QAAQ,QAAQ,CAC7B"}
@@ -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;AA8BpC;;;;;;;;;;;;;iBAlCgB,SAAA;;;;GAIb,2BAA2B;;;;;;;;;;;;;;iBA8BR,cAAA;;;;GAInB,kBAAkB,iBAAiB"}
1
+ {"version":3,"file":"writeFile.d.ts","names":[],"sources":["../src/writeFile.ts"],"mappings":";;;;;;UAUU,eAAA;EACN,IAAA;EACA,OAAA,WAAkB,MAAA;EAClB,KAAA;AAAA;;AAeJ;;;;;;;;;;;iBAAgB,SAAA,CAAA;EACZ,IAAA;EACA,OAAA;EACA;AAAA,GACD,eAAA,YAA2B,MAAA;;;;;;;;;AA8B9B;;;;;iBAAsB,cAAA,CAAA;EAClB,IAAA;EACA,OAAA;EACA;AAAA,GACD,eAAA,GAAkB,OAAA,UAAiB,MAAA"}
package/dist/writeFile.js CHANGED
@@ -1,3 +1,96 @@
1
- import { n as writeFileAsync, t as writeFile } from "./writeFile-mfUS3rMz.js";
1
+ import { FileOperationError, ValidationError } from "./error.js";
2
+ import { writeFileSync } from "node:fs";
3
+ import { writeFile as writeFile$1 } from "node:fs/promises";
2
4
 
3
- export { writeFile, writeFileAsync };
5
+ //#region src/writeFile.ts
6
+ /*!
7
+ * node-minify
8
+ * Copyright (c) 2011-2026 Rodolphe Stoclin
9
+ * MIT Licensed
10
+ */
11
+ /**
12
+ * Write provided content to a target file.
13
+ *
14
+ * When `file` is an array and `index` is provided, the file at that index is used; otherwise `file` is used directly.
15
+ *
16
+ * @param file - Target path or array of target paths
17
+ * @param content - Content to write; may be a `string` or `Buffer`
18
+ * @param index - Optional index to select a file when `file` is an array
19
+ * @returns The same `content` value that was written
20
+ * @throws ValidationError If no target file, no content, or the resolved target path is invalid
21
+ * @throws FileOperationError If the underlying filesystem write fails (wraps the original error)
22
+ */
23
+ function writeFile({ file, content, index }) {
24
+ try {
25
+ const targetFile = resolveTargetFile(file, index);
26
+ validateContent(content);
27
+ writeFileSync(targetFile, content, Buffer.isBuffer(content) ? void 0 : "utf8");
28
+ return content;
29
+ } catch (error) {
30
+ handleWriteError(error, file);
31
+ return content;
32
+ }
33
+ }
34
+ /**
35
+ * Write content to a resolved target file path.
36
+ *
37
+ * Resolves the target from `file` (string or array) using `index` when provided, validates the content,
38
+ * ensures the target is not a directory, and writes the content to disk.
39
+ *
40
+ * @param file - Target path or array of target paths; when `file` is an array, `index` selects the entry
41
+ * @param content - Content to write; a `string` or `Buffer`
42
+ * @param index - Optional index used to select a file when `file` is an array
43
+ * @returns The same `content` value that was written
44
+ * @throws ValidationError If no target file, no content, or the resolved target path is invalid
45
+ * @throws FileOperationError If the underlying filesystem write fails (wraps the original error)
46
+ */
47
+ async function writeFileAsync({ file, content, index }) {
48
+ try {
49
+ const targetFile = resolveTargetFile(file, index);
50
+ validateContent(content);
51
+ await writeFile$1(targetFile, content, Buffer.isBuffer(content) ? void 0 : "utf8");
52
+ return content;
53
+ } catch (error) {
54
+ handleWriteError(error, file);
55
+ return content;
56
+ }
57
+ }
58
+ /**
59
+ * Resolve a target file path from a string or an array of paths, optionally selecting by index.
60
+ *
61
+ * @param file - A file path or an array of file paths to resolve from.
62
+ * @param index - Optional index to select an entry when `file` is an array; ignored if not provided.
63
+ * @returns The resolved file path.
64
+ * @throws ValidationError if no file is provided or the resolved target is not a string.
65
+ */
66
+ function resolveTargetFile(file, index) {
67
+ if (!file) throw new ValidationError("No target file provided");
68
+ const targetFile = index !== void 0 ? Array.isArray(file) ? file[index] : file : file;
69
+ if (typeof targetFile !== "string") throw new ValidationError("Invalid target file path");
70
+ return targetFile;
71
+ }
72
+ /**
73
+ * Ensure content is present before writing.
74
+ *
75
+ * @param content - The data to write; a string or Buffer
76
+ * @throws ValidationError if `content` is empty or otherwise falsy
77
+ */
78
+ function validateContent(content) {
79
+ if (!content) throw new ValidationError("No content provided");
80
+ }
81
+ /**
82
+ * Normalize and rethrow errors that occur while attempting to write to one or more files.
83
+ *
84
+ * @param error - The original error thrown during the write attempt
85
+ * @param file - The target file path or an array of paths that were the intended write targets
86
+ * @throws ValidationError - rethrows the provided ValidationError without modification
87
+ * @throws FileOperationError - thrown for any other error, wrapping the original error with context about the write operation and the target file(s)
88
+ */
89
+ function handleWriteError(error, file) {
90
+ if (error instanceof ValidationError) throw error;
91
+ throw new FileOperationError("write to", typeof file === "string" ? file : "multiple files", error);
92
+ }
93
+
94
+ //#endregion
95
+ export { writeFile, writeFileAsync };
96
+ //# sourceMappingURL=writeFile.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"writeFile.js","names":["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,SAAgB,UAAU,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,QAAMA,YACF,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"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@node-minify/utils",
3
- "version": "10.4.0",
3
+ "version": "10.5.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.4.0"
59
+ "@node-minify/types": "10.5.0"
60
60
  }
61
61
  }
@@ -1,32 +0,0 @@
1
- //#region src/error.ts
2
- /*!
3
- * node-minify
4
- * Copyright (c) 2011-2026 Rodolphe Stoclin
5
- * MIT Licensed
6
- */
7
- /**
8
- * Error class for file operation failures.
9
- * @extends Error
10
- */
11
- var FileOperationError = class extends Error {
12
- cause;
13
- constructor(operation, path, originalError) {
14
- super(`Failed to ${operation} file ${path}: ${originalError?.message || ""}`, originalError ? { cause: originalError } : void 0);
15
- this.name = "FileOperationError";
16
- if (originalError && !this.cause) this.cause = originalError;
17
- }
18
- };
19
- /**
20
- * Error class for validation failures.
21
- * @extends Error
22
- */
23
- var ValidationError = class extends Error {
24
- constructor(message) {
25
- super(message);
26
- this.name = "ValidationError";
27
- }
28
- };
29
-
30
- //#endregion
31
- export { ValidationError as n, FileOperationError as t };
32
- //# sourceMappingURL=error-CUgKxOvI.js.map
@@ -1 +0,0 @@
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"}
@@ -1,46 +0,0 @@
1
- import { t as FileOperationError } from "./error-CUgKxOvI.js";
2
- import { existsSync, lstatSync } from "node:fs";
3
- import { lstat } from "node:fs/promises";
4
-
5
- //#region src/isValidFile.ts
6
- /*!
7
- * node-minify
8
- * Copyright (c) 2011-2026 Rodolphe Stoclin
9
- * MIT Licensed
10
- */
11
- /**
12
- * Check if the path is a valid file.
13
- * @param path Path to check
14
- * @returns true if path exists and is a file, false otherwise
15
- * @throws {FileOperationError} If filesystem operations fail
16
- * @example
17
- * if (isValidFile('path/to/file.js')) {
18
- * // do something
19
- * }
20
- */
21
- function isValidFile(path) {
22
- try {
23
- return existsSync(path) && !lstatSync(path).isDirectory();
24
- } catch (error) {
25
- throw new FileOperationError("validate", path, error);
26
- }
27
- }
28
- /**
29
- * Determine whether a filesystem path refers to an existing file (not a directory).
30
- *
31
- * @param path - Path to check
32
- * @returns `true` if the path exists and is a file, `false` otherwise.
33
- * @throws {FileOperationError} If a filesystem error other than `ENOENT` occurs while validating the path.
34
- */
35
- async function isValidFileAsync(path) {
36
- try {
37
- return !(await lstat(path)).isDirectory();
38
- } catch (error) {
39
- if (error && typeof error === "object" && "code" in error && error.code === "ENOENT") return false;
40
- throw new FileOperationError("validate", path, error instanceof Error ? error : new Error(String(error)));
41
- }
42
- }
43
-
44
- //#endregion
45
- export { isValidFileAsync as n, isValidFile as t };
46
- //# sourceMappingURL=isValidFile-COstpeyW.js.map