diff --git a/lib/make-spawn-args.js b/lib/make-spawn-args.js index 4c38b94..e82c405 100644 --- a/lib/make-spawn-args.js +++ b/lib/make-spawn-args.js @@ -3,24 +3,9 @@ const isWindows = require('./is-windows.js') const setPATH = require('./set-path.js') const {resolve} = require('path') const npm_config_node_gyp = require.resolve('node-gyp/bin/node-gyp.js') -const { quoteForShell, ShellString, ShellStringText, ShellStringUnquoted } = require('puka') +const { ShellString } = require('puka') -const escapeCmd = cmd => { - const result = [] - const parsed = ShellString.sh([cmd]) - for (const child of parsed.children) { - if (child instanceof ShellStringText) { - const children = child.contents.filter(segment => segment !== null).map(segment => quoteForShell(segment, false, isWindows && 'win32')) - result.push(...children) - } else if (child instanceof ShellStringUnquoted) { - result.push(child.value) - } else { - result.push(isWindows ? '&' : ';') - } - } - - return result.join('') -} +const escapeCmd = cmd => ShellString.sh([cmd]).toString(isWindows && 'win32') const makeSpawnArgs = options => { const { diff --git a/test/make-spawn-args.js b/test/make-spawn-args.js index 3aec461..5269ea0 100644 --- a/test/make-spawn-args.js +++ b/test/make-spawn-args.js @@ -59,6 +59,27 @@ if (isWindows) { } ]) + // empty string + t.match(makeSpawnArgs({ + event: 'event', + path: 'path', + cmd: 'script ""; second command', + scriptShell: 'cmd.exe', + }), [ + 'cmd.exe', + [ '/d', '/s', '/c', `script ""& second command` ], + { + env: { + npm_package_json: /package\.json$/, + npm_lifecycle_event: 'event', + npm_lifecycle_script: 'script' + }, + stdio: undefined, + cwd: 'path', + windowsVerbatimArguments: true, + } + ]) + t.match(makeSpawnArgs({ event: 'event', path: 'path',