New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(config): deprecate cache.dir
option
#5229
Conversation
✅ Deploy Preview for fastidious-cascaron-4ded94 ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
// cache can only be "false" or an object | ||
transform(cache) { | ||
if (cache) | ||
return {} | ||
return cache | ||
}, | ||
}, | ||
} as VitestCLIOptions['cache'], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, you need to manually pass null
to dir
subcommand instead of removing it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for letting me know, I've updated it.
@@ -24,8 +24,6 @@ export function resolveOptimizerConfig(_testOptions: DepsOptimizationOptions | u | |||
} | |||
} | |||
else { | |||
const root = testConfig.root ?? process.cwd() | |||
const cacheDir = testConfig.cache !== false ? testConfig.cache?.dir : undefined |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We still need to handle it during the deprecation period
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've updated it. I'm new to the optimizer config, not sure if this is right change, could you please help to review again? Thank you so much!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would expect test.cache.dir
to just set cacheDir
, everything else should just refer to config.cacheDir
cache.dir
optioncache.dir
option
Deprecating is not a breaking change as long as it's still resolved. |
Aha...thanks for clarifying! As you said it's still resolved, do I need to handle |
Yes, I would expect |
test/optimize-deps/test/web.test.ts
Outdated
@@ -6,5 +6,5 @@ import { expect, test } from 'vitest' | |||
import { importMetaUrl } from '@vitest/test-dep-url' | |||
|
|||
test('import.meta.url', () => { | |||
expect(importMetaUrl).toContain('/node_modules/.vitest/deps/') | |||
expect(importMetaUrl).toContain('/node_modules/.vite/deps/') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this change means that Vite and Vitest are going to share the same folder for pre-bundling (aka optimizeDeps
).
Though Vitest side of pre-bundling is disabled by default since v1.3.0 #5156, would this mean that users will not be able to run vite dev
and vitest
in watch mode at the same time when they explicitly use deps.optimizer.enable
and have different optimizeDeps
settings between two?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For example, in current main branch, running these two commands at the same time seems to work even with deps.optimizer.web.enabled: true
. DEBUG=vite:deps
is convenient to see what Vite does inside node_modules/.vite
DEBUG=vite:deps pnpm -C examples/react-testing-lib dev
DEBUG=vite:deps pnpm -C examples/react-testing-lib test
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the question and example, I tried running pnpm dlx concurrently "DEBUG=vite:deps pnpm -C examples/react-testing-lib dev" "DEBUG=vite:deps pnpm -C examples/react-testing-lib test"
in this PR's branch, with the workspace's Vitest version, it seems to have worked as expected.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see. I just tried and it looks like it actually works, but it might be a bit coincidental.
When running pnpm dev
, Vite generates files such as examples/react-testing-lib/node_modules/.vite/deps/react.js
, then when I run pnpm test
, Vitest will remove those files. The reason why Vite can keep serving the files in .vite/deps
might be because of Vite's in-memory cache for js requests (I tried "Disable cache" in browser devtools).
I think I need to dig into this further to see whether buggy behavior is reproducible.
Or maybe running Vite and Vitest at the same time in the same directory can be considered an unsupported feature (at least when combined with deps.optimizer.enabled
).
Actually I think Vitest already uses node_modules/.vite
when using Vitest browser mode https://vitest.dev/guide/browser.html#browser-mode, so this might not be an issue in practice.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sheremet-va Do you know if it's safe to use a same directory node_modules/.vite/deps
as Vite for deps optimization?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think it's safe, that's why this option was introduced in the first place 🤔
The main reason back then was that we were not sure if .vite
deletes everything when deps are changed, or just the deps folder. If it just deletes the deps, then we can have .vite/vitest/...
cache folder
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like Vite deletes only node_modules/.vite/deps
, for example, this code is for --force
flag https://github.com/vitejs/vite/blob/b20d54257e6105333c19676a403c574667878e0f/packages/vite/src/node/optimizer/index.ts#L382-L384
I agree we should avoid overlapping .vite/deps
, so using node_modules/.vite/vitest
sounds good to me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the suggestion, I'll update with .vite/vitest
later.
argument: '<path>', | ||
normalize: true, | ||
}, | ||
dir: null, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe it would be better to add a handler that throws an error? I think CLI will still propagate the value even if it's not defined in a schema
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah I noticed that, I'll update it later
Description
Closes #3272
This PR removes the
cache.dir
option and reuses Vite'scacheDir
to save cache.Related
Please don't delete this checklist! Before submitting the PR, please make sure you do the following:
pnpm-lock.yaml
unless you introduce a new test example.Tests
pnpm test:ci
.Documentation
pnpm run docs
command.Changesets
feat:
,fix:
,perf:
,docs:
, orchore:
.