Skip to content

Capture signal exits more than once #80

Open
@erictheswift

Description

@erictheswift

Hi! 👋

Firstly, thanks for your work on this project! 🙂

Today I used patch-package to patch signal-exit@4.1.0 for the project I'm working on.

I saw version 4.1.0 to

Add the ability to capture signal exits by returning true from the onExit listener.

and decided to try.
I found that capturing signal by returning true actually works only once — after first capture signal-exit eats it successfully but gets unloaded.

Here is the diff that solved my problem:

diff --git a/node_modules/signal-exit/dist/mjs/index.js b/node_modules/signal-exit/dist/mjs/index.js
index 4a78bad..3a289aa 100644
--- a/node_modules/signal-exit/dist/mjs/index.js
+++ b/node_modules/signal-exit/dist/mjs/index.js
@@ -61,13 +61,14 @@ class Emitter {
         if (this.emitted[ev]) {
             return false;
         }
-        this.emitted[ev] = true;
         let ret = false;
         for (const fn of this.listeners[ev]) {
             ret = fn(code, signal) === true || ret;
         }
+        this.emitted[ev] = !ret;
         if (ev === 'exit') {
             ret = this.emit('afterExit', code, signal) || ret;
+            this.emitted['afterExit'] = !ret;
         }
         return ret;
     }
@@ -139,6 +140,7 @@ class SignalExit extends SignalExitBase {
                     const s = sig === 'SIGHUP' ? this.#hupSig : sig;
                     if (!ret)
                         process.kill(process.pid, s);
+                    else this.load()
                     /* c8 ignore stop */
                 }
             };

This issue body was partially generated by patch-package.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions