-
-
Notifications
You must be signed in to change notification settings - Fork 94
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
Add context, add read-only process env option #72
Add context, add read-only process env option #72
Conversation
+1 for the idea of being able to read, but not write to |
|
||
switch (config.ignoreProcessEnv) { | ||
case 'read-only': | ||
environment = rfdc()(process.env) |
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.
Could add a TODO to drop this library and use structuredClone
when only Node 18 is supported
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, process.env
won't be a nested object will it? So this could just use Object.assign
rather than an external Library?
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.
Wasn't aware of structuredClone
until now - whether we need a TODO for this or not is up to @motdotla.
As for the depth of process.env
, theoretically it will be flat, but technically one could mutate it beforehand to be more than one level deep, and it's probably a point for tricky bugs if this library wasn't defensive against that.
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 stand corrected! You're absolutely right about not needing the deep clone.
@WoodyWoodsta is |
@benmccann
|
we removed HELLO=World const dotenv = require('dotenv')
const dotenvExpand = require('dotenv-expand')
const myEnv = {}
dotenvExpand.expand({ processEnv: myEnv, parsed: dotenv.config({ processEnv: {} }).parsed })
console.log(process.env.HELLO) // undefined
console.log(myEnv.HELLO) // World source: https://github.com/motdotla/dotenv-expand?tab=readme-ov-file#processenv |
This PR addresses #55, as well as provides a route to fixing vitejs/vite#6626
Updated Options
ignoreProcessEnv
: addedread-only
option, which will read fromprocess.env
but not write to it.New Options
context
: optionally pass your own environment context to be used ifignoreProcessEnv: true
.