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] Fix error for export star from ambient module #3528

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

PeachScript
Copy link

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
Copy link

ghost commented Jul 10, 2022

CLA assistant check
All CLA requirements met.


try {
starExportedModule = this._fetchSpecifierAstModule(exportStarDeclaration, exportStarSymbol);
} catch {
Copy link
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
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.

None yet

2 participants