nDmitry/grunt-postcss

If processor throws an error then grunt-postcss throws it only if it was in last processed file.

lsobolew opened this issue · 4 comments

When I use this Gruntfile.js:

module.exports = function(grunt) {

    grunt.initConfig({
        postcss: {
            options: {
                processors: [
                    require('postcss-import')()
                ]
            },
            dist: {
                files: [{
                    expand: true, // Enable dynamic expansion.
                    src: ['css/*.css'], // Actual pattern(s) to match.
                    dest: 'build/', // Destination path prefix.
                }],
            }
        }
    });

    grunt.loadNpmTasks('grunt-postcss');
};

and in css drectory have 3 files:

_import.css
a.css
b.css

with contents:

/* _import.css */
body {
    background: red;
}
/* a.css */
@import "_import.css";
/* b.css */
@import "missing.css";

then grunt postcss throws an error (Failed to find 'missing.css'). But when I switch contents of a.css and b.css files so that rule causing error is not in last processed file then grunt doesn't throw an error and generates 2 files instead of 3.

grunt-postcss gets the warnings from postcss, so it ‘throws’ what it gets, there is no related logic that can be broken in this plugin https://github.com/nDmitry/grunt-postcss/blob/master/tasks/postcss.js#L134

But why does it throw an error depending on the order of processed files?
I have added locally catch in https://github.com/nDmitry/grunt-postcss/blob/master/tasks/postcss.js#L165 and it fixed this problem form me but I assume that this is not the way it should be done.

Should be fixed in 0.7.1.

Thanks, that's great