UNPKG

convex

Version:

Client for the Convex Cloud

114 lines (113 loc) 4.01 kB
"use strict"; var __create = Object.create; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __getProtoOf = Object.getPrototypeOf; var __hasOwnProp = Object.prototype.hasOwnProperty; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps( isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod )); var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); var typecheck_exports = {}; __export(typecheck_exports, { processTypeCheckResult: () => processTypeCheckResult, typeCheckFunctions: () => typeCheckFunctions }); module.exports = __toCommonJS(typecheck_exports); var import_child_process = __toESM(require("child_process")); var import_chalk = __toESM(require("chalk")); var import_path = __toESM(require("path")); var Sentry = __toESM(require("@sentry/node")); async function processTypeCheckResult(ctx, typeCheckMode, runTypeCheck) { if (typeCheckMode === "disable") { return; } const result = await runTypeCheck(); if (result === "cantTypeCheck" && typeCheckMode === "enable" || result === "typecheckFailed") { console.error( import_chalk.default.gray("To ignore failing typecheck, use `--typecheck=disable`.") ); return await ctx.fatalError(1, "fs"); } } async function typeCheckFunctions(ctx, functionsDir) { const tsconfig = import_path.default.join(functionsDir, "tsconfig.json"); if (!ctx.fs.exists(tsconfig)) { console.error( "Can't find convex/tsconfig.json to use to typecheck Convex functions." ); console.error("Run `npx convex codegen --tsconfig` to create one."); return "cantTypeCheck"; } return runTsc(ctx, ["--project", functionsDir]); } async function runTsc(ctx, tscArgs) { const tscPath = import_path.default.join( "node_modules", ".bin", process.platform == "win32" ? "tsc.CMD" : "tsc" ); if (!ctx.fs.exists(tscPath)) { return "cantTypeCheck"; } const result = import_child_process.default.spawnSync( tscPath, tscArgs.concat("--listFiles") ); if (result.status === null) { console.error(import_chalk.default.red(`TypeScript typecheck timed out.`)); if (result.error) { console.error(import_chalk.default.red(`${result.error}`)); } return "typecheckFailed"; } const filesTouched = result.stdout.toString("utf-8").split("\n").map((s) => s.trim()).filter((s) => s.length > 0); let anyPathsFound = false; for (const fileTouched of filesTouched) { const absPath = import_path.default.resolve(fileTouched); let st; try { st = ctx.fs.stat(absPath); anyPathsFound = true; } catch (err) { continue; } ctx.fs.registerPath(absPath, st); } if (filesTouched.length > 0 && !anyPathsFound) { const err = new Error( `Failed to stat any files emitted by tsc (received ${filesTouched.length})` ); Sentry.captureException(err); } if (!result.error && result.status === 0) { return "success"; } try { import_child_process.default.execFileSync( tscPath, tscArgs, { stdio: "inherit" } ); ctx.fs.invalidate(); return "success"; } catch (e) { console.error(import_chalk.default.red("TypeScript typecheck via `tsc` failed.")); return "typecheckFailed"; } } //# sourceMappingURL=typecheck.js.map