Skip to content

fix(opencode): skip the plugin postinstall inside the monorepo (cross-platform) - #1735

Merged
backnotprop merged 2 commits into
mainfrom
fix/opencode-postinstall-guard
Oct 6, 2026
Merged

backnotprop merged 2 commits into
mainfrom
fix/opencode-postinstall-guard

Conversation

@backnotprop

@backnotprop backnotprop commented Oct 6, 2026 •

Copy link
Copy Markdown
Owner

Problem

@plannotator/opencode has a postinstall that copies commands/*.md to ${XDG_CONFIG_HOME:-$HOME/.config}/opencode/commands and 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 every bun install in this repo (any worktree, any agent, CI), because apps/opencode-plugin is 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 support case ... esac, so bun install failed on Windows and the guard was reverted (a723641).

Fix

  • postinstall is now node scripts/postinstall.cjs. There is no shell syntax, so the command works under npm, pnpm and bun on macOS, Linux and Windows. scripts/postinstall.cjs is added to files.
  • The script copies only when the package directory has a node_modules path segment. An installed package always does, and a workspace checkout never does.
  • PLANNOTATOR_OPENCODE_POSTINSTALL=1 forces the copy and =0 skips it.
  • Everything else is unchanged: the same targets, an empty XDG_CONFIG_HOME counts as unset, and errors are ignored, so the script never fails an install (as || true did before).
  • scripts/install.sh and the other installers write their own stubs. They are not affected.

When the script runs at all

  • npm and yarn 1 run it. It copies.
  • pnpm 10 and bun block dependency scripts by default. It runs, and copies, only when builds are allowed (pnpm's allow-builds setting, bun add --trust).
  • OpenCode's plugin installer does not run it. OpenCode 1.18.x and 2.0.x install plugins with npm's internal installer and ignoreScripts: true, and older OpenCode used bun 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> and npm link run it from the source directory, which is not under node_modules, so they skip the copy. Set PLANNOTATOR_OPENCODE_POSTINSTALL=1 to copy there.

Verification

  • apps/opencode-plugin/postinstall.test.ts covers the decision (POSIX and Windows paths, pnpm layout, workspace, override), the config-dir resolution, copying into temp XDG_CONFIG_HOME/HOME, missing sources, an unwritable target (exit 0), and the script as a process. Nothing touches the real ~/.config.
  • Ran bun install at the repo root. Bun's verbose log shows the @plannotator/opencode scripts ran. The mtimes of the real ~/.config/opencode stubs and skill did not change.
  • Packed with npm pack and installed the tarball into temp projects with npm, pnpm (builds allowed) and bun add --trust, each with a temp XDG_CONFIG_HOME. All three wrote the 3 stubs and SKILL.md. bun pm pack (the release path) also includes the script.
  • bun test apps/opencode-plugin: 347 pass. bun run typecheck is clean.

Windows CI: the root bun install on windows-latest now runs node scripts/postinstall.cjs. Node is preinstalled on those runners, and bun substitutes itself for node when Node is missing. The OpenCode 2 installed-package job installs the packed tarball, which now includes the script.

…-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.
@backnotprop
backnotprop merged commit e1c342e into main Oct 6, 2026
28 checks passed
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.

1 participant