[PR #5736] bun: avoid reinstall loop for @latest deps #11555

Closed
opened 2026-02-16 18:16:24 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/anomalyco/opencode/pull/5736

State: closed
Merged: No


Why

When OpenCode installs plugins, it runs bun add --force --exact --cwd ~/.cache/opencode <pkg>@latest. Bun rewrites the cache project's package.json to the resolved version (e.g. 4.1.1) because of --exact. On the next startup, OpenCode compares the requested version string (latest) to the package.json entry (4.1.1) and re-runs bun add --force again. With multiple @latest plugins, this repeats N times per startup and can add minutes of latency (often seen behind mirrors/proxies).

What

  • Treat a requested version of latest as satisfied when any version is present in the cache project's package.json and the module is installed (node_modules/<pkg>/package.json exists).
  • Keep strict equality for non-latest versions.

Notes

  • This is intentionally minimal and preserves existing registry resolution behavior.
  • Local validation: bun test packages/opencode/test/bun.test.ts.

Fixes the repeated reinstall behavior reported in issues like #4682 and related BunInstallFailedError/slow startup threads.

**Original Pull Request:** https://github.com/anomalyco/opencode/pull/5736 **State:** closed **Merged:** No --- ### Why When OpenCode installs plugins, it runs `bun add --force --exact --cwd ~/.cache/opencode <pkg>@latest`. Bun rewrites the cache project's `package.json` to the resolved version (e.g. `4.1.1`) because of `--exact`. On the next startup, OpenCode compares the requested version string (`latest`) to the `package.json` entry (`4.1.1`) and re-runs `bun add --force` again. With multiple `@latest` plugins, this repeats N times per startup and can add minutes of latency (often seen behind mirrors/proxies). ### What - Treat a requested version of `latest` as satisfied when *any* version is present in the cache project's `package.json` **and** the module is installed (`node_modules/<pkg>/package.json` exists). - Keep strict equality for non-`latest` versions. ### Notes - This is intentionally minimal and preserves existing registry resolution behavior. - Local validation: `bun test packages/opencode/test/bun.test.ts`. Fixes the repeated reinstall behavior reported in issues like #4682 and related `BunInstallFailedError`/slow startup threads.
yindo added the pull-request label 2026-02-16 18:16:24 -05:00
yindo closed this issue 2026-02-16 18:16:24 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#11555