Skip to content
Closed
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
5 changes: 5 additions & 0 deletions .changeset/import-graph-typescript-7.md
Original file line number Diff line number Diff line change
@@ -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')`.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,8 @@ drops it before webpack sees it — and this holds for every check, whatever too
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 (a stylesheet, an image or another asset webpack bundles aside) — lints
every file again, as does a project without TypeScript. There,
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.

Expand Down
14 changes: 13 additions & 1 deletion src/import-graph.js
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,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.
Expand Down
16 changes: 16 additions & 0 deletions test/import-graph.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,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", () => {
Expand Down
Loading