Skip to content

Commit

Permalink
Fix unlinking on exit (#22)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
zimme authored and Vadim Demedes committed Jun 26, 2019
1 parent 9d35a06 commit cf75d76
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
12 changes: 9 additions & 3 deletions commands/dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')}
Expand Down
2 changes: 1 addition & 1 deletion lib/unlink-bin.js
Original file line number Diff line number Diff line change
Expand Up @@ -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']);
};

0 comments on commit cf75d76

Please sign in to comment.