Skip to content

feat: generate TypeScript modules in the SDK - #39

Merged
TomChv merged 1 commit into
mainfrom
feat/module-codegen-in-sdk
Sep 1, 2026
Merged

TomChv merged 1 commit into
mainfrom
feat/module-codegen-in-sdk

Conversation

@TomChv

@TomChv TomChv commented Aug 28, 2026 •

Copy link
Copy Markdown
Member

Replaces the #18 → #34 stack with a single PR. Rebased onto main after #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, and
the 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.toml module the runtime does no codegen at call time, so
whatever generate writes is what executes, and it has to satisfy an unchanged
runtime byte for byte.

Piece
library/ dagger/dagger's sdk/typescript at v1.0.0-beta.11, vendored, with VENDOR.md recording the source commit, the deliberate omissions, the exhaustive local-delta list and the re-import procedure
.dagger/modules/packager Builds bundle/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 network
helpers/codegen module, entrypoint and library modes alongside client
helpers/config-updator The module config the runtime reads
Mod.generate Local path for dagger-module.toml, engine for dagger.json; both stage the dependency closure and both take it back out of the changeset
targetEngineVersion Stated once; the runtime harness and every fixture read from it, and a check fails when they disagree

On 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/typescript changed exactly one vendored file between the two tags
(provisioning/default.ts, the CLI pin); the schema change shows up in the
regenerated bindings.

Module generation also adopts #37's conclusion: withoutModuleBindings is gone,
the mirror of the withoutClientBindings deletion. Pruning the baseline is
enough now that withNewDirectory means the same thing on both workspace kinds,
so the double prune was dead weight.

One footgun found and written into VENDOR.md: dagger generate packager runs
both 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 check and 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 also
needs a rebase onto #37.

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
TomChv force-pushed the feat/module-codegen-in-sdk branch from aaa5410 to 109bf76 Compare August 28, 2026 14:59
@TomChv
TomChv merged commit 6604ecb into main Sep 1, 2026
75 checks passed
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