Skip to content

fix(cli): pass SUPABASE_TYPEGEN, HOME and XDG_CACHE_HOME to the Swift typegen driver - #7608

Draft
grdsdev wants to merge 2 commits into
developfrom
guilhermesouza/cli-3134-gen-types-lang-swift-the-swift
Draft

grdsdev wants to merge 2 commits into
developfrom
guilhermesouza/cli-3134-gen-types-lang-swift-the-swift

Conversation

@grdsdev

@grdsdev grdsdev commented Nov 12, 2026 •

Copy link
Copy Markdown

Summary

supabase gen types --lang swift gives the Swift driver from @supabase/typegen a filtered environment. The driver reads SUPABASE_TYPEGEN, XDG_CACHE_HOME and HOME from that environment to find the supabase-typegen binary and its release cache. The generator layer passed only PATH, PATHEXT and ComSpec, so:

  • SUPABASE_TYPEGEN had no effect, but the CLI's own error message tells users to set it.
  • The cache path became relative (Library/Caches/supabase/typegen/<version>/ on macOS, .cache/... on Linux). It resolved against the working directory, so the downloaded 23 MB binary landed inside the user's project, and ~/Library/Caches was never read.

This PR adds the three variables to lookupEnv. SIDE_EFFECTS.md already documents them. It also lists SUPABASE_TYPEGEN in CLI_NON_CONFIG_ENV_NAMES, so the registry test accounts for it. Other languages do not change: the spawned tool already inherits the full environment, and the Dart driver reads nothing from this object.

How this fits the supabase-swift v3 alpha

For the alpha, the Swift driver will stop downloading the prebuilt binary. It will build supabase-typegen from source, at the supabase-swift commit pinned in the app's Package.resolved, and cache it by commit (SDK-3043, a separate change in @supabase/typegen). The resolution order becomes SUPABASE_TYPEGEN, then the source build, then PATH.

This PR is still needed for that design, and it lands first:

  • SUPABASE_TYPEGEN stays the first step.
  • The source build caches under XDG_CACHE_HOME or HOME. Without this fix, the cache path is relative, and the build output would land inside the user's project.

The download path that this PR also fixes stays in CLI 3.1.0 until the driver change ships.

Linked issue

Linear: CLI-3134

  • The linked issue is open and carries the open-for-contribution label (or I'm a Supabase maintainer).

How it was tested

  • New integration tests in types.generator.integration.test.ts, with a fake supabase-typegen. They cover three cases: SUPABASE_TYPEGEN, a cached release binary under XDG_CACHE_HOME, and one under HOME. All three failed before the fix and pass after it. The two cache tests skip on platforms that have no Swift release asset.
  • test:integration and test:unit for src/commands/gen/types/ pass (176 and 34 tests).
  • End to end, with a CLI binary built from this branch (bun scripts/build-binary.ts), a Postgres 17 container, and a real supabase-typegen from supabase-swift:
    • With SUPABASE_TYPEGEN=<binary> and nothing on PATH, CLI 3.1.0 fails with GenTypesToolNotInstalledError. This branch generates the Swift file.
    • In a project whose Package.resolved pins supabase-swift 3.0.0-alpha.1, with the binary in ~/Library/Caches/supabase/typegen/3.0.0-alpha.1/: CLI 3.1.0 does not find it, and this branch uses it. No files are written to the project.
    • Not covered: a real download. The first release with the asset (v3.0.0-alpha.1) is not published yet. The download writes to the same path the cache test reads. After SDK-3043, the alpha does not download at all.

Checklist

  • The PR title follows Conventional Commits (e.g. fix(cli): …).
  • Tests added or updated for the change.
  • From the repository root, pnpm check:all passes; relevant package tests pass for every touched workspace, and pnpm types:check passes for each touched TypeScript workspace (or workspace declaring it). Locally, types:check, lint:check, fmt:check and knip:check pass. lint:actions:check did not run, because jactionlint is not installed, and this PR changes no workflow.

Why now

supabase-swift v3 launches as Public Alpha on 2026-12-11. Its demo flow is supabase gen types --lang swift. A CLI release with this fix and the SDK-3043 driver change must ship before that date.

… typegen driver

The Swift driver reads these variables from the host environment to find the
supabase-typegen binary and its release cache. The generator layer passed
only PATH, PATHEXT and ComSpec, so SUPABASE_TYPEGEN had no effect and the
cache path resolved relative to the working directory, which put the
downloaded binary inside the user's project.

Closes CLI-3134
@grdsdev
grdsdev requested a review from a team as a code owner November 12, 2026 23:00
@grdsdev
grdsdev requested a review from avallete November 12, 2026 23:00

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🤖 AI Review

Both independent reviews reported no findings. Reading the changed code confirmed that the three environment variables reach the typegen host, matching the existing documented Swift behavior. The new tests cover the explicit binary override and both cache locations. No conflict with pending next-branch work was identified. Tests were not run because dependencies are absent from the checkout.

Findings

No issues found.

Stats

Claude findings: 0 · Codex findings: 0 · Confirmed: 0 · Refuted: 0 · Uncertain: 0


Models: claude-opus-5-5 + gpt-6.1-sol · Trigger: auto · Workflow run

This review runs once per PR. A maintainer can request another with a /ai-review comment.

@github-actions

Copy link
Copy Markdown
Contributor

CLI benchmark (Lightweight Commands): no changes found

Commit cb8d5f8 against develop at d8f66a0 · 10 runs each · report only, never blocks merging

Command Workload Before After Change
supabase --version version 309 ms 315 ms no real change
supabase --help help 325 ms 303 ms no real change (-7%, within normal variation)
supabase init init 300 ms 325 ms no real change (+8%, within normal variation)
supabase migration new bench migration-new 297 ms 328 ms no real change (+10%, within normal variation)
supabase config convert config-convert 278 ms 277 ms no real change
supabase gen types --lang typescript --project-id replayfixtureprojref gen-types 251 ms 268 ms no real change (+6%, within normal variation)
supabase projects list projects-list 230 ms 228 ms no real change
supabase functions list --project-ref replayfixtureprojref functions-list 258 ms 270 ms no real change

API calls: unchanged for all 8 commands.

Binary size: 134.8 MB, unchanged.

Details: timing ranges, API calls per command, slowest phases

Timing ranges

Command Workload Before range After range Change Verdict
supabase --version version 237-336 ms 240-369 ms +6 ms (+2%) within noise
supabase --help help 280-407 ms 266-356 ms -22 ms (-7%) within noise
supabase init init 272-398 ms 270-420 ms +25 ms (+8%) within noise
supabase migration new bench migration-new 263-353 ms 267-392 ms +31 ms (+10%) within noise
supabase config convert config-convert 226-323 ms 209-310 ms -1 ms (0%) within noise
supabase gen types --lang typescript --project-id replayfixtureprojref gen-types 227-333 ms 222-356 ms +16 ms (+6%) within noise
supabase projects list projects-list 185-260 ms 214-273 ms -2 ms (-1%) within noise
supabase functions list --project-ref replayfixtureprojref functions-list 239-295 ms 217-289 ms +12 ms (+5%) within noise

API calls per command

Command Workload Before After Endpoint changes
supabase --version version 0 0
supabase --help help 0 0
supabase init init 0 0
supabase migration new bench migration-new 0 0
supabase config convert config-convert 0 0
supabase gen types --lang typescript --project-id replayfixtureprojref gen-types 2 2
supabase projects list projects-list 1 1
supabase functions list --project-ref replayfixtureprojref functions-list 2 2

Slowest phases

No command moved beyond noise, so there are no phase deltas.

Workflow run

Comment /bench to run the lightweight benchmark (this comment) again on the latest commit, or /bench full to also run the integration-heavy benchmark, which posts in its own comment.

@grdsdev
grdsdev marked this pull request as draft November 12, 2026 23:53

This branch has not been deployed

No deployments
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.

1 participant