-
Notifications
You must be signed in to change notification settings - Fork 757
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
widen multi-env vars
types in wrangler types
and add --strict-vars
option to the command
#5086
base: main
Are you sure you want to change the base?
Conversation
🦋 Changeset detectedLatest commit: 5405cd8 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/12679174554/npm-package-wrangler-5086 You can reference the automatically updated head of this PR with: npm install --save-dev https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/prs/5086/npm-package-wrangler-5086 Or you can use npx https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/12679174554/npm-package-wrangler-5086 dev path/to/script.js Additional artifacts:wget https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/12679174554/npm-package-cloudflare-workers-bindings-extension-5086 -O ./cloudflare-workers-bindings-extension.0.0.0-v764a02dfa.vsix && code --install-extension ./cloudflare-workers-bindings-extension.0.0.0-v764a02dfa.vsix npx https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/12679174554/npm-package-create-cloudflare-5086 --no-auto-update npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/12679174554/npm-package-cloudflare-kv-asset-handler-5086 npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/12679174554/npm-package-miniflare-5086 npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/12679174554/npm-package-cloudflare-pages-shared-5086 npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/12679174554/npm-package-cloudflare-unenv-preset-5086 npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/12679174554/npm-package-cloudflare-vitest-pool-workers-5086 npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/12679174554/npm-package-cloudflare-workers-editor-shared-5086 npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/12679174554/npm-package-cloudflare-workers-shared-5086 npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/12679174554/npm-package-cloudflare-workflows-shared-5086 Note that these links will no longer work once the GitHub Actions artifact expires.
Please ensure constraints are pinned, and |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #5086 +/- ##
==========================================
+ Coverage 70.33% 70.42% +0.08%
==========================================
Files 298 298
Lines 15515 15536 +21
Branches 3987 3990 +3
==========================================
+ Hits 10913 10941 +28
+ Misses 4602 4595 -7
|
I've converted this PR to draft as it's been decided by the team that we should go with generic |
Hi 👋, Thanks @dario-piotrowicz for the PR, this is something we had to fix manually after running |
I'd be keen to know what the reasoning was for using a generic string type instead of string literals. Surely having more robust types would benefit those of us using typescript? My solution atm is to override the type. |
@dario-piotrowicz Is there a place to track that decision/implementation? I'd also prefer a union but I'm mostly looking to avoid this bug |
Hi @jfsiii 👋 Sorry, honestly this has fallen off my radar and I haven't pushed for a resolution, it's been quite a long time since this PR has been opened... let me ping the team and prompt them to make a decision, then I can update and merge this PR 🙂👍 |
Hey just checking in on the progress. Thanks 😄 |
df55b66
to
b4ac0d9
Compare
@kansson thanks for the ping 🙂 , I checked with the team a few days ago and it was suggested that I add a flag to allow having the loosen/generic types alongside the literal/union ones, so that we can have both the stricter/robust types alongside loosen/generic ones if needed (to try to satisfy everyone) That's what I did with the new I've also rebased the PR, it's ready to be re-reviewer and hopefully merged soon 🙂 @jfsiii so sorry for the late action here 😓 (not to mention @DaniFoldi 😅 🙇) |
vars
types in wrangler types
vars
types in wrangler types
and add --loose-vars
option to the command
@@ -603,6 +603,35 @@ describe("generateTypes()", () => { | |||
`); | |||
}); | |||
|
|||
it("should respect the loose-vars option", async () => { |
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 was considering adding a test for vars generation without loose-vars, but since that's the default behavior (and given the "vars present in multiple environments"
describe block) that felt a bit overkill here 😕 I'm happy to do it if someone thinks that that would be good
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 given the "vars present in multiple environments"
describe block, this test might be a bit overkill... I'm also happy to remove it entirely 🙂
@petebacondarwin, @andyjessop please have a look when you get the chance 🙏 |
vars
types in wrangler types
and add --loose-vars
option to the commandvars
types in wrangler types
and add --strict-vars
option to the command
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.
In general, could you add some more comments explaining the logic? There's some fairly complicated code here
All the types gen logic here seems to me fairly complicated but without any comments, so I was just trying to adhere to the code style in these files, if code consistency is not a concern I'll add some comments to the new logic 👍 Amend: 👆 sorry I misremembered, that's not actually true, there are comments in some places but not in others |
@penalosa I've simplified the logic I had (alongside the var values I was also needlessly collecting their environment name, I did so as it might come in handy in the future, but I think that it's just better to keep things simple and add it later if the extra complexity becomes necessary) and I added a few comments, hopefully the code should be simpler to follow now, please have another look and let me know 🙏 |
@@ -262,11 +247,14 @@ async function generateTypes( | |||
); | |||
} | |||
|
|||
const envTypeStructure: string[] = []; | |||
const envTypeStructure: [string, string][] = []; |
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 think it would be nicer/clearer to have this as
const envTypeStructure: {
key: string,
type: string,
}[] = [];
but it would make all the .push
calls below much more verbose, and the current code should be clear enough
but I am happy with either solution, if anyone prefers the more verbose version (or has any other idea) I'm happy to change this
@petebacondarwin sorry I had to change the code significantly after your approval 😓 🙇 , if you would please have another look (PS: anyways the functionality didn't change, I just cleaned up the code and fixes something I broke) |
e366aed
to
e4d2892
Compare
rename `loose-vars` to `strict-vars`
Co-authored-by: Somhairle MacLeòid <smacleod@cloudflare.com>
Co-authored-by: Pete Bacon Darwin <pete@bacondarwin.com>
Co-authored-by: Pete Bacon Darwin <pete@bacondarwin.com>
e4d2892
to
5405cd8
Compare
Fixes #5082
This PR does two things:
vars
types thatwrangler types
generates when the same variables are defined in different environments (basically instead of incorrectly generate something likeMY_VAR: "dev value";
now we could correctly generateMY_VAR: "dev value" | "prod value";
etc...)--strict-vars
) that allows the generated types not to be literals/unions but to be loose/generic ones (e.g. instead ofMY_VAR: "dev value" | "prod value";
it allows the generation ofMY_VAR: string;
), this was added after various feedback and back and forth from the team (the concern being that literal values/unions can be annoying for people if they change their var values often)For more details please check the changeset files in the PR 🙂
--strict-vars
option to thewrangler types
command cloudflare-docs#18981