Skip to content

Commit

Permalink
fix: do not blow up if process is missing
Browse files Browse the repository at this point in the history
  • Loading branch information
isaacs committed Sep 14, 2021
1 parent 39dcb4e commit bec9f56
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
6 changes: 5 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
'use strict'
const proc = typeof process === 'object' && process ? process : {
stdout: null,
stderr: null,
}
const EE = require('events')
const Stream = require('stream')
const Yallist = require('yallist')
Expand Down Expand Up @@ -310,7 +314,7 @@ module.exports = class Minipass extends Stream {

const ended = this[EMITTED_END]
opts = opts || {}
if (dest === process.stdout || dest === process.stderr)
if (dest === proc.stdout || dest === proc.stderr)
opts.end = false
else
opts.end = opts.end !== false
Expand Down
12 changes: 12 additions & 0 deletions test/no-process-ok.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
const tap = require('tap')
const proc = global.process
global.process = null
const MP = require('../')
const src = new MP()
const dest = new MP({ encoding: 'utf8' })
src.pipe(dest)
src.end('ok')
const result = dest.read()
global.process = proc
const t = require('tap')
t.equal(result, 'ok')

0 comments on commit bec9f56

Please sign in to comment.