fix(cli): Run bun install after writing npm dependencies in ocx add#132
fix(cli): Run bun install after writing npm dependencies in ocx add#132beppe2880 wants to merge 1 commit intokdcokenny:mainfrom
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #132 +/- ##
==========================================
- Coverage 48.34% 48.06% -0.28%
==========================================
Files 47 47
Lines 4944 4972 +28
==========================================
Hits 2390 2390
- Misses 2554 2582 +28 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
OpenCode (at least used to) install all of these automatically using their built-in bun bundle. Please verify that this behaviour has changed. |
|
Hey @kdcokenny, verified — the behaviour hasn't changed, but it only installs under specific conditions. OpenCode's Reproduction steps# 1. Get OpenCode v1.1.52
mkdir -p /tmp/oc-bin && cd /tmp/oc-bin
gh release download v1.1.52 --repo sst/opencode --pattern "opencode-linux-x64.tar.gz" --clobber
tar xzf opencode-linux-x64.tar.gz
# 2. Fresh project with .opencode config
mkdir -p /tmp/oc-repro && cd /tmp/oc-repro && git init
mkdir -p .opencode && echo '{}' > .opencode/opencode.jsonc
# 3. Open OpenCode, send any message, close it
# This creates .opencode/node_modules with @opencode-ai/plugin
/tmp/oc-bin/opencode
# 4. Install worktree
ocx init && ocx registry add https://registry.kdco.dev --name kdco
ocx add kdco/worktree -f
# 5. State: package.json has jsonc-parser, node_modules doesn't
# 6. Restart OpenCode → hangs on blank screen
# Logs show: Cannot find package 'jsonc-parser' from '.opencode/plugin/worktree.ts'
/tmp/oc-bin/opencode
It never checks any other dependency. So when This one drove me nuts — I hit the bug on my desktop, then switched to my laptop (for unrelated reasons) to write a clean repro and it just worked. Couldn't reproduce a reproducibility bug (on NixOS of all things). Turns out on the laptop I'm also going to open a PR on OpenCode to make |
This is super interesting! Thanks for the research! |
Problem
ocx addwritesnpmDependencies/npmDevDependenciestopackage.jsonbut neverruns
bun install. Plugins that import external packages (e.g.jsonc-parser,zod)fail at runtime because the modules are not on disk.
This causes OpenCode to hang on startup with:
Cannot find package 'jsonc-parser' from '~/.opencode/plugin/worktree.ts'Fixes #131
Fix
Run
bun installin the package directory immediately after writingpackage.json,so dependencies are available before OpenCode tries to load the plugin.
A warning is logged if the install fails (e.g. no network), allowing the user to
install manually.
Summary by cubic
Automatically run bun install after ocx add writes package.json so plugin npm dependencies are installed. Prevents startup hangs and “Cannot find package …” errors.
Written for commit 6800faa. Summary will update on new commits.