Skip to content

Commit

Permalink
fix: remove extraneous space when no additional args are passed (#82)
Browse files Browse the repository at this point in the history
  • Loading branch information
nlf committed Jun 22, 2022
1 parent 2daf8db commit 9e09bab
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
10 changes: 8 additions & 2 deletions lib/make-spawn-args.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,20 @@ const makeSpawnArgs = options => {

scriptFile = resolve(tmpdir(), `${event}-${Date.now()}.cmd`)
script += '@echo off\n'
script += `${cmd} ${args.map((arg) => escape.cmd(arg, doubleEscape)).join(' ')}`
script += cmd
if (args.length) {
script += ` ${args.map((arg) => escape.cmd(arg, doubleEscape)).join(' ')}`
}
} else {
const shebang = isAbsolute(scriptShell)
? `#!${scriptShell}`
: `#!/usr/bin/env ${scriptShell}`
scriptFile = resolve(tmpdir(), `${event}-${Date.now()}.sh`)
script += `${shebang}\n`
script += `${cmd} ${args.map((arg) => escape.sh(arg)).join(' ')}`
script += cmd
if (args.length) {
script += ` ${args.map((arg) => escape.sh(arg)).join(' ')}`
}
}

writeFile(scriptFile, script)
Expand Down
3 changes: 1 addition & 2 deletions test/make-spawn-args.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,7 @@ if (isWindows) {
}, 'got expected options')

const contents = fs.readFileSync(args[args.length - 1], { encoding: 'utf8' })
// the contents will have a trailing space if no args are passed
t.equal(contents, `@echo off\nscript "quoted parameter"; second command `)
t.equal(contents, `@echo off\nscript "quoted parameter"; second command`)
t.ok(fs.existsSync(args[args.length - 1]), 'script file was written')
cleanup()
t.not(fs.existsSync(args[args.length - 1]), 'cleanup removes script file')
Expand Down

0 comments on commit 9e09bab

Please sign in to comment.