Skip to content

Commit

Permalink
fix: properly quote arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
henrycunh committed Feb 23, 2022
1 parent 05b7bbe commit b41a3d6
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/index.ts
Expand Up @@ -12,17 +12,17 @@ import { template } from './template'
export const argv = minimist(process.argv.slice(2))
export const sleep = (ms: number) => new Promise(resolve => setTimeout(resolve, ms))

export function $(tokens: string[], ...args: any[]) {
export function $(tokens, ...args) {
const { verbose, shell, prefix, quote } = $

const __from = (new Error('-').stack.split(/^\s*at\s/m)[2]).trim()

let command = tokens[0]
args.forEach((arg, index) => {
const parsedArgument = Array.isArray(arg)
? arg.map(_arg => quote(pruneNewlines(_arg)))
? arg.map(_arg => quote(pruneNewlines(_arg))).join(' ')
: quote(pruneNewlines(arg))
command += parsedArgument + tokens[index]
command += parsedArgument + tokens[index + 1]
})

let resolve, reject
Expand Down Expand Up @@ -67,6 +67,7 @@ export function $(tokens: string[], ...args: any[]) {
}

setTimeout(promise._run, 0) // Make sure all subprocesses started.
promise.command = command
return promise
}

Expand Down Expand Up @@ -118,7 +119,7 @@ function quote(arg) {
.replace(/\t/g, '\\t')
.replace(/\v/g, '\\v')
.replace(/\0/g, '\\0')
return `$'${argScaped}'`
return `'${argScaped}'`
}

function printCommand(command: string) {
Expand Down

0 comments on commit b41a3d6

Please sign in to comment.