mirror of
https://github.com/cachix/install-nix-action.git
synced 2024-11-25 09:58:03 +00:00
1 line
No EOL
19 KiB
Text
1 line
No EOL
19 KiB
Text
{"version":3,"file":"bin.js","sourceRoot":"","sources":["../src/bin.ts"],"names":[],"mappings":";;;AAEA,+BAAoC;AACpC,+BAAyC;AACzC,+BAA8B;AAC9B,iCAAiC;AACjC,2BAA2B;AAC3B,+BAAgC;AAChC,2BAA2B;AAC3B,2BAA2C;AAC3C,mCAAqE;AAErE,MAAM,IAAI,GAAG,GAAG,CAAC;IACf,wBAAwB;IACxB,QAAQ,EAAE,MAAM;IAChB,SAAS,EAAE,OAAO;IAClB,WAAW,EAAE,CAAC,MAAM,CAAC;IAErB,eAAe;IACf,SAAS,EAAE,OAAO;IAClB,QAAQ,EAAE,OAAO;IACjB,WAAW,EAAE,GAAG,CAAC,KAAK;IAEtB,mBAAmB;IACnB,YAAY,EAAE,MAAM;IACpB,oBAAoB,EAAE,aAAK;IAC3B,WAAW,EAAE,MAAM;IACnB,sBAAsB,EAAE,CAAC,MAAM,CAAC;IAChC,UAAU,EAAE,CAAC,MAAM,CAAC;IACpB,kBAAkB,EAAE,OAAO;IAC3B,cAAc,EAAE,OAAO;IACvB,UAAU,EAAE,OAAO;IACnB,gBAAgB,EAAE,OAAO;IACzB,eAAe,EAAE,OAAO;IACxB,kBAAkB,EAAE,OAAO;IAC3B,aAAa,EAAE,OAAO;IAEtB,WAAW;IACX,IAAI,EAAE,QAAQ;IACd,IAAI,EAAE,SAAS;IACf,IAAI,EAAE,WAAW;IACjB,IAAI,EAAE,QAAQ;IACd,IAAI,EAAE,WAAW;IACjB,IAAI,EAAE,kBAAkB;IACxB,IAAI,EAAE,UAAU;IAChB,IAAI,EAAE,WAAW;IACjB,IAAI,EAAE,YAAY;IAClB,IAAI,EAAE,sBAAsB;IAC5B,IAAI,EAAE,oBAAoB;CAC3B,EAAE;IACD,gBAAgB,EAAE,IAAI;CACvB,CAAC,CAAA;AAEF,MAAM,EACJ,QAAQ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AAY,CAAC,IAAI,EAAE,MAAM,CAAC,CAAA;KAClC;IAAC,OAAO,GAAG,EAAE,EAAC,aAAa,EAAC;AAC/B,CAAC;AAED;;GAEG;AACH,SAAS,cAAc,CAAE,IAAY;IACnC,IAAI,IAAI,KAAK,SAAS;QAAE,OAAO,IAAI,CAAA;IAEnC,IAAI;QACF,MAAM,KAAK,GAAG,aAAQ,CAAC,IAAI,CAAC,CAAA;QAC5B,OAAO,KAAK,CAAC,MAAM,EAAE,IAAI,KAAK,CAAC,MAAM,EAAE,CAAA;KACxC;IAAC,OAAO,GAAG,EAAE;QACZ,OAAO,KAAK,CAAA;KACb;AACH,CAAC;AAED,MAAM,cAAc,GAAgB,IAAI,GAAG,CAAC;IAC1C,IAAI;IACJ,IAAI;IACJ,IAAI;IACJ,IAAI;IACJ,IAAI;IACJ,IAAI;IACJ,IAAI,CAAC,oFAAoF;CAC1F,CAAC,CAAA;AAEF;;GAEG;AACH,SAAS,aAAa,CAAE,KAAc;IACpC,OAAO,KAAK,CAAC,eAAe,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,cAAc,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAA;AACtE,CAAC","sourcesContent":["#!/usr/bin/env node\n\nimport { join, resolve } from 'path'\nimport { start, Recoverable } from 'repl'\nimport { inspect } from 'util'\nimport Module = require('module')\nimport arg = require('arg')\nimport { diffLines } from 'diff'\nimport { Script } from 'vm'\nimport { readFileSync, statSync } from 'fs'\nimport { register, VERSION, DEFAULTS, TSError, parse } from './index'\n\nconst args = arg({\n // Node.js-like options.\n '--eval': String,\n '--print': Boolean,\n '--require': [String],\n\n // CLI options.\n '--files': Boolean,\n '--help': Boolean,\n '--version': arg.COUNT,\n\n // Project options.\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 '--pretty': Boolean,\n '--skip-project': Boolean,\n '--skip-ignore': Boolean,\n '--prefer-ts-exts': Boolean,\n '--log-error': Boolean,\n\n // Aliases.\n '-e': '--eval',\n '-p': '--print',\n '-r': '--require',\n '-h': '--help',\n '-v': '--version',\n '-T': '--transpile-only',\n '-I': '--ignore',\n '-P': '--project',\n '-C': '--compiler',\n '-D': '--ignore-diagnostics',\n '-O': '--compiler-options'\n}, {\n stopAtPositional: true\n})\n\nconst {\n '--help': help = false,\n '--version': version = 0,\n '--files': files = DEFAULTS.files,\n '--compiler': compiler = DEFAULTS.compiler,\n '--compiler-options': compilerOptions = DEFAULTS.compilerOptions,\n '--project': project = DEFAULTS.project,\n '--ignore-diagnostics': ignoreDiagnostics = DEFAULTS.ignoreDiagnostics,\n '--ignore': ignore = DEFAULTS.ignore,\n '--transpile-only': transpileOnly = DEFAULTS.transpileOnly,\n '--type-check': typeCheck = DEFAULTS.typeCheck,\n '--pretty': pretty = DEFAULTS.pretty,\n '--skip-project': skipProject = DEFAULTS.skipProject,\n '--skip-ignore': skipIgnore = DEFAULTS.skipIgnore,\n '--prefer-ts-exts': preferTsExts = DEFAULTS.preferTsExts,\n '--log-error': logError = DEFAULTS.logError\n} = args\n\nif (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 Print result of \\`--eval\\`\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 -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 --files Load files from \\`tsconfig.json\\` on startup\n --pretty Use pretty diagnostic formatter\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`)\n\n process.exit(0)\n}\n\n// Output project information.\nif (version === 1) {\n console.log(`v${VERSION}`)\n process.exit(0)\n}\n\nconst cwd = process.cwd()\nconst code = args['--eval']\nconst isPrinted = args['--print'] !== undefined\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// Register the TypeScript compiler instance.\nconst service = register({\n files,\n pretty,\n typeCheck,\n transpileOnly,\n ignore,\n project,\n skipIgnore,\n preferTsExts,\n logError,\n skipProject,\n compiler,\n ignoreDiagnostics,\n compilerOptions,\n readFile: code ? readFileEval : undefined,\n fileExists: code ? fileExistsEval : undefined\n})\n\n// Output project information.\nif (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// Require specified modules before start-up.\nif (args['--require']) (Module as any)._preloadModules(args['--require'])\n\n// Prepend `ts-node` arguments to CLI for child processes.\nprocess.execArgv.unshift(__filename, ...process.argv.slice(2, process.argv.length - args._.length))\nprocess.argv = [process.argv[1]].concat(args._.length ? resolve(cwd, args._[0]) : []).concat(args._.slice(1))\n\n// Execute the main contents (either eval, script or piped).\nif (code) {\n evalAndExit(code, isPrinted)\n} else {\n if (args._.length) {\n Module.runMain()\n } else {\n // Piping of execution _only_ occurs when no other script is specified.\n if (process.stdin.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)\n } catch (error) {\n if (error instanceof TSError) {\n console.error(error.diagnosticText)\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) {\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) : result\n }, undefined)\n}\n\n/**\n * Execute some code.\n */\nfunction exec (code: string, filename: string) {\n const script = new Script(code, { filename: filename })\n\n return script.runInThisContext()\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 terminal: process.stdout.isTTY,\n eval: replEval,\n useGlobal: true\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)\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(`${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 | null, result?: any) => any) {\n let err: Error | null = null\n let result: any\n\n // TODO: Figure out how to handle completion here.\n if (code === '.scope') {\n callback(err)\n return\n }\n\n try {\n result = _eval(code)\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 console.error(error.diagnosticText)\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: Set<number> = new Set([\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 2355 // \"A function whose declared type is neither 'void' nor 'any' must return a value.\"\n])\n\n/**\n * Check if a function can recover gracefully.\n */\nfunction isRecoverable (error: TSError) {\n return error.diagnosticCodes.every(code => RECOVERY_CODES.has(code))\n}\n"]} |