fix(plugin): 外置旧版本不再盖住内置升级(高版本胜)v3.25.44

真实事故:资料目录 plugins/ 残留 browser 1.6.0,内置已有 1.7.0,但合并规则是外置无条件覆盖
⇒ 设置里永远显示 1.6.0 且无更新入口。

- loader 新增 compareVersions(数字分段、缺段补 0)
- 合并规则:ext / 目录插件 只在版本 >= 当前时覆盖(同版本外置胜,允许本地打补丁)
- 新增 tests/plugin-loader-test.js(1.6<1.7 / 1.10>1.9 / 1.20.6>1.9.0 / 空版本)
This commit is contained in:
qiqi committed 2026-11-20 10:00:25 +08:00
1 parent f6e4441504
commit 3211beb706
8 files changed
+59 -7

No files matched your search

+15
View File
@@ -29,6 +29,20 @@
return global.btoa(bin) === expect
}
// 版本比较(v3.25.44):外置插件不再无条件覆盖内置 —— 高版本胜,同版本外置胜(允许本地打补丁)。
// 否则用户资料目录里残留的旧外置插件会永久盖住随包升级后的内置插件(browser 1.6.0 盖 1.7.0 的真实案例)。
function compareVersions (a, b) {
const pa = String(a || '0').split('.').map(function (x) { return parseInt(x, 10) || 0 })
const pb = String(b || '0').split('.').map(function (x) { return parseInt(x, 10) || 0 })
const n = Math.max(pa.length, pb.length)
for (let i = 0; i < n; i++) {
const x = pa[i] || 0
const y = pb[i] || 0
if (x !== y) return x > y ? 1 : -1
}
return 0
}
async function sha256Hex (text) {
const buf = await global.crypto.subtle.digest('SHA-256', new global.TextEncoder().encode(String(text)))
return Array.from(new Uint8Array(buf)).map(function (b) { return b.toString(16).padStart(2, '0') }).join('')
@@ -217,6 +231,7 @@
source: source,
verifyCode: verifyCode,
sha256Hex: sha256Hex,
compareVersions: compareVersions,
loadBuiltin: loadBuiltin,
loadExternal: loadExternal,
loadLocal: loadLocal,