Skip to content

feat(zerogen): move the Swift generator into a zerogen package - #122

Merged
tmm merged 1 commit into
mainfrom
zerogen
Nov 10, 2026
Merged

tmm merged 1 commit into
mainfrom
zerogen

Conversation

@tmm

@tmm tmm commented Nov 10, 2026 •

Copy link
Copy Markdown
Member

Moves the Swift code generator out of packages/zero-swift-cli into a new npm package, zerogen (packages/zerogen), with its own semver. Rust comes later.

zerogen

  • zerogen codegen generates every target in zerogen.json, or the one --target swift|rust names. Only Swift is implemented. --target rust, a rust entry in the config, or no target at all fail with UNSUPPORTED_TARGET / NO_TARGETS before anything is written.
  • zerogen drift record is the same target-independent recorder as before.
  • Shared, in cli.ts / types.ts / drift.ts: schema loading, the type model, the incur commands, output and --check, and the drift recorder. Per language, in targets/swift.ts: naming, escaping, SDK and type mappings, and the Swift options (--schema-name, --zql, --type-prefix, --access). generate.ts moved there unchanged apart from taking its options.
  • zerogen.json has the shared schema and export, and targets.swift takes the rest of zero-swift.json's keys.

zero-swift stays published and is not deprecated. It's now a 5-line wrapper over zerogen/compat, and depends on zerogen with workspace:*, which pnpm pack turns into the exact version. Its config, legacy flags (--schema <path>, --typePrefix=…), results, and output don't change, and the generated banner still says zero-swift codegen.

Releases. swift-release.yml versions and publishes zerogen alongside the Swift client:

  • It publishes zerogen before zero-swift, in the same approved swift-release job. If zerogen fails to publish, zero-swift isn't published.
  • Before publishing, it smoke-tests the packed tarballs and checks that the packed zero-swift depends on exactly the zerogen being released.
  • A version counts as unpublished only on a registry 404. zero-swift's old npm view check counted any error that way.
  • Nothing is published by merging this: the changesets go into the Version Packages PR first.

Verified

Check Result
pnpm --filter zerogen --filter zero-swift test 2 + 29 passed. These include the byte-for-byte fixture and zbugs checks against the checked-in Swift and drift-vectors.json, and the Swift compile sweep (Swift 6.2.4, Linux).
Parity with zero-swift@0.7.9 from npm vs. the new packed tarballs, both on @rocicorp/zero@1.11.0 31 cases identical in stdout, stderr and exit code, and 5 generated files identical. Cases cover --help, codegen --help, --llms, bare --schema, legacy and kebab flags, --json, --check (fresh and stale), every error code, drift record and its --check, and --target (still rejected by the wrapper).
pnpm --filter zerogen smoke Passed: installs both tarballs outside the workspace and runs both CLIs.
check-types (zero-conformance, zerogen, zero-swift), syncpack lint, oxlint, oxfmt Clean.
actionlint 1.7.7 with ShellCheck Only a pre-existing SC2016 info that main also reports.
Plan script vs. the live npm registry and mirror With zero-swift already on npm: npm=false, zerogen-npm=true, mirror=false. With an unreleased zero-swift and zerogen 0.1.0: all true.
Changesets dry run (rebased onto 0.7.10) zerogen 0.0.0→0.1.0 and zero-swift 0.7.10→0.7.11 (swift/VERSION too).
pnpm install --frozen-lockfile Passes, and leaves pnpm-lock.yaml byte-identical. The lockfile was edited by hand, with workspace links only.

Before releasing (tmm)

  1. Set up npm for zerogen before merging the Version Packages PR. npm only adds a trusted publisher to a package that exists, so the first zerogen version has to be published by hand. The publisher to add is this repo, swift-release.yml, environment swift-release, allowed to npm publish. Until then the "Publish zerogen" step fails and blocks zero-swift; the Swift mirror release still goes out. zerogen was unclaimed on npm (404) when this PR was opened.
  2. Every zerogen release also bumps zero-swift by a patch, and with it swift/VERSION, so the Swift mirror is released too. Changesets reads workspace:* as the exact old version; a dry run confirmed that a zerogen-only patch also bumps zero-swift by a patch. Splitting the wrapper's version from swift/VERSION would avoid this, but that's a separate change.

Not run locally: the full swift/ and zbugs swift test suites and macOS CI. No Swift sources, generated Swift, or vectors change; CI runs them.

Started in a thread that stopped on a model usage limit (https://ampcode.com/threads/T-98d49fb9-9997-4a89-ae8f-8810e2d2175d) and finished here.

The code generator is now the npm package zerogen (packages/zerogen),
with its own version, so other targets can be added next to Swift.
`zerogen codegen` generates every target in zerogen.json, or the one
`--target` names. Only Swift is implemented: `--target rust`, or a rust
entry in the config, fails before anything is written. `zerogen drift
record` records the same vectors as before. Schema loading, the type
model, the commands, output and `--check`, and the drift recorder are
shared; Swift's naming, escaping, SDK and type mappings, and options are
in targets/swift.ts.

zero-swift stays published and supported. It depends on the exact
zerogen version and keeps its config, flags, and output: next to
zero-swift 0.7.9 from npm, 31 runs of its help, flags, results, and
errors print the same and write the same files. The checked-in generated
Swift and drift vectors are unchanged.

The release workflow publishes zerogen before zero-swift, after the same
approval, and checks that the packed zero-swift depends on the zerogen
being released. A version only counts as unpublished when npm says it
doesn't exist. CI installs the packed packages outside the workspace and
runs both CLIs. Every zerogen release also bumps zero-swift by a patch,
since Changesets reads `workspace:*` as the exact version.

Co-authored-by: tmm <tmm@tmm.dev>
Amp-Thread-ID: https://ampcode.com/threads/T-25ebc75a-8a01-4e52-bb02-ea048d34e417
@tmm
tmm merged commit b96f6d1 into main Nov 10, 2026
22 of 23 checks passed
@tmm
tmm deleted the zerogen branch November 10, 2026 20:44
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.

2 participants