UNPKG

ttsc

Version:

General-purpose TypeScript-Go compiler, runtime, plugin host, and LSP host.

62 lines 2.43 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.buildNativeCompiler = buildNativeCompiler; const node_fs_1 = __importDefault(require("node:fs")); const node_path_1 = __importDefault(require("node:path")); const buildSourcePlugin_1 = require("../../plugin/internal/buildSourcePlugin"); /** * Build (or retrieve from cache) the native ttsc compiler host binary used by * the in-memory API compilation paths (`compileProjectInMemory`, * `transformProjectInMemory`). * * The host is the `cmd/ttsc` Go entrypoint compiled with `buildSourcePlugin`. * The cache key incorporates the ttsc package version and the full `go.mod` * contents so a toolchain upgrade automatically produces a fresh binary. * * @returns Absolute path to the compiled host executable. */ function buildNativeCompiler(options) { return (0, buildSourcePlugin_1.buildSourcePlugin)({ baseDir: options.cacheBaseDir, cacheDir: options.cacheDir, label: "compiler host", overlayDirs: [], pluginName: "ttsc", quiet: true, source: node_path_1.default.join(options.packageRoot, "cmd", "ttsc"), ttscVersion: readOwnPackageVersion(options.packageRoot), tsgoVersion: readGoModuleVersion(options.packageRoot), }); } /** * Read the `version` field from `package.json` inside `packageRoot`, falling * back to `"0.0.0"` when the file is absent or malformed. */ function readOwnPackageVersion(packageRoot) { try { const pkg = JSON.parse(node_fs_1.default.readFileSync(node_path_1.default.join(packageRoot, "package.json"), "utf8")); return typeof pkg.version === "string" ? pkg.version : "0.0.0"; } catch { return "0.0.0"; } } /** * Read the full contents of `go.mod` inside `packageRoot` and use it as a * version token for the binary cache key. Returns `"unknown"` on read error. * * Using the entire `go.mod` ensures that any dependency bump (including * indirect ones) invalidates the cached binary. */ function readGoModuleVersion(packageRoot) { try { return node_fs_1.default.readFileSync(node_path_1.default.join(packageRoot, "go.mod"), "utf8"); } catch { return "unknown"; } } //# sourceMappingURL=buildNativeCompiler.js.map