Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
TimeBather opened this issue Oct 24, 2023 · 11 comments

Comments

@TimeBather
Copy link

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
Copy link
Contributor

CyanChanges commented Oct 24, 2023

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

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

@TimeBather
Copy link
Author

第一,这里是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
Copy link
Contributor

第一,这里是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
Copy link
Contributor

CyanChanges commented Oct 24, 2023

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

@CyanChanges
Copy link
Contributor

CyanChanges commented Oct 24, 2023

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

@shigma
Copy link
Member

shigma commented Oct 24, 2023

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

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

@TimeBather
Copy link
Author

TimeBather commented Oct 24, 2023

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

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

支持。

Sounds good!

Хорошо!

@CyanChanges
Copy link
Contributor

CyanChanges commented Oct 25, 2023

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

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

全部 Optional.png (非常合理

@shigma shigma transferred this issue from koishijs/koishi Nov 4, 2023
@shigma
Copy link
Member

shigma commented Nov 5, 2023

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

@shigma shigma closed this as completed in 7eeffe2 Nov 5, 2023
@MaikoTan
Copy link
Member

MaikoTan commented Nov 6, 2023

咦,我刚刚想到,现在可以声明 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
Copy link
Member

shigma commented Nov 6, 2023

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

CyanChanges pushed a commit to CyanForks/webui that referenced this issue Feb 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants