npm / cmd-shim

The cmd-shim used in npm
ISC License
76 stars 40 forks source link

Fix: Fixed an issue with files named node.js on Windows #64

Open giovannicalo opened 2 years ago

giovannicalo commented 2 years ago

When a Node module binary is run in a folder containing a file called node.js, on Windows, that file will be opened instead of the binary.

This happens due to Windows' PATHEXT environment variable containing .JS.

The issue was originally fixed in 8b1433c26aabf0d38b70a3fec6162dfd699fad24, but it has reappeared in c0396463c1730e812b1d4c461871aa7d0961ccef.

Currently, endlocal is called after editing PATHEXT but before invoking Node, so the latter is not affected by it.

My solution edits PATHEXT after calling endlocal, thus affecting the Node invocation and fixing the issue.

The only downside is the Node process will receive the edited PATHEXT, which however must've been the original behaviour anyway.