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cesContent":["#!/usr/bin/env node\n\nimport { join, resolve, dirname } from 'path'\nimport { inspect } from 'util'\nimport Module = require('module')\nimport arg = require('arg')\nimport {\n EVAL_FILENAME,\n EvalState,\n createRepl,\n ReplService\n } from './repl'\nimport { VERSION, TSError, parse, register } from './index'\n\n/**\n * Main `bin` functionality.\n */\nexport function main (argv: string[] = process.argv.slice(2), entrypointArgs: Record = {}) {\n const args = {\n ...entrypointArgs,\n ...arg({\n // Node.js-like options.\n '--eval': String,\n '--interactive': Boolean,\n '--print': Boolean,\n '--require': [String],\n\n // CLI options.\n '--help': Boolean,\n '--script-mode': Boolean,\n '--version': arg.COUNT,\n\n // Project options.\n '--dir': String,\n '--files': Boolean,\n '--compiler': String,\n '--compiler-options': parse,\n '--project': String,\n '--ignore-diagnostics': [String],\n '--ignore': [String],\n '--transpile-only': Boolean,\n '--type-check': Boolean,\n '--compiler-host': Boolean,\n '--pretty': Boolean,\n '--skip-project': Boolean,\n '--skip-ignore': Boolean,\n '--prefer-ts-exts': Boolean,\n '--log-error': Boolean,\n '--emit': Boolean,\n\n // Aliases.\n '-e': '--eval',\n '-i': '--interactive',\n '-p': '--print',\n '-r': '--require',\n '-h': '--help',\n '-s': '--script-mode',\n '-v': '--version',\n '-T': '--transpile-only',\n '-H': '--compiler-host',\n '-I': '--ignore',\n '-P': '--project',\n '-C': '--compiler',\n '-D': '--ignore-diagnostics',\n '-O': '--compiler-options'\n }, {\n argv,\n stopAtPositional: true\n })\n }\n\n // Only setting defaults for CLI-specific flags\n // Anything passed to `register()` can be `undefined`; `create()` will apply\n // defaults.\n const {\n '--dir': dir,\n '--help': help = false,\n '--script-mode': scriptMode = false,\n '--version': version = 0,\n '--require': argsRequire = [],\n '--eval': code = undefined,\n '--print': print = false,\n '--interactive': interactive = false,\n '--files': files,\n '--compiler': compiler,\n '--compiler-options': compilerOptions,\n '--project': project,\n '--ignore-diagnostics': ignoreDiagnostics,\n '--ignore': ignore,\n '--transpile-only': transpileOnly,\n '--type-check': typeCheck,\n '--compiler-host': compilerHost,\n '--pretty': pretty,\n '--skip-project': skipProject,\n '--skip-ignore': skipIgnore,\n '--prefer-ts-exts': preferTsExts,\n '--log-error': logError,\n '--emit': emit\n } = args\n\n if (help) {\n console.log(`\n Usage: ts-node [options] [ -e script | script.ts ] [arguments]\n\n Options:\n\n -e, --eval [code] Evaluate code\n -p, --print Print result of \\`--eval\\`\n -r, --require [path] Require a node module before execution\n -i, --interactive Opens the REPL even if stdin does not appear to be a terminal\n\n -h, --help Print CLI usage\n -v, --version Print module version information\n -s, --script-mode Use cwd from instead of current directory\n\n -T, --transpile-only Use TypeScript's faster \\`transpileModule\\`\n -H, --compiler-host Use TypeScript's compiler host API\n -I, --ignore [pattern] Override the path patterns to skip compilation\n -P, --project [path] Path to TypeScript JSON project file\n -C, --compiler [name] Specify a custom TypeScript compiler\n -D, --ignore-diagnostics [code] Ignore TypeScript warnings by diagnostic code\n -O, --compiler-options [opts] JSON object to merge with compiler options\n\n --dir Specify working directory for config resolution\n --scope Scope compiler to files within \\`cwd\\` only\n --files Load \\`files\\`, \\`include\\` and \\`exclude\\` from \\`tsconfig.json\\` on startup\n --pretty Use pretty diagnostic formatter (usually enabled by default)\n --skip-project Skip reading \\`tsconfig.json\\`\n --skip-ignore Skip \\`--ignore\\` checks\n --prefer-ts-exts Prefer importing TypeScript files over JavaScript files\n --log-error Logs TypeScript errors to stderr instead of throwing exceptions\n `)\n\n process.exit(0)\n }\n\n // Output project information.\n if (version === 1) {\n console.log(`v${VERSION}`)\n process.exit(0)\n }\n\n const cwd = dir || process.cwd()\n /** Unresolved. May point to a symlink, not realpath. May be missing file extension */\n const scriptPath = args._.length ? resolve(cwd, args._[0]) : undefined\n const state = new EvalState(scriptPath || join(cwd, EVAL_FILENAME))\n const replService = createRepl({ state })\n const { evalAwarePartialHost } = replService\n\n // Register the TypeScript compiler instance.\n const service = register({\n dir: getCwd(dir, scriptMode, scriptPath),\n emit,\n files,\n pretty,\n transpileOnly,\n typeCheck,\n compilerHost,\n ignore,\n preferTsExts,\n logError,\n project,\n skipProject,\n skipIgnore,\n compiler,\n ignoreDiagnostics,\n compilerOptions,\n require: argsRequire,\n readFile: code !== undefined ? evalAwarePartialHost.readFile : undefined,\n fileExists: code !== undefined ? evalAwarePartialHost.fileExists : undefined\n })\n\n // Bind REPL service to ts-node compiler service (chicken-and-egg problem)\n replService.setService(service)\n\n // Output project information.\n if (version >= 2) {\n console.log(`ts-node v${VERSION}`)\n console.log(`node ${process.version}`)\n console.log(`compiler v${service.ts.version}`)\n process.exit(0)\n }\n\n // Create a local module instance based on `cwd`.\n const module = new Module(state.path)\n module.filename = state.path\n module.paths = (Module as any)._nodeModulePaths(cwd)\n\n // Prepend `ts-node` arguments to CLI for child processes.\n process.execArgv.unshift(__filename, ...process.argv.slice(2, process.argv.length - args._.length))\n process.argv = [process.argv[1]].concat(scriptPath || []).concat(args._.slice(1))\n\n // Execute the main contents (either eval, script or piped).\n if (code !== undefined && !interactive) {\n evalAndExit(replService, module, code, print)\n } else {\n if (args._.length) {\n Module.runMain()\n } else {\n // Piping of execution _only_ occurs when no other script is specified.\n // --interactive flag forces REPL\n if (interactive || process.stdin.isTTY) {\n replService.start(code)\n } else {\n let buffer = code || ''\n process.stdin.on('data', (chunk: Buffer) => buffer += chunk)\n process.stdin.on('end', () => evalAndExit(replService, module, buffer, print))\n }\n }\n }\n}\n\n/**\n * Get project path from args.\n */\nfunction getCwd (dir?: string, scriptMode?: boolean, scriptPath?: string) {\n // Validate `--script-mode` usage is correct.\n if (scriptMode) {\n if (!scriptPath) {\n throw new TypeError('Script mode must be used with a script name, e.g. `ts-node -s `')\n }\n\n if (dir) {\n throw new TypeError('Script mode cannot be combined with `--dir`')\n }\n\n // Use node's own resolution behavior to ensure we follow symlinks.\n // scriptPath may omit file extension or point to a directory with or without package.json.\n // This happens before we are registered, so we tell node's resolver to consider ts, tsx, and jsx files.\n // In extremely rare cases, is is technically possible to resolve the wrong directory,\n // because we do not yet know preferTsExts, jsx, nor allowJs.\n // See also, justification why this will not happen in real-world situations:\n // https://github.com/TypeStrong/ts-node/pull/1009#issuecomment-613017081\n const exts = ['.js', '.jsx', '.ts', '.tsx']\n const extsTemporarilyInstalled: string[] = []\n for (const ext of exts) {\n if (!hasOwnProperty(require.extensions, ext)) { // tslint:disable-line\n extsTemporarilyInstalled.push(ext)\n require.extensions[ext] = function() {} // tslint:disable-line\n }\n }\n try {\n return dirname(require.resolve(scriptPath))\n } finally {\n for (const ext of extsTemporarilyInstalled) {\n delete require.extensions[ext] // tslint:disable-line\n }\n }\n }\n\n return dir\n}\n\n/**\n * Evaluate a script.\n */\nfunction evalAndExit (replService: ReplService, module: Module, code: string, isPrinted: boolean) {\n let result: any\n\n ;(global as any).__filename = module.filename\n ;(global as any).__dirname = dirname(module.filename)\n ;(global as any).exports = module.exports\n ;(global as any).module = module\n ;(global as any).require = module.require.bind(module)\n\n try {\n result = replService.evalCode(code)\n } catch (error) {\n if (error instanceof TSError) {\n console.error(error)\n process.exit(1)\n }\n\n throw error\n }\n\n if (isPrinted) {\n console.log(typeof result === 'string' ? result : inspect(result))\n }\n}\n\n/** Safe `hasOwnProperty` */\nfunction hasOwnProperty (object: any, property: string): boolean {\n return Object.prototype.hasOwnProperty.call(object, property)\n}\n\nif (require.main === module) {\n main()\n}\n"]}