Skip to content

Commit fd08a3e

Browse files
committed
Child shifter runs should only use the arguments provided
When spawning a child Shifter run, we should not pass the child all of the default arguments as these will override any specified in the build.json.
1 parent 4199a12 commit fd08a3e

File tree

3 files changed

+67
-1
lines changed

3 files changed

+67
-1
lines changed

lib/args.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,34 @@ var clean = function(args) {
6767
return parsed;
6868
};
6969

70+
// Get the base arguments list without defaults applied.
71+
var baseOptions = function(args) {
72+
var options = {},
73+
key;
74+
75+
// Get any supplied arguments if not specified.
76+
if (!args) {
77+
args = clean();
78+
}
79+
80+
// Define all of the base arguments.
81+
for (key in known) {
82+
if (known.hasOwnProperty(key)) {
83+
options[key] = undefined;
84+
}
85+
}
86+
87+
// Add any supplied overrides.
88+
for (key in args) {
89+
// And override with the specified arguments.
90+
if (args.hasOwnProperty(key)) {
91+
options[key] = args[key];
92+
}
93+
}
94+
95+
return options;
96+
};
97+
7098
var setDefaults = function(parsed) {
7199
if (parsed === undefined) {
72100
parsed = clean();
@@ -113,6 +141,7 @@ var parse = function (args) {
113141
};
114142

115143
exports.defaults = setDefaults;
144+
exports.baseOptions = baseOptions;
116145
exports.has = has;
117146
exports.raw = raw;
118147
exports.parse = parse;

lib/index.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,9 @@ exports.init = function (opts, initCallback) {
200200
} else {
201201
if (options.walk) {
202202
walk = require('./walk');
203-
walk.run(options, initCallback);
203+
// Use the less-processed opts here instead - we don't want the defaults to override the individual
204+
// Shifter configurations.
205+
walk.run(args.baseOptions(opts), initCallback);
204206
} else {
205207
log.warn('no ' + buildFileName + ' file, downshifting to convert ant files');
206208
ant = require('./ant');

tests/1-args.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,41 @@ var tests = {
265265
assert.isFalse(topic.quiet);
266266
assert.isFalse(topic.cache);
267267
}
268+
},
269+
'args.baseOptions should define all of the standard options': {
270+
topic: function() {
271+
return args.baseOptions();
272+
},
273+
'should default undefined': function(topic) {
274+
assert.isTrue(topic.hasOwnProperty('walk') && topic.walk === undefined);
275+
assert.isTrue(topic.hasOwnProperty('cache') && topic.cache === undefined);
276+
assert.isTrue(topic.hasOwnProperty('lint') && topic.lint === undefined);
277+
},
278+
'should not have undefined values': function(topic) {
279+
assert.isFalse(topic.hasOwnProperty('foo'));
280+
assert.isFalse(topic.hasOwnProperty('bar'));
281+
assert.isFalse(topic.hasOwnProperty('baz'));
282+
}
283+
},
284+
'args.baseOptions should allow CLI overrides of options': {
285+
topic: function() {
286+
return args.baseOptions({
287+
cache: true,
288+
lint: 'config'
289+
});
290+
},
291+
'should allow overrides': function(topic) {
292+
assert.isTrue(topic.cache);
293+
assert.equal('config', topic.lint);
294+
},
295+
'should default undefined': function(topic) {
296+
assert.isTrue(topic.hasOwnProperty('walk') && topic.walk === undefined);
297+
},
298+
'should not have undefined values': function(topic) {
299+
assert.isFalse(topic.hasOwnProperty('foo'));
300+
assert.isFalse(topic.hasOwnProperty('bar'));
301+
assert.isFalse(topic.hasOwnProperty('baz'));
302+
}
268303
}
269304
};
270305

0 commit comments

Comments
 (0)