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CAAC,KAAK,CAAC,UAAA,CAAC,IAAI,OAAA,cAAc,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,EAAnC,CAAmC,CAAC,CAAA;AAC1E,CAAC","sourcesContent":["#!/usr/bin/env node\n\nimport { join, resolve } from 'path'\nimport { start, Recoverable } from 'repl'\nimport { inspect } from 'util'\nimport arrify = require('arrify')\nimport Module = require('module')\nimport minimist = require('minimist')\nimport chalk from 'chalk'\nimport { diffLines } from 'diff'\nimport { Script } from 'vm'\nimport { readFileSync, statSync } from 'fs'\nimport { register, VERSION, DEFAULTS, TSError, parse, printError } from './index'\n\ninterface Argv {\n // Node.js-like options.\n eval?: string\n print?: string\n require?: string | string[]\n // CLI options.\n help?: boolean\n version?: boolean\n // Register options.\n typeCheck?: boolean\n transpileOnly?: boolean\n cache?: boolean\n cacheDirectory?: string\n compiler?: string\n ignore?: string | string[]\n project?: string\n skipIgnore?: boolean\n skipProject?: boolean\n ignoreDiagnostics?: string | string[]\n compilerOptions?: string\n _: string[]\n}\n\nconst argv = minimist<Argv>(process.argv.slice(2), {\n stopEarly: true,\n string: ['eval', 'print', 'compiler', 'project', 'ignoreDiagnostics', 'require', 'cacheDirectory', 'ignore'],\n boolean: ['help', 'transpileOnly', 'typeCheck', 'version', 'cache', 'skipProject', 'skipIgnore'],\n alias: {\n eval: ['e'],\n print: ['p'],\n require: ['r'],\n help: ['h'],\n version: ['v'],\n typeCheck: ['type-check'],\n transpileOnly: ['T', 'transpile-only'],\n cacheDirectory: ['cache-directory'],\n ignore: ['I'],\n project: ['P'],\n skipIgnore: ['skip-ignore'],\n skipProject: ['skip-project'],\n compiler: ['C'],\n ignoreDiagnostics: ['D', 'ignore-diagnostics'],\n compilerOptions: ['O', 'compiler-options']\n },\n default: {\n cache: DEFAULTS.cache,\n typeCheck: DEFAULTS.typeCheck,\n transpileOnly: DEFAULTS.transpileOnly,\n skipIgnore: DEFAULTS.skipIgnore,\n skipProject: DEFAULTS.skipProject\n }\n})\n\nif (argv.help) {\n console.log(`\nUsage: ts-node [options] [ -e script | script.ts ] [arguments]\n\nOptions:\n\n -e, --eval [code] Evaluate code\n -p, --print [code] Evaluate code and print result\n -r, --require [path] Require a node module before execution\n\n -h, --help Print CLI usage\n -v, --version Print module version information\n\n -T, --transpile-only Use TypeScript's faster \\`transpileModule\\`\n --cache-directory Configure the output file cache directory\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, --ignoreDiagnostics [code] Ignore TypeScript warnings by diagnostic code\n -O, --compilerOptions [opts] JSON object to merge with compiler options\n\n --no-cache Disable the local TypeScript Node cache\n --skip-project Skip reading \\`tsconfig.json\\`\n --skip-ignore Skip \\`--ignore\\` checks\n`)\n\n process.exit(0)\n}\n\nconst cwd = process.cwd()\nconst code = argv.eval === undefined ? argv.print : argv.eval\nconst isEval = typeof argv.eval === 'string' || !!argv.print // Minimist struggles with empty strings.\nconst isPrinted = argv.print !== undefined\n\n// Register the TypeScript compiler instance.\nconst service = register({\n typeCheck: argv.typeCheck,\n transpileOnly: argv.transpileOnly,\n cache: argv.cache,\n cacheDirectory: argv.cacheDirectory,\n ignore: argv.ignore,\n project: argv.project,\n skipIgnore: argv.skipIgnore,\n skipProject: argv.skipProject,\n compiler: argv.compiler,\n ignoreDiagnostics: argv.ignoreDiagnostics,\n compilerOptions: parse(argv.compilerOptions),\n readFile: isEval ? readFileEval : undefined,\n fileExists: isEval ? fileExistsEval : undefined\n})\n\n// Output project information.\nif (argv.version) {\n console.log(`ts-node v${VERSION}`)\n console.log(`node ${process.version}`)\n console.log(`typescript v${service.ts.version}`)\n console.log(`cache ${JSON.stringify(service.cachedir)}`)\n process.exit(0)\n}\n\n// Require specified modules before start-up.\n(Module as any)._preloadModules(arrify(argv.require))\n\n/**\n * Eval helpers.\n */\nconst EVAL_FILENAME = `[eval].ts`\nconst EVAL_PATH = join(cwd, EVAL_FILENAME)\nconst EVAL_INSTANCE = { input: '', output: '', version: 0, lines: 0 }\n\n// Execute the main contents (either eval, script or piped).\nif (isEval) {\n evalAndExit(code as string, isPrinted)\n} else {\n if (argv._.length) {\n process.argv = ['node'].concat(resolve(cwd, argv._[0])).concat(argv._.slice(1))\n process.execArgv.unshift(__filename)\n Module.runMain()\n } else {\n // Piping of execution _only_ occurs when no other script is specified.\n if ((process.stdin as any).isTTY) {\n startRepl()\n } else {\n let code = ''\n process.stdin.on('data', (chunk: Buffer) => code += chunk)\n process.stdin.on('end', () => evalAndExit(code, isPrinted))\n }\n }\n}\n\n/**\n * Evaluate a script.\n */\nfunction evalAndExit (code: string, isPrinted: boolean) {\n const module = new Module(EVAL_FILENAME)\n module.filename = EVAL_FILENAME\n module.paths = (Module as any)._nodeModulePaths(cwd)\n\n ;(global as any).__filename = EVAL_FILENAME\n ;(global as any).__dirname = cwd\n ;(global as any).exports = module.exports\n ;(global as any).module = module\n ;(global as any).require = module.require.bind(module)\n\n let result: any\n\n try {\n result = _eval(code, global)\n } catch (error) {\n if (error instanceof TSError) {\n console.error(printError(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/**\n * Evaluate the code snippet.\n */\nfunction _eval (input: string, context: any) {\n const lines = EVAL_INSTANCE.lines\n const isCompletion = !/\\n$/.test(input)\n const undo = appendEval(input)\n let output: string\n\n try {\n output = service.compile(EVAL_INSTANCE.input, EVAL_PATH, -lines)\n } catch (err) {\n undo()\n throw err\n }\n\n // Use `diff` to check for new JavaScript to execute.\n const changes = diffLines(EVAL_INSTANCE.output, output)\n\n if (isCompletion) {\n undo()\n } else {\n EVAL_INSTANCE.output = output\n }\n\n return changes.reduce((result, change) => {\n return change.added ? exec(change.value, EVAL_FILENAME, context) : result\n }, undefined)\n}\n\n/**\n * Execute some code.\n */\nfunction exec (code: string, filename: string, context: any) {\n const script = new Script(code, { filename: filename })\n\n return script.runInNewContext(context)\n}\n\n/**\n * Start a CLI REPL.\n */\nfunction startRepl () {\n const repl = start({\n prompt: '> ',\n input: process.stdin,\n output: process.stdout,\n eval: replEval,\n useGlobal: false\n })\n\n // Bookmark the point where we should reset the REPL state.\n const resetEval = appendEval('')\n\n function reset () {\n resetEval()\n\n // Hard fix for TypeScript forcing `Object.defineProperty(exports, ...)`.\n exec('exports = module.exports', EVAL_FILENAME, (repl as any).context)\n }\n\n reset()\n repl.on('reset', reset)\n\n repl.defineCommand('type', {\n help: 'Check the type of a TypeScript identifier',\n action: function (identifier: string) {\n if (!identifier) {\n repl.displayPrompt()\n return\n }\n\n const undo = appendEval(identifier)\n const { name, comment } = service.getTypeInfo(EVAL_INSTANCE.input, EVAL_PATH, EVAL_INSTANCE.input.length)\n\n undo()\n\n repl.outputStream.write(`${chalk.bold(name)}\\n${comment ? `${comment}\\n` : ''}`)\n repl.displayPrompt()\n }\n })\n}\n\n/**\n * Eval code from the REPL.\n */\nfunction replEval (code: string, context: any, _filename: string, callback: (err?: Error, result?: any) => any) {\n let err: any\n let result: any\n\n // TODO: Figure out how to handle completion here.\n if (code === '.scope') {\n callback()\n return\n }\n\n try {\n result = _eval(code, context)\n } catch (error) {\n if (error instanceof TSError) {\n // Support recoverable compilations using >= node 6.\n if (Recoverable && isRecoverable(error)) {\n err = new Recoverable(error)\n } else {\n err = printError(error)\n }\n } else {\n err = error\n }\n }\n\n callback(err, result)\n}\n\n/**\n * Append to the eval instance and return an undo function.\n */\nfunction appendEval (input: string) {\n const undoInput = EVAL_INSTANCE.input\n const undoVersion = EVAL_INSTANCE.version\n const undoOutput = EVAL_INSTANCE.output\n const undoLines = EVAL_INSTANCE.lines\n\n // Handle ASI issues with TypeScript re-evaluation.\n if (undoInput.charAt(undoInput.length - 1) === '\\n' && /^\\s*[\\[\\(\\`]/.test(input) && !/;\\s*$/.test(undoInput)) {\n EVAL_INSTANCE.input = `${EVAL_INSTANCE.input.slice(0, -1)};\\n`\n }\n\n EVAL_INSTANCE.input += input\n EVAL_INSTANCE.lines += lineCount(input)\n EVAL_INSTANCE.version++\n\n return function () {\n EVAL_INSTANCE.input = undoInput\n EVAL_INSTANCE.output = undoOutput\n EVAL_INSTANCE.version = undoVersion\n EVAL_INSTANCE.lines = undoLines\n }\n}\n\n/**\n * Count the number of lines.\n */\nfunction lineCount (value: string) {\n let count = 0\n\n for (const char of value) {\n if (char === '\\n') {\n count++\n }\n }\n\n return count\n}\n\n/**\n * Get the file text, checking for eval first.\n */\nfunction readFileEval (path: string) {\n if (path === EVAL_PATH) return EVAL_INSTANCE.input\n\n try {\n return readFileSync(path, 'utf8')\n } catch (err) {/* Ignore. */}\n}\n\n/**\n * Get whether the file exists.\n */\nfunction fileExistsEval (path: string) {\n if (path === EVAL_PATH) return true\n\n try {\n const stats = statSync(path)\n return stats.isFile() || stats.isFIFO()\n } catch (err) {\n return false\n }\n}\n\nconst RECOVERY_CODES: number[] = [\n 1003, // \"Identifier expected.\"\n 1005, // \"')' expected.\"\n 1109, // \"Expression expected.\"\n 1126, // \"Unexpected end of text.\"\n 1160, // \"Unterminated template literal.\"\n 1161 // \"Unterminated regular expression literal.\"\n]\n\n/**\n * Check if a function can recover gracefully.\n */\nfunction isRecoverable (error: TSError) {\n return error.diagnostics.every(x => RECOVERY_CODES.indexOf(x.code) > -1)\n}\n"]}
\No newline at end of file