@@ -64,9 +64,9 @@ namespace ts {
64
64
return { fileName : resolved . path , packageId : resolved . packageId } ;
65
65
}
66
66
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 {
68
68
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 } ,
70
70
failedLookupLocations
71
71
} ;
72
72
}
@@ -732,12 +732,12 @@ namespace ts {
732
732
733
733
const result = jsOnly ? tryResolve ( Extensions . JavaScript ) : ( tryResolve ( Extensions . TypeScript ) || tryResolve ( Extensions . JavaScript ) ) ;
734
734
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 ) ;
737
737
}
738
738
return { resolvedModule : undefined , failedLookupLocations } ;
739
739
740
- function tryResolve ( extensions : Extensions ) : SearchResult < { resolved : Resolved , isExternalLibraryImport : boolean } > {
740
+ function tryResolve ( extensions : Extensions ) : SearchResult < { resolved : Resolved , originalPath ?: string , isExternalLibraryImport : boolean } > {
741
741
const loader : ResolutionKindSpecificLoader = ( extensions , candidate , failedLookupLocations , onlyRecordFailures , state ) => nodeLoadModuleByRelativeName ( extensions , candidate , failedLookupLocations , onlyRecordFailures , state , /*considerPackageJson*/ true ) ;
742
742
const resolved = tryLoadModuleUsingOptionalResolutionSettings ( extensions , moduleName , containingDirectory , loader , failedLookupLocations , state ) ;
743
743
if ( resolved ) {
@@ -752,11 +752,17 @@ namespace ts {
752
752
if ( ! resolved ) return undefined ;
753
753
754
754
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 } ;
757
763
}
758
764
// 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 } } ;
760
766
}
761
767
else {
762
768
const { path : candidate , parts } = normalizePathAndParts ( combinePaths ( containingDirectory , moduleName ) ) ;
@@ -1115,7 +1121,8 @@ namespace ts {
1115
1121
const containingDirectory = getDirectoryPath ( containingFile ) ;
1116
1122
1117
1123
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 ) ;
1119
1126
1120
1127
function tryResolve ( extensions : Extensions ) : SearchResult < Resolved > {
1121
1128
const resolvedUsingSettings = tryLoadModuleUsingOptionalResolutionSettings ( extensions , moduleName , containingDirectory , loadModuleFromFileNoPackageId , failedLookupLocations , state ) ;
@@ -1162,7 +1169,7 @@ namespace ts {
1162
1169
const state : ModuleResolutionState = { compilerOptions, host, traceEnabled } ;
1163
1170
const failedLookupLocations : string [ ] = [ ] ;
1164
1171
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 ) ;
1166
1173
}
1167
1174
1168
1175
/**
0 commit comments