@@ -734,6 +734,11 @@ export class ProjectConfiguration {
734
734
*/
735
735
private expectedFilePaths = new Set < string > ( ) ;
736
736
737
+ /**
738
+ * List of resolved extra root directories to allow global typings to be loaded from.
739
+ */
740
+ private typeRoots : string [ ] ;
741
+
737
742
/**
738
743
* @param fs file system to use
739
744
* @param documentRegistry Shared DocumentRegistry that manages SourceFile objects
@@ -838,6 +843,10 @@ export class ProjectConfiguration {
838
843
this . expectedFilePaths = new Set ( configParseResult . fileNames ) ;
839
844
840
845
const options = configParseResult . options ;
846
+ this . typeRoots = options . typeRoots ?
847
+ options . typeRoots . map ( ( r : string ) => path . resolve ( this . rootFilePath , r ) ) :
848
+ [ ] ;
849
+
841
850
if ( / ( ^ | \/ ) j s c o n f i g \. j s o n $ / . test ( this . configFilePath ) ) {
842
851
options . allowJs = true ;
843
852
}
@@ -864,6 +873,17 @@ export class ProjectConfiguration {
864
873
865
874
private ensuredBasicFiles = false ;
866
875
876
+ private isTypeRootDeclaration ( path : string ) {
877
+ if ( isDeclarationFile ( path ) ) {
878
+ for ( const base of this . typeRoots ) {
879
+ if ( path . startsWith ( base ) ) {
880
+ return true ;
881
+ }
882
+ }
883
+ }
884
+ return false ;
885
+ }
886
+
867
887
/**
868
888
* Ensures we added basic files (global TS files, dependencies, declarations)
869
889
*/
@@ -882,7 +902,9 @@ export class ProjectConfiguration {
882
902
// Add all global declaration files from the workspace and all declarations from the project
883
903
for ( const uri of this . fs . uris ( ) ) {
884
904
const fileName = uri2path ( uri ) ;
885
- if ( isGlobalTSFile ( fileName ) || ( isDeclarationFile ( fileName ) && this . expectedFilePaths . has ( toUnixPath ( fileName ) ) ) ) {
905
+ if ( isGlobalTSFile ( fileName ) ||
906
+ this . isTypeRootDeclaration ( fileName ) ||
907
+ ( isDeclarationFile ( fileName ) && this . expectedFilePaths . has ( toUnixPath ( fileName ) ) ) ) {
886
908
const sourceFile = program . getSourceFile ( fileName ) ;
887
909
if ( ! sourceFile ) {
888
910
this . getHost ( ) . addFile ( fileName ) ;
0 commit comments