Skip to content
This repository has been archived by the owner on Sep 25, 2020. It is now read-only.

Commit

Permalink
(fix) changed to chain the process() promises
Browse files Browse the repository at this point in the history
The previous implementation ran process() parallel on one processor instance
which messed up variables when plugins auto generated fallback styles for
CSS variables for example.
  • Loading branch information
tholewebgods committed Apr 12, 2019
1 parent 90257f4 commit fe9d4db
Showing 1 changed file with 17 additions and 11 deletions.
28 changes: 17 additions & 11 deletions tasks/postcss.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@ module.exports = function(grunt) {

tally.diffs += 1;
}

return Promise.resolve();
}

grunt.registerMultiTask('postcss', 'Process CSS files.', function() {
Expand All @@ -149,9 +151,9 @@ module.exports = function(grunt) {
}

var done = this.async();
var tasks = [];
var taskChain;

this.files.forEach(function(f) {
taskChain = this.files.reduce(function(previousFileset, f) {
var src = f.src.filter(function(filepath) {
if (!grunt.file.exists(filepath)) {
grunt.log.warn('Source file ' + chalk.cyan(filepath) + ' not found.');
Expand All @@ -165,24 +167,28 @@ module.exports = function(grunt) {
if (src.length === 0) {
grunt.log.error('No source files were found.');

return done();
// Complete this file set, don't fail all file sets.
return Promise.resolve();

// This check shall not apply for configs without destination
// (in place processsing).
} else if (src.length > 1 && f.dest) {
grunt.log.warn("Multiple source files with one destination file configured. All files would write to that *one* destination file.\nThe configured file set is: " + f.src.join(", ") + " => " + f.dest + ".");
}

Array.prototype.push.apply(tasks, src.map(function(filepath) {
var dest = f.dest || filepath;
var input = grunt.file.read(filepath);
return previousFileset.then(function() {
return src.reduce(function(previousTask, filepath) {
var dest = f.dest || filepath;
var input = grunt.file.read(filepath);

return process(input, filepath, dest)
.then(writeResult.bind(null, tally, input, dest));
}));
});
return previousTask
.then(process.bind(null, input, filepath, dest))
.then(writeResult.bind(null, tally, input, dest));
}, Promise.resolve() /* to kick-off the chain */ );
});
}, Promise.resolve() /* to kick-off the chain */ );

Promise.all(tasks).then(function() {
taskChain.then(function() {
if (tally.sheets) {
if (options.writeDest) {
grunt.log.ok(tally.sheets + ' processed ' + grunt.util.pluralize(tally.sheets, 'stylesheet/stylesheets') + ' created.');
Expand Down

0 comments on commit fe9d4db

Please sign in to comment.