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

Turn on wrangler.json(c) support by default #7230

Merged
merged 23 commits into from
Nov 22, 2024
Merged

Conversation

penalosa
Copy link
Contributor

@penalosa penalosa commented Nov 11, 2024

Fixes DEVX-1466

Turn on the --experimental-json-config flag by default, enabling reading of wrangler.json & wrangler.jsonc config files. It can still be disabled by setting --experimental-json-config=false. Since it's on by default, this also unblocks support for Pages (pending release of this PR & bumping of Wrangler in the build image)

This PR only enables it in Wrangler. Follow up PRs will adjust the documentation to call out this support properly as well as updating C3.


  • Tests
    • TODO (before merge)
    • Tests included
    • Tests not necessary because:
  • E2E Tests CI Job required? (Use "e2e" label or ask maintainer to run separately)
    • I don't know
    • Required
    • Not required because:
  • Public documentation

@penalosa penalosa requested review from a team as code owners November 11, 2024 17:57
Copy link

changeset-bot bot commented Nov 11, 2024

🦋 Changeset detected

Latest commit: 174a555

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

This PR includes changesets to release 2 packages
Name Type
wrangler Minor
@cloudflare/vitest-pool-workers 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

Copy link
Contributor

github-actions bot commented Nov 11, 2024

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/11975603642/npm-package-wrangler-7230

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

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

Or you can use npx with this latest build directly:

npx https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/11975603642/npm-package-wrangler-7230 dev path/to/script.js
Additional artifacts:
npx https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/11975603642/npm-package-create-cloudflare-7230 --no-auto-update
npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/11975603642/npm-package-cloudflare-kv-asset-handler-7230
npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/11975603642/npm-package-miniflare-7230
npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/11975603642/npm-package-cloudflare-pages-shared-7230
npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/11975603642/npm-package-cloudflare-vitest-pool-workers-7230
npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/11975603642/npm-package-cloudflare-workers-editor-shared-7230
npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/11975603642/npm-package-cloudflare-workers-shared-7230
npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/11975603642/npm-package-cloudflare-workflows-shared-7230

Note that these links will no longer work once the GitHub Actions artifact expires.


[email protected] includes the following runtime dependencies:

Package Constraint Resolved
miniflare workspace:* 3.20241106.1
workerd 1.20241106.1 1.20241106.1
workerd --version 1.20241106.1 2024-11-06

Please ensure constraints are pinned, and miniflare/workerd minor versions match.

Copy link
Contributor

@petebacondarwin petebacondarwin left a comment

Choose a reason for hiding this comment

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

Ran out of time so dumping my comments so far.

.changeset/brave-paws-build.md Outdated Show resolved Hide resolved
\`\`\`
\`\`\`
[[migrations]]
tag = \\"v1\\"
Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm, this change seems a bit out of place for this PR.

Or you could pass it in your terminal as \`--compatibility-date XXXX-XX-XX\`
See https://developers.cloudflare.com/workers/platform/compatibility-dates for more information."
`);
"A compatibility_date is required when publishing. Add the following to your wrangler.toml file:.
Copy link
Contributor

Choose a reason for hiding this comment

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

Given the snippet below is now JSON I think this needs to be wrangler.json.

- In wrangler.toml, you have configured [durable_objects] exported by this Worker (SomeClass),
but no [migrations] for them. This may not work as expected until you add a [migrations] section
to your wrangler.toml. Add this configuration to your wrangler.toml:
- In wrangler.toml, you have configured [durable_objects] exported by this Worker (SomeClass),
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need to change these messages to accommodate the actual format of the config file in use?

packages/wrangler/src/__tests__/kv.test.ts Outdated Show resolved Hide resolved
export type Config = ConfigFields<DevConfig> & PagesConfigFields & Environment;
export type Config = ConfigFields<DevConfig> &
PagesConfigFields &
Environment & { parsedFormat?: "jsonc" | "toml" };
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not keen on adding extra stuff inline here.
I note that there is already a precedent in that configPath is part of ConfigFields but is not something we can read from the wrangler.toml/json directly (despite appearing in RawConfig).

I think the most accurate way to do this is to create a new ConfigInfo type, which contains configPath and parsedFormat (perhaps configFormat?).
Then include this in the Config type (and not in the ConfigFields type) wyich will avoid it appearing in the RawConfig type.

experimentalJsonConfig?: boolean | undefined;
};
export function formatConfigSnippet(
config: RawEnvironment,
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we call this something like snippet to avoid the reader from thinking that we are passing in the current Wrangler configuration here?

export function formatConfigSnippet(
config: RawEnvironment,
parsedFormat: Config["parsedFormat"],
spacing = true
Copy link
Contributor

Choose a reason for hiding this comment

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

BIKESHED: formatted or pretty or something?

Copy link
Contributor

@petebacondarwin petebacondarwin left a comment

Choose a reason for hiding this comment

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

I love where this is going but the more I read through the changes the more I questioned whether we need a parseFormat property on config.
We have the configPath property already, and it would be simple to provide a helper function like:

function configFormat(configPath: string|undefined): "json"|"toml"|"none" { ... }

This means not having to thread this extra parameter around alongside the configPath.
Moreover, as you can guess from the signature of the helper function above, there is the scenario where the user has not provided a config file at all, which we need to support. In that case, snippet messaging might be more along the lines of "Create a wrangler.json with this content".

@@ -73,7 +73,8 @@ export function isPagesConfig(rawConfig: RawConfig): boolean {
export function normalizeAndValidateConfig(
rawConfig: RawConfig,
configPath: string | undefined,
args: NormalizeAndValidateConfigArgs
args: NormalizeAndValidateConfigArgs,
parsedFormat: Config["parsedFormat"] = "toml"
Copy link
Contributor

Choose a reason for hiding this comment

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

This function is internal, so there is no value in making this field optional, IMO. It is better to constrain all usage to provide this. That also helps to ensure we have considered every usage.

Also since this and configPath are similar properties (in their usage) I would propose to group this new param as the third one ahead of args.

packages/wrangler/src/config/validation.ts Outdated Show resolved Hide resolved
packages/wrangler/src/config/validation.ts Outdated Show resolved Hide resolved
Copy link
Contributor

@petebacondarwin petebacondarwin left a comment

Choose a reason for hiding this comment

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

Love it!
There may be some instances missing but I didn't find any.
Ship it!

packages/wrangler/README.md Outdated Show resolved Hide resolved
) {
fs.writeFileSync(
path,
formatConfigSnippet(
Copy link
Contributor

Choose a reason for hiding this comment

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

sneaky!

@penalosa penalosa added the e2e Run e2e tests on a PR label Nov 21, 2024
@penalosa penalosa merged commit 6fe9533 into main Nov 22, 2024
32 checks passed
@penalosa penalosa deleted the penalosa/json-no-flag branch November 22, 2024 17:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
e2e Run e2e tests on a PR
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

3 participants