Skip to content

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

Open
PeachScript wants to merge 2 commits into
microsoft:mainfrom
PeachScript:hotfix/export-star-ambient
Open

[api-extractor] Fix error for export star from ambient module#3528
PeachScript wants to merge 2 commits into
microsoft:mainfrom
PeachScript:hotfix/export-star-ambient

Conversation

@PeachScript

Copy link
Copy Markdown

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.

@ghost

ghost commented Jul 10, 2022

Copy link
Copy Markdown

CLA assistant check
All CLA requirements met.


try {
starExportedModule = this._fetchSpecifierAstModule(exportStarDeclaration, exportStarSymbol);
} catch {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this catching Internal Error: getResolvedModule() could not resolve module name? That error is thrown by API Extractor's own implementation. Generally we try to avoid throwing/catching exceptions during normal successful operation.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I explained in the PR description:

Why use try...catch? The TypeScriptHelpers.isAmbient cannot working for this, is there a more precise way than try...catch?

Can you provide a better way to catch that?

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

Successfully merging this pull request may close these issues.

2 participants