Skip to content

Skip reading the compliance region from the config file when it is set in the environment - #372

Open
jamesopstad wants to merge 1 commit into
mainfrom
james/fix-api-config-loading
Open

jamesopstad wants to merge 1 commit into
mainfrom
james/fix-api-config-loading

Conversation

@jamesopstad

Copy link
Copy Markdown
Contributor

Fixes #207

Skip reading the compliance region from the config file when it is set in the environment

Resolve CLOUDFLARE_COMPLIANCE_REGION before project settings, matching the existing account ID priority. Commands with both CLOUDFLARE_ACCOUNT_ID and CLOUDFLARE_COMPLIANCE_REGION no longer evaluate a cloudflare.config.ts file solely to establish API context.

@ask-bonk

ask-bonk Bot commented Oct 20, 2026

Copy link
Copy Markdown
Contributor

LGTM

github run

@pkg-pr-new

pkg-pr-new Bot commented Oct 20, 2026

Copy link
Copy Markdown
npm i https://pkg.pr.new/cf@372

commit: ab2d3cc

@github-actions

Copy link
Copy Markdown
Contributor

cf --help startup

mean stddev min max
PR 277.3 ms 4.8 ms 269.8 ms 284.3 ms
base 278.5 ms 6.0 ms 269.5 ms 291.5 ms

Δ (PR vs base): ↓ -1.2 ms (-0.4%)

Measured with hyperfine on ubuntu-latest (3 warmup runs, 20 timed runs). CI numbers carry ±a few ms of runner jitter; treat small deltas as noise.

@jamesopstad
jamesopstad marked this pull request as ready for review October 20, 2026 14:41
@clanky-the-clanker

Copy link
Copy Markdown

✅ Approved — No issues found. resolveComplianceRegion now reads CLOUDFLARE_COMPLIANCE_REGION before project settings, the same order account ID resolution already uses, and the new end-to-end test confirms that cloudflare.config.ts is not evaluated when both environment variables are set.

The decision is advisory: this comment never approves, blocks or requests changes on the pull request.


✅ All checks passed

🚀 Release: ✅ LGTM

Risk: Low. .changeset/skip-api-project-config.md uses a patch bump, which fits a bug fix under the repository's changeset rules.


🔒 Security: ✅ LGTM

No security concerns. The compliance region from the environment still goes through normalizeComplianceRegion, so invalid values are still rejected.


📖 AGENTS.md: ✅ LGTM

The existing guidance already says the compliance region resolves from its environment variable before project settings. This change matches that and needs no guidance update.


📋 Code Quality: ✅ LGTM

I found no problems in this change.

  • New order: resolveComplianceRegion in packages/cli/src/lib/context.ts now checks CLOUDFLARE_COMPLIANCE_REGION first and returns before touching project settings. When the variable is unset, it still falls back to getLoadedProjectSettings / loadProjectSettings. This is the same order resolveAccountId uses for CLOUDFLARE_ACCOUNT_ID, and it matches the resolution order described in the repository's guidance.
  • Removed warning: the complianceRegionConflictsReported flag and the "takes precedence" warning are gone, and nothing else references them. A conflicting or invalid complianceRegion in cloudflare.config.ts is no longer reported when the environment variable is set. That follows from not loading the config file at all, and the changeset describes it.
  • Tests:
    • context.test.ts covers the new priority with a config file that throws when loaded.
    • api-config-loading.test.ts runs a real command end to end with a config that imports a missing package, so it would fail if the config were evaluated.

⚡ Performance: ✅ LGTM

This change removes work. When the region comes from the environment, the function returns early and cloudflare.config.ts is never loaded, which saves evaluating a TypeScript module for API commands. No regressions.


📝 Documentation: ✅ LGTM

The changeset clearly describes the new priority and its effect.


Reviewed commit: ab2d3ccc

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.

API commands fail when ./cloudflare.config.ts cannot load, even with CLOUDFLARE_ACCOUNT_ID and CLOUDFLARE_COMPLIANCE_REGION set

1 participant