Skip to content

fix(tsgo): keep declarations for files outside the tsconfig dir in the temp outDir - #313

Merged
sxzz merged 3 commits into
sxzz:mainfrom
lifeiscontent:fix/tsgo-dts-outside-outdir
Nov 6, 2026
Merged

sxzz merged 3 commits into
sxzz:mainfrom
lifeiscontent:fix/tsgo-dts-outside-outdir

Conversation

@lifeiscontent

@lifeiscontent lifeiscontent commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor

AI usage

  • No AI was used in this PR.
  • AI was used: Claude Code + Opus 5.5
    • I have carefully reviewed the AI-generated content myself.

Description

In a source-first monorepo, a package often pulls another workspace package's TypeScript sources into its program, through tsconfig paths or a relative import. The deprecated TypeScript 7.0 tsgo CLI backend runs tsgo with --rootDir set to the tsconfig directory, so declarations for those outside files are written next to their sources instead of into the temp outDir. Building one package quietly creates .d.ts files in other packages' src, and fails with TS5033 when those directories aren't writable.

This passes the filesystem root as --rootDir, so every declaration tsgo emits lands in the temp directory.

Linked Issues

Additional context

The new test runs the CLI backend with the real tsgo binary. It fails without this change.

@astrocreep

astrocreep commented Oct 9, 2026 •

Copy link
Copy Markdown

We hit the same problem in a pnpm monorepo and this fix solves it.

Our setup: a published package (packages/client) inlines the types of three private workspace packages (packages/ui, shared/browser-lib, shared/hybrid-lib). Those packages expose their types from src/*.ts, not from built .d.ts files.

With the current rootDir logic the tsconfig for the dts build needs to be placed in the repo root, because the plugin looks up every emitted file relative to the tsconfig directory. A tsconfig inside packages/client fails with:

tsgo did not generate dts file for .../shared/hybrid-lib/src/index.ts, please check your tsconfig.

I tested this PR locally by applying the one-line change to the installed plugin (rolldown-plugin-dts 0.28.6, tsdown 0.23.0, TypeScript 7.0.2). With a tsconfig inside the package that includes the other sources, the build succeeds.

Thanks for the fix, would be awesome to see this merged!

edit: some more details.

…e temp outDir

tsgo was run with --rootDir set to the tsconfig directory. Files the program
pulls in from outside it, such as workspace packages that resolve to their
sources, are not under rootDir, so tsgo wrote their .d.ts next to the source
files instead of into the temp outDir. Use the filesystem root as rootDir so
every emitted declaration lands in the temp dir.
@lifeiscontent
lifeiscontent force-pushed the fix/tsgo-dts-outside-outdir branch from 276aaf3 to 008f261 Compare November 6, 2026 03:03
@github-actions

github-actions Bot commented Nov 6, 2026

Copy link
Copy Markdown

Thank you for contributing! This PR does not follow the required PR template.

Missing: the template instruction comment, the "AI usage" section, the "Description" section, the "Linked Issues" section, the "Additional context" section.

Please use the shared PR template, preserve its comments and sections, and complete the applicable fields, including the AI usage disclosure.

This PR is being closed automatically. After updating the description, you can reopen it or ask a maintainer to reopen it.

@github-actions github-actions Bot closed this Nov 6, 2026
@lifeiscontent

Copy link
Copy Markdown
Contributor Author

@sxzz I updated the description to follow the PR template. Could you reopen this PR? I can't reopen it myself.

@sxzz sxzz reopened this Nov 6, 2026
@pkg-pr-new

pkg-pr-new Bot commented Nov 6, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/sxzz/rolldown-plugin-dts@313

commit: 65bfcfe

@sxzz
sxzz enabled auto-merge (squash) November 6, 2026 05:46
@sxzz
sxzz merged commit 7b15002 into sxzz:main Nov 6, 2026
13 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.

4 participants