Skip to content

Use Workspace.withDirectory for init and client codegen once beta.11 is out #36

Description

@TomChv

Blocked on the v1.0.0-beta.11 release.

dagger/dagger#13956 (fixes dagger/dagger#13955 — the engine issue #35 said was worth filing) splits Workspace.withNewDirectory in two:

  • withNewDirectory now replaces whatever the path held, on every workspace kind — host-backed, value and git alike. The local/git divergence that cost Keep existing files when init and client codegen write a directory #35 two red CI rounds is gone.
  • The new Workspace.withDirectory merges the source onto what the path already holds, the same contract Directory.withDirectory has.

Both workarounds #35 had to write — the read-back-and-layer, and pruning the bindings twice — are that second field, so they can go away.

What to change

Once dagger.json moves to engineVersion: v1.0.0-beta.11:

initModule (typescript-sdk.dang:234)

# withNewDirectory replaces the directory it writes, so layer the starter
# onto what is already there: init must never remove a user's files, nor
# the config the engine wrote at `modPath` before calling us.
ws.withNewDirectory(
  "/" + modPath,
  existingDir(ws, modPath).withDirectory(".", templateSource),
).changes(ws)

becomes ws.withDirectory("/" + modPath, templateSource).changes(ws), and that half of the comment goes with it. The modPath anchoring note above it still applies and should stay.

generateClient (typescript-sdk.dang:620) and generateAllClient (typescript-sdk.dang:687)

withoutClientBindings(ws, path)
  .withNewDirectory("/" + path, existingClientBase(ws, path).withDirectory(".", generated))
  .changes(ws)

should collapse to pruning the stale bindings out of the workspace and merging the generated package on top:

withoutClientBindings(ws, path)
  .withDirectory("/" + path, generated)
  .changes(ws)

That keeps the ownership split #9 established — the SDK owns *.gen.ts, the user owns everything else — with one prune instead of two.

Then:

  • existingClientBase (typescript-sdk.dang:566) becomes dead — delete it.
  • withoutClientBindings' doc comment (typescript-sdk.dang:573) is the "pruning has to happen twice" explanation. It describes a divergence that no longer exists; it should shrink to what the helper does.
  • existingDir stays: clientBindings still reads the destination through it.
  • In generateAllClient, the reason the baseline read from the untouched ws while the prune ran on stagedWs was that reading back out of a pruned host-backed workspace came up empty. With no read-back left there is nothing to keep straight — but the fold still needs its prune on stagedWs, so verify rather than assume.

Guards

dagger check 'e-2-e*' — the three checks #35 added exist for this and should all still pass:

  • init:init-over-existing-check
  • client:generate-client-respects-existing-check (main.ts survives, stale-dep.gen.ts is pruned)
  • client:generate-client-on-synthetic-workspace-check

The last one was there to catch the local/git split. It is worth keeping even though the engine no longer diverges.

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