@node-minify/utils 10.1.1 → 10.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -1
- package/README.md +4 -4
- package/dist/buildArgs.js +2 -2
- package/dist/buildArgs.js.map +1 -1
- package/dist/compressSingleFile.d.ts +6 -4
- package/dist/compressSingleFile.d.ts.map +1 -1
- package/dist/compressSingleFile.js +27 -9
- package/dist/compressSingleFile.js.map +1 -1
- package/dist/compressor-resolver.d.ts +46 -0
- package/dist/compressor-resolver.d.ts.map +1 -0
- package/dist/compressor-resolver.js +155 -0
- package/dist/compressor-resolver.js.map +1 -0
- package/dist/deleteFile.d.ts +1 -1
- package/dist/deleteFile.js +2 -2
- package/dist/deleteFile.js.map +1 -1
- package/dist/deprecation.d.ts +1 -1
- package/dist/deprecation.js +1 -1
- package/dist/deprecation.js.map +1 -1
- package/dist/ensureStringContent.d.ts +18 -0
- package/dist/ensureStringContent.d.ts.map +1 -0
- package/dist/ensureStringContent.js +23 -0
- package/dist/ensureStringContent.js.map +1 -0
- package/dist/{error-B_uK-F18.js → error-Ctspysdk.js} +5 -3
- package/dist/error-Ctspysdk.js.map +1 -0
- package/dist/error.d.ts +2 -1
- package/dist/error.d.ts.map +1 -1
- package/dist/error.js +1 -1
- package/dist/getContentFromFiles.d.ts +11 -2
- package/dist/getContentFromFiles.d.ts.map +1 -1
- package/dist/getContentFromFiles.js +38 -4
- package/dist/getContentFromFiles.js.map +1 -1
- package/dist/getFilesizeBrotliInBytes.d.ts +10 -0
- package/dist/getFilesizeBrotliInBytes.d.ts.map +1 -0
- package/dist/getFilesizeBrotliInBytes.js +29 -0
- package/dist/getFilesizeBrotliInBytes.js.map +1 -0
- package/dist/getFilesizeGzippedInBytes.d.ts +1 -1
- package/dist/getFilesizeGzippedInBytes.js +3 -3
- package/dist/getFilesizeGzippedInBytes.js.map +1 -1
- package/dist/getFilesizeInBytes.d.ts +1 -1
- package/dist/getFilesizeInBytes.js +1 -1
- package/dist/getFilesizeInBytes.js.map +1 -1
- package/dist/index.d.ts +9 -5
- package/dist/index.js +9 -5
- package/dist/isImageFile.d.ts +16 -0
- package/dist/isImageFile.d.ts.map +1 -0
- package/dist/isImageFile.js +35 -0
- package/dist/isImageFile.js.map +1 -0
- package/dist/isValidFile-BW5AgBWb.js +46 -0
- package/dist/isValidFile-BW5AgBWb.js.map +1 -0
- package/dist/isValidFile.d.ts +10 -2
- package/dist/isValidFile.d.ts.map +1 -1
- package/dist/isValidFile.js +2 -2
- package/dist/prettyBytes.d.ts +1 -1
- package/dist/prettyBytes.js +2 -2
- package/dist/prettyBytes.js.map +1 -1
- package/dist/readFile.d.ts +25 -3
- package/dist/readFile.d.ts.map +1 -1
- package/dist/readFile.js +31 -7
- package/dist/readFile.js.map +1 -1
- package/dist/run.d.ts +10 -12
- package/dist/run.d.ts.map +1 -1
- package/dist/run.js +114 -12
- package/dist/run.js.map +1 -1
- package/dist/setFileNameMin.d.ts +1 -1
- package/dist/setFileNameMin.js +2 -2
- package/dist/setFileNameMin.js.map +1 -1
- package/dist/setPublicFolder.d.ts +1 -1
- package/dist/setPublicFolder.js +1 -1
- package/dist/setPublicFolder.js.map +1 -1
- package/dist/{types-DtDQlx-T.d.ts → types-CzkB7gxg.d.ts} +51 -4
- package/dist/types-CzkB7gxg.d.ts.map +1 -0
- package/dist/types.d.ts +1 -1
- package/dist/wildcards.d.ts +1 -1
- package/dist/wildcards.js +1 -1
- package/dist/wildcards.js.map +1 -1
- package/dist/writeFile-DgV8EbFP.js +123 -0
- package/dist/writeFile-DgV8EbFP.js.map +1 -0
- package/dist/writeFile.d.ts +30 -10
- package/dist/writeFile.d.ts.map +1 -1
- package/dist/writeFile.js +2 -2
- package/package.json +2 -2
- package/dist/error-B_uK-F18.js.map +0 -1
- package/dist/isValidFile-UAwceQud.js +0 -30
- package/dist/isValidFile-UAwceQud.js.map +0 -1
- package/dist/types-DtDQlx-T.d.ts.map +0 -1
- package/dist/writeFile-CwK9ZWXr.js +0 -37
- package/dist/writeFile-CwK9ZWXr.js.map +0 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@node-minify/utils",
|
|
3
|
-
"version": "10.
|
|
3
|
+
"version": "10.3.0",
|
|
4
4
|
"description": "utils for @node-minify",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"compressor",
|
|
@@ -56,6 +56,6 @@
|
|
|
56
56
|
"gzip-size": "7.0.0"
|
|
57
57
|
},
|
|
58
58
|
"devDependencies": {
|
|
59
|
-
"@node-minify/types": "10.
|
|
59
|
+
"@node-minify/types": "10.3.0"
|
|
60
60
|
}
|
|
61
61
|
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"error-B_uK-F18.js","names":[],"sources":["../src/error.ts"],"sourcesContent":["/*!\n * node-minify\n * Copyright(c) 2011-2025 Rodolphe Stoclin\n * MIT Licensed\n */\n\n/**\n * Error class for file operation failures.\n * @extends Error\n */\nexport class FileOperationError extends Error {\n constructor(operation: string, path: string, originalError?: Error) {\n super(\n `Failed to ${operation} file ${path}: ${originalError?.message || \"\"}`\n );\n this.name = \"FileOperationError\";\n }\n}\n\n/**\n * Error class for validation failures.\n * @extends Error\n */\nexport class ValidationError extends Error {\n constructor(message: string) {\n super(message);\n this.name = \"ValidationError\";\n }\n}\n"],"mappings":";;;;;;;;;;AAUA,IAAa,qBAAb,cAAwC,MAAM;CAC1C,YAAY,WAAmB,MAAc,eAAuB;AAChE,QACI,aAAa,UAAU,QAAQ,KAAK,IAAI,eAAe,WAAW,KACrE;AACD,OAAK,OAAO;;;;;;;AAQpB,IAAa,kBAAb,cAAqC,MAAM;CACvC,YAAY,SAAiB;AACzB,QAAM,QAAQ;AACd,OAAK,OAAO"}
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import { t as FileOperationError } from "./error-B_uK-F18.js";
|
|
2
|
-
import { existsSync, lstatSync } from "node:fs";
|
|
3
|
-
|
|
4
|
-
//#region src/isValidFile.ts
|
|
5
|
-
/*!
|
|
6
|
-
* node-minify
|
|
7
|
-
* Copyright(c) 2011-2025 Rodolphe Stoclin
|
|
8
|
-
* MIT Licensed
|
|
9
|
-
*/
|
|
10
|
-
/**
|
|
11
|
-
* Check if the path is a valid file.
|
|
12
|
-
* @param path Path to check
|
|
13
|
-
* @returns true if path exists and is a file, false otherwise
|
|
14
|
-
* @throws {FileOperationError} If filesystem operations fail
|
|
15
|
-
* @example
|
|
16
|
-
* if (isValidFile('path/to/file.js')) {
|
|
17
|
-
* // do something
|
|
18
|
-
* }
|
|
19
|
-
*/
|
|
20
|
-
function isValidFile(path) {
|
|
21
|
-
try {
|
|
22
|
-
return existsSync(path) && !lstatSync(path).isDirectory();
|
|
23
|
-
} catch (error) {
|
|
24
|
-
throw new FileOperationError("validate", path, error);
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
//#endregion
|
|
29
|
-
export { isValidFile as t };
|
|
30
|
-
//# sourceMappingURL=isValidFile-UAwceQud.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"isValidFile-UAwceQud.js","names":[],"sources":["../src/isValidFile.ts"],"sourcesContent":["/*!\n * node-minify\n * Copyright(c) 2011-2025 Rodolphe Stoclin\n * MIT Licensed\n */\n\nimport { existsSync, lstatSync } from \"node:fs\";\nimport { FileOperationError } from \"./error.ts\";\n\n/**\n * Check if the path is a valid file.\n * @param path Path to check\n * @returns true if path exists and is a file, false otherwise\n * @throws {FileOperationError} If filesystem operations fail\n * @example\n * if (isValidFile('path/to/file.js')) {\n * // do something\n * }\n */\nexport function isValidFile(path: string): boolean {\n try {\n return existsSync(path) && !lstatSync(path).isDirectory();\n } catch (error) {\n throw new FileOperationError(\"validate\", path, error as Error);\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAmBA,SAAgB,YAAY,MAAuB;AAC/C,KAAI;AACA,SAAO,WAAW,KAAK,IAAI,CAAC,UAAU,KAAK,CAAC,aAAa;UACpD,OAAO;AACZ,QAAM,IAAI,mBAAmB,YAAY,MAAM,MAAe"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types-DtDQlx-T.d.ts","names":["CompressorReturnType","CompressorResult","CompressorOptions","Record","Compressor","TOptions","MinifierOptions","Promise","FileType","Settings","Result","MinifyOptions"],"sources":["../../types/src/types.d.ts"],"sourcesContent":["/*!\n * node-minify\n * Copyright(c) 2011-2025 Rodolphe Stoclin\n * MIT Licensed\n */\n\n/**\n * The return type of a compressor function.\n * @deprecated Use `CompressorResult` instead. Will be removed in v11.\n */\nexport type CompressorReturnType = string;\n\n/**\n * Result returned by a compressor function.\n */\nexport type CompressorResult = {\n code: string;\n map?: string;\n};\n\n/**\n * Base options that all compressors can accept.\n * Specific compressors may extend this with their own options.\n */\nexport type CompressorOptions = Record<string, unknown>;\n\n/**\n * A compressor function that minifies content.\n * @param args - The minifier options including settings and content\n * @returns A promise resolving to the compression result\n */\nexport type Compressor<TOptions extends CompressorOptions = CompressorOptions> =\n (args: MinifierOptions<TOptions>) => Promise<CompressorResult>;\n\n/**\n * File type for compressors that support multiple types (e.g., YUI).\n */\nexport type FileType = \"js\" | \"css\";\n\n/**\n * User-facing settings for the minify function.\n * This is what users pass when calling minify().\n *\n * @example\n * ```ts\n * import { minify } from '@node-minify/core';\n * import { terser } from '@node-minify/terser';\n *\n * await minify({\n * compressor: terser,\n * input: 'src/*.js',\n * output: 'dist/bundle.min.js',\n * options: { mangle: true }\n * });\n * ```\n */\nexport type Settings<TOptions extends CompressorOptions = CompressorOptions> = {\n /**\n * The compressor function to use for minification.\n */\n compressor: Compressor<TOptions>;\n\n /**\n * Optional label for the compressor (used in logging).\n */\n compressorLabel?: string;\n\n /**\n * Content to minify (for in-memory minification).\n * If provided, input/output are not required.\n */\n content?: string;\n\n /**\n * Input file path(s) or glob pattern.\n * Can be a single file, array of files, or wildcard pattern.\n *\n * @example\n * - 'src/app.js'\n * - ['src/a.js', 'src/b.js']\n * - 'src/**\\/*.js'\n */\n input?: string | string[];\n\n /**\n * Output file path.\n * Use $1 as placeholder for input filename in multi-file scenarios.\n * Can be a single file, array of files, or pattern with $1.\n *\n * @example\n * - 'dist/bundle.min.js'\n * - ['file1.min.js', 'file2.min.js']\n * - '$1.min.js' (creates app.min.js from app.js)\n */\n output?: string | string[];\n\n /**\n * Compressor-specific options.\n * See individual compressor documentation for available options.\n */\n options?: TOptions;\n\n /**\n * CLI option string (used by CLI only).\n * @internal\n */\n option?: string;\n\n /**\n * Buffer size for file operations (in bytes).\n * @default 1024000 (1MB)\n */\n buffer?: number;\n\n /**\n * File type for compressors that support multiple types.\n * Required for YUI compressor.\n */\n type?: FileType;\n\n /**\n * Suppress console output.\n * @default false\n */\n silence?: boolean;\n\n /**\n * Public folder to prepend to input paths.\n *\n * @example\n * With publicFolder: 'public/js/' and input: 'app.js',\n * the actual path becomes 'public/js/app.js'\n */\n publicFolder?: string;\n\n /**\n * Replace files in place instead of creating new output files.\n * @default false\n */\n replaceInPlace?: boolean;\n};\n\n/**\n * Options passed to compressor functions internally.\n * This is what compressors receive, not what users pass.\n */\nexport type MinifierOptions<\n TOptions extends CompressorOptions = CompressorOptions,\n> = {\n /**\n * The full settings object.\n */\n settings: Settings<TOptions>;\n\n /**\n * The content to minify.\n */\n content?: string;\n\n /**\n * Index of current file when processing multiple files.\n */\n index?: number;\n};\n\n/**\n * Result returned after compression (used by CLI).\n */\nexport type Result = {\n /**\n * Label of the compressor used.\n */\n compressorLabel: string;\n\n /**\n * Size of minified content (formatted string, e.g., \"1.5 KB\").\n */\n size: string;\n\n /**\n * Gzipped size of minified content (formatted string).\n */\n sizeGzip: string;\n};\n\n/**\n * Type alias for user convenience.\n * @deprecated Use `Settings` instead. Will be removed in v11.\n */\nexport type MinifyOptions<\n TOptions extends CompressorOptions = CompressorOptions,\n> = Settings<TOptions>;\n"],"mappings":";;AAwDA;;;AAI2BK,KA7CfJ,gBAAAA,GA6CeI;EAAXD,IAAAA,EAAAA,MAAAA;EAwCFC,GAAAA,CAAAA,EAAAA,MAAAA;CAkBHG;AA4BX;;;;AAMcC,KAhIFP,iBAAAA,GAAoBC,MAgIlBM,CAAAA,MAAAA,EAAAA,OAAAA,CAAAA;;;;;;KAzHFL,4BAA4BF,oBAAoBA,4BACjDI,gBAAgBD,cAAcE,QAAQN;;;;KAKrCO,QAAAA;;;;;;;;;;;;;;;;;;KAmBAC,0BAA0BP,oBAAoBA;;;;cAI1CE,WAAWC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;YAwCbA;;;;;;;;;;;;;;;;;;SAkBHG;;;;;;;;;;;;;;;;;;;;;;;;;;;KA4BCF,iCACSJ,oBAAoBA;;;;YAK3BO,SAASJ"}
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import { n as ValidationError, t as FileOperationError } from "./error-B_uK-F18.js";
|
|
2
|
-
import { existsSync, lstatSync, writeFileSync } from "node:fs";
|
|
3
|
-
|
|
4
|
-
//#region src/writeFile.ts
|
|
5
|
-
/*!
|
|
6
|
-
* node-minify
|
|
7
|
-
* Copyright(c) 2011-2025 Rodolphe Stoclin
|
|
8
|
-
* MIT Licensed
|
|
9
|
-
*/
|
|
10
|
-
/**
|
|
11
|
-
* Write content into file.
|
|
12
|
-
* @param params Object containing file path, content and optional index
|
|
13
|
-
* @returns Written content
|
|
14
|
-
* @throws {ValidationError} If no target file is provided
|
|
15
|
-
* @throws {FileOperationError} If file operations fail
|
|
16
|
-
* @example
|
|
17
|
-
* writeFile({ file: 'output.js', content: 'console.log("Hello")' })
|
|
18
|
-
* writeFile({ file: ['file1.js', 'file2.js'], content: 'shared content', index: 0 })
|
|
19
|
-
*/
|
|
20
|
-
function writeFile({ file, content, index }) {
|
|
21
|
-
try {
|
|
22
|
-
if (!file) throw new ValidationError("No target file provided");
|
|
23
|
-
if (!content) throw new ValidationError("No content provided");
|
|
24
|
-
const targetFile = index !== void 0 ? Array.isArray(file) ? file[index] : file : file;
|
|
25
|
-
if (typeof targetFile !== "string") throw new ValidationError("Invalid target file path");
|
|
26
|
-
if (!(!existsSync(targetFile) || !lstatSync(targetFile).isDirectory())) throw new Error("Target path exists and is a directory");
|
|
27
|
-
writeFileSync(targetFile, content, "utf8");
|
|
28
|
-
return content;
|
|
29
|
-
} catch (error) {
|
|
30
|
-
if (error instanceof ValidationError) throw error;
|
|
31
|
-
throw new FileOperationError("write to", typeof file === "string" ? file : "multiple files", error);
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
//#endregion
|
|
36
|
-
export { writeFile as t };
|
|
37
|
-
//# sourceMappingURL=writeFile-CwK9ZWXr.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"writeFile-CwK9ZWXr.js","names":[],"sources":["../src/writeFile.ts"],"sourcesContent":["/*!\n * node-minify\n * Copyright(c) 2011-2025 Rodolphe Stoclin\n * MIT Licensed\n */\n\nimport { existsSync, lstatSync, writeFileSync } from \"node:fs\";\nimport { FileOperationError, ValidationError } from \"./error.ts\";\n\ninterface WriteFileParams {\n file: string | string[];\n content: string | Buffer;\n index?: number;\n}\n\n/**\n * Write content into file.\n * @param params Object containing file path, content and optional index\n * @returns Written content\n * @throws {ValidationError} If no target file is provided\n * @throws {FileOperationError} If file operations fail\n * @example\n * writeFile({ file: 'output.js', content: 'console.log(\"Hello\")' })\n * writeFile({ file: ['file1.js', 'file2.js'], content: 'shared content', index: 0 })\n */\nexport function writeFile({\n file,\n content,\n index,\n}: WriteFileParams): string | Buffer {\n try {\n if (!file) {\n throw new ValidationError(\"No target file provided\");\n }\n\n if (!content) {\n throw new ValidationError(\"No content provided\");\n }\n\n const targetFile =\n index !== undefined\n ? Array.isArray(file)\n ? file[index]\n : file\n : file;\n\n if (typeof targetFile !== \"string\") {\n throw new ValidationError(\"Invalid target file path\");\n }\n\n const shouldWrite =\n !existsSync(targetFile) || !lstatSync(targetFile).isDirectory();\n\n if (!shouldWrite) {\n throw new Error(\"Target path exists and is a directory\");\n }\n\n writeFileSync(targetFile, content, \"utf8\");\n return content;\n } catch (error) {\n if (error instanceof ValidationError) {\n throw error;\n }\n throw new FileOperationError(\n \"write to\",\n typeof file === \"string\" ? file : \"multiple files\",\n error as Error\n );\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAyBA,SAAgB,UAAU,EACtB,MACA,SACA,SACiC;AACjC,KAAI;AACA,MAAI,CAAC,KACD,OAAM,IAAI,gBAAgB,0BAA0B;AAGxD,MAAI,CAAC,QACD,OAAM,IAAI,gBAAgB,sBAAsB;EAGpD,MAAM,aACF,UAAU,SACJ,MAAM,QAAQ,KAAK,GACf,KAAK,SACL,OACJ;AAEV,MAAI,OAAO,eAAe,SACtB,OAAM,IAAI,gBAAgB,2BAA2B;AAMzD,MAAI,EAFA,CAAC,WAAW,WAAW,IAAI,CAAC,UAAU,WAAW,CAAC,aAAa,EAG/D,OAAM,IAAI,MAAM,wCAAwC;AAG5D,gBAAc,YAAY,SAAS,OAAO;AAC1C,SAAO;UACF,OAAO;AACZ,MAAI,iBAAiB,gBACjB,OAAM;AAEV,QAAM,IAAI,mBACN,YACA,OAAO,SAAS,WAAW,OAAO,kBAClC,MACH"}
|