@@ -114,7 +114,7 @@ namespace ts.moduleSpecifiers {
114
114
function getLocalModuleSpecifier ( moduleFileName : string , { getCanonicalFileName, sourceDirectory } : Info , compilerOptions : CompilerOptions , { ending, relativePreference } : Preferences ) : string {
115
115
const { baseUrl, paths, rootDirs } = compilerOptions ;
116
116
117
- const relativePath = rootDirs && tryGetModuleNameFromRootDirs ( rootDirs , moduleFileName , sourceDirectory , getCanonicalFileName ) ||
117
+ const relativePath = rootDirs && tryGetModuleNameFromRootDirs ( rootDirs , moduleFileName , sourceDirectory , getCanonicalFileName , ending , compilerOptions ) ||
118
118
removeExtensionAndIndexPostFix ( ensurePathIsNonModuleName ( getRelativePathFromDirectory ( sourceDirectory , moduleFileName , getCanonicalFileName ) ) , ending , compilerOptions ) ;
119
119
if ( ! baseUrl || relativePreference === RelativePreference . Relative ) {
120
120
return relativePath ;
@@ -248,15 +248,17 @@ namespace ts.moduleSpecifiers {
248
248
}
249
249
}
250
250
251
- function tryGetModuleNameFromRootDirs ( rootDirs : ReadonlyArray < string > , moduleFileName : string , sourceDirectory : string , getCanonicalFileName : ( file : string ) => string ) : string | undefined {
251
+ function tryGetModuleNameFromRootDirs ( rootDirs : ReadonlyArray < string > , moduleFileName : string , sourceDirectory : string , getCanonicalFileName : ( file : string ) => string , ending : Ending , compilerOptions : CompilerOptions ) : string | undefined {
252
252
const normalizedTargetPath = getPathRelativeToRootDirs ( moduleFileName , rootDirs , getCanonicalFileName ) ;
253
253
if ( normalizedTargetPath === undefined ) {
254
254
return undefined ;
255
255
}
256
256
257
257
const normalizedSourcePath = getPathRelativeToRootDirs ( sourceDirectory , rootDirs , getCanonicalFileName ) ;
258
258
const relativePath = normalizedSourcePath !== undefined ? ensurePathIsNonModuleName ( getRelativePathFromDirectory ( normalizedSourcePath , normalizedTargetPath , getCanonicalFileName ) ) : normalizedTargetPath ;
259
- return removeFileExtension ( relativePath ) ;
259
+ return getEmitModuleResolutionKind ( compilerOptions ) === ModuleResolutionKind . NodeJs
260
+ ? removeExtensionAndIndexPostFix ( relativePath , ending , compilerOptions )
261
+ : removeFileExtension ( relativePath ) ;
260
262
}
261
263
262
264
function tryGetModuleNameAsNodeModule ( moduleFileName : string , { getCanonicalFileName, sourceDirectory } : Info , host : ModuleSpecifierResolutionHost , options : CompilerOptions ) : string | undefined {
0 commit comments