Skip to content

Make lint and fix cwd-aware - #2

Merged
kpenfound merged 7 commits into
mainfrom
cwd_aware
Jul 24, 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 — same approach as dagger/vitest#17, dagger/prettier#13, and dagger/eslint#12, ported to the TypeScript SDK:

  • The constructor takes ws: Workspace instead of a defaultPath: "/" source directory; source is now ws.directory("/") and a new path function exposes the client's cwd relative to the workspace root.
  • The full workspace root stays mounted at /src (so a root biome.json still resolves), but lint and fix set withWorkdir("/src/" + path) before running Biome.
  • fix 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.
  • When the workspace root holds no package.json, the npm install step is skipped and npx fetches Biome on demand — a standalone Biome config no longer hard-fails on ENOENT package.json.

Also adds a README documenting the functions and the cwd behavior.

Testing

In a scratch workspace with messy files at the root and under sub/nested/:

  • call path → sub from sub/.
  • lint from sub/ checks exactly 1 file (nested/messy2.ts), leaving the root file out of scope.
  • fix from sub/ yields a changeset touching only sub/nested/messy2.ts (root-relative); from the root it touches both files.
  • Both the with-package.json (npm install runs) and standalone (install skipped, npx fetch) paths verified.

🤖 Generated with Claude Code

Take the Workspace in the constructor instead of a defaultPath'd source
directory, and run Biome from the client's working directory within the
workspace. The full workspace stays mounted so a root biome.json still
resolves, but lint and fix now set the container workdir to /src/<cwd>
(via the new path function, from ws.path), scoping Biome 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.

When the workspace root holds no package.json the dependency install is
skipped and npx fetches Biome on demand, so a standalone Biome config
works without a Node project.

Also add a README documenting the functions and the cwd behavior.

Co-Authored-By: Claude Fable 5 <[email protected]>
Signed-off-by: kpenfound <[email protected]>
kpenfound and others added 5 commits July 22, 2026 14:36
Add a workspace dagger.toml with github.com/dagger/typescript-sdk installed
as an SDK (via `dagger sdk install typescript`), mirroring the Dang SDK
setup in the dang-based toolchains, 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.biomejs] source = "." so the workspace — and the TypeScript
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]>
With the module registered in the workspace, `dagger check` now runs
biomejs:lint against this repo itself. Apply biome's fixes to src/index.ts,
prefer template literals over concatenation, and add a biome.json that
keeps JSON files space-indented (dagger.json and package.json are written
that way by tooling) and excludes the generated SDK files from checking.

Co-Authored-By: Claude Fable 5 <[email protected]>
Signed-off-by: kpenfound <[email protected]>
Record this module in [[modules.dagger-typescript-sdk.as-sdk.modules]] —
the SDK's managed-modules list that `dagger generate` iterates. Applying
generate marks the SDK entrypoint file as generated and git-ignored.

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]>
@kpenfound

Copy link
Copy Markdown
Contributor Author

typescript-sdk:generate-all is failing, but its passing for me on beta.7 so I think we're ok

@TomChv

TomChv commented Jul 23, 2026

Copy link
Copy Markdown
Member

typescript-sdk:generate-all is failing, but its passing for me on beta.7 so I think we're ok

I think that's because the engine version in the CI is younger than beta.7 so some changes may have happen regarding the generate.
I would suggest you try to run generate with --x-release=main to see what happen.

@TomChv

TomChv commented Jul 23, 2026

Copy link
Copy Markdown
Member

Tested end-to-end against engine v1.0.0-beta.7 — installed the module into throwaway workspaces (one with a root package.json + @biomejs/biome, one standalone with no Node project), each with a root biome.json plus a well-formatted clean/ subdir and a badly-formatted messy/ subdir. Ran path, lint, and fix from the root and from subdirs.

Works ✅

  • path → `` (empty) at root, clean/`messy` from those subdirs.
  • lint scoping — from clean/ PASS, from messy/ FAIL (Checked 1 file), from root FAIL. Confirmed the root biome.json really is resolved from a subdir (not just Biome's built-in defaults): with a root config that disables all analyzers, a messy/ run flips from the formatting error to Checked 0 files — so the whole-workspace-at-/src mount is doing its job. 👍
  • standalone (no package.json) — npx fetches @biomejs/[email protected] on demand and lints. 👍
  • fixFilter keeps package.json/lockfiles out of the changeset, so fix from the root is clean (no lockfile leak).

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

Same issue I flagged on dagger/eslint#12: 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.ts in place ✅
  • fix -y from messy/ → creates messy/messy/bad.ts instead of touching messy/bad.ts ❌

Reproduced identically in the standalone workspace (from sub/ → sub/sub/bad.ts). The PR's own testing checked the changeset content ("touching only sub/nested/messy2.ts, root-relative") but not where -y actually writes it.

The extraction is scoped to the subdir, but the changeset is still rooted at the full tree (src/index.ts):

.directory("/src")                                              // extraction — full root
...
.changes(
  dag.directory().withDirectory(".", this.source, { include: fixFilter }),  // base — full root
);

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

const p = (await this.path()) || ".";
const fixed = (await this.base())
  .withWorkdir(`/src/${p}`)
  .withExec(["npx", "@biomejs/biome", "check", "--write", ...files])
  .directory(`/src/${p}`)                       // was "/src"
  .withoutDirectory("node_modules");

return dag
  .directory()
  .withDirectory(".", fixed, { include: fixFilter })
  .changes(
    dag
      .directory()
      .withDirectory(".", this.source.directory(p), { include: fixFilter }),  // was this.source
  );

(The || "." matters here: unlike the .dang modules, TS ws.path() returns "" at the root, so this.source.directory("") needs normalizing.)

I applied exactly this locally and re-tested: fix -y now edits messy/bad.ts 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).

This mirrors dagger/eslint#12 and dagger/prettier#13, which share the same directory("/src") pattern and the same bug. (If the intended contract is instead that api call -y applies at the workspace root, 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.)

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 76dea6c into main Jul 24, 2026
1 of 2 checks passed
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