Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Yarn virtual packages/workspaces not watched in pnp #15809

Open
7 tasks done
mrginglymus opened this issue Feb 5, 2024 · 1 comment · May be fixed by #19276
Open
7 tasks done

Yarn virtual packages/workspaces not watched in pnp #15809

mrginglymus opened this issue Feb 5, 2024 · 1 comment · May be fixed by #19276

Comments

@mrginglymus
Copy link
Contributor

Describe the bug

I have a project set up as a monorepo using yarn workspaces and pnp .

c:\dev\package.json
-------vite.config.js
-------packages\react\package.json
---------------------\src\button.tsx

Because some of the workspaces have peer dependencies, files from that workspace will apear as a PnP virtual. That is, when a change is made to button it will come through as something like

c:/dev/.yarn/__virtual__/@react-virtual-12345abcd/packages/react/button.tsx

However, the chokidar watcher is initialised like this:

? (chokidar.watch(
// config file dependencies and env file might be outside of root
[
root,
...config.configFileDependencies,
...getEnvFilesForMode(config.mode, config.envDir),
],
resolvedWatchOptions,
) as FSWatcher)

ie, with the project root; in this case c:/dev. The __virtual__ dir is not picked up by this, and file change events come in under the physical file location (c:/dev/packages/react/button.tsx) which isn't watched and thus the changes are ignored.

The problem appears to be here:

// only need to watch if out of root
!file.startsWith(withTrailingSlash(root)) &&

in ensureWatchedFile, which is supposed to add any used files to the watcher that aren't already there.

Because the __virtual__ dir is located in the project root, this bit of code assumes that it is already watched and ignores.

Reproduction

https://github.com/mrginglymus/vite-pnp

Steps to reproduce

Check out the linked reproduction and install with yarn.

Run yarn dev and attempt to make changes to button.jsx - observe that they do not trigger hmr.

Edite vite.config.js to have a root of demo and run yarn dev again.

Make changes to button.jsx - observe that they do now trigger hmr.

System Info

System:
    OS: Windows 10 10.0.19045
    CPU: (24) x64 Intel(R) Core(TM) i9-10920X CPU @ 3.50GHz
    Memory: 33.56 GB / 63.80 GB
  Binaries:
    Node: 20.11.0 - C:\Program Files\nodejs\node.EXE
    Yarn: 4.1.0 - C:\Program Files\nodejs\yarn.CMD
    npm: 10.2.4 - C:\Program Files\nodejs\npm.CMD
  Browsers:
    Edge: Chromium (121.0.2277.83)
    Internet Explorer: 11.0.19041.3636

Used Package Manager

yarn

Logs

No response

Validations

@sapphi-red
Copy link
Member

I guess we can change that line to (isPnp || !file.startsWith(withTrailingSlash(root))) && .
Related: yarnpkg/berry#2959

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

Successfully merging a pull request may close this issue.

2 participants