Skip to content

[BUG] Reports invalid process.cwd() #69

@jclab-joseph

Description

@jclab-joseph

Is there an existing issue for this?

  • I have searched the existing issues

Current Behavior

The working directory changed by cd after setlocal is not maintained.
So process.cwd() returns the wrong location.

Expected Behavior

The current directory after the cd command should be kept.

Steps To Reproduce

$HOME\AppData\Roaming\npm\aaaa.js :

console.log('CWD:', process.cwd());

$HOME\AppData\Roaming\npm\test.cmd :

@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%\aaaa.js" %*

test.bat:

setlocal
cd C:\abcdefg\
test.cmd
endlocal

Run test.bat

CWD: C:\Users...\ (Other directory instead of "C:\abcdefg")

Environment

  • npm: 8.12.2
  • Node: v16.15.1
  • OS: Windows
  • platform:

Source

+ 'endLocal & goto #_undefined_# 2>NUL || title %COMSPEC% & '

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions