aboutsummaryrefslogtreecommitdiff
path: root/node_modules/signal-exit
diff options
context:
space:
mode:
authorJoel Kronqvist <work.joelkronqvist@pm.me>2022-03-11 20:46:06 +0200
committerJoel Kronqvist <work.joelkronqvist@pm.me>2022-03-11 20:46:06 +0200
commit080c5819d87b933816d724a83f3bf4f1686770a7 (patch)
tree4a2ccc68b27edf7d4cbc586c932cc7542b655e19 /node_modules/signal-exit
parent5ac7049a9d30733165cc212dee308163c2a14644 (diff)
parentd003b82235a9329f912522a2f70aa950dfce4998 (diff)
downloadLYLLRuoka-080c5819d87b933816d724a83f3bf4f1686770a7.tar.gz
LYLLRuoka-080c5819d87b933816d724a83f3bf4f1686770a7.zip
Merge branch 'master' of https://github.com/JoelHMikael/FoodJS
Updating remote changes
Diffstat (limited to 'node_modules/signal-exit')
-rw-r--r--node_modules/signal-exit/LICENSE.txt16
-rw-r--r--node_modules/signal-exit/README.md39
-rw-r--r--node_modules/signal-exit/index.js202
-rw-r--r--node_modules/signal-exit/package.json38
-rw-r--r--node_modules/signal-exit/signals.js53
5 files changed, 348 insertions, 0 deletions
diff --git a/node_modules/signal-exit/LICENSE.txt b/node_modules/signal-exit/LICENSE.txt
new file mode 100644
index 0000000..eead04a
--- /dev/null
+++ b/node_modules/signal-exit/LICENSE.txt
@@ -0,0 +1,16 @@
+The ISC License
+
+Copyright (c) 2015, Contributors
+
+Permission to use, copy, modify, and/or distribute this software
+for any purpose with or without fee is hereby granted, provided
+that the above copyright notice and this permission notice
+appear in all copies.
+
+THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
+OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE
+LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES
+OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
+WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
diff --git a/node_modules/signal-exit/README.md b/node_modules/signal-exit/README.md
new file mode 100644
index 0000000..f9c7c00
--- /dev/null
+++ b/node_modules/signal-exit/README.md
@@ -0,0 +1,39 @@
+# signal-exit
+
+[![Build Status](https://travis-ci.org/tapjs/signal-exit.png)](https://travis-ci.org/tapjs/signal-exit)
+[![Coverage](https://coveralls.io/repos/tapjs/signal-exit/badge.svg?branch=master)](https://coveralls.io/r/tapjs/signal-exit?branch=master)
+[![NPM version](https://img.shields.io/npm/v/signal-exit.svg)](https://www.npmjs.com/package/signal-exit)
+[![Standard Version](https://img.shields.io/badge/release-standard%20version-brightgreen.svg)](https://github.com/conventional-changelog/standard-version)
+
+When you want to fire an event no matter how a process exits:
+
+* reaching the end of execution.
+* explicitly having `process.exit(code)` called.
+* having `process.kill(pid, sig)` called.
+* receiving a fatal signal from outside the process
+
+Use `signal-exit`.
+
+```js
+var onExit = require('signal-exit')
+
+onExit(function (code, signal) {
+ console.log('process exited!')
+})
+```
+
+## API
+
+`var remove = onExit(function (code, signal) {}, options)`
+
+The return value of the function is a function that will remove the
+handler.
+
+Note that the function *only* fires for signals if the signal would
+cause the process to exit. That is, there are no other listeners, and
+it is a fatal signal.
+
+## Options
+
+* `alwaysLast`: Run this handler after any other signal or exit
+ handlers. This causes `process.emit` to be monkeypatched.
diff --git a/node_modules/signal-exit/index.js b/node_modules/signal-exit/index.js
new file mode 100644
index 0000000..93703f3
--- /dev/null
+++ b/node_modules/signal-exit/index.js
@@ -0,0 +1,202 @@
+// Note: since nyc uses this module to output coverage, any lines
+// that are in the direct sync flow of nyc's outputCoverage are
+// ignored, since we can never get coverage for them.
+// grab a reference to node's real process object right away
+var process = global.process
+
+const processOk = function (process) {
+ return process &&
+ typeof process === 'object' &&
+ typeof process.removeListener === 'function' &&
+ typeof process.emit === 'function' &&
+ typeof process.reallyExit === 'function' &&
+ typeof process.listeners === 'function' &&
+ typeof process.kill === 'function' &&
+ typeof process.pid === 'number' &&
+ typeof process.on === 'function'
+}
+
+// some kind of non-node environment, just no-op
+/* istanbul ignore if */
+if (!processOk(process)) {
+ module.exports = function () {
+ return function () {}
+ }
+} else {
+ var assert = require('assert')
+ var signals = require('./signals.js')
+ var isWin = /^win/i.test(process.platform)
+
+ var EE = require('events')
+ /* istanbul ignore if */
+ if (typeof EE !== 'function') {
+ EE = EE.EventEmitter
+ }
+
+ var emitter
+ if (process.__signal_exit_emitter__) {
+ emitter = process.__signal_exit_emitter__
+ } else {
+ emitter = process.__signal_exit_emitter__ = new EE()
+ emitter.count = 0
+ emitter.emitted = {}
+ }
+
+ // Because this emitter is a global, we have to check to see if a
+ // previous version of this library failed to enable infinite listeners.
+ // I know what you're about to say. But literally everything about
+ // signal-exit is a compromise with evil. Get used to it.
+ if (!emitter.infinite) {
+ emitter.setMaxListeners(Infinity)
+ emitter.infinite = true
+ }
+
+ module.exports = function (cb, opts) {
+ /* istanbul ignore if */
+ if (!processOk(global.process)) {
+ return function () {}
+ }
+ assert.equal(typeof cb, 'function', 'a callback must be provided for exit handler')
+
+ if (loaded === false) {
+ load()
+ }
+
+ var ev = 'exit'
+ if (opts && opts.alwaysLast) {
+ ev = 'afterexit'
+ }
+
+ var remove = function () {
+ emitter.removeListener(ev, cb)
+ if (emitter.listeners('exit').length === 0 &&
+ emitter.listeners('afterexit').length === 0) {
+ unload()
+ }
+ }
+ emitter.on(ev, cb)
+
+ return remove
+ }
+
+ var unload = function unload () {
+ if (!loaded || !processOk(global.process)) {
+ return
+ }
+ loaded = false
+
+ signals.forEach(function (sig) {
+ try {
+ process.removeListener(sig, sigListeners[sig])
+ } catch (er) {}
+ })
+ process.emit = originalProcessEmit
+ process.reallyExit = originalProcessReallyExit
+ emitter.count -= 1
+ }
+ module.exports.unload = unload
+
+ var emit = function emit (event, code, signal) {
+ /* istanbul ignore if */
+ if (emitter.emitted[event]) {
+ return
+ }
+ emitter.emitted[event] = true
+ emitter.emit(event, code, signal)
+ }
+
+ // { <signal>: <listener fn>, ... }
+ var sigListeners = {}
+ signals.forEach(function (sig) {
+ sigListeners[sig] = function listener () {
+ /* istanbul ignore if */
+ if (!processOk(global.process)) {
+ return
+ }
+ // If there are no other listeners, an exit is coming!
+ // Simplest way: remove us and then re-send the signal.
+ // We know that this will kill the process, so we can
+ // safely emit now.
+ var listeners = process.listeners(sig)
+ if (listeners.length === emitter.count) {
+ unload()
+ emit('exit', null, sig)
+ /* istanbul ignore next */
+ emit('afterexit', null, sig)
+ /* istanbul ignore next */
+ if (isWin && sig === 'SIGHUP') {
+ // "SIGHUP" throws an `ENOSYS` error on Windows,
+ // so use a supported signal instead
+ sig = 'SIGINT'
+ }
+ /* istanbul ignore next */
+ process.kill(process.pid, sig)
+ }
+ }
+ })
+
+ module.exports.signals = function () {
+ return signals
+ }
+
+ var loaded = false
+
+ var load = function load () {
+ if (loaded || !processOk(global.process)) {
+ return
+ }
+ loaded = true
+
+ // This is the number of onSignalExit's that are in play.
+ // It's important so that we can count the correct number of
+ // listeners on signals, and don't wait for the other one to
+ // handle it instead of us.
+ emitter.count += 1
+
+ signals = signals.filter(function (sig) {
+ try {
+ process.on(sig, sigListeners[sig])
+ return true
+ } catch (er) {
+ return false
+ }
+ })
+
+ process.emit = processEmit
+ process.reallyExit = processReallyExit
+ }
+ module.exports.load = load
+
+ var originalProcessReallyExit = process.reallyExit
+ var processReallyExit = function processReallyExit (code) {
+ /* istanbul ignore if */
+ if (!processOk(global.process)) {
+ return
+ }
+ process.exitCode = code || /* istanbul ignore next */ 0
+ emit('exit', process.exitCode, null)
+ /* istanbul ignore next */
+ emit('afterexit', process.exitCode, null)
+ /* istanbul ignore next */
+ originalProcessReallyExit.call(process, process.exitCode)
+ }
+
+ var originalProcessEmit = process.emit
+ var processEmit = function processEmit (ev, arg) {
+ if (ev === 'exit' && processOk(global.process)) {
+ /* istanbul ignore else */
+ if (arg !== undefined) {
+ process.exitCode = arg
+ }
+ var ret = originalProcessEmit.apply(this, arguments)
+ /* istanbul ignore next */
+ emit('exit', process.exitCode, null)
+ /* istanbul ignore next */
+ emit('afterexit', process.exitCode, null)
+ /* istanbul ignore next */
+ return ret
+ } else {
+ return originalProcessEmit.apply(this, arguments)
+ }
+ }
+}
diff --git a/node_modules/signal-exit/package.json b/node_modules/signal-exit/package.json
new file mode 100644
index 0000000..e1a0031
--- /dev/null
+++ b/node_modules/signal-exit/package.json
@@ -0,0 +1,38 @@
+{
+ "name": "signal-exit",
+ "version": "3.0.7",
+ "description": "when you want to fire an event no matter how a process exits.",
+ "main": "index.js",
+ "scripts": {
+ "test": "tap",
+ "snap": "tap",
+ "preversion": "npm test",
+ "postversion": "npm publish",
+ "prepublishOnly": "git push origin --follow-tags"
+ },
+ "files": [
+ "index.js",
+ "signals.js"
+ ],
+ "repository": {
+ "type": "git",
+ "url": "https://github.com/tapjs/signal-exit.git"
+ },
+ "keywords": [
+ "signal",
+ "exit"
+ ],
+ "author": "Ben Coe <ben@npmjs.com>",
+ "license": "ISC",
+ "bugs": {
+ "url": "https://github.com/tapjs/signal-exit/issues"
+ },
+ "homepage": "https://github.com/tapjs/signal-exit",
+ "devDependencies": {
+ "chai": "^3.5.0",
+ "coveralls": "^3.1.1",
+ "nyc": "^15.1.0",
+ "standard-version": "^9.3.1",
+ "tap": "^15.1.1"
+ }
+}
diff --git a/node_modules/signal-exit/signals.js b/node_modules/signal-exit/signals.js
new file mode 100644
index 0000000..3bd67a8
--- /dev/null
+++ b/node_modules/signal-exit/signals.js
@@ -0,0 +1,53 @@
+// This is not the set of all possible signals.
+//
+// It IS, however, the set of all signals that trigger
+// an exit on either Linux or BSD systems. Linux is a
+// superset of the signal names supported on BSD, and
+// the unknown signals just fail to register, so we can
+// catch that easily enough.
+//
+// Don't bother with SIGKILL. It's uncatchable, which
+// means that we can't fire any callbacks anyway.
+//
+// If a user does happen to register a handler on a non-
+// fatal signal like SIGWINCH or something, and then
+// exit, it'll end up firing `process.emit('exit')`, so
+// the handler will be fired anyway.
+//
+// SIGBUS, SIGFPE, SIGSEGV and SIGILL, when not raised
+// artificially, inherently leave the process in a
+// state from which it is not safe to try and enter JS
+// listeners.
+module.exports = [
+ 'SIGABRT',
+ 'SIGALRM',
+ 'SIGHUP',
+ 'SIGINT',
+ 'SIGTERM'
+]
+
+if (process.platform !== 'win32') {
+ module.exports.push(
+ 'SIGVTALRM',
+ 'SIGXCPU',
+ 'SIGXFSZ',
+ 'SIGUSR2',
+ 'SIGTRAP',
+ 'SIGSYS',
+ 'SIGQUIT',
+ 'SIGIOT'
+ // should detect profiler and enable/disable accordingly.
+ // see #21
+ // 'SIGPROF'
+ )
+}
+
+if (process.platform === 'linux') {
+ module.exports.push(
+ 'SIGIO',
+ 'SIGPOLL',
+ 'SIGPWR',
+ 'SIGSTKFLT',
+ 'SIGUNUSED'
+ )
+}