Skip to content

Process package.json exports with auto-import provider #47092

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

Merged

Conversation

andrewbranch
Copy link
Member

Significantly changes the package.json auto-import provider’s resolution process. Previously it used resolveTypeReferenceDirective with a fallback to tryResolveJsModule for JS projects. Using resolveTypeReferenceDirective was close but not quite right, so this fixes a couple straight up bugs, and also gives us the opportunity to pull in all files specifically referenced by an export map so those can be offered as auto-imports too. (Files matching a pattern export aren’t pulled in.)

Fixes #47009

@typescript-bot typescript-bot added the For Milestone Bug PRs that fix a bug with a specific milestone label Dec 9, 2021
@andrewbranch andrewbranch requested a review from sandersn December 9, 2021 22:42
//// { "dependencies": { "mylib": "file:packages/mylib" } }

// @Filename: /packages/mylib/package.json
//// { "name": "mylib", "version": "1.0.0" }
Copy link
Member Author

Choose a reason for hiding this comment

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

The diff between this test and autoImportProvider7.ts demonstrates a bug fixed by no longer using resolveTypeReferenceDirective:

- //// { "name": "mylib", "version": "1.0.0", "main": "index.js", "types": "index" }
+ //// { "name": "mylib", "version": "1.0.0" }

The test previously needed "types": "index" (required to have no extension) to work, due to a quirk of type reference directive resolution.

}
}

return packageJsonInfo.resolvedEntrypoints = entrypoints || false;
Copy link
Member Author

Choose a reason for hiding this comment

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

Calling this function caches its results on the PackageJsonInfo, which itself is stored in the PackageJsonInfoCache which is part of the ModuleResolutionCache—open to suggestions for a cleaner place to put this if there are objections.

@andrewbranch andrewbranch force-pushed the auto-import-provider-resolution branch from 68f312c to f18e95d Compare December 14, 2021 20:15
Copy link
Member

@sandersn sandersn left a comment

Choose a reason for hiding this comment

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

I read over the changes and didn't come up with anything but some style comments. If you need another reviewer I'll need a background explanation for the code (again -- I think you explained it all to me last year or so).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Author: Team For Milestone Bug PRs that fix a bug with a specific milestone
Projects
None yet
Development

Successfully merging this pull request may close these issues.

No auto-imports from exports fields apart from .
4 participants