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

Optimized dependencies are unable to resolve external dependencies provided by their respective workspaces #4898

Open
6 tasks done
kherock opened this issue Jan 8, 2024 · 0 comments

Comments

@kherock
Copy link

kherock commented Jan 8, 2024

Describe the bug

I found a regression caused by the changes introduced by #4036 - I have a Yarn PnP monorepo setup that provides dependencies used both in my component/test code and optimized dependency code. I'm using React and Ariakit in the linked reproduction, but this issue is a bit more critical in my private setup where I have both a dependency that is sensitive to duplicate instances and another dependent that requires transpilation by Vite's dependency optimizer.

I'm not sure if the changes in #4036 were completely necessary, as prior to Vitest 0.34.4, I was already seeing Vitest isolate the optimized dependency cache across workspaces. For example, on Vitest 0.34.3, I have two projects that would each optimize the dependency under two separate caches in the respective node_modules folders:

  • site-a/node_modules/.vitest/deps/@kherock_example.js
  • site-b/node_modules/.vitest/deps/@kherock_example.js

Regardless, amending the code to store project caches relative to the workspace root rather than the project root would alleviate my issue. The regression boils down to the fact that resolveOptimizerConfig previously resolved a relative path node_modules/.vitest as the cacheDir, but after the changes to this function, it now resolves to an absolute path via VitestCache.resolveCacheDir. I think the most obvious fix would be to provide a default value for the root argument that resolves to the folder containing the workspace vitest.config.js file instead of process.cwd().

Reproduction

https://github.com/kherock/vitest-workspace-deps-repro

System Info

System:
    OS: macOS 13.4.1
    CPU: (10) arm64 Apple M1 Pro
    Memory: 78.67 MB / 16.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 16.20.2 - /opt/homebrew/bin/node
    Yarn: 3.7.0 - /opt/homebrew/bin/yarn
    npm: 8.19.4 - /opt/homebrew/bin/npm
  Browsers:
    Chrome: 120.0.6099.199
    Edge: 120.0.2210.121
    Firefox: 115.4.0
    Safari: 17.2.1

Used Package Manager

yarn

Validations

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

No branches or pull requests

1 participant