@@ -29,6 +29,15 @@ namespace ts {
29
29
path : string ;
30
30
extension : Extension ;
31
31
packageId : PackageId | undefined ;
32
+ /**
33
+ * When the resolved is not created from cache, the value is
34
+ * - string if original Path if it is symbolic link to the resolved path
35
+ * - undefined if path is not a symbolic link
36
+ * When the resolved is created using value from cache of ResolvedModuleWithFailedLookupLocations, the value is:
37
+ * - string if original Path if it is symbolic link to the resolved path
38
+ * - true if path is not a symbolic link - this indicates that the originalPath calculation is already done and needs to be skipped
39
+ */
40
+ originalPath ?: string | true ;
32
41
}
33
42
34
43
/** Result of trying to resolve a module at a file. Needs to have 'packageId' added later. */
@@ -62,9 +71,9 @@ namespace ts {
62
71
return { fileName : resolved . path , packageId : resolved . packageId } ;
63
72
}
64
73
65
- function createResolvedModuleWithFailedLookupLocations ( resolved : Resolved | undefined , originalPath : string | undefined , isExternalLibraryImport : boolean , failedLookupLocations : string [ ] ) : ResolvedModuleWithFailedLookupLocations {
74
+ function createResolvedModuleWithFailedLookupLocations ( resolved : Resolved | undefined , isExternalLibraryImport : boolean , failedLookupLocations : string [ ] ) : ResolvedModuleWithFailedLookupLocations {
66
75
return {
67
- resolvedModule : resolved && { resolvedFileName : resolved . path , originalPath, extension : resolved . extension , isExternalLibraryImport, packageId : resolved . packageId } ,
76
+ resolvedModule : resolved && { resolvedFileName : resolved . path , originalPath : resolved . originalPath === true ? undefined : resolved . originalPath , extension : resolved . extension , isExternalLibraryImport, packageId : resolved . packageId } ,
68
77
failedLookupLocations
69
78
} ;
70
79
}
@@ -751,12 +760,12 @@ namespace ts {
751
760
tryResolve ( Extensions . JavaScript ) ||
752
761
( compilerOptions . resolveJsonModule ? tryResolve ( Extensions . Json ) : undefined ) ) ;
753
762
if ( result && result . value ) {
754
- const { resolved, originalPath , isExternalLibraryImport } = result . value ;
755
- return createResolvedModuleWithFailedLookupLocations ( resolved , originalPath , isExternalLibraryImport , failedLookupLocations ) ;
763
+ const { resolved, isExternalLibraryImport } = result . value ;
764
+ return createResolvedModuleWithFailedLookupLocations ( resolved , isExternalLibraryImport , failedLookupLocations ) ;
756
765
}
757
766
return { resolvedModule : undefined , failedLookupLocations } ;
758
767
759
- function tryResolve ( extensions : Extensions ) : SearchResult < { resolved : Resolved , originalPath ?: string , isExternalLibraryImport : boolean } > {
768
+ function tryResolve ( extensions : Extensions ) : SearchResult < { resolved : Resolved , isExternalLibraryImport : boolean } > {
760
769
const loader : ResolutionKindSpecificLoader = ( extensions , candidate , failedLookupLocations , onlyRecordFailures , state ) => nodeLoadModuleByRelativeName ( extensions , candidate , failedLookupLocations , onlyRecordFailures , state , /*considerPackageJson*/ true ) ;
761
770
const resolved = tryLoadModuleUsingOptionalResolutionSettings ( extensions , moduleName , containingDirectory , loader , failedLookupLocations , state ) ;
762
771
if ( resolved ) {
@@ -771,17 +780,13 @@ namespace ts {
771
780
if ( ! resolved ) return undefined ;
772
781
773
782
let resolvedValue = resolved . value ;
774
- let originalPath : string | undefined ;
775
- if ( ! compilerOptions . preserveSymlinks && resolvedValue ) {
776
- originalPath = resolvedValue . path ;
783
+ if ( ! compilerOptions . preserveSymlinks && resolvedValue && ! resolvedValue . originalPath ) {
777
784
const path = realPath ( resolvedValue . path , host , traceEnabled ) ;
778
- if ( path === originalPath ) {
779
- originalPath = undefined ;
780
- }
781
- resolvedValue = { ...resolvedValue , path } ;
785
+ const originalPath = path === resolvedValue . path ? undefined : resolvedValue . path ;
786
+ resolvedValue = { ...resolvedValue , path, originalPath } ;
782
787
}
783
788
// For node_modules lookups, get the real path so that multiple accesses to an `npm link`-ed module do not create duplicate files.
784
- return { value : resolvedValue && { resolved : resolvedValue , originalPath , isExternalLibraryImport : true } } ;
789
+ return { value : resolvedValue && { resolved : resolvedValue , isExternalLibraryImport : true } } ;
785
790
}
786
791
else {
787
792
const { path : candidate , parts } = normalizePathAndParts ( combinePaths ( containingDirectory , moduleName ) ) ;
@@ -1231,7 +1236,7 @@ namespace ts {
1231
1236
trace ( host , Diagnostics . Resolution_for_module_0_was_found_in_cache_from_location_1 , moduleName , containingDirectory ) ;
1232
1237
}
1233
1238
failedLookupLocations . push ( ...result . failedLookupLocations ) ;
1234
- return { value : result . resolvedModule && { path : result . resolvedModule . resolvedFileName , extension : result . resolvedModule . extension , packageId : result . resolvedModule . packageId } } ;
1239
+ return { value : result . resolvedModule && { path : result . resolvedModule . resolvedFileName , originalPath : result . resolvedModule . originalPath || true , extension : result . resolvedModule . extension , packageId : result . resolvedModule . packageId } } ;
1235
1240
}
1236
1241
}
1237
1242
@@ -1243,7 +1248,7 @@ namespace ts {
1243
1248
1244
1249
const resolved = tryResolve ( Extensions . TypeScript ) || tryResolve ( Extensions . JavaScript ) ;
1245
1250
// No originalPath because classic resolution doesn't resolve realPath
1246
- return createResolvedModuleWithFailedLookupLocations ( resolved && resolved . value , /*originalPath*/ undefined , /* isExternalLibraryImport*/ false , failedLookupLocations ) ;
1251
+ return createResolvedModuleWithFailedLookupLocations ( resolved && resolved . value , /*isExternalLibraryImport*/ false , failedLookupLocations ) ;
1247
1252
1248
1253
function tryResolve ( extensions : Extensions ) : SearchResult < Resolved > {
1249
1254
const resolvedUsingSettings = tryLoadModuleUsingOptionalResolutionSettings ( extensions , moduleName , containingDirectory , loadModuleFromFileNoPackageId , failedLookupLocations , state ) ;
@@ -1290,7 +1295,7 @@ namespace ts {
1290
1295
const state : ModuleResolutionState = { compilerOptions, host, traceEnabled } ;
1291
1296
const failedLookupLocations : string [ ] = [ ] ;
1292
1297
const resolved = loadModuleFromNodeModulesOneLevel ( Extensions . DtsOnly , moduleName , globalCache , failedLookupLocations , state ) ;
1293
- return createResolvedModuleWithFailedLookupLocations ( resolved , /*originalPath*/ undefined , /* isExternalLibraryImport*/ true , failedLookupLocations ) ;
1298
+ return createResolvedModuleWithFailedLookupLocations ( resolved , /*isExternalLibraryImport*/ true , failedLookupLocations ) ;
1294
1299
}
1295
1300
1296
1301
/**
0 commit comments