@node-minify/utils 10.2.0 → 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/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 +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 +1 -1
- package/dist/ensureStringContent.js +1 -1
- package/dist/ensureStringContent.js.map +1 -1
- package/dist/{error-Ck87RwDD.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 +1 -1
- package/dist/getContentFromFiles.js +4 -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 +6 -3
- package/dist/index.js +7 -4
- 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-BW5AgBWb.js} +4 -4
- package/dist/isValidFile-BW5AgBWb.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 +39 -32
- 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-CzkB7gxg.d.ts} +8 -2
- 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 +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
package/LICENSE
CHANGED
package/dist/buildArgs.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/buildArgs.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
|
/**
|
package/dist/buildArgs.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"buildArgs.js","names":["result: BuildArgsOptions","args: string[]"],"sources":["../src/buildArgs.ts"],"sourcesContent":["/*!\n * node-minify\n * Copyright(c) 2011-
|
|
1
|
+
{"version":3,"file":"buildArgs.js","names":["result: BuildArgsOptions","args: string[]"],"sources":["../src/buildArgs.ts"],"sourcesContent":["/*!\n * node-minify\n * Copyright (c) 2011-2026 Rodolphe Stoclin\n * MIT Licensed\n */\n\nimport { ValidationError } from \"./error.ts\";\nimport type { BuildArgsOptions } from \"./types.ts\";\n\n/**\n * Converts a generic options object to BuildArgsOptions by filtering out non-primitive values.\n * Only keeps string, number, boolean, and undefined values.\n * @param options - Generic options object\n * @returns Filtered options compatible with buildArgs\n */\nexport function toBuildArgsOptions(\n options: Record<string, unknown>\n): BuildArgsOptions {\n const result: BuildArgsOptions = {};\n for (const [key, value] of Object.entries(options)) {\n if (\n typeof value === \"string\" ||\n typeof value === \"number\" ||\n typeof value === \"boolean\" ||\n value === undefined\n ) {\n result[key] = value;\n }\n }\n return result;\n}\n\n/**\n * Builds arguments array based on an object.\n * @param options Object containing command line arguments\n * @returns Array of command line arguments\n * @throws {ValidationError} If options is null or undefined\n * @example\n * buildArgs({ compress: true, output: 'file.min.js' })\n * // returns ['--compress', '--output', 'file.min.js']\n */\nexport function buildArgs(options: BuildArgsOptions): string[] {\n if (!options || typeof options !== \"object\") {\n throw new ValidationError(\"Options must be a valid object\");\n }\n\n const args: string[] = [];\n Object.entries(options).forEach(([key, value]) => {\n if (value !== undefined && value !== false) {\n args.push(`--${key}`);\n if (value !== true) {\n args.push(String(value));\n }\n }\n });\n\n return args;\n}\n"],"mappings":";;;;;;;;;;;;;;AAeA,SAAgB,mBACZ,SACgB;CAChB,MAAMA,SAA2B,EAAE;AACnC,MAAK,MAAM,CAAC,KAAK,UAAU,OAAO,QAAQ,QAAQ,CAC9C,KACI,OAAO,UAAU,YACjB,OAAO,UAAU,YACjB,OAAO,UAAU,aACjB,UAAU,OAEV,QAAO,OAAO;AAGtB,QAAO;;;;;;;;;;;AAYX,SAAgB,UAAU,SAAqC;AAC3D,KAAI,CAAC,WAAW,OAAO,YAAY,SAC/B,OAAM,IAAI,gBAAgB,iCAAiC;CAG/D,MAAMC,OAAiB,EAAE;AACzB,QAAO,QAAQ,QAAQ,CAAC,SAAS,CAAC,KAAK,WAAW;AAC9C,MAAI,UAAU,UAAa,UAAU,OAAO;AACxC,QAAK,KAAK,KAAK,MAAM;AACrB,OAAI,UAAU,KACV,MAAK,KAAK,OAAO,MAAM,CAAC;;GAGlC;AAEF,QAAO"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"compressSingleFile.d.ts","names":[],"sources":["../src/compressSingleFile.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"compressSingleFile.d.ts","names":[],"sources":["../src/compressSingleFile.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;iBAsBsB,6BACR,oBAAoB,6BACtB,SAAS,KAAK"}
|
|
@@ -1,37 +1,9 @@
|
|
|
1
1
|
import { getContentFromFilesAsync } from "./getContentFromFiles.js";
|
|
2
|
+
import { isImageFile } from "./isImageFile.js";
|
|
3
|
+
import { readFileAsync } from "./readFile.js";
|
|
2
4
|
import { run } from "./run.js";
|
|
3
|
-
import { readFile } from "node:fs/promises";
|
|
4
5
|
|
|
5
6
|
//#region src/compressSingleFile.ts
|
|
6
|
-
/*!
|
|
7
|
-
* node-minify
|
|
8
|
-
* Copyright(c) 2011-2025 Rodolphe Stoclin
|
|
9
|
-
* MIT Licensed
|
|
10
|
-
*/
|
|
11
|
-
const IMAGE_EXTENSIONS = new Set([
|
|
12
|
-
".png",
|
|
13
|
-
".jpg",
|
|
14
|
-
".jpeg",
|
|
15
|
-
".gif",
|
|
16
|
-
".webp",
|
|
17
|
-
".avif",
|
|
18
|
-
".tiff",
|
|
19
|
-
".tif",
|
|
20
|
-
".heif",
|
|
21
|
-
".heic"
|
|
22
|
-
]);
|
|
23
|
-
/**
|
|
24
|
-
* Determines whether a file path refers to a supported image file by its extension.
|
|
25
|
-
*
|
|
26
|
-
* @param filePath - The file name or path to check; may include directories.
|
|
27
|
-
* @returns `true` if the path ends with a recognized image extension, `false` otherwise.
|
|
28
|
-
*/
|
|
29
|
-
function isImageFile(filePath) {
|
|
30
|
-
const lastDot = filePath.lastIndexOf(".");
|
|
31
|
-
if (lastDot === -1) return false;
|
|
32
|
-
const ext = filePath.slice(lastDot).toLowerCase();
|
|
33
|
-
return IMAGE_EXTENSIONS.has(ext);
|
|
34
|
-
}
|
|
35
7
|
/**
|
|
36
8
|
* Compress a single file using the provided settings.
|
|
37
9
|
*
|
|
@@ -57,11 +29,13 @@ async function determineContent(settings) {
|
|
|
57
29
|
const imageFilesCount = settings.input.filter((file) => isImageFile(file)).length;
|
|
58
30
|
if (imageFilesCount > 0) {
|
|
59
31
|
if (imageFilesCount !== settings.input.length) throw new Error("Cannot mix image and text files in the same input array");
|
|
60
|
-
|
|
32
|
+
const firstInput = settings.input[0];
|
|
33
|
+
if (settings.input.length === 1 && firstInput) return await readFileAsync(firstInput, true);
|
|
34
|
+
return await Promise.all(settings.input.map((file) => readFileAsync(file, true)));
|
|
61
35
|
}
|
|
62
36
|
}
|
|
63
37
|
if (settings.input && typeof settings.input === "string") {
|
|
64
|
-
if (isImageFile(settings.input)) return await
|
|
38
|
+
if (isImageFile(settings.input)) return await readFileAsync(settings.input, true);
|
|
65
39
|
}
|
|
66
40
|
if (settings.input) return await getContentFromFilesAsync(settings.input);
|
|
67
41
|
return "";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"compressSingleFile.js","names":[],"sources":["../src/compressSingleFile.ts"],"sourcesContent":["/*!\n * node-minify\n * Copyright(c) 2011-
|
|
1
|
+
{"version":3,"file":"compressSingleFile.js","names":[],"sources":["../src/compressSingleFile.ts"],"sourcesContent":["/*!\n * node-minify\n * Copyright (c) 2011-2026 Rodolphe Stoclin\n * MIT Licensed\n */\n\nimport type {\n CompressorOptions,\n MinifierOptions,\n Settings,\n} from \"@node-minify/types\";\nimport { getContentFromFilesAsync } from \"./getContentFromFiles.ts\";\nimport { isImageFile } from \"./isImageFile.ts\";\nimport { readFileAsync } from \"./readFile.ts\";\nimport { run } from \"./run.ts\";\n\n/**\n * Compress a single file using the provided settings.\n *\n * @param settings - Configuration that specifies input content or input path(s) and compressor options\n * @returns The compressed output as a string\n */\nexport async function compressSingleFile<\n T extends CompressorOptions = CompressorOptions,\n>(settings: Settings<T>): Promise<string> {\n const content = await determineContent(settings);\n return run({ settings, content } as MinifierOptions<T>);\n}\n\n/**\n * Resolve the content to be minified from the provided settings.\n *\n * @param settings - Settings that may contain `content` or `input` (string or string[]); `content` is used preferentially.\n * @returns The resolved content: a `string` for text input, a `Buffer` for a single image file, or a `Buffer[]` for multiple image files.\n * @throws Error - If `settings.input` is an array that mixes image and non-image file paths.\n */\nasync function determineContent<\n T extends CompressorOptions = CompressorOptions,\n>(settings: Settings<T>): Promise<string | Buffer | Buffer[]> {\n if (settings.content) {\n return settings.content;\n }\n\n if (settings.input && Array.isArray(settings.input)) {\n const imageFilesCount = settings.input.filter((file) =>\n isImageFile(file)\n ).length;\n if (imageFilesCount > 0) {\n if (imageFilesCount !== settings.input.length) {\n throw new Error(\n \"Cannot mix image and text files in the same input array\"\n );\n }\n const firstInput = settings.input[0];\n if (settings.input.length === 1 && firstInput) {\n return await readFileAsync(firstInput, true);\n }\n return await Promise.all(\n settings.input.map((file) => readFileAsync(file, true))\n );\n }\n }\n\n if (settings.input && typeof settings.input === \"string\") {\n if (isImageFile(settings.input)) {\n return await readFileAsync(settings.input, true);\n }\n }\n\n if (settings.input) {\n return await getContentFromFilesAsync(settings.input);\n }\n\n return \"\";\n}\n"],"mappings":";;;;;;;;;;;;AAsBA,eAAsB,mBAEpB,UAAwC;AAEtC,QAAO,IAAI;EAAE;EAAU,SADP,MAAM,iBAAiB,SAAS;EAChB,CAAuB;;;;;;;;;AAU3D,eAAe,iBAEb,UAA4D;AAC1D,KAAI,SAAS,QACT,QAAO,SAAS;AAGpB,KAAI,SAAS,SAAS,MAAM,QAAQ,SAAS,MAAM,EAAE;EACjD,MAAM,kBAAkB,SAAS,MAAM,QAAQ,SAC3C,YAAY,KAAK,CACpB,CAAC;AACF,MAAI,kBAAkB,GAAG;AACrB,OAAI,oBAAoB,SAAS,MAAM,OACnC,OAAM,IAAI,MACN,0DACH;GAEL,MAAM,aAAa,SAAS,MAAM;AAClC,OAAI,SAAS,MAAM,WAAW,KAAK,WAC/B,QAAO,MAAM,cAAc,YAAY,KAAK;AAEhD,UAAO,MAAM,QAAQ,IACjB,SAAS,MAAM,KAAK,SAAS,cAAc,MAAM,KAAK,CAAC,CAC1D;;;AAIT,KAAI,SAAS,SAAS,OAAO,SAAS,UAAU,UAC5C;MAAI,YAAY,SAAS,MAAM,CAC3B,QAAO,MAAM,cAAc,SAAS,OAAO,KAAK;;AAIxD,KAAI,SAAS,MACT,QAAO,MAAM,yBAAyB,SAAS,MAAM;AAGzD,QAAO"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { t as Compressor } from "./types-CzkB7gxg.js";
|
|
2
|
+
|
|
3
|
+
//#region src/compressor-resolver.d.ts
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Result from resolving a compressor.
|
|
7
|
+
*/
|
|
8
|
+
type CompressorResolution = {
|
|
9
|
+
/**
|
|
10
|
+
* The resolved compressor function.
|
|
11
|
+
*/
|
|
12
|
+
compressor: Compressor;
|
|
13
|
+
/**
|
|
14
|
+
* Label for the compressor (used in logs/reports).
|
|
15
|
+
*/
|
|
16
|
+
label: string;
|
|
17
|
+
/**
|
|
18
|
+
* Whether this is a built-in @node-minify compressor.
|
|
19
|
+
*/
|
|
20
|
+
isBuiltIn: boolean;
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* Resolve a compressor by name from a built-in @node-minify package, an installed npm package, or a local file path.
|
|
24
|
+
*
|
|
25
|
+
* @param name - Compressor identifier: a built-in name (e.g., "terser"), an npm package name, or a local path (e.g., "./compressor.js")
|
|
26
|
+
* @returns The resolved CompressorResolution containing the compressor function, a display `label`, and `isBuiltIn` flag
|
|
27
|
+
* @throws Error if the compressor cannot be found or the module does not export a valid compressor function
|
|
28
|
+
*/
|
|
29
|
+
declare function resolveCompressor(name: string): Promise<CompressorResolution>;
|
|
30
|
+
/**
|
|
31
|
+
* Determines whether a compressor name corresponds to a known built-in compressor.
|
|
32
|
+
*
|
|
33
|
+
* @param name - The compressor identifier (e.g., built-in package name or alias)
|
|
34
|
+
* @returns `true` if the name corresponds to a known built-in compressor, `false` otherwise.
|
|
35
|
+
*/
|
|
36
|
+
declare function isBuiltInCompressor(name: string): boolean;
|
|
37
|
+
/**
|
|
38
|
+
* Return the known exported symbol name for a built-in compressor package.
|
|
39
|
+
*
|
|
40
|
+
* @param name - The compressor package name (for example, `"esbuild"`, `"terser"`)
|
|
41
|
+
* @returns The export name used by the built-in package, or `undefined` if the compressor is not a known built-in
|
|
42
|
+
*/
|
|
43
|
+
declare function getKnownExportName(name: string): string | undefined;
|
|
44
|
+
//#endregion
|
|
45
|
+
export { CompressorResolution, getKnownExportName, isBuiltInCompressor, resolveCompressor };
|
|
46
|
+
//# sourceMappingURL=compressor-resolver.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compressor-resolver.d.ts","names":[],"sources":["../src/compressor-resolver.ts"],"sourcesContent":[],"mappings":";;;;AAkRA;;;KAzOY,oBAAA;;;;cAII;;;;;;;;;;;;;;;;;iBAqHM,iBAAA,gBAEnB,QAAQ;;;;;;;iBAoGK,mBAAA;;;;;;;iBAUA,kBAAA"}
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import { pathToFileURL } from "node:url";
|
|
3
|
+
|
|
4
|
+
//#region src/compressor-resolver.ts
|
|
5
|
+
/*!
|
|
6
|
+
* node-minify
|
|
7
|
+
* Copyright (c) 2011-2026 Rodolphe Stoclin
|
|
8
|
+
* MIT Licensed
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* Known compressor exports for built-in @node-minify packages.
|
|
12
|
+
* Maps package name to the exported function name.
|
|
13
|
+
*/
|
|
14
|
+
const KNOWN_COMPRESSOR_EXPORTS = {
|
|
15
|
+
esbuild: "esbuild",
|
|
16
|
+
"google-closure-compiler": "gcc",
|
|
17
|
+
oxc: "oxc",
|
|
18
|
+
swc: "swc",
|
|
19
|
+
terser: "terser",
|
|
20
|
+
"uglify-js": "uglifyJs",
|
|
21
|
+
"babel-minify": "babelMinify",
|
|
22
|
+
"uglify-es": "uglifyEs",
|
|
23
|
+
yui: "yui",
|
|
24
|
+
"clean-css": "cleanCss",
|
|
25
|
+
cssnano: "cssnano",
|
|
26
|
+
csso: "csso",
|
|
27
|
+
lightningcss: "lightningCss",
|
|
28
|
+
crass: "crass",
|
|
29
|
+
sqwish: "sqwish",
|
|
30
|
+
"html-minifier": "htmlMinifier",
|
|
31
|
+
jsonminify: "jsonMinify",
|
|
32
|
+
imagemin: "imagemin",
|
|
33
|
+
sharp: "sharp",
|
|
34
|
+
svgo: "svgo",
|
|
35
|
+
"no-compress": "noCompress"
|
|
36
|
+
};
|
|
37
|
+
/**
|
|
38
|
+
* Determines whether a string represents a local file path.
|
|
39
|
+
*
|
|
40
|
+
* Recognizes POSIX-style relative or absolute paths starting with "./", "../", or "/",
|
|
41
|
+
* and Windows absolute paths like "C:\\" or "C:/".
|
|
42
|
+
*
|
|
43
|
+
* @param name - The path string to test
|
|
44
|
+
* @returns `true` if `name` appears to be a local file path, `false` otherwise
|
|
45
|
+
*/
|
|
46
|
+
function isLocalPath(name) {
|
|
47
|
+
return name.startsWith("./") || name.startsWith("../") || name.startsWith("/") || /^[a-zA-Z]:[\\/]/.test(name);
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Converts a package name to camelCase for export lookup.
|
|
51
|
+
*
|
|
52
|
+
* Examples: "my-tool" -> "myTool", "some_pkg" -> "somePkg"
|
|
53
|
+
*
|
|
54
|
+
* @returns The input `name` converted to camelCase where characters following `-` or `_` are uppercased
|
|
55
|
+
*/
|
|
56
|
+
function toCamelCase(name) {
|
|
57
|
+
return name.replace(/[-_](.)/g, (_, char) => char.toUpperCase());
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Resolve a compressor function exported by a loaded module.
|
|
61
|
+
*
|
|
62
|
+
* Searches the module's exports in this priority order to locate a usable compressor:
|
|
63
|
+
* 1. Known built-in export for the given name
|
|
64
|
+
* 2. CamelCase export derived from the package/base name
|
|
65
|
+
* 3. Named export `compressor`
|
|
66
|
+
* 4. Default export
|
|
67
|
+
* 5. First export whose value is a function
|
|
68
|
+
*
|
|
69
|
+
* @param mod - The imported module object to inspect for exports
|
|
70
|
+
* @param name - The package or file name used to derive known and camelCase export names
|
|
71
|
+
* @returns The resolved `Compressor` function if found, or `null` if no suitable function export exists
|
|
72
|
+
*/
|
|
73
|
+
function extractCompressor(mod, name) {
|
|
74
|
+
const knownExport = KNOWN_COMPRESSOR_EXPORTS[name];
|
|
75
|
+
if (knownExport && typeof mod[knownExport] === "function") return mod[knownExport];
|
|
76
|
+
const camelName = toCamelCase(name.includes("/") ? name.split("/").pop() ?? name : name);
|
|
77
|
+
if (typeof mod[camelName] === "function") return mod[camelName];
|
|
78
|
+
if (typeof mod.compressor === "function") return mod.compressor;
|
|
79
|
+
if (typeof mod.default === "function") return mod.default;
|
|
80
|
+
for (const value of Object.values(mod)) if (typeof value === "function") return value;
|
|
81
|
+
return null;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Create a display label from a compressor package name or a local file path.
|
|
85
|
+
*
|
|
86
|
+
* @param name - Compressor npm package name or a local file path (./, ../, /, or Windows absolute).
|
|
87
|
+
* @returns The package name for npm compressors, or the local file's basename without its .js/.ts/.mjs/.cjs extension.
|
|
88
|
+
*/
|
|
89
|
+
function generateLabel(name) {
|
|
90
|
+
if (isLocalPath(name)) return path.basename(name).replace(/\.(js|ts|mjs|cjs)$/, "");
|
|
91
|
+
return name;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Resolve a compressor by name from a built-in @node-minify package, an installed npm package, or a local file path.
|
|
95
|
+
*
|
|
96
|
+
* @param name - Compressor identifier: a built-in name (e.g., "terser"), an npm package name, or a local path (e.g., "./compressor.js")
|
|
97
|
+
* @returns The resolved CompressorResolution containing the compressor function, a display `label`, and `isBuiltIn` flag
|
|
98
|
+
* @throws Error if the compressor cannot be found or the module does not export a valid compressor function
|
|
99
|
+
*/
|
|
100
|
+
async function resolveCompressor(name) {
|
|
101
|
+
if (name in KNOWN_COMPRESSOR_EXPORTS) try {
|
|
102
|
+
const compressor = extractCompressor(await import(`@node-minify/${name}`), name);
|
|
103
|
+
if (compressor) return {
|
|
104
|
+
compressor,
|
|
105
|
+
label: name,
|
|
106
|
+
isBuiltIn: true
|
|
107
|
+
};
|
|
108
|
+
} catch {}
|
|
109
|
+
try {
|
|
110
|
+
const compressor = extractCompressor(await import(name), name);
|
|
111
|
+
if (compressor) return {
|
|
112
|
+
compressor,
|
|
113
|
+
label: generateLabel(name),
|
|
114
|
+
isBuiltIn: false
|
|
115
|
+
};
|
|
116
|
+
throw new Error(`Package '${name}' doesn't export a valid compressor function. Expected a function as default export, named export 'compressor', or named export '${toCamelCase(name)}'.`);
|
|
117
|
+
} catch (error) {
|
|
118
|
+
if (error instanceof Error && error.message.includes("doesn't export a valid compressor")) throw error;
|
|
119
|
+
if (isLocalPath(name)) try {
|
|
120
|
+
const compressor = extractCompressor(await import(pathToFileURL(path.resolve(process.cwd(), name)).href), name);
|
|
121
|
+
if (compressor) return {
|
|
122
|
+
compressor,
|
|
123
|
+
label: generateLabel(name),
|
|
124
|
+
isBuiltIn: false
|
|
125
|
+
};
|
|
126
|
+
throw new Error(`Local file '${name}' doesn't export a valid compressor function. Expected a function as default export or named export 'compressor'.`);
|
|
127
|
+
} catch (localError) {
|
|
128
|
+
if (localError instanceof Error && localError.message.includes("doesn't export a valid compressor")) throw localError;
|
|
129
|
+
throw new Error(`Could not load local compressor '${name}'. File not found or failed to import: ${localError instanceof Error ? localError.message : String(localError)}`);
|
|
130
|
+
}
|
|
131
|
+
throw new Error(`Could not resolve compressor '${name}'. Is it installed? For local files, use a path starting with './' or '/'.`);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Determines whether a compressor name corresponds to a known built-in compressor.
|
|
136
|
+
*
|
|
137
|
+
* @param name - The compressor identifier (e.g., built-in package name or alias)
|
|
138
|
+
* @returns `true` if the name corresponds to a known built-in compressor, `false` otherwise.
|
|
139
|
+
*/
|
|
140
|
+
function isBuiltInCompressor(name) {
|
|
141
|
+
return name in KNOWN_COMPRESSOR_EXPORTS;
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Return the known exported symbol name for a built-in compressor package.
|
|
145
|
+
*
|
|
146
|
+
* @param name - The compressor package name (for example, `"esbuild"`, `"terser"`)
|
|
147
|
+
* @returns The export name used by the built-in package, or `undefined` if the compressor is not a known built-in
|
|
148
|
+
*/
|
|
149
|
+
function getKnownExportName(name) {
|
|
150
|
+
return KNOWN_COMPRESSOR_EXPORTS[name];
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
//#endregion
|
|
154
|
+
export { getKnownExportName, isBuiltInCompressor, resolveCompressor };
|
|
155
|
+
//# sourceMappingURL=compressor-resolver.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compressor-resolver.js","names":["KNOWN_COMPRESSOR_EXPORTS: Record<string, string>"],"sources":["../src/compressor-resolver.ts"],"sourcesContent":["/*!\n * node-minify\n * Copyright (c) 2011-2026 Rodolphe Stoclin\n * MIT Licensed\n */\n\nimport path from \"node:path\";\nimport { pathToFileURL } from \"node:url\";\nimport type { Compressor } from \"@node-minify/types\";\n\n/**\n * Known compressor exports for built-in @node-minify packages.\n * Maps package name to the exported function name.\n */\nconst KNOWN_COMPRESSOR_EXPORTS: Record<string, string> = {\n esbuild: \"esbuild\",\n \"google-closure-compiler\": \"gcc\",\n oxc: \"oxc\",\n swc: \"swc\",\n terser: \"terser\",\n \"uglify-js\": \"uglifyJs\",\n \"babel-minify\": \"babelMinify\",\n \"uglify-es\": \"uglifyEs\",\n yui: \"yui\",\n \"clean-css\": \"cleanCss\",\n cssnano: \"cssnano\",\n csso: \"csso\",\n lightningcss: \"lightningCss\",\n crass: \"crass\",\n sqwish: \"sqwish\",\n \"html-minifier\": \"htmlMinifier\",\n jsonminify: \"jsonMinify\",\n imagemin: \"imagemin\",\n sharp: \"sharp\",\n svgo: \"svgo\",\n \"no-compress\": \"noCompress\",\n};\n\n/**\n * Result from resolving a compressor.\n */\nexport type CompressorResolution = {\n /**\n * The resolved compressor function.\n */\n compressor: Compressor;\n\n /**\n * Label for the compressor (used in logs/reports).\n */\n label: string;\n\n /**\n * Whether this is a built-in @node-minify compressor.\n */\n isBuiltIn: boolean;\n};\n\n/**\n * Determines whether a string represents a local file path.\n *\n * Recognizes POSIX-style relative or absolute paths starting with \"./\", \"../\", or \"/\",\n * and Windows absolute paths like \"C:\\\\\" or \"C:/\".\n *\n * @param name - The path string to test\n * @returns `true` if `name` appears to be a local file path, `false` otherwise\n */\nfunction isLocalPath(name: string): boolean {\n return (\n name.startsWith(\"./\") ||\n name.startsWith(\"../\") ||\n name.startsWith(\"/\") ||\n /^[a-zA-Z]:[\\\\/]/.test(name) // Windows absolute path\n );\n}\n\n/**\n * Converts a package name to camelCase for export lookup.\n *\n * Examples: \"my-tool\" -> \"myTool\", \"some_pkg\" -> \"somePkg\"\n *\n * @returns The input `name` converted to camelCase where characters following `-` or `_` are uppercased\n */\nfunction toCamelCase(name: string): string {\n return name.replace(/[-_](.)/g, (_, char) => char.toUpperCase());\n}\n\n/**\n * Resolve a compressor function exported by a loaded module.\n *\n * Searches the module's exports in this priority order to locate a usable compressor:\n * 1. Known built-in export for the given name\n * 2. CamelCase export derived from the package/base name\n * 3. Named export `compressor`\n * 4. Default export\n * 5. First export whose value is a function\n *\n * @param mod - The imported module object to inspect for exports\n * @param name - The package or file name used to derive known and camelCase export names\n * @returns The resolved `Compressor` function if found, or `null` if no suitable function export exists\n */\nfunction extractCompressor(\n mod: Record<string, unknown>,\n name: string\n): Compressor | null {\n // 1. Check known exports first\n const knownExport = KNOWN_COMPRESSOR_EXPORTS[name];\n if (knownExport && typeof mod[knownExport] === \"function\") {\n return mod[knownExport] as Compressor;\n }\n\n // 2. Try camelCase of package name\n const baseName = name.includes(\"/\")\n ? (name.split(\"/\").pop() ?? name)\n : name;\n const camelName = toCamelCase(baseName);\n if (typeof mod[camelName] === \"function\") {\n return mod[camelName] as Compressor;\n }\n\n // 3. Try \"compressor\" named export\n if (typeof mod.compressor === \"function\") {\n return mod.compressor as Compressor;\n }\n\n // 4. Try default export\n if (typeof mod.default === \"function\") {\n return mod.default as Compressor;\n }\n\n // 5. Find first function export\n for (const value of Object.values(mod)) {\n if (typeof value === \"function\") {\n return value as Compressor;\n }\n }\n\n return null;\n}\n\n/**\n * Create a display label from a compressor package name or a local file path.\n *\n * @param name - Compressor npm package name or a local file path (./, ../, /, or Windows absolute).\n * @returns The package name for npm compressors, or the local file's basename without its .js/.ts/.mjs/.cjs extension.\n */\nfunction generateLabel(name: string): string {\n if (isLocalPath(name)) {\n // For local paths, use the filename without extension\n return path.basename(name).replace(/\\.(js|ts|mjs|cjs)$/, \"\");\n }\n // For npm packages, use as-is\n return name;\n}\n\n/**\n * Resolve a compressor by name from a built-in @node-minify package, an installed npm package, or a local file path.\n *\n * @param name - Compressor identifier: a built-in name (e.g., \"terser\"), an npm package name, or a local path (e.g., \"./compressor.js\")\n * @returns The resolved CompressorResolution containing the compressor function, a display `label`, and `isBuiltIn` flag\n * @throws Error if the compressor cannot be found or the module does not export a valid compressor function\n */\nexport async function resolveCompressor(\n name: string\n): Promise<CompressorResolution> {\n const isKnown = name in KNOWN_COMPRESSOR_EXPORTS;\n\n // 1. Try built-in @node-minify package\n if (isKnown) {\n try {\n const mod = (await import(`@node-minify/${name}`)) as Record<\n string,\n unknown\n >;\n const compressor = extractCompressor(mod, name);\n\n if (compressor) {\n return {\n compressor,\n label: name,\n isBuiltIn: true,\n };\n }\n } catch {\n // Built-in package not installed, will try as external\n }\n }\n\n // 2. Try as npm package\n try {\n const mod = (await import(name)) as Record<string, unknown>;\n const compressor = extractCompressor(mod, name);\n\n if (compressor) {\n return {\n compressor,\n label: generateLabel(name),\n isBuiltIn: false,\n };\n }\n\n throw new Error(\n `Package '${name}' doesn't export a valid compressor function. ` +\n `Expected a function as default export, named export 'compressor', or ` +\n `named export '${toCamelCase(name)}'.`\n );\n } catch (error) {\n // If it's our error about invalid exports, rethrow\n if (\n error instanceof Error &&\n error.message.includes(\"doesn't export a valid compressor\")\n ) {\n throw error;\n }\n\n // 3. Try as local file path\n if (isLocalPath(name)) {\n try {\n const absolutePath = path.resolve(process.cwd(), name);\n const fileUrl = pathToFileURL(absolutePath).href;\n const mod = (await import(fileUrl)) as Record<string, unknown>;\n const compressor = extractCompressor(mod, name);\n\n if (compressor) {\n return {\n compressor,\n label: generateLabel(name),\n isBuiltIn: false,\n };\n }\n\n throw new Error(\n `Local file '${name}' doesn't export a valid compressor function. ` +\n `Expected a function as default export or named export 'compressor'.`\n );\n } catch (localError) {\n if (\n localError instanceof Error &&\n localError.message.includes(\n \"doesn't export a valid compressor\"\n )\n ) {\n throw localError;\n }\n throw new Error(\n `Could not load local compressor '${name}'. ` +\n `File not found or failed to import: ${localError instanceof Error ? localError.message : String(localError)}`\n );\n }\n }\n\n throw new Error(\n `Could not resolve compressor '${name}'. ` +\n `Is it installed? For local files, use a path starting with './' or '/'.`\n );\n }\n}\n\n/**\n * Determines whether a compressor name corresponds to a known built-in compressor.\n *\n * @param name - The compressor identifier (e.g., built-in package name or alias)\n * @returns `true` if the name corresponds to a known built-in compressor, `false` otherwise.\n */\nexport function isBuiltInCompressor(name: string): boolean {\n return name in KNOWN_COMPRESSOR_EXPORTS;\n}\n\n/**\n * Return the known exported symbol name for a built-in compressor package.\n *\n * @param name - The compressor package name (for example, `\"esbuild\"`, `\"terser\"`)\n * @returns The export name used by the built-in package, or `undefined` if the compressor is not a known built-in\n */\nexport function getKnownExportName(name: string): string | undefined {\n return KNOWN_COMPRESSOR_EXPORTS[name];\n}\n"],"mappings":";;;;;;;;;;;;;AAcA,MAAMA,2BAAmD;CACrD,SAAS;CACT,2BAA2B;CAC3B,KAAK;CACL,KAAK;CACL,QAAQ;CACR,aAAa;CACb,gBAAgB;CAChB,aAAa;CACb,KAAK;CACL,aAAa;CACb,SAAS;CACT,MAAM;CACN,cAAc;CACd,OAAO;CACP,QAAQ;CACR,iBAAiB;CACjB,YAAY;CACZ,UAAU;CACV,OAAO;CACP,MAAM;CACN,eAAe;CAClB;;;;;;;;;;AA+BD,SAAS,YAAY,MAAuB;AACxC,QACI,KAAK,WAAW,KAAK,IACrB,KAAK,WAAW,MAAM,IACtB,KAAK,WAAW,IAAI,IACpB,kBAAkB,KAAK,KAAK;;;;;;;;;AAWpC,SAAS,YAAY,MAAsB;AACvC,QAAO,KAAK,QAAQ,aAAa,GAAG,SAAS,KAAK,aAAa,CAAC;;;;;;;;;;;;;;;;AAiBpE,SAAS,kBACL,KACA,MACiB;CAEjB,MAAM,cAAc,yBAAyB;AAC7C,KAAI,eAAe,OAAO,IAAI,iBAAiB,WAC3C,QAAO,IAAI;CAOf,MAAM,YAAY,YAHD,KAAK,SAAS,IAAI,GAC5B,KAAK,MAAM,IAAI,CAAC,KAAK,IAAI,OAC1B,KACiC;AACvC,KAAI,OAAO,IAAI,eAAe,WAC1B,QAAO,IAAI;AAIf,KAAI,OAAO,IAAI,eAAe,WAC1B,QAAO,IAAI;AAIf,KAAI,OAAO,IAAI,YAAY,WACvB,QAAO,IAAI;AAIf,MAAK,MAAM,SAAS,OAAO,OAAO,IAAI,CAClC,KAAI,OAAO,UAAU,WACjB,QAAO;AAIf,QAAO;;;;;;;;AASX,SAAS,cAAc,MAAsB;AACzC,KAAI,YAAY,KAAK,CAEjB,QAAO,KAAK,SAAS,KAAK,CAAC,QAAQ,sBAAsB,GAAG;AAGhE,QAAO;;;;;;;;;AAUX,eAAsB,kBAClB,MAC6B;AAI7B,KAHgB,QAAQ,yBAIpB,KAAI;EAKA,MAAM,aAAa,kBAJN,MAAM,OAAO,gBAAgB,SAIA,KAAK;AAE/C,MAAI,WACA,QAAO;GACH;GACA,OAAO;GACP,WAAW;GACd;SAED;AAMZ,KAAI;EAEA,MAAM,aAAa,kBADN,MAAM,OAAO,OACgB,KAAK;AAE/C,MAAI,WACA,QAAO;GACH;GACA,OAAO,cAAc,KAAK;GAC1B,WAAW;GACd;AAGL,QAAM,IAAI,MACN,YAAY,KAAK,mIAEI,YAAY,KAAK,CAAC,IAC1C;UACI,OAAO;AAEZ,MACI,iBAAiB,SACjB,MAAM,QAAQ,SAAS,oCAAoC,CAE3D,OAAM;AAIV,MAAI,YAAY,KAAK,CACjB,KAAI;GAIA,MAAM,aAAa,kBADN,MAAM,OADH,cADK,KAAK,QAAQ,QAAQ,KAAK,EAAE,KAAK,CACX,CAAC,OAEF,KAAK;AAE/C,OAAI,WACA,QAAO;IACH;IACA,OAAO,cAAc,KAAK;IAC1B,WAAW;IACd;AAGL,SAAM,IAAI,MACN,eAAe,KAAK,mHAEvB;WACI,YAAY;AACjB,OACI,sBAAsB,SACtB,WAAW,QAAQ,SACf,oCACH,CAED,OAAM;AAEV,SAAM,IAAI,MACN,oCAAoC,KAAK,yCACE,sBAAsB,QAAQ,WAAW,UAAU,OAAO,WAAW,GACnH;;AAIT,QAAM,IAAI,MACN,iCAAiC,KAAK,4EAEzC;;;;;;;;;AAUT,SAAgB,oBAAoB,MAAuB;AACvD,QAAO,QAAQ;;;;;;;;AASnB,SAAgB,mBAAmB,MAAkC;AACjE,QAAO,yBAAyB"}
|
package/dist/deleteFile.d.ts
CHANGED
package/dist/deleteFile.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { t as FileOperationError } from "./error-
|
|
1
|
+
import { t as FileOperationError } from "./error-Ctspysdk.js";
|
|
2
2
|
import { existsSync, unlinkSync } from "node:fs";
|
|
3
3
|
|
|
4
4
|
//#region src/deleteFile.ts
|
|
5
5
|
/*!
|
|
6
6
|
* node-minify
|
|
7
|
-
* Copyright(c) 2011-
|
|
7
|
+
* Copyright (c) 2011-2026 Rodolphe Stoclin
|
|
8
8
|
* MIT Licensed
|
|
9
9
|
*/
|
|
10
10
|
/**
|
package/dist/deleteFile.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"deleteFile.js","names":[],"sources":["../src/deleteFile.ts"],"sourcesContent":["/*!\n * node-minify\n * Copyright(c) 2011-
|
|
1
|
+
{"version":3,"file":"deleteFile.js","names":[],"sources":["../src/deleteFile.ts"],"sourcesContent":["/*!\n * node-minify\n * Copyright (c) 2011-2026 Rodolphe Stoclin\n * MIT Licensed\n */\n\nimport { existsSync, unlinkSync } from \"node:fs\";\nimport { FileOperationError } from \"./error.ts\";\n\n/**\n * Delete file from the filesystem.\n * @param file Path to the file to delete\n * @throws {FileOperationError} If file doesn't exist or deletion fails\n * @example\n * deleteFile('path/to/file.js')\n */\nexport function deleteFile(file: string): void {\n try {\n if (!existsSync(file)) {\n throw new Error(\"File does not exist\");\n }\n unlinkSync(file);\n } catch (error) {\n throw new FileOperationError(\"delete\", file, error as Error);\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAgBA,SAAgB,WAAW,MAAoB;AAC3C,KAAI;AACA,MAAI,CAAC,WAAW,KAAK,CACjB,OAAM,IAAI,MAAM,sBAAsB;AAE1C,aAAW,KAAK;UACX,OAAO;AACZ,QAAM,IAAI,mBAAmB,UAAU,MAAM,MAAe"}
|
package/dist/deprecation.d.ts
CHANGED
package/dist/deprecation.js
CHANGED
package/dist/deprecation.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"deprecation.js","names":[],"sources":["../src/deprecation.ts"],"sourcesContent":["/*!\n * node-minify\n * Copyright(c) 2011-
|
|
1
|
+
{"version":3,"file":"deprecation.js","names":[],"sources":["../src/deprecation.ts"],"sourcesContent":["/*!\n * node-minify\n * Copyright (c) 2011-2026 Rodolphe Stoclin\n * MIT Licensed\n */\n\nconst warnedPackages = new Set<string>();\n\n/**\n * Show a deprecation warning for a package, but only once per process.\n * Subsequent calls with the same package name will be ignored.\n *\n * @param packageName - The package name (e.g., \"babel-minify\", \"uglify-es\")\n * @param message - The deprecation message explaining why and what to use instead\n *\n * @example\n * ```ts\n * warnDeprecation(\n * \"babel-minify\",\n * \"babel-minify uses Babel 6 which is no longer maintained. \" +\n * \"Please migrate to @node-minify/terser for continued support.\"\n * );\n * ```\n */\nexport function warnDeprecation(packageName: string, message: string): void {\n if (warnedPackages.has(packageName)) {\n return;\n }\n\n warnedPackages.add(packageName);\n console.warn(`[@node-minify/${packageName}] DEPRECATED: ${message}`);\n}\n\n/**\n * Reset the deprecation warning state.\n * Only intended for testing purposes.\n */\nexport function resetDeprecationWarnings(): void {\n warnedPackages.clear();\n}\n"],"mappings":";;;;;;AAMA,MAAM,iCAAiB,IAAI,KAAa;;;;;;;;;;;;;;;;;AAkBxC,SAAgB,gBAAgB,aAAqB,SAAuB;AACxE,KAAI,eAAe,IAAI,YAAY,CAC/B;AAGJ,gBAAe,IAAI,YAAY;AAC/B,SAAQ,KAAK,iBAAiB,YAAY,gBAAgB,UAAU;;;;;;AAOxE,SAAgB,2BAAiC;AAC7C,gBAAe,OAAO"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ensureStringContent.js","names":[],"sources":["../src/ensureStringContent.ts"],"sourcesContent":["/*!\n * node-minify\n * Copyright(c) 2011-
|
|
1
|
+
{"version":3,"file":"ensureStringContent.js","names":[],"sources":["../src/ensureStringContent.ts"],"sourcesContent":["/*!\n * node-minify\n * Copyright (c) 2011-2026 Rodolphe Stoclin\n * MIT Licensed\n */\n\n/**\n * Convert provided content to a string suitable for text-based compressors.\n *\n * @param content - The input content; a `Buffer` is converted to a string, `undefined` becomes an empty string, and a `Buffer[]` is rejected.\n * @param compressorName - Name used in the error message when array content is not supported.\n * @returns The content as a string; returns an empty string when `content` is `undefined`.\n * @throws Error if `content` is an array with message \"`<compressorName> compressor does not support array content`\".\n */\nexport function ensureStringContent(\n content: string | Buffer | Buffer[] | undefined,\n compressorName: string\n): string {\n if (Array.isArray(content)) {\n throw new Error(\n `${compressorName} compressor does not support array content`\n );\n }\n\n if (Buffer.isBuffer(content)) {\n return content.toString();\n }\n\n return content ?? \"\";\n}\n"],"mappings":";;;;;;;;;;;;;;AAcA,SAAgB,oBACZ,SACA,gBACM;AACN,KAAI,MAAM,QAAQ,QAAQ,CACtB,OAAM,IAAI,MACN,GAAG,eAAe,4CACrB;AAGL,KAAI,OAAO,SAAS,QAAQ,CACxB,QAAO,QAAQ,UAAU;AAG7B,QAAO,WAAW"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
//#region src/error.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
|
/**
|
|
@@ -9,9 +9,11 @@
|
|
|
9
9
|
* @extends Error
|
|
10
10
|
*/
|
|
11
11
|
var FileOperationError = class extends Error {
|
|
12
|
+
cause;
|
|
12
13
|
constructor(operation, path, originalError) {
|
|
13
|
-
super(`Failed to ${operation} file ${path}: ${originalError?.message || ""}
|
|
14
|
+
super(`Failed to ${operation} file ${path}: ${originalError?.message || ""}`, originalError ? { cause: originalError } : void 0);
|
|
14
15
|
this.name = "FileOperationError";
|
|
16
|
+
if (originalError && !this.cause) this.cause = originalError;
|
|
15
17
|
}
|
|
16
18
|
};
|
|
17
19
|
/**
|
|
@@ -27,4 +29,4 @@ var ValidationError = class extends Error {
|
|
|
27
29
|
|
|
28
30
|
//#endregion
|
|
29
31
|
export { ValidationError as n, FileOperationError as t };
|
|
30
|
-
//# sourceMappingURL=error-
|
|
32
|
+
//# sourceMappingURL=error-Ctspysdk.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"error-Ctspysdk.js","names":[],"sources":["../src/error.ts"],"sourcesContent":["/*!\n * node-minify\n * Copyright (c) 2011-2026 Rodolphe Stoclin\n * MIT Licensed\n */\n\n/**\n * Error class for file operation failures.\n * @extends Error\n */\nexport class FileOperationError extends Error {\n override cause?: Error;\n\n constructor(operation: string, path: string, originalError?: Error) {\n super(\n `Failed to ${operation} file ${path}: ${originalError?.message || \"\"}`,\n originalError ? { cause: originalError } : undefined\n );\n this.name = \"FileOperationError\";\n // For older runtimes that don't support the cause option\n if (originalError && !this.cause) {\n this.cause = originalError;\n }\n }\n}\n\n/**\n * Error class for validation failures.\n * @extends Error\n */\nexport class ValidationError extends Error {\n constructor(message: string) {\n super(message);\n this.name = \"ValidationError\";\n }\n}\n"],"mappings":";;;;;;;;;;AAUA,IAAa,qBAAb,cAAwC,MAAM;CAC1C,AAAS;CAET,YAAY,WAAmB,MAAc,eAAuB;AAChE,QACI,aAAa,UAAU,QAAQ,KAAK,IAAI,eAAe,WAAW,MAClE,gBAAgB,EAAE,OAAO,eAAe,GAAG,OAC9C;AACD,OAAK,OAAO;AAEZ,MAAI,iBAAiB,CAAC,KAAK,MACvB,MAAK,QAAQ;;;;;;;AASzB,IAAa,kBAAb,cAAqC,MAAM;CACvC,YAAY,SAAiB;AACzB,QAAM,QAAQ;AACd,OAAK,OAAO"}
|
package/dist/error.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
//#region src/error.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
|
/**
|
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
* @extends Error
|
|
10
10
|
*/
|
|
11
11
|
declare class FileOperationError extends Error {
|
|
12
|
+
cause?: Error;
|
|
12
13
|
constructor(operation: string, path: string, originalError?: Error);
|
|
13
14
|
}
|
|
14
15
|
/**
|
package/dist/error.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"error.d.ts","names":[],"sources":["../src/error.ts"],"sourcesContent":[],"mappings":";;AAUA
|
|
1
|
+
{"version":3,"file":"error.d.ts","names":[],"sources":["../src/error.ts"],"sourcesContent":[],"mappings":";;AAUA;;;;;AAoBA;;;cApBa,kBAAA,SAA2B,KAAA;UACnB;+DAE4C;;;;;;cAiBpD,eAAA,SAAwB,KAAA"}
|
package/dist/error.js
CHANGED
|
@@ -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-Ctspysdk.js";
|
|
2
|
+
import { t as isValidFile } from "./isValidFile-BW5AgBWb.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":["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"}
|