Skip to content

Batch mode with returnPromise=true #1186

Description

@Amphiluke

Hello,

I’m trying to implement a batched minification of an array of hashes as stated in the docs. Everything works fine in synchronous mode. But if I set the option returnPromise: true, the returned promise always gets rejected in spite of the minification seems to complete successfully behind the scenes.

let CleanCSS = require('clean-css');

(async () => {
    try {
        let cleanCSS = new CleanCSS({
            batch: true,
            returnPromise: true,
        });
        let outputs = await cleanCSS.minify([
            {'path/to/file/one': {styles: 'html { color: #000000; }'}},
            {'path/to/file/two': {styles: 'body { background: #ffffff; }'}}
        ]);
        console.log('OK', outputs);
    } catch (e) {
        console.log('error', e); // <-- always logs: "error" [null, null]
    }
})();

Probably, this happens because there is no check for innerErrors === null in the function whenHashBatchDone.


Precheck

  • Do a quick search and make sure a bug has not yet been reported;
  • do a quick check if the bug still exists in the latest patch version;
  • finally, be nice and have fun!

Environment

  • clean-css version: 5.2.0
  • node.js version: 14.17.6
  • operating system: any

Configuration options

var CleanCSS = require('clean-css');
new CleanCSS({
    batch: true,
    returnPromise: true,
});

Demo link for the issue reproduction

clean-css-batch-promise

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions