UNPKG

ttsc

Version:

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

45 lines 2.08 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.resolveTtscserverBinary = resolveTtscserverBinary; const node_fs_1 = __importDefault(require("node:fs")); const node_path_1 = __importDefault(require("node:path")); /** * Resolve the platform-specific ttscserver binary path. Looks first at the * TTSCSERVER_BINARY environment override (must be absolute), then at the * shipped per-platform npm package (`@ttsc/<platform>-<arch>/bin/ttscserver`), * then at the local-build fallback under `packages/native/`. * * Mirrors `resolveBinary` for the ttsc helper so editors that install ttsc via * pnpm see the LSP host alongside the existing helper. */ function resolveTtscserverBinary(opts = {}) { const env = opts.env ?? process.env; if (env.TTSCSERVER_BINARY && node_path_1.default.isAbsolute(env.TTSCSERVER_BINARY)) { return env.TTSCSERVER_BINARY; } try { return require.resolve(`@ttsc/${process.platform}-${process.arch}/bin/${process.platform === "win32" ? "ttscserver.exe" : "ttscserver"}`); } catch { /* fall through to local lookup */ } const local = defaultLocalBinaryPath(); if (local) return local; return null; } function defaultLocalBinaryPath() { const root = packageRootDir(); const candidate = node_path_1.default.resolve(root, "..", "native", process.platform === "win32" ? "ttscserver.exe" : "ttscserver"); return node_fs_1.default.existsSync(candidate) ? candidate : null; } function packageRootDir() { const moduleDir = node_path_1.default.resolve(__dirname, "..", ".."); // Prefer the faster native variant; fall back to the JS implementation on // platforms (or environments) where `realpathSync.native` is unavailable. return node_fs_1.default.realpathSync.native?.(moduleDir) ?? node_fs_1.default.realpathSync(moduleDir); } //# sourceMappingURL=resolveTtscserverBinary.js.map