Skip to content
This repository has been archived by the owner on Apr 20, 2018. It is now read-only.

Commit

Permalink
Close #323 PR: fix #307 - grunt-watch spawn:false compatibility fix.
Browse files Browse the repository at this point in the history
  • Loading branch information
vlajos authored and sindresorhus committed Feb 23, 2015
1 parent 17e99b2 commit eb73f98
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
16 changes: 15 additions & 1 deletion lib/configwriter.js
Expand Up @@ -6,8 +6,22 @@ var _ = require('lodash');
var deepMerge = function (origCfg, cfg) {
var outCfg = origCfg;

// If the newly generated part is already in the config file
// with the same destination update only the source part, instead of add the whole block again.
// This way the same targets wont be regenerated multiple times if usemin is called
// multiple times which can happen with grunt-watcher spawn:false mode (#307)

if (origCfg.files && cfg.files) {
outCfg.files = _.union(origCfg.files, cfg.files);
var done = false;
for (var i = 0; i < origCfg.files.length; i++) {
if (outCfg.files[i].dest === cfg.files[0].dest) {
outCfg.files[i].src = cfg.files[0].src;
done = true;
}
}
if (!done) {
outCfg.files = _.union(origCfg.files, cfg.files);
}
} else if (cfg.files) {
outCfg.files = cfg.files;
}
Expand Down
19 changes: 19 additions & 0 deletions test/test-config-writer.js
Expand Up @@ -402,5 +402,24 @@ describe('ConfigWriter', function () {
assert.deepEqual(names, ['concat', 'uglify']);
});
});

it('should not add the same block multiple times though we call process() explicitly 2 times.', function () {
var flow = new Flow({steps: {js: ['concat', 'uglifyjs']}});

var file = helpers.createFile('foo', 'app', blocks);
var c = new ConfigWriter(flow, {input: 'app', dest: 'destination', staging: '.tmp'});
var config = c.process(file);
config = c.process(file, config); // This second process is intentional. Details are in issue #307.
var expected = helpers.normalize({
concat: {generated: {files: [
{dest: '.tmp/concat/scripts/site.js', src: ['app/foo.js', 'app/bar.js', 'app/baz.js']}
]}},
uglify: {generated: {files: [
{dest: 'destination/scripts/site.js', src: ['.tmp/concat/scripts/site.js']}
]}}
});

assert.deepEqual(config, expected);
});
});
});

0 comments on commit eb73f98

Please sign in to comment.