Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions src/parser/ts-patch.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,16 @@ try {
readFile(fname) {
let fileName = fname;
let content = '';
if (fileName.endsWith('tsconfig.tsbuildinfo')) {
return content;
if (fileName.endsWith('.tsbuildinfo')) {

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the main fix here is that we don't require tsconfig prefix

// Incremental build state is optional and never a .gts/.gjs file, so
// delegate to the real host: it returns the content when present and
// reports a missing file as absent (undefined) instead of throwing.
// The watch program reads `tsBuildInfoFile` without a fileExists
// probe (readBuilderProgram -> host.readFile), so a fresh/cleaned
// project with a custom buildinfo path (e.g.
// "declarations/.tsbuildinfo") would otherwise abort linting of
// every file with a Parsing error: ENOENT.
return sys.readFile(fileName);
}

try {
Expand Down
45 changes: 45 additions & 0 deletions tests/ts-patch.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { describe, expect, it } from 'vitest';
import { createRequire } from 'node:module';
import fs from 'node:fs';
import os from 'node:os';
import path from 'node:path';

import { patchTs } from '../src/parser/ts-patch.js';

// Resolve the same typescript instance ts-patch patches (the one
// @typescript-eslint/parser depends on), so we observe the patched ts.sys.
const require = createRequire(import.meta.url);
const parserPath = require.resolve('@typescript-eslint/parser');
const ts = require(require.resolve('typescript', { paths: [parserPath] }));

// Incremental build state is optional input: when `tsBuildInfoFile` points at
// a file that has not been produced yet (fresh checkout, cleaned repo), the
// watch program used for type-aware linting reads it WITHOUT a fileExists
// probe (readBuilderProgram -> host.readFile). ts.sys.readFile's contract is
// to report a missing file as absent, not to throw — a throw here aborts
// linting of every file in the project with
// `Parsing error: ENOENT ... <project>/declarations/.tsbuildinfo`.
describe('patched ts.sys.readFile — .tsbuildinfo handling', () => {
patchTs();

it('treats a missing custom-named .tsbuildinfo as absent instead of throwing', () => {
// e.g. { "tsBuildInfoFile": "declarations/.tsbuildinfo" } — only the
// default `tsconfig.tsbuildinfo` name was guarded before.
const missing = path.join(os.tmpdir(), 'ee-parser-no-such-dir', 'declarations', '.tsbuildinfo');

expect(() => ts.sys.readFile(missing)).not.toThrow();
expect(ts.sys.readFile(missing)).toBeUndefined();
});

it('returns the real content when the .tsbuildinfo exists', () => {
const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'ee-parser-buildinfo-'));
const buildInfo = path.join(dir, 'custom.tsbuildinfo');
fs.writeFileSync(buildInfo, '{"version":"5.9.3"}');

try {
expect(ts.sys.readFile(buildInfo)).toBe('{"version":"5.9.3"}');
} finally {
fs.rmSync(dir, { recursive: true, force: true });
}
});
});
Loading