From aef8a52a7fceee74c3a5c3c9b4fd6d4509d972ed Mon Sep 17 00:00:00 2001 From: Joe Esposito Date: Mon, 28 Nov 2016 14:48:28 -0500 Subject: [PATCH] Allow 'production' ENV to take precedence over NODE_ENV --- __tests__/commands/install/integration.js | 14 ++++++++++++++ .../package.json | 8 ++++++++ src/config.js | 5 ++++- 3 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 __tests__/fixtures/install/install-should-respect-npm_config_production/package.json diff --git a/__tests__/commands/install/integration.js b/__tests__/commands/install/integration.js index 297ba9cec5..a91ba99dc5 100644 --- a/__tests__/commands/install/integration.js +++ b/__tests__/commands/install/integration.js @@ -403,6 +403,20 @@ test('install should respect NODE_ENV=production', (): Promise => { }); }); +// don't run this test in `concurrent`, it will affect other tests +test('install should respect NPM_CONFIG_PRODUCTION=false over NODE_ENV=production', (): Promise => { + const env = process.env.NODE_ENV; + const prod = process.env.NPM_CONFIG_PRODUCTION; + process.env.NODE_ENV = 'production'; + process.env.NPM_CONFIG_PRODUCTION = 'false'; + return runInstall({}, 'install-should-respect-npm_config_production', async (config) => { + expect(await fs.exists(path.join(config.cwd, 'node_modules/is-negative-zero/package.json'))).toBe(true); + // restore env + process.env.NODE_ENV = env; + process.env.NPM_CONFIG_PRODUCTION = prod; + }); +}); + test.concurrent('install should resolve circular dependencies 2', (): Promise => { return runInstall({}, 'install-should-circumvent-circular-dependencies-2', async (config, reporter) => { assert.equal( diff --git a/__tests__/fixtures/install/install-should-respect-npm_config_production/package.json b/__tests__/fixtures/install/install-should-respect-npm_config_production/package.json new file mode 100644 index 0000000000..65501c3c04 --- /dev/null +++ b/__tests__/fixtures/install/install-should-respect-npm_config_production/package.json @@ -0,0 +1,8 @@ +{ + "dependencies": { + "left-pad": "1.0.0" + }, + "devDependencies": { + "is-negative-zero": "1.0.0" + } +} diff --git a/src/config.js b/src/config.js index 8899852690..00d5ae0558 100644 --- a/src/config.js +++ b/src/config.js @@ -210,7 +210,10 @@ export default class Config { await fs.mkdirp(this.cacheFolder); await fs.mkdirp(this.tempFolder); - if (this.getOption('production') || process.env.NODE_ENV === 'production') { + if (this.getOption('production') || ( + process.env.NODE_ENV === 'production' && + process.env.NPM_CONFIG_PRODUCTION !== 'false' && + process.env.YARN_PRODUCTION !== 'false')) { this.production = true; } }