Skip to content
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

Merged
merged 19 commits into from Mar 15, 2024

Conversation

fenghan34
Copy link
Contributor

Description

Closes #3272

This PR removes the cache.dir option and reuses Vite's cacheDir to save cache.

Related

Please don't delete this checklist! Before submitting the PR, please make sure you do the following:

  • It's really useful if your PR references an issue where it is discussed ahead of time. If the feature is substantial or introduces breaking changes without a discussion, PR might be closed.
  • Ideally, include a test that fails without this PR but passes with it.
  • Please, don't make changes to pnpm-lock.yaml unless you introduce a new test example.

Tests

  • Run the tests with pnpm test:ci.

Documentation

  • If you introduce new functionality, document it. You can run documentation with pnpm run docs command.

Changesets

  • Changes in changelog are generated from PR name. Please, make sure that it explains your changes in an understandable manner. Please, prefix changeset messages with feat:, fix:, perf:, docs:, or chore:.

Copy link

netlify bot commented Feb 18, 2024

Deploy Preview for fastidious-cascaron-4ded94 ready!

Name Link
🔨 Latest commit 8af373b
🔍 Latest deploy log https://app.netlify.com/sites/fastidious-cascaron-4ded94/deploys/65f3fecb5edb86000821e512
😎 Deploy Preview https://deploy-preview-5229--fastidious-cascaron-4ded94.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@fenghan34 fenghan34 marked this pull request as draft February 18, 2024 13:51
// cache can only be "false" or an object
transform(cache) {
if (cache)
return {}
return cache
},
},
} as VitestCLIOptions['cache'],
Copy link
Member

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

Copy link
Contributor Author

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
Copy link
Member

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

Copy link
Contributor Author

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!

Copy link
Member

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

@sheremet-va sheremet-va changed the title feat!(config): deprecate cache.dir option feat(config): deprecate cache.dir option Feb 20, 2024
@sheremet-va
Copy link
Member

Deprecating is not a breaking change as long as it's still resolved.

@fenghan34
Copy link
Contributor Author

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 cache.dir in resolving config? Like assigning Vite's cacheDir as cache.dir if it exists?

@sheremet-va
Copy link
Member

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 cache.dir in resolving config? Like assigning Vite's cacheDir as cache.dir if it exists?

Yes, I would expect cache.dir to affect the directory somehow until the option is removed completely in the next major.

@fenghan34 fenghan34 marked this pull request as ready for review February 21, 2024 15:02
@@ -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/')
Copy link
Contributor

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?

Copy link
Contributor

@hi-ogawa hi-ogawa Feb 22, 2024

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

Copy link
Contributor Author

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.

Copy link
Contributor

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.

Copy link
Contributor

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?

Copy link
Member

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

Copy link
Contributor

@hi-ogawa hi-ogawa Feb 26, 2024

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.

Copy link
Contributor Author

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,
Copy link
Member

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

Copy link
Contributor Author

@fenghan34 fenghan34 Mar 15, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

location of results.json when use test.root in vite.config.ts
3 participants