fix(build): strip-plugins 跨卷时静默失效,插件被打进安装包
Verify (Gitea) / gate (build · unit · facts) (push) Failing after 59s

Windows 构建机 TEMP 在 C:、仓库在 D:,rename 抛 EXDEV 后旧 fallback 只 unlink
第一层文件,子目录失败被 catch 吞掉、rmdir 也失败被吞,仍打印「已清空」,
四个目录插件(album/gallery/grouplib/promptlib)因此进了 v3.26.104-108 的 win 包。

现在:os.tmpdir → 同卷 src-tauri/target 二级降级 → 递归删除,末尾硬断言,
清不干净 exit 1;新增 tests/strip-plugins-test.js 覆盖两条路径与拦截路径。
This commit is contained in:
qiqi committed 2026-11-27 11:51:44 +08:00
1 parent 332e710481
commit 012fd0267c
4 files changed
+141 -19

No files matched your search

+58 -17
View File
@@ -3,26 +3,67 @@
// 桌面版打包前清掉 dist/plugins/:插件不再随应用发布,全部从市场安装到 <资料目录>/plugins/。
// 保留 plugins/ 目录本身是给 scripts/gen-market.js(市场产物)用的,不进安装包。
//
// 为什么用 rename 而不是 rmSync:build.js 开头已经 rmSync 过整个 dist(一次删 50+ 个文件),
// 为什么优先用 rename 而不是 rmSync:build.js 开头已经 rmSync 过整个 dist(一次删 50+ 个文件),
// 紧接着再递归删 dist/plugins 会撞上执行环境的「单轮批量删除」上限(threshold 50),
// 整个构建直接失败。rename 不产生删除操作,同样能让这个目录从打包路径里消失。
//
// v3.26.109 修:旧 fallback 只 unlink 目录第一层文件,子目录 unlink 全部失败又被 catch 吞掉,
// rmdir 因非空失败同样被吞,最后照样打印「已逐个清空」——静默失效。
// Windows 构建机 TEMP 在 C:、仓库在 D:,rename 必抛 EXDEV,于是目录插件被原样打进安装包
// (v3.26.104–108 的 win 包都带了 album/gallery/grouplib/promptlib 四个目录)。
// 现在:临时目录 → 仓库卷内的 target 二级降级 → 递归删除,末尾硬断言,清理不干净直接 exit 1。
const fs = require('fs')
const os = require('os')
const path = require('path')
const dir = path.resolve(__dirname, '..', 'dist', 'plugins')
if (fs.existsSync(dir)) {
const trash = path.join(os.tmpdir(), 'iwb-plugin-strip-' + Date.now())
try {
fs.renameSync(dir, trash)
console.log('[strip-plugins] 已移出 dist/plugins → ' + trash + '(插件改由市场安装)')
} catch (e) {
// 跨设备 rename 会 EXDEV:退回逐个删除(数量小,不触发批量上限)
for (const name of fs.readdirSync(dir)) {
try { fs.unlinkSync(path.join(dir, name)) } catch (e2) { /* 单个失败不影响打包 */ }
}
try { fs.rmdirSync(dir) } catch (e2) { /* 同上 */ }
console.log('[strip-plugins] 已逐个清空 dist/plugins(插件改由市场安装)')
}
} else {
console.log('[strip-plugins] dist/plugins 不存在,跳过')
const root = path.resolve(__dirname, '..')
const dir = path.join(root, 'dist', 'plugins')
function leftovers() {
try { return fs.readdirSync(dir) } catch (e) { return [] }
}
function cleanupThing(p) {
try { fs.rmSync(p, { recursive: true, force: true, maxRetries: 2 }) } catch (e) { /* 留在 target 里不影响打包 */ }
}
function main() {
if (!fs.existsSync(dir)) {
console.log('[strip-plugins] dist/plugins 不存在,跳过')
return
}
const stamp = Date.now()
// 同一卷内的降级目标:src-tauri/target 一定与仓库同卷,且不进安装包
const fallback = path.join(root, 'src-tauri', 'target', 'iwb-plugin-strip-' + stamp)
const targets = [path.join(os.tmpdir(), 'iwb-plugin-strip-' + stamp), fallback]
if (!process.env.IWB_STRIP_PLUGINS_FORCE_FALLBACK) {
for (const trash of targets) {
try {
fs.mkdirSync(path.dirname(trash), { recursive: true })
fs.renameSync(dir, trash)
cleanupThing(trash)
console.log('[strip-plugins] 已移出 dist/plugins → ' + trash + '(插件改由市场安装)')
verify()
return
} catch (e) { /* EXDEV / EPERM / EBUSY:换下一个目标 */ }
}
}
try {
fs.rmSync(dir, { recursive: true, force: true, maxRetries: 2 })
} catch (e) {
console.error('[strip-plugins] 递归删除失败:' + (e && e.code ? e.code : e))
}
if (!leftovers().length) console.log('[strip-plugins] 已递归删除 dist/plugins(插件改由市场安装)')
verify()
}
function verify() {
const rest = leftovers()
if (rest.length) {
console.error('[strip-plugins] 清理失败,dist/plugins 仍有 ' + rest.length + ' 项:' + rest.join(', '))
console.error('[strip-plugins] 拒绝带着插件继续打包(插件必须从市场安装)')
process.exit(1)
}
}
main()