@@ -887,6 +887,8 @@ namespace ts {
887
887
// Key is a file name. Value is the (non-empty, or undefined) list of files that redirect to it.
888
888
let redirectTargetsMap = createMultiMap < Path , string > ( ) ;
889
889
let usesUriStyleNodeCoreModules = false ;
890
+ // Used when resolving something like 'dom' for libs
891
+ // const libResolveCache = createModuleResolutionCache(currentDirectory, host.getCanonicalFileName, { moduleResolution: ModuleResolutionKind.NodeJs });
890
892
891
893
/**
892
894
* map with
@@ -995,7 +997,7 @@ namespace ts {
995
997
}
996
998
else {
997
999
forEach ( options . lib , ( libFileName , index ) => {
998
- processRootFile ( combinePaths ( defaultLibraryPath , libFileName ) , /*isDefaultLib*/ true , /*ignoreNoDefaultLib*/ false , { kind : FileIncludeKind . LibFile , index } ) ;
1000
+ processRootFile ( pathForLibFile ( libFileName ) , /*isDefaultLib*/ true , /*ignoreNoDefaultLib*/ false , { kind : FileIncludeKind . LibFile , index } ) ;
999
1001
} ) ;
1000
1002
}
1001
1003
}
@@ -1737,7 +1739,7 @@ namespace ts {
1737
1739
return equalityComparer ( file . fileName , getDefaultLibraryFileName ( ) ) ;
1738
1740
}
1739
1741
else {
1740
- return some ( options . lib , libFileName => equalityComparer ( file . fileName , combinePaths ( defaultLibraryPath , libFileName ) ) ) ;
1742
+ return some ( options . lib , libFileName => equalityComparer ( file . fileName , pathForLibFile ( libFileName ) ) ) ;
1741
1743
}
1742
1744
}
1743
1745
@@ -2406,7 +2408,7 @@ namespace ts {
2406
2408
const libName = toFileNameLowerCase ( ref . fileName ) ;
2407
2409
const libFileName = libMap . get ( libName ) ;
2408
2410
if ( libFileName ) {
2409
- return getSourceFile ( combinePaths ( defaultLibraryPath , libFileName ) ) ;
2411
+ return getSourceFile ( pathForLibFile ( libFileName ) ) ;
2410
2412
}
2411
2413
}
2412
2414
@@ -2883,13 +2885,32 @@ namespace ts {
2883
2885
}
2884
2886
}
2885
2887
2888
+ function pathForLibFile ( libFileName : string ) : string {
2889
+ // Support resolving to lib.dom.d.ts -> @typescript/dom, and
2890
+ // lib.dom.iterable.d.ts -> @typescript/dom/iterable
2891
+ // lib.es2015.symbol.wellknown.d.ts -> @typescript/es2015/symbol-wellknown
2892
+ const components = libFileName . split ( "." ) ;
2893
+ let path = components [ 1 ] ;
2894
+ let i = 2 ;
2895
+ while ( components [ i ] && components [ i ] !== "d" ) {
2896
+ path += ( i === 2 ? "/" : "-" ) + components [ i ] ;
2897
+ i ++ ;
2898
+ }
2899
+ // const localOverride = resolveModuleNameFromCache("@typescript/" + path, currentDirectory, libResolveCache);
2900
+ const localOverride = resolveModuleName ( "@typescript/" + path , currentDirectory , { moduleResolution : ModuleResolutionKind . NodeJs } , host ) ;
2901
+ if ( localOverride ?. resolvedModule ) {
2902
+ return localOverride . resolvedModule . resolvedFileName ;
2903
+ }
2904
+ return combinePaths ( defaultLibraryPath , libFileName ) ;
2905
+ }
2906
+
2886
2907
function processLibReferenceDirectives ( file : SourceFile ) {
2887
2908
forEach ( file . libReferenceDirectives , ( libReference , index ) => {
2888
2909
const libName = toFileNameLowerCase ( libReference . fileName ) ;
2889
2910
const libFileName = libMap . get ( libName ) ;
2890
2911
if ( libFileName ) {
2891
2912
// we ignore any 'no-default-lib' reference set on this file.
2892
- processRootFile ( combinePaths ( defaultLibraryPath , libFileName ) , /*isDefaultLib*/ true , /*ignoreNoDefaultLib*/ true , { kind : FileIncludeKind . LibReferenceDirective , file : file . path , index, } ) ;
2913
+ processRootFile ( pathForLibFile ( libFileName ) , /*isDefaultLib*/ true , /*ignoreNoDefaultLib*/ true , { kind : FileIncludeKind . LibReferenceDirective , file : file . path , index, } ) ;
2893
2914
}
2894
2915
else {
2895
2916
const unqualifiedLibName = removeSuffix ( removePrefix ( libName , "lib." ) , ".d.ts" ) ;
0 commit comments