MCPcopy
hub / github.com/vercel/next.js / CommandImpl

Class CommandImpl

turbopack/packages/devlow-bench/src/shell.ts:32–183  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

30const shellOutput = !!process.env.SHELL_OUTPUT
31
32class CommandImpl {
33 stdout: string = ''
34 stderr: string = ''
35 output: string = ''
36 outputCursor: number = 0
37 exitPromise: Promise<number>
38 waitingForOutput: (() => void)[] = []
39 constructor(private process: ChildProcess) {
40 process.stdout?.pipe(split2()).on('data', (data) => {
41 const str = data.toString()
42 this.stdout += str + '\n'
43 this.output += str + '\n'
44 if (shellOutput) {
45 console.log(`[STDOUT] ${str}`)
46 }
47 if (this.waitingForOutput.length !== 0) {
48 const waitingForOutput = this.waitingForOutput
49 this.waitingForOutput = []
50 for (const fn of waitingForOutput) {
51 fn()
52 }
53 }
54 })
55 process.stderr?.pipe(split2()).on('data', (data) => {
56 const str = data.toString()
57 this.stderr += str + '\n'
58 this.output += str + '\n'
59 if (shellOutput) {
60 console.log(`[STDERR] ${str}`)
61 }
62 if (this.waitingForOutput.length !== 0) {
63 const waitingForOutput = this.waitingForOutput
64 this.waitingForOutput = []
65 for (const fn of waitingForOutput) {
66 fn()
67 }
68 }
69 })
70 this.exitPromise = new Promise<number>((resolve, reject) => {
71 process.on('error', reject)
72 process.on('exit', resolve)
73 })
74 }
75
76 async ok() {
77 const exitCode = await this.exitPromise
78 if (exitCode !== 0) {
79 throw new Error(
80 `Command exited with code ${exitCode}\n\nOutput:\n${this.output}`
81 )
82 }
83 }
84
85 async end() {
86 return await this.exitPromise
87 }
88
89 async kill() {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected