fix(ci): lazy-load TypeScript in ts guard utils

This commit is contained in:
Vincent Koc
2026-03-22 16:04:23 -07:00
parent 19c85cf44f
commit 091b811a61

View File

@@ -1,7 +1,15 @@
import { promises as fs } from "node:fs";
import { createRequire } from "node:module";
import path from "node:path";
import { fileURLToPath } from "node:url";
import ts from "typescript";
const require = createRequire(import.meta.url);
let tsCache;
function getTypeScript() {
tsCache ??= require("typescript");
return tsCache;
}
const baseTestSuffixes = [".test.ts", ".test-utils.ts", ".test-harness.ts", ".e2e-harness.ts"];
@@ -113,6 +121,7 @@ export function toLine(sourceFile, node) {
}
export function getPropertyNameText(name) {
const ts = getTypeScript();
if (ts.isIdentifier(name) || ts.isStringLiteral(name) || ts.isNumericLiteral(name)) {
return name.text;
}
@@ -120,6 +129,7 @@ export function getPropertyNameText(name) {
}
export function unwrapExpression(expression) {
const ts = getTypeScript();
let current = expression;
while (true) {
if (ts.isParenthesizedExpression(current)) {