@node-minify/utils 10.1.1 → 10.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -1
- package/README.md +4 -4
- package/dist/buildArgs.js +2 -2
- package/dist/buildArgs.js.map +1 -1
- package/dist/compressSingleFile.d.ts +6 -4
- package/dist/compressSingleFile.d.ts.map +1 -1
- package/dist/compressSingleFile.js +27 -9
- package/dist/compressSingleFile.js.map +1 -1
- package/dist/compressor-resolver.d.ts +46 -0
- package/dist/compressor-resolver.d.ts.map +1 -0
- package/dist/compressor-resolver.js +155 -0
- package/dist/compressor-resolver.js.map +1 -0
- package/dist/deleteFile.d.ts +1 -1
- package/dist/deleteFile.js +2 -2
- package/dist/deleteFile.js.map +1 -1
- package/dist/deprecation.d.ts +1 -1
- package/dist/deprecation.js +1 -1
- package/dist/deprecation.js.map +1 -1
- package/dist/ensureStringContent.d.ts +18 -0
- package/dist/ensureStringContent.d.ts.map +1 -0
- package/dist/ensureStringContent.js +23 -0
- package/dist/ensureStringContent.js.map +1 -0
- package/dist/{error-B_uK-F18.js → error-Ctspysdk.js} +5 -3
- package/dist/error-Ctspysdk.js.map +1 -0
- package/dist/error.d.ts +2 -1
- package/dist/error.d.ts.map +1 -1
- package/dist/error.js +1 -1
- package/dist/getContentFromFiles.d.ts +11 -2
- package/dist/getContentFromFiles.d.ts.map +1 -1
- package/dist/getContentFromFiles.js +38 -4
- package/dist/getContentFromFiles.js.map +1 -1
- package/dist/getFilesizeBrotliInBytes.d.ts +10 -0
- package/dist/getFilesizeBrotliInBytes.d.ts.map +1 -0
- package/dist/getFilesizeBrotliInBytes.js +29 -0
- package/dist/getFilesizeBrotliInBytes.js.map +1 -0
- package/dist/getFilesizeGzippedInBytes.d.ts +1 -1
- package/dist/getFilesizeGzippedInBytes.js +3 -3
- package/dist/getFilesizeGzippedInBytes.js.map +1 -1
- package/dist/getFilesizeInBytes.d.ts +1 -1
- package/dist/getFilesizeInBytes.js +1 -1
- package/dist/getFilesizeInBytes.js.map +1 -1
- package/dist/index.d.ts +9 -5
- package/dist/index.js +9 -5
- package/dist/isImageFile.d.ts +16 -0
- package/dist/isImageFile.d.ts.map +1 -0
- package/dist/isImageFile.js +35 -0
- package/dist/isImageFile.js.map +1 -0
- package/dist/isValidFile-BW5AgBWb.js +46 -0
- package/dist/isValidFile-BW5AgBWb.js.map +1 -0
- package/dist/isValidFile.d.ts +10 -2
- package/dist/isValidFile.d.ts.map +1 -1
- package/dist/isValidFile.js +2 -2
- package/dist/prettyBytes.d.ts +1 -1
- package/dist/prettyBytes.js +2 -2
- package/dist/prettyBytes.js.map +1 -1
- package/dist/readFile.d.ts +25 -3
- package/dist/readFile.d.ts.map +1 -1
- package/dist/readFile.js +31 -7
- package/dist/readFile.js.map +1 -1
- package/dist/run.d.ts +10 -12
- package/dist/run.d.ts.map +1 -1
- package/dist/run.js +114 -12
- package/dist/run.js.map +1 -1
- package/dist/setFileNameMin.d.ts +1 -1
- package/dist/setFileNameMin.js +2 -2
- package/dist/setFileNameMin.js.map +1 -1
- package/dist/setPublicFolder.d.ts +1 -1
- package/dist/setPublicFolder.js +1 -1
- package/dist/setPublicFolder.js.map +1 -1
- package/dist/{types-DtDQlx-T.d.ts → types-CzkB7gxg.d.ts} +51 -4
- package/dist/types-CzkB7gxg.d.ts.map +1 -0
- package/dist/types.d.ts +1 -1
- package/dist/wildcards.d.ts +1 -1
- package/dist/wildcards.js +1 -1
- package/dist/wildcards.js.map +1 -1
- package/dist/writeFile-DgV8EbFP.js +123 -0
- package/dist/writeFile-DgV8EbFP.js.map +1 -0
- package/dist/writeFile.d.ts +30 -10
- package/dist/writeFile.d.ts.map +1 -1
- package/dist/writeFile.js +2 -2
- package/package.json +2 -2
- package/dist/error-B_uK-F18.js.map +0 -1
- package/dist/isValidFile-UAwceQud.js +0 -30
- package/dist/isValidFile-UAwceQud.js.map +0 -1
- package/dist/types-DtDQlx-T.d.ts.map +0 -1
- package/dist/writeFile-CwK9ZWXr.js +0 -37
- package/dist/writeFile-CwK9ZWXr.js.map +0 -1
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
import { t as FileOperationError } from "./error-
|
|
2
|
-
import { t as isValidFile } from "./isValidFile-
|
|
1
|
+
import { t as FileOperationError } from "./error-Ctspysdk.js";
|
|
2
|
+
import { t as isValidFile } from "./isValidFile-BW5AgBWb.js";
|
|
3
3
|
import { existsSync, readFileSync } from "node:fs";
|
|
4
|
+
import { readFile } from "node:fs/promises";
|
|
4
5
|
|
|
5
6
|
//#region src/getContentFromFiles.ts
|
|
6
7
|
/*!
|
|
7
8
|
* node-minify
|
|
8
|
-
* Copyright(c) 2011-
|
|
9
|
+
* Copyright (c) 2011-2026 Rodolphe Stoclin
|
|
9
10
|
* MIT Licensed
|
|
10
11
|
*/
|
|
11
12
|
/**
|
|
@@ -24,6 +25,20 @@ function readFileContent(path) {
|
|
|
24
25
|
}
|
|
25
26
|
}
|
|
26
27
|
/**
|
|
28
|
+
* Read the UTF-8 content of a single file.
|
|
29
|
+
*
|
|
30
|
+
* @param path - Filesystem path to the file
|
|
31
|
+
* @returns The file content as a string
|
|
32
|
+
* @throws FileOperationError if the file does not exist, the path is a directory, or reading the file fails
|
|
33
|
+
*/
|
|
34
|
+
async function readFileContentAsync(path) {
|
|
35
|
+
try {
|
|
36
|
+
return await readFile(path, "utf8");
|
|
37
|
+
} catch (error) {
|
|
38
|
+
throw new FileOperationError("read", path, error);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
27
42
|
* Concatenate all input files and get the data.
|
|
28
43
|
* @param input Single file path or array of file paths
|
|
29
44
|
* @returns Concatenated content of all files
|
|
@@ -43,7 +58,26 @@ function getContentFromFiles(input) {
|
|
|
43
58
|
throw new Error(`Failed to process input files: ${error instanceof Error ? error.message : String(error)}`);
|
|
44
59
|
}
|
|
45
60
|
}
|
|
61
|
+
/**
|
|
62
|
+
* Concatenate contents of one or more files asynchronously.
|
|
63
|
+
*
|
|
64
|
+
* @param input - A file path or an array of file paths to read
|
|
65
|
+
* @returns The files' contents joined with newline characters
|
|
66
|
+
* @throws {FileOperationError} If an underlying file operation fails for any path
|
|
67
|
+
* @throws {Error} If `input` is missing or processing of the provided input fails
|
|
68
|
+
*/
|
|
69
|
+
async function getContentFromFilesAsync(input) {
|
|
70
|
+
try {
|
|
71
|
+
if (!input) throw new Error("Input must be a string or array of strings");
|
|
72
|
+
if (!Array.isArray(input)) return await readFileContentAsync(input);
|
|
73
|
+
if (input.length === 0) return "";
|
|
74
|
+
return (await Promise.all(input.map(readFileContentAsync))).join("\n");
|
|
75
|
+
} catch (error) {
|
|
76
|
+
if (error instanceof FileOperationError) throw error;
|
|
77
|
+
throw new Error(`Failed to process input files: ${error instanceof Error ? error.message : String(error)}`);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
46
80
|
|
|
47
81
|
//#endregion
|
|
48
|
-
export { getContentFromFiles };
|
|
82
|
+
export { getContentFromFiles, getContentFromFilesAsync };
|
|
49
83
|
//# sourceMappingURL=getContentFromFiles.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getContentFromFiles.js","names":["error: unknown"],"sources":["../src/getContentFromFiles.ts"],"sourcesContent":["/*!\n * node-minify\n * Copyright(c) 2011-
|
|
1
|
+
{"version":3,"file":"getContentFromFiles.js","names":["error: unknown"],"sources":["../src/getContentFromFiles.ts"],"sourcesContent":["/*!\n * node-minify\n * Copyright (c) 2011-2026 Rodolphe Stoclin\n * MIT Licensed\n */\n\nimport { existsSync, readFileSync } from \"node:fs\";\nimport { readFile } from \"node:fs/promises\";\nimport { FileOperationError } from \"./error.ts\";\nimport { isValidFile } from \"./isValidFile.ts\";\n\n/**\n * Read content from a single file with error handling.\n * @param path Path to the file\n * @returns Content of the file\n * @throws {FileOperationError} If file doesn't exist or reading fails\n */\nfunction readFileContent(path: string): string {\n try {\n if (!existsSync(path)) {\n throw new Error(\"File does not exist\");\n }\n if (!isValidFile(path)) {\n throw new Error(\"Path is not a valid file\");\n }\n return readFileSync(path, \"utf8\");\n } catch (error) {\n throw new FileOperationError(\"read\", path, error as Error);\n }\n}\n\n/**\n * Read the UTF-8 content of a single file.\n *\n * @param path - Filesystem path to the file\n * @returns The file content as a string\n * @throws FileOperationError if the file does not exist, the path is a directory, or reading the file fails\n */\nasync function readFileContentAsync(path: string): Promise<string> {\n try {\n return await readFile(path, \"utf8\");\n } catch (error) {\n throw new FileOperationError(\"read\", path, error as Error);\n }\n}\n\n/**\n * Concatenate all input files and get the data.\n * @param input Single file path or array of file paths\n * @returns Concatenated content of all files\n * @throws {FileOperationError} If any file operation fails\n * @example\n * getContentFromFiles('file.js')\n * getContentFromFiles(['file1.js', 'file2.js'])\n */\nexport function getContentFromFiles(input: string | string[]): string {\n try {\n if (!input) {\n throw new Error(\"Input must be a string or array of strings\");\n }\n\n if (!Array.isArray(input)) {\n return readFileContent(input);\n }\n\n if (input.length === 0) {\n return \"\";\n }\n\n return input.map(readFileContent).join(\"\\n\");\n } catch (error: unknown) {\n if (error instanceof FileOperationError) {\n throw error;\n }\n throw new Error(\n `Failed to process input files: ${error instanceof Error ? error.message : String(error)}`\n );\n }\n}\n\n/**\n * Concatenate contents of one or more files asynchronously.\n *\n * @param input - A file path or an array of file paths to read\n * @returns The files' contents joined with newline characters\n * @throws {FileOperationError} If an underlying file operation fails for any path\n * @throws {Error} If `input` is missing or processing of the provided input fails\n */\nexport async function getContentFromFilesAsync(\n input: string | string[]\n): Promise<string> {\n try {\n if (!input) {\n throw new Error(\"Input must be a string or array of strings\");\n }\n\n if (!Array.isArray(input)) {\n return await readFileContentAsync(input);\n }\n\n if (input.length === 0) {\n return \"\";\n }\n\n // Read files in parallel\n const contents = await Promise.all(input.map(readFileContentAsync));\n return contents.join(\"\\n\");\n } catch (error: unknown) {\n if (error instanceof FileOperationError) {\n throw error;\n }\n throw new Error(\n `Failed to process input files: ${error instanceof Error ? error.message : String(error)}`\n );\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAiBA,SAAS,gBAAgB,MAAsB;AAC3C,KAAI;AACA,MAAI,CAAC,WAAW,KAAK,CACjB,OAAM,IAAI,MAAM,sBAAsB;AAE1C,MAAI,CAAC,YAAY,KAAK,CAClB,OAAM,IAAI,MAAM,2BAA2B;AAE/C,SAAO,aAAa,MAAM,OAAO;UAC5B,OAAO;AACZ,QAAM,IAAI,mBAAmB,QAAQ,MAAM,MAAe;;;;;;;;;;AAWlE,eAAe,qBAAqB,MAA+B;AAC/D,KAAI;AACA,SAAO,MAAM,SAAS,MAAM,OAAO;UAC9B,OAAO;AACZ,QAAM,IAAI,mBAAmB,QAAQ,MAAM,MAAe;;;;;;;;;;;;AAalE,SAAgB,oBAAoB,OAAkC;AAClE,KAAI;AACA,MAAI,CAAC,MACD,OAAM,IAAI,MAAM,6CAA6C;AAGjE,MAAI,CAAC,MAAM,QAAQ,MAAM,CACrB,QAAO,gBAAgB,MAAM;AAGjC,MAAI,MAAM,WAAW,EACjB,QAAO;AAGX,SAAO,MAAM,IAAI,gBAAgB,CAAC,KAAK,KAAK;UACvCA,OAAgB;AACrB,MAAI,iBAAiB,mBACjB,OAAM;AAEV,QAAM,IAAI,MACN,kCAAkC,iBAAiB,QAAQ,MAAM,UAAU,OAAO,MAAM,GAC3F;;;;;;;;;;;AAYT,eAAsB,yBAClB,OACe;AACf,KAAI;AACA,MAAI,CAAC,MACD,OAAM,IAAI,MAAM,6CAA6C;AAGjE,MAAI,CAAC,MAAM,QAAQ,MAAM,CACrB,QAAO,MAAM,qBAAqB,MAAM;AAG5C,MAAI,MAAM,WAAW,EACjB,QAAO;AAKX,UADiB,MAAM,QAAQ,IAAI,MAAM,IAAI,qBAAqB,CAAC,EACnD,KAAK,KAAK;UACrBA,OAAgB;AACrB,MAAI,iBAAiB,mBACjB,OAAM;AAEV,QAAM,IAAI,MACN,kCAAkC,iBAAiB,QAAQ,MAAM,UAAU,OAAO,MAAM,GAC3F"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
//#region src/getFilesizeBrotliInBytes.d.ts
|
|
2
|
+
/*!
|
|
3
|
+
* node-minify
|
|
4
|
+
* Copyright (c) 2011-2026 Rodolphe Stoclin
|
|
5
|
+
* MIT Licensed
|
|
6
|
+
*/
|
|
7
|
+
declare function getFilesizeBrotliInBytes(file: string): Promise<string>;
|
|
8
|
+
//#endregion
|
|
9
|
+
export { getFilesizeBrotliInBytes };
|
|
10
|
+
//# sourceMappingURL=getFilesizeBrotliInBytes.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getFilesizeBrotliInBytes.d.ts","names":[],"sources":["../src/getFilesizeBrotliInBytes.ts"],"sourcesContent":[],"mappings":";;AAgBA;;;;iBAAsB,wBAAA,gBAAwC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { t as FileOperationError } from "./error-Ctspysdk.js";
|
|
2
|
+
import { t as isValidFile } from "./isValidFile-BW5AgBWb.js";
|
|
3
|
+
import { prettyBytes } from "./prettyBytes.js";
|
|
4
|
+
import { existsSync } from "node:fs";
|
|
5
|
+
import { readFile } from "node:fs/promises";
|
|
6
|
+
import { promisify } from "node:util";
|
|
7
|
+
import { brotliCompress, constants } from "node:zlib";
|
|
8
|
+
|
|
9
|
+
//#region src/getFilesizeBrotliInBytes.ts
|
|
10
|
+
/*!
|
|
11
|
+
* node-minify
|
|
12
|
+
* Copyright (c) 2011-2026 Rodolphe Stoclin
|
|
13
|
+
* MIT Licensed
|
|
14
|
+
*/
|
|
15
|
+
const brotliCompressAsync = promisify(brotliCompress);
|
|
16
|
+
async function getFilesizeBrotliInBytes(file) {
|
|
17
|
+
try {
|
|
18
|
+
if (!existsSync(file)) throw new FileOperationError("access", file, /* @__PURE__ */ new Error("File does not exist"));
|
|
19
|
+
if (!isValidFile(file)) throw new FileOperationError("access", file, /* @__PURE__ */ new Error("Path is not a valid file"));
|
|
20
|
+
return prettyBytes((await brotliCompressAsync(await readFile(file), { params: { [constants.BROTLI_PARAM_QUALITY]: constants.BROTLI_MAX_QUALITY } })).length);
|
|
21
|
+
} catch (error) {
|
|
22
|
+
if (error instanceof FileOperationError) throw error;
|
|
23
|
+
throw new FileOperationError("get brotli size of", file, error);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
//#endregion
|
|
28
|
+
export { getFilesizeBrotliInBytes };
|
|
29
|
+
//# sourceMappingURL=getFilesizeBrotliInBytes.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getFilesizeBrotliInBytes.js","names":[],"sources":["../src/getFilesizeBrotliInBytes.ts"],"sourcesContent":["/*!\n * node-minify\n * Copyright (c) 2011-2026 Rodolphe Stoclin\n * MIT Licensed\n */\n\nimport { existsSync } from \"node:fs\";\nimport { readFile } from \"node:fs/promises\";\nimport { promisify } from \"node:util\";\nimport { brotliCompress, constants } from \"node:zlib\";\nimport { FileOperationError } from \"./error.ts\";\nimport { isValidFile } from \"./isValidFile.ts\";\nimport { prettyBytes } from \"./prettyBytes.ts\";\n\nconst brotliCompressAsync = promisify(brotliCompress);\n\nexport async function getFilesizeBrotliInBytes(file: string): Promise<string> {\n try {\n if (!existsSync(file)) {\n throw new FileOperationError(\n \"access\",\n file,\n new Error(\"File does not exist\")\n );\n }\n\n if (!isValidFile(file)) {\n throw new FileOperationError(\n \"access\",\n file,\n new Error(\"Path is not a valid file\")\n );\n }\n\n const content = await readFile(file);\n const compressed = await brotliCompressAsync(content, {\n params: {\n [constants.BROTLI_PARAM_QUALITY]: constants.BROTLI_MAX_QUALITY,\n },\n });\n\n return prettyBytes(compressed.length);\n } catch (error) {\n if (error instanceof FileOperationError) {\n throw error;\n }\n throw new FileOperationError(\n \"get brotli size of\",\n file,\n error as Error\n );\n }\n}\n"],"mappings":";;;;;;;;;;;;;;AAcA,MAAM,sBAAsB,UAAU,eAAe;AAErD,eAAsB,yBAAyB,MAA+B;AAC1E,KAAI;AACA,MAAI,CAAC,WAAW,KAAK,CACjB,OAAM,IAAI,mBACN,UACA,sBACA,IAAI,MAAM,sBAAsB,CACnC;AAGL,MAAI,CAAC,YAAY,KAAK,CAClB,OAAM,IAAI,mBACN,UACA,sBACA,IAAI,MAAM,2BAA2B,CACxC;AAUL,SAAO,aANY,MAAM,oBADT,MAAM,SAAS,KAAK,EACkB,EAClD,QAAQ,GACH,UAAU,uBAAuB,UAAU,oBAC/C,EACJ,CAAC,EAE4B,OAAO;UAChC,OAAO;AACZ,MAAI,iBAAiB,mBACjB,OAAM;AAEV,QAAM,IAAI,mBACN,sBACA,MACA,MACH"}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { t as FileOperationError } from "./error-
|
|
2
|
-
import { t as isValidFile } from "./isValidFile-
|
|
1
|
+
import { t as FileOperationError } from "./error-Ctspysdk.js";
|
|
2
|
+
import { t as isValidFile } from "./isValidFile-BW5AgBWb.js";
|
|
3
3
|
import { prettyBytes } from "./prettyBytes.js";
|
|
4
4
|
import { createReadStream, existsSync } from "node:fs";
|
|
5
5
|
|
|
6
6
|
//#region src/getFilesizeGzippedInBytes.ts
|
|
7
7
|
/*!
|
|
8
8
|
* node-minify
|
|
9
|
-
* Copyright(c) 2011-
|
|
9
|
+
* Copyright (c) 2011-2026 Rodolphe Stoclin
|
|
10
10
|
* MIT Licensed
|
|
11
11
|
*/
|
|
12
12
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getFilesizeGzippedInBytes.js","names":[],"sources":["../src/getFilesizeGzippedInBytes.ts"],"sourcesContent":["/*!\n * node-minify\n * Copyright(c) 2011-
|
|
1
|
+
{"version":3,"file":"getFilesizeGzippedInBytes.js","names":[],"sources":["../src/getFilesizeGzippedInBytes.ts"],"sourcesContent":["/*!\n * node-minify\n * Copyright (c) 2011-2026 Rodolphe Stoclin\n * MIT Licensed\n */\n\nimport { createReadStream, existsSync } from \"node:fs\";\nimport { FileOperationError } from \"./error.ts\";\nimport { isValidFile } from \"./isValidFile.ts\";\nimport { prettyBytes } from \"./prettyBytes.ts\";\n\n/**\n * Get the gzipped file size as a human-readable string.\n * @param file - Path to the file\n * @returns Formatted gzipped file size string (e.g., \"1.5 kB\")\n * @throws {FileOperationError} If file doesn't exist or operation fails\n * @example\n * const size = await getFilesizeGzippedInBytes('file.js')\n * console.log(size) // '1.5 kB'\n */\nexport async function getFilesizeGzippedInBytes(file: string): Promise<string> {\n try {\n if (!existsSync(file)) {\n throw new FileOperationError(\n \"access\",\n file,\n new Error(\"File does not exist\")\n );\n }\n\n if (!isValidFile(file)) {\n throw new FileOperationError(\n \"access\",\n file,\n new Error(\"Path is not a valid file\")\n );\n }\n\n const { gzipSizeStream } = await import(\"gzip-size\");\n const source = createReadStream(file);\n\n const size = await new Promise<number>((resolve, reject) => {\n source\n .pipe(gzipSizeStream())\n .on(\"gzip-size\", resolve)\n .on(\"error\", reject);\n });\n\n return prettyBytes(size);\n } catch (error) {\n throw new FileOperationError(\n \"get gzipped size of\",\n file,\n error as Error\n );\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAoBA,eAAsB,0BAA0B,MAA+B;AAC3E,KAAI;AACA,MAAI,CAAC,WAAW,KAAK,CACjB,OAAM,IAAI,mBACN,UACA,sBACA,IAAI,MAAM,sBAAsB,CACnC;AAGL,MAAI,CAAC,YAAY,KAAK,CAClB,OAAM,IAAI,mBACN,UACA,sBACA,IAAI,MAAM,2BAA2B,CACxC;EAGL,MAAM,EAAE,mBAAmB,MAAM,OAAO;EACxC,MAAM,SAAS,iBAAiB,KAAK;AASrC,SAAO,YAPM,MAAM,IAAI,SAAiB,SAAS,WAAW;AACxD,UACK,KAAK,gBAAgB,CAAC,CACtB,GAAG,aAAa,QAAQ,CACxB,GAAG,SAAS,OAAO;IAC1B,CAEsB;UACnB,OAAO;AACZ,QAAM,IAAI,mBACN,uBACA,MACA,MACH"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getFilesizeInBytes.js","names":[],"sources":["../src/getFilesizeInBytes.ts"],"sourcesContent":["/*!\n * node-minify\n * Copyright(c) 2011-
|
|
1
|
+
{"version":3,"file":"getFilesizeInBytes.js","names":[],"sources":["../src/getFilesizeInBytes.ts"],"sourcesContent":["/*!\n * node-minify\n * Copyright (c) 2011-2026 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"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,17 +1,21 @@
|
|
|
1
1
|
import { BuildArgsOptions } from "./types.js";
|
|
2
2
|
import { buildArgs, toBuildArgsOptions } from "./buildArgs.js";
|
|
3
3
|
import { compressSingleFile } from "./compressSingleFile.js";
|
|
4
|
+
import { CompressorResolution, getKnownExportName, isBuiltInCompressor, resolveCompressor } from "./compressor-resolver.js";
|
|
4
5
|
import { deleteFile } from "./deleteFile.js";
|
|
5
6
|
import { resetDeprecationWarnings, warnDeprecation } from "./deprecation.js";
|
|
6
|
-
import {
|
|
7
|
+
import { ensureStringContent } from "./ensureStringContent.js";
|
|
8
|
+
import { getContentFromFiles, getContentFromFilesAsync } from "./getContentFromFiles.js";
|
|
9
|
+
import { getFilesizeBrotliInBytes } from "./getFilesizeBrotliInBytes.js";
|
|
7
10
|
import { getFilesizeGzippedInBytes } from "./getFilesizeGzippedInBytes.js";
|
|
8
11
|
import { getFilesizeInBytes } from "./getFilesizeInBytes.js";
|
|
9
|
-
import {
|
|
12
|
+
import { isImageFile } from "./isImageFile.js";
|
|
13
|
+
import { isValidFile, isValidFileAsync } from "./isValidFile.js";
|
|
10
14
|
import { prettyBytes } from "./prettyBytes.js";
|
|
11
|
-
import { readFile } from "./readFile.js";
|
|
15
|
+
import { readFile, readFileAsync } from "./readFile.js";
|
|
12
16
|
import { run } from "./run.js";
|
|
13
17
|
import { setFileNameMin } from "./setFileNameMin.js";
|
|
14
18
|
import { setPublicFolder } from "./setPublicFolder.js";
|
|
15
19
|
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 };
|
|
20
|
+
import { writeFile, writeFileAsync } from "./writeFile.js";
|
|
21
|
+
export { type BuildArgsOptions, type CompressorResolution, buildArgs, compressSingleFile, deleteFile, ensureStringContent, getContentFromFiles, getContentFromFilesAsync, getFilesizeBrotliInBytes, getFilesizeGzippedInBytes, getFilesizeInBytes, getKnownExportName, isBuiltInCompressor, isImageFile, isValidFile, isValidFileAsync, prettyBytes, readFile, readFileAsync, resetDeprecationWarnings, resolveCompressor, run, setFileNameMin, setPublicFolder, toBuildArgsOptions, warnDeprecation, wildcards, writeFile, writeFileAsync };
|
package/dist/index.js
CHANGED
|
@@ -1,17 +1,21 @@
|
|
|
1
1
|
import { buildArgs, toBuildArgsOptions } from "./buildArgs.js";
|
|
2
|
-
import { t as isValidFile } from "./isValidFile-
|
|
3
|
-
import { getContentFromFiles } from "./getContentFromFiles.js";
|
|
4
|
-
import {
|
|
2
|
+
import { n as isValidFileAsync, t as isValidFile } from "./isValidFile-BW5AgBWb.js";
|
|
3
|
+
import { getContentFromFiles, getContentFromFilesAsync } from "./getContentFromFiles.js";
|
|
4
|
+
import { isImageFile } from "./isImageFile.js";
|
|
5
|
+
import { readFile, readFileAsync } from "./readFile.js";
|
|
6
|
+
import { n as writeFileAsync, t as writeFile } from "./writeFile-DgV8EbFP.js";
|
|
5
7
|
import { run } from "./run.js";
|
|
6
8
|
import { compressSingleFile } from "./compressSingleFile.js";
|
|
9
|
+
import { getKnownExportName, isBuiltInCompressor, resolveCompressor } from "./compressor-resolver.js";
|
|
7
10
|
import { deleteFile } from "./deleteFile.js";
|
|
8
11
|
import { resetDeprecationWarnings, warnDeprecation } from "./deprecation.js";
|
|
12
|
+
import { ensureStringContent } from "./ensureStringContent.js";
|
|
9
13
|
import { prettyBytes } from "./prettyBytes.js";
|
|
14
|
+
import { getFilesizeBrotliInBytes } from "./getFilesizeBrotliInBytes.js";
|
|
10
15
|
import { getFilesizeGzippedInBytes } from "./getFilesizeGzippedInBytes.js";
|
|
11
16
|
import { getFilesizeInBytes } from "./getFilesizeInBytes.js";
|
|
12
|
-
import { readFile } from "./readFile.js";
|
|
13
17
|
import { setFileNameMin } from "./setFileNameMin.js";
|
|
14
18
|
import { setPublicFolder } from "./setPublicFolder.js";
|
|
15
19
|
import { wildcards } from "./wildcards.js";
|
|
16
20
|
|
|
17
|
-
export { buildArgs, compressSingleFile, deleteFile, getContentFromFiles, getFilesizeGzippedInBytes, getFilesizeInBytes, isValidFile, prettyBytes, readFile, resetDeprecationWarnings, run, setFileNameMin, setPublicFolder, toBuildArgsOptions, warnDeprecation, wildcards, writeFile };
|
|
21
|
+
export { buildArgs, compressSingleFile, deleteFile, ensureStringContent, getContentFromFiles, getContentFromFilesAsync, getFilesizeBrotliInBytes, getFilesizeGzippedInBytes, getFilesizeInBytes, getKnownExportName, isBuiltInCompressor, isImageFile, isValidFile, isValidFileAsync, prettyBytes, readFile, readFileAsync, resetDeprecationWarnings, resolveCompressor, run, setFileNameMin, setPublicFolder, toBuildArgsOptions, warnDeprecation, wildcards, writeFile, writeFileAsync };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
//#region src/isImageFile.d.ts
|
|
2
|
+
/*!
|
|
3
|
+
* node-minify
|
|
4
|
+
* Copyright (c) 2011-2026 Rodolphe Stoclin
|
|
5
|
+
* MIT Licensed
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Determines whether a file path refers to a supported image file by its extension.
|
|
9
|
+
*
|
|
10
|
+
* @param filePath - The file name or path to check; may include directories.
|
|
11
|
+
* @returns `true` if the path ends with a recognized image extension, `false` otherwise.
|
|
12
|
+
*/
|
|
13
|
+
declare function isImageFile(filePath: string): boolean;
|
|
14
|
+
//#endregion
|
|
15
|
+
export { isImageFile };
|
|
16
|
+
//# sourceMappingURL=isImageFile.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"isImageFile.d.ts","names":[],"sources":["../src/isImageFile.ts"],"sourcesContent":[],"mappings":";;AA0BA;;;;;;;;;;iBAAgB,WAAA"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
//#region src/isImageFile.ts
|
|
2
|
+
/*!
|
|
3
|
+
* node-minify
|
|
4
|
+
* Copyright (c) 2011-2026 Rodolphe Stoclin
|
|
5
|
+
* MIT Licensed
|
|
6
|
+
*/
|
|
7
|
+
const IMAGE_EXTENSIONS = new Set([
|
|
8
|
+
".png",
|
|
9
|
+
".jpg",
|
|
10
|
+
".jpeg",
|
|
11
|
+
".gif",
|
|
12
|
+
".webp",
|
|
13
|
+
".avif",
|
|
14
|
+
".tiff",
|
|
15
|
+
".tif",
|
|
16
|
+
".heif",
|
|
17
|
+
".heic",
|
|
18
|
+
".svg"
|
|
19
|
+
]);
|
|
20
|
+
/**
|
|
21
|
+
* Determines whether a file path refers to a supported image file by its extension.
|
|
22
|
+
*
|
|
23
|
+
* @param filePath - The file name or path to check; may include directories.
|
|
24
|
+
* @returns `true` if the path ends with a recognized image extension, `false` otherwise.
|
|
25
|
+
*/
|
|
26
|
+
function isImageFile(filePath) {
|
|
27
|
+
const lastDot = filePath.lastIndexOf(".");
|
|
28
|
+
if (lastDot === -1) return false;
|
|
29
|
+
const ext = filePath.slice(lastDot).toLowerCase();
|
|
30
|
+
return IMAGE_EXTENSIONS.has(ext);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
//#endregion
|
|
34
|
+
export { isImageFile };
|
|
35
|
+
//# sourceMappingURL=isImageFile.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"isImageFile.js","names":[],"sources":["../src/isImageFile.ts"],"sourcesContent":["/*!\n * node-minify\n * Copyright (c) 2011-2026 Rodolphe Stoclin\n * MIT Licensed\n */\n\nconst IMAGE_EXTENSIONS = new Set([\n \".png\",\n \".jpg\",\n \".jpeg\",\n \".gif\",\n \".webp\",\n \".avif\",\n \".tiff\",\n \".tif\",\n \".heif\",\n \".heic\",\n \".svg\",\n]);\n\n/**\n * Determines whether a file path refers to a supported image file by its extension.\n *\n * @param filePath - The file name or path to check; may include directories.\n * @returns `true` if the path ends with a recognized image extension, `false` otherwise.\n */\nexport function isImageFile(filePath: string): boolean {\n const lastDot = filePath.lastIndexOf(\".\");\n if (lastDot === -1) return false;\n const ext = filePath.slice(lastDot).toLowerCase();\n return IMAGE_EXTENSIONS.has(ext);\n}\n"],"mappings":";;;;;;AAMA,MAAM,mBAAmB,IAAI,IAAI;CAC7B;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACH,CAAC;;;;;;;AAQF,SAAgB,YAAY,UAA2B;CACnD,MAAM,UAAU,SAAS,YAAY,IAAI;AACzC,KAAI,YAAY,GAAI,QAAO;CAC3B,MAAM,MAAM,SAAS,MAAM,QAAQ,CAAC,aAAa;AACjD,QAAO,iBAAiB,IAAI,IAAI"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { t as FileOperationError } from "./error-Ctspysdk.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-BW5AgBWb.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"isValidFile-BW5AgBWb.js","names":["error: unknown"],"sources":["../src/isValidFile.ts"],"sourcesContent":["/*!\n * node-minify\n * Copyright (c) 2011-2026 Rodolphe Stoclin\n * MIT Licensed\n */\n\nimport { existsSync, lstatSync } from \"node:fs\";\nimport { lstat } from \"node:fs/promises\";\nimport { FileOperationError } from \"./error.ts\";\n\n/**\n * Check if the path is a valid file.\n * @param path Path to check\n * @returns true if path exists and is a file, false otherwise\n * @throws {FileOperationError} If filesystem operations fail\n * @example\n * if (isValidFile('path/to/file.js')) {\n * // do something\n * }\n */\nexport function isValidFile(path: string): boolean {\n try {\n return existsSync(path) && !lstatSync(path).isDirectory();\n } catch (error) {\n throw new FileOperationError(\"validate\", path, error as Error);\n }\n}\n\n/**\n * Determine whether a filesystem path refers to an existing file (not a directory).\n *\n * @param path - Path to check\n * @returns `true` if the path exists and is a file, `false` otherwise.\n * @throws {FileOperationError} If a filesystem error other than `ENOENT` occurs while validating the path.\n */\nexport async function isValidFileAsync(path: string): Promise<boolean> {\n try {\n const stats = await lstat(path);\n return !stats.isDirectory();\n } catch (error: unknown) {\n if (\n error &&\n typeof error === \"object\" &&\n \"code\" in error &&\n error.code === \"ENOENT\"\n ) {\n return false;\n }\n throw new FileOperationError(\n \"validate\",\n path,\n error instanceof Error ? error : new Error(String(error))\n );\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAoBA,SAAgB,YAAY,MAAuB;AAC/C,KAAI;AACA,SAAO,WAAW,KAAK,IAAI,CAAC,UAAU,KAAK,CAAC,aAAa;UACpD,OAAO;AACZ,QAAM,IAAI,mBAAmB,YAAY,MAAM,MAAe;;;;;;;;;;AAWtE,eAAsB,iBAAiB,MAAgC;AACnE,KAAI;AAEA,SAAO,EADO,MAAM,MAAM,KAAK,EACjB,aAAa;UACtBA,OAAgB;AACrB,MACI,SACA,OAAO,UAAU,YACjB,UAAU,SACV,MAAM,SAAS,SAEf,QAAO;AAEX,QAAM,IAAI,mBACN,YACA,MACA,iBAAiB,QAAQ,QAAQ,IAAI,MAAM,OAAO,MAAM,CAAC,CAC5D"}
|
package/dist/isValidFile.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
//#region src/isValidFile.d.ts
|
|
2
2
|
/*!
|
|
3
3
|
* node-minify
|
|
4
|
-
* Copyright(c) 2011-
|
|
4
|
+
* Copyright (c) 2011-2026 Rodolphe Stoclin
|
|
5
5
|
* MIT Licensed
|
|
6
6
|
*/
|
|
7
7
|
/**
|
|
@@ -15,6 +15,14 @@
|
|
|
15
15
|
* }
|
|
16
16
|
*/
|
|
17
17
|
declare function isValidFile(path: string): boolean;
|
|
18
|
+
/**
|
|
19
|
+
* Determine whether a filesystem path refers to an existing file (not a directory).
|
|
20
|
+
*
|
|
21
|
+
* @param path - Path to check
|
|
22
|
+
* @returns `true` if the path exists and is a file, `false` otherwise.
|
|
23
|
+
* @throws {FileOperationError} If a filesystem error other than `ENOENT` occurs while validating the path.
|
|
24
|
+
*/
|
|
25
|
+
declare function isValidFileAsync(path: string): Promise<boolean>;
|
|
18
26
|
//#endregion
|
|
19
|
-
export { isValidFile };
|
|
27
|
+
export { isValidFile, isValidFileAsync };
|
|
20
28
|
//# sourceMappingURL=isValidFile.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"isValidFile.d.ts","names":[],"sources":["../src/isValidFile.ts"],"sourcesContent":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"isValidFile.d.ts","names":[],"sources":["../src/isValidFile.ts"],"sourcesContent":[],"mappings":";;AAoBA;AAeA;;;;;;;;;;;;;iBAfgB,WAAA;;;;;;;;iBAeM,gBAAA,gBAAgC"}
|
package/dist/isValidFile.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { t as isValidFile } from "./isValidFile-
|
|
1
|
+
import { n as isValidFileAsync, t as isValidFile } from "./isValidFile-BW5AgBWb.js";
|
|
2
2
|
|
|
3
|
-
export { isValidFile };
|
|
3
|
+
export { isValidFile, isValidFileAsync };
|
package/dist/prettyBytes.d.ts
CHANGED
package/dist/prettyBytes.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { n as ValidationError } from "./error-
|
|
1
|
+
import { n as ValidationError } from "./error-Ctspysdk.js";
|
|
2
2
|
|
|
3
3
|
//#region src/prettyBytes.ts
|
|
4
4
|
/*!
|
|
5
5
|
* node-minify
|
|
6
|
-
* Copyright(c) 2011-
|
|
6
|
+
* Copyright (c) 2011-2026 Rodolphe Stoclin
|
|
7
7
|
* MIT Licensed
|
|
8
8
|
*/
|
|
9
9
|
const UNITS = [
|
package/dist/prettyBytes.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prettyBytes.js","names":[],"sources":["../src/prettyBytes.ts"],"sourcesContent":["/*!\n * node-minify\n * Copyright(c) 2011-
|
|
1
|
+
{"version":3,"file":"prettyBytes.js","names":[],"sources":["../src/prettyBytes.ts"],"sourcesContent":["/*!\n * node-minify\n * Copyright (c) 2011-2026 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"}
|
package/dist/readFile.d.ts
CHANGED
|
@@ -1,15 +1,37 @@
|
|
|
1
1
|
//#region src/readFile.d.ts
|
|
2
2
|
/*!
|
|
3
3
|
* node-minify
|
|
4
|
-
* Copyright(c) 2011-
|
|
4
|
+
* Copyright (c) 2011-2026 Rodolphe Stoclin
|
|
5
5
|
* MIT Licensed
|
|
6
6
|
*/
|
|
7
7
|
/**
|
|
8
8
|
* Read content from file.
|
|
9
9
|
* @param file - Path to file
|
|
10
|
-
* @
|
|
10
|
+
* @param asBuffer - If true, return Buffer; if false, return string (default: false)
|
|
11
|
+
* @returns File content as string or Buffer
|
|
12
|
+
* @throws {FileOperationError} If file doesn't exist or reading fails
|
|
13
|
+
* @example
|
|
14
|
+
* // Read as string
|
|
15
|
+
* const content = readFile('file.txt');
|
|
16
|
+
*
|
|
17
|
+
* // Read as Buffer (for binary files like images)
|
|
18
|
+
* const buffer = readFile('image.png', true);
|
|
11
19
|
*/
|
|
12
20
|
declare function readFile(file: string): string;
|
|
21
|
+
declare function readFile(file: string, asBuffer: true): Buffer;
|
|
22
|
+
declare function readFile(file: string, asBuffer: false): string;
|
|
23
|
+
declare function readFile(file: string, asBuffer?: boolean): string | Buffer;
|
|
24
|
+
/**
|
|
25
|
+
* Read content from file asynchronously.
|
|
26
|
+
* @param file - Path to file
|
|
27
|
+
* @param asBuffer - If true, return Buffer; if false, return string (default: false)
|
|
28
|
+
* @returns File content as string or Buffer
|
|
29
|
+
* @throws {FileOperationError} If file doesn't exist or reading fails
|
|
30
|
+
*/
|
|
31
|
+
declare function readFileAsync(file: string): Promise<string>;
|
|
32
|
+
declare function readFileAsync(file: string, asBuffer: true): Promise<Buffer>;
|
|
33
|
+
declare function readFileAsync(file: string, asBuffer: false): Promise<string>;
|
|
34
|
+
declare function readFileAsync(file: string, asBuffer?: boolean): Promise<string | Buffer>;
|
|
13
35
|
//#endregion
|
|
14
|
-
export { readFile };
|
|
36
|
+
export { readFile, readFileAsync };
|
|
15
37
|
//# sourceMappingURL=readFile.d.ts.map
|
package/dist/readFile.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"readFile.d.ts","names":[],"sources":["../src/readFile.ts"],"sourcesContent":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"readFile.d.ts","names":[],"sources":["../src/readFile.ts"],"sourcesContent":[],"mappings":";;AAuBA;AACA;AACA;AACA;AA4BA;AACA;AAIA;AAIA;;;;;;;;;;iBAxCgB,QAAA;iBACA,QAAA,gCAAwC;iBACxC,QAAA;iBACA,QAAA,6CAAqD;;;;;;;;iBA4B/C,aAAA,gBAA6B;iBAC7B,aAAA,gCAGnB,QAAQ;iBACW,aAAA,iCAGnB;iBACmB,aAAA,oCAGnB,iBAAiB"}
|
package/dist/readFile.js
CHANGED
|
@@ -1,20 +1,44 @@
|
|
|
1
|
+
import { t as FileOperationError } from "./error-Ctspysdk.js";
|
|
1
2
|
import { readFileSync } from "node:fs";
|
|
3
|
+
import { readFile as readFile$1 } from "node:fs/promises";
|
|
2
4
|
|
|
3
5
|
//#region src/readFile.ts
|
|
4
6
|
/*!
|
|
5
7
|
* node-minify
|
|
6
|
-
* Copyright(c) 2011-
|
|
8
|
+
* Copyright (c) 2011-2026 Rodolphe Stoclin
|
|
7
9
|
* MIT Licensed
|
|
8
10
|
*/
|
|
9
11
|
/**
|
|
10
|
-
* Read
|
|
11
|
-
*
|
|
12
|
-
* @
|
|
12
|
+
* Read a file from disk and return its contents as a UTF-8 string by default or as a raw Buffer.
|
|
13
|
+
*
|
|
14
|
+
* @param file - Path to the file to read.
|
|
15
|
+
* @param asBuffer - If `true`, return a raw `Buffer`; if `false` or omitted, return the file decoded as a UTF-8 `string`.
|
|
16
|
+
* @returns A `Buffer` when `asBuffer` is `true`, otherwise the file content as a UTF-8 `string`.
|
|
17
|
+
* @throws FileOperationError when the file cannot be read; the original error is attached as the cause.
|
|
13
18
|
*/
|
|
14
|
-
function readFile(file) {
|
|
15
|
-
|
|
19
|
+
function readFile(file, asBuffer) {
|
|
20
|
+
try {
|
|
21
|
+
return asBuffer ? readFileSync(file) : readFileSync(file, "utf8");
|
|
22
|
+
} catch (error) {
|
|
23
|
+
throw new FileOperationError("read", file, error instanceof Error ? error : void 0);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Read a file from disk asynchronously and return its contents as a UTF-8 string by default or as a raw Buffer.
|
|
28
|
+
*
|
|
29
|
+
* @param file - Path to the file to read.
|
|
30
|
+
* @param asBuffer - If `true`, return a raw `Buffer`; if `false` or omitted, return the file decoded as a UTF-8 `string`.
|
|
31
|
+
* @returns A `Buffer` when `asBuffer` is `true`, otherwise the file content as a UTF-8 `string`.
|
|
32
|
+
* @throws FileOperationError when the file cannot be read; the original error is attached as the cause.
|
|
33
|
+
*/
|
|
34
|
+
async function readFileAsync(file, asBuffer) {
|
|
35
|
+
try {
|
|
36
|
+
return asBuffer ? await readFile$1(file) : await readFile$1(file, "utf8");
|
|
37
|
+
} catch (error) {
|
|
38
|
+
throw new FileOperationError("read", file, error instanceof Error ? error : void 0);
|
|
39
|
+
}
|
|
16
40
|
}
|
|
17
41
|
|
|
18
42
|
//#endregion
|
|
19
|
-
export { readFile };
|
|
43
|
+
export { readFile, readFileAsync };
|
|
20
44
|
//# sourceMappingURL=readFile.js.map
|
package/dist/readFile.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"readFile.js","names":[],"sources":["../src/readFile.ts"],"sourcesContent":["/*!\n * node-minify\n * Copyright(c) 2011-
|
|
1
|
+
{"version":3,"file":"readFile.js","names":["readFilePromise"],"sources":["../src/readFile.ts"],"sourcesContent":["/*!\n * node-minify\n * Copyright (c) 2011-2026 Rodolphe Stoclin\n * MIT Licensed\n */\n\nimport { readFileSync } from \"node:fs\";\nimport { readFile as readFilePromise } from \"node:fs/promises\";\nimport { FileOperationError } from \"./error.ts\";\n\n/**\n * Read content from file.\n * @param file - Path to file\n * @param asBuffer - If true, return Buffer; if false, return string (default: false)\n * @returns File content as string or Buffer\n * @throws {FileOperationError} If file doesn't exist or reading fails\n * @example\n * // Read as string\n * const content = readFile('file.txt');\n *\n * // Read as Buffer (for binary files like images)\n * const buffer = readFile('image.png', true);\n */\nexport function readFile(file: string): string;\nexport function readFile(file: string, asBuffer: true): Buffer;\nexport function readFile(file: string, asBuffer: false): string;\nexport function readFile(file: string, asBuffer?: boolean): string | Buffer;\n/**\n * Read a file from disk and return its contents as a UTF-8 string by default or as a raw Buffer.\n *\n * @param file - Path to the file to read.\n * @param asBuffer - If `true`, return a raw `Buffer`; if `false` or omitted, return the file decoded as a UTF-8 `string`.\n * @returns A `Buffer` when `asBuffer` is `true`, otherwise the file content as a UTF-8 `string`.\n * @throws FileOperationError when the file cannot be read; the original error is attached as the cause.\n */\nexport function readFile(file: string, asBuffer?: boolean): string | Buffer {\n try {\n return asBuffer ? readFileSync(file) : readFileSync(file, \"utf8\");\n } catch (error) {\n throw new FileOperationError(\n \"read\",\n file,\n error instanceof Error ? error : undefined\n );\n }\n}\n\n/**\n * Read content from file asynchronously.\n * @param file - Path to file\n * @param asBuffer - If true, return Buffer; if false, return string (default: false)\n * @returns File content as string or Buffer\n * @throws {FileOperationError} If file doesn't exist or reading fails\n */\nexport async function readFileAsync(file: string): Promise<string>;\nexport async function readFileAsync(\n file: string,\n asBuffer: true\n): Promise<Buffer>;\nexport async function readFileAsync(\n file: string,\n asBuffer: false\n): Promise<string>;\nexport async function readFileAsync(\n file: string,\n asBuffer?: boolean\n): Promise<string | Buffer>;\n/**\n * Read a file from disk asynchronously and return its contents as a UTF-8 string by default or as a raw Buffer.\n *\n * @param file - Path to the file to read.\n * @param asBuffer - If `true`, return a raw `Buffer`; if `false` or omitted, return the file decoded as a UTF-8 `string`.\n * @returns A `Buffer` when `asBuffer` is `true`, otherwise the file content as a UTF-8 `string`.\n * @throws FileOperationError when the file cannot be read; the original error is attached as the cause.\n */\nexport async function readFileAsync(\n file: string,\n asBuffer?: boolean\n): Promise<string | Buffer> {\n try {\n return asBuffer\n ? await readFilePromise(file)\n : await readFilePromise(file, \"utf8\");\n } catch (error) {\n throw new FileOperationError(\n \"read\",\n file,\n error instanceof Error ? error : undefined\n );\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAmCA,SAAgB,SAAS,MAAc,UAAqC;AACxE,KAAI;AACA,SAAO,WAAW,aAAa,KAAK,GAAG,aAAa,MAAM,OAAO;UAC5D,OAAO;AACZ,QAAM,IAAI,mBACN,QACA,MACA,iBAAiB,QAAQ,QAAQ,OACpC;;;;;;;;;;;AAgCT,eAAsB,cAClB,MACA,UACwB;AACxB,KAAI;AACA,SAAO,WACD,MAAMA,WAAgB,KAAK,GAC3B,MAAMA,WAAgB,MAAM,OAAO;UACpC,OAAO;AACZ,QAAM,IAAI,mBACN,QACA,MACA,iBAAiB,QAAQ,QAAQ,OACpC"}
|
package/dist/run.d.ts
CHANGED
|
@@ -1,23 +1,21 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { n as CompressorOptions, r as MinifierOptions } from "./types-CzkB7gxg.js";
|
|
2
2
|
|
|
3
3
|
//#region src/run.d.ts
|
|
4
4
|
|
|
5
|
-
interface RunParameters {
|
|
6
|
-
settings: Settings;
|
|
7
|
-
content?: string;
|
|
8
|
-
index?: number;
|
|
9
|
-
}
|
|
10
5
|
/**
|
|
11
|
-
* Execute the compressor and
|
|
12
|
-
*
|
|
13
|
-
* @
|
|
14
|
-
* @
|
|
6
|
+
* Execute the configured compressor and persist its outputs according to the provided settings.
|
|
7
|
+
*
|
|
8
|
+
* @param settings - Compressor settings including output targets, options, and the `compressor` implementation
|
|
9
|
+
* @param content - The input content to be compressed
|
|
10
|
+
* @param index - Optional index used when processing multiple inputs
|
|
11
|
+
* @returns The minified code produced by the compressor
|
|
12
|
+
* @throws ValidationError If `settings` is missing, `settings.compressor` is not provided, or the compressor returns an invalid result
|
|
15
13
|
*/
|
|
16
|
-
declare function run({
|
|
14
|
+
declare function run<T extends CompressorOptions = CompressorOptions>({
|
|
17
15
|
settings,
|
|
18
16
|
content,
|
|
19
17
|
index
|
|
20
|
-
}:
|
|
18
|
+
}: MinifierOptions<T>): Promise<string>;
|
|
21
19
|
//#endregion
|
|
22
20
|
export { run };
|
|
23
21
|
//# sourceMappingURL=run.d.ts.map
|
package/dist/run.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"run.d.ts","names":[],"sources":["../src/run.ts"],"sourcesContent":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"run.d.ts","names":[],"sources":["../src/run.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;;;;iBAyBsB,cAAc,oBAAoB;;;;GAIrD,gBAAgB,KAAK"}
|