Skip to content

declaration maps (*.d.ts.map) have incorrect relative paths in sources unless declarationDir is set #204

@agilgur5

Description

@agilgur5

What happens and why it is wrong

This comes from downstream TSDX at jaredpalmer/tsdx#479 (and jaredpalmer/tsdx#135), which I fixed in jaredpalmer/tsdx#488 by adding a declarationDir, but I'm not sure if this isn't just a bug here. I believe the potential bug is either in

overrides.declarationDir = undefined;
or in
const relativePath = relative(pluginOptions.cwd, fileName);
but I'm not sure. Also not sure if this is related to #136 or not.

The tl;dr on those related issues is that TSDX takes ./src/index.ts as input and outputs ./dist/index.js, ./dist/index.d.ts, and if declarationMap is true, ./dist/index.d.ts.map, which has a sources attribute.

  • The problem is that when declarationDir is not set, sources will incorrectly point to index.ts
  • When declarationDir is set to ./dist, sources will correctly point to ../src/index.ts.
    • (with useTsconfigDeclarationDir: true ofc)

But in both cases, whether declarationDir is set to ./dist or not, everything gets output to ./dist via Rollup config.

If I'm understanding the code correctly, this is because the TS Language Service isn't creating the files when declarationDir isn't set, and so the relative paths are generated incorrectly before emitFile is called.
So that seems like a bug here, but maybe I'm missing something or its not fixable without setting declarationDir, sorry if that's the case 😅

Environment

TSDX @ master

Versions

  • typescript: 3.7.5
  • rollup: 1.27.8
  • rollup-plugin-typescript2: 0.26.0

rollup.config.js

The only difference is what's listed above (useTsconfigDeclarationDir and declarationDir), but current, non-trivial config is here

tsconfig.json

declarationDir is the only relevant one but here's a fixture

package.json

Probably not relevant but here

plugin output with verbosity 3

No errors, so I don't think it's relevant? Can run this on a fixture if needed.

Metadata

Metadata

Assignees

No one assigned

    Labels

    kind: bugSomething isn't working properly

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions