import * as childProcess from 'child_process' ; import type { EventEmitter } from 'events' ; import * as util from 'util' ; const execa = util . promisify ( childProcess . exec ) ; interface OnceEmitter < T extends string , U extends any [ ] > { once ( name , listener ) : this ; } function oncea < T extends EventEmitter , U extends string > ( emitter , finish , error ? ) { return new Promise < T extends OnceEmitter < U , infer V > ? V : unknown [ ] > ( ( resolve , reject ) => { emitter . once ( finish , ( ... args ) => { resolve ( args ) ; } ) ; if ( error ) { emitter . once ( error , ( ... args ) => { reject ( args ) ; } ) ; } } ) ; } type IDIterator = ( id : number ) => number ; function createIDGenerator ( iterator ? ) { if ( ! iterator ) { iterator = id => id + 1 ; } let id = 0 ; return ( ) => { id = iterator ! ( id ) ; return id ; } ; } function createPattern ( expression ) { const matches = expression . match ( /^s\/(.+)\/([a-z]+)?$/ ) ; if ( ! matches ) return null ; try { return new RegExp ( matches [ 1 ] , matches [ 2 ] ) ; } catch { return null ; } } export { execa , oncea , createIDGenerator , createPattern , } ;