* Determines the entry-point information from the argv and phase2 result. This * method will be invoked in two places: * * 1. In phase 3 to be able to find a project from the potential entry-point script. * 2. In phase 4 to determine the actual entry-point script. * * Note that we need to
(state: BootstrapState)
| 434 | * details can be found in here: https://github.com/TypeStrong/ts-node/issues/1812. |
| 435 | */ |
| 436 | function getEntryPointInfo(state: BootstrapState) { |
| 437 | const { code, interactive, restArgs } = state.parseArgvResult!; |
| 438 | const { cwd } = state.phase2Result!; |
| 439 | const { isCli } = state; |
| 440 | |
| 441 | // Figure out which we are executing: piped stdin, --eval, REPL, and/or entrypoint |
| 442 | // This is complicated because node's behavior is complicated |
| 443 | // `node -e code -i ./script.js` ignores -e |
| 444 | const executeEval = code != null && !(interactive && restArgs.length); |
| 445 | const executeEntrypoint = !executeEval && restArgs.length > 0; |
| 446 | const executeRepl = |
| 447 | !executeEntrypoint && |
| 448 | (interactive || (process.stdin.isTTY && !executeEval)); |
| 449 | const executeStdin = !executeEval && !executeRepl && !executeEntrypoint; |
| 450 | |
| 451 | /** |
| 452 | * Unresolved. May point to a symlink, not realpath. May be missing file extension |
| 453 | * NOTE: resolution relative to cwd option (not `process.cwd()`) is legacy backwards-compat; should be changed in next major: https://github.com/TypeStrong/ts-node/issues/1834 |
| 454 | */ |
| 455 | const entryPointPath = executeEntrypoint |
| 456 | ? isCli |
| 457 | ? resolve(cwd, restArgs[0]) |
| 458 | : resolve(restArgs[0]) |
| 459 | : undefined; |
| 460 | |
| 461 | return { |
| 462 | executeEval, |
| 463 | executeEntrypoint, |
| 464 | executeRepl, |
| 465 | executeStdin, |
| 466 | entryPointPath, |
| 467 | }; |
| 468 | } |
| 469 | |
| 470 | function phase4(payload: BootstrapState) { |
| 471 | const { isInChildProcess, tsNodeScript } = payload; |