koishijs / webui

WebUI plugins for Koishi
https://koishi.online
GNU Affero General Public License v3.0
30 stars 15 forks source link

Feature: Service dependencies mismatch warnings between "package.json" and cordis "using" #241

Closed TimeBather closed 1 year ago

TimeBather commented 1 year ago

Describe the problem related to the feature request

自从Cordis 2.11,在插件中访问没有在"using"字段中定义的依赖会产生一个警告。我认为有必要检查package.json和"using"字段中定义的依赖的一致性,因为Koishi插件管理器会读取和展示package.json中的以来信息并在控制台展示,这对于使用插件的人来说很重要。

Since Cordis 2.11, access the dependencies which did not declared in the "using" field of the plugin will cause a warning. I think it's nesseary to check the consistency between the package.json and "using" field because the koishi plugin manager reads and displays them in the console page. It's important for user who using these plugins.

Describe the solution you'd like

无 None

Describe alternatives you've considered

无 None

Additional context

无 None

CyanChanges commented 1 year ago

你说的对,但是子插件怎么算,子插件可能不是在 apply 时加载,可能在其他事件发生时被 plugin,子插件不一定随着包的启用而启用,这将导致检测操作不准确,不确定,做这个检测是没有必要的

而且 package.json 中的 koishi 字段 仅适用于 koishijs/webui 中的 config 和 market 等浏览器端插件,cordis 如果要检查相关内容,则只能支持一种Plugin.Package(差不多是这个意思)类型的插件,如果要 Koishi 进行检查,将会引起很多不必要的 hook

TimeBather commented 1 year ago

第一,这里是Koishi项目的Issue,不是Cordis项目的Issue。所以我的想法是不会在Cordis内进行检查,而是由Cordis提供相关Event,由Koishi完成检查 其二,这个检查并不需要很多不必要的Hook,只需要增加一个internal/plugin事件和一个可继承的属性(用于存储包名)【可能可以作为一个包间独立的服务?】,在加载一个包时在上下文对象(Context)上写入一个包名。而在插件(包含子插件)加载并发出时internal/plugin检查。如果存在不一致则告警

First, this is a isuue for koishi repository , not for cordis , which means I think the checking process should implement in Koishi and cordis should provide some Events.
Secondly, it is not necessary to require many hooks. Only a "internal/plugin" event and a inheritable attribute to store the package name ( may be a service which isolating between packages ? ) . When we loading package , we attach package name to context. And when the plugin is loading, we will recieve "internal/plugin" event and we can check it.

CyanChanges commented 1 year ago

第一,这里是Koishi项目的Issue,不是Cordis项目的Issue。所以我的想法是不会在Cordis内进行检查,而是由Cordis提供相关Event,由Koishi完成检查 其二,这个检查并不需要很多不必要的Hook,只需要增加一个internal/plugin事件和一个可继承的属性(用于存储包名)【可能可以作为一个包间独立的服务?】,在加载一个包时在上下文对象(Context)上写入一个包名。而在插件(包含子插件)加载并发出时internal/plugin检查。如果存在不一致则告警

First, this is a isuue for koishi repository , not for cordis , which means I think the checking process should implement in Koishi and cordis should provide some Events. Secondly, it is not necessary to require many hooks. Only a "internal/plugin" event and a inheritable attribute to store the package name ( may be a service which isolating between packages ? ) . When we loading package , we attach package name to context. And when the plugin is loading, we will recieve "internal/plugin" event and we can check it.

所以没用到的服务不算了?(

CyanChanges commented 1 year ago

就怕每用一次服务都得 emit ( 整个 mount 什么的仅在首次调用的时候 mount 这个服务,然后后续都不用再跑一遍找服务什么的?(

CyanChanges commented 1 year ago

ctx.plugin beforeHook afterHook ctx.['service'] beforeHook ctx.lifecycle.* beforeHook afterHook Hook hook 你的(x

shigma commented 1 year ago

我的建议是检查包含关系,即:

TimeBather commented 1 year ago

我的建议是检查包含关系,即:

  • 如果在插件中声明了,但未在 package.json 中声明,则在控制台上提示
  • 如果反过来,则一切正常

支持。

Sounds good!

Хорошо!

CyanChanges commented 1 year ago

我的建议是检查包含关系,即:

  • 如果在插件中声明了,但未在 package.json 中声明,则在控制台上提示
  • 如果反过来,则一切正常

全部 Optional.png (非常合理

shigma commented 1 year ago

咦,我刚刚想到,现在可以声明 required 和 optional 的话,是不是没有必要在 package.json 中声明服务依赖了?

MaikoTan commented 1 year ago

咦,我刚刚想到,现在可以声明 required 和 optional 的话,是不是没有必要在 package.json 中声明服务依赖了?

I think it should be still required, since you don't have approaches to get the inject.required and inject.optional before installing a plugin.

我認爲它依舊是必要的,因爲在安裝插件之前你並沒有方法得到 inject.requiredinject.optional

shigma commented 1 year ago

安装插件之前也不需要这些数据吧……