@node-minify/utils 9.0.1 → 10.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (81) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +70 -5
  3. package/dist/buildArgs.d.ts +24 -0
  4. package/dist/buildArgs.d.ts.map +1 -0
  5. package/dist/buildArgs.js +43 -0
  6. package/dist/buildArgs.js.map +1 -0
  7. package/dist/compressSingleFile.d.ts +12 -0
  8. package/dist/compressSingleFile.d.ts.map +1 -0
  9. package/dist/compressSingleFile.js +28 -0
  10. package/dist/compressSingleFile.js.map +1 -0
  11. package/dist/deleteFile.d.ts +17 -0
  12. package/dist/deleteFile.d.ts.map +1 -0
  13. package/dist/deleteFile.js +28 -0
  14. package/dist/deleteFile.js.map +1 -0
  15. package/dist/deprecation.d.ts +31 -0
  16. package/dist/deprecation.d.ts.map +1 -0
  17. package/dist/deprecation.js +39 -0
  18. package/dist/deprecation.js.map +1 -0
  19. package/dist/error-B_uK-F18.js +30 -0
  20. package/dist/error-B_uK-F18.js.map +1 -0
  21. package/dist/error.d.ts +23 -0
  22. package/dist/error.d.ts.map +1 -0
  23. package/dist/error.js +3 -0
  24. package/dist/getContentFromFiles.d.ts +19 -0
  25. package/dist/getContentFromFiles.d.ts.map +1 -0
  26. package/dist/getContentFromFiles.js +49 -0
  27. package/dist/getContentFromFiles.js.map +1 -0
  28. package/dist/getFilesizeGzippedInBytes.d.ts +19 -0
  29. package/dist/getFilesizeGzippedInBytes.d.ts.map +1 -0
  30. package/dist/getFilesizeGzippedInBytes.js +37 -0
  31. package/dist/getFilesizeGzippedInBytes.js.map +1 -0
  32. package/dist/getFilesizeInBytes.d.ts +17 -0
  33. package/dist/getFilesizeInBytes.d.ts.map +1 -0
  34. package/dist/getFilesizeInBytes.js +24 -0
  35. package/dist/getFilesizeInBytes.js.map +1 -0
  36. package/dist/index.d.ts +17 -31
  37. package/dist/index.js +16 -158
  38. package/dist/isValidFile-UAwceQud.js +30 -0
  39. package/dist/isValidFile-UAwceQud.js.map +1 -0
  40. package/dist/isValidFile.d.ts +20 -0
  41. package/dist/isValidFile.d.ts.map +1 -0
  42. package/dist/isValidFile.js +3 -0
  43. package/dist/prettyBytes.d.ts +20 -0
  44. package/dist/prettyBytes.d.ts.map +1 -0
  45. package/dist/prettyBytes.js +43 -0
  46. package/dist/prettyBytes.js.map +1 -0
  47. package/dist/readFile.d.ts +15 -0
  48. package/dist/readFile.d.ts.map +1 -0
  49. package/dist/readFile.js +20 -0
  50. package/dist/readFile.js.map +1 -0
  51. package/dist/run.d.ts +23 -0
  52. package/dist/run.d.ts.map +1 -0
  53. package/dist/run.js +52 -0
  54. package/dist/run.js.map +1 -0
  55. package/dist/setFileNameMin.d.ts +22 -0
  56. package/dist/setFileNameMin.d.ts.map +1 -0
  57. package/dist/setFileNameMin.js +45 -0
  58. package/dist/setFileNameMin.js.map +1 -0
  59. package/dist/setPublicFolder.d.ts +19 -0
  60. package/dist/setPublicFolder.d.ts.map +1 -0
  61. package/dist/setPublicFolder.js +26 -0
  62. package/dist/setPublicFolder.js.map +1 -0
  63. package/dist/types-DtDQlx-T.d.ts +149 -0
  64. package/dist/types-DtDQlx-T.d.ts.map +1 -0
  65. package/dist/types.d.ts +12 -0
  66. package/dist/types.d.ts.map +1 -0
  67. package/dist/types.js +1 -0
  68. package/dist/wildcards.d.ts +19 -0
  69. package/dist/wildcards.d.ts.map +1 -0
  70. package/dist/wildcards.js +58 -0
  71. package/dist/wildcards.js.map +1 -0
  72. package/dist/writeFile-CwK9ZWXr.js +37 -0
  73. package/dist/writeFile-CwK9ZWXr.js.map +1 -0
  74. package/dist/writeFile.d.ts +29 -0
  75. package/dist/writeFile.d.ts.map +1 -0
  76. package/dist/writeFile.js +3 -0
  77. package/package.json +23 -20
  78. package/dist/index.d.mts +0 -31
  79. package/dist/index.js.map +0 -1
  80. package/dist/index.mjs +0 -132
  81. package/dist/index.mjs.map +0 -1
package/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2024 Rodolphe Stoclin
3
+ Copyright (c) 2025 Rodolphe Stoclin
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/README.md CHANGED
@@ -6,14 +6,79 @@
6
6
  <br>
7
7
  <a href="https://npmjs.org/package/@node-minify/utils"><img src="https://img.shields.io/npm/v/@node-minify/utils.svg"></a>
8
8
  <a href="https://npmjs.org/package/@node-minify/utils"><img src="https://img.shields.io/npm/dm/@node-minify/utils.svg"></a>
9
- <a href="https://github.com/srod/node-minify/actions"><img alt="Build Status" src="https://img.shields.io/endpoint.svg?url=https%3A%2F%2Factions-badge.atrox.dev%2Fsrod%2Fnode-minify%2Fbadge%3Fref%3Ddevelop&style=flat" /></a>
10
- <a href="https://codecov.io/gh/srod/node-minify"><img src="https://codecov.io/gh/srod/node-minify/branch/develop/graph/badge.svg"></a>
9
+ <a href="https://github.com/srod/node-minify/actions"><img alt="Build Status" src="https://img.shields.io/endpoint.svg?url=https%3A%2F%2Factions-badge.atrox.dev%2Fsrod%2Fnode-minify%2Fbadge%3Fref%3Dmain&style=flat" /></a>
10
+ <a href="https://codecov.io/gh/srod/node-minify"><img src="https://codecov.io/gh/srod/node-minify/branch/main/graph/badge.svg"></a>
11
11
  </p>
12
12
 
13
- # utils
13
+ # @node-minify/utils
14
14
 
15
- `utils` is parts of [`node-minify`](https://github.com/srod/node-minify).
15
+ Shared utilities for [`node-minify`](https://github.com/srod/node-minify) compressor packages.
16
+
17
+ This package provides common file operations, argument building, and helper functions used internally by node-minify compressors.
18
+
19
+ ## Installation
20
+
21
+ ```bash
22
+ npm install @node-minify/utils
23
+ ```
24
+
25
+ ## Exported Functions
26
+
27
+ ### File Operations
28
+
29
+ | Function | Description |
30
+ |----------|-------------|
31
+ | `readFile(filePath)` | Read file contents as a string |
32
+ | `writeFile({ file, content, index })` | Write content to a file |
33
+ | `deleteFile(file)` | Delete a file from the filesystem |
34
+ | `isValidFile(filePath)` | Check if a file exists and is readable |
35
+ | `getContentFromFiles(settings)` | Read and concatenate content from multiple files |
36
+
37
+ ### File Size Utilities
38
+
39
+ | Function | Description |
40
+ |----------|-------------|
41
+ | `getFilesizeInBytes(filePath)` | Get human-readable file size (e.g., "1.5 kB") |
42
+ | `getFilesizeGzippedInBytes(content)` | Get human-readable gzipped size |
43
+ | `prettyBytes(bytes)` | Format bytes as human-readable string |
44
+
45
+ ### Compression Helpers
46
+
47
+ | Function | Description |
48
+ |----------|-------------|
49
+ | `compressSingleFile(settings)` | Compress a single file using the configured compressor |
50
+ | `run(settings)` | Execute compression with the provided settings |
51
+ | `buildArgs(options)` | Build command line arguments from options object |
52
+ | `toBuildArgsOptions(options, definitions)` | Convert options to buildArgs format |
53
+ | `setFileNameMin(file, output, publicFolder, replaceInPlace)` | Generate output filename from input |
54
+
55
+ ### Deprecation Warnings
56
+
57
+ | Function | Description |
58
+ |----------|-------------|
59
+ | `warnDeprecation(packageName, message)` | Display a deprecation warning (once per package) |
60
+ | `resetDeprecationWarnings()` | Reset warning state (useful for testing) |
61
+
62
+ ## Usage Example
63
+
64
+ ```ts
65
+ import { readFile, writeFile, getFilesizeInBytes } from '@node-minify/utils';
66
+
67
+ // Read a file
68
+ const content = await readFile('src/app.js');
69
+
70
+ // Write minified content
71
+ await writeFile({
72
+ file: 'dist/app.min.js',
73
+ content: minifiedContent,
74
+ index: 0
75
+ });
76
+
77
+ // Get file size
78
+ const size = await getFilesizeInBytes('dist/app.min.js');
79
+ console.log(`Output size: ${size}`); // "Output size: 2.3 kB"
80
+ ```
16
81
 
17
82
  ## License
18
83
 
19
- [MIT](https://github.com/srod/node-minify/blob/develop/LICENSE)
84
+ [MIT](https://github.com/srod/node-minify/blob/main/LICENSE)
@@ -0,0 +1,24 @@
1
+ import { BuildArgsOptions } from "./types.js";
2
+
3
+ //#region src/buildArgs.d.ts
4
+
5
+ /**
6
+ * Converts a generic options object to BuildArgsOptions by filtering out non-primitive values.
7
+ * Only keeps string, number, boolean, and undefined values.
8
+ * @param options - Generic options object
9
+ * @returns Filtered options compatible with buildArgs
10
+ */
11
+ declare function toBuildArgsOptions(options: Record<string, unknown>): BuildArgsOptions;
12
+ /**
13
+ * Builds arguments array based on an object.
14
+ * @param options Object containing command line arguments
15
+ * @returns Array of command line arguments
16
+ * @throws {ValidationError} If options is null or undefined
17
+ * @example
18
+ * buildArgs({ compress: true, output: 'file.min.js' })
19
+ * // returns ['--compress', '--output', 'file.min.js']
20
+ */
21
+ declare function buildArgs(options: BuildArgsOptions): string[];
22
+ //#endregion
23
+ export { buildArgs, toBuildArgsOptions };
24
+ //# sourceMappingURL=buildArgs.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"buildArgs.d.ts","names":[],"sources":["../src/buildArgs.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;iBAegB,kBAAA,UACH,0BACV;;;;;;;;;;iBAwBa,SAAA,UAAmB"}
@@ -0,0 +1,43 @@
1
+ import { n as ValidationError } from "./error-B_uK-F18.js";
2
+
3
+ //#region src/buildArgs.ts
4
+ /*!
5
+ * node-minify
6
+ * Copyright(c) 2011-2025 Rodolphe Stoclin
7
+ * MIT Licensed
8
+ */
9
+ /**
10
+ * Converts a generic options object to BuildArgsOptions by filtering out non-primitive values.
11
+ * Only keeps string, number, boolean, and undefined values.
12
+ * @param options - Generic options object
13
+ * @returns Filtered options compatible with buildArgs
14
+ */
15
+ function toBuildArgsOptions(options) {
16
+ const result = {};
17
+ for (const [key, value] of Object.entries(options)) if (typeof value === "string" || typeof value === "number" || typeof value === "boolean" || value === void 0) result[key] = value;
18
+ return result;
19
+ }
20
+ /**
21
+ * Builds arguments array based on an object.
22
+ * @param options Object containing command line arguments
23
+ * @returns Array of command line arguments
24
+ * @throws {ValidationError} If options is null or undefined
25
+ * @example
26
+ * buildArgs({ compress: true, output: 'file.min.js' })
27
+ * // returns ['--compress', '--output', 'file.min.js']
28
+ */
29
+ function buildArgs(options) {
30
+ if (!options || typeof options !== "object") throw new ValidationError("Options must be a valid object");
31
+ const args = [];
32
+ Object.entries(options).forEach(([key, value]) => {
33
+ if (value !== void 0 && value !== false) {
34
+ args.push(`--${key}`);
35
+ if (value !== true) args.push(String(value));
36
+ }
37
+ });
38
+ return args;
39
+ }
40
+
41
+ //#endregion
42
+ export { buildArgs, toBuildArgsOptions };
43
+ //# sourceMappingURL=buildArgs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"buildArgs.js","names":["result: BuildArgsOptions","args: string[]"],"sources":["../src/buildArgs.ts"],"sourcesContent":["/*!\n * node-minify\n * Copyright(c) 2011-2025 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"}
@@ -0,0 +1,12 @@
1
+ import { t as Settings } from "./types-DtDQlx-T.js";
2
+
3
+ //#region src/compressSingleFile.d.ts
4
+
5
+ /**
6
+ * Compress a single file.
7
+ * @param settings Settings
8
+ */
9
+ declare function compressSingleFile(settings: Settings): Promise<string>;
10
+ //#endregion
11
+ export { compressSingleFile };
12
+ //# sourceMappingURL=compressSingleFile.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"compressSingleFile.d.ts","names":[],"sources":["../src/compressSingleFile.ts"],"sourcesContent":[],"mappings":";;;;;;;;iBAcsB,kBAAA,WAA6B,WAAW"}
@@ -0,0 +1,28 @@
1
+ import { getContentFromFiles } from "./getContentFromFiles.js";
2
+ import { run } from "./run.js";
3
+
4
+ //#region src/compressSingleFile.ts
5
+ /**
6
+ * Compress a single file.
7
+ * @param settings Settings
8
+ */
9
+ async function compressSingleFile(settings) {
10
+ return run({
11
+ settings,
12
+ content: determineContent(settings)
13
+ });
14
+ }
15
+ /**
16
+ * Determine the content to minify.
17
+ * @param settings - Minification settings
18
+ * @returns Content string to minify
19
+ */
20
+ function determineContent(settings) {
21
+ if (settings.content) return settings.content;
22
+ if (settings.input) return getContentFromFiles(settings.input);
23
+ return "";
24
+ }
25
+
26
+ //#endregion
27
+ export { compressSingleFile };
28
+ //# sourceMappingURL=compressSingleFile.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"compressSingleFile.js","names":[],"sources":["../src/compressSingleFile.ts"],"sourcesContent":["/*!\n * node-minify\n * Copyright(c) 2011-2025 Rodolphe Stoclin\n * MIT Licensed\n */\n\nimport type { Settings } from \"@node-minify/types\";\nimport { getContentFromFiles } from \"./getContentFromFiles.ts\";\nimport { run } from \"./run.ts\";\n\n/**\n * Compress a single file.\n * @param settings Settings\n */\nexport async function compressSingleFile(settings: Settings): Promise<string> {\n const content = determineContent(settings);\n return run({ settings, content });\n}\n\n/**\n * Determine the content to minify.\n * @param settings - Minification settings\n * @returns Content string to minify\n */\nfunction determineContent(settings: Settings): string {\n if (settings.content) {\n return settings.content;\n }\n\n if (settings.input) {\n return getContentFromFiles(settings.input);\n }\n\n return \"\";\n}\n"],"mappings":";;;;;;;;AAcA,eAAsB,mBAAmB,UAAqC;AAE1E,QAAO,IAAI;EAAE;EAAU,SADP,iBAAiB,SAAS;EACV,CAAC;;;;;;;AAQrC,SAAS,iBAAiB,UAA4B;AAClD,KAAI,SAAS,QACT,QAAO,SAAS;AAGpB,KAAI,SAAS,MACT,QAAO,oBAAoB,SAAS,MAAM;AAG9C,QAAO"}
@@ -0,0 +1,17 @@
1
+ //#region src/deleteFile.d.ts
2
+ /*!
3
+ * node-minify
4
+ * Copyright(c) 2011-2025 Rodolphe Stoclin
5
+ * MIT Licensed
6
+ */
7
+ /**
8
+ * Delete file from the filesystem.
9
+ * @param file Path to the file to delete
10
+ * @throws {FileOperationError} If file doesn't exist or deletion fails
11
+ * @example
12
+ * deleteFile('path/to/file.js')
13
+ */
14
+ declare function deleteFile(file: string): void;
15
+ //#endregion
16
+ export { deleteFile };
17
+ //# sourceMappingURL=deleteFile.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"deleteFile.d.ts","names":[],"sources":["../src/deleteFile.ts"],"sourcesContent":[],"mappings":";;AAgBA;;;;;;;;;;;iBAAgB,UAAA"}
@@ -0,0 +1,28 @@
1
+ import { t as FileOperationError } from "./error-B_uK-F18.js";
2
+ import { existsSync, unlinkSync } from "node:fs";
3
+
4
+ //#region src/deleteFile.ts
5
+ /*!
6
+ * node-minify
7
+ * Copyright(c) 2011-2025 Rodolphe Stoclin
8
+ * MIT Licensed
9
+ */
10
+ /**
11
+ * Delete file from the filesystem.
12
+ * @param file Path to the file to delete
13
+ * @throws {FileOperationError} If file doesn't exist or deletion fails
14
+ * @example
15
+ * deleteFile('path/to/file.js')
16
+ */
17
+ function deleteFile(file) {
18
+ try {
19
+ if (!existsSync(file)) throw new Error("File does not exist");
20
+ unlinkSync(file);
21
+ } catch (error) {
22
+ throw new FileOperationError("delete", file, error);
23
+ }
24
+ }
25
+
26
+ //#endregion
27
+ export { deleteFile };
28
+ //# sourceMappingURL=deleteFile.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"deleteFile.js","names":[],"sources":["../src/deleteFile.ts"],"sourcesContent":["/*!\n * node-minify\n * Copyright(c) 2011-2025 Rodolphe Stoclin\n * MIT Licensed\n */\n\nimport { existsSync, unlinkSync } from \"node:fs\";\nimport { FileOperationError } from \"./error.ts\";\n\n/**\n * Delete file from the filesystem.\n * @param file Path to the file to delete\n * @throws {FileOperationError} If file doesn't exist or deletion fails\n * @example\n * deleteFile('path/to/file.js')\n */\nexport function deleteFile(file: string): void {\n try {\n if (!existsSync(file)) {\n throw new Error(\"File does not exist\");\n }\n unlinkSync(file);\n } catch (error) {\n throw new FileOperationError(\"delete\", file, error as Error);\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAgBA,SAAgB,WAAW,MAAoB;AAC3C,KAAI;AACA,MAAI,CAAC,WAAW,KAAK,CACjB,OAAM,IAAI,MAAM,sBAAsB;AAE1C,aAAW,KAAK;UACX,OAAO;AACZ,QAAM,IAAI,mBAAmB,UAAU,MAAM,MAAe"}
@@ -0,0 +1,31 @@
1
+ //#region src/deprecation.d.ts
2
+ /*!
3
+ * node-minify
4
+ * Copyright(c) 2011-2025 Rodolphe Stoclin
5
+ * MIT Licensed
6
+ */
7
+ /**
8
+ * Show a deprecation warning for a package, but only once per process.
9
+ * Subsequent calls with the same package name will be ignored.
10
+ *
11
+ * @param packageName - The package name (e.g., "babel-minify", "uglify-es")
12
+ * @param message - The deprecation message explaining why and what to use instead
13
+ *
14
+ * @example
15
+ * ```ts
16
+ * warnDeprecation(
17
+ * "babel-minify",
18
+ * "babel-minify uses Babel 6 which is no longer maintained. " +
19
+ * "Please migrate to @node-minify/terser for continued support."
20
+ * );
21
+ * ```
22
+ */
23
+ declare function warnDeprecation(packageName: string, message: string): void;
24
+ /**
25
+ * Reset the deprecation warning state.
26
+ * Only intended for testing purposes.
27
+ */
28
+ declare function resetDeprecationWarnings(): void;
29
+ //#endregion
30
+ export { resetDeprecationWarnings, warnDeprecation };
31
+ //# sourceMappingURL=deprecation.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"deprecation.d.ts","names":[],"sources":["../src/deprecation.ts"],"sourcesContent":[],"mappings":";;AAwBA;AAaA;;;;;;;;;;;;;;;;;;;iBAbgB,eAAA;;;;;iBAaA,wBAAA,CAAA"}
@@ -0,0 +1,39 @@
1
+ //#region src/deprecation.ts
2
+ /*!
3
+ * node-minify
4
+ * Copyright(c) 2011-2025 Rodolphe Stoclin
5
+ * MIT Licensed
6
+ */
7
+ const warnedPackages = /* @__PURE__ */ new Set();
8
+ /**
9
+ * Show a deprecation warning for a package, but only once per process.
10
+ * Subsequent calls with the same package name will be ignored.
11
+ *
12
+ * @param packageName - The package name (e.g., "babel-minify", "uglify-es")
13
+ * @param message - The deprecation message explaining why and what to use instead
14
+ *
15
+ * @example
16
+ * ```ts
17
+ * warnDeprecation(
18
+ * "babel-minify",
19
+ * "babel-minify uses Babel 6 which is no longer maintained. " +
20
+ * "Please migrate to @node-minify/terser for continued support."
21
+ * );
22
+ * ```
23
+ */
24
+ function warnDeprecation(packageName, message) {
25
+ if (warnedPackages.has(packageName)) return;
26
+ warnedPackages.add(packageName);
27
+ console.warn(`[@node-minify/${packageName}] DEPRECATED: ${message}`);
28
+ }
29
+ /**
30
+ * Reset the deprecation warning state.
31
+ * Only intended for testing purposes.
32
+ */
33
+ function resetDeprecationWarnings() {
34
+ warnedPackages.clear();
35
+ }
36
+
37
+ //#endregion
38
+ export { resetDeprecationWarnings, warnDeprecation };
39
+ //# sourceMappingURL=deprecation.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"deprecation.js","names":[],"sources":["../src/deprecation.ts"],"sourcesContent":["/*!\n * node-minify\n * Copyright(c) 2011-2025 Rodolphe Stoclin\n * MIT Licensed\n */\n\nconst warnedPackages = new Set<string>();\n\n/**\n * Show a deprecation warning for a package, but only once per process.\n * Subsequent calls with the same package name will be ignored.\n *\n * @param packageName - The package name (e.g., \"babel-minify\", \"uglify-es\")\n * @param message - The deprecation message explaining why and what to use instead\n *\n * @example\n * ```ts\n * warnDeprecation(\n * \"babel-minify\",\n * \"babel-minify uses Babel 6 which is no longer maintained. \" +\n * \"Please migrate to @node-minify/terser for continued support.\"\n * );\n * ```\n */\nexport function warnDeprecation(packageName: string, message: string): void {\n if (warnedPackages.has(packageName)) {\n return;\n }\n\n warnedPackages.add(packageName);\n console.warn(`[@node-minify/${packageName}] DEPRECATED: ${message}`);\n}\n\n/**\n * Reset the deprecation warning state.\n * Only intended for testing purposes.\n */\nexport function resetDeprecationWarnings(): void {\n warnedPackages.clear();\n}\n"],"mappings":";;;;;;AAMA,MAAM,iCAAiB,IAAI,KAAa;;;;;;;;;;;;;;;;;AAkBxC,SAAgB,gBAAgB,aAAqB,SAAuB;AACxE,KAAI,eAAe,IAAI,YAAY,CAC/B;AAGJ,gBAAe,IAAI,YAAY;AAC/B,SAAQ,KAAK,iBAAiB,YAAY,gBAAgB,UAAU;;;;;;AAOxE,SAAgB,2BAAiC;AAC7C,gBAAe,OAAO"}
@@ -0,0 +1,30 @@
1
+ //#region src/error.ts
2
+ /*!
3
+ * node-minify
4
+ * Copyright(c) 2011-2025 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
+ constructor(operation, path, originalError) {
13
+ super(`Failed to ${operation} file ${path}: ${originalError?.message || ""}`);
14
+ this.name = "FileOperationError";
15
+ }
16
+ };
17
+ /**
18
+ * Error class for validation failures.
19
+ * @extends Error
20
+ */
21
+ var ValidationError = class extends Error {
22
+ constructor(message) {
23
+ super(message);
24
+ this.name = "ValidationError";
25
+ }
26
+ };
27
+
28
+ //#endregion
29
+ export { ValidationError as n, FileOperationError as t };
30
+ //# sourceMappingURL=error-B_uK-F18.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"error-B_uK-F18.js","names":[],"sources":["../src/error.ts"],"sourcesContent":["/*!\n * node-minify\n * Copyright(c) 2011-2025 Rodolphe Stoclin\n * MIT Licensed\n */\n\n/**\n * Error class for file operation failures.\n * @extends Error\n */\nexport class FileOperationError extends Error {\n constructor(operation: string, path: string, originalError?: Error) {\n super(\n `Failed to ${operation} file ${path}: ${originalError?.message || \"\"}`\n );\n this.name = \"FileOperationError\";\n }\n}\n\n/**\n * Error class for validation failures.\n * @extends Error\n */\nexport class ValidationError extends Error {\n constructor(message: string) {\n super(message);\n this.name = \"ValidationError\";\n }\n}\n"],"mappings":";;;;;;;;;;AAUA,IAAa,qBAAb,cAAwC,MAAM;CAC1C,YAAY,WAAmB,MAAc,eAAuB;AAChE,QACI,aAAa,UAAU,QAAQ,KAAK,IAAI,eAAe,WAAW,KACrE;AACD,OAAK,OAAO;;;;;;;AAQpB,IAAa,kBAAb,cAAqC,MAAM;CACvC,YAAY,SAAiB;AACzB,QAAM,QAAQ;AACd,OAAK,OAAO"}
@@ -0,0 +1,23 @@
1
+ //#region src/error.d.ts
2
+ /*!
3
+ * node-minify
4
+ * Copyright(c) 2011-2025 Rodolphe Stoclin
5
+ * MIT Licensed
6
+ */
7
+ /**
8
+ * Error class for file operation failures.
9
+ * @extends Error
10
+ */
11
+ declare class FileOperationError extends Error {
12
+ constructor(operation: string, path: string, originalError?: Error);
13
+ }
14
+ /**
15
+ * Error class for validation failures.
16
+ * @extends Error
17
+ */
18
+ declare class ValidationError extends Error {
19
+ constructor(message: string);
20
+ }
21
+ //#endregion
22
+ export { FileOperationError, ValidationError };
23
+ //# sourceMappingURL=error.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"error.d.ts","names":[],"sources":["../src/error.ts"],"sourcesContent":[],"mappings":";;AAUA;AAaA;;;;;;;cAba,kBAAA,SAA2B,KAAA;+DACyB;;;;;;cAYpD,eAAA,SAAwB,KAAA"}
package/dist/error.js ADDED
@@ -0,0 +1,3 @@
1
+ import { n as ValidationError, t as FileOperationError } from "./error-B_uK-F18.js";
2
+
3
+ export { FileOperationError, ValidationError };
@@ -0,0 +1,19 @@
1
+ //#region src/getContentFromFiles.d.ts
2
+ /*!
3
+ * node-minify
4
+ * Copyright(c) 2011-2025 Rodolphe Stoclin
5
+ * MIT Licensed
6
+ */
7
+ /**
8
+ * Concatenate all input files and get the data.
9
+ * @param input Single file path or array of file paths
10
+ * @returns Concatenated content of all files
11
+ * @throws {FileOperationError} If any file operation fails
12
+ * @example
13
+ * getContentFromFiles('file.js')
14
+ * getContentFromFiles(['file1.js', 'file2.js'])
15
+ */
16
+ declare function getContentFromFiles(input: string | string[]): string;
17
+ //#endregion
18
+ export { getContentFromFiles };
19
+ //# sourceMappingURL=getContentFromFiles.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getContentFromFiles.d.ts","names":[],"sources":["../src/getContentFromFiles.ts"],"sourcesContent":[],"mappings":";;AAuCA;;;;;;;;;;;;;iBAAgB,mBAAA"}
@@ -0,0 +1,49 @@
1
+ import { t as FileOperationError } from "./error-B_uK-F18.js";
2
+ import { t as isValidFile } from "./isValidFile-UAwceQud.js";
3
+ import { existsSync, readFileSync } from "node:fs";
4
+
5
+ //#region src/getContentFromFiles.ts
6
+ /*!
7
+ * node-minify
8
+ * Copyright(c) 2011-2025 Rodolphe Stoclin
9
+ * MIT Licensed
10
+ */
11
+ /**
12
+ * Read content from a single file with error handling.
13
+ * @param path Path to the file
14
+ * @returns Content of the file
15
+ * @throws {FileOperationError} If file doesn't exist or reading fails
16
+ */
17
+ function readFileContent(path) {
18
+ try {
19
+ if (!existsSync(path)) throw new Error("File does not exist");
20
+ if (!isValidFile(path)) throw new Error("Path is not a valid file");
21
+ return readFileSync(path, "utf8");
22
+ } catch (error) {
23
+ throw new FileOperationError("read", path, error);
24
+ }
25
+ }
26
+ /**
27
+ * Concatenate all input files and get the data.
28
+ * @param input Single file path or array of file paths
29
+ * @returns Concatenated content of all files
30
+ * @throws {FileOperationError} If any file operation fails
31
+ * @example
32
+ * getContentFromFiles('file.js')
33
+ * getContentFromFiles(['file1.js', 'file2.js'])
34
+ */
35
+ function getContentFromFiles(input) {
36
+ try {
37
+ if (!input) throw new Error("Input must be a string or array of strings");
38
+ if (!Array.isArray(input)) return readFileContent(input);
39
+ if (input.length === 0) return "";
40
+ return input.map(readFileContent).join("\n");
41
+ } catch (error) {
42
+ if (error instanceof FileOperationError) throw error;
43
+ throw new Error(`Failed to process input files: ${error instanceof Error ? error.message : String(error)}`);
44
+ }
45
+ }
46
+
47
+ //#endregion
48
+ export { getContentFromFiles };
49
+ //# sourceMappingURL=getContentFromFiles.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getContentFromFiles.js","names":["error: unknown"],"sources":["../src/getContentFromFiles.ts"],"sourcesContent":["/*!\n * node-minify\n * Copyright(c) 2011-2025 Rodolphe Stoclin\n * MIT Licensed\n */\n\nimport { existsSync, readFileSync } from \"node:fs\";\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 * 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"],"mappings":";;;;;;;;;;;;;;;;AAgBA,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;;;;;;;;;;;;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"}
@@ -0,0 +1,19 @@
1
+ //#region src/getFilesizeGzippedInBytes.d.ts
2
+ /*!
3
+ * node-minify
4
+ * Copyright(c) 2011-2025 Rodolphe Stoclin
5
+ * MIT Licensed
6
+ */
7
+ /**
8
+ * Get the gzipped file size as a human-readable string.
9
+ * @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'
15
+ */
16
+ declare function getFilesizeGzippedInBytes(file: string): Promise<string>;
17
+ //#endregion
18
+ export { getFilesizeGzippedInBytes };
19
+ //# sourceMappingURL=getFilesizeGzippedInBytes.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getFilesizeGzippedInBytes.d.ts","names":[],"sources":["../src/getFilesizeGzippedInBytes.ts"],"sourcesContent":[],"mappings":";;AAoBA;;;;;;;;;;;;;iBAAsB,yBAAA,gBAAyC"}
@@ -0,0 +1,37 @@
1
+ import { t as FileOperationError } from "./error-B_uK-F18.js";
2
+ import { t as isValidFile } from "./isValidFile-UAwceQud.js";
3
+ import { prettyBytes } from "./prettyBytes.js";
4
+ import { createReadStream, existsSync } from "node:fs";
5
+
6
+ //#region src/getFilesizeGzippedInBytes.ts
7
+ /*!
8
+ * node-minify
9
+ * Copyright(c) 2011-2025 Rodolphe Stoclin
10
+ * MIT Licensed
11
+ */
12
+ /**
13
+ * Get the gzipped file size as a human-readable string.
14
+ * @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'
20
+ */
21
+ async function getFilesizeGzippedInBytes(file) {
22
+ 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
+ }));
30
+ } catch (error) {
31
+ throw new FileOperationError("get gzipped size of", file, error);
32
+ }
33
+ }
34
+
35
+ //#endregion
36
+ export { getFilesizeGzippedInBytes };
37
+ //# sourceMappingURL=getFilesizeGzippedInBytes.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getFilesizeGzippedInBytes.js","names":[],"sources":["../src/getFilesizeGzippedInBytes.ts"],"sourcesContent":["/*!\n * node-minify\n * Copyright(c) 2011-2025 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"}
@@ -0,0 +1,17 @@
1
+ //#region src/getFilesizeInBytes.d.ts
2
+ /*!
3
+ * node-minify
4
+ * Copyright(c) 2011-2025 Rodolphe Stoclin
5
+ * MIT Licensed
6
+ */
7
+ /**
8
+ * Get the file size as a human-readable string.
9
+ * @param file - Path to the file
10
+ * @returns Formatted file size string (e.g., "1.34 kB")
11
+ * @example
12
+ * getFilesizeInBytes('bundle.js') // '45.2 kB'
13
+ */
14
+ declare const getFilesizeInBytes: (file: string) => string;
15
+ //#endregion
16
+ export { getFilesizeInBytes };
17
+ //# sourceMappingURL=getFilesizeInBytes.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getFilesizeInBytes.d.ts","names":[],"sources":["../src/getFilesizeInBytes.ts"],"sourcesContent":[],"mappings":";;AAgBA;;;;;;;;;;;cAAa"}
@@ -0,0 +1,24 @@
1
+ import { prettyBytes } from "./prettyBytes.js";
2
+ import { statSync } from "node:fs";
3
+
4
+ //#region src/getFilesizeInBytes.ts
5
+ /*!
6
+ * node-minify
7
+ * Copyright(c) 2011-2025 Rodolphe Stoclin
8
+ * MIT Licensed
9
+ */
10
+ /**
11
+ * Get the file size as a human-readable string.
12
+ * @param file - Path to the file
13
+ * @returns Formatted file size string (e.g., "1.34 kB")
14
+ * @example
15
+ * getFilesizeInBytes('bundle.js') // '45.2 kB'
16
+ */
17
+ const getFilesizeInBytes = (file) => {
18
+ const fileSizeInBytes = statSync(file).size;
19
+ return prettyBytes(fileSizeInBytes);
20
+ };
21
+
22
+ //#endregion
23
+ export { getFilesizeInBytes };
24
+ //# sourceMappingURL=getFilesizeInBytes.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getFilesizeInBytes.js","names":[],"sources":["../src/getFilesizeInBytes.ts"],"sourcesContent":["/*!\n * node-minify\n * Copyright(c) 2011-2025 Rodolphe Stoclin\n * MIT Licensed\n */\n\nimport { statSync } from \"node:fs\";\nimport { prettyBytes } from \"./prettyBytes.ts\";\n\n/**\n * Get the file size as a human-readable string.\n * @param file - Path to the file\n * @returns Formatted file size string (e.g., \"1.34 kB\")\n * @example\n * getFilesizeInBytes('bundle.js') // '45.2 kB'\n */\nexport const getFilesizeInBytes = (file: string): string => {\n const stats = statSync(file);\n const fileSizeInBytes = stats.size;\n return prettyBytes(fileSizeInBytes);\n};\n"],"mappings":";;;;;;;;;;;;;;;;AAgBA,MAAa,sBAAsB,SAAyB;CAExD,MAAM,kBADQ,SAAS,KAAK,CACE;AAC9B,QAAO,YAAY,gBAAgB"}