-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from benjamin-wilkins/spawn-stdio
Add stdio options to spawn
- Loading branch information
Showing
10 changed files
with
165 additions
and
101 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
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,34 @@ | ||
import { CurrentRuntime, Runtime } from "@cross/runtime"; | ||
|
||
import process from "node:process"; | ||
import { Readable, Writable } from "node:stream"; | ||
|
||
if (CurrentRuntime === Runtime.Bun) { | ||
// Bun has a bug in Writable.toWeb, so polyfill | ||
Writable.toWeb = (streamWritable) => { | ||
return new WritableStream({ | ||
write(chunk) { | ||
streamWritable.write(chunk); | ||
}, | ||
}); | ||
}; | ||
} | ||
|
||
/** | ||
* Get the stdin as a web-standard `ReadableStream` object. | ||
* @returns the stdin stream | ||
*/ | ||
// @ts-ignore Node has strange typings on Stream objects | ||
export const stdin = (): ReadableStream => Readable.toWeb(process.stdin); | ||
|
||
/** | ||
* Get the stdout as a web-standard `WritableStream` object. | ||
* @returns the stdout stream | ||
*/ | ||
export const stdout = (): WritableStream => Writable.toWeb(process.stdout); | ||
|
||
/** | ||
* Get the stderr as a web-standard `WritableStream` object. | ||
* @returns the stderr stream | ||
*/ | ||
export const stderr = (): WritableStream => Writable.toWeb(process.stderr); |
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