Repository navigation
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). |
Nathan Shively-Sanders (sandersn)
left a comment
There was a problem hiding this comment.
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.
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.
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
baseUrlandpathsand symlinks.