chore(build): set an explicit rootDir for declaration output - #540
Merged
Conversation
@rollup/plugin-typescript 12 no longer sets `rootDir` itself, and TypeScript 6 no longer infers the common source directory (TS5011). This repo is still on plugin 11, so the emitted layout is currently correct — but without an explicit `rootDir` the next plugin bump would move the entry declarations to `dist/<fmt>/src/index.d.ts` while `package.json` keeps pointing `types` at `dist/<fmt>/index.d.ts`. That is exactly what broke the pro packages: @coreui/vue-pro from 5.20.0 (coreui/coreui-pro#704) and @coreui/react-pro from 5.27.0, in both cases with TS7016 on every import for every TypeScript consumer.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Preventive — this repo is not currently broken. It hardens the build against a defect that already shipped in the pro packages.
Background
package.jsonpointstypesatdist/esm/index.d.ts. Emitting the entry declarations anywhere else silently breaks every TypeScript consumer withTS7016on every import, while the runtime keeps working — the JavaScript entry is unaffected because rollup applies its ownpreserveModulesRoot: 'src'.That is exactly what happened to
@coreui/react-pro(from 5.27.0) and@coreui/vue-pro(from 5.20.0, reported as coreui/coreui-pro#704): the declarations moved todist/esm/src/index.d.tsanddist/cjs/src/index.d.ts.Cause, and why this repo escaped it
It takes two ingredients:
@rollup/plugin-typescript12.x no longer setsrootDiritself.TypeScript 6.x no longer infers the common source directory:
The pro repos have both. This repo already resolves TypeScript 6.x (transitive dependencies lifted it to the root, where the hoisted plugin picks it up regardless of the
typescript@^5.9.3pin), but is still on plugin 11.1.6, which setsrootDiron its own. So today's output is correct and the next plugin bump would break it.Fix
Set
rootDirexplicitly — exactly what TS5011 asks for. This makes the output layout independent of the plugin and compiler versions.Verification
Built ESM + CJS before and after: output is byte-for-byte the same layout, with the entry declarations at
dist/esm/index.d.tsanddist/cjs/index.d.tsand nosrc/segment.