Skip to content

Commit

Permalink
Allow 'production' ENV to take precedence over NODE_ENV (#2057)
Browse files Browse the repository at this point in the history
  • Loading branch information
joeyespo authored and bestander committed Dec 8, 2016
1 parent ee6cb2f commit c2a84a1
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
14 changes: 14 additions & 0 deletions __tests__/commands/install/integration.js
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,20 @@ test('install should respect NODE_ENV=production', (): Promise<void> => {
});
});

// 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<void> => {
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<void> => {
return runInstall({}, 'install-should-circumvent-circular-dependencies-2', async (config, reporter) => {
assert.equal(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"dependencies": {
"left-pad": "1.0.0"
},
"devDependencies": {
"is-negative-zero": "1.0.0"
}
}
5 changes: 4 additions & 1 deletion src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,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;
}
}
Expand Down

0 comments on commit c2a84a1

Please sign in to comment.