-
-
Notifications
You must be signed in to change notification settings - Fork 594
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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-typescript
This 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.json
because within the Rollup build hooks and output generation hooks, these files do not exist). Specifically in the test case added, theexport
statement inmain.ts
is removed when transpiling into JavaScript becauseMyNumber
is 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
emittedFiles
to solve the linked issue.