1- import { spawn } from 'node:child_process' ;
1+ import { execSync , spawn } from 'node:child_process' ;
22import fs from 'node:fs' ;
3- import os from 'node:os' ;
43import path from 'node:path' ;
54import readline from 'node:readline' ;
65
76import { subscribeSpyTo } from '@hirez_io/observer-spy' ;
87import { sendCtrlC , spawnWithWrapper } from 'ctrlc-wrapper' ;
9- import { build } from 'esbuild' ;
108import Rx from 'rxjs' ;
119import { map } from 'rxjs/operators' ;
1210import stringArgv from 'string-argv' ;
13- import { afterAll , beforeAll , describe , expect , it } from 'vitest' ;
11+ import { beforeAll , describe , expect , it } from 'vitest' ;
1412
1513import { escapeRegExp } from '../lib/utils.js' ;
1614
@@ -24,37 +22,20 @@ const createKillMessage = (prefix: string, signal: 'SIGTERM' | 'SIGINT' | string
2422 return new RegExp ( `${ escapeRegExp ( prefix ) } exited with code ${ map [ signal ] ?? signal } ` ) ;
2523} ;
2624
27- let tmpDir : string ;
28-
29- beforeAll ( async ( ) => {
30- // Build 'concurrently' and store it in a temporary directory
31- tmpDir = fs . mkdtempSync ( path . join ( os . tmpdir ( ) , 'concurrently-' ) ) ;
32- await build ( {
33- entryPoints : [ path . join ( __dirname , 'index.ts' ) ] ,
34- platform : 'node' ,
35- bundle : true ,
36- // it doesn't seem like esbuild is able to change a CJS module to ESM, so target CJS instead.
37- // https://github.com/evanw/esbuild/issues/1921
38- format : 'cjs' ,
39- outfile : path . join ( tmpDir , 'concurrently.cjs' ) ,
40- } ) ;
41- fs . copyFileSync ( path . join ( __dirname , '..' , 'package.json' ) , path . join ( tmpDir , 'package.json' ) ) ;
42- } , 8000 ) ;
43-
44- afterAll ( ( ) => {
45- // Remove the temporary directory where 'concurrently' was stored
46- if ( tmpDir ) {
47- fs . rmSync ( tmpDir , { recursive : true } ) ;
48- }
49- } ) ;
25+ const concurrentlyBin = path . join ( __dirname , '..' , 'dist' , 'bin' , 'index.js' ) ;
26+
27+ // Build once, then spawn the real CLI without a shell (see open-cli-tools/concurrently#346).
28+ beforeAll ( ( ) => {
29+ execSync ( 'pnpm run build' , { cwd : path . join ( __dirname , '..' ) , stdio : 'pipe' } ) ;
30+ } , 20_000 ) ;
5031
5132/**
5233 * Creates a child process running 'concurrently' with the given args.
5334 * Returns observables for its combined stdout + stderr output, close events, pid, and stdin stream.
5435 */
5536const run = ( args : string , ctrlcWrapper ?: boolean ) => {
5637 const spawnFn = ctrlcWrapper ? spawnWithWrapper : spawn ;
57- const child = spawnFn ( 'node' , [ path . join ( tmpDir , 'concurrently.cjs' ) , ...stringArgv ( args ) ] , {
38+ const child = spawnFn ( 'node' , [ concurrentlyBin , ...stringArgv ( args ) ] , {
5839 cwd : __dirname ,
5940 env : {
6041 ...process . env ,
0 commit comments