Skip to content

Empty files are not allowed as output. #2790

@liwa-datev

Description

@liwa-datev

We are currently trying to minimize a cluecumber report.
This report contains a css file that only contains two comments (License + a "place your custom css here").

When run though a compressor, using the replaceInPlace option, the file turns out empty (as expected), but node-minify is not allowed to write out empty files. Causing a validation error. We are still on 10.2.0 but I think this is still an issue in the latest 10.3.0.

I'd like to have a configuration option that allows either the write out of empty files, or (even better) to automatically skip/remove empty files.

To reproduce:

echo "/** a comment */" > empty.css

node-minify --compressor clean-css -t css --input empty.css --output '$1.css'

or

const fs = require('node:fs');
const { minify } = require('@node-minify/core');
const { cleanCss } = require('@node-minify/clean-css');

fs.writeFileSync('empty.css', '/* This is a comment */');

minify({
    compressor: cleanCss,
    type: 'css',
    input: `empty.css`,
    output: `$1.css`,
    replaceInPlace: true
});

The later produces:

file:///C:/...mint/node_modules/@node-minify/utils/dist/writeFile-DgV8EbFP.js:81
        if (!content) throw new ValidationError("No content provided");
                            ^

ValidationError: No content provided
    at validateContent (file:///C:/.../mint/node_modules/@node-minify/utils/dist/writeFile-DgV8EbFP.js:81:22)
    at writeFileAsync (file:///C:/.../mint/node_modules/@node-minify/utils/dist/writeFile-DgV8EbFP.js:51:3)
    at writeOutput (file:///C:/.../mint/node_modules/@node-minify/utils/dist/run.js:67:25)
    at run (file:///C:/.../mint/node_modules/@node-minify/utils/dist/run.js:29:8)

Node.js v22.17.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions