@node-minify/utils 10.2.0 → 10.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -1
- package/dist/buildArgs.js +2 -2
- package/dist/buildArgs.js.map +1 -1
- package/dist/compressSingleFile.d.ts +1 -1
- package/dist/compressSingleFile.d.ts.map +1 -1
- package/dist/compressSingleFile.js +6 -32
- package/dist/compressSingleFile.js.map +1 -1
- package/dist/compressor-resolver.d.ts +76 -0
- package/dist/compressor-resolver.d.ts.map +1 -0
- package/dist/compressor-resolver.js +183 -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 +1 -1
- package/dist/ensureStringContent.js +1 -1
- package/dist/ensureStringContent.js.map +1 -1
- package/dist/{error-Ck87RwDD.js → error-CUgKxOvI.js} +5 -3
- package/dist/error-CUgKxOvI.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/errors.d.ts +27 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +32 -0
- package/dist/errors.js.map +1 -0
- package/dist/getContentFromFiles.d.ts +1 -1
- package/dist/getContentFromFiles.js +4 -4
- package/dist/getContentFromFiles.js.map +1 -1
- package/dist/getFilesizeBrotliInBytes.d.ts +26 -0
- package/dist/getFilesizeBrotliInBytes.d.ts.map +1 -0
- package/dist/getFilesizeBrotliInBytes.js +63 -0
- package/dist/getFilesizeBrotliInBytes.js.map +1 -0
- package/dist/getFilesizeGzippedInBytes.d.ts +14 -8
- package/dist/getFilesizeGzippedInBytes.d.ts.map +1 -1
- package/dist/getFilesizeGzippedInBytes.js +41 -18
- 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 +8 -4
- 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-DnWJtlKA.js → isValidFile-COstpeyW.js} +4 -4
- package/dist/isValidFile-COstpeyW.js.map +1 -0
- package/dist/isValidFile.d.ts +1 -1
- package/dist/isValidFile.js +1 -1
- 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 +13 -2
- package/dist/readFile.d.ts.map +1 -1
- package/dist/readFile.js +19 -3
- package/dist/readFile.js.map +1 -1
- package/dist/run.d.ts +4 -4
- package/dist/run.js +48 -37
- 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-BUlX1Zbb.d.ts → types-CWBFD3au.d.ts} +16 -2
- package/dist/types-CWBFD3au.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-mfUS3rMz.js +96 -0
- package/dist/writeFile-mfUS3rMz.js.map +1 -0
- package/dist/writeFile.d.ts +20 -2
- package/dist/writeFile.d.ts.map +1 -1
- package/dist/writeFile.js +2 -2
- package/package.json +2 -2
- package/dist/error-Ck87RwDD.js.map +0 -1
- package/dist/isValidFile-DnWJtlKA.js.map +0 -1
- package/dist/types-BUlX1Zbb.d.ts.map +0 -1
- package/dist/writeFile-BRfs9FqY.js +0 -39
- package/dist/writeFile-BRfs9FqY.js.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","names":[],"sources":["../src/errors.ts"],"sourcesContent":["/*!\n * node-minify\n * Copyright (c) 2011-2026 Rodolphe Stoclin\n * MIT Licensed\n */\n\n/**\n * Wraps an error thrown during minification with a consistent, descriptive message.\n *\n * @param compressorName - The name of the compressor that failed\n * @param error - The original error (unknown type for proper catch handling)\n * @returns A new Error with a standardized message format\n */\nexport function wrapMinificationError(\n compressorName: string,\n error: unknown\n): Error {\n const message = error instanceof Error ? error.message : String(error);\n const cause = error instanceof Error ? error : undefined;\n return new Error(`${compressorName} minification failed: ${message}`, {\n cause,\n });\n}\n\n/**\n * Validates that a minification result contains valid output.\n *\n * @param result - The result object to validate\n * @param compressorName - The name of the compressor (for error messages)\n * @throws Error if result is falsy or result.code is not a string\n */\nexport function validateMinifyResult(\n result: unknown,\n compressorName: string\n): asserts result is { code: string } {\n if (\n !result ||\n typeof result !== \"object\" ||\n !(\"code\" in result) ||\n typeof (result as { code: unknown }).code !== \"string\"\n ) {\n throw new Error(`${compressorName} failed: empty or invalid result`);\n }\n}\n"],"mappings":";;;;;;;;;;;;;AAaA,SAAgB,sBACZ,gBACA,OACK;CACL,MAAM,UAAU,iBAAiB,QAAQ,MAAM,UAAU,OAAO,MAAM;CACtE,MAAM,QAAQ,iBAAiB,QAAQ,QAAQ;AAC/C,QAAO,IAAI,MAAM,GAAG,eAAe,wBAAwB,WAAW,EAClE,OACH,CAAC;;;;;;;;;AAUN,SAAgB,qBACZ,QACA,gBACkC;AAClC,KACI,CAAC,UACD,OAAO,WAAW,YAClB,EAAE,UAAU,WACZ,OAAQ,OAA6B,SAAS,SAE9C,OAAM,IAAI,MAAM,GAAG,eAAe,kCAAkC"}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { t as FileOperationError } from "./error-
|
|
2
|
-
import { t as isValidFile } from "./isValidFile-
|
|
3
|
-
import { readFile } from "node:fs/promises";
|
|
1
|
+
import { t as FileOperationError } from "./error-CUgKxOvI.js";
|
|
2
|
+
import { t as isValidFile } from "./isValidFile-COstpeyW.js";
|
|
4
3
|
import { existsSync, readFileSync } from "node:fs";
|
|
4
|
+
import { readFile } from "node:fs/promises";
|
|
5
5
|
|
|
6
6
|
//#region src/getContentFromFiles.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":"getContentFromFiles.js","names":[
|
|
1
|
+
{"version":3,"file":"getContentFromFiles.js","names":[],"sources":["../src/getContentFromFiles.ts"],"sourcesContent":["/*!\n * node-minify\n * Copyright (c) 2011-2026 Rodolphe Stoclin\n * MIT Licensed\n */\n\nimport { existsSync, readFileSync } from \"node:fs\";\nimport { readFile } from \"node:fs/promises\";\nimport { FileOperationError } from \"./error.ts\";\nimport { isValidFile } from \"./isValidFile.ts\";\n\n/**\n * Read content from a single file with error handling.\n * @param path Path to the file\n * @returns Content of the file\n * @throws {FileOperationError} If file doesn't exist or reading fails\n */\nfunction readFileContent(path: string): string {\n try {\n if (!existsSync(path)) {\n throw new Error(\"File does not exist\");\n }\n if (!isValidFile(path)) {\n throw new Error(\"Path is not a valid file\");\n }\n return readFileSync(path, \"utf8\");\n } catch (error) {\n throw new FileOperationError(\"read\", path, error as Error);\n }\n}\n\n/**\n * Read the UTF-8 content of a single file.\n *\n * @param path - Filesystem path to the file\n * @returns The file content as a string\n * @throws FileOperationError if the file does not exist, the path is a directory, or reading the file fails\n */\nasync function readFileContentAsync(path: string): Promise<string> {\n try {\n return await readFile(path, \"utf8\");\n } catch (error) {\n throw new FileOperationError(\"read\", path, error as Error);\n }\n}\n\n/**\n * Concatenate all input files and get the data.\n * @param input Single file path or array of file paths\n * @returns Concatenated content of all files\n * @throws {FileOperationError} If any file operation fails\n * @example\n * getContentFromFiles('file.js')\n * getContentFromFiles(['file1.js', 'file2.js'])\n */\nexport function getContentFromFiles(input: string | string[]): string {\n try {\n if (!input) {\n throw new Error(\"Input must be a string or array of strings\");\n }\n\n if (!Array.isArray(input)) {\n return readFileContent(input);\n }\n\n if (input.length === 0) {\n return \"\";\n }\n\n return input.map(readFileContent).join(\"\\n\");\n } catch (error: unknown) {\n if (error instanceof FileOperationError) {\n throw error;\n }\n throw new Error(\n `Failed to process input files: ${error instanceof Error ? error.message : String(error)}`\n );\n }\n}\n\n/**\n * Concatenate contents of one or more files asynchronously.\n *\n * @param input - A file path or an array of file paths to read\n * @returns The files' contents joined with newline characters\n * @throws {FileOperationError} If an underlying file operation fails for any path\n * @throws {Error} If `input` is missing or processing of the provided input fails\n */\nexport async function getContentFromFilesAsync(\n input: string | string[]\n): Promise<string> {\n try {\n if (!input) {\n throw new Error(\"Input must be a string or array of strings\");\n }\n\n if (!Array.isArray(input)) {\n return await readFileContentAsync(input);\n }\n\n if (input.length === 0) {\n return \"\";\n }\n\n // Read files in parallel\n const contents = await Promise.all(input.map(readFileContentAsync));\n return contents.join(\"\\n\");\n } catch (error: unknown) {\n if (error instanceof FileOperationError) {\n throw error;\n }\n throw new Error(\n `Failed to process input files: ${error instanceof Error ? error.message : String(error)}`\n );\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAiBA,SAAS,gBAAgB,MAAsB;AAC3C,KAAI;AACA,MAAI,CAAC,WAAW,KAAK,CACjB,OAAM,IAAI,MAAM,sBAAsB;AAE1C,MAAI,CAAC,YAAY,KAAK,CAClB,OAAM,IAAI,MAAM,2BAA2B;AAE/C,SAAO,aAAa,MAAM,OAAO;UAC5B,OAAO;AACZ,QAAM,IAAI,mBAAmB,QAAQ,MAAM,MAAe;;;;;;;;;;AAWlE,eAAe,qBAAqB,MAA+B;AAC/D,KAAI;AACA,SAAO,MAAM,SAAS,MAAM,OAAO;UAC9B,OAAO;AACZ,QAAM,IAAI,mBAAmB,QAAQ,MAAM,MAAe;;;;;;;;;;;;AAalE,SAAgB,oBAAoB,OAAkC;AAClE,KAAI;AACA,MAAI,CAAC,MACD,OAAM,IAAI,MAAM,6CAA6C;AAGjE,MAAI,CAAC,MAAM,QAAQ,MAAM,CACrB,QAAO,gBAAgB,MAAM;AAGjC,MAAI,MAAM,WAAW,EACjB,QAAO;AAGX,SAAO,MAAM,IAAI,gBAAgB,CAAC,KAAK,KAAK;UACvC,OAAgB;AACrB,MAAI,iBAAiB,mBACjB,OAAM;AAEV,QAAM,IAAI,MACN,kCAAkC,iBAAiB,QAAQ,MAAM,UAAU,OAAO,MAAM,GAC3F;;;;;;;;;;;AAYT,eAAsB,yBAClB,OACe;AACf,KAAI;AACA,MAAI,CAAC,MACD,OAAM,IAAI,MAAM,6CAA6C;AAGjE,MAAI,CAAC,MAAM,QAAQ,MAAM,CACrB,QAAO,MAAM,qBAAqB,MAAM;AAG5C,MAAI,MAAM,WAAW,EACjB,QAAO;AAKX,UADiB,MAAM,QAAQ,IAAI,MAAM,IAAI,qBAAqB,CAAC,EACnD,KAAK,KAAK;UACrB,OAAgB;AACrB,MAAI,iBAAiB,mBACjB,OAAM;AAEV,QAAM,IAAI,MACN,kCAAkC,iBAAiB,QAAQ,MAAM,UAAU,OAAO,MAAM,GAC3F"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
//#region src/getFilesizeBrotliInBytes.d.ts
|
|
2
|
+
/*!
|
|
3
|
+
* node-minify
|
|
4
|
+
* Copyright (c) 2011-2026 Rodolphe Stoclin
|
|
5
|
+
* MIT Licensed
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Get the brotli-compressed size of a file as a human-readable string.
|
|
9
|
+
*
|
|
10
|
+
* @param file - Path to the file
|
|
11
|
+
* @returns The brotli-compressed size formatted for display (for example, "1.5 kB")
|
|
12
|
+
*/
|
|
13
|
+
declare function getFilesizeBrotliInBytes(file: string): Promise<string>;
|
|
14
|
+
/**
|
|
15
|
+
* Get the brotli-compressed file size in bytes.
|
|
16
|
+
*
|
|
17
|
+
* @param file - Path to the file
|
|
18
|
+
* @returns Brotli-compressed file size in bytes
|
|
19
|
+
* @example
|
|
20
|
+
* const bytes = await getFilesizeBrotliRaw('bundle.js')
|
|
21
|
+
* console.log(bytes) // 12583
|
|
22
|
+
*/
|
|
23
|
+
declare function getFilesizeBrotliRaw(file: string): Promise<number>;
|
|
24
|
+
//#endregion
|
|
25
|
+
export { getFilesizeBrotliInBytes, getFilesizeBrotliRaw };
|
|
26
|
+
//# sourceMappingURL=getFilesizeBrotliInBytes.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getFilesizeBrotliInBytes.d.ts","names":[],"sources":["../src/getFilesizeBrotliInBytes.ts"],"sourcesContent":[],"mappings":";;AAyDA;AAyBA;;;;;;;;;iBAzBsB,wBAAA,gBAAwC;;;;;;;;;;iBAyBxC,oBAAA,gBAAoC"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { t as FileOperationError } from "./error-CUgKxOvI.js";
|
|
2
|
+
import { t as isValidFile } from "./isValidFile-COstpeyW.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
|
+
/**
|
|
17
|
+
* Compute the brotli-compressed size of a file in bytes.
|
|
18
|
+
*
|
|
19
|
+
* @param file - Path to the file to measure
|
|
20
|
+
* @returns The brotli-compressed size in bytes
|
|
21
|
+
* @throws FileOperationError if the file does not exist or the path is not a valid file
|
|
22
|
+
* @internal
|
|
23
|
+
*/
|
|
24
|
+
async function getBrotliSize(file) {
|
|
25
|
+
if (!existsSync(file)) throw new FileOperationError("access", file, /* @__PURE__ */ new Error("File does not exist"));
|
|
26
|
+
if (!isValidFile(file)) throw new FileOperationError("access", file, /* @__PURE__ */ new Error("Path is not a valid file"));
|
|
27
|
+
return (await brotliCompressAsync(await readFile(file), { params: { [constants.BROTLI_PARAM_QUALITY]: constants.BROTLI_MAX_QUALITY } })).length;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Get the brotli-compressed size of a file as a human-readable string.
|
|
31
|
+
*
|
|
32
|
+
* @param file - Path to the file
|
|
33
|
+
* @returns The brotli-compressed size formatted for display (for example, "1.5 kB")
|
|
34
|
+
*/
|
|
35
|
+
async function getFilesizeBrotliInBytes(file) {
|
|
36
|
+
try {
|
|
37
|
+
return prettyBytes(await getBrotliSize(file));
|
|
38
|
+
} catch (error) {
|
|
39
|
+
if (error instanceof FileOperationError) throw error;
|
|
40
|
+
throw new FileOperationError("get brotli size of", file, error);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Get the brotli-compressed file size in bytes.
|
|
45
|
+
*
|
|
46
|
+
* @param file - Path to the file
|
|
47
|
+
* @returns Brotli-compressed file size in bytes
|
|
48
|
+
* @example
|
|
49
|
+
* const bytes = await getFilesizeBrotliRaw('bundle.js')
|
|
50
|
+
* console.log(bytes) // 12583
|
|
51
|
+
*/
|
|
52
|
+
async function getFilesizeBrotliRaw(file) {
|
|
53
|
+
try {
|
|
54
|
+
return await getBrotliSize(file);
|
|
55
|
+
} catch (error) {
|
|
56
|
+
if (error instanceof FileOperationError) throw error;
|
|
57
|
+
throw new FileOperationError("get brotli size of", file, error);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
//#endregion
|
|
62
|
+
export { getFilesizeBrotliInBytes, getFilesizeBrotliRaw };
|
|
63
|
+
//# 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\n/**\n * Compute the brotli-compressed size of a file in bytes.\n *\n * @param file - Path to the file to measure\n * @returns The brotli-compressed size in bytes\n * @throws FileOperationError if the file does not exist or the path is not a valid file\n * @internal\n */\nasync function getBrotliSize(file: string): Promise<number> {\n if (!existsSync(file)) {\n throw new FileOperationError(\n \"access\",\n file,\n new Error(\"File does not exist\")\n );\n }\n\n if (!isValidFile(file)) {\n throw new FileOperationError(\n \"access\",\n file,\n new Error(\"Path is not a valid file\")\n );\n }\n\n const content = await readFile(file);\n const compressed = await brotliCompressAsync(content, {\n params: {\n [constants.BROTLI_PARAM_QUALITY]: constants.BROTLI_MAX_QUALITY,\n },\n });\n\n return compressed.length;\n}\n\n/**\n * Get the brotli-compressed size of a file as a human-readable string.\n *\n * @param file - Path to the file\n * @returns The brotli-compressed size formatted for display (for example, \"1.5 kB\")\n */\nexport async function getFilesizeBrotliInBytes(file: string): Promise<string> {\n try {\n const size = await getBrotliSize(file);\n return prettyBytes(size);\n } catch (error) {\n if (error instanceof FileOperationError) {\n throw error;\n }\n throw new FileOperationError(\n \"get brotli size of\",\n file,\n error as Error\n );\n }\n}\n\n/**\n * Get the brotli-compressed file size in bytes.\n *\n * @param file - Path to the file\n * @returns Brotli-compressed file size in bytes\n * @example\n * const bytes = await getFilesizeBrotliRaw('bundle.js')\n * console.log(bytes) // 12583\n */\nexport async function getFilesizeBrotliRaw(file: string): Promise<number> {\n try {\n return await getBrotliSize(file);\n } catch (error) {\n if (error instanceof FileOperationError) {\n throw error;\n }\n throw new FileOperationError(\n \"get brotli size of\",\n file,\n error as Error\n );\n }\n}\n"],"mappings":";;;;;;;;;;;;;;AAcA,MAAM,sBAAsB,UAAU,eAAe;;;;;;;;;AAUrD,eAAe,cAAc,MAA+B;AACxD,KAAI,CAAC,WAAW,KAAK,CACjB,OAAM,IAAI,mBACN,UACA,sBACA,IAAI,MAAM,sBAAsB,CACnC;AAGL,KAAI,CAAC,YAAY,KAAK,CAClB,OAAM,IAAI,mBACN,UACA,sBACA,IAAI,MAAM,2BAA2B,CACxC;AAUL,SANmB,MAAM,oBADT,MAAM,SAAS,KAAK,EACkB,EAClD,QAAQ,GACH,UAAU,uBAAuB,UAAU,oBAC/C,EACJ,CAAC,EAEgB;;;;;;;;AAStB,eAAsB,yBAAyB,MAA+B;AAC1E,KAAI;AAEA,SAAO,YADM,MAAM,cAAc,KAAK,CACd;UACnB,OAAO;AACZ,MAAI,iBAAiB,mBACjB,OAAM;AAEV,QAAM,IAAI,mBACN,sBACA,MACA,MACH;;;;;;;;;;;;AAaT,eAAsB,qBAAqB,MAA+B;AACtE,KAAI;AACA,SAAO,MAAM,cAAc,KAAK;UAC3B,OAAO;AACZ,MAAI,iBAAiB,mBACjB,OAAM;AAEV,QAAM,IAAI,mBACN,sBACA,MACA,MACH"}
|
|
@@ -1,19 +1,25 @@
|
|
|
1
1
|
//#region src/getFilesizeGzippedInBytes.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
|
-
* Get the gzipped file
|
|
8
|
+
* Get the gzipped size of a file as a human-readable string.
|
|
9
|
+
*
|
|
9
10
|
* @param file - Path to the file
|
|
10
|
-
* @returns
|
|
11
|
-
* @throws {FileOperationError} If file doesn't exist or operation fails
|
|
12
|
-
* @example
|
|
13
|
-
* const size = await getFilesizeGzippedInBytes('file.js')
|
|
14
|
-
* console.log(size) // '1.5 kB'
|
|
11
|
+
* @returns The gzipped size formatted for display (for example, "1.5 kB")
|
|
15
12
|
*/
|
|
16
13
|
declare function getFilesizeGzippedInBytes(file: string): Promise<string>;
|
|
14
|
+
/**
|
|
15
|
+
* Get the gzipped file size in bytes.
|
|
16
|
+
* @param file - Path to the file
|
|
17
|
+
* @returns Gzipped file size in bytes
|
|
18
|
+
* @example
|
|
19
|
+
* const bytes = await getFilesizeGzippedRaw('bundle.js')
|
|
20
|
+
* console.log(bytes) // 12583
|
|
21
|
+
*/
|
|
22
|
+
declare function getFilesizeGzippedRaw(file: string): Promise<number>;
|
|
17
23
|
//#endregion
|
|
18
|
-
export { getFilesizeGzippedInBytes };
|
|
24
|
+
export { getFilesizeGzippedInBytes, getFilesizeGzippedRaw };
|
|
19
25
|
//# sourceMappingURL=getFilesizeGzippedInBytes.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getFilesizeGzippedInBytes.d.ts","names":[],"sources":["../src/getFilesizeGzippedInBytes.ts"],"sourcesContent":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"getFilesizeGzippedInBytes.d.ts","names":[],"sources":["../src/getFilesizeGzippedInBytes.ts"],"sourcesContent":[],"mappings":";;AAgDA;AAwBA;;;;;;;;;iBAxBsB,yBAAA,gBAAyC;;;;;;;;;iBAwBzC,qBAAA,gBAAqC"}
|
|
@@ -1,37 +1,60 @@
|
|
|
1
|
-
import { t as FileOperationError } from "./error-
|
|
2
|
-
import { t as isValidFile } from "./isValidFile-
|
|
1
|
+
import { t as FileOperationError } from "./error-CUgKxOvI.js";
|
|
2
|
+
import { t as isValidFile } from "./isValidFile-COstpeyW.js";
|
|
3
3
|
import { prettyBytes } from "./prettyBytes.js";
|
|
4
|
-
import {
|
|
4
|
+
import { 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
|
/**
|
|
13
|
-
*
|
|
13
|
+
* Compute the gzipped size of a file in bytes.
|
|
14
|
+
*
|
|
15
|
+
* @param file - Path to the file to measure
|
|
16
|
+
* @returns The gzipped size in bytes
|
|
17
|
+
* @throws FileOperationError if the file does not exist or the path is not a valid file
|
|
18
|
+
* @internal
|
|
19
|
+
*/
|
|
20
|
+
async function getGzipSize(file) {
|
|
21
|
+
if (!existsSync(file)) throw new FileOperationError("access", file, /* @__PURE__ */ new Error("File does not exist"));
|
|
22
|
+
if (!isValidFile(file)) throw new FileOperationError("access", file, /* @__PURE__ */ new Error("Path is not a valid file"));
|
|
23
|
+
const { gzipSize } = await import("gzip-size");
|
|
24
|
+
const { readFile } = await import("node:fs/promises");
|
|
25
|
+
return gzipSize(await readFile(file));
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Get the gzipped size of a file as a human-readable string.
|
|
29
|
+
*
|
|
14
30
|
* @param file - Path to the file
|
|
15
|
-
* @returns
|
|
16
|
-
* @throws {FileOperationError} If file doesn't exist or operation fails
|
|
17
|
-
* @example
|
|
18
|
-
* const size = await getFilesizeGzippedInBytes('file.js')
|
|
19
|
-
* console.log(size) // '1.5 kB'
|
|
31
|
+
* @returns The gzipped size formatted for display (for example, "1.5 kB")
|
|
20
32
|
*/
|
|
21
33
|
async function getFilesizeGzippedInBytes(file) {
|
|
22
34
|
try {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
35
|
+
return prettyBytes(await getGzipSize(file));
|
|
36
|
+
} catch (error) {
|
|
37
|
+
if (error instanceof FileOperationError) throw error;
|
|
38
|
+
throw new FileOperationError("get gzipped size of", file, error);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Get the gzipped file size in bytes.
|
|
43
|
+
* @param file - Path to the file
|
|
44
|
+
* @returns Gzipped file size in bytes
|
|
45
|
+
* @example
|
|
46
|
+
* const bytes = await getFilesizeGzippedRaw('bundle.js')
|
|
47
|
+
* console.log(bytes) // 12583
|
|
48
|
+
*/
|
|
49
|
+
async function getFilesizeGzippedRaw(file) {
|
|
50
|
+
try {
|
|
51
|
+
return await getGzipSize(file);
|
|
30
52
|
} catch (error) {
|
|
53
|
+
if (error instanceof FileOperationError) throw error;
|
|
31
54
|
throw new FileOperationError("get gzipped size of", file, error);
|
|
32
55
|
}
|
|
33
56
|
}
|
|
34
57
|
|
|
35
58
|
//#endregion
|
|
36
|
-
export { getFilesizeGzippedInBytes };
|
|
59
|
+
export { getFilesizeGzippedInBytes, getFilesizeGzippedRaw };
|
|
37
60
|
//# sourceMappingURL=getFilesizeGzippedInBytes.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getFilesizeGzippedInBytes.js","names":[],"sources":["../src/getFilesizeGzippedInBytes.ts"],"sourcesContent":["/*!\n * node-minify\n * Copyright(c) 2011-
|
|
1
|
+
{"version":3,"file":"getFilesizeGzippedInBytes.js","names":[],"sources":["../src/getFilesizeGzippedInBytes.ts"],"sourcesContent":["/*!\n * node-minify\n * Copyright (c) 2011-2026 Rodolphe Stoclin\n * MIT Licensed\n */\n\nimport { existsSync } from \"node:fs\";\nimport { FileOperationError } from \"./error.ts\";\nimport { isValidFile } from \"./isValidFile.ts\";\nimport { prettyBytes } from \"./prettyBytes.ts\";\n\n/**\n * Compute the gzipped size of a file in bytes.\n *\n * @param file - Path to the file to measure\n * @returns The gzipped size in bytes\n * @throws FileOperationError if the file does not exist or the path is not a valid file\n * @internal\n */\nasync function getGzipSize(file: string): Promise<number> {\n if (!existsSync(file)) {\n throw new FileOperationError(\n \"access\",\n file,\n new Error(\"File does not exist\")\n );\n }\n\n if (!isValidFile(file)) {\n throw new FileOperationError(\n \"access\",\n file,\n new Error(\"Path is not a valid file\")\n );\n }\n\n const { gzipSize } = await import(\"gzip-size\");\n const { readFile } = await import(\"node:fs/promises\");\n const content = await readFile(file);\n return gzipSize(content);\n}\n\n/**\n * Get the gzipped size of a file as a human-readable string.\n *\n * @param file - Path to the file\n * @returns The gzipped size formatted for display (for example, \"1.5 kB\")\n */\nexport async function getFilesizeGzippedInBytes(file: string): Promise<string> {\n try {\n const size = await getGzipSize(file);\n return prettyBytes(size);\n } catch (error) {\n if (error instanceof FileOperationError) {\n throw error;\n }\n throw new FileOperationError(\n \"get gzipped size of\",\n file,\n error as Error\n );\n }\n}\n\n/**\n * Get the gzipped file size in bytes.\n * @param file - Path to the file\n * @returns Gzipped file size in bytes\n * @example\n * const bytes = await getFilesizeGzippedRaw('bundle.js')\n * console.log(bytes) // 12583\n */\nexport async function getFilesizeGzippedRaw(file: string): Promise<number> {\n try {\n return await getGzipSize(file);\n } catch (error) {\n if (error instanceof FileOperationError) {\n throw error;\n }\n throw new FileOperationError(\n \"get gzipped size of\",\n file,\n error as Error\n );\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAmBA,eAAe,YAAY,MAA+B;AACtD,KAAI,CAAC,WAAW,KAAK,CACjB,OAAM,IAAI,mBACN,UACA,sBACA,IAAI,MAAM,sBAAsB,CACnC;AAGL,KAAI,CAAC,YAAY,KAAK,CAClB,OAAM,IAAI,mBACN,UACA,sBACA,IAAI,MAAM,2BAA2B,CACxC;CAGL,MAAM,EAAE,aAAa,MAAM,OAAO;CAClC,MAAM,EAAE,aAAa,MAAM,OAAO;AAElC,QAAO,SADS,MAAM,SAAS,KAAK,CACZ;;;;;;;;AAS5B,eAAsB,0BAA0B,MAA+B;AAC3E,KAAI;AAEA,SAAO,YADM,MAAM,YAAY,KAAK,CACZ;UACnB,OAAO;AACZ,MAAI,iBAAiB,mBACjB,OAAM;AAEV,QAAM,IAAI,mBACN,uBACA,MACA,MACH;;;;;;;;;;;AAYT,eAAsB,sBAAsB,MAA+B;AACvE,KAAI;AACA,SAAO,MAAM,YAAY,KAAK;UACzB,OAAO;AACZ,MAAI,iBAAiB,mBACjB,OAAM;AAEV,QAAM,IAAI,mBACN,uBACA,MACA,MACH"}
|
|
@@ -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,18 +1,22 @@
|
|
|
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, isLocalPath, resolveCompressor, tryResolveBuiltIn, tryResolveLocalFile, tryResolveNpmPackage } from "./compressor-resolver.js";
|
|
4
5
|
import { deleteFile } from "./deleteFile.js";
|
|
5
6
|
import { resetDeprecationWarnings, warnDeprecation } from "./deprecation.js";
|
|
6
7
|
import { ensureStringContent } from "./ensureStringContent.js";
|
|
8
|
+
import { validateMinifyResult, wrapMinificationError } from "./errors.js";
|
|
7
9
|
import { getContentFromFiles, getContentFromFilesAsync } from "./getContentFromFiles.js";
|
|
8
|
-
import {
|
|
10
|
+
import { getFilesizeBrotliInBytes, getFilesizeBrotliRaw } from "./getFilesizeBrotliInBytes.js";
|
|
11
|
+
import { getFilesizeGzippedInBytes, getFilesizeGzippedRaw } from "./getFilesizeGzippedInBytes.js";
|
|
9
12
|
import { getFilesizeInBytes } from "./getFilesizeInBytes.js";
|
|
13
|
+
import { isImageFile } from "./isImageFile.js";
|
|
10
14
|
import { isValidFile, isValidFileAsync } from "./isValidFile.js";
|
|
11
15
|
import { prettyBytes } from "./prettyBytes.js";
|
|
12
|
-
import { readFile } from "./readFile.js";
|
|
16
|
+
import { readFile, readFileAsync } from "./readFile.js";
|
|
13
17
|
import { run } from "./run.js";
|
|
14
18
|
import { setFileNameMin } from "./setFileNameMin.js";
|
|
15
19
|
import { setPublicFolder } from "./setPublicFolder.js";
|
|
16
20
|
import { wildcards } from "./wildcards.js";
|
|
17
|
-
import { writeFile } from "./writeFile.js";
|
|
18
|
-
export { type BuildArgsOptions, buildArgs, compressSingleFile, deleteFile, ensureStringContent, getContentFromFiles, getContentFromFilesAsync, getFilesizeGzippedInBytes, getFilesizeInBytes, isValidFile, isValidFileAsync, prettyBytes, readFile, resetDeprecationWarnings, run, setFileNameMin, setPublicFolder, toBuildArgsOptions, warnDeprecation, wildcards, writeFile };
|
|
21
|
+
import { writeFile, writeFileAsync } from "./writeFile.js";
|
|
22
|
+
export { type BuildArgsOptions, type CompressorResolution, buildArgs, compressSingleFile, deleteFile, ensureStringContent, getContentFromFiles, getContentFromFilesAsync, getFilesizeBrotliInBytes, getFilesizeBrotliRaw, getFilesizeGzippedInBytes, getFilesizeGzippedRaw, getFilesizeInBytes, getKnownExportName, isBuiltInCompressor, isImageFile, isLocalPath, isValidFile, isValidFileAsync, prettyBytes, readFile, readFileAsync, resetDeprecationWarnings, resolveCompressor, run, setFileNameMin, setPublicFolder, toBuildArgsOptions, tryResolveBuiltIn, tryResolveLocalFile, tryResolveNpmPackage, validateMinifyResult, warnDeprecation, wildcards, wrapMinificationError, writeFile, writeFileAsync };
|
package/dist/index.js
CHANGED
|
@@ -1,18 +1,22 @@
|
|
|
1
1
|
import { buildArgs, toBuildArgsOptions } from "./buildArgs.js";
|
|
2
|
-
import { n as isValidFileAsync, t as isValidFile } from "./isValidFile-
|
|
2
|
+
import { n as isValidFileAsync, t as isValidFile } from "./isValidFile-COstpeyW.js";
|
|
3
3
|
import { getContentFromFiles, getContentFromFilesAsync } from "./getContentFromFiles.js";
|
|
4
|
-
import {
|
|
4
|
+
import { isImageFile } from "./isImageFile.js";
|
|
5
|
+
import { readFile, readFileAsync } from "./readFile.js";
|
|
6
|
+
import { n as writeFileAsync, t as writeFile } from "./writeFile-mfUS3rMz.js";
|
|
5
7
|
import { run } from "./run.js";
|
|
6
8
|
import { compressSingleFile } from "./compressSingleFile.js";
|
|
9
|
+
import { getKnownExportName, isBuiltInCompressor, isLocalPath, resolveCompressor, tryResolveBuiltIn, tryResolveLocalFile, tryResolveNpmPackage } from "./compressor-resolver.js";
|
|
7
10
|
import { deleteFile } from "./deleteFile.js";
|
|
8
11
|
import { resetDeprecationWarnings, warnDeprecation } from "./deprecation.js";
|
|
9
12
|
import { ensureStringContent } from "./ensureStringContent.js";
|
|
13
|
+
import { validateMinifyResult, wrapMinificationError } from "./errors.js";
|
|
10
14
|
import { prettyBytes } from "./prettyBytes.js";
|
|
11
|
-
import {
|
|
15
|
+
import { getFilesizeBrotliInBytes, getFilesizeBrotliRaw } from "./getFilesizeBrotliInBytes.js";
|
|
16
|
+
import { getFilesizeGzippedInBytes, getFilesizeGzippedRaw } from "./getFilesizeGzippedInBytes.js";
|
|
12
17
|
import { getFilesizeInBytes } from "./getFilesizeInBytes.js";
|
|
13
|
-
import { readFile } from "./readFile.js";
|
|
14
18
|
import { setFileNameMin } from "./setFileNameMin.js";
|
|
15
19
|
import { setPublicFolder } from "./setPublicFolder.js";
|
|
16
20
|
import { wildcards } from "./wildcards.js";
|
|
17
21
|
|
|
18
|
-
export { buildArgs, compressSingleFile, deleteFile, ensureStringContent, getContentFromFiles, getContentFromFilesAsync, getFilesizeGzippedInBytes, getFilesizeInBytes, isValidFile, isValidFileAsync, prettyBytes, readFile, resetDeprecationWarnings, run, setFileNameMin, setPublicFolder, toBuildArgsOptions, warnDeprecation, wildcards, writeFile };
|
|
22
|
+
export { buildArgs, compressSingleFile, deleteFile, ensureStringContent, getContentFromFiles, getContentFromFilesAsync, getFilesizeBrotliInBytes, getFilesizeBrotliRaw, getFilesizeGzippedInBytes, getFilesizeGzippedRaw, getFilesizeInBytes, getKnownExportName, isBuiltInCompressor, isImageFile, isLocalPath, isValidFile, isValidFileAsync, prettyBytes, readFile, readFileAsync, resetDeprecationWarnings, resolveCompressor, run, setFileNameMin, setPublicFolder, toBuildArgsOptions, tryResolveBuiltIn, tryResolveLocalFile, tryResolveNpmPackage, validateMinifyResult, warnDeprecation, wildcards, wrapMinificationError, writeFile, writeFileAsync };
|
|
@@ -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"}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { t as FileOperationError } from "./error-
|
|
2
|
-
import { lstat } from "node:fs/promises";
|
|
1
|
+
import { t as FileOperationError } from "./error-CUgKxOvI.js";
|
|
3
2
|
import { existsSync, lstatSync } from "node:fs";
|
|
3
|
+
import { lstat } from "node:fs/promises";
|
|
4
4
|
|
|
5
5
|
//#region src/isValidFile.ts
|
|
6
6
|
/*!
|
|
7
7
|
* node-minify
|
|
8
|
-
* Copyright(c) 2011-
|
|
8
|
+
* Copyright (c) 2011-2026 Rodolphe Stoclin
|
|
9
9
|
* MIT Licensed
|
|
10
10
|
*/
|
|
11
11
|
/**
|
|
@@ -43,4 +43,4 @@ async function isValidFileAsync(path) {
|
|
|
43
43
|
|
|
44
44
|
//#endregion
|
|
45
45
|
export { isValidFileAsync as n, isValidFile as t };
|
|
46
|
-
//# sourceMappingURL=isValidFile-
|
|
46
|
+
//# sourceMappingURL=isValidFile-COstpeyW.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"isValidFile-COstpeyW.js","names":[],"sources":["../src/isValidFile.ts"],"sourcesContent":["/*!\n * node-minify\n * Copyright (c) 2011-2026 Rodolphe Stoclin\n * MIT Licensed\n */\n\nimport { existsSync, lstatSync } from \"node:fs\";\nimport { lstat } from \"node:fs/promises\";\nimport { FileOperationError } from \"./error.ts\";\n\n/**\n * Check if the path is a valid file.\n * @param path Path to check\n * @returns true if path exists and is a file, false otherwise\n * @throws {FileOperationError} If filesystem operations fail\n * @example\n * if (isValidFile('path/to/file.js')) {\n * // do something\n * }\n */\nexport function isValidFile(path: string): boolean {\n try {\n return existsSync(path) && !lstatSync(path).isDirectory();\n } catch (error) {\n throw new FileOperationError(\"validate\", path, error as Error);\n }\n}\n\n/**\n * Determine whether a filesystem path refers to an existing file (not a directory).\n *\n * @param path - Path to check\n * @returns `true` if the path exists and is a file, `false` otherwise.\n * @throws {FileOperationError} If a filesystem error other than `ENOENT` occurs while validating the path.\n */\nexport async function isValidFileAsync(path: string): Promise<boolean> {\n try {\n const stats = await lstat(path);\n return !stats.isDirectory();\n } catch (error: unknown) {\n if (\n error &&\n typeof error === \"object\" &&\n \"code\" in error &&\n error.code === \"ENOENT\"\n ) {\n return false;\n }\n throw new FileOperationError(\n \"validate\",\n path,\n error instanceof Error ? error : new Error(String(error))\n );\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAoBA,SAAgB,YAAY,MAAuB;AAC/C,KAAI;AACA,SAAO,WAAW,KAAK,IAAI,CAAC,UAAU,KAAK,CAAC,aAAa;UACpD,OAAO;AACZ,QAAM,IAAI,mBAAmB,YAAY,MAAM,MAAe;;;;;;;;;;AAWtE,eAAsB,iBAAiB,MAAgC;AACnE,KAAI;AAEA,SAAO,EADO,MAAM,MAAM,KAAK,EACjB,aAAa;UACtB,OAAgB;AACrB,MACI,SACA,OAAO,UAAU,YACjB,UAAU,SACV,MAAM,SAAS,SAEf,QAAO;AAEX,QAAM,IAAI,mBACN,YACA,MACA,iBAAiB,QAAQ,QAAQ,IAAI,MAAM,OAAO,MAAM,CAAC,CAC5D"}
|
package/dist/isValidFile.d.ts
CHANGED
package/dist/isValidFile.js
CHANGED
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-CUgKxOvI.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,7 +1,7 @@
|
|
|
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
|
/**
|
|
@@ -21,6 +21,17 @@ declare function readFile(file: string): string;
|
|
|
21
21
|
declare function readFile(file: string, asBuffer: true): Buffer;
|
|
22
22
|
declare function readFile(file: string, asBuffer: false): string;
|
|
23
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>;
|
|
24
35
|
//#endregion
|
|
25
|
-
export { readFile };
|
|
36
|
+
export { readFile, readFileAsync };
|
|
26
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,10 +1,11 @@
|
|
|
1
|
-
import { t as FileOperationError } from "./error-
|
|
1
|
+
import { t as FileOperationError } from "./error-CUgKxOvI.js";
|
|
2
2
|
import { readFileSync } from "node:fs";
|
|
3
|
+
import { readFile as readFile$1 } from "node:fs/promises";
|
|
3
4
|
|
|
4
5
|
//#region src/readFile.ts
|
|
5
6
|
/*!
|
|
6
7
|
* node-minify
|
|
7
|
-
* Copyright(c) 2011-
|
|
8
|
+
* Copyright (c) 2011-2026 Rodolphe Stoclin
|
|
8
9
|
* MIT Licensed
|
|
9
10
|
*/
|
|
10
11
|
/**
|
|
@@ -22,7 +23,22 @@ function readFile(file, asBuffer) {
|
|
|
22
23
|
throw new FileOperationError("read", file, error instanceof Error ? error : void 0);
|
|
23
24
|
}
|
|
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
|
+
}
|
|
40
|
+
}
|
|
25
41
|
|
|
26
42
|
//#endregion
|
|
27
|
-
export { readFile };
|
|
43
|
+
export { readFile, readFileAsync };
|
|
28
44
|
//# sourceMappingURL=readFile.js.map
|