From aae6e873251a21c1e8d528e5e529dbc74dc166f3 Mon Sep 17 00:00:00 2001 From: Evan Shortiss Date: Tue, 22 Nov 2016 10:29:08 -0800 Subject: [PATCH 1/3] only add vars that are not undefined --- package.json | 3 ++- tasks/env.js | 5 ++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index a3e32aa..6ec4f80 100644 --- a/package.json +++ b/package.json @@ -29,6 +29,7 @@ }, "devDependencies": { "grunt": "~0.4.5", + "grunt-cli": "~1.2.0", "grunt-contrib-clean": "~0.6.0", "grunt-contrib-jshint": "~0.11.0", "grunt-jscs": "^1.5.0" @@ -42,4 +43,4 @@ "ini": "~1.3.0", "lodash": "~2.4.1" } -} \ No newline at end of file +} diff --git a/tasks/env.js b/tasks/env.js index 24cc024..02c1e6a 100644 --- a/tasks/env.js +++ b/tasks/env.js @@ -65,7 +65,10 @@ module.exports = function(grunt) { } else { var data = {}; data[option] = typeof optionData === 'function' ? optionData() : optionData; - _.extend(process.env, data); + + if (typeof data[option] !== undefined) { + _.extend(process.env, data); + } } }); } From 50eb2c16d3a8de070df8bb4833652867447294c8 Mon Sep 17 00:00:00 2001 From: Evan Shortiss Date: Tue, 22 Nov 2016 10:35:14 -0800 Subject: [PATCH 2/3] add test --- Gruntfile.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Gruntfile.js b/Gruntfile.js index bda8cf0..be0446e 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -10,6 +10,10 @@ module.exports = function(grunt) { globalOption: 'foo' }, testData: { + UNDEFINED_OPTION: function() { + // logic here might return undefined or not, but for testing we do + return undefined; + }, TEST: 'test', data: 'bar' }, @@ -97,6 +101,12 @@ module.exports = function(grunt) { assert.equal(process.env.data, 'bar', 'data should be set'); delete process.env.globalOption; delete process.env.data; + + assert.equal( + process.env.hasOwnProperty('undefinedOption'), + false, + 'undefinedOption should not be set on process.env' + ); }); grunt.registerTask('testOptions', function() { From 8f4ab5beb72759788aa17e6c00ecb6788750deb0 Mon Sep 17 00:00:00 2001 From: Evan Shortiss Date: Tue, 22 Nov 2016 10:45:59 -0800 Subject: [PATCH 3/3] fix test --- Gruntfile.js | 4 ++-- tasks/env.js | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Gruntfile.js b/Gruntfile.js index be0446e..5d78c75 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -103,9 +103,9 @@ module.exports = function(grunt) { delete process.env.data; assert.equal( - process.env.hasOwnProperty('undefinedOption'), + process.env.hasOwnProperty('UNDEFINED_OPTION'), false, - 'undefinedOption should not be set on process.env' + 'UNDEFINED_OPTION should not be set on process.env' ); }); diff --git a/tasks/env.js b/tasks/env.js index 02c1e6a..0d9c38f 100644 --- a/tasks/env.js +++ b/tasks/env.js @@ -66,7 +66,7 @@ module.exports = function(grunt) { var data = {}; data[option] = typeof optionData === 'function' ? optionData() : optionData; - if (typeof data[option] !== undefined) { + if (data[option] !== undefined) { _.extend(process.env, data); } }