fix(desktop): keep ! in npx arguments on Windows (#12680)

Signed-off-by: Seydi Charyyev <seydi.charyev@gmail.com>
This commit is contained in:
Seydi Charyyev
2026-10-19 23:05:53 +00:00
committed by GitHub
parent fb9e3c89b2
commit d409bc0818
2 changed files with 15 additions and 0 deletions
@@ -10,6 +10,8 @@ SET "MIN_SYSTEM_NODE_MAJOR=22"
REM === Check for previously downloaded portable Node.js (matching version) ===
if exist "%GOOSE_NODE_DIR%\node-v%NODE_VERSION%.installed" (
SET "PATH=%GOOSE_NODE_DIR%;!PATH!"
REM Turn delayed expansion off before npx runs, or cmd reads ! in the arguments as a variable.
SETLOCAL DisableDelayedExpansion
"%GOOSE_NODE_DIR%\npx.cmd" %*
exit /b !errorlevel!
)
@@ -24,6 +26,7 @@ for /f "delims=" %%N in ('where $PATH:node.exe 2^>nul') do (
call "%%~dpNnpx.cmd" --version <nul >nul 2>&1
if "!errorlevel!"=="0" (
SET "PATH=%%~dpN;!PATH!"
SETLOCAL DisableDelayedExpansion
"%%~dpNnpx.cmd" %*
exit /b !errorlevel!
)
@@ -57,6 +60,7 @@ if exist "%GOOSE_NODE_DIR%\npx.cmd" (
echo.>"%GOOSE_NODE_DIR%\node-v%NODE_VERSION%.installed"
SET "PATH=%GOOSE_NODE_DIR%;!PATH!"
echo [Goose] Node.js v%NODE_VERSION% ready. 1>&2
SETLOCAL DisableDelayedExpansion
"%GOOSE_NODE_DIR%\npx.cmd" %*
exit /b !errorlevel!
)
@@ -146,6 +146,17 @@ describe.skipIf(process.platform !== 'win32')('Windows npx wrapper', () => {
expect((JSON.parse(result.stdout) as ChildReport).nodeDir).toBe(systemNodeDir);
});
it.each<[string, () => { pathDirs: string[]; goosePortableDir?: string }]>([
['the downloaded Node.js', () => ({ pathDirs: [], goosePortableDir: portableNodeDir })],
['a system Node.js', () => ({ pathDirs: [systemNodeDir] })],
])('keeps ! and ^ in the arguments with %s', (_name, setup) => {
const args = ['-y', 'pkg', '--token=abc!123', '--pattern=a^b!c', 'x!'];
const result = runWrapper({ ...setup(), args });
expect(result.status).toBe(0);
expect((JSON.parse(result.stdout) as ChildReport).args).toEqual(args);
});
it('propagates the npx exit status', () => {
const result = runWrapper({ pathDirs: [systemNodeDir], args: ['-y', 'pkg'], exitCode: 37 });