(
stream: fs.WriteStream,
options: { redactionPatterns: RegExp[]; includeTokens?: string[] },
)
| 24 | type LineWriter = { onChunk: (chunk: string) => void; flush: () => void }; |
| 25 | |
| 26 | export function createLineWriter( |
| 27 | stream: fs.WriteStream, |
| 28 | options: { redactionPatterns: RegExp[]; includeTokens?: string[] }, |
| 29 | ): LineWriter { |
| 30 | const includeTokens = options.includeTokens?.filter((token) => token.length > 0) ?? []; |
| 31 | let pending = ''; |
| 32 | |
| 33 | const writeLine = (line: string): void => { |
| 34 | if (includeTokens.length > 0) { |
| 35 | const shouldInclude = includeTokens.some((token) => line.includes(token)); |
| 36 | if (!shouldInclude) return; |
| 37 | } |
| 38 | stream.write(redactChunk(line, options.redactionPatterns)); |
| 39 | }; |
| 40 | |
| 41 | return { |
| 42 | onChunk: (chunk: string) => { |
| 43 | const combined = `${pending}${chunk}`; |
| 44 | const lines = combined.split('\n'); |
| 45 | pending = lines.pop() ?? ''; |
| 46 | for (const line of lines) { |
| 47 | writeLine(`${line}\n`); |
| 48 | } |
| 49 | }, |
| 50 | flush: () => { |
| 51 | if (!pending) return; |
| 52 | writeLine(pending); |
| 53 | pending = ''; |
| 54 | }, |
| 55 | }; |
| 56 | } |
| 57 | |
| 58 | type StreamableChildProcess = { |
| 59 | killed: boolean; |
no test coverage detected