From c725825299b1bc6925cccdf2de1df4c286669c61 Mon Sep 17 00:00:00 2001 From: Thiery Laverdure Date: Fri, 13 Dec 2019 13:50:52 -0500 Subject: [PATCH 1/3] 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 --- cli/run/index.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cli/run/index.ts b/cli/run/index.ts index 53825ce2c1e..6c25c7ddcd7 100644 --- a/cli/run/index.ts +++ b/cli/run/index.ts @@ -47,9 +47,9 @@ export default function runRollup(command: any) { environment.forEach((arg: string) => { arg.split(',').forEach((pair: string) => { - const [key, value] = pair.split(':'); + const [key, ...value] = pair.split(':'); if (value) { - process.env[key] = value; + process.env[key] = value.join(':'); } else { process.env[key] = String(true); } From 8cfac88d7c878578522e902dfc75643814429641 Mon Sep 17 00:00:00 2001 From: Thiery Laverdure Date: Fri, 13 Dec 2019 14:13:48 -0500 Subject: [PATCH 2/3] Add test. --- cli/run/index.ts | 2 +- test/cli/samples/config-env/_config.js | 2 +- test/cli/samples/config-env/main.js | 1 + test/cli/samples/config-env/rollup.config.js | 3 ++- 4 files changed, 5 insertions(+), 3 deletions(-) diff --git a/cli/run/index.ts b/cli/run/index.ts index 6c25c7ddcd7..35500f0c559 100644 --- a/cli/run/index.ts +++ b/cli/run/index.ts @@ -48,7 +48,7 @@ export default function runRollup(command: any) { environment.forEach((arg: string) => { arg.split(',').forEach((pair: string) => { const [key, ...value] = pair.split(':'); - if (value) { + if (value && value.length) { process.env[key] = value.join(':'); } else { process.env[key] = String(true); diff --git a/test/cli/samples/config-env/_config.js b/test/cli/samples/config-env/_config.js index 5b5f4936b00..3036cc208f5 100644 --- a/test/cli/samples/config-env/_config.js +++ b/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 }; diff --git a/test/cli/samples/config-env/main.js b/test/cli/samples/config-env/main.js index b18f7a91323..595e774fb84 100644 --- a/test/cli/samples/config-env/main.js +++ b/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' ); diff --git a/test/cli/samples/config-env/rollup.config.js b/test/cli/samples/config-env/rollup.config.js index cd113e77749..7fe713ad17b 100644 --- a/test/cli/samples/config-env/rollup.config.js +++ b/test/cli/samples/config-env/rollup.config.js @@ -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 } ) ] }; From b18e7451786c019c84a7ce88d018bc70ea7aa3e6 Mon Sep 17 00:00:00 2001 From: Thiery Laverdure Date: Sat, 14 Dec 2019 09:36:35 -0500 Subject: [PATCH 3/3] Update conditional that sets env variables. --- cli/run/index.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cli/run/index.ts b/cli/run/index.ts index 35500f0c559..5bf7d73dd6e 100644 --- a/cli/run/index.ts +++ b/cli/run/index.ts @@ -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) { @@ -48,7 +48,7 @@ export default function runRollup(command: any) { environment.forEach((arg: string) => { arg.split(',').forEach((pair: string) => { const [key, ...value] = pair.split(':'); - if (value && value.length) { + if (value.length) { process.env[key] = value.join(':'); } else { process.env[key] = String(true); @@ -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 {