-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
fix(env): do not override NODE_ENV if already set #474
fix(env): do not override NODE_ENV if already set #474
Conversation
- If NODE_ENV is set, use it - In ReactComponent, instead of checking for `development`, check for `not production`, allowing to use `debug` for example and treat it the same as `development`
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool, thanks! Could you please check CI?
@@ -5,7 +5,7 @@ import Methods from 'rsg-components/Methods'; | |||
import Examples from 'rsg-components/Examples'; | |||
import ReactComponentRenderer from 'rsg-components/ReactComponent/ReactComponentRenderer'; | |||
|
|||
const ExamplePlaceholder = process.env.NODE_ENV === 'development' | |||
const ExamplePlaceholder = process.env.NODE_ENV !== 'production' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually that is what causing CI to fail.
I'm assuming Jest snapshots have been taken with NODE_ENV set to 'production'. In CI, the test runs with NODE_ENV=test, so it makes my test (process.env.NODE_ENV !== 'production') truthy. That means that in test mode, component are not rendered in 'production' mode, and therefore the snapshots do not match.
Before my change, with NODE_ENV set to 'test' would render the component in production mode... quite a conundrum here. I have a feeling that it would make more sense to revert this change and keep snapshots 'production'. It means that ONLY when specifically set to 'development', component are rendered that special way? Let me know what you think @sapegin
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thinks != production is more common way to check that but we’ll probably need to grep the code for development
and update checks in other places too ;-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right. So I grep'd around and didn't find any places that looked like they should be updated, beside that one line. So my suggestion is to consider the 'test' path by updating the condition to:
const ExamplePlaceholder = process.env.NODE_ENV !== 'production' && process.env.NODE_ENV !== 'test'
? require('rsg-components/ExamplePlaceholder').default
: () => <div />;
This has no impact for production code and it should allow CI to pass.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can just update snapshots because it doesn’t really matter if it renders placeholder or not if it does the right thing ;-)
Codecov Report
@@ Coverage Diff @@
## master #474 +/- ##
=======================================
Coverage 95.23% 95.23%
=======================================
Files 98 98
Lines 1280 1280
Branches 264 264
=======================================
Hits 1219 1219
Misses 59 59
Partials 2 2
Continue to review full report at Codecov.
|
@sapegin I finally got around this PR and by virtue of synchronizing it with the latest from master, CI tests are all passing 😄 Let me know if you need anything else. Thanks! |
Awesome, thanks! |
This recent styleguidist update to support Create React App is overriding NODE_ENV, even if it's already set by the user.
This PR is an attempt to fix this and still support Create React App:
development
, check fornot production
, allowing the use ofdebug
for example and treat it the same asdevelopment
This is allowing a user to do this:
and configure their webpack/styleguidist configuration to act accordingly on 'debug'