import { resolve } from 'pathe' ; import fs from 'fs-extra' ; import fg from 'fast-glob' ; import execa from 'execa' ; export const cacheDir = resolve ( __dirname , '.cache' ) ; export const cli = resolve ( __dirname , '../src/node/cli.ts' ) ; export async function runCli ( files ) { const testDir = resolve ( cacheDir , Date . now ( ) . toString ( ) ) ; const getFileContent = ( filename ) => fs . readFile ( resolve ( testDir , filename ) , 'utf8' ) ; await Promise . all ( Object . entries ( files ) . map ( ( [ path , content ] ) => fs . outputFile ( resolve ( testDir , path ) , content , 'utf8' ) ) ) ; const { exitCode , stdout , stderr } = await execa ( 'npx' , [ 'esno' , cli , 'src/input.js' ] , { cwd : testDir } ) ; const logs = stdout + stderr ; if ( exitCode !== 0 ) { throw new Error ( logs ) ; } const output = await getFileContent ( 'index.js' ) ; const outFiles = await fg ( '**/*' , { cwd : testDir , ignore : [ 'src' ] } ) ; return { output , outFiles , logs , getFileContent } ; }