From 9549a19131450a38f2f70344f02c2bd7f93b11c8 Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 23 Oct 2026 13:28:28 +0000 Subject: [PATCH] fix: answer without an import graph where TypeScript is the native 7 TypeScript 7's package is a native compiler and exports only its version. Loaded as the project's TypeScript, it made a graph whose first read threw: a rebuild of oxlint or Biome swallowed it and linted every file, and typed ESLint's signatures failed the check with "Cannot read properties of undefined (reading 'readFile')". The graph is now made only from a TypeScript with `preProcessFile`, `resolveModuleName` and `sys`; anything else is answered as one that cannot be loaded, which every caller already falls back from. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01App18sYbe6Vf6HDCjCXbvf --- .changeset/import-graph-typescript-7.md | 5 +++++ README.md | 3 ++- src/import-graph.js | 14 +++++++++++++- test/import-graph.test.js | 16 ++++++++++++++++ 4 files changed, 36 insertions(+), 2 deletions(-) create mode 100644 .changeset/import-graph-typescript-7.md diff --git a/.changeset/import-graph-typescript-7.md b/.changeset/import-graph-typescript-7.md new file mode 100644 index 0000000..1aeb19e --- /dev/null +++ b/.changeset/import-graph-typescript-7.md @@ -0,0 +1,5 @@ +--- +"diagnostics-webpack-plugin": patch +--- + +Lint every file again, rather than fail, where a project's TypeScript is the native TypeScript 7, which has no API to read what a file imports through: a check reading across files failed with `Cannot read properties of undefined (reading 'readFile')`. diff --git a/README.md b/README.md index a59d455..694ef91 100644 --- a/README.md +++ b/README.md @@ -380,7 +380,8 @@ Which file imports which is read with the project's own TypeScript, through the drops it before webpack sees it — and this holds for every check, whatever tool it runs. A change that could reach files some other way — a declaration file nothing imports, a `declare global`, a config file, an import that resolves to -nothing — lints every file again, as does a project without TypeScript. There, +nothing — lints every file again, as does a project without TypeScript, or with +TypeScript 7, whose native compiler has no API to read imports through. There, an ESLint check with `cache: true` written down keeps ESLint's own cache, which answers for a file whose import changed from before the change. diff --git a/src/import-graph.js b/src/import-graph.js index 8933662..228a4db 100644 --- a/src/import-graph.js +++ b/src/import-graph.js @@ -267,7 +267,19 @@ function getGraph(compiler, context, owner) { ).href ); - return createGraph(loaded.default || loaded); + const ts = loaded.default || loaded; + + // TypeScript 7 is a native compiler whose package exports no such + // API: what a file imports cannot be read through it. + if ( + typeof ts.preProcessFile !== "function" || + typeof ts.resolveModuleName !== "function" || + !ts.sys + ) { + return undefined; + } + + return createGraph(ts); } catch { // Without a TypeScript of the project's own there is nothing to say // which file reads which, and every file is linted again instead. diff --git a/test/import-graph.test.js b/test/import-graph.test.js index cec262a..2022f80 100644 --- a/test/import-graph.test.js +++ b/test/import-graph.test.js @@ -205,6 +205,22 @@ describe("the graph a compiler keeps", () => { assert.strictEqual(await getGraph({}, project), undefined); }); + + it("should be nothing for a project whose TypeScript has no API to read imports with", async (t) => { + // As TypeScript 7 is: a native compiler whose package exports a version. + const project = mkdtempSync(join(tmpdir(), "native-typescript-")); + const native = join(project, "node_modules", "typescript"); + + t.after(() => rmSync(project, { recursive: true, force: true })); + mkdirSync(native, { recursive: true }); + writeFileSync(join(native, "package.json"), '{ "main": "index.js" }'); + writeFileSync( + join(native, "index.js"), + 'module.exports = { version: "7.0.0", versionMajorMinor: "7.0" };\n', + ); + + assert.strictEqual(await getGraph({}, project), undefined); + }); }); describe("signatures", () => {