-
Notifications
You must be signed in to change notification settings - Fork 174
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
[Feature]: Add dryRun
option to parse env files without modifying process.env
#4638
Comments
I prefer to add a new // copied from `dotenv-expand`
export interface DotenvExpandOptions {
/**
* Default: `process.env`
*
* Specify an object to write your secrets to. Defaults to process.env environment variables.
*
* example: `const processEnv = {}; require('dotenv').config({ processEnv: processEnv })`
*/
processEnv?: DotenvPopulateInput;
} When the user needs to dry run, just pass an empty object in loadEnv({ processEnv: {} }); |
Yes, I revisited it, and providing the // default: use real environment variables
loadEnv({ processEnv: process.env });
// dryRun: mock cloned environment (isolated from real process.env)
loadEnv({ processEnv: {...process.env}});
// dryRun: empty environment (no variables)
loadEnv({ processEnv: {} }); Providing |
Do you plan to add a |
Yes I will |
What problem does this feature solve?
Description
Currently,
loadEnv()
merges environment variables from.env
,.env[.local]
.env[.mode]
, and.env[.mode[.local]]
files intoprocess.env
. While useful for build processes, this causes environment pollution when using custom CLI tools outside rsbuild's build/dev flows.The current loadEnv() + cleanup() pattern has limitations when environment variables already exist before loading:
Proposal
Add a
dryRun
boolean option toloadEnv()
. When enabled:parsed
fieldprocess.env
(Note:
loadEnv()
May need a separateprocessEnv
configuration for advanced environment injection control,like:https://dotenvx.com/docs/advanced/parse-process-env)What does the proposed API look like?
Use Case
Creating custom CLI tools that need env values without side effects:
Behavior Comparison
Implementation Notes
The text was updated successfully, but these errors were encountered: