Skip to content
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

[api-extractor] Inline imports sometimes incorrectly hoisted (unmodified) into rollups #4507

Open
Josmithr opened this issue Feb 1, 2024 · 1 comment

Comments

@Josmithr
Copy link
Contributor

Josmithr commented Feb 1, 2024

There are cases where TSC decides it's okay to inline import calls.
In most cases, API-Extractor seems to handle these correctly when generating its rollups, but there are some cases where it fails to do so, potentially hoisting relative file path imports as-is into the rollup.

A contrived example

A package contains the following file structure:

src
* index.ts
* Bar.ts
* foo
  * Foo.ts
 ```

Bar.ts
```typescript
export enum Bar {
	A = 'A',
}

foo/Foo.ts

export type Foo = import('../Bar').Bar.A;

index.ts

export { Foo } from './foo/Foo';

TSC generates the following foo/Foo.d.ts:

export type Foo = import('../Bar').Bar.A;

API-Extractor then generates the following (untrimmed) rollup:

export declare type Foo = import('../Bar').Bar.A;

Note that the untrimmed rollup file lives one level higher in the directory hierarchy than foo, but it hoisted the ../Bar import unmodified, resulting in an invalid rollup.

 
The above example has also been captured here: https://github.com/Josmithr/api-extractor-playground/tree/relative-path-import-repro

Standard questions

Please answer these questions to help us investigate your issue more quickly:

Question Answer
@microsoft/api-extractor version? 7.39.4
Operating system? Linux
API Extractor scenario? rollups (.d.ts)
Would you consider contributing a PR? Yes
TypeScript compiler version? 5.3.2
Node.js version (node -v)? 20.11.0
@Josmithr
Copy link
Contributor Author

Josmithr commented Feb 1, 2024

@octogonz In our last chat, we discussed this issue (or at least a manifestation of it). I was finally able to minify a repro, which I've outlined above and in a sandbox here: https://github.com/Josmithr/api-extractor-playground/tree/relative-path-import-repro.

Let me know if you have any questions.

Josmithr added a commit to microsoft/FluidFramework that referenced this issue Feb 2, 2024
…o related github issue (#19465)

Adds additional workaround for existing issue, and links to
microsoft/rushstack#4507
alexvy86 pushed a commit to alexvy86/FluidFramework that referenced this issue Feb 13, 2024
…o related github issue (microsoft#19465)

Adds additional workaround for existing issue, and links to
microsoft/rushstack#4507
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: AE/AD
Development

No branches or pull requests

1 participant