Repository navigation
fix: an embedded module's clients ship inside sdk/ - #60
Merged
Merged
Conversation
A [runtime] module's clients landed in clients/, loose files reached by tsconfig alias — but sdk/ is the one directory the engine's builtin runtime mounts into node_modules, and it cannot be told to mount anything else, so the clients only resolved where the JS runtime happened to honour the alias. The packaged clients/ layout needs the entrypoint path, whose generated recipe installs whatever the module declares; the embedded path gets no such hook. The layouts now branch on the loading path: - entrypoint: unchanged — clients/ of self-contained npm packages, wired through package.json. - embedded [runtime]: every client file and the loader ship flat inside sdk/, beside client.gen.ts. `codegen module` grows --flat-clients for that shape, the legacy __dagger.entrypoint.ts imports ./sdk/loader.gen.js (the --loader-import knob returns for it), the tsconfig aliases point into sdk/, and a clients/ directory an earlier generation left is taken with the move. Verified on a repro carrying one module of each kind: regeneration migrates the embedded module's clients into sdk/ and leaves the entrypoint module byte-quiet, both modules run — including a call through the migrated hello client — and regeneration is byte-quiet after the move. The full e2e suite passes with the embedded checks pointed at the new location. Signed-off-by: Tom Chauveau <[email protected]>
TomChv
force-pushed
the
fix/runtime-clients-in-sdk
branch
from
September 17, 2026 23:41
f31df5d to
5d8b7fe
Compare
Loading a [runtime] module executes its TypeScript, and the self client only renders in the second pass. Staging the first pass used to strip every existing binding, so a module whose source imports its own client could not load: the import dangled, the load was rescued into an empty self set, the second pass never ran, and the prune then deleted the very file the source needs. Uncommenting a self-call erased sdk/<self>.gen.ts on the next generate. Keep the previous generation's bindings in the staged tree — a stale unimported binding is inert at load time, while its absence is what made the module unloadable. And only prune stale bindings when the module actually loaded (an empty self set on an embedded module means it did not), so a failed load degrades to a partial regeneration instead of eating user-visible files. The by-path repair in mod.dang never runs a second pass, so it never prunes. Signed-off-by: Tom Chauveau <[email protected]>
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.
Follow-up to #54.
Problem
A module created without
--entrypointgot the sameclients/directory as an entrypoint module — loose files reached by tsconfig alias. Butsdk/is the one directory the engine's builtin[runtime]runtime mounts intonode_modules, and it cannot be told to mount anything else; the clients only resolved where the JS runtime happened to honour the alias mechanics. The packagedclients/layout depends on the entrypoint path, whose generated recipe installs whatever the module declares — the embedded path has no such hook.Fix
The layouts branch on the loading path:
--entrypoint— unchanged:clients/of self-contained npm packages, wired throughpackage.json.--entrypoint— every client file and the loader ship flat insidesdk/, besideclient.gen.ts, so the runtime's single mount carries them by construction:codegen module --flat-clientsemits that shape;--loader-importreturns so the legacy__dagger.entrypoint.tsimports./sdk/loader.gen.js.sdk/(@dagger.io/<m>→./sdk/<m>.gen.ts).clients/directory an earlier generation left besidesdk/is taken with the move on regeneration.Fix 2: the self client survived init but not use
Loading a
[runtime]module executes its TypeScript, and the self client only renders in the second generation pass. Staging the first pass used to strip every existing binding, so the moment a module's source actually imported its own client, generation destroyed it: the import dangled in the staged tree, the load failed and was rescued into an empty self set, the second pass never ran, and the stale-binding prune deletedsdk/<self>.gen.ts— the very file the source needs.Now the staged tree keeps the previous generation's bindings (a stale unimported binding is inert at load time; its absence is what made the module unloadable), and the prune only runs when the module actually loaded — a failed load degrades to a partial regeneration instead of eating user-visible files. The by-path repair in
mod.dangnever runs a second pass, so it never prunes.Verified
On a repro workspace carrying one module of each kind: regeneration migrates the embedded module's clients into
sdk/(rename-only diff plus the two pointer updates) and leaves the entrypoint module byte-quiet; both modules run — including a call through the migratedhelloclient on the builtin runtime — and regeneration is byte-quiet after the move. For the self-client fix: uncommenting a function that calls the module through its own client now regenerates cleanly (+7/+7, both the entrypoint andsdk/<self>.gen.tsgain the function), the call runs on the builtin runtime, and a further generate is byte-quiet. The full e2e suite passes, including a new regression check (generate-self-import-survives-check) plus the existing stale-prune check; codegen and config-updater suites green.