11#!/usr/bin/env node
22
33import { spawnSync } from 'node:child_process'
4+ import { buildPnpmCommand } from './pnpm-command.mjs'
45
56// Turbo 版 QA 编排器。
67// 这个入口把 workspace QA 拆成可缓存、可并行的任务链,优先服务速度和 affected 场景;
@@ -214,11 +215,14 @@ function hasPathChanges(pathspecs, sinceRef, ignorePatterns = []) {
214215function resolveTurboRunner ( ) {
215216 // 优先走 `pnpm exec turbo`,确保使用工作区锁定的版本;
216217 // 若外部环境已安装 turbo,则允许回退到全局命令,降低本地接入门槛。
218+ // 这里复用共享 pnpm 解析逻辑,避免 Windows 下把 pnpm 可执行文件交给错误的启动器。
219+ const pnpmTurboCommand = buildPnpmCommand ( [ 'exec' , 'turbo' ] )
220+ const pnpmTurboVersionCommand = buildPnpmCommand ( [ 'exec' , 'turbo' , '--version' ] )
217221 const candidates = [
218222 {
219- command : 'pnpm' ,
220- args : [ 'exec' , 'turbo' ] ,
221- versionArgs : [ 'exec' , 'turbo' , '--version' ] ,
223+ command : pnpmTurboCommand . command ,
224+ args : pnpmTurboCommand . args ,
225+ versionArgs : pnpmTurboVersionCommand . args ,
222226 } ,
223227 { command : 'turbo' , args : [ ] , versionArgs : [ '--version' ] } ,
224228 ]
@@ -242,10 +246,11 @@ function runWorkspaceQa(modeValue, sinceRef) {
242246 const turboRunner = resolveTurboRunner ( )
243247
244248 if ( ! turboRunner ) {
249+ const pnpmTurboVersionCommand = buildPnpmCommand ( [ 'exec' , 'turbo' , '--version' ] )
245250 throw new CommandFailedError (
246251 'workspace-turbo-not-found' ,
247- 'pnpm' ,
248- [ 'exec' , 'turbo' , '--version' ] ,
252+ pnpmTurboVersionCommand . command ,
253+ pnpmTurboVersionCommand . args ,
249254 1 ,
250255 new Error ( 'turbo command is not available' ) ,
251256 )
@@ -302,7 +307,8 @@ function runRootPwshQa(modeValue, sinceRef) {
302307 // 这样可以在享受 workspace 并行收益的同时,避免一次性重构根目录测试编排。
303308 if ( modeValue === 'all' ) {
304309 console . log ( '[turbo:qa] run root qa:pwsh (all)' )
305- runCommand ( 'root-qa-pwsh-all' , 'pnpm' , [ 'run' , 'qa:pwsh' ] )
310+ const pnpmCommand = buildPnpmCommand ( [ 'run' , 'qa:pwsh' ] )
311+ runCommand ( 'root-qa-pwsh-all' , pnpmCommand . command , pnpmCommand . args )
306312 return
307313 }
308314
@@ -321,7 +327,8 @@ function runRootPwshQa(modeValue, sinceRef) {
321327 }
322328
323329 console . log ( '[turbo:qa] run root qa:pwsh (changed)' )
324- runCommand ( 'root-qa-pwsh-changed' , 'pnpm' , [ 'run' , 'qa:pwsh' ] )
330+ const pnpmCommand = buildPnpmCommand ( [ 'run' , 'qa:pwsh' ] )
331+ runCommand ( 'root-qa-pwsh-changed' , pnpmCommand . command , pnpmCommand . args )
325332}
326333
327334const sinceRef = mode === 'changed' ? resolveSinceRef ( ) : null
0 commit comments