From 54c4f7b8705b2c9d5b8bc5bb846f4e7863735b7e Mon Sep 17 00:00:00 2001 From: Gar Date: Tue, 14 Nov 2023 10:08:52 -0800 Subject: [PATCH] deps: signal-exit@4.1.0 --- node_modules/signal-exit/dist/cjs/index.js | 31 +++++++++++++--------- node_modules/signal-exit/dist/mjs/index.js | 31 +++++++++++++--------- node_modules/signal-exit/package.json | 2 +- package-lock.json | 6 ++--- 4 files changed, 42 insertions(+), 28 deletions(-) diff --git a/node_modules/signal-exit/dist/cjs/index.js b/node_modules/signal-exit/dist/cjs/index.js index 9312d0c96e879..797e6743fe48e 100644 --- a/node_modules/signal-exit/dist/cjs/index.js +++ b/node_modules/signal-exit/dist/cjs/index.js @@ -20,7 +20,7 @@ const processOk = (process) => !!process && const kExitEmitter = Symbol.for('signal-exit emitter'); const global = globalThis; const ObjectDefineProperty = Object.defineProperty.bind(Object); -// teeny tiny ee +// teeny special purpose ee class Emitter { emitted = { afterExit: false, @@ -63,12 +63,17 @@ class Emitter { } emit(ev, code, signal) { if (this.emitted[ev]) { - return; + return false; } this.emitted[ev] = true; + let ret = false; for (const fn of this.listeners[ev]) { - fn(code, signal); + ret = fn(code, signal) === true || ret; + } + if (ev === 'exit') { + ret = this.emit('afterExit', code, signal) || ret; } + return ret; } } class SignalExitBase { @@ -122,18 +127,22 @@ class SignalExit extends SignalExitBase { // exit v4 are not aware of each other, and each will attempt to let // the other handle it, so neither of them do. To correct this, we // detect if we're the only handler *except* for previous versions - // of signal-exit. + // of signal-exit, and increment by the count of listeners it has + // created. /* c8 ignore start */ - //@ts-ignore - if (typeof process.__signal_exit_emitter__ === 'object') - count++; + const p = process; + if (typeof p.__signal_exit_emitter__ === 'object' && + typeof p.__signal_exit_emitter__.count === 'number') { + count += p.__signal_exit_emitter__.count; + } /* c8 ignore stop */ if (listeners.length === count) { this.unload(); - this.#emitter.emit('exit', null, sig); - this.#emitter.emit('afterExit', null, sig); + const ret = this.#emitter.emit('exit', null, sig); /* c8 ignore start */ - process.kill(process.pid, sig === 'SIGHUP' ? this.#hupSig : sig); + const s = sig === 'SIGHUP' ? this.#hupSig : sig; + if (!ret) + process.kill(process.pid, s); /* c8 ignore stop */ } }; @@ -216,7 +225,6 @@ class SignalExit extends SignalExitBase { this.#process.exitCode = code || 0; /* c8 ignore stop */ this.#emitter.emit('exit', this.#process.exitCode, null); - this.#emitter.emit('afterExit', this.#process.exitCode, null); return this.#originalProcessReallyExit.call(this.#process, this.#process.exitCode); } #processEmit(ev, ...args) { @@ -230,7 +238,6 @@ class SignalExit extends SignalExitBase { const ret = og.call(this.#process, ev, ...args); /* c8 ignore start */ this.#emitter.emit('exit', this.#process.exitCode, null); - this.#emitter.emit('afterExit', this.#process.exitCode, null); /* c8 ignore stop */ return ret; } diff --git a/node_modules/signal-exit/dist/mjs/index.js b/node_modules/signal-exit/dist/mjs/index.js index 97f409239c8f3..4a78bad847d40 100644 --- a/node_modules/signal-exit/dist/mjs/index.js +++ b/node_modules/signal-exit/dist/mjs/index.js @@ -16,7 +16,7 @@ const processOk = (process) => !!process && const kExitEmitter = Symbol.for('signal-exit emitter'); const global = globalThis; const ObjectDefineProperty = Object.defineProperty.bind(Object); -// teeny tiny ee +// teeny special purpose ee class Emitter { emitted = { afterExit: false, @@ -59,12 +59,17 @@ class Emitter { } emit(ev, code, signal) { if (this.emitted[ev]) { - return; + return false; } this.emitted[ev] = true; + let ret = false; for (const fn of this.listeners[ev]) { - fn(code, signal); + ret = fn(code, signal) === true || ret; + } + if (ev === 'exit') { + ret = this.emit('afterExit', code, signal) || ret; } + return ret; } } class SignalExitBase { @@ -118,18 +123,22 @@ class SignalExit extends SignalExitBase { // exit v4 are not aware of each other, and each will attempt to let // the other handle it, so neither of them do. To correct this, we // detect if we're the only handler *except* for previous versions - // of signal-exit. + // of signal-exit, and increment by the count of listeners it has + // created. /* c8 ignore start */ - //@ts-ignore - if (typeof process.__signal_exit_emitter__ === 'object') - count++; + const p = process; + if (typeof p.__signal_exit_emitter__ === 'object' && + typeof p.__signal_exit_emitter__.count === 'number') { + count += p.__signal_exit_emitter__.count; + } /* c8 ignore stop */ if (listeners.length === count) { this.unload(); - this.#emitter.emit('exit', null, sig); - this.#emitter.emit('afterExit', null, sig); + const ret = this.#emitter.emit('exit', null, sig); /* c8 ignore start */ - process.kill(process.pid, sig === 'SIGHUP' ? this.#hupSig : sig); + const s = sig === 'SIGHUP' ? this.#hupSig : sig; + if (!ret) + process.kill(process.pid, s); /* c8 ignore stop */ } }; @@ -212,7 +221,6 @@ class SignalExit extends SignalExitBase { this.#process.exitCode = code || 0; /* c8 ignore stop */ this.#emitter.emit('exit', this.#process.exitCode, null); - this.#emitter.emit('afterExit', this.#process.exitCode, null); return this.#originalProcessReallyExit.call(this.#process, this.#process.exitCode); } #processEmit(ev, ...args) { @@ -226,7 +234,6 @@ class SignalExit extends SignalExitBase { const ret = og.call(this.#process, ev, ...args); /* c8 ignore start */ this.#emitter.emit('exit', this.#process.exitCode, null); - this.#emitter.emit('afterExit', this.#process.exitCode, null); /* c8 ignore stop */ return ret; } diff --git a/node_modules/signal-exit/package.json b/node_modules/signal-exit/package.json index 455452f96a0b3..ac176cec74374 100644 --- a/node_modules/signal-exit/package.json +++ b/node_modules/signal-exit/package.json @@ -1,6 +1,6 @@ { "name": "signal-exit", - "version": "4.0.2", + "version": "4.1.0", "description": "when you want to fire an event no matter how a process exits.", "main": "./dist/cjs/index.js", "module": "./dist/mjs/index.js", diff --git a/package-lock.json b/package-lock.json index a162df7ffd2b9..ff2f01a781979 100644 --- a/package-lock.json +++ b/package-lock.json @@ -13502,9 +13502,9 @@ } }, "node_modules/signal-exit": { - "version": "4.0.2", - "resolved": "https://registry.npmjs.org/signal-exit/-/signal-exit-4.0.2.tgz", - "integrity": "sha512-MY2/qGx4enyjprQnFaZsHib3Yadh3IXyV2C321GY0pjGfVBu4un0uDJkwgdxqO+Rdx8JMT8IfJIRwbYVz3Ob3Q==", + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/signal-exit/-/signal-exit-4.1.0.tgz", + "integrity": "sha512-bzyZ1e88w9O1iNJbKnOlvYTrWPDl46O1bG0D3XInv+9tkPrxrN8jUUTiFlDkkmKWgn1M6CfIA13SuGqOa9Korw==", "inBundle": true, "engines": { "node": ">=14"