From 213fed526df5e3f6043bdde72d288e88b5e1cd79 Mon Sep 17 00:00:00 2001 From: nlf Date: Wed, 22 Jun 2022 15:30:54 -0700 Subject: [PATCH] fix: remove extraneous space when no additional args are passed --- lib/make-spawn-args.js | 10 ++++++++-- test/make-spawn-args.js | 3 +-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/lib/make-spawn-args.js b/lib/make-spawn-args.js index ef27e91..c49b6ab 100644 --- a/lib/make-spawn-args.js +++ b/lib/make-spawn-args.js @@ -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) diff --git a/test/make-spawn-args.js b/test/make-spawn-args.js index 640dced..ed02533 100644 --- a/test/make-spawn-args.js +++ b/test/make-spawn-args.js @@ -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')