Skip to content

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

Closed

Description

@shykes

Problem

A module can receive a Workspace, but it cannot load another Dagger module from that workspace.

For example, a module should be able to say: "load the module at ./foo in this workspace" and get back a ModuleSource.

Today there is no direct core API for that. The only option is to implement a module-side shim for Workspace.moduleSource().

That shim is difficult and unreliable for several reasons:

  1. Low-level module loading logic must be reimplemented: walking dependencies, differentiating local from remote dependencies, honoring include fields, and so on.
  2. Directory.asModuleSource() is the right low-level primitive in theory, but it is buggy when called from a module. See Directory.asModuleSource fails resolving local deps from module context #13139. There is a workaround, using a native helper, but it adds a lot of complexity.
  3. Even with that workaround, a ModuleSource loaded from a Directory has more bugs. Dependency manipulation functions do not work. See ModuleSource.withDependencies rejects directory-backed module sources #13152. This forces modules to reimplement dagger.json dependency management from scratch.

Solution

Add a workspace-scoped API for loading a module source.

For example:

extend type Workspace {
  moduleSource(path: String! = "."): ModuleSource!
}

Expected behavior:

  • resolve path inside the given Workspace
  • load the module using normal local module loading rules
  • return a ModuleSource
  • fail if the path does not point to a module in the workspace
  • avoid depending on host cwd or module-client context

This would let workspace-aware modules load local modules directly, without rebuilding core module loading in userland.

See also

These issues are related, but distinct. They were found while working around the missing API:

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions