-
Notifications
You must be signed in to change notification settings - Fork 566
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: write dep-graph payloads to stdout stream
- Loading branch information
1 parent
60c2939
commit c6a175d
Showing
7 changed files
with
135 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { Readable } from 'stream'; | ||
|
||
export class ConcatStream extends Readable { | ||
private current: Readable | undefined; | ||
private queue: Readable[] = []; | ||
|
||
constructor(...streams: Readable[]) { | ||
super({ objectMode: false }); // Adjust objectMode if needed | ||
this.queue.push(...streams); | ||
} | ||
|
||
append(...streams: Readable[]): void { | ||
this.queue.push(...streams); | ||
if (!this.current) { | ||
this._read(); | ||
} | ||
} | ||
|
||
_read(size?: number): void { | ||
if (this.current) { | ||
return; | ||
} | ||
|
||
this.current = this.queue.shift(); | ||
if (!this.current) { | ||
this.push(null); | ||
return; | ||
} | ||
|
||
this.current.on('data', (chunk) => this.push(chunk)); | ||
this.current.on('end', () => { | ||
this.current = undefined; | ||
this._read(size); | ||
}); | ||
this.current.on('error', (err) => this.emit('error', err)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { Readable, Writable } from 'stream'; | ||
|
||
import { ConcatStream } from '../../../../src/lib/stream'; | ||
|
||
describe('ConcatStream', () => { | ||
it('should create a readable stream', () => { | ||
const stream = new ConcatStream(); | ||
|
||
expect(stream).toBeInstanceOf(Readable); | ||
}); | ||
|
||
it('should concatenate readable streams', async () => { | ||
const stream = new ConcatStream(); | ||
const chunks = jest.fn(); | ||
const out = new Writable({ | ||
write: (chunk, enc, done) => { | ||
chunks(chunk.toString()); | ||
done(); | ||
}, | ||
}); | ||
|
||
stream.append(Readable.from('foo'), Readable.from('bar')); | ||
|
||
await new Promise((res) => { | ||
stream.pipe(out).on('finish', res); | ||
}); | ||
|
||
expect(chunks).toHaveBeenCalledWith('foo'); | ||
expect(chunks).toHaveBeenCalledWith('bar'); | ||
}); | ||
}); |