-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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 global add
on Windows
#1043
Conversation
global add
on Windows
What do you think about #1226 ? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense.
Could you fix a nit and let's merge it
@@ -114,6 +114,9 @@ async function initUpdateBins(config: Config, reporter: Reporter): Promise<() => | |||
const dest = path.join(binFolder, path.basename(src)); | |||
await fs.unlink(dest); | |||
await linkBin(src, dest); | |||
if (process.platform === 'win32' && dest.indexOf('.cmd') != -1) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: !== -1
@FLGMwt Are you still working on it? Looks like it's so close to being merged. |
merged? I am using 0.17.10 on Windows7, it still create .cmd.cmd file. |
Sorry all! Lost my GitHub notifications for awhile and missed the response. Nit fixed @bestander : ) |
Summary
yarn global add <package>
is almost entirely broken on Windows due to the global linking workflow trying to use cmd-shim for linking more than one level. 😞During a global install, we first do the normal install, which cmd-shims all the bins into node_modules/.bin. cmd-shiming involves creating a
sh
style andcmd
style passthru script for each bin in the package. However, since yarn globals link to those and not the package bins directly (like npm does), we need and extra level of linking from globalbin to node_modules/.bin.node_modules/.bin/pm2
turns intonode/pm2
andnode/pm2.cmd
then
node_modules/.bin/pm2.cmd
turns intonode/pm2.cmd
andnode/pm2.cmd.cmd
The second
node/pm2.cmd
overwrites the first, but there's no way to configure cmd-shim to do anything else. Whats more, neither of the twopm2.cmd
s are valid. The first one is a cmd-style wrapper to a sh style script and the second (despite the name) is a sh-style script to a cmd style script in the /.bin.The two valid files are
node/pm2
which is an sh that calls the.bin/pm2
sh which calls the package bin andnode/pm2.cmd.cmd
which is a cmd that calls the.bin/pm2.cmd
which calls the package bin. Without any way to configure cmd-shim, I opted for renamingnode/pm2.cmd.cmd
asnode/pm2.cmd
after the shims are done.I've been struggling for a while about how to fix this (might involve a forking cmd-shim), but I think it's worth temporarily shifting the jank from global installs not working at all to not working exactly as they should.
Test plan
Before:
yarn global add pm2
resulted in a broken global install and an extra filepm2.cmd.cmd
.After changes, pm2 works correctly after installing in powershell shown here:
and the global bin has only the sh and cmd files: