From ad0b29c63dc4819df75dc021df8085b6ec7ee7fc Mon Sep 17 00:00:00 2001 From: Erik Demaine Date: Tue, 25 Jun 2024 18:44:53 -0400 Subject: [PATCH 1/3] Host uses getDirectories from System --- packages/typescript-vfs/src/index.ts | 1 - packages/typescript-vfs/test/fsbacked.test.ts | 14 ++++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/packages/typescript-vfs/src/index.ts b/packages/typescript-vfs/src/index.ts index 8040f29ce242..84d388967510 100755 --- a/packages/typescript-vfs/src/index.ts +++ b/packages/typescript-vfs/src/index.ts @@ -572,7 +572,6 @@ export function createVirtualCompilerHost(sys: System, compilerOptions: Compiler getCanonicalFileName: fileName => fileName, getDefaultLibFileName: () => "/" + ts.getDefaultLibFileName(compilerOptions), // '/lib.d.ts', // getDefaultLibLocation: () => '/', - getDirectories: () => [], getNewLine: () => sys.newLine, getSourceFile: (fileName, languageVersionOrOptions) => { return ( diff --git a/packages/typescript-vfs/test/fsbacked.test.ts b/packages/typescript-vfs/test/fsbacked.test.ts index bb0f18b2824e..e0938a6678f4 100644 --- a/packages/typescript-vfs/test/fsbacked.test.ts +++ b/packages/typescript-vfs/test/fsbacked.test.ts @@ -58,3 +58,17 @@ it("can import files in the virtual fs", () => { expect(errs.map(e => e.messageText)).toEqual([]) }) + +it("searches node_modules/@types", () => { + const compilerOpts: ts.CompilerOptions = { target: ts.ScriptTarget.ES2016, esModuleInterop: true } + const monorepoRoot = __dirname + + const fsMap = new Map() + fsMap.set("index.ts", "it('found @types/jest', () => undefined)") + + const system = createFSBackedSystem(fsMap, monorepoRoot, ts) + const env = createVirtualTypeScriptEnvironment(system, ["index.ts"], ts, compilerOpts) + + const semDiags = env.languageService.getSemanticDiagnostics("index.ts") + expect(semDiags.length).toBe(0) +}) From 998788613f713db45f35073d528868422c79427a Mon Sep 17 00:00:00 2001 From: Erik Demaine Date: Tue, 25 Jun 2024 19:04:36 -0400 Subject: [PATCH 2/3] Add changeset --- .changeset/many-avocados-learn.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/many-avocados-learn.md diff --git a/.changeset/many-avocados-learn.md b/.changeset/many-avocados-learn.md new file mode 100644 index 000000000000..21773df7bbfc --- /dev/null +++ b/.changeset/many-avocados-learn.md @@ -0,0 +1,5 @@ +--- +"@typescript/vfs": patch +--- + +Use System's getDirectories if it's provided when constructing Host From c458e52ac4e23e830e23763bcdc435872cd404e9 Mon Sep 17 00:00:00 2001 From: Erik Demaine Date: Tue, 25 Jun 2024 20:27:15 -0400 Subject: [PATCH 3/3] Add types: [] to twoslasher tests --- packages/ts-twoslasher/test/fixtures.test.ts | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/packages/ts-twoslasher/test/fixtures.test.ts b/packages/ts-twoslasher/test/fixtures.test.ts index 45de384136af..8ba7fb3af6ba 100644 --- a/packages/ts-twoslasher/test/fixtures.test.ts +++ b/packages/ts-twoslasher/test/fixtures.test.ts @@ -9,6 +9,11 @@ expect.extend({ toMatchFile }) // To add a test, create a file in the fixtures folder and it will will run through // as though it was the codeblock. +const defaultCompilerOptions = { + // avoid extra annotations from @types/node + types: [] +} + describe("with fixtures", () => { // Add all codefixes const fixturesFolder = join(__dirname, "fixtures") @@ -27,7 +32,7 @@ describe("with fixtures", () => { const file = readFileSync(fixture, "utf8") - const fourslashed = twoslasher(file, extname(fixtureName).substr(1), { customTags: ["annotate"] }) + const fourslashed = twoslasher(file, extname(fixtureName).substr(1), { customTags: ["annotate"], defaultCompilerOptions }) const jsonString = format(JSON.stringify(cleanFixture(fourslashed)), { parser: "json" }) expect(jsonString).toMatchFile(result) }) @@ -46,7 +51,7 @@ describe("with fixtures", () => { const file = readFileSync(fixture, "utf8") - const fourslashed = twoslasher(file, extname(fixtureName).substr(1)) + const fourslashed = twoslasher(file, extname(fixtureName).substr(1), { defaultCompilerOptions }) const jsonString = format(JSON.stringify(cleanFixture(fourslashed)), { parser: "json" }) expect(jsonString).toMatchFile(result) }) @@ -65,7 +70,7 @@ describe("with fixtures", () => { const file = readFileSync(fixture, "utf8") - const fourslashed = twoslasher(file, extname(fixtureName).substr(1)) + const fourslashed = twoslasher(file, extname(fixtureName).substr(1), { defaultCompilerOptions }) const jsonString = format(JSON.stringify(cleanFixture(fourslashed)), { parser: "json" }) expect(jsonString).toMatchFile(result) }) @@ -87,7 +92,7 @@ describe("with fixtures", () => { let thrown = false try { - twoslasher(file, extname(fixtureName).substr(1)) + twoslasher(file, extname(fixtureName).substr(1), { defaultCompilerOptions }) } catch (err) { thrown = true if (err instanceof Error) expect(err.message).toMatchFile(result)