niucloud/uni-app/scripts/purge-core-addon-leaks.cjs
wangchen14709853322 5ed9a0ba81 v2.0-beta-20260626
v2框架公测版测试流程请看v2.0-beta.md
2026-07-01 12:25:30 +08:00

38 lines
1.2 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/**
* 清理 Core 产物中误打入的插件业务 chunk保留 bridge 分包页 addon-*-pages-*
*/
const fs = require('fs')
const path = require('path')
const { ROOT, listAddonKeys } = require('./addon-utils.cjs')
const CORE_ASSETS = path.join(ROOT, 'dist', '.core', 'h5', 'assets')
function isLeakedAddonChunk(name, addonKeys) {
if (!name.endsWith('.js') && !name.endsWith('.css')) return false
for (const key of addonKeys) {
const dashed = key.replace(/_/g, '-')
for (const slug of new Set([key, dashed])) {
if (name.startsWith(`addon-${slug}-`) && !name.includes('-pages-')) return true
if (name.includes(`addon-${slug}-`) && name.includes('-locale-')) return true
}
}
return false
}
function purge() {
if (!fs.existsSync(CORE_ASSETS)) {
console.log('[purge-core-addon-leaks] no core assets dir, skip')
return
}
const addonKeys = listAddonKeys()
let removed = 0
for (const name of fs.readdirSync(CORE_ASSETS)) {
if (!isLeakedAddonChunk(name, addonKeys)) continue
fs.rmSync(path.join(CORE_ASSETS, name), { force: true })
removed++
}
console.log(`[purge-core-addon-leaks] removed ${removed} leaked addon chunks from core`)
}
purge()