123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275 |
- import { c as commonjsGlobal } from './vendor-_commonjsHelpers.4da45ef5.mjs';
- import assert$1 from 'assert';
- import require$$2 from 'events';
- var signalExit = {exports: {}};
- var signals$1 = {exports: {}};
- var hasRequiredSignals;
- function requireSignals () {
- if (hasRequiredSignals) return signals$1.exports;
- hasRequiredSignals = 1;
- (function (module) {
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- module.exports = [
- 'SIGABRT',
- 'SIGALRM',
- 'SIGHUP',
- 'SIGINT',
- 'SIGTERM'
- ];
- if (process.platform !== 'win32') {
- module.exports.push(
- 'SIGVTALRM',
- 'SIGXCPU',
- 'SIGXFSZ',
- 'SIGUSR2',
- 'SIGTRAP',
- 'SIGSYS',
- 'SIGQUIT',
- 'SIGIOT'
-
-
-
- );
- }
- if (process.platform === 'linux') {
- module.exports.push(
- 'SIGIO',
- 'SIGPOLL',
- 'SIGPWR',
- 'SIGSTKFLT',
- 'SIGUNUSED'
- );
- }
- } (signals$1));
- return signals$1.exports;
- }
- var process$1 = commonjsGlobal.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'
- };
- if (!processOk(process$1)) {
- signalExit.exports = function () {
- return function () {}
- };
- } else {
- var assert = assert$1;
- var signals = requireSignals();
- var isWin = /^win/i.test(process$1.platform);
- var EE = require$$2;
-
- if (typeof EE !== 'function') {
- EE = EE.EventEmitter;
- }
- var emitter;
- if (process$1.__signal_exit_emitter__) {
- emitter = process$1.__signal_exit_emitter__;
- } else {
- emitter = process$1.__signal_exit_emitter__ = new EE();
- emitter.count = 0;
- emitter.emitted = {};
- }
-
-
-
-
- if (!emitter.infinite) {
- emitter.setMaxListeners(Infinity);
- emitter.infinite = true;
- }
- signalExit.exports = function (cb, opts) {
-
- if (!processOk(commonjsGlobal.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(commonjsGlobal.process)) {
- return
- }
- loaded = false;
- signals.forEach(function (sig) {
- try {
- process$1.removeListener(sig, sigListeners[sig]);
- } catch (er) {}
- });
- process$1.emit = originalProcessEmit;
- process$1.reallyExit = originalProcessReallyExit;
- emitter.count -= 1;
- };
- signalExit.exports.unload = unload;
- var emit = function emit (event, code, signal) {
-
- if (emitter.emitted[event]) {
- return
- }
- emitter.emitted[event] = true;
- emitter.emit(event, code, signal);
- };
-
- var sigListeners = {};
- signals.forEach(function (sig) {
- sigListeners[sig] = function listener () {
-
- if (!processOk(commonjsGlobal.process)) {
- return
- }
-
-
-
-
- var listeners = process$1.listeners(sig);
- if (listeners.length === emitter.count) {
- unload();
- emit('exit', null, sig);
-
- emit('afterexit', null, sig);
-
- if (isWin && sig === 'SIGHUP') {
-
-
- sig = 'SIGINT';
- }
-
- process$1.kill(process$1.pid, sig);
- }
- };
- });
- signalExit.exports.signals = function () {
- return signals
- };
- var loaded = false;
- var load = function load () {
- if (loaded || !processOk(commonjsGlobal.process)) {
- return
- }
- loaded = true;
-
-
-
-
- emitter.count += 1;
- signals = signals.filter(function (sig) {
- try {
- process$1.on(sig, sigListeners[sig]);
- return true
- } catch (er) {
- return false
- }
- });
- process$1.emit = processEmit;
- process$1.reallyExit = processReallyExit;
- };
- signalExit.exports.load = load;
- var originalProcessReallyExit = process$1.reallyExit;
- var processReallyExit = function processReallyExit (code) {
-
- if (!processOk(commonjsGlobal.process)) {
- return
- }
- process$1.exitCode = code || 0;
- emit('exit', process$1.exitCode, null);
-
- emit('afterexit', process$1.exitCode, null);
-
- originalProcessReallyExit.call(process$1, process$1.exitCode);
- };
- var originalProcessEmit = process$1.emit;
- var processEmit = function processEmit (ev, arg) {
- if (ev === 'exit' && processOk(commonjsGlobal.process)) {
-
- if (arg !== undefined) {
- process$1.exitCode = arg;
- }
- var ret = originalProcessEmit.apply(this, arguments);
-
- emit('exit', process$1.exitCode, null);
-
- emit('afterexit', process$1.exitCode, null);
-
- return ret
- } else {
- return originalProcessEmit.apply(this, arguments)
- }
- };
- }
- export { signalExit as s };
|