From 8ba5570c45ae290b842827a41de206955333e7c0 Mon Sep 17 00:00:00 2001 From: Matthias Stemmler Date: Wed, 8 May 2024 13:30:07 +0200 Subject: [PATCH] fix(vite): get tsconfig from new path including target (#22775) ## Current Behavior Since v18.2.3 (e4c4697f69cf29c50aced1997715a7da5f680e23) the `tsconfig.generated.json` file generated if `"buildLibsFromSource": false` is placed under a path containing the current build target. The `nx-tsconfig-paths` plugin of `@nx/vite` was not updated accordingly, so now it doesn't find `tsconfig.generated.json`, effectively causing `@nx/vite` to ignore the `"buildLibsFromSource": false` setting. ## Expected Behavior With this PR, `nx-tsconfig-paths` finds `tsconfig.generated.json` at the correct path, so `"buildLibsFromSource": false` works as it did before v18.2.3. (cherry picked from commit b4f6e425c42a6008ca90beeafccd22c1a33b0e5a) --- e2e/vite/src/vite-legacy.test.ts | 2 +- packages/vite/plugins/nx-tsconfig-paths.plugin.ts | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/e2e/vite/src/vite-legacy.test.ts b/e2e/vite/src/vite-legacy.test.ts index 48b9fe9e01733..8f4bd7f4c9fd5 100644 --- a/e2e/vite/src/vite-legacy.test.ts +++ b/e2e/vite/src/vite-legacy.test.ts @@ -248,7 +248,7 @@ export default App; const results = runCLI(`build ${app} --buildLibsFromSource=false`); expect(results).toContain('Successfully ran target build for project'); // this should be less modules than building from source - expect(results).toContain('40 modules transformed'); + expect(results).toContain('38 modules transformed'); }); it('should build app from libs without package.json in lib', () => { diff --git a/packages/vite/plugins/nx-tsconfig-paths.plugin.ts b/packages/vite/plugins/nx-tsconfig-paths.plugin.ts index 4fd839c4d811b..e88e92ee7b7d1 100644 --- a/packages/vite/plugins/nx-tsconfig-paths.plugin.ts +++ b/packages/vite/plugins/nx-tsconfig-paths.plugin.ts @@ -56,6 +56,7 @@ export function nxViteTsPaths(options: nxViteTsPathsOptions = {}) { workspaceRoot, 'tmp', projectRootFromWorkspaceRoot, + process.env.NX_TASK_TARGET_TARGET ?? 'build', 'tsconfig.generated.json' ) );