mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-21 18:22:58 -05:00
Apart from typing, use main field in package json to resolve typescript files
Fixes #23502
This commit is contained in:
@@ -1049,9 +1049,18 @@ namespace ts {
|
||||
}
|
||||
|
||||
function loadModuleFromPackageJson(jsonContent: PackageJsonPathFields, extensions: Extensions, candidate: string, failedLookupLocations: Push<string>, state: ModuleResolutionState): PathAndExtension | undefined {
|
||||
const file = tryReadPackageJsonFields(extensions !== Extensions.JavaScript && extensions !== Extensions.Json, jsonContent, candidate, state);
|
||||
let file = tryReadPackageJsonFields(extensions !== Extensions.JavaScript && extensions !== Extensions.Json, jsonContent, candidate, state);
|
||||
if (!file) {
|
||||
return undefined;
|
||||
if (extensions === Extensions.TypeScript) {
|
||||
// When resolving typescript modules, try resolving using main field as well
|
||||
file = tryReadPackageJsonFields(/*readTypes*/ false, jsonContent, candidate, state);
|
||||
if (!file) {
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
else {
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
|
||||
const onlyRecordFailures = !directoryProbablyExists(getDirectoryPath(file), state.host);
|
||||
|
||||
@@ -181,6 +181,13 @@ namespace ts {
|
||||
"/a/b/foo.ts",
|
||||
"/a/b/foo.tsx",
|
||||
"/a/b/foo.d.ts",
|
||||
"/c/d",
|
||||
"/c/d.ts",
|
||||
"/c/d.tsx",
|
||||
"/c/d.d.ts",
|
||||
"/c/d/index.ts",
|
||||
"/c/d/index.tsx",
|
||||
"/c/d/index.d.ts",
|
||||
"/a/b/foo/index.ts",
|
||||
"/a/b/foo/index.tsx",
|
||||
]);
|
||||
|
||||
Reference in New Issue
Block a user