11import { cpus } from 'os'
22import pLimit from 'p-limit'
33import { spawn } from './spawn.js'
4- import { getRunArgs } from './args.js'
4+ import { getArgs } from './args.js'
55
66/**
77 * Run package manager scripts serial.
88 * @param {string } pm
99 * @param {string[][] } scripts
10+ * @param {{ scripts?: Record<string, string> } } pkg - package.json
1011 * @returns Exit code
1112 */
12- export async function runSerial ( pm , scripts ) {
13- const pmScripts = scripts . map ( script => getRunArgs ( pm , script ) )
13+ export async function runSerial ( pm , scripts , pkg ) {
14+ const cmds = scripts . map ( script => getArgs ( pm , script , pkg ) )
1415 let exitCode = 0
1516
16- for ( const pmScript of pmScripts ) {
17- exitCode = exitCode || ( await spawn ( pm , pmScript ) ) . exitCode
17+ for ( const [ bin , args ] of cmds ) {
18+ exitCode = exitCode || ( await spawn ( bin , args ) ) . exitCode
1819 }
1920
2021 return exitCode
@@ -24,12 +25,13 @@ export async function runSerial(pm, scripts) {
2425 * Run package manager scripts parallel.
2526 * @param {string } pm
2627 * @param {string[][] } scripts
28+ * @param {{ scripts?: Record<string, string> } } pkg - package.json
2729 * @returns Exit code.
2830 */
29- export async function runParallel ( pm , scripts ) {
31+ export async function runParallel ( pm , scripts , pkg ) {
3032 const limit = pLimit ( cpus ( ) . length )
31- const pmScripts = scripts . map ( script => getRunArgs ( pm , script ) )
32- const tasks = pmScripts . map ( pmScript => limit ( ( ) => spawn ( pm , pmScript , false ) ) )
33+ const cmds = scripts . map ( script => getArgs ( pm , script , pkg ) )
34+ const tasks = cmds . map ( ( [ bin , args ] ) => limit ( ( ) => spawn ( bin , args , false ) ) )
3335 let exitCode = 0
3436 /** @type {{ exitCode: number, output?: string | Error } } */
3537 let result
0 commit comments