rushstack icon indicating copy to clipboard operation
rushstack copied to clipboard

[api-extractor] Fix error for export star from ambient module

Open PeachScript opened this issue 3 years ago • 1 comments

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.

PeachScript avatar Jul 10 '22 10:07 PeachScript

CLA assistant check
All CLA requirements met.

ghost avatar Jul 10 '22 10:07 ghost