11import { promises as fs } from "fs" ;
2- import path from "path" ;
2+ import path , { dirname } from "path" ;
33import * as readline from "readline" ;
44import { type Client } from "@hey-api/client-fetch" ;
55import ora from "ora" ;
@@ -20,6 +20,7 @@ import {
2020import { getInferredApiKey } from "../../utils/constants" ;
2121import { hashDirectory } from "../utils/hash" ;
2222import { startVm } from "../../Sandboxes" ;
23+ import { mkdir , writeFile } from "fs/promises" ;
2324
2425export type BuildCommandArgs = {
2526 directory : string ;
@@ -35,6 +36,11 @@ export type BuildCommandArgs = {
3536 logPath ?: string ;
3637} ;
3738
39+ async function writeFileEnsureDir ( filePath , data ) {
40+ await mkdir ( dirname ( filePath ) , { recursive : true } ) ;
41+ await writeFile ( filePath , data ) ;
42+ }
43+
3844function stripAnsiCodes ( str : string ) {
3945 // Matches ESC [ params … finalChar
4046 // \x1B = ESC
@@ -172,11 +178,11 @@ export const buildCommand: yargs.CommandModule<
172178 const timestamp = new Date ( ) . toISOString ( ) . replace ( / : / g, "-" ) ;
173179 const logFilename = path . join (
174180 logPath ,
175- `setup-failure-${ step . name } -${ timestamp } .log`
181+ `setup-failure-${ sandbox . id } -${ timestamp } .log`
176182 ) ;
177183
178184 try {
179- await fs . writeFile ( logFilename , buffer . join ( "\n" ) ) ;
185+ await writeFileEnsureDir ( logFilename , buffer . join ( "\n" ) ) ;
180186 console . error ( `Log saved to: ${ logFilename } ` ) ;
181187 } catch ( writeError ) {
182188 console . error ( `Failed to write log file: ${ writeError } ` ) ;
0 commit comments