Skip to content

fix: deterministic, portable codegen output#11

Merged
ilbertt merged 3 commits into
mainfrom
fix/deterministic-portable-codegen
Jun 25, 2026
Merged

fix: deterministic, portable codegen output#11
ilbertt merged 3 commits into
mainfrom
fix/deterministic-portable-codegen

Conversation

@ilbertt

@ilbertt ilbertt commented Jun 25, 2026

Copy link
Copy Markdown
Owner

Two fixes that make the generated module stable across machines and usable from another package's declaration output. Both surfaced while trialing the package in a real Bun workspace.

1. Deterministic output ordering

generate.ts collected query files via Bun.Glob(...).scanSync(...), which yields filesystem order — that differs between macOS and Linux. Because the registry is emitted in discovery order, the generated module's ordering changed across platforms, so a file generated on macOS and committed would read as stale when --check re-generated it on Linux CI (and vice-versa). Migrations were already .sort()ed; query files now are too.

2. Export the generated result interfaces (TS4053)

The I<Name>Result interfaces were module-local, on the assumption that QueryResults['Name'] is the only access path. That holds for --noEmit type-checking, but breaks under declaration emission: when a consumer re-emits a row type into a .d.ts (e.g. bundling a service whose public method returns QueryResults['FindPeopleByIds']), TypeScript dereferences the indexed access to the concrete interface and fails with TS4053 ("cannot be named") because it isn't exported. Exporting them keeps the underlying name reachable; QueryResults['Name'] remains the intended handle.

Validation

Adopted the package across a 5-workspace Bun monorepo (repositories typed from QueryResults, the row types flowing through an Elysia Eden App type into other packages and a bundled client). Before: CI's codegen check failed on (1) and a .d.ts bundle step failed on (2). After: type-check, codegen --check, and tests pass on all workspaces.

🤖 Generated with Claude Code

ilbertt and others added 3 commits June 25, 2026 10:52
Bun.Glob.scanSync yields filesystem order, which differs between macOS and
Linux. Since the registry is emitted in discovery order, the generated module
churned across platforms and `--check` failed spuriously in CI (Linux) against
output committed from macOS. Sort the matched files, matching the existing
migration ordering.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
… emission

The `I<Name>Result` interfaces were module-local, on the assumption that
`QueryResults['Name']` is the only access path. But when a consumer re-emits a
row type in a declaration file (e.g. bundling a service's public API), TypeScript
dereferences the indexed access to the concrete interface and fails with TS4053
("cannot be named") because it isn't exported. Export them; `QueryResults['Name']`
stays the intended handle.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
The example `queries.gen.d.ts` fixtures are committed and checked with
`--check`; the new `export`ed interfaces (and stable file ordering) made them
stale, failing CI. Regenerate them with the updated generator.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@ilbertt ilbertt merged commit d526a6c into main Jun 25, 2026
5 checks passed
@ilbertt ilbertt deleted the fix/deterministic-portable-codegen branch June 25, 2026 12: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.

1 participant