-
Notifications
You must be signed in to change notification settings - Fork 1k
Add wrangler types support for importable env and process.env
#8478
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
Conversation
🦋 Changeset detectedLatest commit: 142f65e The changes in this PR will be included in the next version bump. This PR includes changesets to release 2 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
A wrangler prerelease is available for testing. You can install this latest build in your project with: npm install --save-dev https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/13846240203/npm-package-wrangler-8478You can reference the automatically updated head of this PR with: npm install --save-dev https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/prs/8478/npm-package-wrangler-8478Or you can use npx https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/13846240203/npm-package-wrangler-8478 dev path/to/script.jsAdditional artifacts:cloudflare-workers-bindings-extension: wget https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/13846240203/npm-package-cloudflare-workers-bindings-extension-8478 -O ./cloudflare-workers-bindings-extension.0.0.0-v32a125aae.vsix && code --install-extension ./cloudflare-workers-bindings-extension.0.0.0-v32a125aae.vsixcreate-cloudflare: npx https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/13846240203/npm-package-create-cloudflare-8478 --no-auto-update@cloudflare/kv-asset-handler: npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/13846240203/npm-package-cloudflare-kv-asset-handler-8478miniflare: npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/13846240203/npm-package-miniflare-8478@cloudflare/pages-shared: npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/13846240203/npm-package-cloudflare-pages-shared-8478@cloudflare/unenv-preset: npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/13846240203/npm-package-cloudflare-unenv-preset-8478@cloudflare/vite-plugin: npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/13846240203/npm-package-cloudflare-vite-plugin-8478@cloudflare/vitest-pool-workers: npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/13846240203/npm-package-cloudflare-vitest-pool-workers-8478@cloudflare/workers-editor-shared: npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/13846240203/npm-package-cloudflare-workers-editor-shared-8478@cloudflare/workers-shared: npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/13846240203/npm-package-cloudflare-workers-shared-8478@cloudflare/workflows-shared: npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/13846240203/npm-package-cloudflare-workflows-shared-8478Note that these links will no longer work once the GitHub Actions artifact expires.
Please ensure constraints are pinned, and |
| @@ -0,0 +1,30 @@ | |||
| import { UserError } from "./errors"; | |||
|
|
|||
| export function isProcessEnvPopulated( | |||
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.
error if nodejs_compat_populate_process_env && !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.
I don't think so, since that's not really an error case, it's just bad configuration
3013113 to
a5926c5
Compare
| "wrangler": patch | ||
| --- | ||
|
|
||
| Add `wrangler types` support for importable env and `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.
Arguably this is a minor, but I think it's a fine line. As such, I've made this a patch to test out backporting to v3.
ae5488e to
142f65e
Compare
Fixes #8454 and fixes #7757
There are two parts to this:
import { env } from "cloudflare:workers"has a type ofCloudflare.Env, whereCloudflareis a namespace defined by@cloudflare/workers-types. This PR changeswrangler typesto augment this namespace, and defineEnvin terms ofCloudflare.Env. This means that existing workers relying on anEnvtype being defined will continue to work, andimport { env } from "cloudflare:workers"will also be typed correctly.NodeJSnamespace when thenodejs_compat_populate_process_envcompatibility flag is turned on.process.envtypes are derived from aPickof thetext/json/secretbindings available, and always have a string-compatible value type (i.e. if--no-strict-varsis provided, every value will have a type ofstring, otherwisetextbindings will have a literal string type)