Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow 'production' ENV to take precedence over NODE_ENV #2057

Merged
merged 1 commit into from
Dec 8, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -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') || (
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's no --no-production to my knowledge, but this does work exactly like npm where you can set NPM_CONFIG_PRODUCTION=false in your config.

My concern is that if NODE_ENV is set to production overriding it can only be done with another env variable, e.g. YARN_PRODUCTION.
Sometimes people don't have full control over environment variables in the system and overriding with an arg can be a more obvious API.

In npm you can do --production=false and it will override env variables.
Can you do similar thing for Yarn?

Copy link

@adamreisnz adamreisnz Dec 17, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if the opposite is true, where people only have control over env variables rather than CLI arguments? E.g. when running on Heroku under the constraints as described in #2283

process.env.NODE_ENV === 'production' &&
process.env.NPM_CONFIG_PRODUCTION !== 'false' &&
process.env.YARN_PRODUCTION !== 'false')) {
this.production = true;
}
}
Expand Down