Skip to content

feat(core): add Workspace.moduleSource to load a module from a workspace - #13663

Merged
TomChv merged 1 commit into
mainfrom
feat+add-workspace-modulesource-api
Jul 17, 2026
Merged

TomChv merged 1 commit into
mainfrom
feat+add-workspace-modulesource-api

Conversation

@TomChv

@TomChv TomChv commented Jul 16, 2026

Copy link
Copy Markdown
Member

What

Add a workspace-scoped Workspace.moduleSource(path): ModuleSource! field that
resolves a path inside the workspace to a ModuleSource, using the same path
rules as Workspace.directory / file / glob:

  • Absolute path (/foo) → resolved from the workspace root.
  • Relative path (foo, ../foo) → resolved from the workspace cwd
    (determined at load).

It materializes the workspace tree (workspaceOverlayRootfs, so host reads route
to the workspace owner) and loads via asModuleSource, failing if the path does
not point to an initialized module or escapes the workspace root. Gated
AfterVersion("v1.0.0-0"), PerClientInput.

Why

Two consumers:

  1. Generated-client module loading (runtime half). A generated client's
    connect wrapper needs to serve the single module it is bound to before the
    user's callback runs. The old helper did moduleSource(".") — a cwd-relative
    dagger.json find-up that resolves to the wrong module (or nothing) now that
    the client dir and module dir are decoupled. The client can instead bake its
    module's workspace-relative path and call
    dag.currentWorkspace().moduleSource(path).asModule().serve(), which resolves
    against the find-up-discovered workspace rather than the process cwd. Design:
    hack/designs/generated-client-module-loading.md (added here). The codegen
    half lives in the TypeScript SDK's client generator and is handled separately.

  2. Workspace.moduleSource(): load a module from a workspace #13157 — a module that receives a Workspace can now load a local module
    from it directly, instead of reimplementing core module loading in userland.

Depends on the client-codegen schema primitives in #13646
(ModuleSource.clientSchemaIntrospectionJSON is what makes "core + the bound
module only" true, so the runtime only ever needs to serve the one module).

Notes

  • Intentionally does not route through resolveClientTargetModule: its
    local/remote branch selection uses IsLocalRef, which mis-classifies a module
    directory whose name contains a . as a remote ref. The input here is always a
    local workspace path, so it loads the local branch directly.
  • Regenerated SDK bindings + GraphQL SDL + reference docs for the new field.

Test

TestModuleSourceResolvesWorkspacePaths (core/integration/workspace_api_test.go)
covers relative-from-root-cwd, relative-from-nested-cwd (../sub), absolute
(/sub, cwd-independent), default ., non-module → error, and escaping the
workspace root → error.

Closes #13157

@TomChv
TomChv requested review from a team as code owners July 16, 2026 16:46
@TomChv
TomChv force-pushed the feat+add-workspace-modulesource-api branch from 653c413 to 7887bdb Compare July 16, 2026 17:58
TomChv added a commit to dagger/typescript-sdk that referenced this pull request Jul 17, 2026
Replace the generated serveModuleDependencies wrapper (git-dep loop +
moduleSource(".") configExists-guarded serve + includeDependencies) with a
minimal serveBoundModule bootstrap, per dagger/dagger#13663's design.

The client schema is core + the bound module only, so there are no
dependencies to serve and includeDependencies is dead. The old
moduleSource(".") also mis-resolved once the client dir and module dir are
decoupled: it find-ups dagger.json from the client's cwd, not the module.

serveBoundModule serves exactly the one bound module, chosen by kind:
- local (LOCAL_SOURCE/DIR_SOURCE): resolve the module's workspace-root-
  relative path against the workspace via dag.currentWorkspace()
  .moduleSource(path) (needs Workspace.moduleSource from #13663). The path is
  forced absolute (leading slash) so it resolves from the workspace root,
  cwd-independent.
- git (GIT_SOURCE): serve the canonical ref + pin directly
  (dag.moduleSource(ref, { refPin })), which resolves from anywhere.

The bound module's identity comes from the client entry (client.module /
.pin) plus moduleSource.kind/.asString; asString is unusable for the local
path (absolute host path for LOCAL_SOURCE, empty for DIR_SOURCE), so the
workspace-relative path is taken from client.module / the module argument.

meta.json now carries a single {kind, path, ref, pin} module object instead
of a dependencies array. Adds a golden test for both serve branches.

Depends on dagger/dagger#13663 (Workspace.moduleSource) in addition to
#13646. generateClientCompilesCheck type-checks the generated
currentWorkspace().moduleSource(...) and so requires an engine with #13663.

Signed-off-by: Tom Chauveau <[email protected]>
@TomChv
TomChv force-pushed the feat+add-workspace-modulesource-api branch from 7887bdb to eed05f8 Compare July 17, 2026 16:04
Add a workspace-scoped `Workspace.moduleSource(path): ModuleSource!` field that resolves a path inside the workspace to a module source, using the standard workspace path rules: absolute paths from the workspace root, relative paths from the workspace cwd. It materializes the workspace tree and loads via asModuleSource, failing if the path does not point to an initialized module.

This is the runtime primitive a generated client's connect wrapper calls to serve the module it is bound to (dag.currentWorkspace().moduleSource(path).asModule().serve()), replacing the cwd-relative moduleSource(".") find-up that breaks once the client and module directories are decoupled. It also implements the API requested in #13157, so a module that receives a Workspace can load a local module from it.

Regenerate SDK bindings and reference docs for the new field, and add the generated-client-module-loading design doc.

Signed-off-by: Tom Chauveau <[email protected]>
@TomChv
TomChv force-pushed the feat+add-workspace-modulesource-api branch from eed05f8 to 4f6e6ae Compare July 17, 2026 16:43
@TomChv

TomChv commented Jul 17, 2026

Copy link
Copy Markdown
Member Author

As a follow up, we should allow path to be a ref so it can load even if the module is outside the workspace.
That would be convenient for generated client because we would be able to rely on dag.Workspace.ModuleSource only instead of using dag.ModuleSource for remote dependencies

@TomChv
TomChv merged commit 9cf1d52 into main Jul 17, 2026
87 checks passed
@TomChv
TomChv deleted the feat+add-workspace-modulesource-api branch July 17, 2026 17:10
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.

Workspace.moduleSource(): load a module from a workspace

2 participants