Skip to content

fix(installer): handle wildcard exports redirecting package.json in resolveNonRootPackage (#745) - #757

Open
yaojin3616 wants to merge 1 commit into
V0.12.2from
fix/issue-745-resolve-non-root-package-wildcard-exports
Open

yaojin3616 wants to merge 1 commit into
V0.12.2from
fix/issue-745-resolve-non-root-package-wildcard-exports

Conversation

@yaojin3616

Copy link
Copy Markdown
Contributor

解决的问题

修复 #745:当插件依赖的包(如 @modelcontextprotocol/sdk)在其 package.json 中声明了子路径通配符导出(如 "./*": "./dist/cjs/*")时,requireFromPackage.resolve("${dependency}/package.json") 会命中通配符被重定向到子目录下的编译产物 dist/cjs/package.json(通常仅含 {"type": "commonjs"},无 name 字段)。现有逻辑因 manifest.name !== dependency 提前 return undefined,导致正常的子路径包无法通过 peer 校验,插件安装必失败。

变更说明

  1. 全候选路径探测与向上回溯根包:
    • 当 selectedManifest 解析出的 manifest 缺少匹配的 name 时,向父级目录回溯寻找真正的包根 package.json;
    • 即使回溯未命中,继续遍历 resolve.paths 的拼接路径,而不是短路退出。
  2. 规范子路径返回路径:对仅声明子路径导出的包,返回包根目录下合法的 package.json 路径。
  3. 新增单元测试回归:在 test/generation-installer.test.ts 中新增对含 "./*": "./dist/cjs/*" 通配导出的 SDK 包的 peer 校验测试。

验证

  • npm test -- test/generation-installer.test.ts 全部 25 个测试用例通过。
  • npm run typecheck 干净通过。
  • git diff --check 无异常。

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