Add auto-import for the package.json imports field (#55015)

Co-authored-by: Mateusz Burzyński <mateuszburzynski@gmail.com>
Co-authored-by: Andrew Branch <andrew@wheream.io>
This commit is contained in:
Emma Hamilton
2023-12-21 09:48:03 -08:00
committed by GitHub
co-authored by Mateusz Burzyński Andrew Branch
parent 93e6b9da0c
commit fbcdb8cf4f
35 changed files with 2298 additions and 69 deletions
+2 -9
View File
@@ -362,6 +362,7 @@ import {
tokenToString,
toPath,
tryCast,
tryParseJson,
Type,
TypeChecker,
TypeFlags,
@@ -2473,6 +2474,7 @@ export function createModuleSpecifierResolutionHost(program: Program, host: Lang
isSourceOfProjectReferenceRedirect: fileName => program.isSourceOfProjectReferenceRedirect(fileName),
getNearestAncestorDirectoryWithPackageJson: maybeBind(host, host.getNearestAncestorDirectoryWithPackageJson),
getFileIncludeReasons: () => program.getFileIncludeReasons(),
getCommonSourceDirectory: () => program.getCommonSourceDirectory(),
};
}
@@ -3895,15 +3897,6 @@ export function createPackageJsonImportFilter(fromFile: SourceFile, preferences:
}
}
function tryParseJson(text: string) {
try {
return JSON.parse(text);
}
catch {
return undefined;
}
}
/** @internal */
export function consumesNodeCoreModules(sourceFile: SourceFile): boolean {
return some(sourceFile.imports, ({ text }) => JsTyping.nodeCoreModules.has(text));