Skip to content

Commit 2d6477d

Browse files
committed
feat: display time taken to start the HTTP server process
1 parent ff1a009 commit 2d6477d

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
"@swc/core": "1.3.82",
4545
"@types/node": "^20.4.5",
4646
"@types/picomatch": "^2.3.0",
47+
"@types/pretty-hrtime": "^1.0.1",
4748
"c8": "^8.0.1",
4849
"cross-env": "^7.0.3",
4950
"dedent": "^1.5.1",
@@ -68,6 +69,7 @@
6869
"get-port": "^7.0.0",
6970
"junk": "^4.0.1",
7071
"picomatch": "^2.3.1",
72+
"pretty-hrtime": "^1.0.3",
7173
"slash": "^5.1.0",
7274
"ts-morph": "^20.0.0"
7375
},

src/dev_server.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import type { Watcher } from '@poppinss/chokidar-ts'
1616
import type { DevServerOptions } from './types.js'
1717
import { AssetsDevServer } from './assets_dev_server.js'
1818
import { getPort, isDotEnvFile, isRcFile, runNode, watch } from './helpers.js'
19+
import prettyHrtime from 'pretty-hrtime'
1920

2021
/**
2122
* Instance of CLIUI
@@ -101,6 +102,7 @@ export class DevServer {
101102
* Starts the HTTP server
102103
*/
103104
#startHTTPServer(port: string, mode: 'blocking' | 'nonblocking') {
105+
let initialTime = process.hrtime()
104106
this.#httpServer = runNode(this.#cwd, {
105107
script: this.#scriptFile,
106108
env: { PORT: port, ...this.#options.env },
@@ -110,6 +112,8 @@ export class DevServer {
110112

111113
this.#httpServer.on('message', (message) => {
112114
if (this.#isAdonisJSReadyMessage(message)) {
115+
const readyAt = process.hrtime(initialTime)
116+
113117
ui.sticker()
114118
.useColors(this.#colors)
115119
.useRenderer(this.#logger.getRenderer())
@@ -119,6 +123,7 @@ export class DevServer {
119123
`${this.#isWatching ? 'enabled' : 'disabled'}`
120124
)}`
121125
)
126+
.add(`Ready in: ${this.#colors.cyan(prettyHrtime(readyAt))}`)
122127
.render()
123128
}
124129
})
@@ -129,13 +134,17 @@ export class DevServer {
129134
this.#onClose?.(result.exitCode)
130135
this.#watcher?.close()
131136
this.#assetsServer?.stop()
137+
} else {
138+
this.#logger.info('Underlying HTTP server closed. Still watching for changes')
132139
}
133140
})
134141
.catch((error) => {
135142
if (mode === 'nonblocking') {
136143
this.#onError?.(error)
137144
this.#watcher?.close()
138145
this.#assetsServer?.stop()
146+
} else {
147+
this.#logger.info('Underlying HTTP server died. Still watching for changes')
139148
}
140149
})
141150
}

0 commit comments

Comments
 (0)