Skip to content

Commit e465938

Browse files
authored
Fix undefined cli flags override config
When cli flags are not passed their value is undefined and they override the config file options. This branch fixes this behaviour. Fixes #54
1 parent 531b246 commit e465938

File tree

5 files changed

+32
-8
lines changed

5 files changed

+32
-8
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
### HEAD
22

3+
### 3.0.1 (November XX, 2016)
4+
5+
* Fix: `undefined` cli flags don't override config
6+
37
### 3.0.0 (October 20, 2016)
48

59
* Pin core plugins order:

bin/suitcss

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -110,12 +110,18 @@ function run() {
110110
read(input, function(err, buffer) {
111111
if (err) logger.throw(err);
112112
var css = buffer.toString();
113-
var opts = assign({}, config, {
114-
minify: program.minify,
115-
root: program.importRoot,
116-
encapsulate: program.encapsulate,
117-
lint: program.lint
118-
});
113+
var flags = [
114+
'minify',
115+
'encapsulate',
116+
'root',
117+
'lint'
118+
].reduce(function (accumulator, flag) {
119+
if (({}).hasOwnProperty.call(program, flag)) {
120+
accumulator[flag] = program[flag];
121+
}
122+
return accumulator;
123+
}, {});
124+
var opts = assign({}, config, flags);
119125

120126
if (program.throwError) {
121127
assign(opts, {

test/cli.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,11 +87,21 @@ describe('cli', function() {
8787
});
8888

8989
it('should allow to override config options via cli flags', function(done) {
90-
exec('node bin/suitcss -L -c test/config/test.js test/fixtures/import.css test/fixtures/cli/output.css', function(err) {
90+
exec('node bin/suitcss -m -c test/config/test.js test/fixtures/import.css test/fixtures/cli/output.css', function(err) {
9191
if (err) return done(err);
9292
var res = util.read('fixtures/cli/output');
9393
var commentsPattern = /\/\*[^]*?\*\//g;
94-
expect(res).to.match(commentsPattern);
94+
expect(res).to.not.match(commentsPattern);
95+
done();
96+
});
97+
});
98+
99+
it('should preserve config options when not passing cli flags', function(done) {
100+
exec('node bin/suitcss -c test/config/cli-undefined-flags.js test/fixtures/import.css test/fixtures/cli/output.css', function(err) {
101+
if (err) return done(err);
102+
var res = util.read('fixtures/cli/output');
103+
var commentsPattern = /\/\*[^]*?\*\//g;
104+
expect(res).to.not.match(commentsPattern);
95105
done();
96106
});
97107
});

test/config/cli-undefined-flags.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module.exports = {
2+
minify: true
3+
};

test/config/test.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
module.exports = {
22
lint: true,
3+
minify: false,
34
use: [
45
'postcss-property-lookup'
56
],

0 commit comments

Comments
 (0)