From 26d54f042b93660539ca1580b86e4bcdc97130c9 Mon Sep 17 00:00:00 2001 From: thzxx Date: Sun, 9 Aug 2026 16:52:17 +0800 Subject: [PATCH] =?UTF-8?q?chore:=20=E7=A7=BB=E9=99=A4=20rollup=20?= =?UTF-8?q?=E5=B9=B3=E5=8F=B0=E5=8C=85=20postinstall=20=E8=84=9A=E6=9C=AC?= =?UTF-8?q?=EF=BC=8C=E5=B9=B3=E5=8F=B0=E4=BE=9D=E8=B5=96=E6=8C=89=E9=9C=80?= =?UTF-8?q?=E6=89=8B=E5=8A=A8=E5=AE=89=E8=A3=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 3 +- scripts/ensure-rollup-platform.mjs | 55 ------------------------------ 2 files changed, 1 insertion(+), 57 deletions(-) delete mode 100644 scripts/ensure-rollup-platform.mjs diff --git a/package.json b/package.json index 467b2c8..107635e 100644 --- a/package.json +++ b/package.json @@ -14,8 +14,7 @@ "test": "vitest run", "test:watch": "vitest", "test:coverage": "vitest run --coverage", - "prepare": "husky", - "postinstall": "node scripts/ensure-rollup-platform.mjs" + "prepare": "husky" }, "lint-staged": { "*.{ts,tsx}": [ diff --git a/scripts/ensure-rollup-platform.mjs b/scripts/ensure-rollup-platform.mjs deleted file mode 100644 index 33c8dd1..0000000 --- a/scripts/ensure-rollup-platform.mjs +++ /dev/null @@ -1,55 +0,0 @@ -/** - * 确保 rollup 当前平台的 optional 原生包已安装。 - * - * 背景: npm bug #4828 导致跨平台共享 node_modules(如 WSL 与 Windows 挂载同一目录)时, - * 一方 npm install 可能清理掉另一方的 rollup 平台包(@rollup/rollup--x64-), - * 导致 build/test 报 "Cannot find module @rollup/rollup-"。 - * - * 方案: 在 postinstall 阶段检测当前平台所需的 rollup 原生包,缺失则自动补装 - * (--no-save 不污染依赖清单,--ignore-scripts 防止递归触发 postinstall)。 - */ -import { execSync } from 'child_process' -import { existsSync } from 'fs' -import { join, dirname } from 'path' -import { fileURLToPath } from 'url' - -const ROLLUP_VERSION = '4.60.4' -const __dirname = dirname(fileURLToPath(import.meta.url)) - -/** 平台 → 架构 → 对应 rollup 原生包 */ -const PLATFORM_PACKAGES = { - win32: { - x64: '@rollup/rollup-win32-x64-msvc', - ia32: '@rollup/rollup-win32-ia32-msvc', - arm64: '@rollup/rollup-win32-arm64-msvc', - }, - linux: { - x64: '@rollup/rollup-linux-x64-gnu', - arm64: '@rollup/rollup-linux-arm64-gnu', - arm: '@rollup/rollup-linux-arm-gnueabihf', - }, - darwin: { - x64: '@rollup/rollup-darwin-x64', - arm64: '@rollup/rollup-darwin-arm64', - }, -} - -const pkg = PLATFORM_PACKAGES[process.platform]?.[process.arch] -if (!pkg) { - process.exit(0) -} - -const pkgDir = join(__dirname, '..', 'node_modules', ...pkg.split('/')) -if (existsSync(pkgDir)) { - process.exit(0) -} - -try { - execSync(`npm install --no-save --ignore-scripts ${pkg}@${ROLLUP_VERSION}`, { - stdio: 'inherit', - cwd: join(__dirname, '..'), - }) -} catch (err) { - // eslint-disable-next-line no-console -- 安装失败仅告警,不阻断 npm install - console.warn(`[ensure-rollup-platform] 自动安装 ${pkg} 失败:`, err) -}