Conversation
|
|
|
||
| const accounts = await fetchAllAccounts(config); | ||
| if (accounts.length === 1) { | ||
| saveAccountToCache({ id: accounts[0].id, name: accounts[0].name }); |
There was a problem hiding this comment.
Note that the env var value was saved to cache before.
I assume that is only because the code was convoluted. Adding comment on the previous line:
// vicb: here we have !getCloudflareAccountIdFromEnv because it has
// higher priority but was handled in getAccountChoices
if (cachedAccount && !getCloudflareAccountIdFromEnv()) {
return cachedAccount.id;
}
// vicb: this is now fetchAllAccounts that only fetches
// env var handling has been extracted out
const accounts = await getAccountChoices(config);There was a problem hiding this comment.
That turned out to be an happy bug - the only reason why tests in packages/wrangler/src/__tests__/containers/push.test.ts were passing is because the value was cache 🥳
Added a fixup commit properly calling mockAccountId() to fix that
create-cloudflare
@cloudflare/kv-asset-handler
miniflare
@cloudflare/pages-shared
@cloudflare/unenv-preset
@cloudflare/vite-plugin
@cloudflare/vitest-pool-workers
@cloudflare/workers-editor-shared
@cloudflare/workers-utils
wrangler
commit: |
Minor refactoring of the account handling before landing active account.
Coded together with OCOpus
Objective
Improve naming, separation of concerns, and consistency for the account resolution functions.
getAccountChoices→fetchAllAccounts, rename filechoose-account.ts→fetch-accounts.ts, and extract theCLOUDFLARE_ACCOUNT_IDenv var handling out to the callergetActiveAccountId()— a synchronous, side-effect-free function for quiet account resolutiongetAccountId→getOrSelectAccountId, refactored to usegetActiveAccountIdthenfetchAllAccountssecrets-store/commands.ts— replacegetAccountIdwithrequireAuth(missing login check)pages/projects.ts— remove redundantgetCloudflareAccountIdFromEnv()prefixcontainers/deploy.ts— remove redundantconfig.account_id ||guardA picture of a cute animal (not mandatory, but encouraged)