ttsc
Version:
General-purpose TypeScript-Go compiler, runtime, plugin host, and LSP host.
39 lines • 1.76 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.getCompilerVersionText = getCompilerVersionText;
const node_fs_1 = __importDefault(require("node:fs"));
const node_path_1 = __importDefault(require("node:path"));
const resolveTsgo_1 = require("../../compiler/internal/resolveTsgo");
const spawnNative_1 = require("../../compiler/internal/spawnNative");
/** Format the CLI version banner from the wrapper package and resolved tsc. */
function getCompilerVersionText(options = {}) {
const tsgo = (0, resolveTsgo_1.resolveTsgo)(options);
const res = (0, spawnNative_1.spawnNative)(tsgo.binary, ["--version"], {
cwd: options.cwd,
env: { ...process.env, ...options.env },
});
if (res.error || res.status !== 0) {
throw new Error("ttsc.version: failed: " + ((0, spawnNative_1.outputText)(res.stderr) || res.error?.message));
}
return `ttsc ${readOwnPackageVersion()} (${(0, spawnNative_1.outputText)(res.stdout).trim()})`;
}
/**
* Read the `version` field from the `@ttsc/ttsc` package.json that sits three
* directories above the compiled launcher output (`lib/launcher/internal/`).
* Returns `"0.0.0"` on any I/O or parse failure so the banner is always safe to
* display.
*/
function readOwnPackageVersion() {
try {
const file = node_path_1.default.resolve(__dirname, "..", "..", "..", "package.json");
const pkg = JSON.parse(node_fs_1.default.readFileSync(file, "utf8"));
return pkg.version ?? "0.0.0";
}
catch {
return "0.0.0";
}
}
//# sourceMappingURL=getCompilerVersionText.js.map