yarnpkg / berry

📦🐈 Active development trunk for Yarn ⚒
https://yarnpkg.com
BSD 2-Clause "Simplified" License
7.43k stars 1.11k forks source link

[Bug] Patched `fs` doesn't account for the `__virtual__` folder and its immediate children #2959

Open merceyz opened 3 years ago

merceyz commented 3 years ago

Describe the bug

The result of calling fs.readdir on <pwd>/.yarn doesn't include __virtual__ and its immediate children making libraries like chokidar unable to detect changes to virtual files (read: workspaces with peer dependencies)

To Reproduce

Reproduction ```js repro const fs = require('fs') const installPromise = packageJsonAndInstall({ dependencies: { [`react-dom`]: `17.0.0`, }, }); await expect(installPromise).resolves.toBeTruthy(); expect(fs.readdirSync(process.cwd() + '/.yarn')).toContain('__virtual__'); ```

Environment if relevant (please complete the following information):

yarnbot commented 3 years ago

This issue reproduces on master:

Error: expect(received).toContain(expected) // indexOf

Expected value: "__virtual__"
Received array: ["cache", "install-state.gz"]
    at module.exports (evalmachine.<anonymous>:12:50)
    at processTicksAndRejections (internal/process/task_queues.js:93:5)
    at async /github/workspace/.yarn/cache/@arcanis-sherlock-npm-2.0.2-91650a2501-627bee24a7.zip/node_modules/@arcanis/sherlock/lib/executeRepro.js:56:13
    at async executeInTempDirectory (/github/workspace/.yarn/cache/@arcanis-sherlock-npm-2.0.2-91650a2501-627bee24a7.zip/node_modules/@arcanis/sherlock/lib/executeRepro.js:17:16)
    at async Object.executeRepro (/github/workspace/.yarn/cache/@arcanis-sherlock-npm-2.0.2-91650a2501-627bee24a7.zip/node_modules/@arcanis/sherlock/lib/executeRepro.js:24:12)
    at async ExecCommand.execute (/github/workspace/.yarn/cache/@arcanis-sherlock-npm-2.0.2-91650a2501-627bee24a7.zip/node_modules/@arcanis/sherlock/lib/commands/exec.js:25:38)
    at async ExecCommand.validateAndExecute (/github/workspace/.yarn/cache/clipanion-npm-2.0.0-rc.16-b9444aaf89-91cf93ba72.zip/node_modules/clipanion/lib/advanced/Command.js:161:26)
    at async Cli.run (/github/workspace/.yarn/cache/clipanion-npm-2.0.0-rc.16-b9444aaf89-91cf93ba72.zip/node_modules/clipanion/lib/advanced/Cli.js:74:24)
    at async Cli.runExit (/github/workspace/.yarn/cache/clipanion-npm-2.0.0-rc.16-b9444aaf89-91cf93ba72.zip/node_modules/clipanion/lib/advanced/Cli.js:83:28)
arcanis commented 3 years ago

I'm not sure it's a bug, more like a limitation - the folder doesn't really exist, so it probably shouldn't be returned. Even if we could, there's by design an infinity of possible virtual paths, which couldn't be represented on the disk. We potentially could only show those that are in the PnP map, but it remains to see how much complexity it would add 🤔

kepta commented 3 years ago

Wanted to add that this is a blocker for using modern tools like Vite which depend on chokidar to watch for any changes in linked packaged.

missing1984 commented 3 years ago

+1 on this. I've used pnp for more than a year and this is one of the bugs that keep frustrated me.

DiFuks commented 8 months ago

This issue has been interfering with the operation of Vite since version 5.1.0 https://github.com/vitejs/vite/issues/15910#issuecomment-1945471207

There is a workaround, but it seems that this problem should be fixed on the yarn side.