@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.
Files changed (157) hide show
  1. package/README.md +603 -9
  2. package/dist/a11y-B5DUaiCs.js +246 -0
  3. package/dist/a11y-panel-p_t4eD7p.js +207 -0
  4. package/dist/{capabilities-CjulXFQX.js → access-C7zlaqj6.js} +1 -90
  5. package/dist/{access-CNvJOwKM.d.ts → access-D_ewAEJG.d.ts} +11 -4
  6. package/dist/access-panel-CEfTr9ZI.js +123 -0
  7. package/dist/adapter-BYoxPYTI.d.ts +33 -0
  8. package/dist/adapter-hcwmJtNx.js +65 -0
  9. package/dist/auto/runtime.d.ts +65 -0
  10. package/dist/auto/runtime.js +50 -0
  11. package/dist/auto.d.ts +15 -0
  12. package/dist/auto.js +33 -0
  13. package/dist/capabilities-rDSKjXpq.js +110 -0
  14. package/dist/capture-CwrIwLqi.js +300 -0
  15. package/dist/capture-buffer-Bbbo6omF.d.ts +35 -0
  16. package/dist/cli.d.ts +1 -0
  17. package/dist/cli.js +275 -0
  18. package/dist/data-panel-DhxAmP91.js +817 -0
  19. package/dist/data-store-ChF1td_P.js +164 -0
  20. package/dist/define-hud-CHPedaQ5.d.ts +50 -0
  21. package/dist/design-D0kGgPoP.js +87 -0
  22. package/dist/detect-BxHZ0pxW.d.ts +25 -0
  23. package/dist/detect-CHZiSeZs.js +63 -0
  24. package/dist/dispatch-panel-B-xr_Giy.js +279 -0
  25. package/dist/{env-vEjyJfPW.d.ts → env-CApnbI0r.d.ts} +2 -0
  26. package/dist/{env-DfxpPfs9.js → env-CaiFPIhF.js} +3 -0
  27. package/dist/file-xdSaQ2uR.js +103 -0
  28. package/dist/flags-DVtaJ8pQ.d.ts +58 -0
  29. package/dist/flags.d.ts +2 -0
  30. package/dist/flags.js +82 -0
  31. package/dist/force-state-panel-_otVYh9i.js +97 -0
  32. package/dist/generate-C8lQl3Eh.js +53 -0
  33. package/dist/handler-BpVhxEmU.js +106 -0
  34. package/dist/{handler-WmE4Lu7l.d.ts → handler-DtYVCZY6.d.ts} +1 -1
  35. package/dist/index-BAV_1W8a.d.ts +43 -0
  36. package/dist/index-BJ26pse9.d.ts +70 -0
  37. package/dist/index-BnQ0dTZf.d.ts +19 -0
  38. package/dist/index-CwfX-W87.d.ts +72 -0
  39. package/dist/index-DcH9V3cU.d.ts +48 -0
  40. package/dist/index-DqOyNf1u.d.ts +65 -0
  41. package/dist/index-DstI_ike.d.ts +66 -0
  42. package/dist/index-Dxz4fn4j.d.ts +42 -0
  43. package/dist/index-Hhh7OXzU.d.ts +129 -0
  44. package/dist/index-ReFbhQ9p.d.ts +25 -0
  45. package/dist/index-RgXfMBuW.d.ts +48 -0
  46. package/dist/{index-BYsdS-7d.d.ts → index-gCZBO53s.d.ts} +21 -3
  47. package/dist/index.d.ts +5 -5
  48. package/dist/index.js +710 -69
  49. package/dist/inspect-C9Ft8fqn.js +142 -0
  50. package/dist/inspect-root-BkaupBMp.js +429 -0
  51. package/dist/meta-Bv0sEao3.js +6 -0
  52. package/dist/meta-C_G7MB5w.d.ts +49 -0
  53. package/dist/mocks-CA-wM2SB.d.ts +109 -0
  54. package/dist/mocks-ESiRqk9o.js +150 -0
  55. package/dist/msw-browser-wjaYgkB7.d.ts +31 -0
  56. package/dist/next/config.d.ts +52 -0
  57. package/dist/next/config.js +78 -0
  58. package/dist/next.d.ts +14 -4
  59. package/dist/next.js +5 -3
  60. package/dist/observe-CdDnDBRP.js +89 -0
  61. package/dist/observe-panel-Cgp1M8oT.js +347 -0
  62. package/dist/ops-panel-CEqDe_UT.js +234 -0
  63. package/dist/{payload-CLKDVZWl.d.ts → payload-MUQ9ciER.d.ts} +25 -1
  64. package/dist/plugins/a11y.d.ts +2 -0
  65. package/dist/plugins/a11y.js +2 -0
  66. package/dist/plugins/access/server.d.ts +5 -5
  67. package/dist/plugins/access/server.js +4 -3
  68. package/dist/plugins/access.d.ts +5 -5
  69. package/dist/plugins/access.js +16 -215
  70. package/dist/plugins/agent/server.d.ts +3 -38
  71. package/dist/plugins/agent/server.js +47 -21
  72. package/dist/plugins/agent.d.ts +4 -4
  73. package/dist/plugins/agent.js +6 -348
  74. package/dist/plugins/capture/server.d.ts +92 -0
  75. package/dist/plugins/capture/server.js +248 -0
  76. package/dist/plugins/capture.d.ts +24 -0
  77. package/dist/plugins/capture.js +70 -0
  78. package/dist/plugins/data/msw-browser.d.ts +2 -0
  79. package/dist/plugins/data/msw-browser.js +39 -0
  80. package/dist/plugins/data/msw-node.d.ts +36 -0
  81. package/dist/plugins/data/msw-node.js +68 -0
  82. package/dist/plugins/data/server.d.ts +257 -0
  83. package/dist/plugins/data/server.js +717 -0
  84. package/dist/plugins/data.d.ts +6 -0
  85. package/dist/plugins/data.js +51 -0
  86. package/dist/plugins/design/server.d.ts +54 -0
  87. package/dist/plugins/design/server.js +198 -0
  88. package/dist/plugins/design.d.ts +4 -124
  89. package/dist/plugins/design.js +4 -619
  90. package/dist/plugins/inspect/convex.d.ts +2 -0
  91. package/dist/plugins/inspect/convex.js +486 -0
  92. package/dist/plugins/inspect/react-query.d.ts +2 -0
  93. package/dist/plugins/inspect/react-query.js +225 -0
  94. package/dist/plugins/inspect/sockets.d.ts +51 -0
  95. package/dist/plugins/inspect/sockets.js +397 -0
  96. package/dist/plugins/inspect/swr.d.ts +2 -0
  97. package/dist/plugins/inspect/swr.js +218 -0
  98. package/dist/plugins/inspect.d.ts +4 -0
  99. package/dist/plugins/inspect.js +3 -0
  100. package/dist/plugins/observe.d.ts +4 -64
  101. package/dist/plugins/observe.js +1 -616
  102. package/dist/plugins/ops/server.d.ts +1 -1
  103. package/dist/plugins/ops/server.js +2 -1
  104. package/dist/plugins/ops.d.ts +2 -1
  105. package/dist/plugins/ops.js +15 -336
  106. package/dist/plugins/routes/server.d.ts +88 -0
  107. package/dist/plugins/routes/server.js +62 -0
  108. package/dist/plugins/routes.d.ts +3 -0
  109. package/dist/plugins/routes.js +216 -0
  110. package/dist/plugins/seo.d.ts +2 -0
  111. package/dist/plugins/seo.js +2 -0
  112. package/dist/plugins/vitals.d.ts +2 -25
  113. package/dist/plugins/vitals.js +3 -2
  114. package/dist/{plugins-CQ_0w1ot.d.ts → plugins-BZvDqGx5.d.ts} +33 -3
  115. package/dist/poll-CjKsWZi8.js +89 -0
  116. package/dist/requests-BwD6MKEq.js +282 -0
  117. package/dist/requests-CJrUf465.d.ts +50 -0
  118. package/dist/review.js +2 -2
  119. package/dist/same-origin-BGet22CC.js +21 -0
  120. package/dist/scan-DzJNXqOk.js +165 -0
  121. package/dist/seo-Dq9q_QkO.js +551 -0
  122. package/dist/seo-panel-CfiY-TnT.js +124 -0
  123. package/dist/server.d.ts +2 -2
  124. package/dist/server.js +2 -105
  125. package/dist/sessions-panel-COvhPAzv.js +98 -0
  126. package/dist/{shortcut-U6ftVY06.js → shortcut-s_mjGeU8.js} +1 -44
  127. package/dist/{types-QJUajwWq.js → state-CjjZPjPJ.js} +13 -8
  128. package/dist/store/convex.d.ts +33 -0
  129. package/dist/store/convex.js +52 -0
  130. package/dist/{vitals-panel-Dvc5dnR-.js → store-CQqIIKTc.js} +1 -29
  131. package/dist/store-Ync9eb1G.js +67 -0
  132. package/dist/store.d.ts +76 -0
  133. package/dist/store.js +188 -0
  134. package/dist/{styles--slk86ZQ.js → styles-BA8ueHoV.js} +13 -3
  135. package/dist/styles-DKU_P8MH.js +139 -0
  136. package/dist/styles-DPpDPmzi.js +68 -0
  137. package/dist/tokens-panel-CbMQfasZ.js +142 -0
  138. package/dist/types-B-ulf2Jp.js +8 -0
  139. package/dist/types-BIgGf-0C.d.ts +25 -0
  140. package/dist/types-BIkI-qN8.js +30 -0
  141. package/dist/{types-DADBRiGk.d.ts → types-Cxh4twqc.d.ts} +1 -1
  142. package/dist/types-DIdPfjtV.js +6 -0
  143. package/dist/types-DaJcsEjO.d.ts +44 -0
  144. package/dist/types-Dn68psVz.d.ts +118 -0
  145. package/dist/types-szkr2QOF.d.ts +39 -0
  146. package/dist/unlock-store-4V3vR4Eg.js +96 -0
  147. package/dist/variant-groups-TIfO3NIj.js +137 -0
  148. package/dist/variant-groups-aAIrcNK5.d.ts +36 -0
  149. package/dist/variants-panel-BDoSkwBJ.js +457 -0
  150. package/dist/variants-types-CcRf119M.d.ts +63 -0
  151. package/dist/variants.d.ts +43 -0
  152. package/dist/variants.js +83 -0
  153. package/dist/vitals-panel-BCmMUntW.js +30 -0
  154. package/dist/vite.d.ts +37 -0
  155. package/dist/vite.js +134 -0
  156. package/package.json +65 -5
  157. package/dist/define-hud-BBzsSl8b.d.ts +0 -36
@@ -0,0 +1,109 @@
1
+ //#region src/plugins/data/mocks.d.ts
2
+ /**
3
+ * Mock scenarios, the msw-free half: how a scenario is declared, how the
4
+ * active set is stored, and how a request is matched against the active
5
+ * scenarios to produce a mocked answer. The same resolver runs in the
6
+ * browser (behind an MSW worker, `msw-browser`) and in Node (behind an MSW
7
+ * server started from `instrumentation.ts`, `msw-node`); only those two
8
+ * entries import `msw`, so the panel, the server half and an app's scenario
9
+ * module never depend on it.
10
+ */
11
+ type HudMockMethod = "GET" | "POST" | "PUT" | "PATCH" | "DELETE" | "HEAD" | "OPTIONS";
12
+ interface HudMockContext {
13
+ /** Values of `:name` segments in the matched endpoint path. */
14
+ params: Record<string, string>;
15
+ }
16
+ /**
17
+ * One alternative answer for one endpoint. Scenarios with the same `endpoint`
18
+ * are exclusive: the panel shows them as `real | empty | error | slow` and at
19
+ * most one is active per endpoint.
20
+ */
21
+ interface HudMockScenario {
22
+ /** Unique across the app: `orders:empty`. */
23
+ id: string;
24
+ /**
25
+ * `METHOD path`: `GET /api/orders`, `GET /api/orders/:id`, `* /api/*`,
26
+ * `POST https://api.example.com/v1/orders`. A relative path matches on
27
+ * every origin; `:name` captures one segment; a trailing `*` matches the rest.
28
+ */
29
+ endpoint: string;
30
+ /** Shown on the segment: `empty`, `error`, `slow`. */
31
+ label: string;
32
+ description?: string;
33
+ /** Waits this long before answering, or before passing through when nothing else is set: the "slow" scenario. */
34
+ delay?: number;
35
+ /** HTTP status of the mocked answer. Default 200 when `json` is set; alone it answers an empty body. */
36
+ status?: number;
37
+ /** JSON body of the mocked answer. */
38
+ json?: unknown;
39
+ headers?: Record<string, string>;
40
+ /** Full control: return a `Response`, or `undefined` to pass the request through to the real endpoint. */
41
+ respond?: (request: Request, ctx: HudMockContext) => Response | undefined | Promise<Response | undefined>;
42
+ }
43
+ /** What the browser is told about a scenario: the definition without its behaviour. */
44
+ interface HudMockScenarioInfo {
45
+ id: string;
46
+ endpoint: string;
47
+ label: string;
48
+ description?: string;
49
+ }
50
+ /** The active set: endpoint → the id of the scenario answering it. */
51
+ type HudMockActive = Readonly<Record<string, string>>;
52
+ /** Scenario and seed ids: slugs with dots and colons, one line, bounded. */
53
+ declare const MOCK_SCENARIO_ID: RegExp;
54
+ /** The store collection the active set lives in: `.hud/mocks.json` with `file()`. */
55
+ declare const MOCKS_COLLECTION = "mocks";
56
+ /** The one document in that collection: `{ active: { "GET /api/orders": "orders:empty" } }`. */
57
+ declare const MOCKS_DOCUMENT = "active";
58
+ /** Answers a request from the active scenarios, or `undefined` to let it through. */
59
+ type HudMockResolve = (request: Request) => Promise<Response | undefined>;
60
+ interface ParsedEndpoint {
61
+ method: HudMockMethod | "*";
62
+ /** Set when the path was absolute: only that origin matches. */
63
+ origin: string | null;
64
+ segments: string[];
65
+ }
66
+ /** `GET /api/orders/:id` → method, origin and path segments; throws on anything else. */
67
+ declare function parseEndpoint(endpoint: string): ParsedEndpoint;
68
+ /** The params when `endpoint` matches `method` + `url`, else `null`. Query strings are ignored. */
69
+ declare function matchEndpoint(endpoint: ParsedEndpoint, method: string, url: URL): Record<string, string> | null;
70
+ interface ValidatedScenario {
71
+ scenario: HudMockScenario;
72
+ endpoint: ParsedEndpoint;
73
+ }
74
+ /** Parses every endpoint and rejects duplicate or malformed ids; a developer error throws. */
75
+ declare function validateScenarios(scenarios: readonly HudMockScenario[]): Map<string, ValidatedScenario>;
76
+ /**
77
+ * The active set out of the store's document, keeping only entries that
78
+ * name a registered scenario under its own endpoint (a stale file names
79
+ * scenarios that no longer exist).
80
+ */
81
+ declare function toMockActive(value: unknown, scenarios: ReadonlyMap<string, ValidatedScenario>): HudMockActive;
82
+ /**
83
+ * The resolver both MSW halves run: the first active scenario whose
84
+ * endpoint matches the request answers it. `getActive` is read on every
85
+ * request, so a toggle applies to the next fetch without re-registering
86
+ * handlers.
87
+ */
88
+ declare function createMockResolver(scenarios: ReadonlyMap<string, ValidatedScenario>, getActive: () => HudMockActive): HudMockResolve;
89
+ /** Where the Node MSW server reports and takes the active set from. */
90
+ interface HudMockNodeStatus {
91
+ /** `live`: `startMockServer()` listens. `off`: nobody started it. `failed`: it tried; `hint` says why. */
92
+ status: "live" | "off" | "failed";
93
+ hint?: string;
94
+ }
95
+ /**
96
+ * The hand-off between `startMockServer()` (run once from
97
+ * `instrumentation.ts`) and `dataServer()` (run per request, possibly from
98
+ * another bundle of the same process): a registry on `globalThis`.
99
+ */
100
+ interface HudMockRegistry {
101
+ status: HudMockNodeStatus;
102
+ active: () => HudMockActive;
103
+ /** Called after every write, so the next server-side fetch sees the new set. */
104
+ apply: (active: HudMockActive) => void;
105
+ close: () => void;
106
+ }
107
+ declare function readMockRegistry(): HudMockRegistry | undefined;
108
+ //#endregion
109
+ export { validateScenarios as _, HudMockRegistry as a, HudMockScenarioInfo as c, MOCK_SCENARIO_ID as d, createMockResolver as f, toMockActive as g, readMockRegistry as h, HudMockNodeStatus as i, MOCKS_COLLECTION as l, parseEndpoint as m, HudMockContext as n, HudMockResolve as o, matchEndpoint as p, HudMockMethod as r, HudMockScenario as s, HudMockActive as t, MOCKS_DOCUMENT as u };
@@ -0,0 +1,150 @@
1
+ //#region src/plugins/data/mocks.ts
2
+ const METHODS = [
3
+ "GET",
4
+ "POST",
5
+ "PUT",
6
+ "PATCH",
7
+ "DELETE",
8
+ "HEAD",
9
+ "OPTIONS"
10
+ ];
11
+ /** Scenario and seed ids: slugs with dots and colons, one line, bounded. */
12
+ const MOCK_SCENARIO_ID = /^[a-zA-Z0-9][a-zA-Z0-9._:-]{0,99}$/;
13
+ /** The store collection the active set lives in: `.hud/mocks.json` with `file()`. */
14
+ const MOCKS_COLLECTION = "mocks";
15
+ /** The one document in that collection: `{ active: { "GET /api/orders": "orders:empty" } }`. */
16
+ const MOCKS_DOCUMENT = "active";
17
+ const ENDPOINT = /^(\S+)\s+(\S+)$/;
18
+ function splitPath(pathname) {
19
+ return pathname.split("/").filter(Boolean);
20
+ }
21
+ /** `GET /api/orders/:id` → method, origin and path segments; throws on anything else. */
22
+ function parseEndpoint(endpoint) {
23
+ const match = ENDPOINT.exec(endpoint.trim());
24
+ if (!match) throw new Error(`hud mocks: endpoint "${endpoint}" must be "METHOD /path"`);
25
+ const [, rawMethod = "", rawPath = ""] = match;
26
+ const method = rawMethod.toUpperCase();
27
+ if (method !== "*" && method !== "ALL" && !METHODS.includes(method)) throw new Error(`hud mocks: endpoint "${endpoint}" has an unknown method "${rawMethod}"`);
28
+ let origin = null;
29
+ let pathname = rawPath;
30
+ if (/^https?:\/\//i.test(rawPath)) {
31
+ const url = new URL(rawPath);
32
+ origin = url.origin;
33
+ pathname = url.pathname;
34
+ } else if (!rawPath.startsWith("/")) throw new Error(`hud mocks: endpoint "${endpoint}" path must start with "/" or "http"`);
35
+ return {
36
+ method: method === "ALL" ? "*" : method,
37
+ origin,
38
+ segments: splitPath(pathname)
39
+ };
40
+ }
41
+ /** The params when `endpoint` matches `method` + `url`, else `null`. Query strings are ignored. */
42
+ function matchEndpoint(endpoint, method, url) {
43
+ if (endpoint.method !== "*" && endpoint.method !== method.toUpperCase()) return null;
44
+ if (endpoint.origin !== null && endpoint.origin !== url.origin) return null;
45
+ const actual = splitPath(url.pathname);
46
+ const params = {};
47
+ for (const [i, pattern] of endpoint.segments.entries()) {
48
+ if (pattern === "*" && i === endpoint.segments.length - 1) return params;
49
+ const segment = actual[i];
50
+ if (segment === void 0) return null;
51
+ if (pattern.startsWith(":")) try {
52
+ params[pattern.slice(1)] = decodeURIComponent(segment);
53
+ } catch {
54
+ return null;
55
+ }
56
+ else if (pattern !== "*" && pattern !== segment) return null;
57
+ }
58
+ return actual.length === endpoint.segments.length ? params : null;
59
+ }
60
+ /** Parses every endpoint and rejects duplicate or malformed ids; a developer error throws. */
61
+ function validateScenarios(scenarios) {
62
+ const byId = /* @__PURE__ */ new Map();
63
+ for (const scenario of scenarios) {
64
+ if (!MOCK_SCENARIO_ID.test(scenario.id)) throw new Error(`hud mocks: scenario id "${scenario.id}" must match ${MOCK_SCENARIO_ID}`);
65
+ if (byId.has(scenario.id)) throw new Error(`hud mocks: duplicate scenario id "${scenario.id}"`);
66
+ byId.set(scenario.id, {
67
+ scenario,
68
+ endpoint: parseEndpoint(scenario.endpoint)
69
+ });
70
+ }
71
+ return byId;
72
+ }
73
+ /** What the browser may know: no `respond`, `json` or `headers`. */
74
+ function scenarioInfo({ id, endpoint, label, description }) {
75
+ return description === void 0 ? {
76
+ id,
77
+ endpoint,
78
+ label
79
+ } : {
80
+ id,
81
+ endpoint,
82
+ label,
83
+ description
84
+ };
85
+ }
86
+ function isRecord(value) {
87
+ return typeof value === "object" && value !== null && !Array.isArray(value);
88
+ }
89
+ /**
90
+ * The active set out of the store's document, keeping only entries that
91
+ * name a registered scenario under its own endpoint (a stale file names
92
+ * scenarios that no longer exist).
93
+ */
94
+ function toMockActive(value, scenarios) {
95
+ if (!isRecord(value) || !isRecord(value.active)) return {};
96
+ const active = {};
97
+ for (const [endpoint, id] of Object.entries(value.active)) {
98
+ if (typeof id !== "string") continue;
99
+ const known = scenarios.get(id);
100
+ if (known && known.scenario.endpoint === endpoint) active[endpoint] = id;
101
+ }
102
+ return active;
103
+ }
104
+ const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
105
+ /** The scenario's answer for a matched request, or `undefined` to pass it through. */
106
+ async function respondWith(scenario, request, ctx) {
107
+ if (scenario.delay !== void 0 && scenario.delay > 0) await sleep(scenario.delay);
108
+ if (scenario.respond) return scenario.respond(request, ctx);
109
+ const init = {
110
+ status: scenario.status ?? 200,
111
+ headers: scenario.headers ?? {}
112
+ };
113
+ if (scenario.json !== void 0) return Response.json(scenario.json, init);
114
+ if (scenario.status !== void 0) return new Response(null, init);
115
+ }
116
+ /**
117
+ * The resolver both MSW halves run: the first active scenario whose
118
+ * endpoint matches the request answers it. `getActive` is read on every
119
+ * request, so a toggle applies to the next fetch without re-registering
120
+ * handlers.
121
+ */
122
+ function createMockResolver(scenarios, getActive) {
123
+ return async (request) => {
124
+ const active = getActive();
125
+ if (Object.keys(active).length === 0) return void 0;
126
+ const url = new URL(request.url);
127
+ for (const id of Object.values(active)) {
128
+ const entry = scenarios.get(id);
129
+ if (!entry) continue;
130
+ const params = matchEndpoint(entry.endpoint, request.method, url);
131
+ if (params) return respondWith(entry.scenario, request, { params });
132
+ }
133
+ };
134
+ }
135
+ const REGISTRY_KEY = Symbol.for("hansenexus.hud.mocks");
136
+ function readMockRegistry() {
137
+ return globalThis[REGISTRY_KEY];
138
+ }
139
+ function writeMockRegistry(registry) {
140
+ globalThis[REGISTRY_KEY] = registry;
141
+ }
142
+ /** What `dataServer()` reports about the Node side. */
143
+ function nodeMockStatus() {
144
+ return readMockRegistry()?.status ?? {
145
+ status: "off",
146
+ hint: "Server fetches are not mocked: call startMockServer() from @hansenexus/hud/plugins/data/msw-node in instrumentation.ts."
147
+ };
148
+ }
149
+ //#endregion
150
+ export { matchEndpoint as a, readMockRegistry as c, validateScenarios as d, writeMockRegistry as f, createMockResolver as i, scenarioInfo as l, MOCKS_DOCUMENT as n, nodeMockStatus as o, MOCK_SCENARIO_ID as r, parseEndpoint as s, MOCKS_COLLECTION as t, toMockActive as u };
@@ -0,0 +1,31 @@
1
+ import { o as HudMockResolve } from "./mocks-CA-wM2SB.js";
2
+ //#region src/plugins/data/msw-browser.d.ts
3
+ interface MockWorkerOptions {
4
+ /** URL of the worker script. Default `/mockServiceWorker.js` (`npx msw init public/`). */
5
+ workerUrl?: string;
6
+ }
7
+ interface HudMockWorkerHandle {
8
+ stop: () => void | Promise<void>;
9
+ }
10
+ /**
11
+ * What `data({ mocks: { worker } })` loads: this module, or one of your own
12
+ * when the app already runs an MSW worker (register the HUD's catch-all on
13
+ * it with `worker.use(http.all("*", ({ request }) => resolve(request)))`).
14
+ */
15
+ interface HudMockWorkerModule {
16
+ startMockWorker: (resolve: HudMockResolve, options?: MockWorkerOptions) => Promise<HudMockWorkerHandle>;
17
+ }
18
+ /**
19
+ * Starts an MSW worker whose one handler asks the HUD's resolver, so client
20
+ * fetches follow the active scenarios. The data plugin loads this module on
21
+ * demand through the `worker` loader:
22
+ *
23
+ * ```ts
24
+ * data({ mocks: { scenarios, worker: () => import("@hansenexus/hud/plugins/data/msw-browser") } })
25
+ * ```
26
+ *
27
+ * Needs `msw` and its worker script in the app's public directory.
28
+ */
29
+ declare function startMockWorker(resolve: HudMockResolve, { workerUrl }?: MockWorkerOptions): Promise<HudMockWorkerHandle>;
30
+ //#endregion
31
+ export { startMockWorker as i, HudMockWorkerModule as n, MockWorkerOptions as r, HudMockWorkerHandle as t };
@@ -0,0 +1,52 @@
1
+ import { t as HudAutoDetected } from "../detect-BxHZ0pxW.js";
2
+ //#region src/next/config.d.ts
3
+ /** What the app imports; the wrapper aliases it to the generated file. */
4
+ export declare const AUTO_ID = "@hansenexus/hud/auto";
5
+ /** Where the generated module lives, relative to the app dir. Add it to .gitignore. */
6
+ export declare const AUTO_FILE = ".hud/auto.mjs";
7
+ export interface WithHudOptions {
8
+ /** The app directory. Default: `process.cwd()`, which is where Next loads next.config from. */
9
+ dir?: string;
10
+ /** The package.json detection reads. Default: `<dir>/package.json`. */
11
+ packageJson?: string;
12
+ }
13
+ interface WebpackConfigLike {
14
+ resolve?: {
15
+ alias?: Record<string, unknown> | unknown[] | undefined;
16
+ [key: string]: unknown;
17
+ };
18
+ [key: string]: unknown;
19
+ }
20
+ /**
21
+ * The slice of `NextConfig` the wrapper touches, structurally, so `next` is
22
+ * neither imported nor a peer. Method syntax keeps Next's own `webpack`
23
+ * signature assignable.
24
+ */
25
+ export interface NextConfigLike {
26
+ turbopack?: {
27
+ resolveAlias?: Record<string, unknown> | undefined;
28
+ [key: string]: unknown;
29
+ } | undefined;
30
+ webpack?(config: WebpackConfigLike, context: unknown): WebpackConfigLike;
31
+ [key: string]: unknown;
32
+ }
33
+ /** Reads, detects and writes `.hud/auto.mjs`; returns the detection and the file's absolute path. */
34
+ export declare function writeAutoModule({ dir, packageJson }?: WithHudOptions): {
35
+ detected: HudAutoDetected;
36
+ file: string;
37
+ };
38
+ /**
39
+ * Wraps next.config: reads the app's package.json, writes `.hud/auto.mjs`
40
+ * (a module importing only the plugins the dependencies call for) and
41
+ * aliases `@hansenexus/hud/auto` to it, for Turbopack and webpack alike.
42
+ * Runs on every `next dev` and `next build`, so the file follows
43
+ * package.json; it belongs in .gitignore.
44
+ *
45
+ * ```js
46
+ * // next.config.js
47
+ * import { withHud } from "@hansenexus/hud/next/config";
48
+ * export default withHud({ reactStrictMode: true });
49
+ * ```
50
+ */
51
+ export declare function withHud<C extends NextConfigLike>(config?: C, options?: WithHudOptions): C;
52
+ //#endregion
@@ -0,0 +1,78 @@
1
+ import { n as detectHudAuto, r as parsePackageJson } from "../detect-CHZiSeZs.js";
2
+ import { t as generateAutoModule } from "../generate-C8lQl3Eh.js";
3
+ import { mkdirSync, readFileSync, writeFileSync } from "node:fs";
4
+ import { dirname, resolve } from "node:path";
5
+ //#region src/next/config.ts
6
+ /** What the app imports; the wrapper aliases it to the generated file. */
7
+ const AUTO_ID = "@hansenexus/hud/auto";
8
+ /** Where the generated module lives, relative to the app dir. Add it to .gitignore. */
9
+ const AUTO_FILE = ".hud/auto.mjs";
10
+ /** Reads, detects and writes `.hud/auto.mjs`; returns the detection and the file's absolute path. */
11
+ function writeAutoModule({ dir = process.cwd(), packageJson } = {}) {
12
+ const manifest = packageJson ?? resolve(dir, "package.json");
13
+ let text = "{}";
14
+ try {
15
+ text = readFileSync(manifest, "utf8");
16
+ } catch {
17
+ console.warn(`hud: ${manifest} not found; @hansenexus/hud/auto enables the base plugins only`);
18
+ }
19
+ const detected = detectHudAuto(parsePackageJson(text));
20
+ const file = resolve(dir, AUTO_FILE);
21
+ const source = generateAutoModule(detected, manifest);
22
+ let current;
23
+ try {
24
+ current = readFileSync(file, "utf8");
25
+ } catch {}
26
+ if (current !== source) {
27
+ mkdirSync(dirname(file), { recursive: true });
28
+ writeFileSync(file, source, "utf8");
29
+ }
30
+ return {
31
+ detected,
32
+ file
33
+ };
34
+ }
35
+ /**
36
+ * Wraps next.config: reads the app's package.json, writes `.hud/auto.mjs`
37
+ * (a module importing only the plugins the dependencies call for) and
38
+ * aliases `@hansenexus/hud/auto` to it, for Turbopack and webpack alike.
39
+ * Runs on every `next dev` and `next build`, so the file follows
40
+ * package.json; it belongs in .gitignore.
41
+ *
42
+ * ```js
43
+ * // next.config.js
44
+ * import { withHud } from "@hansenexus/hud/next/config";
45
+ * export default withHud({ reactStrictMode: true });
46
+ * ```
47
+ */
48
+ function withHud(config, options = {}) {
49
+ const base = config ?? {};
50
+ const { file } = writeAutoModule(options);
51
+ const webpack = base.webpack;
52
+ return {
53
+ ...base,
54
+ turbopack: {
55
+ ...base.turbopack,
56
+ resolveAlias: {
57
+ ...base.turbopack?.resolveAlias,
58
+ [AUTO_ID]: `./${AUTO_FILE}`
59
+ }
60
+ },
61
+ webpack(webpackConfig, context) {
62
+ const own = webpack ? webpack.call(base, webpackConfig, context) : webpackConfig;
63
+ const resolveOptions = own.resolve ?? {};
64
+ const alias = resolveOptions.alias;
65
+ resolveOptions.alias = Array.isArray(alias) ? [...alias, {
66
+ name: AUTO_ID,
67
+ alias: file
68
+ }] : {
69
+ ...alias,
70
+ [`${AUTO_ID}$`]: file
71
+ };
72
+ own.resolve = resolveOptions;
73
+ return own;
74
+ }
75
+ };
76
+ }
77
+ //#endregion
78
+ export { AUTO_FILE, AUTO_ID, withHud, writeAutoModule };
package/dist/next.d.ts CHANGED
@@ -1,10 +1,18 @@
1
- import { n as HudMountProps } from "./define-hud-BBzsSl8b.js";
2
- import { n as hudEnvLabel, r as resolveHudEnv, t as HudEnv } from "./env-vEjyJfPW.js";
1
+ import { r as HudMountProps } from "./define-hud-CHPedaQ5.js";
2
+ import { n as hudEnvLabel, r as resolveHudEnv, t as HudEnv } from "./env-CApnbI0r.js";
3
3
  import { ComponentType } from "react";
4
4
  //#region src/next/loader.d.ts
5
5
  type HudModuleLoader = () => Promise<{
6
6
  default: ComponentType<HudMountProps>;
7
7
  }>;
8
+ interface HudLoaderOptions {
9
+ /**
10
+ * The tier, when the env ladder cannot read it. A Vite client has no
11
+ * `process`, so pass a literal the bundler folds:
12
+ * `import.meta.env.DEV ? "development" : "production"`. Default: `resolveHudEnv()`.
13
+ */
14
+ env?: HudEnv;
15
+ }
8
16
  /**
9
17
  * Mounts the app's `defineHud` module, lazily and client side only.
10
18
  *
@@ -27,7 +35,9 @@ type HudModuleLoader = () => Promise<{
27
35
  * do that: the `import()` would still sit in the consumer's module and the
28
36
  * chunk would ship unreachable but readable (hn-monorepo#1283). Pass `null`
29
37
  * and the loader renders nothing.
38
+ *
39
+ * Outside Next (Vite), gate on `import.meta.env.DEV` and pass `{ env }`.
30
40
  */
31
- export declare function createHudLoader(load: HudModuleLoader | null): ComponentType<HudMountProps>;
41
+ export declare function createHudLoader(load: HudModuleLoader | null, options?: HudLoaderOptions): ComponentType<HudMountProps>;
32
42
  //#endregion
33
- export { type HudEnv, type HudModuleLoader, type HudMountProps, hudEnvLabel, resolveHudEnv };
43
+ export { type HudEnv, type HudLoaderOptions, type HudModuleLoader, type HudMountProps, hudEnvLabel, resolveHudEnv };
package/dist/next.js CHANGED
@@ -1,4 +1,4 @@
1
- import { n as resolveHudEnv, t as hudEnvLabel } from "./env-DfxpPfs9.js";
1
+ import { n as resolveHudEnv, t as hudEnvLabel } from "./env-CaiFPIhF.js";
2
2
  import { Suspense, lazy, useEffect, useState } from "react";
3
3
  import { jsx } from "react/jsx-runtime";
4
4
  //#region src/next/loader.tsx
@@ -24,15 +24,17 @@ import { jsx } from "react/jsx-runtime";
24
24
  * do that: the `import()` would still sit in the consumer's module and the
25
25
  * chunk would ship unreachable but readable (hn-monorepo#1283). Pass `null`
26
26
  * and the loader renders nothing.
27
+ *
28
+ * Outside Next (Vite), gate on `import.meta.env.DEV` and pass `{ env }`.
27
29
  */
28
- function createHudLoader(load) {
30
+ function createHudLoader(load, options = {}) {
29
31
  if (!load) return NoHud;
30
32
  const LazyHud = lazy(load);
31
33
  function HudLoader(props) {
32
34
  const [mounted, setMounted] = useState(false);
33
35
  useEffect(() => setMounted(true), []);
34
36
  if (!mounted) return null;
35
- const env = resolveHudEnv();
37
+ const env = options.env ?? resolveHudEnv();
36
38
  if (env === "disabled") return null;
37
39
  return /* @__PURE__ */ jsx(Suspense, {
38
40
  fallback: null,
@@ -0,0 +1,89 @@
1
+ import { i as definePlugin } from "./plugins-DVy_vaYr.js";
2
+ import { _ as captureBuffer, v as isError } from "./requests-BwD6MKEq.js";
3
+ import { t as installCapture } from "./capture-CwrIwLqi.js";
4
+ import { r as startVitals } from "./store-CQqIIKTc.js";
5
+ import { lazy, useEffect, useSyncExternalStore } from "react";
6
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
7
+ //#region src/plugins/observe/view.ts
8
+ const FILTERS = [
9
+ "all",
10
+ "errors",
11
+ "warn",
12
+ "log",
13
+ "fetch",
14
+ "xhr",
15
+ "longtask"
16
+ ];
17
+ function matches(entry, filter) {
18
+ if (filter === "all") return true;
19
+ if (filter === "errors") return isError(entry);
20
+ return entry.kind === filter;
21
+ }
22
+ let view = {
23
+ tab: "console",
24
+ filter: "all"
25
+ };
26
+ const listeners = /* @__PURE__ */ new Set();
27
+ function setView(next) {
28
+ view = {
29
+ ...view,
30
+ ...next
31
+ };
32
+ for (const listener of listeners) listener();
33
+ }
34
+ function subscribe(listener) {
35
+ listeners.add(listener);
36
+ return () => listeners.delete(listener);
37
+ }
38
+ const getView = () => view;
39
+ function useView() {
40
+ return useSyncExternalStore(subscribe, getView, getView);
41
+ }
42
+ function useCapture() {
43
+ return useSyncExternalStore(captureBuffer.subscribe, captureBuffer.getSnapshot, captureBuffer.getSnapshot);
44
+ }
45
+ //#endregion
46
+ //#region src/plugins/observe/index.tsx
47
+ const Panel = lazy(() => import("./observe-panel-Cgp1M8oT.js"));
48
+ const NO_ENV = {};
49
+ const noUser = () => void 0;
50
+ function useErrorCount() {
51
+ return useCapture().filter(isError).length;
52
+ }
53
+ /**
54
+ * Console and network capture, an app/build/browser/user snapshot and the
55
+ * page's Web Vitals. The pill counts errors; opening the panel while there are
56
+ * any lands on the console filtered to them.
57
+ */
58
+ function observe({ env = NO_ENV, useUser = noUser, ignore } = {}) {
59
+ function ObservePill() {
60
+ useEffect(() => installCapture(ignore ? { ignore } : {}), []);
61
+ useEffect(() => startVitals(), []);
62
+ const errors = useErrorCount();
63
+ return /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("span", {
64
+ className: "dot",
65
+ "data-rating": errors > 0 ? "poor" : "good"
66
+ }), errors === 1 ? "1 error" : `${errors} errors`] });
67
+ }
68
+ function ObservePanel({ ctx }) {
69
+ return /* @__PURE__ */ jsx(Panel, {
70
+ ctx,
71
+ env,
72
+ useUser
73
+ });
74
+ }
75
+ return definePlugin({
76
+ id: "observe",
77
+ title: "Observe",
78
+ pill: ObservePill,
79
+ pillPriority: 20,
80
+ panel: ObservePanel,
81
+ commands: [{
82
+ id: "clear",
83
+ title: "Clear console capture",
84
+ run: () => captureBuffer.clear()
85
+ }]
86
+ });
87
+ }
88
+ //#endregion
89
+ export { useCapture as a, setView as i, FILTERS as n, useView as o, matches as r, observe as t };