Skip to content

Commit

Permalink
fix(index.js): fix flow errors
Browse files Browse the repository at this point in the history
  • Loading branch information
jedwards1211 committed Oct 6, 2018
1 parent ace2c82 commit 8fe29c3
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,19 @@ type ErrorWithOutput = Error & Output & {

type ChildProcessPromise = ChildProcess & Promise<Output>

function joinChunks<T: string | Buffer>(chunks: Array<T>, encoding: string): T {
function joinChunks(chunks: $ReadOnlyArray<string | Buffer>, encoding: ?string): string | Buffer {
if (chunks[0] instanceof Buffer) {
const buffer = Buffer.concat(chunks)
if (encoding) return buffer.toString(encoding)
const buffer = Buffer.concat((chunks: any))
if (encoding) return buffer.toString((encoding: any))
return buffer
}
return chunks.join('')
}

export function promisifyChildProcess(child: ChildProcess, options: {encoding?: string} = {}): ChildProcessPromise {
const _promise = new Promise((resolve: (result: Output) => void, reject: (error: ErrorWithOutput) => void) => {
const stdoutChunks = []
const stderrChunks = []
const stdoutChunks: Array<string | Buffer> = []
const stderrChunks: Array<string | Buffer> = []
if (child.stdout) child.stdout.on('data', data => stdoutChunks.push(data))
if (child.stderr) child.stderr.on('data', data => stderrChunks.push(data))

Expand All @@ -42,7 +42,8 @@ export function promisifyChildProcess(child: ChildProcess, options: {encoding?:
if (error) {
if (code != null) error.code = code
if (signal != null) error.signal = signal
reject(Object.assign(error, output))
Object.assign(error, output)
reject(error)
} else {
resolve(output)
}
Expand Down

0 comments on commit 8fe29c3

Please sign in to comment.