mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-11-18 17:21:48 +00:00
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:
co-authored by
Mateusz Burzyński
Andrew Branch
parent
93e6b9da0c
commit
fbcdb8cf4f
@@ -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));
|
||||
|
||||
Reference in New Issue
Block a user