Skip to content

Commit f2f7364

Browse files
JLHwungNoahDragon
authored andcommitted
fix(process): gracefully exit process (#26)
As is noted on https://nodejs.org/api/process.html#process_process_exit_code > In most situations, it is not actually necessary to call process.exit() explicitly. It is problematic to print stdout and instruct process.exit() call. Now we set process.exitCode to allow the process exit naturally
1 parent 89145a5 commit f2f7364

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

lib/hexo.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ var goodbye = require('./goodbye');
1010
var minimist = require('minimist');
1111
var camelCaseKeys = require('hexo-util/lib/camel_case_keys');
1212

13+
class HexoNotFoundError extends Error {}
14+
1315
function entry(cwd, args) {
1416
cwd = cwd || process.cwd();
1517
args = camelCaseKeys(args || minimist(process.argv.slice(2)));
@@ -21,11 +23,11 @@ function entry(cwd, args) {
2123
process.title = 'hexo';
2224

2325
function handleError(err) {
24-
if (err) {
26+
if (err && !(err instanceof HexoNotFoundError)) {
2527
log.fatal(err);
2628
}
2729

28-
process.exit(2);
30+
process.exitCode = 2;
2931
}
3032

3133
return findPkg(cwd, args).then(function(path) {
@@ -36,7 +38,7 @@ function entry(cwd, args) {
3638
return loadModule(path, args).catch(function() {
3739
log.error('Local hexo not found in %s', chalk.magenta(tildify(path)));
3840
log.error('Try running: \'npm install hexo --save\'');
39-
process.exit(2);
41+
throw new HexoNotFoundError;
4042
});
4143
}).then(function(mod) {
4244
if (mod) hexo = mod;

0 commit comments

Comments
 (0)