From aac63036968f9bf0e3dbb7928e70f9fca1b18481 Mon Sep 17 00:00:00 2001 From: Christopher Monsanto Date: Sat, 13 Dec 2014 01:41:57 -0500 Subject: [PATCH] run _6to5-node using execvp() if available --- bin/6to5-node | 27 +++++++++++++++++---------- doc/caveats.md | 7 +++++++ 2 files changed, 24 insertions(+), 10 deletions(-) diff --git a/bin/6to5-node b/bin/6to5-node index 2387551176..85311725a8 100755 --- a/bin/6to5-node +++ b/bin/6to5-node @@ -5,7 +5,6 @@ * when found, before invoking the "real" _6to5-node(1) executable. */ -var spawn = require("child_process").spawn; var args = ["--harmony", __dirname + "/_6to5-node"]; process.argv.slice(2).forEach(function(arg){ @@ -49,13 +48,21 @@ process.argv.slice(2).forEach(function(arg){ } }); -var proc = spawn(process.argv[0], args, { stdio: "inherit" }); -proc.on("exit", function (code, signal) { - process.on("exit", function () { - if (signal) { - process.kill(process.pid, signal); - } else { - process.exit(code); - } +try { + var kexec = require("kexec"); + kexec(process.argv[0], args); +} catch(e) { + if (e.code !== "MODULE_NOT_FOUND") throw err; + + var child_process = require("child_process"); + var proc = child_process.spawn(process.argv[0], args, { stdio: "inherit" }); + proc.on("exit", function (code, signal) { + process.on("exit", function () { + if (signal) { + process.kill(process.pid, signal); + } else { + process.exit(code); + } + }) }); -}); +} diff --git a/doc/caveats.md b/doc/caveats.md index 32049b2f98..269d114207 100644 --- a/doc/caveats.md +++ b/doc/caveats.md @@ -39,3 +39,10 @@ class Bar extends Foo { } } ``` + +## 6to5-node + +It is necessary to manually install `kexec` package on Unix-like OSes for +`6to5-node` to correctly handle signals. + +**It is not recommended to use `6to5-node` with a process manager (`supervisord`, `upstart`, `systemd`, ...) without first installing `kexec`!**