@@ -2,6 +2,7 @@ import type { Readable, Writable } from 'node:stream';
22import { stripVTControlCharacters } from 'node:util' ;
33import { isCI } from 'std-env' ;
44import { type Options , exec } from 'tinyexec' ;
5+ import path from 'node:path' ;
56
67// Based on https://github.com/vitest-dev/vitest/blob/main/test/test-utils/index.ts
78
@@ -116,55 +117,44 @@ function isWritable(stream: any): stream is Writable {
116117 return stream && typeof stream ?. write === 'function' ;
117118}
118119
119- export async function runPubmCli (
120- command : string ,
121- _options ?: Partial < Options > ,
120+ export function runPubmCli (
121+ _options ?: Partial < Options > | string ,
122122 ...args : string [ ]
123- ) : Promise < {
123+ ) : {
124124 controller : CliController ;
125125 exitCode : number | undefined ;
126126 stdout : string ;
127127 stderr : string ;
128128 waitForClose : ( ) => Promise < unknown > ;
129- } > {
129+ } {
130130 let options = _options ;
131131
132132 if ( typeof _options === 'string' ) {
133133 args . unshift ( _options ) ;
134134 options = undefined ;
135135 }
136136
137- const subprocess = exec ( command , args , options as Options ) . process ;
137+ const subprocess = exec ( path . resolve ( import . meta . dirname , '../../bin/cli.js' ) , args , options as Options ) . process ! ;
138138 const controller = new CliController ( {
139139 // biome-ignore lint/style/noNonNullAssertion: <explanation>
140- stdin : subprocess ! . stdin ! ,
140+ stdin : subprocess . stdin ! ,
141141 // biome-ignore lint/style/noNonNullAssertion: <explanation>
142- stdout : subprocess ! . stdout ! ,
142+ stdout : subprocess . stdout ! ,
143143 // biome-ignore lint/style/noNonNullAssertion: <explanation>
144- stderr : subprocess ! . stderr ! ,
144+ stderr : subprocess . stderr ! ,
145145 } ) ;
146146
147- let setDone : ( value ?: unknown ) => void ;
148-
149147 const isDone = new Promise ( ( resolve ) => {
150- setDone = resolve ;
148+ subprocess ?. on ( 'exit' , resolve ) ;
151149 } ) ;
152150
153- subprocess ?. on ( 'exit' , ( ) => setDone ( ) ) ;
154-
155- function output ( ) {
156- return {
157- controller,
158- exitCode : subprocess ?. exitCode ?? undefined ,
159- stdout : controller . stdout || '' ,
160- stderr : controller . stderr || '' ,
161- waitForClose : ( ) => isDone ,
162- } ;
163- }
164-
165- await isDone ;
166-
167- return output ( ) ;
151+ return {
152+ controller,
153+ exitCode : subprocess ?. exitCode ?? undefined ,
154+ stdout : controller . stdout || '' ,
155+ stderr : controller . stderr || '' ,
156+ waitForClose : ( ) => isDone ,
157+ } ;
168158}
169159
170160export const DOWN = '\x1B\x5B\x42' ;
0 commit comments