npm / cmd-shim

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

[BUG] [ReOpening] Having a file named node.js will be "run" instead of node #71

Open ckohen opened 2 years ago

ckohen commented 2 years ago

Is there an existing issue for this?

The existing issue was closed with the reason JS shouldn't be in your pathext environment variable. While that is a solution, it is a completely invalid solution from my perspective. It took me 2 hours of debugging to identify that was the problem, and in case you were unaware, that is the default in Windows. Though it certainly seems like you are aware given you attempt to remove it in the shim. Now that I know what it is, its an easy fix, but that's a terrible developer experience and needs fixing.

Current Behavior

For reference, npms generated shim for rimraf:

@ECHO off
GOTO start
:find_dp0
SET dp0=%~dp0
EXIT /b
:start
SETLOCAL
CALL :find_dp0

IF EXIST "%dp0%\node.exe" (
  SET "_prog=%dp0%\node.exe"
) ELSE (
  SET "_prog=node"
  SET PATHEXT=%PATHEXT:;.JS;=;%
)

endLocal & goto #_undefined_# 2>NUL || title %COMSPEC% & "%_prog%"  "%dp0%\..\rimraf\bin.js" %*

Expected Behavior

For reference, yarns generated shim for rimraf:

@IF EXIST "%~dp0\node.exe" (
  "%~dp0\node.exe"  "%~dp0\..\rimraf\bin.js" %*
) ELSE (
  @SETLOCAL
  @SET PATHEXT=%PATHEXT:;.JS;=;%
  node  "%~dp0\..\rimraf\bin.js" %*
)

Steps To Reproduce

  1. npm install a package with a bin script
  2. create a file called node.js in the same directory as the package.json you will be running scripts from OR the directory you run the command directly from
  3. run the script via a script in package.json OR with npx
  4. notice the file opens and the script never runs

Environment