Skip to content

Make lint and fix cwd-aware - #12

Merged
kpenfound merged 7 commits into
mainfrom
cwd_aware
Jul 23, 2026
Merged

kpenfound merged 7 commits into
mainfrom
cwd_aware

Conversation

@kpenfound

Copy link
Copy Markdown
Contributor

Summary

Running dagger check (or fix) now behaves as if invoked from the user's current working directory within the workspace, rather than always from the workspace root — same approach as dagger/vitest#17 and dagger/prettier#13:

  • New path field, set from ws.path in the constructor: the client's cwd relative to the workspace root (. at the root).
  • The full workspace root stays mounted at /src (so root .eslintrc.* / eslint.config.* still resolve), but lint and fix set withWorkdir("/src/" + path) before running ESLint.
  • fix now extracts directory("/src") instead of the workdir-relative directory("."); otherwise the changeset would diff the subdirectory against the full root and manifest as mass deletions.

Also rewrites the README in the style of the playwright module's, documents the cwd behavior, and drops documentation for an extensions argument the module doesn't have.

Testing

Verified against a fresh clone of dagger/hello-dagger:

  • call path → src/components from that subdir.
  • lint from src/components passes and resolves the repo-root .eslintrc.cjs by walking up from the workdir — the case root-mounting exists to support; the root run also still passes.

🤖 Generated with Claude Code

Run ESLint from the client's working directory within the workspace
instead of always from the workspace root. The full workspace stays
mounted so root eslint configs still resolve, but lint and fix now set
the container workdir to /src/<cwd> (via the new path field, set from
ws.path), scoping linting to the invoking subtree.

fix now extracts directory("/src") instead of the workdir-relative
directory("."), so the changeset is diffed root-against-root rather
than subdir-against-root.

Also rewrite the README in the style of the playwright module's, and
drop documentation for an extensions argument the module doesn't have.

Co-Authored-By: Claude Fable 5 <[email protected]>
Signed-off-by: kpenfound <[email protected]>
A standalone eslint config without a Node project previously hard-failed
on npm install (ENOENT package.json). When the workspace root holds no
package.json, build the runtime container without the install step and let
npx fetch ESLint on demand instead.

Co-Authored-By: Claude Fable 5 <[email protected]>
Signed-off-by: kpenfound <[email protected]>
kpenfound and others added 4 commits July 22, 2026 14:26
Wire github.com/dagger/dang-sdk into dagger.toml, matching the playwright
module's setup, so `dagger generate` covers this module. Generate currently
reports no changes to apply.

Co-Authored-By: Claude Fable 5 <[email protected]>
Signed-off-by: kpenfound <[email protected]>
Add [modules.eslint] source = "." so the workspace — and the Dang SDK's
generate — can find the module, matching the playwright module's setup.

Co-Authored-By: Claude Fable 5 <[email protected]>
Signed-off-by: kpenfound <[email protected]>
Mark the dang-sdk install with its as-sdk name and record this module in
[[modules.dang-sdk.as-sdk.modules]] — the SDK's managed-modules list that
`dagger generate` iterates. The module remains in generated form (no
changes to apply).

Co-Authored-By: Claude Fable 5 <[email protected]>
Signed-off-by: kpenfound <[email protected]>
Drop the [modules.{name}] source = "." entry: it installs the module into
the workspace, which is not intended — the workspace should only carry the
test fixtures and SDK functions. The [[...as-sdk.modules]] entry alone
drives `dagger generate` over the module.

Co-Authored-By: Claude Fable 5 <[email protected]>
Signed-off-by: kpenfound <[email protected]>
@TomChv

TomChv commented Jul 23, 2026

Copy link
Copy Markdown
Member

Tested this end-to-end against engine v1.0.0-beta.7 — installed the module into throwaway workspaces (one with a root package.json + eslint 9, one standalone with no Node project), each with a root eslint.config.js (semi rule) plus a clean subdir and a messy subdir. Ran path, lint, and fix from the root and from subdirs.

Works ✅

  • path → . at root, clean/messy from those subdirs.
  • lint scoping — from clean/ PASS, from messy/ FAIL, from root FAIL. From messy/ ESLint still resolves the root eslint.config.js by walking up from /src/messy, so the full-workspace-at-/src mount does its job while the run is scoped. 👍
  • no-package.json runtime branch — standalone config with no Node project works; npx fetches ESLint on demand and lints. Mount path (/src) matches nodejs.base, so withWorkdir("/src/" + path) is consistent across both branches.

Bug 🔴 — fix writes to the wrong place from a subdirectory

dagger api call ... -y applies a changeset relative to the caller's cwd, but fix returns a changeset rooted at the workspace root (/src). They only coincide at the root:

  • fix -y from root → correctly edits messy/bad.js in place ✅
  • fix -y from messy/ → creates messy/messy/bad.js (+ messy/package-lock.json) instead of touching messy/bad.js ❌

Reproduced identically in the no-package.json workspace (from sub/ → sub/sub/bad.js), with no lockfile to muddy it — so the cause is purely the root-rooted changeset applied at cwd.

The extraction was scoped to the subdir, but the changeset is still rooted at the full tree:

.directory("/src")                                  // extraction
...
.changes(source.withoutDirectory("node_modules"))   // base is the full root

The changeset needs to be rooted at the subtree (= cwd). Scoping both sides to path fixes it:

.directory("/src/" + path)                                          // was "/src"
...
.changes(source.directory(path).withoutDirectory("node_modules"))   // was source.without…

I applied exactly this locally and re-tested: fix -y now edits messy/bad.js in place from both messy/ and the root, with no nesting. It still avoids the mass-deletion problem this PR was solving (the diff base is the same subtree, not the full root), and as a bonus drops the package-lock.json leak for subdir runs since the root lockfile isn't in the subtree.

Note: dagger/prettier#13 shares the identical write structure and will have the same bug from a subdirectory; dagger/vitest#17 has no writing function, so it's unaffected. (If the intended contract is instead that api call -y applies at the workspace root, then the defect is CLI-side — but either way fix from a subdir is broken today, and the module-side change above makes it correct against current beta.7.)

Minor

  • package-lock.json leak (pre-existing, not a regression): from the root, npm install generates a lockfile inside /src that lands in the fix changeset. The subtree-scoping above removes it for subdir runs.
  • source.glob("package.json") matches only the workspace root, so a monorepo with only nested package.jsons takes the npx-on-demand branch — reads intentional, just noting it.

@TomChv TomChv left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still approving the PR if you wanna fix that in a follow up

The CLI applies a returned changeset relative to the caller's working
directory, but the changeset was rooted at the workspace root — so applying
from a subdirectory nested the paths (e.g. creating messy/messy/bad.js
instead of editing messy/bad.js). Scope both the extraction and the diff
base to the subtree so the changeset is rooted where it lands. This still
avoids the mass-deletion problem (the diff base is the same subtree), and
drops the root package-lock.json leak from subdirectory runs.

Reported by @TomChv on #12.

Co-Authored-By: Claude Fable 5 <[email protected]>
Signed-off-by: kpenfound <[email protected]>
kpenfound added a commit to dagger/biomejs that referenced this pull request Jul 23, 2026
The CLI applies a returned changeset relative to the caller's working
directory, but the changeset was rooted at the workspace root — so applying
from a subdirectory nested the paths (e.g. creating messy/messy/bad.js
instead of editing messy/bad.js). Scope both the extraction and the diff
base to the subtree so the changeset is rooted where it lands. This still
avoids the mass-deletion problem (the diff base is the same subtree), and
drops the root package-lock.json leak from subdirectory runs.

Reported by @TomChv on dagger/eslint#12.

Co-Authored-By: Claude Fable 5 <[email protected]>
Signed-off-by: kpenfound <[email protected]>
kpenfound added a commit to dagger/prettier that referenced this pull request Jul 23, 2026
The CLI applies a returned changeset relative to the caller's working
directory, but the changeset was rooted at the workspace root — so applying
from a subdirectory nested the paths (e.g. creating messy/messy/bad.js
instead of editing messy/bad.js). Scope both the extraction and the diff
base to the subtree so the changeset is rooted where it lands. This still
avoids the mass-deletion problem (the diff base is the same subtree), and
drops the root package-lock.json leak from subdirectory runs.

Reported by @TomChv on dagger/eslint#12.

Co-Authored-By: Claude Fable 5 <[email protected]>
Signed-off-by: kpenfound <[email protected]>
@kpenfound
kpenfound merged commit 35a0cc0 into main Jul 23, 2026
3 checks passed
TomChv pushed a commit to dagger/helm that referenced this pull request Jul 24, 2026
Part of the cwd-awareness sweep (dagger/vitest#17, dagger/prettier#13, dagger/eslint#12, dagger/playwright#1). Like dagger/shellcheck#2, helm needs no code change: it already takes the Workspace per function and discovers charts via relative workspace paths (ws.directory(".")), which resolve from the client's working directory. Running from a subdirectory already lints only the charts in that subtree, and each chart mounts its own directory — the chart boundary — so nothing above it is needed.

This PR:

- Fixes docstrings that described chart paths as workspace-relative when they are actually cwd-relative.
- Adds a README documenting the functions, the ci/*-values.yaml values matrix, and the cwd scoping.

Signed-off-by: kpenfound <[email protected]>
TomChv pushed a commit to dagger/playwright that referenced this pull request Jul 24, 2026
The module now behaves as if invoked from the user's current working directory within the workspace — same approach as dagger/vitest#17, dagger/prettier#13, and dagger/eslint#12, adapted to this module's structure and the beta engine's Workspace API (ws.cwd, root-absolute with / as the workspace root):

source is now the workspace root (excluding **/node_modules) instead of just the project directory. A new root-absolute path field records where the project lives, resolved by a workspacePath helper from ws.cwd plus either sourcePath (relative resolves from the cwd, absolute from the root) or playwright.config.* discovery — which still searches at or below the cwd.
base mounts the root at /app and sets withWorkdir("/app" + path), so configs and dependencies that live above the project (monorepo roots, shared configs) keep resolving inside the test container.
lockedVersion / declaredImage read package.json and the lockfile through a project accessor (source.directory(path)) since source no longer points at the project.

Signed-off-by: kpenfound <[email protected]>
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.

2 participants