Skip to content

Fix upgrade fails to find package.json #1030

Open
clarajohan wants to merge 1 commit into
garrytan:masterfrom
clarajohan:master
Open

Fix upgrade fails to find package.json #1030
clarajohan wants to merge 1 commit into
garrytan:masterfrom
clarajohan:master

Conversation

@clarajohan
Copy link
Copy Markdown

@clarajohan clarajohan commented May 15, 2026

Fixes Issue 1029

  • Added detectBunGlobalInstallRoot() helper that walks up from realpath(process.argv[1]) and returns the first ancestor with both package.json AND a node_modules/ subdir.
  • case 'bun': now calls it and passes the result as cwd to execFileSync('bun', ['update', 'gbrain'], ...).
  • Switched from execSync to execFileSync (no shell needed, tighter surface).
  • When detection fails, prints a paste-ready manual recovery line instead of the misleading "Upgrade failed" message.

Test (test/upgrade-bun-cwd.serial.test.ts, 5 cases): walks up correctly inside a faithful /.bun/install/global/ replica; returns null on missing
argv[1]; returns null on no install-root signal; rejects node_modules/gbrain/package.json as a false positive (the "first package.json wins" trap);
resolves through the symlinked-bin shape (
/.bun/bin/gbrain → real cli.ts). Marked .serial.test.ts because it mutates process.argv[1], which is
process-global. macOS /tmp → /private/tmp symlink handled by realpath'ing the workDir in beforeEach.

Fixes #1029

  - Added detectBunGlobalInstallRoot() helper that walks up from realpath(process.argv[1]) and returns the first ancestor with both package.json AND a
  node_modules/ subdir.
  - case 'bun': now calls it and passes the result as cwd to execFileSync('bun', ['update', 'gbrain'], ...).
  - Switched from execSync to execFileSync (no shell needed, tighter surface).
  - When detection fails, prints a paste-ready manual recovery line instead of the misleading "Upgrade failed" message.

Test (test/upgrade-bun-cwd.serial.test.ts, 5 cases): walks up correctly inside a faithful ~/.bun/install/global/ replica; returns null on missing
  argv[1]; returns null on no install-root signal; rejects node_modules/gbrain/package.json as a false positive (the "first package.json wins" trap);
  resolves through the symlinked-bin shape (~/.bun/bin/gbrain → real cli.ts). Marked .serial.test.ts because it mutates process.argv[1], which is
  process-global. macOS /tmp → /private/tmp symlink handled by realpath'ing the workDir in beforeEach.
@clarajohan
Copy link
Copy Markdown
Author

Another fix 1032 addresses the same issue. If that fix is merged, close this one

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

gbrain upgrade - No package.json, so nothing to update

1 participant