rushstack
rushstack copied to clipboard
[api-extractor] Can not rollup DTS importing from index file
Summary
When using dtsRollup feature, I found that it is unable to bundle types from importing from a index file but not write the full path.
Repro steps
https://github.com/Timeless0911/api-extractor-issue-index-path
pnpm installpnpm build
Expected result:
see https://github.com/Timeless0911/api-extractor-issue-index-path/blob/main/dist-expected/index.d.ts
Actual result:
see https://github.com/Timeless0911/api-extractor-issue-index-path/blob/main/dist-actual/index.d.ts
Details
type-fest is a npm package which has a collection of essential TypeScript types that has below file structure:
.
├── index.d.ts
├── package.json
└── source
├── ...
├── delimiter-case.d.ts
├── internal
│ ├── ...
│ └── index.d.ts
└── ...
This repro demo import KebabCase from type-fest
// src/index.ts
import type { KebabCase } from "type-fest";
export function kebabCase<T extends string>(str: T): KebabCase<T> {
return str as KebabCase<T>;
}
The KebabCase type is from source/kebab-case.d.ts which have an import from ./delimiter-case
// source/kebab-case.d.ts
import type {DelimiterCase} from './delimiter-case';
// ....
export type KebabCase<Value> = DelimiterCase<Value, '-'>;
In source/delimiter-case.d.ts file, it import some types from ./internal which should be resolved to ./internal/index.d.ts
// source/delimiter-case.d.ts
import type {UpperCaseCharacters, WordSeparators} from './internal';
The actual result keeps these import from ./internal
import type { UpperCaseCharacters } from './internal';
import type { WordSeparators } from './internal';
I modify the source/delimiter-case.d.ts file to write full path of the importer like below, it works as expected.
- import type {UpperCaseCharacters, WordSeparators} from './internal';
+ import type {UpperCaseCharacters, WordSeparators} from './internal/index';
Since both Node.js and Typescript support index file resolution, I think ./internal should be resolved correctly when rolluping DTS.
Standard questions
Please answer these questions to help us investigate your issue more quickly:
| Question | Answer |
|---|---|
@microsoft/api-extractor version? |
7.47.11 |
| Operating system? | Mac |
| API Extractor scenario? | rollups (.d.ts) |
| Would you consider contributing a PR? | No |
| TypeScript compiler version? | 5.4.2 |
Node.js version (node -v)? |
22.10.0 |