rushstack
rushstack copied to clipboard
[api-extractor] Fix error for export star from ambient module
Summary
Handle export * from '<ambient module>' when rollup .d.ts.
For example, there has export * from 'fs' statement in the @types/fs-extra, and the fs is an ambient module of @types/node, we will get the following error when running api-extractor:
InternalError: Internal Error: getResolvedModule() could not resolve module name "fs"
Ref issue: #3335 Ref PR: #3339
Details
The solutions is, catch the resolve error and fallback to append a fake external AstModule, then handle it in the _collectAllExportsRecursive method.
Why use try...catch? The TypeScriptHelpers.isAmbient cannot working for this, is there a more precise way than try...catch?
How it was tested
Add export * from 'fs' into build-tests/api-extractor-scenarios/src/exportStar2/index.ts, and make sure it can be rollup successfully.