Skip to content
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

Support wrangler.json #2409

Merged
merged 17 commits into from
Jan 23, 2023
Merged

Support wrangler.json #2409

merged 17 commits into from
Jan 23, 2023

Conversation

penalosa
Copy link
Contributor

@penalosa penalosa commented Dec 14, 2022

What this PR solves / how to test:

This PR adds wrangler.json (which is JSONC) support! It doesn't add support for converting TOML to JSON, or change the format init generates. To test, create a normal worker, and convert the generated wrangler.toml file to wrangler.json (ether by hand, or by using something like toml2json). All the property names are the same between TOML and JSONC.

Associated docs issues/PR: #7166

Author has included the following, where applicable:

  • Tests
  • Changeset

Reviewer has performed the following, where applicable:

  • Checked for inclusion of relevant tests
  • Checked for inclusion of a relevant changeset
  • Checked for creation of associated docs updates
  • Manually pulled down the changes and spot-tested

Fixes #2376.

@penalosa penalosa requested a review from a team as a code owner December 14, 2022 01:33
@changeset-bot
Copy link

changeset-bot bot commented Dec 14, 2022

🦋 Changeset detected

Latest commit: e06c4db

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
wrangler Patch

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

@github-actions
Copy link
Contributor

github-actions bot commented Dec 14, 2022

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/runs/3990523105/npm-package-wrangler-2409

You can reference the automatically updated head of this PR with:

npm install --save-dev https://prerelease-registry.devprod.cloudflare.dev/prs/2409/npm-package-wrangler-2409

Or you can use npx with this latest build directly:

npx https://prerelease-registry.devprod.cloudflare.dev/runs/3990523105/npm-package-wrangler-2409 dev path/to/script.js
Additional artifacts:
npm install https://prerelease-registry.devprod.cloudflare.dev/runs/3990523105/npm-package-cloudflare-pages-shared-2409

@codecov
Copy link

codecov bot commented Dec 14, 2022

Codecov Report

Merging #2409 (e06c4db) into main (e6c9c5c) will decrease coverage by 0.10%.
The diff coverage is 77.59%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #2409      +/-   ##
==========================================
- Coverage   73.32%   73.23%   -0.10%     
==========================================
  Files         159      159              
  Lines        9800     9847      +47     
  Branches     2583     2622      +39     
==========================================
+ Hits         7186     7211      +25     
- Misses       2614     2636      +22     
Impacted Files Coverage Δ
packages/wrangler/src/d1/create.tsx 33.33% <0.00%> (ø)
packages/wrangler/src/d1/list.tsx 29.62% <0.00%> (-1.14%) ⬇️
packages/wrangler/src/docs/index.ts 27.27% <0.00%> (-1.30%) ⬇️
packages/wrangler/src/d1/index.ts 84.61% <33.33%> (ø)
packages/wrangler/src/api/dev.ts 60.21% <47.36%> (-8.88%) ⬇️
packages/wrangler/src/d1/backups.tsx 26.58% <50.00%> (ø)
packages/wrangler/src/d1/delete.ts 34.78% <50.00%> (ø)
packages/wrangler/src/d1/execute.tsx 16.93% <50.00%> (ø)
packages/wrangler/src/d1/migrations/create.tsx 35.48% <50.00%> (ø)
packages/wrangler/src/d1/migrations/list.tsx 35.48% <50.00%> (ø)
... and 37 more

@JacobMGEvans
Copy link
Contributor

I'm excited.

Copy link
Contributor

@JacobMGEvans JacobMGEvans left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not seeing any significant issues, is there anything else we are waiting on before this can go in?

Edit: Please add a changeset 😄

packages/wrangler/src/config/index.ts Show resolved Hide resolved
@penalosa
Copy link
Contributor Author

@JacobMGEvans it's waiting on docs and a command line flag to enable, which I need to implement (and a changeset). Will get to those soon!

@penalosa penalosa force-pushed the penalosa/json-config branch 2 times, most recently from e1f6aa1 to 9140713 Compare January 4, 2023 19:50
@penalosa penalosa requested review from JacobMGEvans and a team January 4, 2023 19:53
@admah
Copy link
Contributor

admah commented Jan 4, 2023

@penalosa are there docs on this yet?

Copy link
Contributor

@JacobMGEvans JacobMGEvans left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thought we were gonna use JSON5?

Edit: I probably am just remembering things wrong, been awhile since the discussion lol

Copy link
Contributor

@JacobMGEvans JacobMGEvans left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nothing else is blocking or outstanding on my end. Looks awesome!!

packages/wrangler/src/__tests__/parse.test.ts Show resolved Hide resolved
Copy link
Contributor

@mrbbot mrbbot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! 🎉 Added some comments... 🙂 I also think JSON config should probably have camelCase keys, but given this is experimental I guess we could change that later? Would probably be a bit of a pain though.

packages/wrangler/scripts/bundle.ts Show resolved Hide resolved
packages/wrangler/src/__tests__/d1.test.ts Outdated Show resolved Hide resolved
packages/wrangler/src/config/index.ts Outdated Show resolved Hide resolved
packages/wrangler/src/parse.ts Outdated Show resolved Hide resolved
@penalosa penalosa requested a review from a team as a code owner January 10, 2023 13:26
Copy link
Contributor

@JacobMGEvans JacobMGEvans left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the Types refactoring commit d84dfcf: How much of this is in regard to the JSON configuration support and how much could be its own separate refactoring effort?

Copy link
Contributor

@JacobMGEvans JacobMGEvans left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is looking great, really looking forward to JSON support myself. A few questions, and concerns.

packages/wrangler/src/index.ts Show resolved Hide resolved
packages/wrangler/src/index.ts Show resolved Hide resolved
packages/wrangler/src/dispatch-namespace.ts Show resolved Hide resolved
packages/wrangler/src/dev.tsx Show resolved Hide resolved
packages/wrangler/src/dev.tsx Show resolved Hide resolved
packages/wrangler/src/config/index.ts Show resolved Hide resolved
@penalosa
Copy link
Contributor Author

For the Types refactoring commit d84dfcf: How much of this is in regard to the JSON configuration support and how much could be its own separate refactoring effort?

Some of it is separate, but a lot of it is related to the improved typing of the readConfig function (to support the JSON configuration flag). This function is used everywhere, and so a change to it's types required a lot of changes across the codebase (because it's parameters were typed as unknown before, which let callers of readConfig have a lot of flexibility in what they passed—I'm pretty sure it was always the right thing, but it was rarely typed correctly)

@JacobMGEvans
Copy link
Contributor

For the Types refactoring commit d84dfcf: How much of this is in regard to the JSON configuration support and how much could be its own separate refactoring effort?

Some of it is separate, but a lot of it is related to the improved typing of the readConfig function (to support the JSON configuration flag). This function is used everywhere, and so a change to it's types required a lot of changes across the codebase (because it's parameters were typed as unknown before, which let callers of readConfig have a lot of flexibility in what they passed—I'm pretty sure it was always the right thing, but it was rarely typed correctly)

Thank you for connecting the type changes to the JSON changes, that definitely makes sense with the additional context. The type change look amazing too!

@penalosa
Copy link
Contributor Author

penalosa commented Jan 13, 2023

Is there any particular reason for if - else if rather than if - else

I can't seem to reply to this inline 😅
No particular reason other than a slight readability benefit (it makes it clear what type of file we're looking for—I think .jsonc is also sometimes used for json with comments). Happy to go with if - else if you'd prefer

@lrapoport-cf
Copy link
Contributor

@penalosa are there docs on this yet?

related discussion: cloudflare/cloudflare-docs#7278 (review) and cloudflare/cloudflare-docs#7278 (comment)

@penalosa
Copy link
Contributor Author

@JacobMGEvans is there anything else outstanding in this PR that you're concerned about?

@JacobMGEvans
Copy link
Contributor

@JacobMGEvans is there anything else outstanding in this PR that you're concerned about?

Nope, as I mentioned in the meeting I'm super onboard with getting this in. I appreciate you covering all my questions, concerns, and comments 😁

T extends (yargs: Argv<CommonYargsOptions>) => Argv
> = T extends (yargs: Argv<CommonYargsOptions>) => Argv<infer P>
? ArgumentsCamelCase<P>
export type StrictYargsOptionsToInterface<
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Niiiiiice. ❤️

@penalosa penalosa force-pushed the penalosa/json-config branch from ae414d1 to 9df2e21 Compare January 23, 2023 17:18
@penalosa penalosa force-pushed the penalosa/json-config branch from 9df2e21 to 190102f Compare January 23, 2023 17:28
@lrapoport-cf
Copy link
Contributor

lrapoport-cf commented Jan 23, 2023

@penalosa is there a docs PR to link in the description for this PR?

@penalosa penalosa merged commit 89d78c0 into main Jan 23, 2023
@penalosa penalosa deleted the penalosa/json-config branch January 23, 2023 21:37
@github-actions github-actions bot mentioned this pull request Jan 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

🚀 Feature Request: wrangler.json support
6 participants