fix: deterministic, portable codegen output#11
Merged
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.tscollected query files viaBun.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--checkre-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>Resultinterfaces were module-local, on the assumption thatQueryResults['Name']is the only access path. That holds for--noEmittype-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 returnsQueryResults['FindPeopleByIds']), TypeScript dereferences the indexed access to the concrete interface and fails withTS4053("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 EdenApptype into other packages and a bundled client). Before: CI's codegen check failed on (1) and a.d.tsbundle step failed on (2). After: type-check, codegen--check, and tests pass on all workspaces.🤖 Generated with Claude Code