microsoft / rushstack

Monorepo for tools developed by the Rush Stack community
https://rushstack.io/
Other
5.93k stars 597 forks source link

[api-extractor] Imports are not correctly "trimmed" in rollups nor report variants #4861

Open Josmithr opened 3 months ago

Josmithr commented 3 months ago

Currently, neither generated rollups nor API report "variants" trim their imports to only those referenced by their "trimmed" exports. This results in unnecessary file bloat in both cases, and unnecessary noise in the case of API reports (e.g., reports change when unused imports change, even when there are no export changes).

For a repro of the issue, see here: https://github.com/Josmithr/api-extractor-playground/tree/import-trimming-issue

Standard questions

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

Question Answer
@microsoft/api-extractor version? 7.47.5
Operating system? Linux
API Extractor scenario?
Would you consider contributing a PR? Yes
TypeScript compiler version? 5.5.2
Node.js version (node -v)? 20.15.1
Josmithr commented 3 months ago

@octogonz I looked briefly into your suggestion to modify _fetchAstImport to track the most-public export that references a given import, but it doesn't appear that there is sufficient to get that information at that layer in the system. Seems like this needs further design consideration. Happy to contribute to this, but I think it merits deeper consideration before I proceed any further.