fix(typescript): emit declaration files for type-only source files that are not explicitly included#1555
Conversation
| function isMapOutputFile(name: string): boolean { | ||
| return name.endsWith('.map'); | ||
| export function isMapOutputFile(name: string): boolean { | ||
| return name.endsWith('ts.map'); | ||
| } |
There was a problem hiding this comment.
The reason for this change is that we only need to worry about emitting .d.ts.map (and equivalent .d.cts.map & .d.mts.map) files. The .js.map files are already being emitted by the TypeScript compiler (unless the noEmit option is set to true).
shellscape
left a comment
There was a problem hiding this comment.
Looks good. Will this alter any existing behavior, cause a difference in output (aside from additional files)
No, the only change in behaviour is that in the |
|
don't report bugs on closed pull requests. open a new issue and follow the issue template |

Rollup Plugin Name:
@rollup/plugin-typescriptThis PR contains:
Are tests included?
Breaking Changes?
If yes, then include "BREAKING CHANGES:" in the first commit message body, followed by a description of what is breaking.
List any relevant issue numbers:
Description
Please read the linked issue first for context.
The core issue is that TypeScript source files which contain only type definitions transpile into nothing. This means that Rollup has no equivalent JavaScript files to operate on (i.e., we cannot handle these files if they are not already included in
tsconfig.jsonbecause within the Rollup build hooks and output generation hooks, these files do not exist). Specifically in the test case added, theexportstatement inmain.tsis removed when transpiling into JavaScript becauseMyNumberis a type. This means that by the time Rollup operates onmain.js, there is no longer any logical link betweenmain.ts&should-be-emitted-types.ts.However, the observation here is that we don't have to manually keep track of which files to emit because the TypeScript compiler already does it for us. Specifically, the TypeScript compiler only emits the files which are necessary (this is verified in the test case I added). This means that we can simply emit all declaration & source map files in
emittedFilesto solve the linked issue.