Skip to content

Commit 5028bb0

Browse files
strip ansi codes
1 parent dd3c46a commit 5028bb0

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,6 @@
103103
"path": "^0.12.7",
104104
"react": "^18.3.1",
105105
"readline": "^1.3.0",
106-
"strip-ansi": "^7.1.0",
107106
"util": "^0.12.5",
108107
"yargs": "^17.7.2"
109108
}

src/bin/commands/build.ts

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { promises as fs } from "fs";
22
import path from "path";
3-
import stripAnsi from "strip-ansi";
43
import * as readline from "readline";
54
import { type Client } from "@hey-api/client-fetch";
65
import ora from "ora";
@@ -11,7 +10,6 @@ import { VMTier, CodeSandbox, Sandbox, SandboxClient } from "@codesandbox/sdk";
1110
import {
1211
templatesCreate,
1312
vmAssignTagAlias,
14-
vmCreateTag,
1513
VmUpdateSpecsRequest,
1614
} from "../../api-clients/client";
1715
import {
@@ -22,7 +20,6 @@ import {
2220
import { getInferredApiKey } from "../../utils/constants";
2321
import { hashDirectory } from "../utils/hash";
2422
import { startVm } from "../../Sandboxes";
25-
import { DisposableStore } from "../../utils/disposable";
2623

2724
export 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+
4149
export 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

Comments
 (0)