简体   繁体   中英

How do I make a working symlink to a command in my node_modules .bin folder on Windows?

I'd like to run lab from my root directory without having to mess with %bindir% or .\\node_modules\\.bin\\lab.cmd . I want to be able to run tests with $ lab and that's it.

Here's my attempt. Keep in mind that I've already set up some aliases for things like grep in Powershell.

$ ll .\node_modules\.bin | grep lab
-a----         7/5/2017   2:57 PM            293 lab
-a----         7/5/2017   2:57 PM            170 lab.cmd

$ cmd /c mklink lab .\node_modules\.bin\lab\lab.cmd
symbolic link created for lab <<===>> .\node_modules\.bin\lab\lab.cmd

$ ll lab

Mode                LastWriteTime         Length Name
----                -------------         ------ ----
-a---l         7/7/2017   9:04 AM              0 lab

$ lab
lab : The term 'lab' is not recognized as the name of a cmdlet, function, script file... 

$ ./lab
Program 'lab' failed to run: No application is associated with the specified file...

Naming the alias lab.cmd didn't do anything. Is this possible on Windows?

I really think it's a matter of Windows not really being built like that. I do think there is probably a way you could sort out the symlink but in all reality this is what the various powershell profiles are there for. When something shouldn't be system wide but you want easy and quick access to it.

If you want it to be available just to yourself you can put it in $profile, if you want it to be available to any user you happen to run powershell as you can put it in C:\\windows\\System32\\WindowsPowerShell\\v1.0\\Microsoft.PowerShell_profile.ps1

The functionality for symlinks exists in Windows, but it isn't as fleshed out as in *nix, for better or for worse, depending on locations, filenames and a whole host of other quirky things you are likely to run into all manner of problems.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM