diff --git a/scripts/lib/ts-guard-utils.mjs b/scripts/lib/ts-guard-utils.mjs index 0bbb81cc45c..e9130e4ae22 100644 --- a/scripts/lib/ts-guard-utils.mjs +++ b/scripts/lib/ts-guard-utils.mjs @@ -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)) {