fix: resolve plugin host root from published dist layout#852
fix: resolve plugin host root from published dist layout#852jackwener merged 1 commit intojackwener:mainfrom
Conversation
Astro-Han
left a comment
There was a problem hiding this comment.
Reviewed top to bottom against our AGENTS.md framework.
No P0 to P3 findings.
This is a meaningful and focused fix. It addresses the root cause in published builds, where resolving the host root from the module path could land on dist/ instead of the package root, which then broke plugin host linking and package export resolution.
Scope is tight, the helper is reused in both affected call sites, and the added regression test covers the dist/src layout that triggered the bug.
LGTM.
jackwener
left a comment
There was a problem hiding this comment.
LGTM. Clean fix.
Problem: path.dirname(thisFile) + '..' assumed the module is always one level deep (src/plugin.ts or dist/plugin.js). But in published builds, the compiled file lives at dist/src/plugin.js — two levels deep — so .. resolves to dist/ instead of the package root, breaking plugin host symlinks and esbuild resolution.
Solution: resolveHostOpencliRoot() walks upward from the current file until it finds a package.json with name: '@jackwener/opencli'. Falls back to the old dirname + '..' if nothing matches, preserving backward compatibility.
Review notes:
- Walk-up logic is correct — checks
pkg.nameto avoid stopping at nested package.json files (e.g. in node_modules) - The
catch {}on JSON parse is appropriate — a malformed package.json shouldn't halt the search - Both call sites (
linkHostOpencliandresolveEsbuildBin) are updated - Regression test covers the exact scenario (dist/src layout)
- CI all green
No issues found.
Summary
Fixes plugin host package linking for published builds by resolving the real
@jackwener/openclipackage root from the running module path instead of assuming it is always one directory up.In published installs,
src/plugin.tscompiles underdist/src/plugin.js, so the olddirname + '..'logic could point pluginnode_modules/@jackwener/opencliatdist/instead of the package root. That breaks package export resolution for imports like@jackwener/opencli/registry.Changes
resolveHostOpencliRoot()to walk upward until it finds the host packagepackage.json.dist/src/plugin.jslayout.Validation
npm test -- --run src/plugin.test.tsnpm run typecheckFixes #843
Refs #722