Local node incorrectly resolved on Windows

Open
#41 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

  • #42 by @connorjsmith — closed without merging

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
45/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
javascript
Domain
cli, tooling

Research direction

Start by reviewing the change in issue #26 and the cmd-shim entry points that generate Windows command scripts. Reproduce the local-node and PATH-node cases on Windows using the proposed command forms; done means local node paths still work while the fallback node command does not use unnecessary quotes.

Written by the indexing model from the issue text.

Description

Disclaimer: I am not that experienced with cmd scripting

After updating to the latest npm, some of our scripts broke. I traced this to the change in #26, which always quotes the executable name (even if it is just node). This seems to cause issues for some paths (The system cannot find the path specified.)

Proposed fix (using tslint as an example):

@ECHO off
SETLOCAL
CALL :find_dp0

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

%_maybeQuote%%_prog%%_maybeQuote%  "%dp0%\..\tslint\bin\tslint" %*
ENDLOCAL
EXIT /b %errorlevel%
:find_dp0
SET dp0=%~dp0
EXIT /b

For the %dp0% case, this resolves to
"%dp0%\node.exe" "%dp0%\..\tslint\bin\tslint" %*
otherwise, it resolves to
node "%dp0%\..\tslint\bin\tslint" %*

Effectively, we only use quotes around the node executable when we use .bin\node.exe

Dominant language
JavaScript
Stars
81
Forks
51
PR merge metrics
No merged PRs in 30d

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from npm/cmd-shim

All issues in npm/cmd-shim

Similar issues

More JavaScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.