Repository navigation
Commit e17f70f
fix(cli): read Wrangler configs that start with a UTF-8 BOM
Bug: a root wrangler.jsonc/wrangler.json saved with a UTF-8 BOM (common
for files written by Windows editors) is valid for Wrangler, but Void
treats it as unreadable. `vite dev` / `vite build` stop with "db: cannot
read malformed Wrangler configuration". `void deploy --platform
cloudflare` on an app with a durable-objects/ file treats the file as
missing and overwrites it with only `durable_objects` and `migrations`,
so `name`, `main`, `routes` and every other key are lost. For typed
projects the truncated config is then saved as the lock's resolved
state. The managed deploy live-binding sync reaches the same reader.
Plain `void deploy` (no --platform, no saved destination), which the
deployment guide names as the way to link an existing Worker, stops
with "Set the existing Worker's name in a valid wrangler.jsonc before
linking to Cloudflare." even though the name is set.
Repro: write wrangler.jsonc as U+FEFF + `{ // app, "name": "existing",
"main": ..., "routes": [...] }`, then call syncWranglerDurableObjects()
with one Durable Object module (or readRootWranglerConfig()). The file
ends up as `{ durable_objects, migrations }` (or the reader throws
"Failed to parse JSONC"). With the same BOM file and no saved
destination, maybeLinkCloudflareDeploy() throws instead of offering to
link the Worker.
Cause: two JSONC readers pass the text straight to jsonc-parser: the
private parseJsonc() in packages/void/src/cli/wrangler.ts and the
onboarding check in maybeLinkCloudflareDeploy()
(packages/void/src/cli/cloudflare-link.ts). Node's utf-8 read keeps the
BOM. jsonc-parser still returns the object, but also reports the BOM as
a syntax error at offset 0, and both readers treat any error as a bad
file. readOrCreateProjectWranglerConfig() swallows that error and
returns an empty config with created: true, so its callers write their
keys over the user's file. Void's other JSONC readers
(generated-wrangler-config, migrate) and the comment-preserving writers
in wrangler.ts already strip the BOM.
Fix: strip one leading BOM before parsing in both readers. In
wrangler.ts, parseJsonc() uses the file's existing UTF8_BOM constant,
which fixes every reader in that file at once
(readOrCreateProjectWranglerConfig, readRootWranglerConfig, the Durable
Object, compat and WebSocket readers). In cloudflare-link.ts the
onboarding read uses the same `.replace(/^\uFEFF/, '')` as
generated-wrangler-config; its checks and error messages are unchanged,
and it still never writes the file. No other behaviour changes.
Test:
- packages/void/test/unit/wrangler.test.ts, "keeps existing keys of a
BOM-prefixed config when adding Durable Objects". Without the fix
readRootWranglerConfig() throws "Failed to parse JSONC", and the sync
replaces the file with only durable_objects and migrations.
- packages/void/test/unit/cloudflare-link.test.ts, "offers to link a
Worker whose config starts with a UTF-8 BOM". Without the fix
maybeLinkCloudflareDeploy() throws "Set the existing Worker's name in
a valid wrangler.jsonc"; with it, it returns 'existing' and the file
bytes, BOM included, are unchanged.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0123r5HnanmW2VUrZ7VWDufH1 parent bd55219 commit e17f70f
4 files changed
Lines changed: 49 additions & 2 deletions
File tree
- packages/void
- src/cli
- test/unit
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
225 | 225 | | |
226 | 226 | | |
227 | 227 | | |
228 | | - | |
| 228 | + | |
229 | 229 | | |
230 | 230 | | |
231 | 231 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1771 | 1771 | | |
1772 | 1772 | | |
1773 | 1773 | | |
1774 | | - | |
| 1774 | + | |
| 1775 | + | |
1775 | 1776 | | |
1776 | 1777 | | |
1777 | 1778 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
35 | 35 | | |
36 | 36 | | |
37 | 37 | | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
38 | 50 | | |
39 | 51 | | |
40 | 52 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
| 16 | + | |
16 | 17 | | |
17 | 18 | | |
18 | 19 | | |
| |||
549 | 550 | | |
550 | 551 | | |
551 | 552 | | |
| 553 | + | |
| 554 | + | |
| 555 | + | |
| 556 | + | |
| 557 | + | |
| 558 | + | |
| 559 | + | |
| 560 | + | |
| 561 | + | |
| 562 | + | |
| 563 | + | |
| 564 | + | |
| 565 | + | |
| 566 | + | |
| 567 | + | |
| 568 | + | |
| 569 | + | |
| 570 | + | |
| 571 | + | |
| 572 | + | |
| 573 | + | |
| 574 | + | |
| 575 | + | |
| 576 | + | |
| 577 | + | |
| 578 | + | |
| 579 | + | |
| 580 | + | |
| 581 | + | |
| 582 | + | |
| 583 | + | |
| 584 | + | |
| 585 | + | |
552 | 586 | | |
553 | 587 | | |
554 | 588 | | |
| |||
0 commit comments