-
Notifications
You must be signed in to change notification settings - Fork 343
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
Implement importable env #3610
base: main
Are you sure you want to change the base?
Implement importable env #3610
Conversation
Summary of internal discussion:
|
8d7dffe
to
66d9c5c
Compare
Next round of updates:
Next known remaining todos:
|
36e3c6f
to
9a88837
Compare
Hmm, yeah, damn you're right :-/ ... ok, it's going to get rather complicated then. The other alternative I was considering is adding a new |
See my last comment above:
So I think you can keep the implementation as-is, except don't remove |
], | ||
compatibilityDate = "2025-02-01", | ||
compatibilityFlags = [ | ||
"nodejs_compat_v2", |
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.
Does this need nodejs compat?
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.
Oh... Assert
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've been debating whether to make node:assert
always available in wd-tests.
The PR description mentions that the flag is off by default. I think this is not the current state. Would be nice to read about security considerations in the description too. IIUC this could be used by any library to get access to the bindings. |
One last thing: is "(dis)allow_importable_env" really reflecting what this does? IIUC the PR does not (dis)allow anything. Env is always importable - sometimes not populated/connected. Would be nice to have a better description on the PR description and maybe a name reflecting the actual behavior. Thanks |
Happy to accept suggestions for alternative names for the compat flags. I feel they are descriptive of what they are doing but opinions may vary |
```js import { env } from 'cloudflare:workers'; console.log(env.FOO); // Undefined, outside request io context export default { fetch(req) { console.log(env.FOO); // 'BAR', inside request io context // ... } } ``` Gated by a compat flag that is off by default * `allow_importable_env` * `disallow_importable_env` Mutations of the env properties are passed through to the underlying object so will be reflected on the `env` argument passed into the handlers.
Rather than persisting the env in Worker::Impl, store it in jsg::Lock so that it is easier to access from places that do not have access to Worker::Impl.
f07505e
to
2603d7e
Compare
"Note that this is not related to process.env..." It actually is somehow related now that process.env is populated from the env. |
|
||
import { strictEqual, notDeepStrictEqual } from 'node:assert'; | ||
|
||
strictEqual(env.FOO, undefined); |
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.
maybe add a test setting env.BAR
not reflected on argEnv.BAR
# When enabled, `import { env } from 'cloudflare:workers'` will provide access | ||
# the per-request environment/bindings. |
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.
# When enabled, `import { env } from 'cloudflare:workers'` will provide access | |
# the per-request environment/bindings. | |
# When allowed, `import { env } from 'cloudflare:workers'` will provide access | |
# to the per-request environment/bindings. |
if (inner) { | ||
return Reflect.deleteProperty(inner, prop); | ||
} | ||
return true; |
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.
Should this return false
here ?
PR marked as a draft until we're certain this is what we want....
Gated by a compat flag that is off by defaultThe flag is now on by default.allow_importable_env
disallow_importable_env
Mutations of the env properties are passed through to the underlying object so will be reflected on the
env
argument passed into the handlers.Note that this is not related to
process.env
... this exposes the regularenv
/bindings
via the import when accessed within the context of a request. As such, any modules used by your worker can access the bindings without having them explicitly passed down.