Skip to content
Browse files

Don't clobber user-defined environment variables

Re: javache 's suggestions from #7878. Didn't want to deal with the merge conflict so I'm opening a separate PR. Here's the original justification:

If I want to set NODE_ENV to "baconator", I should be allowed to. Mutating global state that most devs assume to be immutable is just abysmal dev practice, especially since this mutation only happens when you're building for prod, not running on the simulator.

To test this, run env NODE_ENV=baconator ./gradlew assembleRelease with babel-plugin-transform-inline-environment-variables in your app/.babelrc. You'll see that the final app has NODE_ENV=production.

As a side note, running with babel-plugin-transform-inline-environment-variables in the top-level .babelrc crashes horribly with a compiler error.

For anybody who runs into this bug and doesn't feel like waiting for this to get merged, I wrote a quick babel plugin to remove assignments to process.env, which is sufficient to fix this issue.
Closes #8057

Differential Revision: D3419950

Pulled By: javache

fbshipit-source-id: dc541cad0a99906433e5c14bbc93ce66b4ed325e
  • Loading branch information...
vkarpov15 authored and Facebook Github Bot 6 committed Jun 10, 2016
1 parent 14d0b5c commit 402e7eaac2f15b98bb15ce13198afe2393cb2503
Showing with 6 additions and 1 deletion.
  1. +6 −1 local-cli/bundle/buildBundle.js
@@ -25,7 +25,12 @@ function buildBundle(args, config, output = outputBundle, packagerInstance) {

// This is used by a bazillion of npm modules we don't control so we don't
// have other choice than defining it as an env variable here.
process.env.NODE_ENV = ? 'development' : 'production';
if (!process.env.NODE_ENV) {
// If you're inlining environment variables, you can use babel to remove
// this line:
process.env.NODE_ENV = ? 'development' : 'production';

const options = {
projectRoots: config.getProjectRoots(),

0 comments on commit 402e7ea

Please sign in to comment.
You can’t perform that action at this time.