Skip to content

Commit 28e279a

Browse files
ceccecclaude
andcommitted
fix(build): tolerate trailing commas when reading wrangler.jsonc
After the D1 migration succeeds, migrate-production.mjs calls wranglerD1DatabaseIds() -> readWranglerConfig(), which did JSON.parse(stripJsonComments(text)). strip-json-comments removes comments but not trailing commas, so wrangler.jsonc (e.g. `"binding": "ASSETS",` before `}`) threw 'Expected double-quoted property name in JSON'. Strip trailing commas too. Surfaced now that the Cloudflare build gets past migrate (Node 24 pin + D1 adapter wiring): the D1 schema migration runs and succeeds, then this parse ran. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent d09e34d commit 28e279a

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

scripts/lib/wranglerConfig.mjs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
/**
2-
* Parse `wrangler.jsonc` once per process (comments stripped — valid JSON only after strip).
2+
* Parse `wrangler.jsonc`. `.jsonc` permits both comments and trailing commas; `strip-json-comments`
3+
* removes only comments, so we also strip trailing commas (a `,` right before `}`/`]`) before
4+
* JSON.parse — otherwise a config like `"binding": "ASSETS",\n}` throws "Expected double-quoted
5+
* property name".
36
*/
47
import fs from 'node:fs'
58
import path from 'node:path'
@@ -10,7 +13,8 @@ import stripJsonComments from 'strip-json-comments'
1013
export function readWranglerConfig(cwd = process.cwd()) {
1114
const p = path.join(cwd, 'wrangler.jsonc')
1215
const text = fs.readFileSync(p, 'utf8')
13-
return JSON.parse(stripJsonComments(text))
16+
const json = stripJsonComments(text).replace(/,(\s*[}\]])/g, '$1')
17+
return JSON.parse(json)
1418
}
1519

1620
/**

0 commit comments

Comments
 (0)