Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
Provide mechanism for autopopulating node.js process.env #3311
base: main
Are you sure you want to change the base?
Provide mechanism for autopopulating node.js process.env #3311
Changes from 3 commits
09a9009
ae7d239
94cc609
8ba527b
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
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.
what about:
getEnvObject -> getProcessEnvObj
getEnv -> getProcessEnv
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.
expressed -> exposed?
maybe expand on "when nodejs-compat mode is used" (to refer to the flag)
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.
We also need to call this for JSON vars that parse to a plain string, and any other type of variable whose type is a plain string, otherwise we're still piercing the abstraction here.
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.
It might be easier to just give the entire
env
object over to the proxy, and let the proxy filter for fields which are strings.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.
As discussed.. I'm strongly -1 on special casing JSON fields that parse to a string vs. other js types, largely because it sets up an inconsistency.
It is extremely common in Node.js for env vars to be defined as JSON strings such that node.js code will unconditionally do
JSON.parse(process.env.FOO)
. If sometimes a JSON binding is ignored, sometimes it comes through as a parsed json string, or sometimes it comes through as an encoded JSON string, then this extremely common Node.js pattern breaks. User code would end up having to be changed to inspect the value ofprocess.env.FOO
in advance or wrap theJSON.parse(process.env.FOO)
in atry/catch
, both of which are unlikely when we're talking about ecosystem modules folks are pulling off npm.Yes, I understand that we have edge cases that represent what should be plaintext text bindings as JSON bindings but that's an implementation detail/quirk/edge case that I don't think we should be optimizing for.
Such as?
To be clear, there are no other bindings in workerd-api.c++ whose type is a plain string so it's not clear what you're suggesting here. Given that the internal repo has a different (more expansive) set of bindings possible then sure, the
setEnvField(...)
may need to be called in more places in the internal PR but for workerd there aren't other binding types whose value is a plaintext string.process.env
should be limited to specifically the things we call "environment variables" and not other types of bindings.I disagree. This mechanism also works for old service worker syntax workers in which the
env
object is theglobalThis
. It would make things rather more complicated if we had to special case these options whereas the current implementation keeps things rather simple.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.
Further, if we did decide to propagate other types of bindings to
process.env
we can do so in separate PRs. That shouldn't be blocking for this initial PRThere 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.
Note:
wrangler dev/miniflare
use JSON bindings for now so the PR will not work as is.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.
It appears to do so for local development at least. A quick test of
wrangler deploy
shows that it appropriately usesTEXT
bindings for env vars when pushed to production. So the limitation here would appear to be limited to local dev. Should be fixed, yes, but I don't think it's a blocker for merging.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.
PR to fix
wrangler dev
so that it matches production and usesTEXT
as appropriate cloudflare/workers-sdk#7738