Skip to content

fix: don't shift output when a dependency resolves to a .ts file - #502

Merged
dsherret merged 1 commit into
denoland:mainfrom
dsherret:fix_extra_src_dir
Jul 26, 2026
Merged

fix: don't shift output when a dependency resolves to a .ts file#502
dsherret merged 1 commit into
denoland:mainfrom
dsherret:fix_extra_src_dir

Conversation

@dsherret

Copy link
Copy Markdown
Collaborator

When a dependency's resolution lands on a .ts file, TypeScript pulls it into the program as a source file rather than a declaration file. That moved the inferred common source directory from <outDir>/src up to <outDir>, so every emitted file gained an extra src segment while the package.json paths — built from the transform's entry point paths — did not:

npm/esm/node_modules/type-detect/index.js   <-- a dependency got compiled
npm/esm/src/mod.js                          <-- extra "src" segment
npm/types/mod.d.ts                          <-- no "src" segment
{ "module": "./esm/mod.js" }                 // points at nothing

Pinning rootDir to the sources keeps the output where the package.json says it is, and stops the dependency being emitted into the package.

Type checking hit the same file for the second half of the problem — skipLibCheck only covers a dependency's .d.ts files, so a dependency shipping .ts reported its own errors against the package author (14 of them for type-detect, ex. Cannot find name 'window'). Its code is no more the author's problem than a .d.ts would be, so diagnostics from node_modules are ignored the same way.

The regression test uses type-detect@^4.1.0, which has no types/typings entry and ships index.js, index.d.ts and index.ts. Nothing is specific to that package — any dependency shipping a .ts file that resolution lands on does it. The test fails on both counts without the fix.

Closes #460

A dependency that resolution lands on a `.ts` file for (ex. `type-detect`,
which ships an `index.ts` and declares no `types`) enters the program as a
source file. That moved TypeScript's inferred common source directory from
`<outDir>/src` up to `<outDir>`, so every emitted file gained an extra
`src` segment while the package.json paths did not, leaving them dangling.

Pin `rootDir` to the sources, and ignore diagnostics from node_modules
since `skipLibCheck` only covers a dependency's `.d.ts` files.

Closes denoland#460
@dsherret
dsherret merged commit a58c605 into denoland:main Jul 26, 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.

"exports" field does not have types, and that results in a package being untyped

1 participant