Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@ Typical usage:

```js
import { spawn } from 'node:child_process'
import split2 from 'split2'
import { createInterface } from 'node:readline'
import { Readable } from 'node:stream'
import listStream from 'list-stream'

spawn('bash', ['-c', 'git log'])
.stdout.pipe(split2()) // break up by newline characters
const { stdout } = spawn('bash', ['-c', 'git log'])

Readable.from(createInterface({ input: stdout, crlfDelay: Infinity })) // break up by newline characters
.pipe(commitStream('rvagg', 'commit-stream'))
.pipe(listStream.obj(onCommitList))

Expand Down
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@
"@semantic-release/git": "^11.0.0",
"conventional-changelog-conventionalcommits": "^9.3.1",
"list-stream": "^2.1.0",
"semantic-release": "^25.0.3",
"split2": "^4.2.0"
"semantic-release": "^25.0.3"
},
"release": {
"branches": [
Expand Down
18 changes: 12 additions & 6 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import commitStream from './commit-stream.js'
import { spawn, exec } from 'node:child_process'
import assert from 'node:assert/strict'
import nodeTest from 'node:test'
import split2 from 'split2'
import { createInterface } from 'node:readline'
import listStream from 'list-stream'
import { pipeline } from 'node:stream'
import { pipeline, Readable } from 'node:stream'

function test (name, fn) {
return nodeTest(name, (_, done) => fn({
Expand All @@ -21,6 +21,10 @@ function gitToList (t, gitCmd, user, repo, callback) {
repo = undefined
}
const child = spawn('bash', ['-c', gitCmd])
let pending = 2
const done = () => {
if (--pending === 0) setImmediate(t.end.bind(t))
}
let stderr = ''
child.stderr.setEncoding('utf8').on('data', (chunk) => { stderr += chunk })
child.on('error', (err) => {
Expand All @@ -29,13 +33,15 @@ function gitToList (t, gitCmd, user, repo, callback) {
child.on('close', (code) => {
t.strictEqual(stderr, '')
t.strictEqual(code, 0, 'exit code zero')
setImmediate(t.end.bind(t))
done()
})
pipeline(
child.stdout,
split2(),
Readable.from(createInterface({ input: child.stdout, crlfDelay: Infinity })),

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pipeline accepts async iterables so you shouldn't need the Readable.from

commitStream(user, repo),
listStream.obj(callback),
listStream.obj((err, list) => {
callback(err, list)
done()
}),
() => {}
)
}
Expand Down
Loading