UNPKG

mono-runner

Version:

A script runner for mono repos that just works. Use Mono to run separate compilers and dev servers for your packages at once, build only dependent packages or format everything at once.

100 lines (94 loc) 4.8 kB
#!/usr/bin/env node import * as __WEBPACK_EXTERNAL_MODULE_typescript__ from "typescript"; /******/ // The require scope /******/ var __nccwpck_require__ = {}; /******/ /************************************************************************/ /******/ /* webpack/runtime/define property getters */ /******/ (() => { /******/ // define getter functions for harmony exports /******/ __nccwpck_require__.d = (exports, definition) => { /******/ for(var key in definition) { /******/ if(__nccwpck_require__.o(definition, key) && !__nccwpck_require__.o(exports, key)) { /******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] }); /******/ } /******/ } /******/ }; /******/ })(); /******/ /******/ /* webpack/runtime/hasOwnProperty shorthand */ /******/ (() => { /******/ __nccwpck_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop)) /******/ })(); /******/ /******/ /* webpack/runtime/compat */ /******/ /******/ if (typeof __nccwpck_require__ !== 'undefined') __nccwpck_require__.ab = new URL('.', import.meta.url).pathname.slice(import.meta.url.match(/^file:\/\/\/\w:/) ? 1 : 0, -1) + "/"; /******/ /************************************************************************/ var __webpack_exports__ = {}; ;// CONCATENATED MODULE: external "typescript" var x = (y) => { var x = {}; __nccwpck_require__.d(x, y); return x } var y = (x) => (() => (x)) const external_typescript_namespaceObject = x({ ["default"]: () => (__WEBPACK_EXTERNAL_MODULE_typescript__["default"]) }); ;// CONCATENATED MODULE: ./lib/plugins/typescript.ts const formatHost = { getCanonicalFileName: path => path, getCurrentDirectory: external_typescript_namespaceObject["default"].sys.getCurrentDirectory, getNewLine: () => external_typescript_namespaceObject["default"].sys.newLine }; function watchMain() { const configPath = external_typescript_namespaceObject["default"].findConfigFile( /*searchPath*/ "./", external_typescript_namespaceObject["default"].sys.fileExists, "tsconfig.json"); if (!configPath) { throw new Error("Could not find a valid 'tsconfig.json'."); } // TypeScript can use several different program creation "strategies": // * ts.createEmitAndSemanticDiagnosticsBuilderProgram, // * ts.createSemanticDiagnosticsBuilderProgram // * ts.createAbstractBuilder // The first two produce "builder programs". These use an incremental strategy // to only re-check and emit files whose contents may have changed, or whose // dependencies may have changes which may impact change the result of prior // type-check and emit. // The last uses an ordinary program which does a full type check after every // change. // Between `createEmitAndSemanticDiagnosticsBuilderProgram` and // `createSemanticDiagnosticsBuilderProgram`, the only difference is emit. // For pure type-checking scenarios, or when another tool/process handles emit, // using `createSemanticDiagnosticsBuilderProgram` may be more desirable. const createProgram = external_typescript_namespaceObject["default"].createSemanticDiagnosticsBuilderProgram; // Note that there is another overload for `createWatchCompilerHost` that takes // a set of root files. const host = external_typescript_namespaceObject["default"].createWatchCompilerHost(configPath, { preserveSymlinks: true }, external_typescript_namespaceObject["default"].sys, createProgram, reportDiagnostic, reportWatchStatusChanged); // You can technically override any given hook on the host, though you probably // don't need to. // Note that we're assuming `origCreateProgram` and `origPostProgramCreate` // doesn't use `this` at all. const origPostProgramCreate = host.afterProgramCreate; let initial = true; host.afterProgramCreate = program => { if (initial) { process.send?.({ event: 'READY' }); initial = false; } origPostProgramCreate(program); }; // `createWatchProgram` creates an initial program, watches files, and updates // the program over time. external_typescript_namespaceObject["default"].createWatchProgram(host); } function reportDiagnostic(diagnostic) { console.error("Error", diagnostic.code, ":", external_typescript_namespaceObject["default"].flattenDiagnosticMessageText(diagnostic.messageText, formatHost.getNewLine())); } /** * Prints a diagnostic every time the watch status changes. * This is mainly for messages like "Starting compilation" or "Compilation completed". */ function reportWatchStatusChanged(diagnostic) { console.info(external_typescript_namespaceObject["default"].formatDiagnostic(diagnostic, formatHost)); } ;// CONCATENATED MODULE: ./lib/tsc.ts watchMain();