mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-17 01:49:57 -05:00
Make specifier generation from export map information conditional on module resolution mode (#46670)
This commit is contained in:
@@ -707,13 +707,15 @@ namespace ts.moduleSpecifiers {
|
||||
if (host.fileExists(packageJsonPath)) {
|
||||
const packageJsonContent = JSON.parse(host.readFile!(packageJsonPath)!);
|
||||
// TODO: Inject `require` or `import` condition based on the intended import mode
|
||||
const fromExports = packageJsonContent.exports && typeof packageJsonContent.name === "string" ? tryGetModuleNameFromExports(options, path, packageRootPath, packageJsonContent.name, packageJsonContent.exports, ["node", "types"]) : undefined;
|
||||
if (fromExports) {
|
||||
const withJsExtension = !hasTSFileExtension(fromExports.moduleFileToTry) ? fromExports : { moduleFileToTry: removeFileExtension(fromExports.moduleFileToTry) + tryGetJSExtensionForFile(fromExports.moduleFileToTry, options) };
|
||||
return { ...withJsExtension, verbatimFromExports: true };
|
||||
}
|
||||
if (packageJsonContent.exports) {
|
||||
return { moduleFileToTry: path, blockedByExports: true };
|
||||
if (getEmitModuleResolutionKind(options) === ModuleResolutionKind.Node12 || getEmitModuleResolutionKind(options) === ModuleResolutionKind.NodeNext) {
|
||||
const fromExports = packageJsonContent.exports && typeof packageJsonContent.name === "string" ? tryGetModuleNameFromExports(options, path, packageRootPath, packageJsonContent.name, packageJsonContent.exports, ["node", "types"]) : undefined;
|
||||
if (fromExports) {
|
||||
const withJsExtension = !hasTSFileExtension(fromExports.moduleFileToTry) ? fromExports : { moduleFileToTry: removeFileExtension(fromExports.moduleFileToTry) + tryGetJSExtensionForFile(fromExports.moduleFileToTry, options) };
|
||||
return { ...withJsExtension, verbatimFromExports: true };
|
||||
}
|
||||
if (packageJsonContent.exports) {
|
||||
return { moduleFileToTry: path, blockedByExports: true };
|
||||
}
|
||||
}
|
||||
const versionPaths = packageJsonContent.typesVersions
|
||||
? getPackageJsonTypesVersionsPaths(packageJsonContent.typesVersions)
|
||||
|
||||
Reference in New Issue
Block a user