File tree Expand file tree Collapse file tree 3 files changed +27
-3
lines changed
Expand file tree Collapse file tree 3 files changed +27
-3
lines changed Original file line number Diff line number Diff line change @@ -80,14 +80,14 @@ export type Options = {
8080
8181export type Server = {
8282 /**
83- The [`subprocess.stderr `](https://nodejs.org/api/child_process.html#child_process_subprocess_stdout).
83+ The [`subprocess.stdout `](https://nodejs.org/api/child_process.html#child_process_subprocess_stdout).
8484 */
85- readonly stdout : NodeJS . WritableStream ;
85+ readonly stdout : NodeJS . ReadableStream ;
8686
8787 /**
8888 The [`subprocess.stderr`](https://nodejs.org/api/child_process.html#child_process_subprocess_stderr).
8989 */
90- readonly stderr : NodeJS . WritableStream ;
90+ readonly stderr : NodeJS . ReadableStream ;
9191
9292 /**
9393 The URL to the server.
Original file line number Diff line number Diff line change @@ -112,6 +112,17 @@ export default async function phpServer(options) {
112112 } ,
113113 } ) ;
114114
115+ // Drain stdout/stderr to prevent the child process from blocking if nothing reads them.
116+ // Users can still attach listeners on these streams as needed.
117+ // See https://github.com/sindresorhus/php-server/issues/6
118+ if ( subprocess . stdout ) {
119+ subprocess . stdout . resume ( ) ;
120+ }
121+
122+ if ( subprocess . stderr ) {
123+ subprocess . stderr . resume ( ) ;
124+ }
125+
115126 subprocess . ref ( ) ;
116127
117128 process . on ( 'exit' , ( ) => {
Original file line number Diff line number Diff line change 1+ import { test } from 'node:test' ;
2+ import assert from 'node:assert/strict' ;
3+ import phpServer from '../index.js' ;
4+
5+ test ( 'stdout/stderr are flowing to avoid blocking' , async ( ) => {
6+ const server = await phpServer ( { base : 'test/fixtures/200' } ) ;
7+ try {
8+ assert . equal ( server . stdout ?. readableFlowing , true ) ;
9+ assert . equal ( server . stderr ?. readableFlowing , true ) ;
10+ } finally {
11+ server . stop ( ) ;
12+ }
13+ } ) ;
You can’t perform that action at this time.
0 commit comments