@hansenexus/hud 0.4.0 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +603 -9
- package/dist/a11y-B5DUaiCs.js +246 -0
- package/dist/a11y-panel-p_t4eD7p.js +207 -0
- package/dist/{capabilities-CjulXFQX.js → access-C7zlaqj6.js} +1 -90
- package/dist/{access-CNvJOwKM.d.ts → access-D_ewAEJG.d.ts} +11 -4
- package/dist/access-panel-CEfTr9ZI.js +123 -0
- package/dist/adapter-BYoxPYTI.d.ts +33 -0
- package/dist/adapter-hcwmJtNx.js +65 -0
- package/dist/auto/runtime.d.ts +65 -0
- package/dist/auto/runtime.js +50 -0
- package/dist/auto.d.ts +15 -0
- package/dist/auto.js +33 -0
- package/dist/capabilities-rDSKjXpq.js +110 -0
- package/dist/capture-CwrIwLqi.js +300 -0
- package/dist/capture-buffer-Bbbo6omF.d.ts +35 -0
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +275 -0
- package/dist/data-panel-DhxAmP91.js +817 -0
- package/dist/data-store-ChF1td_P.js +164 -0
- package/dist/define-hud-CHPedaQ5.d.ts +50 -0
- package/dist/design-D0kGgPoP.js +87 -0
- package/dist/detect-BxHZ0pxW.d.ts +25 -0
- package/dist/detect-CHZiSeZs.js +63 -0
- package/dist/dispatch-panel-B-xr_Giy.js +279 -0
- package/dist/{env-vEjyJfPW.d.ts → env-CApnbI0r.d.ts} +2 -0
- package/dist/{env-DfxpPfs9.js → env-CaiFPIhF.js} +3 -0
- package/dist/file-xdSaQ2uR.js +103 -0
- package/dist/flags-DVtaJ8pQ.d.ts +58 -0
- package/dist/flags.d.ts +2 -0
- package/dist/flags.js +82 -0
- package/dist/force-state-panel-_otVYh9i.js +97 -0
- package/dist/generate-C8lQl3Eh.js +53 -0
- package/dist/handler-BpVhxEmU.js +106 -0
- package/dist/{handler-WmE4Lu7l.d.ts → handler-DtYVCZY6.d.ts} +1 -1
- package/dist/index-BAV_1W8a.d.ts +43 -0
- package/dist/index-BJ26pse9.d.ts +70 -0
- package/dist/index-BnQ0dTZf.d.ts +19 -0
- package/dist/index-CwfX-W87.d.ts +72 -0
- package/dist/index-DcH9V3cU.d.ts +48 -0
- package/dist/index-DqOyNf1u.d.ts +65 -0
- package/dist/index-DstI_ike.d.ts +66 -0
- package/dist/index-Dxz4fn4j.d.ts +42 -0
- package/dist/index-Hhh7OXzU.d.ts +129 -0
- package/dist/index-ReFbhQ9p.d.ts +25 -0
- package/dist/index-RgXfMBuW.d.ts +48 -0
- package/dist/{index-BYsdS-7d.d.ts → index-gCZBO53s.d.ts} +21 -3
- package/dist/index.d.ts +5 -5
- package/dist/index.js +710 -69
- package/dist/inspect-C9Ft8fqn.js +142 -0
- package/dist/inspect-root-BkaupBMp.js +429 -0
- package/dist/meta-Bv0sEao3.js +6 -0
- package/dist/meta-C_G7MB5w.d.ts +49 -0
- package/dist/mocks-CA-wM2SB.d.ts +109 -0
- package/dist/mocks-ESiRqk9o.js +150 -0
- package/dist/msw-browser-wjaYgkB7.d.ts +31 -0
- package/dist/next/config.d.ts +52 -0
- package/dist/next/config.js +78 -0
- package/dist/next.d.ts +14 -4
- package/dist/next.js +5 -3
- package/dist/observe-CdDnDBRP.js +89 -0
- package/dist/observe-panel-Cgp1M8oT.js +347 -0
- package/dist/ops-panel-CEqDe_UT.js +234 -0
- package/dist/{payload-CLKDVZWl.d.ts → payload-MUQ9ciER.d.ts} +25 -1
- package/dist/plugins/a11y.d.ts +2 -0
- package/dist/plugins/a11y.js +2 -0
- package/dist/plugins/access/server.d.ts +5 -5
- package/dist/plugins/access/server.js +4 -3
- package/dist/plugins/access.d.ts +5 -5
- package/dist/plugins/access.js +16 -215
- package/dist/plugins/agent/server.d.ts +3 -38
- package/dist/plugins/agent/server.js +47 -21
- package/dist/plugins/agent.d.ts +4 -4
- package/dist/plugins/agent.js +6 -348
- package/dist/plugins/capture/server.d.ts +92 -0
- package/dist/plugins/capture/server.js +248 -0
- package/dist/plugins/capture.d.ts +24 -0
- package/dist/plugins/capture.js +70 -0
- package/dist/plugins/data/msw-browser.d.ts +2 -0
- package/dist/plugins/data/msw-browser.js +39 -0
- package/dist/plugins/data/msw-node.d.ts +36 -0
- package/dist/plugins/data/msw-node.js +68 -0
- package/dist/plugins/data/server.d.ts +257 -0
- package/dist/plugins/data/server.js +717 -0
- package/dist/plugins/data.d.ts +6 -0
- package/dist/plugins/data.js +51 -0
- package/dist/plugins/design/server.d.ts +54 -0
- package/dist/plugins/design/server.js +198 -0
- package/dist/plugins/design.d.ts +4 -124
- package/dist/plugins/design.js +4 -619
- package/dist/plugins/inspect/convex.d.ts +2 -0
- package/dist/plugins/inspect/convex.js +486 -0
- package/dist/plugins/inspect/react-query.d.ts +2 -0
- package/dist/plugins/inspect/react-query.js +225 -0
- package/dist/plugins/inspect/sockets.d.ts +51 -0
- package/dist/plugins/inspect/sockets.js +397 -0
- package/dist/plugins/inspect/swr.d.ts +2 -0
- package/dist/plugins/inspect/swr.js +218 -0
- package/dist/plugins/inspect.d.ts +4 -0
- package/dist/plugins/inspect.js +3 -0
- package/dist/plugins/observe.d.ts +4 -64
- package/dist/plugins/observe.js +1 -616
- package/dist/plugins/ops/server.d.ts +1 -1
- package/dist/plugins/ops/server.js +2 -1
- package/dist/plugins/ops.d.ts +2 -1
- package/dist/plugins/ops.js +15 -336
- package/dist/plugins/routes/server.d.ts +88 -0
- package/dist/plugins/routes/server.js +62 -0
- package/dist/plugins/routes.d.ts +3 -0
- package/dist/plugins/routes.js +216 -0
- package/dist/plugins/seo.d.ts +2 -0
- package/dist/plugins/seo.js +2 -0
- package/dist/plugins/vitals.d.ts +2 -25
- package/dist/plugins/vitals.js +3 -2
- package/dist/{plugins-CQ_0w1ot.d.ts → plugins-BZvDqGx5.d.ts} +33 -3
- package/dist/poll-CjKsWZi8.js +89 -0
- package/dist/requests-BwD6MKEq.js +282 -0
- package/dist/requests-CJrUf465.d.ts +50 -0
- package/dist/review.js +2 -2
- package/dist/same-origin-BGet22CC.js +21 -0
- package/dist/scan-DzJNXqOk.js +165 -0
- package/dist/seo-Dq9q_QkO.js +551 -0
- package/dist/seo-panel-CfiY-TnT.js +124 -0
- package/dist/server.d.ts +2 -2
- package/dist/server.js +2 -105
- package/dist/sessions-panel-COvhPAzv.js +98 -0
- package/dist/{shortcut-U6ftVY06.js → shortcut-s_mjGeU8.js} +1 -44
- package/dist/{types-QJUajwWq.js → state-CjjZPjPJ.js} +13 -8
- package/dist/store/convex.d.ts +33 -0
- package/dist/store/convex.js +52 -0
- package/dist/{vitals-panel-Dvc5dnR-.js → store-CQqIIKTc.js} +1 -29
- package/dist/store-Ync9eb1G.js +67 -0
- package/dist/store.d.ts +76 -0
- package/dist/store.js +188 -0
- package/dist/{styles--slk86ZQ.js → styles-BA8ueHoV.js} +13 -3
- package/dist/styles-DKU_P8MH.js +139 -0
- package/dist/styles-DPpDPmzi.js +68 -0
- package/dist/tokens-panel-CbMQfasZ.js +142 -0
- package/dist/types-B-ulf2Jp.js +8 -0
- package/dist/types-BIgGf-0C.d.ts +25 -0
- package/dist/types-BIkI-qN8.js +30 -0
- package/dist/{types-DADBRiGk.d.ts → types-Cxh4twqc.d.ts} +1 -1
- package/dist/types-DIdPfjtV.js +6 -0
- package/dist/types-DaJcsEjO.d.ts +44 -0
- package/dist/types-Dn68psVz.d.ts +118 -0
- package/dist/types-szkr2QOF.d.ts +39 -0
- package/dist/unlock-store-4V3vR4Eg.js +96 -0
- package/dist/variant-groups-TIfO3NIj.js +137 -0
- package/dist/variant-groups-aAIrcNK5.d.ts +36 -0
- package/dist/variants-panel-BDoSkwBJ.js +457 -0
- package/dist/variants-types-CcRf119M.d.ts +63 -0
- package/dist/variants.d.ts +43 -0
- package/dist/variants.js +83 -0
- package/dist/vitals-panel-BCmMUntW.js +30 -0
- package/dist/vite.d.ts +37 -0
- package/dist/vite.js +134 -0
- package/package.json +65 -5
- package/dist/define-hud-BBzsSl8b.d.ts +0 -36
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
//#region src/plugins/observe/capture-buffer.d.ts
|
|
2
|
+
type CaptureKind = "log" | "warn" | "error" | "fetch" | "xhr" | "longtask";
|
|
3
|
+
interface Stamped {
|
|
4
|
+
id: number;
|
|
5
|
+
ts: number;
|
|
6
|
+
}
|
|
7
|
+
interface CaptureEntryInput {
|
|
8
|
+
kind: CaptureKind;
|
|
9
|
+
text: string;
|
|
10
|
+
status?: number;
|
|
11
|
+
durationMs?: number;
|
|
12
|
+
}
|
|
13
|
+
interface CaptureEntry extends CaptureEntryInput, Stamped {}
|
|
14
|
+
/**
|
|
15
|
+
* Fixed-size ring buffer with a referentially-stable snapshot, shaped for
|
|
16
|
+
* `useSyncExternalStore`: the snapshot array is replaced on every mutation
|
|
17
|
+
* and reused between mutations. Entries get an increasing `id` and a `ts`.
|
|
18
|
+
*/
|
|
19
|
+
declare class RingBuffer<Input extends object> {
|
|
20
|
+
private entries;
|
|
21
|
+
private snapshot;
|
|
22
|
+
private listeners;
|
|
23
|
+
private nextId;
|
|
24
|
+
private readonly maxEntries;
|
|
25
|
+
constructor(maxEntries?: number);
|
|
26
|
+
push(input: Input): Input & Stamped;
|
|
27
|
+
/** Merges `patch` into the entry with `id`; a no-op once the ring has dropped it. */
|
|
28
|
+
update(id: number, patch: Partial<Input>): void;
|
|
29
|
+
clear(): void;
|
|
30
|
+
getSnapshot: () => readonly (Input & Stamped)[];
|
|
31
|
+
subscribe: (listener: () => void) => (() => void);
|
|
32
|
+
private emit;
|
|
33
|
+
}
|
|
34
|
+
//#endregion
|
|
35
|
+
export { Stamped as i, CaptureKind as n, RingBuffer as r, CaptureEntry as t };
|
package/dist/cli.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {}
|
package/dist/cli.js
ADDED
|
@@ -0,0 +1,275 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { r as isExcluded } from "./scan-DzJNXqOk.js";
|
|
3
|
+
//#region src/plugins/routes/sweep.ts
|
|
4
|
+
/** Console errors every dev server produces that never mean a broken page. */
|
|
5
|
+
const DEFAULT_CONSOLE_IGNORE = [
|
|
6
|
+
/favicon\.ico/i,
|
|
7
|
+
/Download the React DevTools/i,
|
|
8
|
+
/\[Fast Refresh\]/i
|
|
9
|
+
];
|
|
10
|
+
const PLAYWRIGHT_MODULES = [
|
|
11
|
+
"playwright",
|
|
12
|
+
"@playwright/test",
|
|
13
|
+
"playwright-core"
|
|
14
|
+
];
|
|
15
|
+
/** Whichever Playwright package the app has; `@playwright/test` re-exports `chromium`. */
|
|
16
|
+
async function loadPlaywright(importer = (specifier) => import(specifier)) {
|
|
17
|
+
for (const name of PLAYWRIGHT_MODULES) try {
|
|
18
|
+
const mod = await importer(name);
|
|
19
|
+
if (mod.chromium) return mod;
|
|
20
|
+
} catch {}
|
|
21
|
+
throw new Error("hud sweep needs Playwright: add `playwright` (or `@playwright/test`) to the app and run `npx playwright install chromium`");
|
|
22
|
+
}
|
|
23
|
+
async function launchChromium() {
|
|
24
|
+
return (await loadPlaywright()).chromium.launch({ headless: true });
|
|
25
|
+
}
|
|
26
|
+
function joinUrl(base, path) {
|
|
27
|
+
return `${base.replace(/\/+$/, "")}/${path.replace(/^\/+/, "")}`;
|
|
28
|
+
}
|
|
29
|
+
/** The route list from the running app's `routes` plugin. */
|
|
30
|
+
async function fetchRoutes(base, apiBase, doFetch = fetch) {
|
|
31
|
+
const url = joinUrl(base, `${apiBase.replace(/^\/+|\/+$/g, "")}/routes/routes`);
|
|
32
|
+
let res;
|
|
33
|
+
try {
|
|
34
|
+
res = await doFetch(url, { headers: { accept: "application/json" } });
|
|
35
|
+
} catch (error) {
|
|
36
|
+
throw new Error(`hud sweep: ${url} unreachable (${describe(error)})`);
|
|
37
|
+
}
|
|
38
|
+
if (res.status === 404) throw new Error(`hud sweep: ${url} answered 404: mount routes() in createHudHandler and run the server in development`);
|
|
39
|
+
const body = await res.json().catch(() => void 0);
|
|
40
|
+
if (!res.ok || !body || body.ok !== true) {
|
|
41
|
+
const detail = body && "error" in body && body.error ? `: ${body.error}` : "";
|
|
42
|
+
throw new Error(`hud sweep: ${url} answered ${res.status}${detail}`);
|
|
43
|
+
}
|
|
44
|
+
return body.routes;
|
|
45
|
+
}
|
|
46
|
+
function describe(error) {
|
|
47
|
+
return error instanceof Error ? error.message : String(error);
|
|
48
|
+
}
|
|
49
|
+
async function visit(browser, url, { timeoutMs, settleMs, ignore, hudApi }) {
|
|
50
|
+
const page = await browser.newPage();
|
|
51
|
+
const consoleErrors = [];
|
|
52
|
+
const pageErrors = [];
|
|
53
|
+
page.on("console", (message) => {
|
|
54
|
+
if (message.type() !== "error") return;
|
|
55
|
+
if (message.location?.().url.startsWith(hudApi)) return;
|
|
56
|
+
consoleErrors.push(message.text());
|
|
57
|
+
});
|
|
58
|
+
page.on("pageerror", (error) => pageErrors.push(error.message));
|
|
59
|
+
try {
|
|
60
|
+
const response = await page.goto(url, {
|
|
61
|
+
waitUntil: "load",
|
|
62
|
+
timeout: timeoutMs
|
|
63
|
+
});
|
|
64
|
+
if (settleMs > 0) await page.waitForTimeout(settleMs);
|
|
65
|
+
return {
|
|
66
|
+
status: response ? response.status() : null,
|
|
67
|
+
finalUrl: page.url(),
|
|
68
|
+
consoleErrors: consoleErrors.filter((text) => !ignore.some((re) => re.test(text))),
|
|
69
|
+
pageErrors
|
|
70
|
+
};
|
|
71
|
+
} catch (error) {
|
|
72
|
+
return {
|
|
73
|
+
status: null,
|
|
74
|
+
finalUrl: null,
|
|
75
|
+
consoleErrors: [],
|
|
76
|
+
pageErrors,
|
|
77
|
+
error: describe(error)
|
|
78
|
+
};
|
|
79
|
+
} finally {
|
|
80
|
+
await page.close();
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
/** Fetches the route list, visits every resolved URL and returns the report. Never throws per route. */
|
|
84
|
+
async function sweep(options) {
|
|
85
|
+
const base = options.base.replace(/\/+$/, "");
|
|
86
|
+
const apiBase = options.apiBase ?? "/api/hud";
|
|
87
|
+
const timeoutMs = options.timeoutMs ?? 3e4;
|
|
88
|
+
const settleMs = options.settleMs ?? 500;
|
|
89
|
+
const ignore = [...DEFAULT_CONSOLE_IGNORE, ...options.ignoreConsole ?? []];
|
|
90
|
+
const hudApi = `${joinUrl(base, apiBase)}/`;
|
|
91
|
+
const routes = await fetchRoutes(base, apiBase, options.fetch);
|
|
92
|
+
const results = [];
|
|
93
|
+
const report = (result) => {
|
|
94
|
+
results.push(result);
|
|
95
|
+
options.onResult?.(result);
|
|
96
|
+
};
|
|
97
|
+
const browser = await (options.launch ?? launchChromium)();
|
|
98
|
+
try {
|
|
99
|
+
for (const route of routes) {
|
|
100
|
+
if (isExcluded(route, options.exclude)) continue;
|
|
101
|
+
if (route.unresolved.length > 0) {
|
|
102
|
+
report({
|
|
103
|
+
pattern: route.pattern,
|
|
104
|
+
url: route.path,
|
|
105
|
+
status: null,
|
|
106
|
+
finalUrl: null,
|
|
107
|
+
consoleErrors: [],
|
|
108
|
+
pageErrors: [],
|
|
109
|
+
ok: true,
|
|
110
|
+
skipped: true,
|
|
111
|
+
reason: `no fixture: ${route.unresolved.join(", ")}`
|
|
112
|
+
});
|
|
113
|
+
continue;
|
|
114
|
+
}
|
|
115
|
+
for (const { url } of route.urls) {
|
|
116
|
+
const outcome = await visit(browser, joinUrl(base, url), {
|
|
117
|
+
timeoutMs,
|
|
118
|
+
settleMs,
|
|
119
|
+
ignore,
|
|
120
|
+
hudApi
|
|
121
|
+
});
|
|
122
|
+
const ok = outcome.error === void 0 && (outcome.status === null || outcome.status < 500) && outcome.consoleErrors.length === 0 && outcome.pageErrors.length === 0;
|
|
123
|
+
report({
|
|
124
|
+
pattern: route.pattern,
|
|
125
|
+
url,
|
|
126
|
+
...outcome,
|
|
127
|
+
ok,
|
|
128
|
+
skipped: false
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
} finally {
|
|
133
|
+
await browser.close();
|
|
134
|
+
}
|
|
135
|
+
return {
|
|
136
|
+
base,
|
|
137
|
+
total: results.length,
|
|
138
|
+
visited: results.filter((r) => !r.skipped).length,
|
|
139
|
+
skipped: results.filter((r) => r.skipped).length,
|
|
140
|
+
failed: results.filter((r) => !r.ok).length,
|
|
141
|
+
results
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
/** One line per result, for a terminal. */
|
|
145
|
+
function formatResult(result) {
|
|
146
|
+
if (result.skipped) return ` · skip ${result.url} (${result.reason ?? "skipped"})`;
|
|
147
|
+
const mark = result.ok ? "✓" : "✗";
|
|
148
|
+
const status = result.status === null ? "---" : String(result.status).padStart(3);
|
|
149
|
+
const notes = [];
|
|
150
|
+
if (result.error) notes.push(result.error);
|
|
151
|
+
if (result.pageErrors.length) notes.push(`${result.pageErrors.length} uncaught`);
|
|
152
|
+
if (result.consoleErrors.length) notes.push(`${result.consoleErrors.length} console error(s)`);
|
|
153
|
+
const detail = [...result.pageErrors, ...result.consoleErrors].slice(0, 3).map((line) => `\n ${line.split("\n")[0]?.slice(0, 160)}`).join("");
|
|
154
|
+
return ` ${mark} ${status} ${result.url}${notes.length ? ` (${notes.join(", ")})` : ""}${detail}`;
|
|
155
|
+
}
|
|
156
|
+
function formatSweepReport(report) {
|
|
157
|
+
const verdict = report.failed > 0 ? `${report.failed} failed` : report.visited > 0 ? "no 5xx, no uncaught errors, no console errors" : "nothing visited";
|
|
158
|
+
return `${report.visited} visited · ${report.skipped} skipped · ${verdict}`;
|
|
159
|
+
}
|
|
160
|
+
//#endregion
|
|
161
|
+
//#region src/cli/args.ts
|
|
162
|
+
const USAGE = `hud sweep --base <url> [options]
|
|
163
|
+
|
|
164
|
+
Visits every route the running app's routes plugin lists, headless, and fails on
|
|
165
|
+
a 5xx answer, an uncaught error or a console error.
|
|
166
|
+
|
|
167
|
+
Options
|
|
168
|
+
--base <url> dev server origin, e.g. http://localhost:3000 (required)
|
|
169
|
+
--api <path> where createHudHandler is mounted (default /api/hud)
|
|
170
|
+
--json print the report as JSON instead of lines
|
|
171
|
+
--timeout <ms> per-navigation timeout (default 30000)
|
|
172
|
+
--wait <ms> settle time after load (default 500)
|
|
173
|
+
--ignore-console <re> ignore console errors matching this pattern (repeatable)
|
|
174
|
+
--exclude <path> skip a URL path or folder pattern, trailing * allowed (repeatable)
|
|
175
|
+
|
|
176
|
+
Exit codes: 0 clean, 1 at least one route failed, 2 usage or setup error.`;
|
|
177
|
+
var UsageError = class extends Error {};
|
|
178
|
+
function next(argv, i, flag) {
|
|
179
|
+
const value = argv[i + 1];
|
|
180
|
+
if (value === void 0 || value.startsWith("--")) throw new UsageError(`${flag} needs a value`);
|
|
181
|
+
return value;
|
|
182
|
+
}
|
|
183
|
+
function integer(value, flag) {
|
|
184
|
+
const n = Number(value);
|
|
185
|
+
if (!Number.isInteger(n) || n < 0) throw new UsageError(`${flag} needs a non-negative integer`);
|
|
186
|
+
return n;
|
|
187
|
+
}
|
|
188
|
+
/** `argv` without the runtime and script. */
|
|
189
|
+
function parseArgs(argv) {
|
|
190
|
+
const [command, ...rest] = argv;
|
|
191
|
+
if (command === void 0 || command === "--help" || command === "-h" || command === "help") return { command: "help" };
|
|
192
|
+
if (command !== "sweep") throw new UsageError(`unknown command "${command}"`);
|
|
193
|
+
const args = {
|
|
194
|
+
command: "sweep",
|
|
195
|
+
base: "",
|
|
196
|
+
apiBase: "/api/hud",
|
|
197
|
+
json: false,
|
|
198
|
+
timeoutMs: 3e4,
|
|
199
|
+
settleMs: 500,
|
|
200
|
+
ignoreConsole: [],
|
|
201
|
+
exclude: []
|
|
202
|
+
};
|
|
203
|
+
for (let i = 0; i < rest.length; i++) {
|
|
204
|
+
const flag = rest[i] ?? "";
|
|
205
|
+
const [name, inline] = flag.includes("=") ? flag.split(/=(.*)/s, 2) : [flag, void 0];
|
|
206
|
+
const value = () => {
|
|
207
|
+
if (inline !== void 0) return inline;
|
|
208
|
+
const v = next(rest, i, flag);
|
|
209
|
+
i++;
|
|
210
|
+
return v;
|
|
211
|
+
};
|
|
212
|
+
switch (name) {
|
|
213
|
+
case "--base":
|
|
214
|
+
args.base = value();
|
|
215
|
+
break;
|
|
216
|
+
case "--api":
|
|
217
|
+
args.apiBase = value();
|
|
218
|
+
break;
|
|
219
|
+
case "--json":
|
|
220
|
+
args.json = true;
|
|
221
|
+
break;
|
|
222
|
+
case "--timeout":
|
|
223
|
+
args.timeoutMs = integer(value(), name);
|
|
224
|
+
break;
|
|
225
|
+
case "--wait":
|
|
226
|
+
args.settleMs = integer(value(), name);
|
|
227
|
+
break;
|
|
228
|
+
case "--ignore-console":
|
|
229
|
+
args.ignoreConsole.push(new RegExp(value(), "i"));
|
|
230
|
+
break;
|
|
231
|
+
case "--exclude":
|
|
232
|
+
args.exclude.push(value());
|
|
233
|
+
break;
|
|
234
|
+
default: throw new UsageError(`unknown option "${flag}"`);
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
if (!args.base) throw new UsageError("--base <url> is required");
|
|
238
|
+
if (!/^https?:\/\//.test(args.base)) throw new UsageError("--base must start with http:// or https://");
|
|
239
|
+
return args;
|
|
240
|
+
}
|
|
241
|
+
//#endregion
|
|
242
|
+
//#region src/cli/index.ts
|
|
243
|
+
async function main(argv) {
|
|
244
|
+
const args = parseArgs(argv);
|
|
245
|
+
if (args.command === "help") {
|
|
246
|
+
process.stdout.write(`${USAGE}\n`);
|
|
247
|
+
return 0;
|
|
248
|
+
}
|
|
249
|
+
const quiet = args.json;
|
|
250
|
+
const log = (line) => {
|
|
251
|
+
if (!quiet) process.stdout.write(`${line}\n`);
|
|
252
|
+
};
|
|
253
|
+
log(`hud sweep ${args.base}`);
|
|
254
|
+
const report = await sweep({
|
|
255
|
+
base: args.base,
|
|
256
|
+
apiBase: args.apiBase,
|
|
257
|
+
timeoutMs: args.timeoutMs,
|
|
258
|
+
settleMs: args.settleMs,
|
|
259
|
+
ignoreConsole: args.ignoreConsole,
|
|
260
|
+
exclude: args.exclude,
|
|
261
|
+
onResult: (result) => log(formatResult(result))
|
|
262
|
+
});
|
|
263
|
+
if (args.json) process.stdout.write(`${JSON.stringify(report, null, 2)}\n`);
|
|
264
|
+
else log(formatSweepReport(report));
|
|
265
|
+
return report.failed > 0 ? 1 : 0;
|
|
266
|
+
}
|
|
267
|
+
main(process.argv.slice(2)).then((code) => {
|
|
268
|
+
process.exitCode = code;
|
|
269
|
+
}, (error) => {
|
|
270
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
271
|
+
process.stderr.write(`${message}\n`);
|
|
272
|
+
if (error instanceof UsageError) process.stderr.write(`\n${USAGE}\n`);
|
|
273
|
+
process.exitCode = 2;
|
|
274
|
+
});
|
|
275
|
+
//#endregion
|