1'use strict';
2
3// Stdin is not a TTY, we will read it and execute it.
4
5const {
6  prepareMainThreadExecution,
7  markBootstrapComplete,
8} = require('internal/process/pre_execution');
9
10const { getOptionValue } = require('internal/options');
11
12const {
13  evalModule,
14  evalScript,
15  readStdin,
16} = require('internal/process/execution');
17
18prepareMainThreadExecution();
19markBootstrapComplete();
20
21readStdin((code) => {
22  // This is necessary for fork() and CJS module compilation.
23  // TODO(joyeecheung): pass this with something really internal.
24  process._eval = code;
25
26  const print = getOptionValue('--print');
27  const loadESM = getOptionValue('--import').length > 0;
28  if (getOptionValue('--input-type') === 'module' ||
29    (getOptionValue('--experimental-default-type') === 'module' && getOptionValue('--input-type') !== 'commonjs')) {
30    evalModule(code, print);
31  } else {
32    evalScript('[stdin]',
33               code,
34               getOptionValue('--inspect-brk'),
35               print,
36               loadESM);
37  }
38});
39