From 2debda01b68b4568260cd197c4d0cbf6cfb71005 Mon Sep 17 00:00:00 2001 From: isaacs Date: Wed, 21 Aug 2019 14:01:41 -0700 Subject: [PATCH] fix: preserve exit code in .cmd files Because we're now exiting with an explicit exit command, we have to preserve %errorlevel% (the equivalent of $? in bash). --- index.js | 4 ++-- tap-snapshots/test-basic.js-TAP.test.js | 16 ++++++++-------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/index.js b/index.js index b1b6e58..010bd38 100644 --- a/index.js +++ b/index.js @@ -113,7 +113,7 @@ function writeShim_ (from, to, prog, args, variables, cb) { // // "%_prog%" "%dp0%\.\node_modules\npm\bin\npm-cli.js" %* // @ENDLOCAL - // @EXIT /b + // @EXIT /b %errorlevel% // // :find_dp0 // SET dp0=%~dp0 @@ -124,7 +124,7 @@ function writeShim_ (from, to, prog, args, variables, cb) { 'SETLOCAL\r\n' + 'CALL :find_dp0\r\n' var foot = 'ENDLOCAL\r\n' + - 'EXIT /b\r\n' + + 'EXIT /b %errorlevel%\r\n' + ':find_dp0\r\n' + 'SET dp0=%~dp0\r\n' + 'EXIT /b\r\n' diff --git a/tap-snapshots/test-basic.js-TAP.test.js b/tap-snapshots/test-basic.js-TAP.test.js index fde2210..1d5f5fd 100644 --- a/tap-snapshots/test-basic.js-TAP.test.js +++ b/tap-snapshots/test-basic.js-TAP.test.js @@ -19,7 +19,7 @@ IF EXIST "%dp0%\\node.exe" (\\r \\r "%_prog%" "%dp0%\\from.env" %*\\r ENDLOCAL\\r -EXIT /b\\r +EXIT /b %errorlevel%\\r :find_dp0\\r SET dp0=%~dp0\\r EXIT /b\\r @@ -81,7 +81,7 @@ IF EXIST "%dp0%\\node.exe" (\\r \\r "%_prog%" --expose_gc "%dp0%\\from.env.args" %*\\r ENDLOCAL\\r -EXIT /b\\r +EXIT /b %errorlevel%\\r :find_dp0\\r SET dp0=%~dp0\\r EXIT /b\\r @@ -144,7 +144,7 @@ IF EXIST "%dp0%\\node.exe" (\\r \\r "%_prog%" "%dp0%\\from.env.variables" %*\\r ENDLOCAL\\r -EXIT /b\\r +EXIT /b %errorlevel%\\r :find_dp0\\r SET dp0=%~dp0\\r EXIT /b\\r @@ -206,7 +206,7 @@ IF EXIST "%dp0%\\/usr/bin/sh.exe" (\\r \\r "%_prog%" "%dp0%\\from.sh" %*\\r ENDLOCAL\\r -EXIT /b\\r +EXIT /b %errorlevel%\\r :find_dp0\\r SET dp0=%~dp0\\r EXIT /b\\r @@ -268,7 +268,7 @@ IF EXIST "%dp0%\\/usr/bin/sh.exe" (\\r \\r "%_prog%" -x "%dp0%\\from.sh.args" %*\\r ENDLOCAL\\r -EXIT /b\\r +EXIT /b %errorlevel%\\r :find_dp0\\r SET dp0=%~dp0\\r EXIT /b\\r @@ -322,7 +322,7 @@ SETLOCAL\\r CALL :find_dp0\\r "%dp0%\\from.exe" %*\\r ENDLOCAL\\r -EXIT /b\\r +EXIT /b %errorlevel%\\r :find_dp0\\r SET dp0=%~dp0\\r EXIT /b\\r @@ -363,7 +363,7 @@ SETLOCAL\\r CALL :find_dp0\\r "%dp0%\\" %*\\r ENDLOCAL\\r -EXIT /b\\r +EXIT /b %errorlevel%\\r :find_dp0\\r SET dp0=%~dp0\\r EXIT /b\\r @@ -404,7 +404,7 @@ SETLOCAL\\r CALL :find_dp0\\r "%dp0%\\from.exe" %*\\r ENDLOCAL\\r -EXIT /b\\r +EXIT /b %errorlevel%\\r :find_dp0\\r SET dp0=%~dp0\\r EXIT /b\\r