(proc: cp.ChildProcess, callback: OnLineCallback)
| 28 | * Split stdout on newlines and strip ANSI codes. |
| 29 | */ |
| 30 | export const onLine = (proc: cp.ChildProcess, callback: OnLineCallback): void => { |
| 31 | let buffer = "" |
| 32 | if (!proc.stdout) { |
| 33 | throw new Error("no stdout") |
| 34 | } |
| 35 | proc.stdout.setEncoding("utf8") |
| 36 | proc.stdout.on("data", (d) => { |
| 37 | const data = buffer + d |
| 38 | const split = data.split("\n") |
| 39 | const last = split.length - 1 |
| 40 | |
| 41 | for (let i = 0; i < last; ++i) { |
| 42 | callback(split[i].replace(re, ""), split[i]) |
| 43 | } |
| 44 | |
| 45 | // The last item will either be an empty string (the data ended with a |
| 46 | // newline) or a partial line (did not end with a newline) and we must |
| 47 | // wait to parse it until we get a full line. |
| 48 | buffer = split[last] |
| 49 | }) |
| 50 | } |
| 51 | |
| 52 | export const paths = getEnvPaths() |
| 53 |
no outgoing calls
no test coverage detected