From 0648e64bff34a82187d566a67b30ade178afa258 Mon Sep 17 00:00:00 2001 From: Joyee Cheung Date: Sat, 29 Dec 2018 11:16:01 +0800 Subject: [PATCH] process: move --help and --bash-completeion handling to startExecution Because they are similar to `--prof-process` and are part of the execution instead of initialization. Also move the `getOptionValue` initialization to top scope since it's used everywhere and add comments about the flags. --- lib/internal/bootstrap/node.js | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/lib/internal/bootstrap/node.js b/lib/internal/bootstrap/node.js index 5bf2dc523f6fd1..0432561a3767ee 100644 --- a/lib/internal/bootstrap/node.js +++ b/lib/internal/bootstrap/node.js @@ -20,7 +20,8 @@ const { internalBinding, NativeModule } = loaderExports; const exceptionHandlerState = { captureFn: null }; -let getOptionValue; +const { getOptionValue } = NativeModule.require('internal/options'); + function startup() { setupTraceCategoryState(); @@ -149,18 +150,6 @@ function startup() { NativeModule.require('internal/inspector_async_hook').setup(); } - getOptionValue = NativeModule.require('internal/options').getOptionValue; - - if (getOptionValue('--help')) { - NativeModule.require('internal/print_help').print(process.stdout); - return; - } - - if (getOptionValue('--completion-bash')) { - NativeModule.require('internal/bash_completion').print(process.stdout); - return; - } - // If the process is spawned with env NODE_CHANNEL_FD, it's probably // spawned by our child_process module, then initialize IPC. // This attaches some internal event listeners and creates: @@ -317,6 +306,18 @@ function startExecution() { return; } + // node --help + if (getOptionValue('--help')) { + NativeModule.require('internal/print_help').print(process.stdout); + return; + } + + // e.g. node --completion-bash >> ~/.bashrc + if (getOptionValue('--completion-bash')) { + NativeModule.require('internal/bash_completion').print(process.stdout); + return; + } + // `node --prof-process` if (getOptionValue('--prof-process')) { NativeModule.require('internal/v8_prof_processor');