1// JSONC as wrangler reads it: // and /* */ comments outside strings, and2// trailing commas, removed so JSON.parse takes the rest.3import { readFileSync } from "node:fs";45export function stripComments(text) {6 let out = "";7 let inString = false;8 for (let i = 0; i < text.length; i++) {9 const c = text[i];10 if (inString) {11 out += c;12 if (c === "\\") out += text[++i];13 else if (c === '"') inString = false;14 } else if (c === '"') {15 inString = true;16 out += c;17 } else if (c === "/" && text[i + 1] === "/") {18 while (i < text.length && text[i] !== "\n") i++;19 out += "\n";20 } else if (c === "/" && text[i + 1] === "*") {21 const end = text.indexOf("*/", i + 2);22 if (end === -1) throw new Error("unterminated comment");23 i = end + 1;24 } else out += c;25 }26 return out.replace(/,(\s*[}\]])/g, "$1");27}2829export const readJSONC = (path) => JSON.parse(stripComments(readFileSync(path, "utf8")));