Skip to content

Commit 8e35c31

Browse files
authored
Merge pull request #21244 from Microsoft/allowNonExistentInputInGetDirectories
Fix the invalid file/directory location when getting file system entries for caching the results
2 parents 99d6b0d + 8281c7a commit 8e35c31

File tree

4 files changed

+33
-3
lines changed

4 files changed

+33
-3
lines changed

src/compiler/core.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ namespace ts {
2020

2121
/* @internal */
2222
namespace ts {
23+
export const emptyArray: never[] = [] as never[];
2324
/** Create a MapLike with good performance. */
2425
function createDictionaryObject<T>(): MapLike<T> {
2526
const map = Object.create(/*prototype*/ null); // tslint:disable-line:no-null-keyword
@@ -3070,6 +3071,10 @@ namespace ts {
30703071
readonly directories: string[];
30713072
}
30723073

3074+
export const emptyFileSystemEntries: FileSystemEntries = {
3075+
files: emptyArray,
3076+
directories: emptyArray
3077+
};
30733078
export function createCachedDirectoryStructureHost(host: DirectoryStructureHost): CachedDirectoryStructureHost {
30743079
const cachedReadDirectoryResult = createMap<MutableFileSystemEntries>();
30753080
const getCurrentDirectory = memoize(() => host.getCurrentDirectory());
@@ -3211,7 +3216,7 @@ namespace ts {
32113216
if (path === rootDirPath) {
32123217
return result;
32133218
}
3214-
return getCachedFileSystemEntries(path) || createCachedFileSystemEntries(dir, path);
3219+
return tryReadDirectory(dir, path) || emptyFileSystemEntries;
32153220
}
32163221
}
32173222

src/compiler/sys.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,7 @@ namespace ts {
398398
return { files, directories };
399399
}
400400
catch (e) {
401-
return { files: [], directories: [] };
401+
return emptyFileSystemEntries;
402402
}
403403
}
404404

src/compiler/utilities.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
/* @internal */
44
namespace ts {
5-
export const emptyArray: never[] = [] as never[];
65
export const resolvingEmptyArray: never[] = [] as never[];
76
export const emptyMap: ReadonlyMap<never> = createMap<never>();
87
export const emptyUnderscoreEscapedMap: ReadonlyUnderscoreEscapedMap<never> = emptyMap as ReadonlyUnderscoreEscapedMap<never>;

src/harness/unittests/tsserverProjectSystem.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4200,6 +4200,32 @@ namespace ts.projectSystem {
42004200
// Since no file from the configured project is open, it would be closed immediately
42014201
projectService.checkNumberOfProjects({ configuredProjects: 0, inferredProjects: 1 });
42024202
});
4203+
4204+
it("should tolerate invalid include files that start in subDirectory", () => {
4205+
const projectFolder = "/user/username/projects/myproject";
4206+
const f = {
4207+
path: `${projectFolder}/src/server/index.ts`,
4208+
content: "let x = 1"
4209+
};
4210+
const config = {
4211+
path: `${projectFolder}/src/server/tsconfig.json`,
4212+
content: JSON.stringify({
4213+
compiler: {
4214+
module: "commonjs",
4215+
outDir: "../../build"
4216+
},
4217+
include: [
4218+
"../src/**/*.ts"
4219+
]
4220+
})
4221+
};
4222+
const host = createServerHost([f, config, libFile], { useCaseSensitiveFileNames: true });
4223+
const projectService = createProjectService(host);
4224+
4225+
projectService.openClientFile(f.path);
4226+
// Since no file from the configured project is open, it would be closed immediately
4227+
projectService.checkNumberOfProjects({ configuredProjects: 0, inferredProjects: 1 });
4228+
});
42034229
});
42044230

42054231
describe("tsserverProjectSystem reload", () => {

0 commit comments

Comments
 (0)