Skip to content

Commit 7b4aa59

Browse files
isaacsfritzy
authored andcommitted
1 parent 654908f commit 7b4aa59

File tree

5 files changed

+1043
-1052
lines changed

5 files changed

+1043
-1052
lines changed

node_modules/.gitignore

-4
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,6 @@ readme*
255255
/lodash.merge
256256
/lodash.uniq
257257
/log-driver
258-
/loose-envify
259258
/make-dir
260259
/markdown-escapes
261260
/marked
@@ -300,16 +299,13 @@ readme*
300299
/prelude-ls
301300
/process-on-spawn
302301
/progress
303-
/prop-types
304302
/property-information
305303
/psl
306304
/pump
307305
/punycode
308306
/qs
309307
/queue-microtask
310308
/rc
311-
/react
312-
/react-is
313309
/read-package-tree
314310
/readdirp
315311
/regexpp

node_modules/signal-exit/index.js

+167-130
Original file line numberDiff line numberDiff line change
@@ -1,163 +1,200 @@
11
// Note: since nyc uses this module to output coverage, any lines
22
// that are in the direct sync flow of nyc's outputCoverage are
33
// ignored, since we can never get coverage for them.
4-
var assert = require('assert')
5-
var signals = require('./signals.js')
6-
var isWin = /^win/i.test(process.platform)
7-
8-
var EE = require('events')
9-
/* istanbul ignore if */
10-
if (typeof EE !== 'function') {
11-
EE = EE.EventEmitter
4+
// grab a reference to node's real process object right away
5+
var process = global.process
6+
7+
const processOk = function (process) {
8+
return process &&
9+
typeof process === 'object' &&
10+
typeof process.removeListener === 'function' &&
11+
typeof process.emit === 'function' &&
12+
typeof process.reallyExit === 'function' &&
13+
typeof process.listeners === 'function' &&
14+
typeof process.kill === 'function' &&
15+
typeof process.pid === 'number' &&
16+
typeof process.on === 'function'
1217
}
1318

14-
var emitter
15-
if (process.__signal_exit_emitter__) {
16-
emitter = process.__signal_exit_emitter__
19+
// some kind of non-node environment, just no-op
20+
/* istanbul ignore if */
21+
if (!processOk(process)) {
22+
module.exports = function () {}
1723
} else {
18-
emitter = process.__signal_exit_emitter__ = new EE()
19-
emitter.count = 0
20-
emitter.emitted = {}
21-
}
22-
23-
// Because this emitter is a global, we have to check to see if a
24-
// previous version of this library failed to enable infinite listeners.
25-
// I know what you're about to say. But literally everything about
26-
// signal-exit is a compromise with evil. Get used to it.
27-
if (!emitter.infinite) {
28-
emitter.setMaxListeners(Infinity)
29-
emitter.infinite = true
30-
}
31-
32-
module.exports = function (cb, opts) {
33-
assert.equal(typeof cb, 'function', 'a callback must be provided for exit handler')
24+
var assert = require('assert')
25+
var signals = require('./signals.js')
26+
var isWin = /^win/i.test(process.platform)
27+
28+
var EE = require('events')
29+
/* istanbul ignore if */
30+
if (typeof EE !== 'function') {
31+
EE = EE.EventEmitter
32+
}
3433

35-
if (loaded === false) {
36-
load()
34+
var emitter
35+
if (process.__signal_exit_emitter__) {
36+
emitter = process.__signal_exit_emitter__
37+
} else {
38+
emitter = process.__signal_exit_emitter__ = new EE()
39+
emitter.count = 0
40+
emitter.emitted = {}
3741
}
3842

39-
var ev = 'exit'
40-
if (opts && opts.alwaysLast) {
41-
ev = 'afterexit'
43+
// Because this emitter is a global, we have to check to see if a
44+
// previous version of this library failed to enable infinite listeners.
45+
// I know what you're about to say. But literally everything about
46+
// signal-exit is a compromise with evil. Get used to it.
47+
if (!emitter.infinite) {
48+
emitter.setMaxListeners(Infinity)
49+
emitter.infinite = true
4250
}
4351

44-
var remove = function () {
45-
emitter.removeListener(ev, cb)
46-
if (emitter.listeners('exit').length === 0 &&
47-
emitter.listeners('afterexit').length === 0) {
48-
unload()
52+
module.exports = function (cb, opts) {
53+
/* istanbul ignore if */
54+
if (!processOk(global.process)) {
55+
return
4956
}
50-
}
51-
emitter.on(ev, cb)
57+
assert.equal(typeof cb, 'function', 'a callback must be provided for exit handler')
5258

53-
return remove
54-
}
59+
if (loaded === false) {
60+
load()
61+
}
5562

56-
module.exports.unload = unload
57-
function unload () {
58-
if (!loaded) {
59-
return
60-
}
61-
loaded = false
63+
var ev = 'exit'
64+
if (opts && opts.alwaysLast) {
65+
ev = 'afterexit'
66+
}
6267

63-
signals.forEach(function (sig) {
64-
try {
65-
process.removeListener(sig, sigListeners[sig])
66-
} catch (er) {}
67-
})
68-
process.emit = originalProcessEmit
69-
process.reallyExit = originalProcessReallyExit
70-
emitter.count -= 1
71-
}
68+
var remove = function () {
69+
emitter.removeListener(ev, cb)
70+
if (emitter.listeners('exit').length === 0 &&
71+
emitter.listeners('afterexit').length === 0) {
72+
unload()
73+
}
74+
}
75+
emitter.on(ev, cb)
7276

73-
function emit (event, code, signal) {
74-
if (emitter.emitted[event]) {
75-
return
77+
return remove
7678
}
77-
emitter.emitted[event] = true
78-
emitter.emit(event, code, signal)
79-
}
8079

81-
// { <signal>: <listener fn>, ... }
82-
var sigListeners = {}
83-
signals.forEach(function (sig) {
84-
sigListeners[sig] = function listener () {
85-
// If there are no other listeners, an exit is coming!
86-
// Simplest way: remove us and then re-send the signal.
87-
// We know that this will kill the process, so we can
88-
// safely emit now.
89-
var listeners = process.listeners(sig)
90-
if (listeners.length === emitter.count) {
91-
unload()
92-
emit('exit', null, sig)
93-
/* istanbul ignore next */
94-
emit('afterexit', null, sig)
95-
/* istanbul ignore next */
96-
if (isWin && sig === 'SIGHUP') {
97-
// "SIGHUP" throws an `ENOSYS` error on Windows,
98-
// so use a supported signal instead
99-
sig = 'SIGINT'
100-
}
101-
process.kill(process.pid, sig)
80+
var unload = function unload () {
81+
if (!loaded || !processOk(global.process)) {
82+
return
10283
}
84+
loaded = false
85+
86+
signals.forEach(function (sig) {
87+
try {
88+
process.removeListener(sig, sigListeners[sig])
89+
} catch (er) {}
90+
})
91+
process.emit = originalProcessEmit
92+
process.reallyExit = originalProcessReallyExit
93+
emitter.count -= 1
10394
}
104-
})
105-
106-
module.exports.signals = function () {
107-
return signals
108-
}
95+
module.exports.unload = unload
10996

110-
module.exports.load = load
111-
112-
var loaded = false
113-
114-
function load () {
115-
if (loaded) {
116-
return
97+
var emit = function emit (event, code, signal) {
98+
/* istanbul ignore if */
99+
if (emitter.emitted[event]) {
100+
return
101+
}
102+
emitter.emitted[event] = true
103+
emitter.emit(event, code, signal)
117104
}
118-
loaded = true
119-
120-
// This is the number of onSignalExit's that are in play.
121-
// It's important so that we can count the correct number of
122-
// listeners on signals, and don't wait for the other one to
123-
// handle it instead of us.
124-
emitter.count += 1
125-
126-
signals = signals.filter(function (sig) {
127-
try {
128-
process.on(sig, sigListeners[sig])
129-
return true
130-
} catch (er) {
131-
return false
105+
106+
// { <signal>: <listener fn>, ... }
107+
var sigListeners = {}
108+
signals.forEach(function (sig) {
109+
sigListeners[sig] = function listener () {
110+
/* istanbul ignore if */
111+
if (!processOk(global.process)) {
112+
return
113+
}
114+
// If there are no other listeners, an exit is coming!
115+
// Simplest way: remove us and then re-send the signal.
116+
// We know that this will kill the process, so we can
117+
// safely emit now.
118+
var listeners = process.listeners(sig)
119+
if (listeners.length === emitter.count) {
120+
unload()
121+
emit('exit', null, sig)
122+
/* istanbul ignore next */
123+
emit('afterexit', null, sig)
124+
/* istanbul ignore next */
125+
if (isWin && sig === 'SIGHUP') {
126+
// "SIGHUP" throws an `ENOSYS` error on Windows,
127+
// so use a supported signal instead
128+
sig = 'SIGINT'
129+
}
130+
/* istanbul ignore next */
131+
process.kill(process.pid, sig)
132+
}
132133
}
133134
})
134135

135-
process.emit = processEmit
136-
process.reallyExit = processReallyExit
137-
}
136+
module.exports.signals = function () {
137+
return signals
138+
}
138139

139-
var originalProcessReallyExit = process.reallyExit
140-
function processReallyExit (code) {
141-
process.exitCode = code || 0
142-
emit('exit', process.exitCode, null)
143-
/* istanbul ignore next */
144-
emit('afterexit', process.exitCode, null)
145-
/* istanbul ignore next */
146-
originalProcessReallyExit.call(process, process.exitCode)
147-
}
140+
var loaded = false
141+
142+
var load = function load () {
143+
if (loaded || !processOk(global.process)) {
144+
return
145+
}
146+
loaded = true
147+
148+
// This is the number of onSignalExit's that are in play.
149+
// It's important so that we can count the correct number of
150+
// listeners on signals, and don't wait for the other one to
151+
// handle it instead of us.
152+
emitter.count += 1
153+
154+
signals = signals.filter(function (sig) {
155+
try {
156+
process.on(sig, sigListeners[sig])
157+
return true
158+
} catch (er) {
159+
return false
160+
}
161+
})
162+
163+
process.emit = processEmit
164+
process.reallyExit = processReallyExit
165+
}
166+
module.exports.load = load
148167

149-
var originalProcessEmit = process.emit
150-
function processEmit (ev, arg) {
151-
if (ev === 'exit') {
152-
if (arg !== undefined) {
153-
process.exitCode = arg
168+
var originalProcessReallyExit = process.reallyExit
169+
var processReallyExit = function processReallyExit (code) {
170+
/* istanbul ignore if */
171+
if (!processOk(global.process)) {
172+
return
154173
}
155-
var ret = originalProcessEmit.apply(this, arguments)
174+
process.exitCode = code || /* istanbul ignore next */ 0
156175
emit('exit', process.exitCode, null)
157176
/* istanbul ignore next */
158177
emit('afterexit', process.exitCode, null)
159-
return ret
160-
} else {
161-
return originalProcessEmit.apply(this, arguments)
178+
/* istanbul ignore next */
179+
originalProcessReallyExit.call(process, process.exitCode)
180+
}
181+
182+
var originalProcessEmit = process.emit
183+
var processEmit = function processEmit (ev, arg) {
184+
if (ev === 'exit' && processOk(global.process)) {
185+
/* istanbul ignore else */
186+
if (arg !== undefined) {
187+
process.exitCode = arg
188+
}
189+
var ret = originalProcessEmit.apply(this, arguments)
190+
/* istanbul ignore next */
191+
emit('exit', process.exitCode, null)
192+
/* istanbul ignore next */
193+
emit('afterexit', process.exitCode, null)
194+
/* istanbul ignore next */
195+
return ret
196+
} else {
197+
return originalProcessEmit.apply(this, arguments)
198+
}
162199
}
163200
}

node_modules/signal-exit/package.json

+10-10
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
{
22
"name": "signal-exit",
3-
"version": "3.0.3",
3+
"version": "3.0.6",
44
"description": "when you want to fire an event no matter how a process exits.",
55
"main": "index.js",
66
"scripts": {
7-
"pretest": "standard",
8-
"test": "tap --timeout=240 ./test/*.js --cov",
9-
"coverage": "nyc report --reporter=text-lcov | coveralls",
10-
"release": "standard-version"
7+
"test": "tap",
8+
"snap": "tap",
9+
"preversion": "npm test",
10+
"postversion": "npm publish",
11+
"prepublishOnly": "git push origin --follow-tags"
1112
},
1213
"files": [
1314
"index.js",
@@ -29,10 +30,9 @@
2930
"homepage": "https://github.com/tapjs/signal-exit",
3031
"devDependencies": {
3132
"chai": "^3.5.0",
32-
"coveralls": "^2.11.10",
33-
"nyc": "^8.1.0",
34-
"standard": "^8.1.0",
35-
"standard-version": "^2.3.0",
36-
"tap": "^8.0.1"
33+
"coveralls": "^3.1.1",
34+
"nyc": "^15.1.0",
35+
"standard-version": "^9.3.1",
36+
"tap": "^15.1.1"
3737
}
3838
}

0 commit comments

Comments
 (0)