fix(build): externalize zod from plugin bundle to prevent dual-instance crash

When oh-my-openagent is loaded by opencode 1.4.6+, both sides ship zod v4
but as two separate instances. zod v4 uses instance-identity checks
(schema._zod.def) that fail across module boundaries, causing:
  TypeError: undefined is not an object (evaluating 'n._zod.def')

Fix:
- Add --external zod to the plugin bundle build command so the plugin
  resolves zod from opencode's runtime instead of embedding its own copy
- Move zod from dependencies to peerDependencies (^4.0.0) so package
  managers know to deduplicate on a single shared instance
- Keep zod in devDependencies so local build/test continues to work

The plugin dist/index.js no longer contains node_modules/zod/v4 internals.

Fixes #3479
This commit is contained in:
YeonGyu-Kim
2026-04-17 12:08:39 +09:00
parent a5ae0b838c
commit e97953e390
2 changed files with 34 additions and 28 deletions
+8 -5
View File
@@ -21,7 +21,7 @@
"./schema.json": "./dist/oh-my-opencode.schema.json"
},
"scripts": {
"build": "bun build src/index.ts --outdir dist --target bun --format esm --external @ast-grep/napi && tsc --emitDeclarationOnly && bun build src/cli/index.ts --outdir dist/cli --target bun --format esm --external @ast-grep/napi && bun run build:schema",
"build": "bun build src/index.ts --outdir dist --target bun --format esm --external @ast-grep/napi --external zod && tsc --emitDeclarationOnly && bun build src/cli/index.ts --outdir dist/cli --target bun --format esm --external @ast-grep/napi && bun run build:schema",
"build:all": "bun run build && bun run build:binaries",
"build:binaries": "bun run script/build-binaries.ts",
"build:schema": "bun run script/build-schema.ts",
@@ -69,14 +69,14 @@
"picocolors": "^1.1.1",
"picomatch": "^4.0.2",
"posthog-node": "^5.29.2",
"vscode-jsonrpc": "^8.2.0",
"zod": "^4.3.0"
"vscode-jsonrpc": "^8.2.0"
},
"devDependencies": {
"@types/js-yaml": "^4.0.9",
"@types/picomatch": "^3.0.2",
"bun-types": "1.3.11",
"typescript": "^5.7.3"
"typescript": "^5.7.3",
"zod": "^4.3.0"
},
"optionalDependencies": {
"oh-my-opencode-darwin-arm64": "3.17.4",
@@ -96,5 +96,8 @@
"@ast-grep/cli",
"@ast-grep/napi",
"@code-yeongyu/comment-checker"
]
],
"peerDependencies": {
"zod": "^4.0.0"
}
}