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

fix(env): set mode after config loaded #4009

Closed
wants to merge 1 commit into from
Closed

Conversation

evenstensberg
Copy link
Member

What kind of change does this PR introduce?
Fixes #3992

Did you add tests for your changes?
No
If relevant, did you update the documentation?
N/A
Summary
Make sure mode is set based on node_env
Does this PR introduce a breaking change?
No
Other information
N/A

Copy link

codecov bot commented Nov 16, 2023

Codecov Report

Merging #4009 (d453561) into master (d40cae4) will increase coverage by 0.02%.
Report is 24 commits behind head on master.
The diff coverage is 100.00%.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #4009      +/-   ##
==========================================
+ Coverage   90.87%   90.90%   +0.02%     
==========================================
  Files          22       22              
  Lines        1688     1693       +5     
  Branches      486      490       +4     
==========================================
+ Hits         1534     1539       +5     
  Misses        154      154              
Files Coverage Δ
packages/webpack-cli/src/webpack-cli.ts 92.64% <100.00%> (+0.03%) ⬆️

Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update d40cae4...d453561. Read the comment docs.

Copy link
Member

@snitin315 snitin315 left a comment

Choose a reason for hiding this comment

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

Can we add a corresponding test case?

@Ivan198407
Copy link

Ivan198407 commented Nov 24, 2023 via email

Copy link
Member

@alexander-akait alexander-akait left a comment

Choose a reason for hiding this comment

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

It is a bad idea, node-env and mode are different things and we already support another solution

@aoberoi
Copy link

aoberoi commented Dec 15, 2023

@alexander-akait can you clarify what the other solution is? maybe we just need to update the docs to reflect it.

@aoberoi
Copy link

aoberoi commented Dec 15, 2023

After reading the code, it seems like the mode is set automatically after the developer's exported config function is run and returns.

Issues like the one @mgnsm has reported (#3992) are occurring because the documentation isn't describing exactly how NODE_ENV, the arguments to the configuration function, and mode are coordinated.

Based on the current docs it seems reasonable to expect the automatic application of NODE_ENV to mode to show up somewhere in the config function. I think its usually the case that developers who implement a config function want to use the mode value to implement other logic as well (enabling / disabling plugins, modifying other config values, etc). The fact that this automatic application happens after the config function runs seems -- less than helpful.

In order to implement logic based on NODE_ENV/mode in the config function, the developer is forced to essentially duplicate the logic that's already in the CLI solution. Which ironically renders the CLI solution moot because the developer could just assign that to mode in the returned config themselves. So who does the CLI solution serve? It seems like its really for developers who are not using a config function.

Beyond updating the docs to make the intended behavior and use cases clear, I don't have a suggestion on updating the implementation. I think removing the current solution would be a breaking change, so I'm not in favor of that. I think adding this change would be duplicative, so I'm not in favor of that. I think we just need better guidance.

@alexander-akait
Copy link
Member

Works as expected due #3992 (comment), yes, we need to update our docs here, I will help

@alexander-akait
Copy link
Member

@aoberoi Yeah, you are right, argv is just an object of passed arguments through CLI, I don't know why developers expected to see the mode there

No need to duplicate logic because you can use argv.nodeEnv or process.env.NODE_ENV, the last solution is more common and using a lot of developers

Anyway feel free to feedback

@alexander-akait alexander-akait deleted the fix/node-env branch January 11, 2024 14:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

--node-env doesn't set the mode as expected
6 participants