From 051cf20072a01839c17920d2e841756251c4f924 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E7=A5=BA?= Date: Fri, 9 Nov 2018 17:33:09 +0800 Subject: [PATCH] fix switches for alternative shells on Windows On Windows, normalizeSpawnArguments set "/d /s /c" for any shells. It cause exec and other methods are limited to cmd.exe as a shell. Powershell and git-bash are often used instead of cmd.exe, and they can recieve "-c" switch like unix shells. So normalizeSpawnArguments is changed to set "/d /s /c" for cmd.exe, and "-c" for others. PR-URL: https://github.com/npm/npm-lifecycle/pull/26 Close: #26 Reviewed-by: @isaacs Credit: @gucong3000 --- index.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 59ac9c1..e9c4eba 100644 --- a/index.js +++ b/index.js @@ -288,8 +288,11 @@ function runCmd_ (cmd, pkg, env, wd, opts, stage, unsafe, uid, gid, cb_) { sh = customShell } else if (isWindows) { sh = process.env.comspec || 'cmd' - shFlag = '/d /s /c' - conf.windowsVerbatimArguments = true + // '/d /s /c' is used only for cmd.exe. + if (/^(?:.*\\)?cmd(?:\.exe)?$/i.test(sh)) { + shFlag = '/d /s /c' + conf.windowsVerbatimArguments = true + } } opts.log.verbose('lifecycle', logid(pkg, stage), 'PATH:', env[PATH])