shelljs / shx

Portable Shell Commands for Node
MIT License
1.72k stars 44 forks source link

shx fails on Windows when a file named `node.js` exists #217

Closed JonathanHolvey closed 1 year ago

JonathanHolvey commented 1 year ago

To reproduce this issue:

touch node.js
npx shx ls

Here, shx will attempt to run node.js instead of node.exe, and nothing will happen. If node.js is a real JavaScript file, then it will be executed using the Windows Script Host.

Changing line 13 of node_modules/.bin/shx.cmd to SET "_prog=node.exe" allows shx to work as expected, but will probably break functionality for other users.

nfischer commented 1 year ago

Thanks for the bug report.

node_modules/.bin/shx.cmd is not actually a part of this project. This is a file which is automatically created by npm while it installs the package. I'm not sure what line 13 looked like before, but I think it's probably not something our project can control.

Does the same bug happen if you install a different npm package which has an executable? What happens if you run something like https://github.com/dthree/cash (or any npm package)?

npm install cash
node_modules\.bin\cash.cmd
JonathanHolvey commented 1 year ago

I think this is actually a Windows problem (or feature?), as I subsequently found that a file named node.js in the current directory will break anything that tries to execute node. The same would presumably be true for other files with an 'executable' extension that happen to share their name with an executable in PATH.