Skip to content
This repository was archived by the owner on Jul 24, 2024. It is now read-only.

Commit 7e2bec0

Browse files
committed
Merge pull request #968 from kkopachev/compile-everything-watched
Fix multi-file compile only writes to the last path when multiple files import a changed partial
2 parents 23e6282 + 02a3712 commit 7e2bec0

File tree

2 files changed

+40
-11
lines changed

2 files changed

+40
-11
lines changed

lib/render.js

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ module.exports = function(options, emitter) {
4242
renderOptions.file = options.src;
4343
}
4444

45+
var sourceMap = options.sourceMap;
46+
var destination = options.dest;
47+
var stdin = options.stdin;
48+
4549
var success = function(result) {
4650
var todo = 1;
4751
var done = function() {
@@ -50,10 +54,10 @@ module.exports = function(options, emitter) {
5054
}
5155
};
5256

53-
if (!options.dest || options.stdin) {
57+
if (!destination || stdin) {
5458
emitter.emit('log', result.css.toString());
5559

56-
if (options.sourceMap) {
60+
if (sourceMap) {
5761
emitter.emit('log', result.map.toString());
5862
}
5963

@@ -62,36 +66,36 @@ module.exports = function(options, emitter) {
6266

6367
emitter.emit('warn', chalk.green('Rendering Complete, saving .css file...'));
6468

65-
mkdirp(path.dirname(options.dest), function(err) {
69+
mkdirp(path.dirname(destination), function(err) {
6670
if (err) {
6771
return emitter.emit('error', chalk.red(err));
6872
}
6973

70-
fs.writeFile(options.dest, result.css.toString(), function(err) {
74+
fs.writeFile(destination, result.css.toString(), function(err) {
7175
if (err) {
7276
return emitter.emit('error', chalk.red(err));
7377
}
7478

75-
emitter.emit('warn', chalk.green('Wrote CSS to ' + options.dest));
76-
emitter.emit('write', err, options.dest, result.css.toString());
79+
emitter.emit('warn', chalk.green('Wrote CSS to ' + destination));
80+
emitter.emit('write', err, destination, result.css.toString());
7781
done();
7882
});
7983
});
8084

81-
if (options.sourceMap) {
85+
if (sourceMap) {
8286
todo++;
8387

84-
mkdirp(path.dirname(options.sourceMap), function(err) {
88+
mkdirp(path.dirname(sourceMap), function(err) {
8589
if (err) {
8690
return emitter.emit('error', chalk.red(err));
8791
}
88-
fs.writeFile(options.sourceMap, result.map, function(err) {
92+
fs.writeFile(sourceMap, result.map, function(err) {
8993
if (err) {
9094
return emitter.emit('error', chalk.red('Error' + err));
9195
}
9296

93-
emitter.emit('warn', chalk.green('Wrote Source Map to ' + options.sourceMap));
94-
emitter.emit('write-source-map', err, options.sourceMap, result.map);
97+
emitter.emit('warn', chalk.green('Wrote Source Map to ' + sourceMap));
98+
emitter.emit('write-source-map', err, sourceMap, result.map);
9599
done();
96100
});
97101
});

test/cli.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,31 @@ describe('cli', function() {
335335
}, 200);
336336
}, 500);
337337
});
338+
339+
it('should compile all changed files in watched directory', function(done) {
340+
var destDir = fixture('watching-css-out/');
341+
var srcDir = fixture('watching/');
342+
var srcFile = path.join(srcDir, 'foo.scss');
343+
344+
fs.writeFileSync(srcFile, '');
345+
346+
var bin = spawn(cli, [
347+
'--output-style', 'compressed',
348+
'--output', destDir,
349+
'--watch', srcDir
350+
]);
351+
352+
setTimeout(function () {
353+
fs.appendFileSync(srcFile, 'body{background:white}\n');
354+
setTimeout(function () {
355+
bin.kill();
356+
var files = fs.readdirSync(destDir);
357+
assert.deepEqual(files, ['foo.css', 'index.css']);
358+
rimraf.sync(destDir);
359+
done();
360+
}, 200);
361+
}, 500);
362+
});
338363
});
339364

340365
describe('node-sass in.scss --output out.css', function() {

0 commit comments

Comments
 (0)