Skip to content

fix(console): 检查更新改原生 fetch 查 registry + 面板移入官方「插件」页子 tab - #16

Open
spacexun2 wants to merge 3 commits into
vlln:mainfrom
spacexun2:fix/console-version-check
Open

fix(console): 检查更新改原生 fetch 查 registry + 面板移入官方「插件」页子 tab#16
spacexun2 wants to merge 3 commits into
vlln:mainfrom
spacexun2:fix/console-version-check

Conversation

@spacexun2

Copy link
Copy Markdown

问题

面板「检查更新」在子进程管道捕获被拦截的环境与 Windows 上永远不出现可更新项、也无失败提示:/api/plugin-console/versions/refresh 返回全 latest: null(含 registry 上确有新版的包)。

npmViewLatest 根因(src/index.ts):

  1. spawnSync('npm', ['view', ...], { stdio: ['ignore','pipe','pipe'] }) 依赖子进程管道捕获输出——该环境拦截管道捕获(EPERM);Windows 下裸名 npm.cmd 垫片,spawnSync 不解析(ENOENT)。
  2. 失败被空 catch {} 静默折叠成 null,且照常写缓存 → UI 显示「已检查」,用户无法区分「已最新」「本地包」「检查失败」。

修复

Node half(新增 src/versions.ts):改为原生 fetch 查询 registry JSON API(GET <registry>/<name>/latest),零子进程,任何环境可工作:

  • 404 = 非 registry 包(git/link 依赖)→ latest: null, error: null
  • 非 404 HTTP 错误 / 网络错误 → error 带回响应并 ctx.logger.warn 记录,不再静默;
  • registry 根走 npm_config_registry,兼容镜像源;scoped 包名 / 编码 %2f

版本缓存记录 error;/versions/versions/refresh 响应每项新增 error 字段。

client half

  • 版本行三态:「已最新」「本地/非 registry」「检查失败(原因)」,失败行错误色;
  • 挂载点从顶层 settings.section(label「插件」)改为官方 settings.plugins.tab 子 tab(label「插件控制台」)——官方 settings-plugins 节已声明该插槽,第三方管理面板挂这里可避免设置页导航出现多个同名「插件」tab。

测试

  • 新增 tests/versions.spec.ts(mock fetch):200 / 404 / 非 404 / 网络错误 / 镜像源 / scoped 编码,7 用例;
  • 全套 41 项 node:test 通过。顺带修正 enumerate.spec.ts 在仓库迁移后过期的 owner 断言(URL 已迁 vlln 但断言仍写 dsh-external)——既有失败,与本次改动无关,一并修正使套件全绿;
  • 实机验证(已升级并验证):管道捕获被拦截的环境下旧链路 spawnSync 必败(EPERM)、新链路 fetch 返回 200;常规 Windows 宿主上旧实现因 .cmd 垫片同样全部 latest: null,新实现返回真实 registry 版本(registry 包),git/link 依赖包返回 nullerror: null

#8 的关系

#8(Windows spawn 兼容)同样改了 npmViewLatest(win32 走 node 直跑 npm-cli.js),但仍是 spawnSync + 管道,不解决管道拦截与静默失败。本 PR 用 fetch 重写该函数,与 #8runPnpm 部分(install/update/remove 仍需 pnpm CLI)互补、冲突极小。

关联 issue


注:恢复提交——原 #12 因 fork 重建(原 fork 已删除)无法重开,本 PR 为同分支、同内容的新提交;原 #12 保持关闭状态作为历史记录。

- npmViewLatest 不再 spawn npm(受限宿主管道捕获被拦 EPERM、Windows .cmd 垫片 ENOENT 均致静默 null)
- 404=非 registry 包(null 无 error);网络/HTTP 错误返回 error 并记日志,缓存含 error
- /versions 与 /versions/refresh 响应带 error 字段;面板区分「已最新/本地包/检查失败」三态
- client 挂载点 settings.section「插件」→ 官方 settings.plugins.tab 子 tab「插件控制台」(消除导航同名 tab)
- 新增 versions.spec.ts(mock fetch 200/404/非 404/网络错误/镜像源/scoped 编码),全套 41 测试通过
- 顺带修正 enumerate.spec.ts 仓库迁移后过期的 owner 断言(dsh-external→vlln)
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.

[Bug] 插件控制台「检查更新」永远无结果(registry 有新版也 latest:null,无失败提示)

1 participant