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

未启用的plugin依旧会被scanner加载(compatibleRequire) #267

Open
niyan-ly opened this issue Dec 1, 2023 · 3 comments
Open

未启用的plugin依旧会被scanner加载(compatibleRequire) #267

niyan-ly opened this issue Dec 1, 2023 · 3 comments

Comments

@niyan-ly
Copy link

niyan-ly commented Dec 1, 2023

举例有以下目录结构, 通过artus scanner的envs配置在不同环境开关启用不同插件时, 发现其他插件虽然未启用, 但是对应目录下的文件依旧会被import, 引发一些冲突问题.

  • config/
    • plugin.gcp.ts
    • plugin.oracle.ts
    • plugin.aws.ts
  • plugin-google-cloud/
  • plugin-oracle-cloud/
  • plugin-aws/
@noahziheng
Copy link
Member

noahziheng commented Dec 3, 2023

这是因为 Scanner 的设计目前遵循 构建 - 运行两个阶段的逻辑:

  • 在构建阶段扫描出具有全量结果的 manifest.json
  • 在运行时通过 ARTUS_SERVER_ENV 环境变量来选择性 load 对应环境下已启用的插件内容

而同时因为基于装饰器的类定义模型,目前只能通过 require 实体的方式才能确定对应类的作用;

综上,目前的设计中需要保证插件及其内部类,在 require/import 阶段没有副作用,将依赖运行环境的代码放进类或方法中,通过 Lifecycle / IoC 等框架机制来管理和运行。

@niyan-ly
Copy link
Author

niyan-ly commented Dec 5, 2023

构建阶段我可以理解. 不过我目前遇到的问题是, 运行时阶段看起来只要在config目录下声明了的插件, 不管是否被启用(enable), 都会被import, 感觉不太合理

@noahziheng
Copy link
Member

运行时阶段是通过 app.load 加载生成好的 manifest,这个过程不会加载未启用的插件才对,只有 scan 才会出现全 import,而 scan 方法预期是在构建环境调的那个时候还没有 ENV

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

No branches or pull requests

2 participants