All files / lib/internal/main repl.js

76.81% Statements 53/69
55.55% Branches 5/9
100% Functions 0/0
76.81% Lines 53/69

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 701x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x       1x 1x 1x             1x 1x 26x 26x 26x 26x 26x 26x     26x 22x           22x 26x 26x 26x 26x 26x 26x 1x 1x 1x 1x 1x 1x 1x  
'use strict';
 
// Create the REPL if `-i` or `--interactive` is passed, or if
// the main module is not specified and stdin is a TTY.
 
const {
  prepareMainThreadExecution,
  markBootstrapComplete
} = require('internal/process/pre_execution');
 
const esmLoader = require('internal/process/esm_loader');
const {
  evalScript
} = require('internal/process/execution');
 
const console = require('internal/console/global');
 
const { getOptionValue } = require('internal/options');
 
const { exitCodes: { kGenericUserError } } = internalBinding('errors');
 
prepareMainThreadExecution();
 
markBootstrapComplete();
 
if (process.env.NODE_REPL_EXTERNAL_MODULE) {
  require('internal/modules/cjs/loader')
    .Module
    ._load(process.env.NODE_REPL_EXTERNAL_MODULE, undefined, true);
} else {
  // --input-type flag not supported in REPL
  if (getOptionValue('--input-type')) {
    // If we can't write to stderr, we'd like to make this a noop,
    // so use console.error.
    console.error('Cannot specify --input-type for REPL');
    // TODO(joyeecheung): should be kInvalidCommandLineArgument.
    process.exit(kGenericUserError);
  }
 
  esmLoader.loadESM(() => {
    console.log(`Welcome to Node.js ${process.version}.\n` +
      'Type ".help" for more information.');
 
    const cliRepl = require('internal/repl');
    cliRepl.createInternalRepl(process.env, (err, repl) => {
      if (err) {
        throw err;
      }
      repl.on('exit', () => {
        if (repl._flushing) {
          repl.pause();
          return repl.once('flushHistory', () => {
            process.exit();
          });
        }
        process.exit();
      });
    });
 
    // If user passed '-e' or '--eval' along with `-i` or `--interactive`,
    // evaluate the code in the current context.
    if (getOptionValue('[has_eval_string]')) {
      evalScript('[eval]',
                 getOptionValue('--eval'),
                 getOptionValue('--inspect-brk'),
                 getOptionValue('--print'));
    }
  });
}