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

fix: ensure local files mapped to yarn virtuals are watched #19276

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

mrginglymus
Copy link
Contributor

Description

There's a somewhat minimal repro here: https://github.com/mrginglymus/vitest-pnp though the focus of that is worrying about the coverage reporting on vitest.

The specific problem is this:

  1. Using Yarn PnP
  2. With a workspace package with peer dependencies
  3. With source files in that workspace package
  4. Imported from files via package name from the root package

Then files are reported as being in <cwd>/.yarn/__virtual__/my-package....

I've failed to exactly follow how files are added to the watcher, but what I can see is that ensureWatchedFile bails if the file considered 'out of root', as presumably it would otherwise be watched.

However, these virtual files are not watched; I don't know how the initial watchlist is populated, but I could envisage it either having an exclusion of directories with a leading ., or scanning the on-disk filesystem (which would not include the virtual files).

Either way, what 'fixes' this for me locally is to either change the root (to trick ensureWatchedFile) or apply this fix which considers virtual files to be out of root.

@mrginglymus mrginglymus changed the title fix: Ensure local files mapped to yarn virtuals are watched fix: ensure local files mapped to yarn virtuals are watched Jan 23, 2025
@mrginglymus
Copy link
Contributor Author

Actually this still doesn't help - even if the virtual file is watched, sometimes the on-disk file will be reported as changed but will have been registered in the module graph as a virtual file so no change is triggered...

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.

Yarn virtual packages/workspaces not watched in pnp
1 participant