This repository has been archived by the owner on Aug 3, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 337
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Don't require an account_id in wrangler.toml (#1966)
* Switch from lazy_static to once_cell `OnceCell` is needed later, and this avoids having two dependencies that do the same thing. Wrangler has dependencies that use both, so this doesn't actually reduce compile times, but it will make it clear which library to use. * Use the None variant of `RouteId::account_id` Previously, it was always `Some` and the empty string was used to see if it wasn't filled out. This removes unnecessary checking for the empty string. * Use an Option for account_id This makes it explicit where the account ID is required and where it's treated as the empty string. * Introduce LazyAccountId This collects all handling of the account_id in one place, so that errors no longer have to be handled at each call-site. Making this a new type, rather than a function on `Manifest`, allows it to be used for other types as well, such as `Target`. Using a `OnceCell` rather than an `Option` has two benefits: 1. It does not allow setting the account twice, which would be a bug. 2. It allows setting the account with only an immutable reference, which reduces the amount of churn in calling functions. Note that this still deserializes the empty string as not having an `account_id` for backwards compatibility. * Handle multiple accounts * Load account lazily in Target too This avoid the following test failure: ``` it_builds_with_webpack_target_webworker_with_custom_file stdout ---- Created fixture at /tmp/.tmpSzLIJb thread 'it_builds_with_webpack_target_webworker_with_custom_file' panicked at 'Build failed: Output { status: ExitStatus(ExitStatus(256)), stdout: "👀 You have multiple accounts.\nPlease choose one from below and add it to `wrangler.toml` under `account_id`.\n🕵\u{fe0f} You can copy your account_id below\n+--------------------------+----------------------------------+\n| Account Name | Account ID |\n+--------------------------+----------------------------------+\n| Cloudflare Community Jam | 6174b0f52802f24a9f52e7015282898c |\n+--------------------------+----------------------------------+\n| Edge Workers | 615f1f0479e7014f0bebcd10d379f10e |\n+--------------------------+----------------------------------+\n", stderr: "Error: \n" }', tests/build.rs:377:5 ``` It also prevents any similar issues that aren't tested, by forcing each command that wants an account ID to load it explicitly. * Fix previews Previews have different behavior when an account is available than when it isn't. This restores that previous behavior: if an account is available, use authenticated previews, otherwise unauthenticated previews. Note that "an account is available" has become a slightly tricky question, since it's no longer guaranteed that it will be in the wrangler.toml. Instead, this checks if it is either in the .toml or if there is only a single account available to the authentication token. * Use `maybe_load` instead of `if_present` for `load_project_info` This only affects `wrangler report`. The old behavior preserved the behavior from before, but was less helpful because it wouldn't include the ID if there was only a single ID for the account token. * Remove unneeded `validate` function It no longer does anything now that the account ID is loaded on demand. * Don't tell the user to add `account_id` after running `wrangler generate` Before, wrangler would give this message: ``` > wrangler generate Creating project called `worker`... Done! New project created /home/jnelson/src/test-project/worker/worker 🕵️ You can find your zone_id in the right sidebar of a zone's overview tab at https://dash.cloudflare.com 🕵️ You can copy your account_id below +----------------------------+----------------------------------+ | Account Name | Account ID | +----------------------------+----------------------------------+ | Jyn514@gmail.com's Account | e1706d218241c1230155b4f91b3218af | +----------------------------+----------------------------------+ 🕵️ You will need to update the following fields in the created wrangler.toml file before continuing: - account_id ``` Adding the account ID is no longer necessary, so don't suggest adding it.
- Loading branch information
Showing
34 changed files
with
173 additions
and
152 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.