11import { promises as fs } from "fs" ;
22import path from "path" ;
3- import stripAnsi from "strip-ansi" ;
43import * as readline from "readline" ;
54import { type Client } from "@hey-api/client-fetch" ;
65import ora from "ora" ;
@@ -11,7 +10,6 @@ import { VMTier, CodeSandbox, Sandbox, SandboxClient } from "@codesandbox/sdk";
1110import {
1211 templatesCreate ,
1312 vmAssignTagAlias ,
14- vmCreateTag ,
1513 VmUpdateSpecsRequest ,
1614} from "../../api-clients/client" ;
1715import {
@@ -22,7 +20,6 @@ import {
2220import { getInferredApiKey } from "../../utils/constants" ;
2321import { hashDirectory } from "../utils/hash" ;
2422import { startVm } from "../../Sandboxes" ;
25- import { DisposableStore } from "../../utils/disposable" ;
2623
2724export type BuildCommandArgs = {
2825 directory : string ;
@@ -38,6 +35,17 @@ export type BuildCommandArgs = {
3835 logPath ?: string ;
3936} ;
4037
38+ function stripAnsiCodes ( str : string ) {
39+ // Matches ESC [ params … finalChar
40+ // \x1B = ESC
41+ // \[ = literal “[”
42+ // [0-?]* = any parameter bytes (digits, ;, ?)
43+ // [ -/]* = any intermediate bytes (space through /)
44+ // [@-~] = final byte ( @ A–Z [ \ ] ^ _ ` a–z { | } ~ )
45+ const CSI_REGEX = / \x1B \[ [ 0 - ? ] * [ - / ] * [ @ - ~ ] / g;
46+ return str . replace ( CSI_REGEX , "" ) ;
47+ }
48+
4149export const buildCommand : yargs . CommandModule <
4250 Record < string , never > ,
4351 BuildCommandArgs
@@ -152,11 +160,11 @@ export const buildCommand: yargs.CommandModule<
152160 ) ;
153161
154162 step . onOutput ( ( output ) => {
155- buffer . push ( stripAnsi ( output ) ) ;
163+ buffer . push ( stripAnsiCodes ( output ) ) ;
156164 } ) ;
157165 const output = await step . open ( ) ;
158166
159- buffer . push ( ...output . split ( "\n" ) . map ( stripAnsi ) ) ;
167+ buffer . push ( ...output . split ( "\n" ) . map ( stripAnsiCodes ) ) ;
160168
161169 await step . waitUntilComplete ( ) ;
162170 } catch ( error ) {
0 commit comments