Skip to content

does not work with Node's stream.pipeline() built-in #1

Closed as not planned
@derhuerst

Description

@derhuerst

Initial checklist

Affected packages and versions

unified-stream@9, unified-stream@10

Link to runnable example

No response

Steps to reproduce

{
  "private": true,
  "name": "unified-stream-bug",
  "version": "1.0.0",
  "type": "module",
  "main": "index.js",
  "dependencies": {
    "rehype-format": "^4.0.1",
    "rehype-parse": "^8.0.4",
    "rehype-stringify": "^9.0.3",
    "unified": "^10.1.2",
    "unified-stream": "^2.0.0"
  }
}
// index.js
import {pipeline} from 'node:stream'
import {stream} from 'unified-stream'
import {unified} from 'unified'
import rehypeParse from 'rehype-parse'
import rehypeFormat from 'rehype-format'
import rehypeStringify from 'rehype-stringify'

pipeline(
  process.stdin,
  stream(
    unified()
    .use(rehypeParse)
    .use(rehypeFormat)
    .use(rehypeStringify)
  ),
  process.stdout,
  (err) => {
    if (!err) return;
    console.error(err)
    process.exit(1)
  },
)
echo -e 'foo\nbar' | node index.js

<html>
  <head></head>
  <body>
    foo
    bar
  </body>
</html>
file:///Users/j/playground/unified-stream-bug/node_modules/unified-stream/index.js:49
          throw new Error('Did not expect `write` after `end`')
          ^

Error: Did not expect `write` after `end`
    at write (file:///Users/j/playground/unified-stream-bug/node_modules/unified-stream/index.js:49:17)
    at EventEmitter.end (file:///Users/j/playground/unified-stream-bug/node_modules/unified-stream/index.js:90:9)
    at Socket.<anonymous> (node:internal/streams/pipeline:364:11)
    at Object.onceWrapper (node:events:627:28)
    at Socket.emit (node:events:525:35)
    at endReadableNT (node:internal/streams/readable:1359:12)
    at process.processTicksAndRejections (node:internal/process/task_queues:82:21)

Node.js v19.4.0

Expected behavior

As unified-stream (claims to?) returns a duplex Node stream, I would expect to be able to use it in combination with stream.pipeline().

Actual behavior

It fails with an error, see the reproduction steps.

Affected runtime and version

node@19.4.0

Affected package manager and version

No response

Affected OS and version

No response

Build and bundle tools

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    👀 no/externalThis makes more sense somewhere else👎 phase/noPost cannot or will not be acted on

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions