File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ /**
2+ * Adapt Bun's `FileSink` to a Web Streams `UnderlyingSink`. `FileSink` exposes
3+ * `write`/`end` (close + flush) but no `close`/`abort` matching the spec, so
4+ * `new WritableStream(fileSink)` would only work because of an undocumented
5+ * runtime `.close` alias. This adapter sticks to the documented `.end` API.
6+ *
7+ * @param {import('bun').FileSink } sink
8+ * @returns {UnderlyingSink }
9+ */
10+ const makeStdinSink = sink => ( {
11+ async write ( /** @type {any } */ chunk ) {
12+ await sink . write ( chunk ) ;
13+ } ,
14+ async close ( ) {
15+ await sink . end ( ) ;
16+ } ,
17+ async abort ( reason ) {
18+ await sink . end ( reason instanceof Error ? reason : new Error ( String ( reason ) ) ) ;
19+ }
20+ } ) ;
21+
122const sanitize = ( value , defaultValue = 'ignore' ) => {
223 switch ( value ) {
324 case 'pipe' :
@@ -47,10 +68,11 @@ class Subprocess {
4768 return code ;
4869 } ) ;
4970
50- // @ts -expect-error TODO: Bun's `FileSink` is not a Web Streams `UnderlyingSink` —
51- // `start`/`write` happen to line up but `close` does not (FileSink uses `end`),
52- // so closing this WritableStream won't signal EOF to the child process.
53- this . stdin = this . childProcess . stdin ? new WritableStream ( this . childProcess . stdin ) : null ;
71+ const stdinSink = this . childProcess . stdin ;
72+ this . stdin =
73+ stdinSink && typeof stdinSink !== 'number'
74+ ? new WritableStream ( makeStdinSink ( stdinSink ) )
75+ : null ;
5476 this . stdout = this . childProcess . stdout || null ;
5577 this . stderr = this . childProcess . stderr || null ;
5678 }
You can’t perform that action at this time.
0 commit comments