Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include Strings in Arrays for ${ENV} variables in .bowerrc #2411

Merged
merged 4 commits into from Mar 28, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions packages/bower-config/lib/util/expand.js
Expand Up @@ -43,6 +43,9 @@ function doEnvReplaceStr (f) {

function envReplace(config) {
var envReplaced = {};
if ( lang.isArray(config) ) {
envReplaced = [];
}

object.forOwn(config, function (value, key) {

Expand All @@ -63,6 +66,9 @@ function envReplace(config) {
if ( lang.isPlainObject(value) ) {
envReplaced[key] = envReplace(value);
}
else if ( lang.isArray(value) ) {
envReplaced[key] = envReplace(value);
}
else if ( lang.isString(value) ) {
envReplaced[key] = doEnvReplaceStr(value);
}
Expand Down
Expand Up @@ -4,7 +4,12 @@
},
"storage" : {
"packages" : "${_BOWERRC_MY_PACKAGES}",
"registry" : "~/.bower-test/registry"
"registry" : {
"register": "~/.bower-test/registry",
"search": [
"${_BOWERRC_MY_USER}:${_BOWERRC_MY_PASS}"
]
}
},
"tmp" : "${_BOWERRC_MY_TMP}"
}
5 changes: 4 additions & 1 deletion packages/bower-config/test/test.js
Expand Up @@ -224,10 +224,13 @@ describe('Allow ${ENV} variables in .bowerrc', function() {
it('sets values from process.env', function() {
process.env._BOWERRC_MY_PACKAGES = 'a';
process.env._BOWERRC_MY_TMP = '/tmp/b';
process.env._BOWERRC_MY_USER = 'username';
process.env._BOWERRC_MY_PASS = 'password';

var config = require('../lib/Config').read('test/assets/env-variables-values');
assert.equal('a', config.storage.packages);
assert.equal('/tmp/b', config.tmp);
assert.equal('username:password', config.storage.registry.search[0]);
assert.equal('${_myshellvar}', config.scripts.postinstall);
});
});
Expand All @@ -238,7 +241,7 @@ describe('untildify paths in .bowerrc', function() {
var config = require('../lib/Config').read('test/assets/env-variables-values');
var untildify = require('untildify');

assert.equal(untildify('~/.bower-test/registry') , config.storage.registry);
assert.equal(untildify('~/.bower-test/registry') , config.storage.registry.register);
});
});

Expand Down