Skip to content

feat: add a cwd build option - #518

Merged
dsherret merged 3 commits into
denoland:mainfrom
dsherret:feat_cwd_build_option
Jul 28, 2026
Merged

feat: add a cwd build option#518
dsherret merged 3 commits into
denoland:mainfrom
dsherret:feat_cwd_build_option

Conversation

@dsherret

Copy link
Copy Markdown
Collaborator

Adds a cwd build option so that dnt can operate on a directory other than the process's current working directory:

await build({
  cwd: "./packages/add",
  entryPoints: ["./mod.ts"], // ./packages/add/mod.ts
  outDir: "./npm",           // ./packages/add/npm
  // ...etc...
});

It defaults to Deno.cwd(), so existing builds are unaffected.

There were three separate places relying on the process cwd:

  1. standardizePath resolved entryPoints, outDir, and testPreloadModule against it.
  2. The test file glob used rootTestDir ?? Deno.cwd() as its root (this is what causes an unrelated subdirectory of the cwd to get pulled into a build).
  3. It was passed to the transform as the workspace root, which is what discovers a deno.json, package.json, and deno.lock when the entry points are all remote.

All three now resolve from the cwd option. Along the way:

  • The lower level transform() API now resolves its own relative paths (entry points, mappings, importMap, configFile, module shims) from its existing cwd option instead of the process cwd, and accepts a plain path there in addition to a file url.
  • rootTestDir was previously handed to expandGlob unresolved, so a relative value resolved against the process cwd. It now resolves from the cwd option.
  • mapMappingKey's existsSync(key) fallback was probing the process cwd.

Closes #337

dsherret added 3 commits July 28, 2026 08:48
So that every call site is explicit about the directory it resolves a
relative path from, leaving `Deno.cwd()` only where it's the answer.
@dsherret
dsherret merged commit 5674950 into denoland:main Jul 28, 2026
5 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.

Ability to specify which directory dnt operates on

1 participant