diff --git a/vue.config.js b/vue.config.js index ab7d9ec..91f1f58 100644 --- a/vue.config.js +++ b/vue.config.js @@ -21,12 +21,18 @@ function _isProductionRelease() { * 生产构建门禁: 同步执行 test-gate.js, 失败立即终止构建 (零产物)。 * 与 package.json 的 "prebuild": "npm run test" 互补 —— 那条只覆盖 npm run build, * 本函数覆盖所有会 require vue.config.js 的入口 (HBuilderX / vue-cli-service / uni-cli)。 + * + * 关键: 使用 process.execPath 而非字符串 "node",避免依赖 PATH 查找 node。 + * 原因: HBuilderX 等 IDE 启动子进程时,PATH 中可能根本没有 node 条目 (本项目 + * 就曾因 Machine PATH 残留指向 v14.21.3 的 Huawei node 而触发问题)。 + * process.execPath 始终是"当前正在运行 vue.config.js 的那个 node 二进制", + * HBuilderX 自带 node (v22.22.2) ≥ 18,天然满足 test-gate 的版本要求。 */ function _enforceTestGate() { if (!_isProductionRelease()) return; // 开发态 / 运行态不拦截 - console.log('\n🛡️ [test-gate] 检测到生产构建,先执行测试门禁...'); + console.log(`\n🛡️ [test-gate] 检测到生产构建,先执行测试门禁 (${process.versions.node})...`); try { - execSync('node scripts/test-gate.js', { + execSync(`"${process.execPath}" scripts/test-gate.js`, { cwd: __dirname, stdio: 'inherit', });