Allow whitelisted values in bower.json file created by bower init

A change in the behavior of `mout.lang.isEmpty()` in Mout v0.10.0
introduced a bug in `bower init`, preventing it from including Boolean
values in "bower.json".

This commit explicitly whitelists the types that are used in the
bower.json spec - Object, Array, String, Boolean - as well as Number for
future compatibility.
This commit is contained in:
Ben Cullen-Kerney
2015-06-11 14:48:48 -05:00
committed by Ben Cullen-Kerney
parent 490f63a838
commit 304b6393d4
2 changed files with 15 additions and 2 deletions

View File

@@ -58,7 +58,7 @@ function readJson(project, logger) {
function saveJson(project, logger, json) {
// Cleanup empty props (null values, empty strings, objects and arrays)
mout.object.forOwn(json, function (value, key) {
if (value == null || mout.lang.isEmpty(value)) {
if (!validConfigValue(value)) {
delete json[key];
}
});
@@ -81,6 +81,18 @@ function saveJson(project, logger, json) {
});
}
// Test if value is of a type supported by bower.json[0] - Object, Array, String, Boolean - or a Number
// [0]: https://github.com/bower/bower.json-spec
function validConfigValue(val) {
return (
mout.lang.isObject(val) ||
mout.lang.isArray(val) ||
mout.lang.isString(val) ||
mout.lang.isBoolean(val) ||
mout.lang.isNumber(val)
);
}
function setDefaults(config, json) {
var name;
var promise = Q.resolve();

View File

@@ -49,7 +49,8 @@ describe('bower init', function () {
description: 'test-description',
moduleType: 'test-moduleType',
keywords: [ 'test-keyword' ],
license: 'test-license'
license: 'test-license',
private: true
});
});
});