* Shuts down the `vercel dev` server, and cleans up any temporary resources.
(exitCode?: number)
| 1271 | * Shuts down the `vercel dev` server, and cleans up any temporary resources. |
| 1272 | */ |
| 1273 | async stop(exitCode?: number): Promise<void> { |
| 1274 | if (this.stopping) return; |
| 1275 | this.stopping = true; |
| 1276 | |
| 1277 | const { devProcess } = this; |
| 1278 | const { debug } = output; |
| 1279 | const ops: Promise<any>[] = []; |
| 1280 | |
| 1281 | for (const match of this.buildMatches.values()) { |
| 1282 | ops.push(shutdownBuilder(match)); |
| 1283 | } |
| 1284 | |
| 1285 | if (devProcess) { |
| 1286 | ops.push(treeKill(devProcess.pid!)); |
| 1287 | } |
| 1288 | |
| 1289 | if (this.orchestrator) { |
| 1290 | ops.push(this.orchestrator.stopAll()); |
| 1291 | } |
| 1292 | |
| 1293 | if (this.queueBroker) { |
| 1294 | this.queueBroker.stop(); |
| 1295 | } |
| 1296 | |
| 1297 | ops.push(close(this.server)); |
| 1298 | |
| 1299 | if (this.watcher) { |
| 1300 | debug(`Closing file watcher`); |
| 1301 | const closePromise = this.watcher.close(); |
| 1302 | if (closePromise) { |
| 1303 | ops.push(closePromise); |
| 1304 | } |
| 1305 | } |
| 1306 | |
| 1307 | for (const pid of this.shutdownCallbacks.keys()) { |
| 1308 | ops.push(this.killBuilderDevServer(pid)); |
| 1309 | } |
| 1310 | |
| 1311 | try { |
| 1312 | await Promise.all(ops); |
| 1313 | } catch (err: unknown) { |
| 1314 | if (isErrnoException(err) && err.code === 'ERR_SERVER_NOT_RUNNING') { |
| 1315 | process.exit(exitCode || 0); |
| 1316 | } else { |
| 1317 | throw err; |
| 1318 | } |
| 1319 | } |
| 1320 | } |
| 1321 | |
| 1322 | async killBuilderDevServer(pid: number) { |
| 1323 | const { debug } = output; |
no test coverage detected