Merge pull request #4503 from eirikurn/empty-env-variables

EnvironmentPlugin: Support empty env variables
This commit is contained in:
Tobias Koppers 2017-03-20 22:34:40 +01:00 committed by GitHub
commit 98ea82340f
4 changed files with 17 additions and 2 deletions

View File

@ -23,7 +23,7 @@ class EnvironmentPlugin {
apply(compiler) {
const definitions = this.keys.reduce((defs, key) => {
const value = process.env[key] || this.defaultValues[key];
const value = process.env[key] !== undefined ? process.env[key] : this.defaultValues[key];
if(value === undefined) {
compiler.plugin("this-compilation", compilation => {

View File

@ -1,4 +1,4 @@
const variables = ['aaa', 'bbb', 'ccc', 'ddd', 'eee', 'fff', 'ggg', 'hhh'];
const variables = ['aaa', 'bbb', 'ccc', 'ddd', 'eee', 'fff', 'ggg', 'hhh', 'iii'];
const modules = [{
name: 'aaa',
variables: ['aaa']
@ -14,6 +14,9 @@ const modules = [{
}, {
name: 'ggghhh',
variables: ['ggg', 'hhh']
}, {
name: 'iii',
variables: ['iii']
}];
// build an array of regular expressions of expected errors

View File

@ -28,3 +28,8 @@ it("should import multiple process.env var with default values", () => {
if(process.env.HHH !== "hhh")
require.include("hhh");
});
it("should import process.env var with empty value", () => {
if(process.env.III !== "")
require.include("iii");
});

View File

@ -6,6 +6,7 @@ process.env.CCC = "ccc";
process.env.EEE = "eee";
process.env.FFF = "fff";
process.env.GGG = "ggg";
process.env.III = "";
module.exports = [{
name: "aaa",
@ -40,4 +41,10 @@ module.exports = [{
HHH: 'hhh'
})
]
}, {
name: "iii",
module: { unknownContextRegExp: /$^/, unknownContextCritical: false },
plugins: [
new EnvironmentPlugin("III")
]
}];