|
4 | 4 | import * as fs from "node:fs"; |
5 | 5 | import { get } from "node:http"; |
6 | 6 |
|
7 | | -const REGISTRY_URL = process.argv[2] || "http://localhost:4873"; |
8 | | -const TIMEOUT_MS = Number(process.env.VERDACCIO_WAIT_TIMEOUT_MS || 60_000); |
9 | | -const POLL_MS = Number(process.env.VERDACCIO_WAIT_POLL_MS || 1_000); |
10 | | - |
11 | | -// Construct a ping URL that's supported by Verdaccio |
12 | | -const pingUrl = new URL(REGISTRY_URL); |
13 | | -// Ensure we hit the ping endpoint regardless of trailing slash |
14 | | -pingUrl.pathname = (pingUrl.pathname?.replace(/\/*$/, "") || "") + "/-/ping"; |
15 | | - |
16 | | -const deadline = Date.now() + TIMEOUT_MS; |
17 | | - |
18 | | -function dumpLogs() { |
19 | | - try { |
20 | | - // Verdaccio config logs to .ado/verdaccio/verdaccio.log |
21 | | - const logUrl = new URL("../verdaccio/verdaccio.log", import.meta.url); |
22 | | - const logFile = fs.readFileSync(logUrl, { encoding: "utf-8" }); |
23 | | - console.log("\n--- Verdaccio log ---\n" + logFile + "\n--- end log ---\n"); |
24 | | - } catch { |
25 | | - console.log("No Verdaccio log output yet."); |
26 | | - } |
27 | | -} |
28 | | - |
29 | | -function check() { |
30 | | - if (Date.now() > deadline) { |
31 | | - console.error(`Timed out waiting for Verdaccio at ${pingUrl.href}`); |
32 | | - dumpLogs(); |
33 | | - process.exit(1); |
34 | | - } |
35 | | - |
36 | | - get(pingUrl, res => { |
37 | | - if (res.statusCode === 200) { |
38 | | - console.log("Verdaccio is ready: " + pingUrl.href); |
39 | | - process.exit(0); |
40 | | - } else { |
41 | | - console.log(`Verdaccio status: ${res.statusCode}; retrying in ${POLL_MS}ms`); |
42 | | - setTimeout(check, POLL_MS); |
| 7 | +/** |
| 8 | + * @param {string} npmRegistryUrl |
| 9 | + */ |
| 10 | +function queryForServerStatus(npmRegistryUrl) { |
| 11 | + get(npmRegistryUrl, res => { |
| 12 | + console.log(`Verdaccio server status: ${res.statusCode}`); |
| 13 | + if (res.statusCode != 200) { |
| 14 | + setTimeout(queryForServerStatus, 2000); |
43 | 15 | } |
44 | 16 | }).on("error", err => { |
45 | | - console.log(`Verdaccio not ready (${err.message}); retrying in ${POLL_MS}ms`); |
46 | | - setTimeout(check, POLL_MS); |
| 17 | + console.log(err.message); |
| 18 | + const logUrl = new URL("../verdaccio/console.log", import.meta.url); |
| 19 | + try { |
| 20 | + const logFile = fs.readFileSync(logUrl, { encoding: "utf-8" }); |
| 21 | + console.log("Verdaccio console output: " + logFile); |
| 22 | + } catch (error) { |
| 23 | + console.log("No Verdaccio console output yet."); |
| 24 | + } |
| 25 | + setTimeout(queryForServerStatus, 2000); |
47 | 26 | }); |
48 | 27 | } |
49 | 28 |
|
50 | | -console.log(`Waiting for Verdaccio to respond at ${pingUrl.href} (timeout ${TIMEOUT_MS}ms)...`); |
51 | | -check(); |
| 29 | +console.log("Waiting for Verdaccio instance to respond..."); |
| 30 | + |
| 31 | +queryForServerStatus(process.argv[2]); |
0 commit comments