Skip to content
This repository was archived by the owner on Oct 16, 2020. It is now read-only.

Commit ed8052b

Browse files
Tom van Ommerentomv564
authored andcommitted
read and resolve typeRoots so ensureBasicFiles can add content
1 parent 3c01fe0 commit ed8052b

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

src/project-manager.ts

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -734,6 +734,11 @@ export class ProjectConfiguration {
734734
*/
735735
private expectedFilePaths = new Set<string>();
736736

737+
/**
738+
* List of resolved extra root directories to allow global typings to be loaded from.
739+
*/
740+
private typeRoots: string[];
741+
737742
/**
738743
* @param fs file system to use
739744
* @param documentRegistry Shared DocumentRegistry that manages SourceFile objects
@@ -838,6 +843,10 @@ export class ProjectConfiguration {
838843
this.expectedFilePaths = new Set(configParseResult.fileNames);
839844

840845
const options = configParseResult.options;
846+
this.typeRoots = options.typeRoots ?
847+
options.typeRoots.map((r: string) => path.resolve(this.rootFilePath, r)) :
848+
[];
849+
841850
if (/(^|\/)jsconfig\.json$/.test(this.configFilePath)) {
842851
options.allowJs = true;
843852
}
@@ -864,6 +873,17 @@ export class ProjectConfiguration {
864873

865874
private ensuredBasicFiles = false;
866875

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+
867887
/**
868888
* Ensures we added basic files (global TS files, dependencies, declarations)
869889
*/
@@ -882,7 +902,9 @@ export class ProjectConfiguration {
882902
// Add all global declaration files from the workspace and all declarations from the project
883903
for (const uri of this.fs.uris()) {
884904
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)))) {
886908
const sourceFile = program.getSourceFile(fileName);
887909
if (!sourceFile) {
888910
this.getHost().addFile(fileName);

0 commit comments

Comments
 (0)