@@ -64,9 +64,9 @@ namespace ts {
6464 return { fileName : resolved . path , packageId : resolved . packageId } ;
6565 }
6666
67- function createResolvedModuleWithFailedLookupLocations ( resolved : Resolved | undefined , isExternalLibraryImport : boolean , failedLookupLocations : string [ ] ) : ResolvedModuleWithFailedLookupLocations {
67+ function createResolvedModuleWithFailedLookupLocations ( resolved : Resolved | undefined , originalPath : string | undefined , isExternalLibraryImport : boolean , failedLookupLocations : string [ ] ) : ResolvedModuleWithFailedLookupLocations {
6868 return {
69- resolvedModule : resolved && { resolvedFileName : resolved . path , extension : resolved . extension , isExternalLibraryImport, packageId : resolved . packageId } ,
69+ resolvedModule : resolved && { resolvedFileName : resolved . path , originalPath , extension : resolved . extension , isExternalLibraryImport, packageId : resolved . packageId } ,
7070 failedLookupLocations
7171 } ;
7272 }
@@ -732,12 +732,12 @@ namespace ts {
732732
733733 const result = jsOnly ? tryResolve ( Extensions . JavaScript ) : ( tryResolve ( Extensions . TypeScript ) || tryResolve ( Extensions . JavaScript ) ) ;
734734 if ( result && result . value ) {
735- const { resolved, isExternalLibraryImport } = result . value ;
736- return createResolvedModuleWithFailedLookupLocations ( resolved , isExternalLibraryImport , failedLookupLocations ) ;
735+ const { resolved, originalPath , isExternalLibraryImport } = result . value ;
736+ return createResolvedModuleWithFailedLookupLocations ( resolved , originalPath , isExternalLibraryImport , failedLookupLocations ) ;
737737 }
738738 return { resolvedModule : undefined , failedLookupLocations } ;
739739
740- function tryResolve ( extensions : Extensions ) : SearchResult < { resolved : Resolved , isExternalLibraryImport : boolean } > {
740+ function tryResolve ( extensions : Extensions ) : SearchResult < { resolved : Resolved , originalPath ?: string , isExternalLibraryImport : boolean } > {
741741 const loader : ResolutionKindSpecificLoader = ( extensions , candidate , failedLookupLocations , onlyRecordFailures , state ) => nodeLoadModuleByRelativeName ( extensions , candidate , failedLookupLocations , onlyRecordFailures , state , /*considerPackageJson*/ true ) ;
742742 const resolved = tryLoadModuleUsingOptionalResolutionSettings ( extensions , moduleName , containingDirectory , loader , failedLookupLocations , state ) ;
743743 if ( resolved ) {
@@ -752,11 +752,17 @@ namespace ts {
752752 if ( ! resolved ) return undefined ;
753753
754754 let resolvedValue = resolved . value ;
755- if ( ! compilerOptions . preserveSymlinks ) {
756- resolvedValue = resolvedValue && { ...resolved . value , path : realPath ( resolved . value . path , host , traceEnabled ) , extension : resolved . value . extension } ;
755+ let originalPath : string | undefined ;
756+ if ( ! compilerOptions . preserveSymlinks && resolvedValue ) {
757+ originalPath = resolvedValue . path ;
758+ const path = realPath ( resolved . value . path , host , traceEnabled ) ;
759+ if ( path === originalPath ) {
760+ originalPath = undefined ;
761+ }
762+ resolvedValue = { ...resolvedValue , path } ;
757763 }
758764 // For node_modules lookups, get the real path so that multiple accesses to an `npm link`-ed module do not create duplicate files.
759- return { value : resolvedValue && { resolved : resolvedValue , isExternalLibraryImport : true } } ;
765+ return { value : resolvedValue && { resolved : resolvedValue , originalPath , isExternalLibraryImport : true } } ;
760766 }
761767 else {
762768 const { path : candidate , parts } = normalizePathAndParts ( combinePaths ( containingDirectory , moduleName ) ) ;
@@ -1115,7 +1121,8 @@ namespace ts {
11151121 const containingDirectory = getDirectoryPath ( containingFile ) ;
11161122
11171123 const resolved = tryResolve ( Extensions . TypeScript ) || tryResolve ( Extensions . JavaScript ) ;
1118- return createResolvedModuleWithFailedLookupLocations ( resolved && resolved . value , /*isExternalLibraryImport*/ false , failedLookupLocations ) ;
1124+ // No originalPath because classic resolution doesn't resolve realPath
1125+ return createResolvedModuleWithFailedLookupLocations ( resolved && resolved . value , /*originalPath*/ undefined , /*isExternalLibraryImport*/ false , failedLookupLocations ) ;
11191126
11201127 function tryResolve ( extensions : Extensions ) : SearchResult < Resolved > {
11211128 const resolvedUsingSettings = tryLoadModuleUsingOptionalResolutionSettings ( extensions , moduleName , containingDirectory , loadModuleFromFileNoPackageId , failedLookupLocations , state ) ;
@@ -1162,7 +1169,7 @@ namespace ts {
11621169 const state : ModuleResolutionState = { compilerOptions, host, traceEnabled } ;
11631170 const failedLookupLocations : string [ ] = [ ] ;
11641171 const resolved = loadModuleFromNodeModulesOneLevel ( Extensions . DtsOnly , moduleName , globalCache , failedLookupLocations , state ) ;
1165- return createResolvedModuleWithFailedLookupLocations ( resolved , /*isExternalLibraryImport*/ true , failedLookupLocations ) ;
1172+ return createResolvedModuleWithFailedLookupLocations ( resolved , /*originalPath*/ undefined , /* isExternalLibraryImport*/ true , failedLookupLocations ) ;
11661173 }
11671174
11681175 /**
0 commit comments