From 9c964a15e2e84765d2a5bd2af9b2bd881a4e11b7 Mon Sep 17 00:00:00 2001 From: Colum Ferry Date: Tue, 27 Aug 2024 16:08:45 +0100 Subject: [PATCH] fix(vite): plugin should infer ts project correctly for libs (#27649) ## Current Behavior The vite plugin's typecheck target is not using the tsconfig.lib.json project when running typecheck for libs ## Expected Behavior It should use the correct tsconfig ## Related Issue(s) Fixes #27501 (cherry picked from commit 564834462e92a0e3354044fddfc480ecdd36e9f9) --- .../plugins/__snapshots__/plugin-vitest.spec.ts.snap | 2 +- .../__snapshots__/plugin-with-test.spec.ts.snap | 2 +- packages/vite/src/plugins/plugin.ts | 11 ++++++----- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/packages/vite/src/plugins/__snapshots__/plugin-vitest.spec.ts.snap b/packages/vite/src/plugins/__snapshots__/plugin-vitest.spec.ts.snap index 5c65c5dbb0d49..aa717d6f3ba12 100644 --- a/packages/vite/src/plugins/__snapshots__/plugin-vitest.spec.ts.snap +++ b/packages/vite/src/plugins/__snapshots__/plugin-vitest.spec.ts.snap @@ -49,7 +49,7 @@ exports[`@nx/vite/plugin root project should create nodes 1`] = ` }, "typecheck": { "cache": true, - "command": "tsc --noEmit", + "command": "tsc --noEmit -p tsconfig.lib.json", "inputs": [ "production", "^production", diff --git a/packages/vite/src/plugins/__snapshots__/plugin-with-test.spec.ts.snap b/packages/vite/src/plugins/__snapshots__/plugin-with-test.spec.ts.snap index ad8da91a728b4..d41dfa2c2433d 100644 --- a/packages/vite/src/plugins/__snapshots__/plugin-with-test.spec.ts.snap +++ b/packages/vite/src/plugins/__snapshots__/plugin-with-test.spec.ts.snap @@ -49,7 +49,7 @@ exports[`@nx/vite/plugin with test node root project should create nodes - with }, "typecheck": { "cache": true, - "command": "tsc --noEmit", + "command": "tsc --noEmit -p tsconfig.lib.json", "inputs": [ "production", "^production", diff --git a/packages/vite/src/plugins/plugin.ts b/packages/vite/src/plugins/plugin.ts index 03cc61d914a87..3653abd62b8d6 100644 --- a/packages/vite/src/plugins/plugin.ts +++ b/packages/vite/src/plugins/plugin.ts @@ -206,18 +206,19 @@ async function buildViteTargets( } if (tsConfigFiles.length) { - const tsconfigToUse = tsConfigFiles.includes('tsconfig.lib.json') - ? 'tsconfig.lib.json' - : tsConfigFiles[0]; + const tsConfigToUse = + ['tsconfig.app.json', 'tsconfig.lib.json', 'tsconfig.json'].find((t) => + tsConfigFiles.includes(t) + ) ?? tsConfigFiles[0]; targets[options.typecheckTargetName] = { cache: true, inputs: ['production', '^production'], - command: 'tsc --noEmit', + command: `tsc --noEmit -p ${tsConfigToUse}`, options: { cwd: joinPathFragments(projectRoot) }, metadata: { description: `Run Typechecking`, help: { - command: `${pmc.exec} tsc --help -p ${tsconfigToUse}`, + command: `${pmc.exec} tsc --help -p ${tsConfigToUse}`, example: { options: { noEmit: true,