ds300 / patch-package

Fix broken node modules instantly 🏃🏽‍♀️💨
MIT License
10.42k stars 294 forks source link

fix: follow cwd symlink on windows #410

Open mukaschultze opened 2 years ago

mukaschultze commented 2 years ago

Node's process.cwd() has different behaviour between unix OS's and Windows when the cwd is inside a symlink. This PR fixes this inconsistency by calling node's fs.realpathSync to follow the directory symlink and simulate unix's behaviour on Windows.

This incosistency causes patch-package to fail on Windows when it runs on a postinstall of a workspace package since yarn (and possibly other package managers as well) use symlinks to hoist packages to the root node_modules.

This PR also fixes the path comparison on the getAppRootPath, since Windows can have both \ and / path separators.

edusperoni commented 2 years ago

You might want to use .replace(sep, "/") (sep comes from path and will replace whatever the separator is on that filesystem to /)

milahu commented 2 years ago

https://github.com/milahu/patch-package/pull/21#issuecomment-1288918158