diff --git a/__tests__/host.spec.ts b/__tests__/host.spec.ts index 21ce7178..fbb95ded 100644 --- a/__tests__/host.spec.ts +++ b/__tests__/host.spec.ts @@ -2,7 +2,7 @@ import { afterAll, beforeAll, test, expect, jest } from "@jest/globals"; import * as ts from "typescript"; import * as path from "path"; import { normalizePath as normalize } from "@rollup/pluginutils"; -import { remove, ensureDir, writeFile } from "fs-extra"; +import { remove, ensureDir, writeFile, ensureSymlink } from "fs-extra"; import { setTypescriptModule } from "../src/tsproxy"; import { LanguageServiceHost } from "../src/host"; @@ -18,12 +18,14 @@ const unaryFuncSnap = { text: unaryFunc }; const local = (x: string) => normalize(path.resolve(__dirname, x)); const testDir = local("__temp/host"); const testFile = `${testDir}/file.ts`; +const linkedTestFile = `${testDir}/link.ts`; const nonExistent = `${testDir}/this-does-not-exist.ts`; afterAll(() => remove(testDir)); beforeAll(async () => { await ensureDir(testDir); await writeFile(testFile, unaryFunc, "utf8"); + await ensureSymlink(testFile, linkedTestFile); }); test("LanguageServiceHost", async () => { @@ -55,10 +57,12 @@ test("LanguageServiceHost", async () => { expect(host.directoryExists(nonExistent)).toBeFalsy(); expect(host.fileExists(nonExistent)).toBeFalsy(); expect(host.fileExists(testFile)).toBeTruthy(); - expect(host.readDirectory(testDir)).toEqual([testFile]); + expect(host.readDirectory(testDir)).toEqual([testFile, linkedTestFile]); expect(host.readFile(nonExistent)).toBeFalsy(); expect(host.readFile(testFile)).toEqual(unaryFunc); expect(host.useCaseSensitiveFileNames()).toBe(process.platform === "linux"); + expect(host.realpath(testFile)).toEqual(testFile); + expect(host.realpath(linkedTestFile)).toEqual(testFile); // test misc functionality expect(host.getCompilationSettings()).toEqual(testOpts); diff --git a/src/host.ts b/src/host.ts index 6c1d4c55..a0831635 100644 --- a/src/host.ts +++ b/src/host.ts @@ -104,6 +104,11 @@ export class LanguageServiceHost implements tsTypes.LanguageServiceHost return tsModule.sys.fileExists(path); } + public realpath(path: string): string + { + return tsModule.sys.realpath!(path); // this exists in the default implementation: https://github.com/microsoft/TypeScript/blob/ab2523bbe0352d4486f67b73473d2143ad64d03d/src/compiler/sys.ts#L1288 + } + public getTypeRootsVersion(): number { return 0;