@node-minify/clean-css 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 CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2025 Rodolphe Stoclin
3
+ Copyright (c) 2011-2026 Rodolphe Stoclin
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/dist/index.d.ts CHANGED
@@ -135,6 +135,12 @@ type Settings<TOptions extends CompressorOptions = CompressorOptions> = {
135
135
  */
136
136
  buffer?: number;
137
137
 
138
+ /**
139
+ * Timeout for the compressor process (in milliseconds).
140
+ * If execution exceeds this limit, the process will be killed.
141
+ */
142
+ timeout?: number;
143
+
138
144
  /**
139
145
  * File type for compressors that support multiple types.
140
146
  * Required for YUI compressor.
@@ -161,6 +167,14 @@ type Settings<TOptions extends CompressorOptions = CompressorOptions> = {
161
167
  * @default false
162
168
  */
163
169
  replaceInPlace?: boolean;
170
+
171
+ /**
172
+ * Allow empty output without throwing an error.
173
+ * When true, if minification results in empty content, the output file will not be written.
174
+ * Useful for CSS files containing only comments that get stripped.
175
+ * @default false
176
+ */
177
+ allowEmptyOutput?: boolean;
164
178
  };
165
179
  /**
166
180
  * Options passed to compressor functions internally.
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","names":["CompressorReturnType","ImageFormat","CompressorOutput","Buffer","CompressorResult","CompressorOptions","Record","Compressor","TOptions","MinifierOptions","Promise","FileType","Settings","Result","MinifyOptions"],"sources":["../../types/src/types.d.ts","../src/index.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 * Supported image formats for image compression.\n */\nexport type ImageFormat =\n | \"webp\"\n | \"avif\"\n | \"png\"\n | \"jpeg\"\n | \"jpg\"\n | \"gif\"\n | \"tiff\"\n | \"heif\"\n | \"heic\";\n\n/**\n * Output result for multi-format image compression.\n */\nexport type CompressorOutput = {\n /**\n * Format of the output (e.g., 'webp', 'avif').\n */\n format?: string;\n\n /**\n * Output content as string or Buffer.\n */\n content: string | Buffer;\n};\n\n/**\n * Result returned by a compressor function.\n */\nexport type CompressorResult = {\n /**\n * Minified content as string (for text-based formats like JS, CSS, HTML, SVG).\n */\n code: string;\n\n /**\n * Source map (for JS/CSS compressors).\n */\n map?: string;\n\n /**\n * Minified content as Buffer (for binary formats like images).\n * @example\n * When using sharp for PNG/WebP compression\n */\n buffer?: Buffer;\n\n /**\n * Multiple outputs for multi-format image compression.\n * Used when converting to multiple formats simultaneously.\n * @example\n * [{ format: 'webp', content: <Buffer> }, { format: 'avif', content: <Buffer> }]\n */\n outputs?: CompressorOutput[];\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 * For text-based formats (JS, CSS, HTML, SVG): string\n * For binary formats (images): Buffer (handled internally by image compressors)\n */\n content?: string | Buffer;\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 * For text-based formats (JS, CSS, HTML, SVG): string\n * For binary formats (images): Buffer\n * For multiple binary files: Buffer[]\n */\n content?: string | Buffer | Buffer[];\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":";;;;;AAqNsC,KAxL1BE,gBAAAA,GAwL0B;;;;ECpMhB,MAAA,CAAA,EAAA,MAAQ;;EAE1B;;;EACiB,OAAA,EAAA,MAAA,GDkBCC,MClBD;CAAO;;;;KDwBhBC,gBAAAA;;;;;;;;;;;;;;;;WAgBCD;;;;;;;;YAQCD;;;;;;KAOFG,iBAAAA,GAAoBC;;;;;;KAOpBC,4BAA4BF,oBAAoBA,4BACjDI,gBAAgBD,cAAcE,QAAQN;;;;KAKrCO,QAAAA;;;;;;;;;;;;;;;;;;KAmBAC,0BAA0BP,oBAAoBA;;;;cAI1CE,WAAWC;;;;;;;;;;;;;qBAaJL;;;;;;;;;;;;;;;;;;;;;;;;;;;;;YA6BTK;;;;;;;;;;;;;;;;;;SAkBHG;;;;;;;;;;;;;;;;;;;;;;;;;;;KA4BCF,iCACSJ,oBAAoBA;;;;YAK3BO,SAASJ;;;;;;;;qBAQAL,SAASA;;;;;;;;;;;;;;;AA7HhC;AAmBYS,iBC1FU,QAAA,CD0FF;EAAA,QAAA;EAAA;AAAA,CAAA,ECvFjB,eDuFiB,CAAA,ECvFC,ODuFD,CCvFS,gBDuFT,CAAA"}
1
+ {"version":3,"file":"index.d.ts","names":["CompressorReturnType","ImageFormat","CompressorOutput","Buffer","CompressorResult","CompressorOptions","Record","Compressor","TOptions","MinifierOptions","Promise","FileType","Settings","Result","MinifyOptions"],"sources":["../../types/src/types.d.ts","../src/index.ts"],"sourcesContent":["/*!\n * node-minify\n * Copyright (c) 2011-2026 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 * Supported image formats for image compression.\n */\nexport type ImageFormat =\n | \"webp\"\n | \"avif\"\n | \"png\"\n | \"jpeg\"\n | \"jpg\"\n | \"gif\"\n | \"tiff\"\n | \"heif\"\n | \"heic\";\n\n/**\n * Output result for multi-format image compression.\n */\nexport type CompressorOutput = {\n /**\n * Format of the output (e.g., 'webp', 'avif').\n */\n format?: string;\n\n /**\n * Output content as string or Buffer.\n */\n content: string | Buffer;\n};\n\n/**\n * Result returned by a compressor function.\n */\nexport type CompressorResult = {\n /**\n * Minified content as string (for text-based formats like JS, CSS, HTML, SVG).\n */\n code: string;\n\n /**\n * Source map (for JS/CSS compressors).\n */\n map?: string;\n\n /**\n * Minified content as Buffer (for binary formats like images).\n * @example\n * When using sharp for PNG/WebP compression\n */\n buffer?: Buffer;\n\n /**\n * Multiple outputs for multi-format image compression.\n * Used when converting to multiple formats simultaneously.\n * @example\n * [{ format: 'webp', content: <Buffer> }, { format: 'avif', content: <Buffer> }]\n */\n outputs?: CompressorOutput[];\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 * For text-based formats (JS, CSS, HTML, SVG): string\n * For binary formats (images): Buffer (handled internally by image compressors)\n */\n content?: string | Buffer;\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 * Timeout for the compressor process (in milliseconds).\n * If execution exceeds this limit, the process will be killed.\n */\n timeout?: 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 * Allow empty output without throwing an error.\n * When true, if minification results in empty content, the output file will not be written.\n * Useful for CSS files containing only comments that get stripped.\n * @default false\n */\n allowEmptyOutput?: 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 * For text-based formats (JS, CSS, HTML, SVG): string\n * For binary formats (images): Buffer\n * For multiple binary files: Buffer[]\n */\n content?: string | Buffer | Buffer[];\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":";;;;;AAmOsC,KAtM1BE,gBAAAA,GAsM0B;;;;EClNhB,MAAA,CAAA,EAAA,MAAQ;;EAE1B;;;EACiB,OAAA,EAAA,MAAA,GDkBCC,MClBD;CAAO;;;;KDwBhBC,gBAAAA;;;;;;;;;;;;;;;;WAgBCD;;;;;;;;YAQCD;;;;;;KAOFG,iBAAAA,GAAoBC;;;;;;KAOpBC,4BAA4BF,oBAAoBA,4BACjDI,gBAAgBD,cAAcE,QAAQN;;;;KAKrCO,QAAAA;;;;;;;;;;;;;;;;;;KAmBAC,0BAA0BP,oBAAoBA;;;;cAI1CE,WAAWC;;;;;;;;;;;;;qBAaJL;;;;;;;;;;;;;;;;;;;;;;;;;;;;;YA6BTK;;;;;;;;;;;;;;;;;;;;;;;;SAwBHG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KAoCCF,iCACSJ,oBAAoBA;;;;YAK3BO,SAASJ;;;;;;;;qBAQAL,SAASA;;;;;;;;;;;;;;;AA3IhC;AAmBYS,iBC1FU,QAAA,CD0FF;EAAA,QAAA;EAAA;AAAA,CAAA,ECvFjB,eDuFiB,CAAA,ECvFC,ODuFD,CCvFS,gBDuFT,CAAA"}
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { ensureStringContent } from "@node-minify/utils";
1
+ import { ensureStringContent, wrapMinificationError } from "@node-minify/utils";
2
2
  import CleanCSS from "clean-css";
3
3
 
4
4
  //#region src/index.ts
@@ -16,14 +16,20 @@ async function cleanCss({ settings, content }) {
16
16
  options._sourceMap = options.sourceMap;
17
17
  options.sourceMap = true;
18
18
  }
19
- const result = new CleanCSS({
20
- returnPromise: false,
21
- ...options
22
- }).minify(contentStr);
23
- return {
24
- code: result.styles,
25
- map: result.sourceMap?.toString()
26
- };
19
+ try {
20
+ const result = new CleanCSS({
21
+ returnPromise: false,
22
+ ...options
23
+ }).minify(contentStr);
24
+ if (result.errors && result.errors.length > 0) throw new Error(result.errors.join("; "));
25
+ if (typeof result.styles !== "string") throw new Error("clean-css failed: empty result");
26
+ return {
27
+ code: result.styles,
28
+ map: result.sourceMap?.toString()
29
+ };
30
+ } catch (error) {
31
+ throw wrapMinificationError("clean-css", error);
32
+ }
27
33
  }
28
34
 
29
35
  //#endregion
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":[],"sources":["../src/index.ts"],"sourcesContent":["/*!\n * node-minify\n * Copyright(c) 2011-2025 Rodolphe Stoclin\n * MIT Licensed\n */\n\nimport type { CompressorResult, MinifierOptions } from \"@node-minify/types\";\nimport { ensureStringContent } from \"@node-minify/utils\";\nimport CleanCSS from \"clean-css\";\n\n/**\n * Minify CSS using the clean-css library and produce an optional source map.\n *\n * @param settings - Configuration for the clean-css minifier (may include an `options` object with clean-css flags)\n * @param content - CSS input to be minified\n * @returns An object with `code` containing the minified CSS and `map` containing the source map as a string if available\n */\nexport async function cleanCss({\n settings,\n content,\n}: MinifierOptions): Promise<CompressorResult> {\n const contentStr = ensureStringContent(content, \"clean-css\");\n\n const options = settings?.options ? { ...settings.options } : {};\n\n if (options.sourceMap && typeof options.sourceMap === \"object\") {\n options._sourceMap = options.sourceMap;\n options.sourceMap = true;\n }\n\n const result = new CleanCSS({ returnPromise: false, ...options }).minify(\n contentStr\n );\n\n return {\n code: result.styles,\n map: result.sourceMap?.toString(),\n };\n}\n"],"mappings":";;;;;;;;;;;AAiBA,eAAsB,SAAS,EAC3B,UACA,WAC2C;CAC3C,MAAM,aAAa,oBAAoB,SAAS,YAAY;CAE5D,MAAM,UAAU,UAAU,UAAU,EAAE,GAAG,SAAS,SAAS,GAAG,EAAE;AAEhE,KAAI,QAAQ,aAAa,OAAO,QAAQ,cAAc,UAAU;AAC5D,UAAQ,aAAa,QAAQ;AAC7B,UAAQ,YAAY;;CAGxB,MAAM,SAAS,IAAI,SAAS;EAAE,eAAe;EAAO,GAAG;EAAS,CAAC,CAAC,OAC9D,WACH;AAED,QAAO;EACH,MAAM,OAAO;EACb,KAAK,OAAO,WAAW,UAAU;EACpC"}
1
+ {"version":3,"file":"index.js","names":[],"sources":["../src/index.ts"],"sourcesContent":["/*!\n * node-minify\n * Copyright (c) 2011-2026 Rodolphe Stoclin\n * MIT Licensed\n */\n\nimport type { CompressorResult, MinifierOptions } from \"@node-minify/types\";\nimport { ensureStringContent, wrapMinificationError } from \"@node-minify/utils\";\nimport CleanCSS from \"clean-css\";\n\n/**\n * Minify CSS using the clean-css library and produce an optional source map.\n *\n * @param settings - Configuration for the clean-css minifier (may include an `options` object with clean-css flags)\n * @param content - CSS input to be minified\n * @returns An object with `code` containing the minified CSS and `map` containing the source map as a string if available\n */\nexport async function cleanCss({\n settings,\n content,\n}: MinifierOptions): Promise<CompressorResult> {\n const contentStr = ensureStringContent(content, \"clean-css\");\n const options = settings?.options ? { ...settings.options } : {};\n\n if (options.sourceMap && typeof options.sourceMap === \"object\") {\n options._sourceMap = options.sourceMap;\n options.sourceMap = true;\n }\n\n try {\n const result = new CleanCSS({\n returnPromise: false,\n ...options,\n }).minify(contentStr);\n\n if (result.errors && result.errors.length > 0) {\n throw new Error(result.errors.join(\"; \"));\n }\n\n if (typeof result.styles !== \"string\") {\n throw new Error(\"clean-css failed: empty result\");\n }\n\n return {\n code: result.styles,\n map: result.sourceMap?.toString(),\n };\n } catch (error) {\n throw wrapMinificationError(\"clean-css\", error);\n }\n}\n"],"mappings":";;;;;;;;;;;AAiBA,eAAsB,SAAS,EAC3B,UACA,WAC2C;CAC3C,MAAM,aAAa,oBAAoB,SAAS,YAAY;CAC5D,MAAM,UAAU,UAAU,UAAU,EAAE,GAAG,SAAS,SAAS,GAAG,EAAE;AAEhE,KAAI,QAAQ,aAAa,OAAO,QAAQ,cAAc,UAAU;AAC5D,UAAQ,aAAa,QAAQ;AAC7B,UAAQ,YAAY;;AAGxB,KAAI;EACA,MAAM,SAAS,IAAI,SAAS;GACxB,eAAe;GACf,GAAG;GACN,CAAC,CAAC,OAAO,WAAW;AAErB,MAAI,OAAO,UAAU,OAAO,OAAO,SAAS,EACxC,OAAM,IAAI,MAAM,OAAO,OAAO,KAAK,KAAK,CAAC;AAG7C,MAAI,OAAO,OAAO,WAAW,SACzB,OAAM,IAAI,MAAM,iCAAiC;AAGrD,SAAO;GACH,MAAM,OAAO;GACb,KAAK,OAAO,WAAW,UAAU;GACpC;UACI,OAAO;AACZ,QAAM,sBAAsB,aAAa,MAAM"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@node-minify/clean-css",
3
- "version": "10.2.0",
3
+ "version": "10.4.0",
4
4
  "description": "clean-css plugin for @node-minify",
5
5
  "keywords": [
6
6
  "compressor",
@@ -52,11 +52,11 @@
52
52
  "dev": "tsdown src/index.ts --watch"
53
53
  },
54
54
  "dependencies": {
55
- "@node-minify/utils": "10.2.0",
55
+ "@node-minify/utils": "10.4.0",
56
56
  "clean-css": "5.3.3"
57
57
  },
58
58
  "devDependencies": {
59
- "@node-minify/types": "10.2.0",
59
+ "@node-minify/types": "10.4.0",
60
60
  "@types/clean-css": "^4.2.11"
61
61
  }
62
62
  }