Repository navigation
fix(opencode): skip the plugin postinstall inside the monorepo (cross-platform) - #1735
Merged
Merged
Conversation
…-platform
The postinstall copied the command stubs and the knowledge skill into
${XDG_CONFIG_HOME:-~/.config}/opencode on every bun install in this repo,
overwriting the developer's real OpenCode setup with the checked-out branch.
It is now a Node script (scripts/postinstall.cjs, shipped in files) that
copies only when the package sits under a node_modules directory, which an
installed package always does and a workspace checkout never does.
PLANNOTATOR_OPENCODE_POSTINSTALL=1 forces the copy, =0 skips it. Targets,
XDG_CONFIG_HOME handling and never-fail behavior are unchanged.
The earlier shell case/esac guard broke bun install on Windows and was
reverted; this one has no shell syntax.
OpenCode's plugin installer never runs it (ignoreScripts, or bun add blocking untrusted scripts); pnpm 10 and bun block it by default; npm install <path> and npm link skip the copy.
1 task
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
@plannotator/opencodehas apostinstallthat copiescommands/*.mdto${XDG_CONFIG_HOME:-$HOME/.config}/opencode/commandsand the knowledge skill to.../opencode/skills/plannotator. That is right when a user installs the package with a package manager that runs its scripts. It also runs on everybun installin this repo (any worktree, any agent, CI), becauseapps/opencode-pluginis a workspace package. Each run overwrote the developer's real OpenCode stubs and skill with the checked-out branch's copies.History
#1697 (fix 4) added a shell
case "$PWD" in */node_modules/*) ...guard to the script line. Bun's script shell on Windows does not supportcase ... esac, sobun installfailed on Windows and the guard was reverted (a723641).Fix
postinstallis nownode scripts/postinstall.cjs. There is no shell syntax, so the command works under npm, pnpm and bun on macOS, Linux and Windows.scripts/postinstall.cjsis added tofiles.node_modulespath segment. An installed package always does, and a workspace checkout never does.PLANNOTATOR_OPENCODE_POSTINSTALL=1forces the copy and=0skips it.XDG_CONFIG_HOMEcounts as unset, and errors are ignored, so the script never fails an install (as|| truedid before).scripts/install.shand the other installers write their own stubs. They are not affected.When the script runs at all
bun add --trust).ignoreScripts: true, and older OpenCode usedbun add, which blocks untrusted scripts. Those users get the stubs from the install scripts and the plugin's native commands. This PR does not change that.npm install <path>andnpm linkrun it from the source directory, which is not undernode_modules, so they skip the copy. SetPLANNOTATOR_OPENCODE_POSTINSTALL=1to copy there.Verification
apps/opencode-plugin/postinstall.test.tscovers the decision (POSIX and Windows paths, pnpm layout, workspace, override), the config-dir resolution, copying into tempXDG_CONFIG_HOME/HOME, missing sources, an unwritable target (exit 0), and the script as a process. Nothing touches the real~/.config.bun installat the repo root. Bun's verbose log shows the@plannotator/opencodescripts ran. The mtimes of the real~/.config/opencodestubs and skill did not change.npm packand installed the tarball into temp projects with npm, pnpm (builds allowed) andbun add --trust, each with a tempXDG_CONFIG_HOME. All three wrote the 3 stubs andSKILL.md.bun pm pack(the release path) also includes the script.bun test apps/opencode-plugin: 347 pass.bun run typecheckis clean.Windows CI: the root
bun installon windows-latest now runsnode scripts/postinstall.cjs. Node is preinstalled on those runners, and bun substitutes itself fornodewhen Node is missing. The OpenCode 2 installed-package job installs the packed tarball, which now includes the script.