@@ -18,7 +18,6 @@ namespace ts.moduleSpecifiers {
18
18
const info = getInfo ( compilerOptions , importingSourceFile , importingSourceFileName , host ) ;
19
19
const modulePaths = getAllModulePaths ( files , toFileName , info . getCanonicalFileName , host ) ;
20
20
return firstDefined ( modulePaths , moduleFileName => getGlobalModuleSpecifier ( moduleFileName , info , host , compilerOptions ) ) ||
21
- getGlobalModuleSpecifier ( toFileName , info , host , compilerOptions ) ||
22
21
first ( getLocalModuleSpecifiers ( toFileName , info , compilerOptions , preferences ) ) ;
23
22
}
24
23
@@ -67,19 +66,19 @@ namespace ts.moduleSpecifiers {
67
66
compilerOptions : CompilerOptions ,
68
67
) {
69
68
return tryGetModuleNameFromTypeRoots ( compilerOptions , host , getCanonicalFileName , moduleFileName , addJsExtension )
70
- || tryGetModuleNameAsNodeModule ( compilerOptions , moduleFileName , host , getCanonicalFileName , sourceDirectory )
71
- || compilerOptions . rootDirs && tryGetModuleNameFromRootDirs ( compilerOptions . rootDirs , moduleFileName , sourceDirectory , getCanonicalFileName ) ;
69
+ || tryGetModuleNameAsNodeModule ( compilerOptions , moduleFileName , host , getCanonicalFileName , sourceDirectory ) ;
72
70
}
73
71
74
72
function getLocalModuleSpecifiers (
75
73
moduleFileName : string ,
76
74
{ moduleResolutionKind, addJsExtension, getCanonicalFileName, sourceDirectory } : Info ,
77
75
compilerOptions : CompilerOptions ,
78
76
preferences : ModuleSpecifierPreferences ,
79
- ) {
80
- const { baseUrl, paths } = compilerOptions ;
77
+ ) : ReadonlyArray < string > {
78
+ const { baseUrl, paths, rootDirs } = compilerOptions ;
81
79
82
- const relativePath = removeExtensionAndIndexPostFix ( ensurePathIsNonModuleName ( getRelativePathFromDirectory ( sourceDirectory , moduleFileName , getCanonicalFileName ) ) , moduleResolutionKind , addJsExtension ) ;
80
+ const relativePath = rootDirs && tryGetModuleNameFromRootDirs ( rootDirs , moduleFileName , sourceDirectory , getCanonicalFileName ) ||
81
+ removeExtensionAndIndexPostFix ( ensurePathIsNonModuleName ( getRelativePathFromDirectory ( sourceDirectory , moduleFileName , getCanonicalFileName ) ) , moduleResolutionKind , addJsExtension ) ;
83
82
if ( ! baseUrl || preferences . importModuleSpecifierPreference === "relative" ) {
84
83
return [ relativePath ] ;
85
84
}
0 commit comments