[Pkg-javascript-commits] [node-foreground-child] 37/69: Set `process.exitCode` based on the child’s exit code

Bastien Roucariès rouca at moszumanska.debian.org
Fri Aug 25 11:43:05 UTC 2017


This is an automated email from the git hooks/post-receive script.

rouca pushed a commit to branch master
in repository node-foreground-child.

commit 12250bf35a4bc817cd6c11ddd0c8c7b18c081a88
Author: Anna Henningsen <sqrt at entless.org>
Date:   Sat Apr 2 17:21:57 2016 +0200

    Set `process.exitCode` based on the child’s exit code
    
    Set `process.exitCode` so that the the before-exit handler can
    inspect it and make decisions based on it. `process.exitCode`
    is the default code used for `process.exit()` since Node.js v0.11.8,
    so it seems reasonable and in line with the intentions of this
    module to set it accordingly.
---
 index.js      | 9 +++++++--
 test/basic.js | 5 +++++
 2 files changed, 12 insertions(+), 2 deletions(-)

diff --git a/index.js b/index.js
index 508b86e..21a395a 100644
--- a/index.js
+++ b/index.js
@@ -69,6 +69,9 @@ module.exports = function (program, args, cb) {
   })
 
   child.on('close', function (code, signal) {
+    // Allow the callback to inspect the child’s exit code and/or modify it.
+    process.exitCode = signal ? 128 + signal : code
+
     cb(function () {
       childExited = true
       if (signal) {
@@ -79,8 +82,10 @@ module.exports = function (program, args, cb) {
         // exit with the intended signal code.
         setTimeout(function () {}, 200)
         process.kill(process.pid, signal)
-      } else
-        process.exit(code)
+      } else {
+        // Equivalent to process.exit() on Node.js >= 0.11.8
+        process.exit(process.exitCode)
+      }
     })
   })
 
diff --git a/test/basic.js b/test/basic.js
index 150c3e7..7ceff2a 100644
--- a/test/basic.js
+++ b/test/basic.js
@@ -28,6 +28,11 @@ if (process.argv[2] === 'parent') {
   // to the foreground-child process; we should test it.
   if (process.argv[4] === 'beforeExitHandler') {
     cb = function (done) {
+      var expectedExitCode = +process.argv[3]
+      if (expectedExitCode !== process.exitCode) {
+        console.log('unexpected exit code', expectedExitCode, process.exitCode);
+      }
+
       console.log('beforeExitHandler')
       return done()
     }

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-foreground-child.git



More information about the Pkg-javascript-commits mailing list