Skip to content

feat(typegen)!: pick the supabase-typegen source with swift-typegen-source - #361

Open
grdsdev wants to merge 3 commits into
mainfrom
guilhermesouza/sdk-3045-swift-typegen-source
Open

grdsdev wants to merge 3 commits into
mainfrom
guilhermesouza/sdk-3045-swift-typegen-source

Conversation

@grdsdev

@grdsdev grdsdev commented Nov 13, 2026

Copy link
Copy Markdown
Collaborator

Supersedes #360 (SDK-3043). This branch keeps #360's two commits and adds the SDK-3045 design on top, so the history and the review context stay.

What changes

supabase gen types --lang swift still builds supabase-typegen from source at a supabase-swift commit. This PR changes which commit, and removes the old fallbacks:

  1. New option swift-typegen-source (the CLI will expose it as --swift-typegen-source <version|branch|sha|path>):
    • ./path, ../path, /path, ~/path: build the local checkout in place, in its own .build. No cache, no git. This is for the dev loop where the macros and the emitter change in one supabase-swift PR.
    • 40 hex characters: that commit. Short SHAs are rejected.
    • A semver, with or without v: the tag (v<version>, then <version>), peeled for annotated tags. The --version check applies.
    • Anything else that is a valid branch name: refs/heads/<name>, resolved on every run.
  2. Else the lockfile pin, as in feat(typegen): build supabase-typegen from source at the pinned supabase-swift commit #360, with these changes:
    • Lockfiles without a supabase-swift pin are skipped.
    • If no parent has a pin, it searches 1–2 levels down (monorepos).
    • Conflicting pins fail and ask for the option.
  3. Else the latest 3.x release: the highest stable 3.x, or the highest 3.x prerelease while none is stable. It never crosses the major version, and it prints a notice.

Removed:

  • SUPABASE_TYPEGEN and the PATH fallback. The error hints now point to the option.
  • Windows support. It is now refused with a clear error, because it only ever had the PATH fallback.

Every run prints the commit it uses on stderr.

The provenance rules from #360 stay:

  • A lockfile pin must be upstream's.
  • A full SHA from the option must be on the default branch.
  • A branch or a version resolves through upstream's own refs, so it skips the ancestry check.

Decisions to review

  • Windows is refused. Before this PR, Windows could only use a binary on PATH.
  • A 2.x version from the option fails before any git call.
  • A relative path without ./ is read as a branch. If that branch does not exist and a folder with that name does, the error suggests ./<name>.
  • Local builds skip --disable-automatic-resolution and --static-swift-stdlib. The checkout is the user's own, and it is never cached.
  • The commit is feat(typegen)!, with a BREAKING CHANGE: footer. Under bump-minor-pre-major, this bumps the minor version.

Test evidence

  • bun test in packages/typegen: 123 pass, 0 fail. swift.test.ts has 69 of them.
    • The tests use fake git and swift scripts.
    • They cover each option form, every rejection case, the lockfile walk (parents, Xcode copies, 2 levels down, skipped lockfiles, conflicts) and latest-release selection (prerelease order, no major crossing, stable preferred).
    • They also check that a branch is resolved on every run with cache reuse, that local builds pick up uncommitted changes, and that SUPABASE_TYPEGEN and PATH are ignored.
    • The pure helpers have direct unit tests: parseTypegenSource, parseRefs, compareVersions and latestRelease.
  • check-types, check-types:consumer, format-and-lint and knip are clean.
  • Not verified in this PR: the new paths have not run against a real Swift toolchain or real supabase-swift tags. Only the fakes ran them. The real-build evidence in feat(typegen): build supabase-typegen from source at the pinned supabase-swift commit #360 covers the shared build steps. Before merge, run one real build each for a version, a branch and a local path.

Follow-ups

Fixes SDK-3045

…ase-swift commit

supabase gen types --lang swift now builds supabase-typegen from the
supabase-swift commit in the app's nearest Package.resolved, with the
generator's committed dependency versions and the user's toolchain,
instead of downloading the prebuilt release binary. The binary is cached
per commit. Linux builds link the Swift runtime statically, and the
build steps remove git's repository variables so a git hook cannot
point them at the user's repository.

Fixes SDK-3043
GitHub serves every commit of the fork network through the upstream URL,
pull request heads included, so fetching the pinned SHA alone let a
Package.resolved get a fork's code built and run. A version pin's tag
must now point at the revision, and any other pin's revision must be on
its upstream branch, checked in a commits-only clone before the fetch.

The Package.resolved lookup also skips files the user does not own and
non-regular files, treats malformed JSON as no pin, and rejects a
version or branch that is not a plain value before git or the terminal
sees it.

Refs SDK-3043
…ource

supabase gen types --lang swift now picks the supabase-swift commit it
builds supabase-typegen from in this order: the new swift-typegen-source
option, the supabase-swift pin of the nearest Package.resolved, then the
latest 3.x release with a notice on stderr. Every run prints the commit
it uses.

The option takes a local checkout (./, ../, / or ~/, built in place in
its own .build folder and never cached), a full commit SHA, a version
resolved through its tag, or a branch resolved with git ls-remote on
every run. Abbreviated SHAs, other path forms, versions below 3 and
branch names git could read as an option or a refspec are refused before
git runs.

The lockfile walk skips lockfiles without a supabase-swift pin and, when
no parent has one, looks up to two levels below cwd, failing when those
pins disagree. Without any pin it builds the highest stable 3.x release,
or the highest 3.x prerelease before one exists.

BREAKING CHANGE: SUPABASE_TYPEGEN and the supabase-typegen on PATH are
no longer read; pass a local checkout to --swift-typegen-source instead.
Windows, which only had the PATH fallback, is refused.

Fixes SDK-3045
@coderabbitai

coderabbitai Bot commented Nov 13, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Summary

Summary by CodeRabbit

  • New Features
    • Swift type generation now builds its generator from source. You can choose a version, branch, commit, or local checkout; otherwise, it selects a source from your project’s lockfile or the latest available 3.x release.
  • Changes
    • Swift generation no longer uses PATH binaries or the SUPABASE_TYPEGEN override. Windows is unsupported, and private and package are no longer accepted as Swift access-control options.
  • Documentation
    • Updated guidance covers source selection, build requirements, caching, and errors.

Swift typegen now builds supabase-typegen from a selected supabase-swift source revision instead of downloading a release binary or using PATH and SUPABASE_TYPEGEN overrides. Source selection supports explicit paths, commits, versions, or branches, plus lockfile and release-based defaults. Revision checks, build execution, caching, platform restrictions, and error handling are updated. Tests and documentation cover the source-build flow.

Sequence Diagram(s)

sequenceDiagram
  participant createSwift
  participant resolveBinary
  participant Git
  participant SwiftBuild
  participant Cache
  participant Typegen
  createSwift->>resolveBinary: resolve selected source
  resolveBinary->>Cache: check revision-keyed executable
  resolveBinary->>Git: fetch and verify revision when needed
  resolveBinary->>SwiftBuild: build supabase-typegen
  SwiftBuild-->>resolveBinary: built executable
  resolveBinary->>Cache: store successful revision build
  resolveBinary-->>createSwift: return executable path
  createSwift->>Typegen: generate output
Loading

Possibly related PRs

  • supabase/sdk#360: Adds source builds of supabase-typegen from Package.resolved; this PR changes the source selection and removes the PATH and SUPABASE_TYPEGEN fallbacks.

Change: Feature

Merge Risk: Minimal · up to 2f1e0

Swift typegen now builds from a selected supabase-swift source revision instead of using a downloaded binary, PATH, or SUPABASE_TYPEGEN. No concrete merge-blocking problem was found. The author asks for real builds with a version, a branch and a local path before merge, and that is worth doing. The change is also breaking for callers who relied on SUPABASE_TYPEGEN or a binary on PATH.

- [ ] Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 0cf98c5b-0b8d-4a36-804b-c57faf391187
Commits

Reviewing files that changed from the base of the PR and between 7012fd8 and 2f1e0ec.

Files selected for processing: 8

  • packages/typegen/CLAUDE.md
  • packages/typegen/README.md
  • packages/typegen/src/contract.ts
  • packages/typegen/src/errors.ts
  • packages/typegen/src/languages/external.ts
  • packages/typegen/src/languages/swift.ts
  • packages/typegen/test/languages.test.ts
  • packages/typegen/test/swift.test.ts

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

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