Skip to content

Commit 1be3b92

Browse files
committed
feat: support debug mode
1 parent da10e50 commit 1be3b92

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

src/app-process.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { type ChildProcessWithoutNullStreams, spawn } from 'node:child_process'
1+
import { type ChildProcess, spawn } from 'node:child_process'
22
import { DeferredPromise } from '@open-draft/deferred-promise'
33
import { invariant } from '@epic-web/invariant'
44

@@ -11,7 +11,7 @@ export interface AppProcessOptions {
1111
export const kUrl = Symbol('kUrl')
1212

1313
export class AppProcess {
14-
private io?: ChildProcessWithoutNullStreams
14+
private io?: ChildProcess
1515
private controller: AbortController
1616
private [kUrl]?: URL
1717

@@ -30,7 +30,7 @@ export class AppProcess {
3030
return url
3131
}
3232

33-
public async launch(): Promise<ChildProcessWithoutNullStreams> {
33+
public async launch(): Promise<ChildProcess> {
3434
const [command, ...args] = this.options.command.split(' ')
3535

3636
invariant(

src/define-launcher.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { ChildProcessWithoutNullStreams } from 'node:child_process'
1+
import type { ChildProcess } from 'node:child_process'
22
import { AppProcess, kUrl } from './app-process.js'
33
import { waitForPort } from './wait-for-port.js'
44

@@ -10,6 +10,11 @@ export interface DefineLauncherOptions<Context> {
1010
*/
1111
extends?: Launcher
1212

13+
/**
14+
* Run the launcher in debug mode.
15+
*/
16+
debug?: boolean
17+
1318
/**
1419
* Define a context object exposed to the other launcher methods.
1520
*
@@ -66,7 +71,7 @@ export interface DefineLauncherOptions<Context> {
6671
url: (options: {
6772
context: Context
6873
env: Record<string, string>
69-
appProcess: ChildProcessWithoutNullStreams
74+
appProcess: ChildProcess
7075
}) => string | URL | Promise<string | URL>
7176
}
7277

@@ -108,6 +113,11 @@ export function defineLauncher<Context>(
108113
})
109114
const childProcess = await app.launch()
110115

116+
if (options?.debug) {
117+
childProcess.stdout?.pipe(process.stdout)
118+
childProcess.stderr?.pipe(process.stderr)
119+
}
120+
111121
// Wait for the provided application URL to be up.
112122
const url = await options.url({
113123
context,

0 commit comments

Comments
 (0)