-
Notifications
You must be signed in to change notification settings - Fork 12.5k
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
Avoid auto-importing from barrel re-exporting index files that are likely to make an import cycle #47516
Conversation
…kely to make an import cycle
If this is specifically just de-prioritizing stuff like |
This is not looking for computed module specifiers, but it does treat files named "index" specially. See the conversation near the end of the linked issue. Only |
That's fair, you're not as likely to have |
It’s not alphabetical sorting, it’s program order, so re-exports come second unless there’s a reason to prefer them (i.e. fewer directory separators). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Basic idea sounds right to me. The code looks good as far as I am familiar with it -- but I have to relearn it a bit every time.
function sortFixes(fixes: readonly ImportFixWithModuleSpecifier[], sourceFile: SourceFile, program: Program, packageJsonImportFilter: PackageJsonImportFilter): readonly ImportFixWithModuleSpecifier[] { | ||
return sort(fixes, (a, b) => compareValues(a.kind, b.kind) || compareModuleSpecifiers(a, b, sourceFile, program, packageJsonImportFilter.allowsImportingSpecifier)); | ||
function sortFixes(fixes: readonly ImportFixWithModuleSpecifier[], sourceFile: SourceFile, program: Program, packageJsonImportFilter: PackageJsonImportFilter, host: LanguageServiceHost): readonly ImportFixWithModuleSpecifier[] { | ||
const _toPath = (fileName: string) => toPath(fileName, host.getCurrentDirectory(), hostGetCanonicalFileName(host)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
toPath
is used as a way to get the current directory and getCanonicalFileName
from the provided host as far as I can tell. Is that basically right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah. I think the current directory is never used in practice in this context. What it’s going to do is lowercase stuff.
Fixes #45953
Slightly better version of #47432
Essentially the same logic as #47432, but does it by file location rather than computed module specifier to allow for non-relative specifier preferences with
baseUrl
andpaths
and symlinks.