@node-minify/utils 10.0.0-next.0 → 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 (79) 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 +17 -131
  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 +13 -11
  78. package/dist/index.cjs +0 -165
  79. package/dist/index.d.cts +0 -31
package/dist/index.d.ts CHANGED
@@ -1,31 +1,17 @@
1
- import { OptionsPossible, Settings, MinifierOptions } from '@node-minify/types';
2
-
3
- /*!
4
- * node-minify
5
- * Copyright(c) 2011-2024 Rodolphe Stoclin
6
- * MIT Licensed
7
- */
8
-
9
- type Utils = {
10
- readFile: (file: string) => string;
11
- writeFile: ({ file, content, index }: WriteFile) => string;
12
- deleteFile: (file: string) => void;
13
- buildArgs: (options: Record<string, OptionsPossible>) => any;
14
- clone: (obj: object) => object;
15
- getFilesizeInBytes: (file: string) => string;
16
- getFilesizeGzippedInBytes: (file: string) => Promise<string>;
17
- prettyBytes: (num: number) => string;
18
- setFileNameMin: (file: string, output: string, publicFolder?: string, replaceInPlace?: boolean) => string;
19
- compressSingleFile: (settings: Settings) => string | Promise<string>;
20
- getContentFromFiles: (input: string | string[]) => string;
21
- runSync: ({ settings, content, index }: MinifierOptions) => string;
22
- runAsync: ({ settings, content, index, }: MinifierOptions) => Promise<string>;
23
- };
24
- type WriteFile = {
25
- file: string;
26
- content: any;
27
- index?: number;
28
- };
29
- declare const utils: Utils;
30
-
31
- export { utils };
1
+ import { BuildArgsOptions } from "./types.js";
2
+ import { buildArgs, toBuildArgsOptions } from "./buildArgs.js";
3
+ import { compressSingleFile } from "./compressSingleFile.js";
4
+ import { deleteFile } from "./deleteFile.js";
5
+ import { resetDeprecationWarnings, warnDeprecation } from "./deprecation.js";
6
+ import { getContentFromFiles } from "./getContentFromFiles.js";
7
+ import { getFilesizeGzippedInBytes } from "./getFilesizeGzippedInBytes.js";
8
+ import { getFilesizeInBytes } from "./getFilesizeInBytes.js";
9
+ import { isValidFile } from "./isValidFile.js";
10
+ import { prettyBytes } from "./prettyBytes.js";
11
+ import { readFile } from "./readFile.js";
12
+ import { run } from "./run.js";
13
+ import { setFileNameMin } from "./setFileNameMin.js";
14
+ import { setPublicFolder } from "./setPublicFolder.js";
15
+ import { wildcards } from "./wildcards.js";
16
+ import { writeFile } from "./writeFile.js";
17
+ export { type BuildArgsOptions, buildArgs, compressSingleFile, deleteFile, getContentFromFiles, getFilesizeGzippedInBytes, getFilesizeInBytes, isValidFile, prettyBytes, readFile, resetDeprecationWarnings, run, setFileNameMin, setPublicFolder, toBuildArgsOptions, warnDeprecation, wildcards, writeFile };
package/dist/index.js CHANGED
@@ -1,131 +1,17 @@
1
- // src/index.ts
2
- import {
3
- createReadStream,
4
- existsSync,
5
- lstatSync,
6
- readFileSync,
7
- statSync,
8
- unlinkSync,
9
- writeFileSync
10
- } from "node:fs";
11
- var utils = {};
12
- utils.readFile = (file) => readFileSync(file, "utf8");
13
- utils.writeFile = ({ file, content, index }) => {
14
- const _file = index !== void 0 ? file[index] : file;
15
- if (!existsSync(_file) || existsSync(_file) && !lstatSync(_file).isDirectory()) {
16
- writeFileSync(_file, content, "utf8");
17
- }
18
- return content;
19
- };
20
- utils.deleteFile = (file) => unlinkSync(file);
21
- utils.buildArgs = (options) => {
22
- const args = [];
23
- Object.keys(options).forEach((key) => {
24
- if (options[key] && options[key] !== false) {
25
- args.push(`--${key}`);
26
- }
27
- if (options[key] && options[key] !== true) {
28
- args.push(options[key]);
29
- }
30
- });
31
- return args;
32
- };
33
- utils.clone = (obj) => JSON.parse(JSON.stringify(obj));
34
- utils.getFilesizeInBytes = (file) => {
35
- const stats = statSync(file);
36
- const fileSizeInBytes = stats.size;
37
- return utils.prettyBytes(fileSizeInBytes);
38
- };
39
- utils.getFilesizeGzippedInBytes = async (file) => {
40
- const { gzipSizeStream } = await import("gzip-size");
41
- return new Promise((resolve) => {
42
- const source = createReadStream(file);
43
- source.pipe(gzipSizeStream()).on("gzip-size", (size) => {
44
- resolve(utils.prettyBytes(size));
45
- });
46
- });
47
- };
48
- utils.prettyBytes = (num) => {
49
- const UNITS = ["B", "kB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"];
50
- if (!Number.isFinite(num)) {
51
- throw new TypeError(
52
- `Expected a finite number, got ${typeof num}: ${num}`
53
- );
54
- }
55
- const neg = num < 0;
56
- if (neg) {
57
- num = -num;
58
- }
59
- if (num < 1) {
60
- return `${(neg ? "-" : "") + num} B`;
61
- }
62
- const exponent = Math.min(
63
- Math.floor(Math.log(num) / Math.log(1e3)),
64
- UNITS.length - 1
65
- );
66
- const numStr = Number((num / 1e3 ** exponent).toPrecision(3));
67
- const unit = UNITS[exponent];
68
- return `${(neg ? "-" : "") + numStr} ${unit}`;
69
- };
70
- utils.setFileNameMin = (file, output, publicFolder, replaceInPlace) => {
71
- const filePath = file.substr(0, file.lastIndexOf("/") + 1);
72
- const fileWithoutPath = file.substr(file.lastIndexOf("/") + 1);
73
- let fileWithoutExtension = fileWithoutPath.substr(
74
- 0,
75
- fileWithoutPath.lastIndexOf(".")
76
- );
77
- if (publicFolder) {
78
- fileWithoutExtension = publicFolder + fileWithoutExtension;
79
- }
80
- if (replaceInPlace) {
81
- fileWithoutExtension = filePath + fileWithoutExtension;
82
- }
83
- return output.replace("$1", fileWithoutExtension);
84
- };
85
- utils.compressSingleFile = (settings) => {
86
- const content = settings.content ? settings.content : settings.input ? utils.getContentFromFiles(settings.input) : "";
87
- return settings.sync ? utils.runSync({ settings, content }) : utils.runAsync({ settings, content });
88
- };
89
- utils.getContentFromFiles = (input) => {
90
- if (!Array.isArray(input)) {
91
- return readFileSync(input, "utf8");
92
- }
93
- return input.map(
94
- (path) => !existsSync(path) || existsSync(path) && !lstatSync(path).isDirectory() ? readFileSync(path, "utf8") : ""
95
- ).join("\n");
96
- };
97
- utils.runSync = ({ settings, content, index }) => settings && typeof settings.compressor !== "string" ? typeof settings.compressor === "function" ? String(
98
- settings.compressor({
99
- settings,
100
- content,
101
- callback: null,
102
- index
103
- }) || ""
104
- ) : "" : "";
105
- utils.runAsync = ({
106
- settings,
107
- content,
108
- index
109
- }) => {
110
- return new Promise((resolve, reject) => {
111
- settings?.compressor && typeof settings.compressor !== "string" ? settings.compressor({
112
- settings,
113
- content,
114
- callback: (err, result) => {
115
- if (err) {
116
- return reject(err);
117
- }
118
- resolve(result || "");
119
- },
120
- index
121
- }) : null;
122
- });
123
- };
124
- export {
125
- utils
126
- };
127
- /*!
128
- * node-minify
129
- * Copyright(c) 2011-2024 Rodolphe Stoclin
130
- * MIT Licensed
131
- */
1
+ import { buildArgs, toBuildArgsOptions } from "./buildArgs.js";
2
+ import { t as isValidFile } from "./isValidFile-UAwceQud.js";
3
+ import { getContentFromFiles } from "./getContentFromFiles.js";
4
+ import { t as writeFile } from "./writeFile-CwK9ZWXr.js";
5
+ import { run } from "./run.js";
6
+ import { compressSingleFile } from "./compressSingleFile.js";
7
+ import { deleteFile } from "./deleteFile.js";
8
+ import { resetDeprecationWarnings, warnDeprecation } from "./deprecation.js";
9
+ import { prettyBytes } from "./prettyBytes.js";
10
+ import { getFilesizeGzippedInBytes } from "./getFilesizeGzippedInBytes.js";
11
+ import { getFilesizeInBytes } from "./getFilesizeInBytes.js";
12
+ import { readFile } from "./readFile.js";
13
+ import { setFileNameMin } from "./setFileNameMin.js";
14
+ import { setPublicFolder } from "./setPublicFolder.js";
15
+ import { wildcards } from "./wildcards.js";
16
+
17
+ export { buildArgs, compressSingleFile, deleteFile, getContentFromFiles, getFilesizeGzippedInBytes, getFilesizeInBytes, isValidFile, prettyBytes, readFile, resetDeprecationWarnings, run, setFileNameMin, setPublicFolder, toBuildArgsOptions, warnDeprecation, wildcards, writeFile };
@@ -0,0 +1,30 @@
1
+ import { t as FileOperationError } from "./error-B_uK-F18.js";
2
+ import { existsSync, lstatSync } from "node:fs";
3
+
4
+ //#region src/isValidFile.ts
5
+ /*!
6
+ * node-minify
7
+ * Copyright(c) 2011-2025 Rodolphe Stoclin
8
+ * MIT Licensed
9
+ */
10
+ /**
11
+ * Check if the path is a valid file.
12
+ * @param path Path to check
13
+ * @returns true if path exists and is a file, false otherwise
14
+ * @throws {FileOperationError} If filesystem operations fail
15
+ * @example
16
+ * if (isValidFile('path/to/file.js')) {
17
+ * // do something
18
+ * }
19
+ */
20
+ function isValidFile(path) {
21
+ try {
22
+ return existsSync(path) && !lstatSync(path).isDirectory();
23
+ } catch (error) {
24
+ throw new FileOperationError("validate", path, error);
25
+ }
26
+ }
27
+
28
+ //#endregion
29
+ export { isValidFile as t };
30
+ //# sourceMappingURL=isValidFile-UAwceQud.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"isValidFile-UAwceQud.js","names":[],"sources":["../src/isValidFile.ts"],"sourcesContent":["/*!\n * node-minify\n * Copyright(c) 2011-2025 Rodolphe Stoclin\n * MIT Licensed\n */\n\nimport { existsSync, lstatSync } from \"node:fs\";\nimport { 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"],"mappings":";;;;;;;;;;;;;;;;;;;AAmBA,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"}
@@ -0,0 +1,20 @@
1
+ //#region src/isValidFile.d.ts
2
+ /*!
3
+ * node-minify
4
+ * Copyright(c) 2011-2025 Rodolphe Stoclin
5
+ * MIT Licensed
6
+ */
7
+ /**
8
+ * Check if the path is a valid file.
9
+ * @param path Path to check
10
+ * @returns true if path exists and is a file, false otherwise
11
+ * @throws {FileOperationError} If filesystem operations fail
12
+ * @example
13
+ * if (isValidFile('path/to/file.js')) {
14
+ * // do something
15
+ * }
16
+ */
17
+ declare function isValidFile(path: string): boolean;
18
+ //#endregion
19
+ export { isValidFile };
20
+ //# sourceMappingURL=isValidFile.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"isValidFile.d.ts","names":[],"sources":["../src/isValidFile.ts"],"sourcesContent":[],"mappings":";;AAmBA;;;;;;;;;;;;;;iBAAgB,WAAA"}
@@ -0,0 +1,3 @@
1
+ import { t as isValidFile } from "./isValidFile-UAwceQud.js";
2
+
3
+ export { isValidFile };
@@ -0,0 +1,20 @@
1
+ //#region src/prettyBytes.d.ts
2
+ /*!
3
+ * node-minify
4
+ * Copyright(c) 2011-2025 Rodolphe Stoclin
5
+ * MIT Licensed
6
+ */
7
+ /**
8
+ * Get the size in human readable format.
9
+ * From https://github.com/sindresorhus/pretty-bytes
10
+ * @param num Number of bytes
11
+ * @returns Human readable string
12
+ * @throws {ValidationError} If input is not a finite number
13
+ * @example
14
+ * prettyBytes(1337) // '1.34 kB'
15
+ * prettyBytes(100) // '100 B'
16
+ */
17
+ declare function prettyBytes(num: number): string;
18
+ //#endregion
19
+ export { prettyBytes };
20
+ //# sourceMappingURL=prettyBytes.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"prettyBytes.d.ts","names":[],"sources":["../src/prettyBytes.ts"],"sourcesContent":[],"mappings":";;AAoBA;;;;;;;;;;;;;;iBAAgB,WAAA"}
@@ -0,0 +1,43 @@
1
+ import { n as ValidationError } from "./error-B_uK-F18.js";
2
+
3
+ //#region src/prettyBytes.ts
4
+ /*!
5
+ * node-minify
6
+ * Copyright(c) 2011-2025 Rodolphe Stoclin
7
+ * MIT Licensed
8
+ */
9
+ const UNITS = [
10
+ "B",
11
+ "kB",
12
+ "MB",
13
+ "GB",
14
+ "TB",
15
+ "PB",
16
+ "EB",
17
+ "ZB",
18
+ "YB"
19
+ ];
20
+ /**
21
+ * Get the size in human readable format.
22
+ * From https://github.com/sindresorhus/pretty-bytes
23
+ * @param num Number of bytes
24
+ * @returns Human readable string
25
+ * @throws {ValidationError} If input is not a finite number
26
+ * @example
27
+ * prettyBytes(1337) // '1.34 kB'
28
+ * prettyBytes(100) // '100 B'
29
+ */
30
+ function prettyBytes(num) {
31
+ if (!Number.isFinite(num)) throw new ValidationError(`Expected a finite number, got ${typeof num}: ${num}`);
32
+ const neg = num < 0;
33
+ const absoluteNum = Math.abs(num);
34
+ if (absoluteNum < 1) return `${neg ? "-" : ""}${absoluteNum} B`;
35
+ const exponent = Math.min(Math.floor(Math.log(absoluteNum) / Math.log(1e3)), UNITS.length - 1);
36
+ const numStr = Number((absoluteNum / 1e3 ** exponent).toPrecision(3));
37
+ const unit = UNITS[exponent];
38
+ return `${neg ? "-" : ""}${numStr} ${unit}`;
39
+ }
40
+
41
+ //#endregion
42
+ export { prettyBytes };
43
+ //# sourceMappingURL=prettyBytes.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"prettyBytes.js","names":[],"sources":["../src/prettyBytes.ts"],"sourcesContent":["/*!\n * node-minify\n * Copyright(c) 2011-2025 Rodolphe Stoclin\n * MIT Licensed\n */\n\nimport { ValidationError } from \"./error.ts\";\n\nconst UNITS = [\"B\", \"kB\", \"MB\", \"GB\", \"TB\", \"PB\", \"EB\", \"ZB\", \"YB\"] as const;\n\n/**\n * Get the size in human readable format.\n * From https://github.com/sindresorhus/pretty-bytes\n * @param num Number of bytes\n * @returns Human readable string\n * @throws {ValidationError} If input is not a finite number\n * @example\n * prettyBytes(1337) // '1.34 kB'\n * prettyBytes(100) // '100 B'\n */\nexport function prettyBytes(num: number): string {\n if (!Number.isFinite(num)) {\n throw new ValidationError(\n `Expected a finite number, got ${typeof num}: ${num}`\n );\n }\n\n const neg = num < 0;\n const absoluteNum = Math.abs(num);\n\n if (absoluteNum < 1) {\n return `${neg ? \"-\" : \"\"}${absoluteNum} B`;\n }\n\n const exponent = Math.min(\n Math.floor(Math.log(absoluteNum) / Math.log(1000)),\n UNITS.length - 1\n );\n\n const numStr = Number((absoluteNum / 1000 ** exponent).toPrecision(3));\n const unit = UNITS[exponent];\n\n return `${neg ? \"-\" : \"\"}${numStr} ${unit}`;\n}\n"],"mappings":";;;;;;;;AAQA,MAAM,QAAQ;CAAC;CAAK;CAAM;CAAM;CAAM;CAAM;CAAM;CAAM;CAAM;CAAK;;;;;;;;;;;AAYnE,SAAgB,YAAY,KAAqB;AAC7C,KAAI,CAAC,OAAO,SAAS,IAAI,CACrB,OAAM,IAAI,gBACN,iCAAiC,OAAO,IAAI,IAAI,MACnD;CAGL,MAAM,MAAM,MAAM;CAClB,MAAM,cAAc,KAAK,IAAI,IAAI;AAEjC,KAAI,cAAc,EACd,QAAO,GAAG,MAAM,MAAM,KAAK,YAAY;CAG3C,MAAM,WAAW,KAAK,IAClB,KAAK,MAAM,KAAK,IAAI,YAAY,GAAG,KAAK,IAAI,IAAK,CAAC,EAClD,MAAM,SAAS,EAClB;CAED,MAAM,SAAS,QAAQ,cAAc,OAAQ,UAAU,YAAY,EAAE,CAAC;CACtE,MAAM,OAAO,MAAM;AAEnB,QAAO,GAAG,MAAM,MAAM,KAAK,OAAO,GAAG"}
@@ -0,0 +1,15 @@
1
+ //#region src/readFile.d.ts
2
+ /*!
3
+ * node-minify
4
+ * Copyright(c) 2011-2025 Rodolphe Stoclin
5
+ * MIT Licensed
6
+ */
7
+ /**
8
+ * Read content from file.
9
+ * @param file - Path to file
10
+ * @returns File content as string
11
+ */
12
+ declare function readFile(file: string): string;
13
+ //#endregion
14
+ export { readFile };
15
+ //# sourceMappingURL=readFile.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"readFile.d.ts","names":[],"sources":["../src/readFile.ts"],"sourcesContent":[],"mappings":";;AAaA;;;;;;;;;iBAAgB,QAAA"}
@@ -0,0 +1,20 @@
1
+ import { readFileSync } from "node:fs";
2
+
3
+ //#region src/readFile.ts
4
+ /*!
5
+ * node-minify
6
+ * Copyright(c) 2011-2025 Rodolphe Stoclin
7
+ * MIT Licensed
8
+ */
9
+ /**
10
+ * Read content from file.
11
+ * @param file - Path to file
12
+ * @returns File content as string
13
+ */
14
+ function readFile(file) {
15
+ return readFileSync(file, "utf8");
16
+ }
17
+
18
+ //#endregion
19
+ export { readFile };
20
+ //# sourceMappingURL=readFile.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"readFile.js","names":[],"sources":["../src/readFile.ts"],"sourcesContent":["/*!\n * node-minify\n * Copyright(c) 2011-2025 Rodolphe Stoclin\n * MIT Licensed\n */\n\nimport { readFileSync } from \"node:fs\";\n\n/**\n * Read content from file.\n * @param file - Path to file\n * @returns File content as string\n */\nexport function readFile(file: string): string {\n return readFileSync(file, \"utf8\");\n}\n"],"mappings":";;;;;;;;;;;;;AAaA,SAAgB,SAAS,MAAsB;AAC3C,QAAO,aAAa,MAAM,OAAO"}
package/dist/run.d.ts ADDED
@@ -0,0 +1,23 @@
1
+ import { t as Settings } from "./types-DtDQlx-T.js";
2
+
3
+ //#region src/run.d.ts
4
+
5
+ interface RunParameters {
6
+ settings: Settings;
7
+ content?: string;
8
+ index?: number;
9
+ }
10
+ /**
11
+ * Execute the compressor and write output.
12
+ * @param params - Run parameters containing settings, content, and index
13
+ * @returns Minified content string
14
+ * @throws {ValidationError} If settings or compressor is missing
15
+ */
16
+ declare function run({
17
+ settings,
18
+ content,
19
+ index
20
+ }: RunParameters): Promise<string>;
21
+ //#endregion
22
+ export { run };
23
+ //# sourceMappingURL=run.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"run.d.ts","names":[],"sources":["../src/run.ts"],"sourcesContent":[],"mappings":";;;;UAUU,aAAA,CAcN;EACA,QAAA,EAdU,QAcV;EACD,OAAA,CAAA,EAAA,MAAA;EAAgB,KAAA,CAAA,EAAA,MAAA;;;;;;;;iBAJG,GAAA;;;;GAInB,gBAAgB"}
package/dist/run.js ADDED
@@ -0,0 +1,52 @@
1
+ import { n as ValidationError } from "./error-B_uK-F18.js";
2
+ import { t as writeFile } from "./writeFile-CwK9ZWXr.js";
3
+
4
+ //#region src/run.ts
5
+ /**
6
+ * Execute the compressor and write output.
7
+ * @param params - Run parameters containing settings, content, and index
8
+ * @returns Minified content string
9
+ * @throws {ValidationError} If settings or compressor is missing
10
+ */
11
+ async function run({ settings, content, index }) {
12
+ if (!settings) throw new ValidationError("Settings must be provided");
13
+ if (!settings.compressor) throw new ValidationError("Compressor must be provided in settings");
14
+ const result = await settings.compressor({
15
+ settings,
16
+ content,
17
+ index
18
+ });
19
+ writeOutput(result, settings, index);
20
+ return result.code;
21
+ }
22
+ function writeOutput(result, settings, index) {
23
+ if (Boolean(settings.content) || !settings.output) return;
24
+ writeFile({
25
+ file: settings.output,
26
+ content: result.code,
27
+ index
28
+ });
29
+ if (result.map) {
30
+ const sourceMapUrl = getSourceMapUrl(settings);
31
+ if (sourceMapUrl) writeFile({
32
+ file: sourceMapUrl,
33
+ content: result.map,
34
+ index
35
+ });
36
+ }
37
+ }
38
+ function getSourceMapUrl(settings) {
39
+ const options = settings.options;
40
+ if (!options) return;
41
+ const sourceMap = options.sourceMap;
42
+ if (sourceMap) {
43
+ if (typeof sourceMap.url === "string") return sourceMap.url;
44
+ if (typeof sourceMap.filename === "string") return sourceMap.filename;
45
+ }
46
+ const _sourceMap = options._sourceMap;
47
+ if (_sourceMap && typeof _sourceMap.url === "string") return _sourceMap.url;
48
+ }
49
+
50
+ //#endregion
51
+ export { run };
52
+ //# sourceMappingURL=run.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"run.js","names":[],"sources":["../src/run.ts"],"sourcesContent":["/*!\n * node-minify\n * Copyright(c) 2011-2025 Rodolphe Stoclin\n * MIT Licensed\n */\n\nimport type { CompressorResult, Settings } from \"@node-minify/types\";\nimport { ValidationError } from \"./error.ts\";\nimport { writeFile } from \"./writeFile.ts\";\n\ninterface RunParameters {\n settings: Settings;\n content?: string;\n index?: number;\n}\n\n/**\n * Execute the compressor and write output.\n * @param params - Run parameters containing settings, content, and index\n * @returns Minified content string\n * @throws {ValidationError} If settings or compressor is missing\n */\nexport async function run({\n settings,\n content,\n index,\n}: RunParameters): 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 writeOutput(result, settings, index);\n\n return result.code;\n}\n\nfunction writeOutput(\n result: CompressorResult,\n settings: Settings,\n index?: number\n): void {\n const isInMemoryMode = Boolean(settings.content);\n if (isInMemoryMode || !settings.output) {\n return;\n }\n\n writeFile({ file: settings.output, content: result.code, index });\n\n if (result.map) {\n const sourceMapUrl = getSourceMapUrl(settings);\n if (sourceMapUrl) {\n writeFile({ file: sourceMapUrl, content: result.map, index });\n }\n }\n}\n\nfunction getSourceMapUrl(settings: Settings): 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":";;;;;;;;;;AAsBA,eAAsB,IAAI,EACtB,UACA,SACA,SAC+B;AAC/B,KAAI,CAAC,SACD,OAAM,IAAI,gBAAgB,4BAA4B;AAG1D,KAAI,CAAC,SAAS,WACV,OAAM,IAAI,gBAAgB,0CAA0C;CAGxE,MAAM,SAAS,MAAM,SAAS,WAAW;EACrC;EACA;EACA;EACH,CAAC;AAEF,aAAY,QAAQ,UAAU,MAAM;AAEpC,QAAO,OAAO;;AAGlB,SAAS,YACL,QACA,UACA,OACI;AAEJ,KADuB,QAAQ,SAAS,QAAQ,IAC1B,CAAC,SAAS,OAC5B;AAGJ,WAAU;EAAE,MAAM,SAAS;EAAQ,SAAS,OAAO;EAAM;EAAO,CAAC;AAEjE,KAAI,OAAO,KAAK;EACZ,MAAM,eAAe,gBAAgB,SAAS;AAC9C,MAAI,aACA,WAAU;GAAE,MAAM;GAAc,SAAS,OAAO;GAAK;GAAO,CAAC;;;AAKzE,SAAS,gBAAgB,UAAwC;CAC7D,MAAM,UAAU,SAAS;AACzB,KAAI,CAAC,QACD;CAGJ,MAAM,YAAY,QAAQ;AAC1B,KAAI,WAAW;AACX,MAAI,OAAO,UAAU,QAAQ,SACzB,QAAO,UAAU;AAErB,MAAI,OAAO,UAAU,aAAa,SAC9B,QAAO,UAAU;;CAIzB,MAAM,aAAa,QAAQ;AAG3B,KAAI,cAAc,OAAO,WAAW,QAAQ,SACxC,QAAO,WAAW"}
@@ -0,0 +1,22 @@
1
+ //#region src/setFileNameMin.d.ts
2
+ /*!
3
+ * node-minify
4
+ * Copyright(c) 2011-2025 Rodolphe Stoclin
5
+ * MIT Licensed
6
+ */
7
+ /**
8
+ * Set the file name as minified.
9
+ * @param file Original file path
10
+ * @param output Output pattern (use $1 as placeholder for filename)
11
+ * @param publicFolder Optional public folder prefix
12
+ * @param replaceInPlace Whether to keep original path
13
+ * @returns Minified file path
14
+ * @throws {ValidationError} If input parameters are invalid
15
+ * @example
16
+ * setFileNameMin('src/file.js', '$1.min.js') // 'src/file.min.js'
17
+ * setFileNameMin('file.js', '$1.min.js', 'public/') // 'public/file.min.js'
18
+ */
19
+ declare function setFileNameMin(file: string, output: string, publicFolder?: string, replaceInPlace?: boolean): string;
20
+ //#endregion
21
+ export { setFileNameMin };
22
+ //# sourceMappingURL=setFileNameMin.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"setFileNameMin.d.ts","names":[],"sources":["../src/setFileNameMin.ts"],"sourcesContent":[],"mappings":";;AAoBA;;;;;;;;;;;;;;;;iBAAgB,cAAA"}
@@ -0,0 +1,45 @@
1
+ import { n as ValidationError } from "./error-B_uK-F18.js";
2
+
3
+ //#region src/setFileNameMin.ts
4
+ /*!
5
+ * node-minify
6
+ * Copyright(c) 2011-2025 Rodolphe Stoclin
7
+ * MIT Licensed
8
+ */
9
+ /**
10
+ * Set the file name as minified.
11
+ * @param file Original file path
12
+ * @param output Output pattern (use $1 as placeholder for filename)
13
+ * @param publicFolder Optional public folder prefix
14
+ * @param replaceInPlace Whether to keep original path
15
+ * @returns Minified file path
16
+ * @throws {ValidationError} If input parameters are invalid
17
+ * @example
18
+ * setFileNameMin('src/file.js', '$1.min.js') // 'src/file.min.js'
19
+ * setFileNameMin('file.js', '$1.min.js', 'public/') // 'public/file.min.js'
20
+ */
21
+ function setFileNameMin(file, output, publicFolder, replaceInPlace) {
22
+ if (!file || typeof file !== "string") throw new ValidationError("File path must be a non-empty string");
23
+ if (!output || typeof output !== "string" || !output.includes("$1")) throw new ValidationError("Output pattern must be a string containing \"$1\"");
24
+ try {
25
+ const lastSlashIndex = file.lastIndexOf("/");
26
+ const filePath = file.substring(0, lastSlashIndex + 1);
27
+ const fileWithoutPath = file.substring(lastSlashIndex + 1);
28
+ const lastDotIndex = fileWithoutPath.lastIndexOf(".");
29
+ if (lastDotIndex === -1) throw new ValidationError("File must have an extension");
30
+ let fileWithoutExtension = fileWithoutPath.substring(0, lastDotIndex);
31
+ if (publicFolder) {
32
+ if (typeof publicFolder !== "string") throw new ValidationError("Public folder must be a string");
33
+ fileWithoutExtension = publicFolder + fileWithoutExtension;
34
+ }
35
+ if (replaceInPlace) fileWithoutExtension = filePath + fileWithoutExtension;
36
+ return output.replace("$1", fileWithoutExtension);
37
+ } catch (error) {
38
+ if (error instanceof ValidationError) throw error;
39
+ throw new ValidationError(`Failed to process file name: ${error instanceof Error ? error.message : String(error)}`);
40
+ }
41
+ }
42
+
43
+ //#endregion
44
+ export { setFileNameMin };
45
+ //# sourceMappingURL=setFileNameMin.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"setFileNameMin.js","names":[],"sources":["../src/setFileNameMin.ts"],"sourcesContent":["/*!\n * node-minify\n * Copyright(c) 2011-2025 Rodolphe Stoclin\n * MIT Licensed\n */\n\nimport { ValidationError } from \"./error.ts\";\n\n/**\n * Set the file name as minified.\n * @param file Original file path\n * @param output Output pattern (use $1 as placeholder for filename)\n * @param publicFolder Optional public folder prefix\n * @param replaceInPlace Whether to keep original path\n * @returns Minified file path\n * @throws {ValidationError} If input parameters are invalid\n * @example\n * setFileNameMin('src/file.js', '$1.min.js') // 'src/file.min.js'\n * setFileNameMin('file.js', '$1.min.js', 'public/') // 'public/file.min.js'\n */\nexport function setFileNameMin(\n file: string,\n output: string,\n publicFolder?: string,\n replaceInPlace?: boolean\n): string {\n if (!file || typeof file !== \"string\") {\n throw new ValidationError(\"File path must be a non-empty string\");\n }\n\n if (!output || typeof output !== \"string\" || !output.includes(\"$1\")) {\n throw new ValidationError(\n 'Output pattern must be a string containing \"$1\"'\n );\n }\n\n try {\n const lastSlashIndex = file.lastIndexOf(\"/\");\n const filePath = file.substring(0, lastSlashIndex + 1);\n const fileWithoutPath = file.substring(lastSlashIndex + 1);\n const lastDotIndex = fileWithoutPath.lastIndexOf(\".\");\n\n if (lastDotIndex === -1) {\n throw new ValidationError(\"File must have an extension\");\n }\n\n let fileWithoutExtension = fileWithoutPath.substring(0, lastDotIndex);\n\n if (publicFolder) {\n if (typeof publicFolder !== \"string\") {\n throw new ValidationError(\"Public folder must be a string\");\n }\n fileWithoutExtension = publicFolder + fileWithoutExtension;\n }\n\n if (replaceInPlace) {\n fileWithoutExtension = filePath + fileWithoutExtension;\n }\n\n return output.replace(\"$1\", fileWithoutExtension);\n } catch (error) {\n if (error instanceof ValidationError) {\n throw error;\n }\n throw new ValidationError(\n `Failed to process file name: ${error instanceof Error ? error.message : String(error)}`\n );\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAoBA,SAAgB,eACZ,MACA,QACA,cACA,gBACM;AACN,KAAI,CAAC,QAAQ,OAAO,SAAS,SACzB,OAAM,IAAI,gBAAgB,uCAAuC;AAGrE,KAAI,CAAC,UAAU,OAAO,WAAW,YAAY,CAAC,OAAO,SAAS,KAAK,CAC/D,OAAM,IAAI,gBACN,oDACH;AAGL,KAAI;EACA,MAAM,iBAAiB,KAAK,YAAY,IAAI;EAC5C,MAAM,WAAW,KAAK,UAAU,GAAG,iBAAiB,EAAE;EACtD,MAAM,kBAAkB,KAAK,UAAU,iBAAiB,EAAE;EAC1D,MAAM,eAAe,gBAAgB,YAAY,IAAI;AAErD,MAAI,iBAAiB,GACjB,OAAM,IAAI,gBAAgB,8BAA8B;EAG5D,IAAI,uBAAuB,gBAAgB,UAAU,GAAG,aAAa;AAErE,MAAI,cAAc;AACd,OAAI,OAAO,iBAAiB,SACxB,OAAM,IAAI,gBAAgB,iCAAiC;AAE/D,0BAAuB,eAAe;;AAG1C,MAAI,eACA,wBAAuB,WAAW;AAGtC,SAAO,OAAO,QAAQ,MAAM,qBAAqB;UAC5C,OAAO;AACZ,MAAI,iBAAiB,gBACjB,OAAM;AAEV,QAAM,IAAI,gBACN,gCAAgC,iBAAiB,QAAQ,MAAM,UAAU,OAAO,MAAM,GACzF"}
@@ -0,0 +1,19 @@
1
+ //#region src/setPublicFolder.d.ts
2
+ /*!
3
+ * node-minify
4
+ * Copyright(c) 2011-2025 Rodolphe Stoclin
5
+ * MIT Licensed
6
+ */
7
+ /**
8
+ * Prepend the public folder to each file.
9
+ * @param input Path to file(s)
10
+ * @param publicFolder Path to the public folder
11
+ */
12
+ declare function setPublicFolder(input: string | string[], publicFolder: string): {
13
+ input?: undefined;
14
+ } | {
15
+ input: string | string[];
16
+ };
17
+ //#endregion
18
+ export { setPublicFolder };
19
+ //# sourceMappingURL=setPublicFolder.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"setPublicFolder.d.ts","names":[],"sources":["../src/setPublicFolder.ts"],"sourcesContent":[],"mappings":";;AAaA;;;;;;;;;iBAAgB,eAAA"}
@@ -0,0 +1,26 @@
1
+ import path from "node:path";
2
+
3
+ //#region src/setPublicFolder.ts
4
+ /*!
5
+ * node-minify
6
+ * Copyright(c) 2011-2025 Rodolphe Stoclin
7
+ * MIT Licensed
8
+ */
9
+ /**
10
+ * Prepend the public folder to each file.
11
+ * @param input Path to file(s)
12
+ * @param publicFolder Path to the public folder
13
+ */
14
+ function setPublicFolder(input, publicFolder) {
15
+ if (typeof publicFolder !== "string") return {};
16
+ const normalizedPublicFolder = path.normalize(publicFolder);
17
+ const addPublicFolder = (item) => {
18
+ const normalizedPath = path.normalize(item);
19
+ return normalizedPath.includes(normalizedPublicFolder) ? normalizedPath : path.normalize(normalizedPublicFolder + item);
20
+ };
21
+ return { input: Array.isArray(input) ? input.map(addPublicFolder) : addPublicFolder(input) };
22
+ }
23
+
24
+ //#endregion
25
+ export { setPublicFolder };
26
+ //# sourceMappingURL=setPublicFolder.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"setPublicFolder.js","names":[],"sources":["../src/setPublicFolder.ts"],"sourcesContent":["/*!\n * node-minify\n * Copyright(c) 2011-2025 Rodolphe Stoclin\n * MIT Licensed\n */\n\nimport path from \"node:path\";\n\n/**\n * Prepend the public folder to each file.\n * @param input Path to file(s)\n * @param publicFolder Path to the public folder\n */\nexport function setPublicFolder(\n input: string | string[],\n publicFolder: string\n) {\n if (typeof publicFolder !== \"string\") {\n return {};\n }\n\n const normalizedPublicFolder = path.normalize(publicFolder);\n\n const addPublicFolder = (item: string) => {\n const normalizedPath = path.normalize(item);\n return normalizedPath.includes(normalizedPublicFolder)\n ? normalizedPath\n : path.normalize(normalizedPublicFolder + item);\n };\n\n return {\n input: Array.isArray(input)\n ? input.map(addPublicFolder)\n : addPublicFolder(input),\n };\n}\n"],"mappings":";;;;;;;;;;;;;AAaA,SAAgB,gBACZ,OACA,cACF;AACE,KAAI,OAAO,iBAAiB,SACxB,QAAO,EAAE;CAGb,MAAM,yBAAyB,KAAK,UAAU,aAAa;CAE3D,MAAM,mBAAmB,SAAiB;EACtC,MAAM,iBAAiB,KAAK,UAAU,KAAK;AAC3C,SAAO,eAAe,SAAS,uBAAuB,GAChD,iBACA,KAAK,UAAU,yBAAyB,KAAK;;AAGvD,QAAO,EACH,OAAO,MAAM,QAAQ,MAAM,GACrB,MAAM,IAAI,gBAAgB,GAC1B,gBAAgB,MAAM,EAC/B"}