@reliverse/rse
Version:
@reliverse/rse is your all-in-one companion for bootstrapping and improving any kind of projects (especially web apps built with frameworks like Next.js) — whether you're kicking off something new or upgrading an existing app. It is also a little AI-power
19 lines (18 loc) • 584 B
JavaScript
import fs from "@reliverse/relifso";
import path from "path";
export function stripJsonComments(jsonString) {
return jsonString.replace(
/\\"|"(?:\\"|[^"])*"|(\/\/.*|\/\*[\s\S]*?\*\/)/g,
(m, g) => g ? "" : m
).replace(/,(?=\s*[}\]])/g, "");
}
export async function getTsconfigInfo(cwd, flatPath) {
let tsConfigPath;
if (flatPath) {
tsConfigPath = flatPath;
} else {
tsConfigPath = cwd ? path.join(cwd, "tsconfig.json") : path.join("tsconfig.json");
}
const text = await fs.readFile(tsConfigPath, "utf-8");
return JSON.parse(stripJsonComments(text));
}