| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546 |
- /**
- * @vue-office/* 安装后须执行 lib/script/postinstall.js 生成 lib/index.js(Vue3 入口)。
- * pnpm 默认可能跳过依赖 lifecycle,导致 vite build 无法解析 @vue-office/pdf 等包。
- */
- import fs from 'node:fs'
- import path from 'node:path'
- import { spawnSync } from 'node:child_process'
- const root = process.cwd()
- const packages = ['pdf', 'docx', 'excel']
- let hadMissing = false
- for (const name of packages) {
- const pkgRoot = path.join(root, 'node_modules/@vue-office', name)
- const indexJs = path.join(pkgRoot, 'lib/index.js')
- const postinstall = path.join(pkgRoot, 'lib/script/postinstall.js')
- if (!fs.existsSync(postinstall)) {
- console.warn(`[setup-vue-office] 跳过 @vue-office/${name}:未找到 postinstall 脚本`)
- continue
- }
- if (!fs.existsSync(indexJs)) {
- hadMissing = true
- const result = spawnSync(process.execPath, [postinstall], {
- cwd: pkgRoot,
- stdio: 'inherit'
- })
- if (result.status !== 0) {
- console.error(`[setup-vue-office] @vue-office/${name} postinstall 失败`)
- process.exit(result.status ?? 1)
- }
- }
- if (!fs.existsSync(indexJs)) {
- console.error(`[setup-vue-office] @vue-office/${name} 仍缺少 lib/index.js`)
- process.exit(1)
- }
- }
- if (hadMissing) {
- console.log('[setup-vue-office] 已生成 @vue-office/* 的 lib/index.js(Vue3 入口)')
- } else {
- console.log('[setup-vue-office] @vue-office/* 入口文件已就绪')
- }
|