Repository navigation
feat: generate TypeScript modules in the SDK - #39
Merged
Merged
Conversation
This was referenced Aug 28, 2026
TomChv
force-pushed
the
feat/module-codegen-in-sdk
branch
from
August 28, 2026 14:28
73cc57d to
aaa5410
Compare
A TypeScript module's generated files — `sdk/`, `__dagger.entrypoint.ts`, and the config the runtime reads — were produced by the engine: `dagger generate` called into this SDK, which handed straight back to the engine's built-in TypeScript runtime, which ran `cmd/codegen` and `ts-introspector` in nested sessions. This SDK now produces them itself, the way it already produced clients: schema and module metadata in as plain data, container execs, changeset out, no round trip. Three reasons, the same ones the client move had. The SDK repo should own what the SDK emits, so a codegen fix is not an engine release. The upstream path carries three SDK-lib origins, a Go+TypeScript shared binary, module/client coexistence and per-runtime duplication, nearly all of which is dead on arrival for our narrower contract. And codegen becomes `go test` plus `dagger check` here instead of an engine integration test. Running a module stays with the engine's runtime. That split is the hardest constraint in the design: for a `dagger-module.toml` module the runtime does no codegen at call time, it mounts `sdk/` as `@dagger.io/dagger` and executes the committed entrypoint. Whatever generate writes *is* the artifact that runs, and it has to satisfy an unchanged runtime byte for byte in the parts it reads. **The library.** Generated bindings import their runtime from `./core.js`, a bundle that only existed inside the engine image. `library/` vendors dagger/dagger's `sdk/typescript` at v1.0.0-beta.11 and `.dagger/modules/packager` builds the bundle from it with the same recipe and pinned image the engine uses, committed so that generating a module needs no bun toolchain and no network. A copy has no merge base git can compute, so `library/VENDOR.md` records the one it would have had: source tag and commit, what was deliberately left behind, the exhaustive list of local deltas, and the re-import procedure. **Codegen.** `helpers/codegen` gains `module` (a module's own bindings, split per dependency), `entrypoint` (the static dispatcher, rendered from the introspector's typedef scan) and `library` (the vendored library's own bindings) alongside `client`. `helpers/config-updater` writes the module config the runtime reads. **Routing.** `Mod.generate` takes the local path for `dagger-module.toml` modules and keeps delegating for `dagger.json` ones, which regenerate at call time regardless. Both stage the local dependency closure first — a dependent's schema is only loadable once its deps' generated files exist — and both take that staging back out of the changeset, each in the way its route requires. Regeneration prunes the `*.gen.ts` it owns out of the baseline the generated tree is layered onto. Layering is what keeps the module's own source and config in the changeset, but it can only add, so a dependency dropped from the config would otherwise keep its `<dep>.gen.ts` — an API against a module that is no longer served, which a default tsc rejects. Pruned in one place, matching what different things on different workspace kinds. **Engine pairing.** Everything here is built for one release. The SDK states it once as `targetEngineVersion`; the runtime harness and every fixture read from there, and a check fails when they disagree. **Tests.** Golden tests over the renderers; e2e checks over the generated tree, the routing, dependency edges in both config formats, config preservation and binding pruning; a differential check that generates a fixture through this SDK and through the engine and diffs everything but the bundle; and one fixture per TypeScript runtime that loads a generated module and calls a function on it, which is the only thing that proves the on-disk contract end to end. Replaces the #18 → #34 stack, squashed: several of those PRs overwrote earlier ones, which made the intermediate states hard to reason about and impossible to test independently. Rebased onto #37 (beta.11) and #38 (the interface-return fix and the config-updater rename); the entrypoint golden #38 added is regenerated here, because this generator emits the source maps the engine expects and main's did not. Signed-off-by: Tom Chauveau <[email protected]>
TomChv
force-pushed
the
feat/module-codegen-in-sdk
branch
from
August 28, 2026 14:59
aaa5410 to
109bf76
Compare
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.
Replaces the #18 → #34 stack with a single PR. Rebased onto
mainafter #37.Why squash
The stack had thirteen PRs where several overwrote earlier ones: #22 added a
9 MB compiler blob and deleted it again, #34 re-vendored over choices made in
#21, #27 rewrote the staging model #26 had just introduced. Intermediate states
were hard to reason about, and every push fanned out ~74 checks per PR, so CI
started failing on a different random subset each time and stopped being
readable. One PR, one suite, one answer.
What it does
A TypeScript module's generated files —
sdk/,__dagger.entrypoint.ts, andthe config the runtime reads — were produced by the engine's built-in
TypeScript runtime via nested sessions. This SDK now produces them itself, the
way it already produced clients: plain data in, container execs, changeset out.
Running a module stays with the engine. That split is the binding constraint:
for a
dagger-module.tomlmodule the runtime does no codegen at call time, sowhatever generate writes is what executes, and it has to satisfy an unchanged
runtime byte for byte.
library/sdk/typescriptat v1.0.0-beta.11, vendored, withVENDOR.mdrecording the source commit, the deliberate omissions, the exhaustive local-delta list and the re-import procedure.dagger/modules/packagerbundle/core.js+ declarations + the introspector from those sources, with the compiler the lockfile pins. Committed, so generating a module needs no bun toolchain and no networkhelpers/codegenmodule,entrypointandlibrarymodes alongsideclienthelpers/config-updatorMod.generatedagger-module.toml, engine fordagger.json; both stage the dependency closure and both take it back out of the changesettargetEngineVersionOn top of #37
Rebased onto beta.11, which is more than a version string here — this SDK ships
a library built for one engine release, so the vendored source, its generated
bindings, the committed bundle and every fixture move together. Upstream's
sdk/typescriptchanged exactly one vendored file between the two tags(
provisioning/default.ts, the CLI pin); the schema change shows up in theregenerated bindings.
Module generation also adopts #37's conclusion:
withoutModuleBindingsis gone,the mirror of the
withoutClientBindingsdeletion. Pruning the baseline isenough now that
withNewDirectorymeans the same thing on both workspace kinds,so the double prune was dead weight.
One footgun found and written into
VENDOR.md:dagger generate packagerrunsboth generators against the same input snapshot, so the bundle gets built from
the pre-regeneration bindings. Bindings and bundle have to be two separate runs.
Testing
Golden tests over the renderers. E2E checks over the generated tree, the
routing, dependency edges in both config formats, config preservation and
binding pruning. A differential check that generates a fixture through this SDK
and through the engine and diffs everything but the bundle. One fixture per
TypeScript runtime that loads a generated module and calls a function on it —
the only thing that proves the on-disk contract end to end.
74/74 dagger checkand all Go tests pass locally against v1.0.0-beta.11.Related
#38 is independent and stays separate: it fixes an interface-return bug that
predates this work and renames
config-updator→config-updater. It alsoneeds a rebase onto #37.