Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/void/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@
"drizzle-valibot": "^0.4.2",
"drizzle-zod": "^0.8.3",
"hono": "^4.12.9",
"jsonc-parser": "3.3.1",
"pg": "^8.20.0",
"wrangler": "catalog:"
},
Expand Down
6 changes: 4 additions & 2 deletions packages/void/src/cli/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
unlinkSync,
} from "node:fs";
import { basename, dirname, join } from "node:path";
import { parse, type ParseError } from "jsonc-parser";
import { parseArgs } from "node:util";
import { intro, outro, log, confirm, isCancel, cancel, note, select } from "@clack/prompts";
import { ensureProjectTsconfig } from "../codegen/project-tsconfig";
Expand Down Expand Up @@ -362,9 +363,10 @@ function setupWranglerConfig(root: string, framework: DetectedFramework): void {
if (existsSync(p)) {
configPath = p;
try {
// Use dynamic import-free JSONC parsing — strip comments, then JSON.parse
const raw = readFileSync(p, "utf-8");
parsed = JSON.parse(raw.replace(/\/\/.*$/gm, "").replace(/\/\*[\s\S]*?\*\//g, ""));
const errors: ParseError[] = [];
parsed = parse(raw, errors);
if (errors.length > 0) throw new SyntaxError("Failed to parse JSONC");
} catch {
// unparseable — start fresh
}
Expand Down
41 changes: 6 additions & 35 deletions packages/void/src/cli/wrangler.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { readFileSync, writeFileSync, existsSync } from "node:fs";
import { join } from "node:path";
import { parse, type ParseError } from "jsonc-parser";
import type { InferredBindings } from "../inference/walk";
import type { VoidConfig } from "../config";
import type { WebSocketRouteDefinition } from "../router/websocket";
Expand Down Expand Up @@ -210,41 +211,11 @@ export function ensureWranglerNodejsAlsFlag(root: string): boolean {
return true;
}

/**
* Minimal JSONC parser — strips single-line (`//`) and multi-line comments
* before parsing as JSON. Handles comments inside strings correctly.
*/
function parseJsonc(text: string): Record<string, unknown> {
let result = "";
let i = 0;
while (i < text.length) {
// String literal — copy verbatim
if (text[i] === '"') {
const start = i;
i++; // skip opening quote
while (i < text.length && text[i] !== '"') {
if (text[i] === "\\") i++; // skip escaped char
i++;
}
i++; // skip closing quote
result += text.slice(start, i);
continue;
}
// Single-line comment
if (text[i] === "/" && text[i + 1] === "/") {
i += 2;
while (i < text.length && text[i] !== "\n") i++;
continue;
}
// Multi-line comment
if (text[i] === "/" && text[i + 1] === "*") {
i += 2;
while (i < text.length && !(text[i] === "*" && text[i + 1] === "/")) i++;
i += 2; // skip */
continue;
}
result += text[i];
i++;
const errors: ParseError[] = [];
const result = parse(text, errors);
if (errors.length > 0) {
throw new SyntaxError("Failed to parse JSONC");
}
return JSON.parse(result);
return result;
}
8 changes: 8 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading