From cf75d76bb0b7016a1850132358fd6085164dc567 Mon Sep 17 00:00:00 2001 From: Simon Fridlund Date: Wed, 26 Jun 2019 14:44:51 +0200 Subject: [PATCH] Fix unlinking on exit (#22) As the same handler for unlinking is used for exit and SIGINT/SIGTERM we need to actually exit the process in case of SIGINT and SIGTERM after unlinking. Only synchronous function calls are supported in exit handlers so use execa.sync and check exit code of that to see if we should exit with an exit code or not, based on if unlink worked. --- commands/dev.js | 12 +++++++++--- lib/unlink-bin.js | 2 +- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/commands/dev.js b/commands/dev.js index 84e45cc..dcae573 100644 --- a/commands/dev.js +++ b/commands/dev.js @@ -19,9 +19,15 @@ module.exports = async () => { lint(projectPath, pkg); - ['exit', 'SIGINT', 'SIGTERM'].forEach(event => - process.on(event, () => unlinkBin(projectPath)) - ); + ['exit', 'SIGINT', 'SIGTERM'].forEach(event => { + process.on(event, () => { + const {code} = unlinkBin(projectPath); + + if (event === 'SIGINT' || event === 'SIGTERM') { + process.exit(code ? 1 : 0); + } + }); + }); console.log(wrapAnsi(stripIndent(` ${chalk.bold('Development mode')} diff --git a/lib/unlink-bin.js b/lib/unlink-bin.js index d956e6d..a83ec22 100644 --- a/lib/unlink-bin.js +++ b/lib/unlink-bin.js @@ -5,5 +5,5 @@ const execa = require('execa'); module.exports = projectPath => { const bin = hasYarn(projectPath) ? 'yarn' : 'npm'; - return execa(bin, ['unlink']); + return execa.sync(bin, ['unlink']); };