Commit Graph
1 Commits
Author SHA1 Message Date
yetone a9242eb68b plugins: a package.json with bytes after its object is mended around each bun command (plugins#405)
klmno1993 (Windows 11, bun 1.4.4, magpie 0.1.1552): plugins/package.json
kept the old file's last 56 bytes after its closing brace once a shorter
one was written over it (244 bytes before and after; zcode-auth had just
left the list). From then on every bun add in plugins/ failed on
"failed to read/parse package.json for workspace ''", whatever the plugin
or source. magpie itself writes package.json only when it is missing, so
the in-place write is likely bun's remove on Windows; not reproduced here.

Now, under installMu, before and after each bun command (runBun and
install's bun add), a package.json that doesn't parse but starts with a
whole object is cut to that object and written through edit.WriteAtomic;
the file as it was is kept as package.json.broken. A file whose start
isn't an object, or one cut short, is left as it is. Users already stuck
are mended on their next install or update, with nothing to do.

Run:
- TestPackageJSONTailIsCut, with the reporter's bytes: red with the write
  pointed elsewhere by hand, green with it.
- go test ./internal/plugin (104s, ok, at e5dd86965), go build ./...,
  gofmt -l, GOOS=linux and GOOS=windows go vet ./internal/plugin; after
  the rebase onto origin/main, the build and the new and Load tests again.
Not tried: a real bun remove on Windows leaving the tail, or the whole
suite.
2026-10-26 15:02:10 +08:00