vendor-index.29636037.mjs 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275
  1. import { c as commonjsGlobal } from './vendor-_commonjsHelpers.4da45ef5.mjs';
  2. import assert$1 from 'assert';
  3. import require$$2 from 'events';
  4. var signalExit = {exports: {}};
  5. var signals$1 = {exports: {}};
  6. var hasRequiredSignals;
  7. function requireSignals () {
  8. if (hasRequiredSignals) return signals$1.exports;
  9. hasRequiredSignals = 1;
  10. (function (module) {
  11. // This is not the set of all possible signals.
  12. //
  13. // It IS, however, the set of all signals that trigger
  14. // an exit on either Linux or BSD systems. Linux is a
  15. // superset of the signal names supported on BSD, and
  16. // the unknown signals just fail to register, so we can
  17. // catch that easily enough.
  18. //
  19. // Don't bother with SIGKILL. It's uncatchable, which
  20. // means that we can't fire any callbacks anyway.
  21. //
  22. // If a user does happen to register a handler on a non-
  23. // fatal signal like SIGWINCH or something, and then
  24. // exit, it'll end up firing `process.emit('exit')`, so
  25. // the handler will be fired anyway.
  26. //
  27. // SIGBUS, SIGFPE, SIGSEGV and SIGILL, when not raised
  28. // artificially, inherently leave the process in a
  29. // state from which it is not safe to try and enter JS
  30. // listeners.
  31. module.exports = [
  32. 'SIGABRT',
  33. 'SIGALRM',
  34. 'SIGHUP',
  35. 'SIGINT',
  36. 'SIGTERM'
  37. ];
  38. if (process.platform !== 'win32') {
  39. module.exports.push(
  40. 'SIGVTALRM',
  41. 'SIGXCPU',
  42. 'SIGXFSZ',
  43. 'SIGUSR2',
  44. 'SIGTRAP',
  45. 'SIGSYS',
  46. 'SIGQUIT',
  47. 'SIGIOT'
  48. // should detect profiler and enable/disable accordingly.
  49. // see #21
  50. // 'SIGPROF'
  51. );
  52. }
  53. if (process.platform === 'linux') {
  54. module.exports.push(
  55. 'SIGIO',
  56. 'SIGPOLL',
  57. 'SIGPWR',
  58. 'SIGSTKFLT',
  59. 'SIGUNUSED'
  60. );
  61. }
  62. } (signals$1));
  63. return signals$1.exports;
  64. }
  65. // Note: since nyc uses this module to output coverage, any lines
  66. // that are in the direct sync flow of nyc's outputCoverage are
  67. // ignored, since we can never get coverage for them.
  68. // grab a reference to node's real process object right away
  69. var process$1 = commonjsGlobal.process;
  70. const processOk = function (process) {
  71. return process &&
  72. typeof process === 'object' &&
  73. typeof process.removeListener === 'function' &&
  74. typeof process.emit === 'function' &&
  75. typeof process.reallyExit === 'function' &&
  76. typeof process.listeners === 'function' &&
  77. typeof process.kill === 'function' &&
  78. typeof process.pid === 'number' &&
  79. typeof process.on === 'function'
  80. };
  81. // some kind of non-node environment, just no-op
  82. /* istanbul ignore if */
  83. if (!processOk(process$1)) {
  84. signalExit.exports = function () {
  85. return function () {}
  86. };
  87. } else {
  88. var assert = assert$1;
  89. var signals = requireSignals();
  90. var isWin = /^win/i.test(process$1.platform);
  91. var EE = require$$2;
  92. /* istanbul ignore if */
  93. if (typeof EE !== 'function') {
  94. EE = EE.EventEmitter;
  95. }
  96. var emitter;
  97. if (process$1.__signal_exit_emitter__) {
  98. emitter = process$1.__signal_exit_emitter__;
  99. } else {
  100. emitter = process$1.__signal_exit_emitter__ = new EE();
  101. emitter.count = 0;
  102. emitter.emitted = {};
  103. }
  104. // Because this emitter is a global, we have to check to see if a
  105. // previous version of this library failed to enable infinite listeners.
  106. // I know what you're about to say. But literally everything about
  107. // signal-exit is a compromise with evil. Get used to it.
  108. if (!emitter.infinite) {
  109. emitter.setMaxListeners(Infinity);
  110. emitter.infinite = true;
  111. }
  112. signalExit.exports = function (cb, opts) {
  113. /* istanbul ignore if */
  114. if (!processOk(commonjsGlobal.process)) {
  115. return function () {}
  116. }
  117. assert.equal(typeof cb, 'function', 'a callback must be provided for exit handler');
  118. if (loaded === false) {
  119. load();
  120. }
  121. var ev = 'exit';
  122. if (opts && opts.alwaysLast) {
  123. ev = 'afterexit';
  124. }
  125. var remove = function () {
  126. emitter.removeListener(ev, cb);
  127. if (emitter.listeners('exit').length === 0 &&
  128. emitter.listeners('afterexit').length === 0) {
  129. unload();
  130. }
  131. };
  132. emitter.on(ev, cb);
  133. return remove
  134. };
  135. var unload = function unload () {
  136. if (!loaded || !processOk(commonjsGlobal.process)) {
  137. return
  138. }
  139. loaded = false;
  140. signals.forEach(function (sig) {
  141. try {
  142. process$1.removeListener(sig, sigListeners[sig]);
  143. } catch (er) {}
  144. });
  145. process$1.emit = originalProcessEmit;
  146. process$1.reallyExit = originalProcessReallyExit;
  147. emitter.count -= 1;
  148. };
  149. signalExit.exports.unload = unload;
  150. var emit = function emit (event, code, signal) {
  151. /* istanbul ignore if */
  152. if (emitter.emitted[event]) {
  153. return
  154. }
  155. emitter.emitted[event] = true;
  156. emitter.emit(event, code, signal);
  157. };
  158. // { <signal>: <listener fn>, ... }
  159. var sigListeners = {};
  160. signals.forEach(function (sig) {
  161. sigListeners[sig] = function listener () {
  162. /* istanbul ignore if */
  163. if (!processOk(commonjsGlobal.process)) {
  164. return
  165. }
  166. // If there are no other listeners, an exit is coming!
  167. // Simplest way: remove us and then re-send the signal.
  168. // We know that this will kill the process, so we can
  169. // safely emit now.
  170. var listeners = process$1.listeners(sig);
  171. if (listeners.length === emitter.count) {
  172. unload();
  173. emit('exit', null, sig);
  174. /* istanbul ignore next */
  175. emit('afterexit', null, sig);
  176. /* istanbul ignore next */
  177. if (isWin && sig === 'SIGHUP') {
  178. // "SIGHUP" throws an `ENOSYS` error on Windows,
  179. // so use a supported signal instead
  180. sig = 'SIGINT';
  181. }
  182. /* istanbul ignore next */
  183. process$1.kill(process$1.pid, sig);
  184. }
  185. };
  186. });
  187. signalExit.exports.signals = function () {
  188. return signals
  189. };
  190. var loaded = false;
  191. var load = function load () {
  192. if (loaded || !processOk(commonjsGlobal.process)) {
  193. return
  194. }
  195. loaded = true;
  196. // This is the number of onSignalExit's that are in play.
  197. // It's important so that we can count the correct number of
  198. // listeners on signals, and don't wait for the other one to
  199. // handle it instead of us.
  200. emitter.count += 1;
  201. signals = signals.filter(function (sig) {
  202. try {
  203. process$1.on(sig, sigListeners[sig]);
  204. return true
  205. } catch (er) {
  206. return false
  207. }
  208. });
  209. process$1.emit = processEmit;
  210. process$1.reallyExit = processReallyExit;
  211. };
  212. signalExit.exports.load = load;
  213. var originalProcessReallyExit = process$1.reallyExit;
  214. var processReallyExit = function processReallyExit (code) {
  215. /* istanbul ignore if */
  216. if (!processOk(commonjsGlobal.process)) {
  217. return
  218. }
  219. process$1.exitCode = code || /* istanbul ignore next */ 0;
  220. emit('exit', process$1.exitCode, null);
  221. /* istanbul ignore next */
  222. emit('afterexit', process$1.exitCode, null);
  223. /* istanbul ignore next */
  224. originalProcessReallyExit.call(process$1, process$1.exitCode);
  225. };
  226. var originalProcessEmit = process$1.emit;
  227. var processEmit = function processEmit (ev, arg) {
  228. if (ev === 'exit' && processOk(commonjsGlobal.process)) {
  229. /* istanbul ignore else */
  230. if (arg !== undefined) {
  231. process$1.exitCode = arg;
  232. }
  233. var ret = originalProcessEmit.apply(this, arguments);
  234. /* istanbul ignore next */
  235. emit('exit', process$1.exitCode, null);
  236. /* istanbul ignore next */
  237. emit('afterexit', process$1.exitCode, null);
  238. /* istanbul ignore next */
  239. return ret
  240. } else {
  241. return originalProcessEmit.apply(this, arguments)
  242. }
  243. };
  244. }
  245. export { signalExit as s };