Skip to content

prepare: let a lane's prepared node_modules be used in the worktree (git hooks run there) #159

Closed

Description

@7schmiede

Context

A lane runs from a snapshot of its worktree (ADR-0002, ADR-0024), and prepare (e.g. npm ci) runs in that snapshot. The worktree itself therefore never gets a node_modules, by design.

Git hooks do not know about the snapshot: git commit runs core.hooksPath hooks in the worktree. A pre-commit hook that lints staged files with npx eslint fails in every lane worktree with Cannot find module from eslint.config.js, although the lane has a fully prepared node_modules a few directories away.

Observed with devstack 0.11.0 on Windows: first commit in a fresh lane worktree failed on the hook; npm ci by hand in the worktree (three minutes, a second copy of node_modules) fixed it.

Why not solve it in the hook

The hook could look for the lane's snapshot when the worktree has no node_modules. That couples the downstream repository to devstack's internal layout (.devstack/lane-<name>/lanes/main/src), which is not a documented contract, and it runs against ADR-0015 ("applications never depend on devstack"). The hand-run npm ci stays the fallback either way.

Proposal

Let prepare optionally make its result usable in the worktree, for example:

[services.web]
prepare = { run = "npm ci", inputs = ["web/package-lock.json"], link = ["web/node_modules"] }
  • After prepare succeeded in the snapshot, devstack puts a junction/symlink for each link path into the worktree, pointing at the prepared directory in the snapshot.
  • Only when the worktree does not already have that path (a developer's own install wins).
  • devstack lane stop and lane prune remove the links again, so git worktree remove never recurses into a linked node_modules (that has deleted a main tree's node_modules before, when a junction was made by hand).
  • devstack status / lane list could show linked next to the service.

Alternative: a documented command that prints the snapshot path of a lane (devstack lane path <name>), so a hook can opt in explicitly through a stable contract instead of guessing the layout. The link option seems the smaller surface for the common case.

Acceptance

  • In a lane worktree, git commit with a lint hook that runs npx eslint passes without a hand-run npm ci.
  • git worktree remove after lane stop leaves the snapshot's node_modules intact and removes only the link.
  • A worktree that already has its own node_modules is left alone.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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