forked from nodejs/node
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patheval_stdin.js
More file actions
57 lines (48 loc) · 1.55 KB
/
Copy patheval_stdin.js
File metadata and controls
57 lines (48 loc) · 1.55 KB
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
'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('--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);
}
});