Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 2 additions & 17 deletions lib/make-spawn-args.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
21 changes: 21 additions & 0 deletions test/make-spawn-args.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down