/** * 启动前校验:@fskj-admin/shell 必须来自私有 npm 且版本满足 package.json 声明的范围。 * 不做本地 platform-shell 兜底,缺包/版本不对时直接失败,便于团队暴露框架问题。 */ import fs from 'node:fs' import path from 'node:path' import { satisfies as semverSatisfies } from 'semver' const root = process.cwd() const pkgJson = JSON.parse(fs.readFileSync(path.join(root, 'package.json'), 'utf8')) const requiredSpec = pkgJson.dependencies?.['@fskj-admin/shell'] if (!requiredSpec) { console.error('[verify-shell] package.json 未声明 @fskj-admin/shell 依赖') process.exit(1) } const shellPkgPath = path.join(root, 'node_modules/@fskj-admin/shell/package.json') if (!fs.existsSync(shellPkgPath)) { console.error( '[verify-shell] 未安装 @fskj-admin/shell。请配置私有 npm 源后执行 pnpm install' ) process.exit(1) } const installedVersion = JSON.parse(fs.readFileSync(shellPkgPath, 'utf8')).version if (!semverSatisfies(installedVersion, requiredSpec, { includePrerelease: true })) { console.error( `[verify-shell] @fskj-admin/shell 版本不满足:package.json 要求 ${requiredSpec},node_modules 为 ${installedVersion}。请执行 pnpm install` ) process.exit(1) } const criticalFiles = [ 'src/constants/systemApplication.ts', 'src/stores/user.ts', 'src/components/core/GlobalHeader.vue' ] for (const rel of criticalFiles) { const abs = path.join(root, 'node_modules/@fskj-admin/shell', rel) if (!fs.existsSync(abs)) { console.error( `[verify-shell] @fskj-admin/shell@${installedVersion} 包不完整,缺少 ${rel}。请检查私有仓库发布或重新 install` ) process.exit(1) } } console.log(`[verify-shell] @fskj-admin/shell@${installedVersion} OK (satisfies ${requiredSpec})`)