Skip to content

Fix: Prevent loading plugins with incompatible engine versions and add ignoreEngines option#571

Merged
ikenxuan merged 7 commits intomainfrom
copilot/fix-plugin-engine-compatibility
Oct 31, 2025
Merged

Fix: Prevent loading plugins with incompatible engine versions and add ignoreEngines option#571
ikenxuan merged 7 commits intomainfrom
copilot/fix-plugin-engine-compatibility

Conversation

Copy link
Contributor

Copilot AI commented Oct 20, 2025

Summary

Fixed the bug where plugins with incompatible engine versions would still execute their main entry file when installed via the web UI or API. Added option to force load plugins with version warnings.

Recent Fix (Latest Commit)

Fixed issue where ignoreEngines=true was not working correctly - plugins with version mismatches were not being loaded even when ignoreEngines was explicitly set to true.

Changes

  • Add version check in pkgLoads before loading main file
  • Add karin.ignoreEngines field to allow force loading with warnings
  • Update loading logic to check ignoreEngines flag
  • Output warning instead of error when force loading incompatible plugins
  • Fix logic to properly force load when ignoreEngines=true

Implementation Details

Version Check Logic

When a version mismatch is detected:

  1. ignoreEngines is undefined or false: Plugin is completely blocked (returns early)
  2. ignoreEngines is true: Sets isCompatible = true to force load the plugin with warning

This ensures only explicitly opted-in plugins (ignoreEngines: true) can bypass version checks.

Example Usage

{
  "name": "karin-plugin-example",
  "version": "1.0.0",
  "karin": {
    "engines": {
      "karin": "^2.0.0"
    },
    "ignoreEngines": true
  }
}

Behavior

Scenario 1: Compatible version

  • Plugin requires: ^1.0.0, Current: 1.5.0
  • Result: Loads normally ✓

Scenario 2: Incompatible WITHOUT ignoreEngines

  • Plugin requires: ^2.0.0, Current: 1.5.0, ignoreEngines: undefined
  • Result: Plugin blocked, main file NOT executed ✓

Scenario 3: Incompatible WITH ignoreEngines=true

  • Plugin requires: ^2.0.0, Current: 1.5.0, ignoreEngines: true
  • Result: Plugin loads with warning, main file IS executed ✓

Impact

  • Breaking Changes: None
  • Backward Compatible: ✅ Full
  • Fixes: Force loading now works correctly with ignoreEngines=true
Original prompt

This section details on the original issue you should resolve

<issue_title>Bug: 插件设置package.json engines 后不完全生效,启动karin仍然执行了入口文件</issue_title>
<issue_description>### 描述问题

https://karinjs.com/guide/plugins/package.html#%E9%85%8D%E7%BD%AE%E8%AF%B4%E6%98%8E

目前逻辑解析该字段后,若karin当前版本小于插件package.json engines的设定版本,则不会注册该插件,但仍然运行了package.json main 的入口文件。

复现步骤

  1. 第一步
  2. 第二步
  3. ...

预期行为

完全停止加载或忽略版本不匹配的插件。
或者在package.json karin 里面新增一个配置允许开发者设置当karin版本低于插件package.json engines时能强制加载插件。

实际行为

插件本体是停止加载了,命令也不响应,但是main入口的文件被执行了

操作系统

Ubuntu 24

Node.js 版本

22

项目版本

1.12.2

附加信息

No response</issue_description>

Comments on the Issue (you are @copilot in this section)

Fixes #570


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

…ugins

Adds engine version compatibility check in pkgLoads function before loading
the main entry file. This ensures that plugins with incompatible karin
versions are not loaded, even when called through hot-reload or install APIs.

The check validates pkg.karin.engines.karin or pkg.engines.karin against
the current KARIN_VERSION and returns early if the version doesn't match,
preventing the main file execution and plugin registration.

Fixes issue where pkgHotReload bypassed version checks during plugin installation.

Co-authored-by: sj817 <74231782+sj817@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix plugin engine behavior for version mismatch Fix: Prevent loading plugins with incompatible engine versions Oct 20, 2025
Copilot AI requested a review from sj817 October 20, 2025 15:22
@sj817
Copy link
Member

sj817 commented Oct 20, 2025

@copilot 给私有字段karin加个能忽略engines的选项,强制加载插件,但是继续输出警告日志。
与package.engines不一样哦。

…match

Added karin.ignoreEngines boolean field in package.json that allows plugins
to be force loaded even when engine version doesn't match. When enabled:
- Plugin continues to load despite version incompatibility
- Outputs warning log (instead of error) with details about version mismatch
- Only applies to karin.engines field, not package.engines

This allows plugin developers to explicitly opt-in to loading on incompatible
versions while still being warned about the incompatibility.

Co-authored-by: sj817 <74231782+sj817@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Oct 20, 2025

@copilot 给私有字段karin加个能忽略engines的选项,强制加载插件,但是继续输出警告日志。
与package.engines不一样哦。

已添加 karin.ignoreEngines 选项。设置为 true 时,即使版本不匹配也会强制加载插件,但会输出警告日志。这个选项只影响 karin.engines,不影响 package.engines

Changes in commit: 4c0a7c8

Copilot AI changed the title Fix: Prevent loading plugins with incompatible engine versions Fix: Prevent loading plugins with incompatible engine versions and add ignoreEngines option Oct 20, 2025
@sj817 sj817 requested review from ikenxuan and removed request for sj817 October 20, 2025 16:33
@sj817
Copy link
Member

sj817 commented Oct 21, 2025

@copilot karin.ingoreEngines true才强行加载

入口文件现在会被莫名其妙加载

Fixed issue where plugins with version mismatch were not being loaded even
when ignoreEngines was set to true. Now when ignoreEngines=true is explicitly
set, isCompatible is set to true to allow the main entry file to load.

Logic flow:
- No version requirement or version matches: loads normally
- Version mismatch + no ignoreEngines: blocked completely
- Version mismatch + ignoreEngines=true: force loads with warning

Co-authored-by: sj817 <74231782+sj817@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Oct 21, 2025

@copilot karin.ingoreEngines true才强行加载

入口文件现在会被莫名其妙加载

已修复。现在只有当 karin.ignoreEngines 明确设置为 true 时,才会强制加载版本不匹配的插件。修复了即使设置了 ignoreEngines=true 也不加载入口文件的问题。

逻辑流程:

  • 无版本要求或版本匹配:正常加载
  • 版本不匹配 + 未设置 ignoreEngines:完全阻止加载
  • 版本不匹配 + ignoreEngines=true:强制加载并输出警告

Changes in commit: e2f8e5b

Copilot AI requested a review from sj817 October 21, 2025 03:54
sj817 and others added 2 commits October 21, 2025 12:18
- 移除对 peerDependencies/dependencies/devDependencies 中 'node-karin' 的查找,仅使用 karin/engines 字段
- 简化版本范围处理(去掉 workspace:/link: 替换,改为 trim)
- 不再在发现不兼容但设置 ignoreEngines 时强制把 isCompatible 设为 true;改为引入 shouldLoad 标志:
  - 若不兼容且未设置 ignoreEngines,则终止加载(提前返回)
  - 若不兼容但设置 ignoreEngines,则保持 isCompatible = false,但仍允许加载插件并执行入口
- 调整入口文件执行条件:非 app 类型插件始终尝试执行入口(支持 ignoreEngines 强制加载场景)
@github-actions
Copy link
Contributor

你可以通过以下命令安装该版本:

pnpm add https://pkg.pr.new/node-karin@796f708 -w

@ikenxuan ikenxuan marked this pull request as ready for review October 31, 2025 10:49
@ikenxuan ikenxuan merged commit 33e3279 into main Oct 31, 2025
3 checks passed
@ikenxuan ikenxuan deleted the copilot/fix-plugin-engine-compatibility branch October 31, 2025 10:50
@github-actions github-actions bot mentioned this pull request Oct 31, 2025
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: 插件设置package.json engines 后不完全生效,启动karin仍然执行了入口文件

3 participants