mirror of
https://github.com/nodejs/node.git
synced 2025-08-16 22:28:51 +02:00

PR-URL: https://github.com/nodejs/node/pull/56359 Reviewed-By: Jordan Harband <ljharb@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Pietro Marchini <pietro.marchini94@gmail.com>
57 lines
1.6 KiB
JavaScript
57 lines
1.6 KiB
JavaScript
'use strict';
|
|
|
|
// Stdin is not a TTY, we will read it and execute it.
|
|
|
|
const {
|
|
prepareMainThreadExecution,
|
|
markBootstrapComplete,
|
|
} = require('internal/process/pre_execution');
|
|
|
|
const { getOptionValue } = require('internal/options');
|
|
|
|
const {
|
|
evalModuleEntryPoint,
|
|
evalTypeScript,
|
|
parseAndEvalCommonjsTypeScript,
|
|
parseAndEvalModuleTypeScript,
|
|
evalScript,
|
|
readStdin,
|
|
} = require('internal/process/execution');
|
|
|
|
prepareMainThreadExecution();
|
|
markBootstrapComplete();
|
|
|
|
readStdin((code) => {
|
|
// This is necessary for fork() and CJS module compilation.
|
|
// TODO(joyeecheung): pass this with something really internal.
|
|
process._eval = code;
|
|
|
|
const print = getOptionValue('--print');
|
|
const shouldLoadESM = getOptionValue('--import').length > 0;
|
|
const inputType = getOptionValue('--input-type');
|
|
const tsEnabled = getOptionValue('--experimental-strip-types');
|
|
if (inputType === 'module') {
|
|
evalModuleEntryPoint(code, print);
|
|
} else if (inputType === 'module-typescript' && tsEnabled) {
|
|
parseAndEvalModuleTypeScript(code, print);
|
|
} else {
|
|
|
|
let evalFunction;
|
|
if (inputType === 'commonjs') {
|
|
evalFunction = evalScript;
|
|
} else if (inputType === 'commonjs-typescript' && tsEnabled) {
|
|
evalFunction = parseAndEvalCommonjsTypeScript;
|
|
} else if (tsEnabled) {
|
|
evalFunction = evalTypeScript;
|
|
} else {
|
|
// Default to commonjs.
|
|
evalFunction = evalScript;
|
|
}
|
|
|
|
evalFunction('[stdin]',
|
|
code,
|
|
getOptionValue('--inspect-brk'),
|
|
print,
|
|
shouldLoadESM);
|
|
}
|
|
});
|