Skip to content

Commit a3dae4a

Browse files
committed
chore: move readline logic after emitting ready event
1 parent cde0f75 commit a3dae4a

1 file changed

Lines changed: 13 additions & 11 deletions

File tree

packages/nuxi/src/dev/utils.ts

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -196,10 +196,6 @@ export class NuxtDevServer extends EventEmitter<DevServerEventMap> {
196196
this.#renderLoadingScreen(req, res)
197197
}
198198
}
199-
200-
if (hasTTY && !isCI) {
201-
this.#rl = readline.createInterface({ input: process.stdin })
202-
}
203199
}
204200

205201
async #renderLoadingScreen(req: IncomingMessage, res: ServerResponse): Promise<void> {
@@ -517,15 +513,24 @@ export class NuxtDevServer extends EventEmitter<DevServerEventMap> {
517513

518514
this.emit('ready', serverUrl)
519515

520-
this.#rl?.removeAllListeners('line')
521-
this.#rl?.addListener('line', this.#quitListener)
516+
if (!this.#rl && hasTTY && !isCI) {
517+
this.#rl = readline.createInterface({ input: process.stdin })
518+
}
519+
520+
if (this.#rl) {
521+
this.#rl.removeAllListeners('line')
522+
this.#rl.addListener('line', this.#quitListener.bind(this))
522523

523-
// eslint-disable-next-line no-console
524-
console.log(`\n${colors.dim(' press ')}${colors.bold(`q + enter`)}${colors.dim(` to quit`)}\n`)
524+
// eslint-disable-next-line no-console
525+
console.log(`\n${colors.dim(' press ')}${colors.bold(`q + enter`)}${colors.dim(` to quit`)}\n`)
526+
}
525527
}
526528

527529
async #quitListener(line: string) {
528530
if (line === 'q' || line === 'quit' || line === 'exit') {
531+
this.#rl?.removeAllListeners('line')
532+
this.#rl?.close()
533+
this.#rl = undefined
529534
try {
530535
await this.close()
531536
}
@@ -536,9 +541,6 @@ export class NuxtDevServer extends EventEmitter<DevServerEventMap> {
536541
}
537542

538543
async close(): Promise<void> {
539-
this.#rl?.removeAllListeners('line')
540-
this.#rl?.close()
541-
this.#rl = undefined
542544
if (this.#currentNuxt) {
543545
await this.#currentNuxt.close()
544546
}

0 commit comments

Comments
 (0)