Repository navigation
feat: unified clients — one clients/ dir per scope, same installable shape everywhere - #58
Merged
Merged
Conversation
Four design notes captured while iterating on the unified-clients model, in order: - unified-clients-spec.md: the first pass (clientRoot), kept for the record. - unified-clients-take2.md: a client is written where it is declared. - unified-clients-option-c.md: the package manifest is the only link, with the drawbacks decomposed and the user journeys walked. - unified-clients-shared-core.md: one vendored @dagger.io/dagger the whole workspace points at, at .dagger/core/<sdk>, until core is published. Signed-off-by: Tom Chauveau <[email protected]>
The mechanism the unified-clients design hinges on: a scope's package.json is the only link between a consumer and the clients it resolves. shared-deps rewrites the @dagger.io/* namespace the SDK owns to exactly what the scope resolves — the vendored shared core as @dagger.io/dagger, and one @dagger.io/<name> per declared client, each a file: dependency on a path relative to the package. Anything else under @dagger.io/* is pruned, so a client dropped from the scope stops resolving; the user's own dependencies and keys are left untouched. Unit-tested; no engine needed. The Dang and entrypoint-recipe wiring that calls it lands next. Signed-off-by: Tom Chauveau <[email protected]>
First step of the shared-core relocation: an entrypoint module scope now writes the one vendored @dagger.io/dagger — the shipped bundle plus the core bindings — at .dagger/core/<sdk> beside dagger.toml, idempotently (its contents are a function of the engine version alone, so writeChanged keeps regeneration byte-quiet). Written alongside the module's embedded sdk/ for now, so nothing that resolves @dagger.io/dagger changes yet; switching consumers onto it and dropping the embedded copy is the next step. Verified on a repro entrypoint module: generate writes .dagger/core/typescript, regeneration reports no changes, and a call still runs. Signed-off-by: Tom Chauveau <[email protected]>
…sdk/ An entrypoint module no longer carries its own sdk/ library. It resolves @dagger.io/dagger from the one vendored core at .dagger/core/typescript: - the generated container recipe folds the core from there into node_modules (new --core-dir on codegen dang-entrypoint; empty keeps a [runtime] module's embedded-sdk behavior, so the goldens and legacy path are untouched), - the module's tsconfig aliases @dagger.io/dagger at the shared core (config- updater's tsconfig/deno-config gain a CORE_DIR arg, defaulting to ./sdk), - the embedded sdk/ is pruned on the switch. The vendored core is a real @dagger.io/dagger package now — it carries a package.json with exports/main/types, without which a bare import into the folded directory resolves to nothing (a self client importing BaseClient fails at runtime otherwise). The module's own package.json declares no @dagger.io/dagger dependency: the recipe folds the library and the tsconfig aliases it, and a file: dep would only break the recipe's isolated install, which cannot see a path outside the manifest it mounts. The file: link is a consumer's concern, landing on a client-only scope next. Verified on a repro entrypoint module against the manifest-v2 engine: generate writes .dagger/core/typescript and a module with no sdk/, regeneration is byte-quiet, and `call base-image-address` runs. Signed-off-by: Tom Chauveau <[email protected]>
Two corrections toward the spec, both verified on the repro: - package.json is the link, not tsconfig. A shared-core module declares @dagger.io/dagger as a file: dependency and the generated recipe installs it: the install replicates the workspace layout (module manifest at its path, the vendored core at CoreDir) so the module's file: specifier resolves, then runs the detected manager. The manual node_modules fold and the tsconfig-as-resolver are gone; the tsconfig alias stays only for editor resolution before an install. - The self client is opt-in. A module generates a client for itself only when its own path is among the recorded clients (`dagger module client add .`); a module that never calls itself carries no self client. Still on the old per-module format (loose clients/<name>.gen.ts files, loader in clients/) — per-module client packages at modules/<mod>/<name>/ and the client-only scope are next. Signed-off-by: Tom Chauveau <[email protected]>
A client-only scope was writing <scope>/.dagger/clients/{dagger,<m>} — a
directory nested inside a scope whose name already meant "clients", and a
regenerated dagger/ core beside every client. Both are gone.
Now the scope directory IS the client directory: one @dagger.io/<module> package
per client, directly in it, each declaring @dagger.io/dagger as a file:
dependency on the one shared core at .dagger/core/typescript rather than a copy.
The scope's package.json is wired the same way (shared-deps), so `npm install`
in the scope resolves the clients and the shared core; the user's other files
in the scope are left untouched, and only stale generated package dirs are
pruned.
The shared core is now rendered client-facing (the superset a consumer sees)
from the module's own session-version schema, so a client package resolves every
core type it references and an old git dependency never drags core back a
version.
Verified: generate writes .dagger/clients/hello beside a shared core, npm
install + resolve works, regeneration is byte-quiet, and the module still runs.
Signed-off-by: Tom Chauveau <[email protected]>
… at root The last of the shared-core layout: a module's declared clients are no longer loose clients/<name>.gen.ts files resolved by tsconfig alias. Each is an installable package directly under the module — modules/<mod>/<name>/, named @dagger.io/<name>, depending on the shared core by file: path — the same packaging a client-only scope gets. The module's package.json names each as a file: dependency, so `npm install` wires them; the recipe includes the client packages in its install context so those file: specifiers resolve. The entrypoint loader moves to the module root (a new --loader-import on codegen entrypoint points the dispatcher at ./loader.gen.js), so there is no clients/ directory left. An old clients/ dir and the package of a client that has left the module are pruned on the switch. Verified end to end on a repro entrypoint module with a git client: generate writes modules/hello-world/hello as a package beside loader.gen.ts with no clients/ dir, package.json declares @dagger.io/hello and @dagger.io/dagger as file: deps, the dispatcher imports ./loader.gen.js, `call` runs, and regeneration is byte-quiet. The client-only scope and the fresh-module paths still pass. Signed-off-by: Tom Chauveau <[email protected]>
module init failed because the starter-template config still called config-updater tsconfig/deno-config with the old CLIENTS_DIR-only signature, which now reads that argument as CORE_DIR and errors on the missing CLIENTS_DIR. The seed only lays down a placeholder config that generation overwrites, so it passes an empty CORE_DIR (the ./sdk default); the real core path is written by moduleConfigDirectory during generation. Verified: `dagger module init typescript --entrypoint -n test` on a fresh workspace creates a module depending only on @dagger.io/dagger (file: shared core), with no clients/ or sdk/, the loader at the module root, and a call runs. Signed-off-by: Tom Chauveau <[email protected]>
…fig aliases Three issues installing a client (generated in a client-only scope) into a module for a self-call: - The IDE could not resolve @dagger.io/<name>: a client package carried only `exports`, which classic `node` moduleResolution ignores. It now carries `main`/`types` beside `exports`, like the core package, so a bare import resolves under the module's tsconfig. - `dagger generate` stripped the dep. shared-deps pruned every @dagger.io/* dependency not in the module's own recorded clients — clobbering a client the user installed from another scope. It now prunes only the SDK's own generated clients (the `file:./<name>` deps); a dep the user added pointing elsewhere (a `file:../` path or a registry) is left alone. - The module's tsconfig still carried @dagger.io/dagger path aliases. With a shared core, node/bun resolve every @dagger.io/* package through node_modules after an install, so the tsconfig now carries none — a new "-" CORE_DIR sentinel writes no lib alias and removes one an earlier layout left. Deno keeps its import-map entry, since that is its resolver. Verified end to end: a client-only scope generates a `test` client, `npm install` of it into the module resolves under `tsc --moduleResolution node` for both @dagger.io/test and @dagger.io/dagger with no path aliases, `dagger generate` keeps the dep and empties the tsconfig paths, and a call runs. Signed-off-by: Tom Chauveau <[email protected]>
…erywhere The spec's final form: every scope that has clients carries a clients/ directory of self-contained npm packages — one per client, the scope's own @dagger.io/dagger package beside them — and a module scope and a client-only scope generate the identical shape. - A fresh module gets clients/dagger (installed by default: package.json is the resolver, the tsconfig carries no aliases) and clients/<self> (generated by default, wired only when the user opts in — npm install, or `dagger module client add .`, which records the self client and installs it by default). Declared clients land beside them, wired as file:./clients/<name>. - A client-only scope gets the same clients/ tree, its package.json wired to the core and each client. - codegen grows --packaged-clients: each client nests in its own package directory and the loader imports it relatively, so an uninstalled self client still resolves at dispatch time. The loader returns to clients/, beside the packages. - The recipe installs from the manifest plus clients/** — the file: targets ride with the manifest, npm's relative symlinks resolve under the workspace mount, and the CoreDir fold is gone with the workspace-level .dagger/core it served (old copies pruned on regeneration, as are root-level packages and the embedded sdk/ of earlier layouts). - config-updater: shared-deps learns keep-only pairs (?name=rel) and a "-" core for an emptied scope, treats npm's file:x spelling as equivalent to file:./x instead of fighting it, and the second generation pass re-runs the config against the user's original files so a keep-only dep survives the first pass's ignorance of the self client's name. Verified end to end on the manifest-v2 engine: init, self-call via npm install, client add . (against dagger/dagger#14188), a client-only scope consumed with dagger run npx tsx, byte-quiet regeneration throughout, and the Go suites and goldens updated to the new recipe shape. Signed-off-by: Tom Chauveau <[email protected]>
A fresh module carries clients/dagger and nothing else. Its own client exists only once the user records it — `module client add .` — and since the ask is explicit and the SDK owns the module's config, the dep is wired in package.json too; the user runs npm install and calls themselves. `client rm` takes the package and the dep back out. This deletes the keep-only machinery the always-generated self needed: no "?" pairs from the SDK, no self-name diffing between passes, and moduleConfigDirectory wires every generated client the same way. A stale package directory is now swept whole when its files go, rather than leaving an emptied husk (the on-host directory an applied changeset cannot remove is an engine limitation, not ours). Verified on a fresh workspace against the dev engine carrying dagger/dagger#14188: init has no self client and runs; add . generates clients/test, wires the dep, self-call answers; rm prunes both; regeneration is byte-quiet throughout. Signed-off-by: Tom Chauveau <[email protected]>
The client-scope checks asserted the retired <scope>/.dagger/clients layout, so checks-check went red. They now assert the per-scope shape: packages under <scope>/clients with the scope's own dagger/ beside them, the scope package.json carrying the SDK's file: deps while the user's keys survive, a stale client file in clients/ pruned, and the .dagger/clients directory an earlier layout kept taken with the move — clientScope now prunes that leftover, and the existing fixture keeps one to prove it. The opt-in self client also reached further than intended: the embedded [runtime] layout lost its always-generated self client, which generate-self-call-check and generate-source-edit-is-scoped-check assert. The opt-in now applies to the entrypoint layout only; the embedded path keeps the behavior it shipped with. The full e2e suite passes locally against the manifest-v2 engine. 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.
The design (see
design/unified-clients-per-scope.md)One
clients/directory per scope, the same installable shape everywhere. Every scope that has clients carries one self-contained npm package per client plus the scope's own@dagger.io/daggerpackage beside them — a module scope and a client-only scope generate the identical tree, and the packages install and run anywhere. The package manifest is the only link (option C):package.jsonfile:deps, written by the SDK for what it generates and bynpm installfor what the user opts into. No tsconfig aliases, no workspace-level shared core, nousekey.Verified end to end (fresh workspace, manifest-v2 beta.14)
.dagger/modules/test/getsclients/daggeronly — no self client; package.json carries only@dagger.io/dagger: file:./clients/dagger; tsconfig isexperimentalDecoratorsonly; a call runs.dagger module client add .(dev engine with Allow a scope to record a client for its own module dagger#14188, which drops the false self-cycle) recordsclients = ["./.dagger/modules/test"], generatesclients/test/and wires the dep; afternpm install,call self-callanswers through the generated client.client rmprunes the package and the dep.client addin a plain directory produces the sameclients/tree with its own core;npm install+dagger run npx tsx main.tsreaches the module from user code.clients/**in the install context, no core fold, requireGenerated onclients/dagger/*).Mechanics worth reviewing
codegen --packaged-clients: clients nest in package directories; the loader imports them relatively so an uninstalled self client still resolves at dispatch time (core stays a bare import).config-updater shared-deps: treats npm'sfile:xspelling as equivalent tofile:./xinstead of fighting it;-core for an emptied scope; the second generation pass re-runs config against the user's original files. (Keep-only?name=relpairs exist in the CLI but the SDK no longer needs them — the self client is opt-in.).dagger/core, root-level client packages, root loader, and the embeddedsdk/of earlier layouts are all removed on regeneration.[runtime]modules keep the legacy embedded layout untouched.Related
client add .).