Skip to content

Commit

Permalink
fix(vite): generate vitest cache dir scoped to each project root and …
Browse files Browse the repository at this point in the history
…normalize vite cache dir (#23330)

- Update Vitest `cache.dir` to be scoped to each project root to avoid
collisions (same as what's already done for Vite)
- Normalize Vite `cacheDir` to avoid trailing `/.` paths for root
projects
- Fix Remix & Storybook Vite `cacheDir` generation 

<!-- Please make sure you have read the submission guidelines before
posting an PR -->
<!--
https://github.com/nrwl/nx/blob/master/CONTRIBUTING.md#-submitting-a-pr
-->

<!-- Please make sure that your commit message follows our format -->
<!-- Example: `fix(nx): must begin with lowercase` -->

## Current Behavior
<!-- This is the behavior we have today -->

## Expected Behavior
<!-- This is the behavior we should expect with the changes in this PR
-->

## Related Issue(s)
<!-- Please link the issue being fixed so it gets closed when this is
merged. -->

Fixes #21775
  • Loading branch information
leosvelperez authored May 13, 2024
1 parent 0bfd75f commit 5fea49a
Show file tree
Hide file tree
Showing 24 changed files with 218 additions and 1,230 deletions.
12 changes: 6 additions & 6 deletions docs/shared/packages/vite/configure-vite.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ If you're using `vitest`, make sure your `test` object in your `vite.config.ts`
test: {
globals: true,
cache: {
dir: '../node_modules/.vitest',
dir: '../node_modules/.vitest/<project-root>',
},
environment: 'jsdom',
include: ['src/**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}'],
Expand Down Expand Up @@ -124,7 +124,7 @@ export default defineConfig({
transformMixedEsModules: true,
},
},
cacheDir: '../../node_modules/.vite/my-app',
cacheDir: '../../node_modules/.vite/apps/my-app',
server: {
port: 4200,
host: 'localhost',
Expand All @@ -145,7 +145,7 @@ export default defineConfig({
},
globals: true,
cache: {
dir: '../../node_modules/.vitest',
dir: '../../node_modules/.vitest/apps/my-app',
},
environment: 'jsdom',
include: ['src/**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}'],
Expand Down Expand Up @@ -180,7 +180,7 @@ export default defineConfig({
// Configuration for building your library.
// See: https://vitejs.dev/guide/build.html#library-mode
build: {
outDir: '../dist/my-lib',
outDir: '../dist/libs/my-lib',
reportCompressedSize: true,
commonjsOptions: {
transformMixedEsModules: true,
Expand All @@ -202,13 +202,13 @@ export default defineConfig({
test: {
globals: true,
cache: {
dir: '../node_modules/.vitest',
dir: '../node_modules/.vitest/libs/my-lib',
},
environment: 'jsdom',
include: ['src/**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}'],
reporters: ['default'],
coverage: {
reportsDirectory: '../coverage/my-lib',
reportsDirectory: '../coverage/libs/my-lib',
provider: 'v8',
},
},
Expand Down
4 changes: 2 additions & 2 deletions docs/shared/recipes/add-stack/add-solid.md
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ import solidPlugin from 'vite-plugin-solid';
import viteTsConfigPaths from 'vite-tsconfig-paths';

export default defineConfig({
cacheDir: '../../node_modules/.vite/my-solid-app',
cacheDir: '../../node_modules/.vite/apps/my-solid-app',

server: {
port: 3000,
Expand Down Expand Up @@ -187,7 +187,7 @@ export default defineConfig({
test: {
globals: true,
cache: {
dir: '../../node_modules/.vitest',
dir: '../../node_modules/.vitest/apps/my-solid-app',
},
environment: 'jsdom',
include: ['src/**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export default defineConfig({
test: {
globals: true,
cache: {
dir: '../node_modules/.vitest',
dir: '../node_modules/.vitest/my-lib',
},
environment: 'jsdom',
include: ['src/**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ export default defineConfig({
test: {
globals: true,
cache: {
dir: '../node_modules/.vitest',
dir: '../node_modules/.vitest/my-app',
},
environment: 'jsdom',
include: ['src/**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}'],
Expand Down
Loading

0 comments on commit 5fea49a

Please sign in to comment.