独立(仓外)插件的前后端通信:Typert Remote 之外的正确做法是什么? #6062
|
背景
|
Replies: 3 comments 1 reply
|
结论先说:Typert Remote 不是"只能构建期 codegen"。 一、证据(0.1.5-alpha.1 线源码)
"exports": {
"./typert": { "types": "./lib/typert.host.d.ts", "default": "./lib/typert.host.js" },
"./remote": { "types": "./lib/typert.remote-client.d.ts", "default": "./lib/typert.remote-client.js" }
}生成产物导出的 二、推荐做法首选 Typert,三步:
不想引生成器也可以:手写 三、B 方案(
|
|
我看这个是不是也是在讨论这个问题
|
|
@zhang-guo-wen 你这个问题问得非常好——它正好问到了 DSH 双层能力模型(构建期 codegen 的 Remote vs 运行时可用的 webServer)的边界。我按你 Q1/Q2/Q3 逐一给源级结论(当前基线 0.1.5-alpha.1): Q1/Q3:Typert Remote 对仓外/独立插件是「构建期 codegen 专用」,没有运行时动态暴露你判断
一句话:Remote 路线要 codegen,仓外插件进不了构建期 → 走不通。 Q2:
|
结论先说:Typert Remote 不是"只能构建期 codegen"。
packages/api/remotes/src/client/index.ts里那份 namespace 数组是一等包的装配清单(把 14 个官方 namespace 挂到ctx.remote),不是"只有它们才能被调用"的白名单。仓外插件走同一套 Typert 通道完全可行,只是产物要自己生成、exports 要自己声明。一、证据(0.1.5-alpha.1 线源码)
TypertContribution = { package, face, schemas, model, invocations }(packages/typert/registry/src/types.ts),不依赖任何构建期全局状态。ctx.typert.register(contribution): TypertDisposer(packages/typert/registry/src/index.ts)。packages/typert/loader/src/index.ts的typert-loader跟随 Loader entry 挂载,解析该 entry 的package.json;只要它导出./typert,就 import 其 host 产物并ctx.typert.register(manifest),entry 卸载时撤销。解析锚点是ctx.baseUrl(cordis.yml所在目录),所以通过 …