Skip to content

Commit

Permalink
Allow environment variables to contain colons (#3283)
Browse files Browse the repository at this point in the history
* Allow environment variables to contain colons

Currently, any environment variables that have colon in them are discarded, including any text following them. This pr includes them.

**Before:**
```
URL:http://localhost:4200 =  ['URL', 'http']
```

**After:**
```
URL:http://localhost:4200 =  ['URL', 'http://localhost:4200']
```

**Example:**
https://jsbin.com/mexeyifuqi/1/edit?js,console

* Add test.

* Update conditional that sets  env variables.
  • Loading branch information
tlaverdure authored and lukastaegert committed Dec 14, 2019
1 parent a5502ad commit 878ac03
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 7 deletions.
10 changes: 5 additions & 5 deletions cli/run/index.ts
Expand Up @@ -9,7 +9,7 @@ import build from './build';
import loadConfigFile from './loadConfigFile';
import watch from './watch';

export default function runRollup(command: any) {
export default function runRollup (command: any) {
let inputSource;
if (command._.length > 0) {
if (command.input) {
Expand Down Expand Up @@ -47,9 +47,9 @@ export default function runRollup(command: any) {

environment.forEach((arg: string) => {
arg.split(',').forEach((pair: string) => {
const [key, value] = pair.split(':');
if (value) {
process.env[key] = value;
const [key, ...value] = pair.split(':');
if (value.length) {
process.env[key] = value.join(':');
} else {
process.env[key] = String(true);
}
Expand Down Expand Up @@ -93,7 +93,7 @@ export default function runRollup(command: any) {
}
}

function execute(configFile: string, configs: GenericConfigObject[], command: any) {
function execute (configFile: string, configs: GenericConfigObject[], command: any) {
if (command.watch) {
watch(configFile, configs, command, command.silent);
} else {
Expand Down
2 changes: 1 addition & 1 deletion test/cli/samples/config-env/_config.js
@@ -1,5 +1,5 @@
module.exports = {
description: 'passes environment variables to config file',
command: 'rollup --config --environment PRODUCTION,FOO:bar',
command: 'rollup --config --environment PRODUCTION,FOO:bar,HOST:http://localhost:4000',
execute: true
};
1 change: 1 addition & 0 deletions test/cli/samples/config-env/main.js
@@ -1,2 +1,3 @@
assert.equal( '__ENVIRONMENT__', 'production' );
assert.equal( '__FOO__', 'bar' );
assert.equal( '__HOST__', 'http://localhost:4000' );
3 changes: 2 additions & 1 deletion test/cli/samples/config-env/rollup.config.js
Expand Up @@ -8,7 +8,8 @@ module.exports = {
plugins: [
replace( {
__ENVIRONMENT__: process.env.PRODUCTION ? 'production' : 'development',
__FOO__: process.env.FOO
__FOO__: process.env.FOO,
__HOST__: process.env.HOST
} )
]
};

0 comments on commit 878ac03

Please sign in to comment.