@hansenexus/hud 0.4.0 → 0.5.1
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 +634 -12
- 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.cjs +201 -0
- package/dist/next/config.d.cts +87 -0
- package/dist/next/config.d.ts +64 -0
- package/dist/next/config.js +84 -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 +237 -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 +72 -5
- 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,201 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
let node_fs = require("node:fs");
|
|
3
|
+
let node_path = require("node:path");
|
|
4
|
+
//#region src/auto/detect.ts
|
|
5
|
+
/** Which package turns on which feature. */
|
|
6
|
+
const AUTO_RULES = {
|
|
7
|
+
next: "next",
|
|
8
|
+
convex: "convex",
|
|
9
|
+
reactQuery: "@tanstack/react-query",
|
|
10
|
+
swr: "swr",
|
|
11
|
+
msw: "msw",
|
|
12
|
+
betterAuth: "better-auth",
|
|
13
|
+
convexAuth: "@convex-dev/auth"
|
|
14
|
+
};
|
|
15
|
+
const AUTO_FEATURES = Object.keys(AUTO_RULES);
|
|
16
|
+
/** The stand-in: nothing detected, nothing configured. */
|
|
17
|
+
const NOTHING_DETECTED = Object.freeze({
|
|
18
|
+
configured: false,
|
|
19
|
+
next: false,
|
|
20
|
+
convex: false,
|
|
21
|
+
reactQuery: false,
|
|
22
|
+
swr: false,
|
|
23
|
+
msw: false,
|
|
24
|
+
betterAuth: false,
|
|
25
|
+
convexAuth: false
|
|
26
|
+
});
|
|
27
|
+
const SECTIONS = [
|
|
28
|
+
"dependencies",
|
|
29
|
+
"devDependencies",
|
|
30
|
+
"peerDependencies",
|
|
31
|
+
"optionalDependencies"
|
|
32
|
+
];
|
|
33
|
+
/** Every package the manifest names, whatever the section. */
|
|
34
|
+
function listDependencies(pkg) {
|
|
35
|
+
const names = /* @__PURE__ */ new Set();
|
|
36
|
+
for (const section of SECTIONS) {
|
|
37
|
+
const entries = pkg[section];
|
|
38
|
+
if (typeof entries !== "object" || entries === null) continue;
|
|
39
|
+
for (const name of Object.keys(entries)) names.add(name);
|
|
40
|
+
}
|
|
41
|
+
return names;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Detection from a parsed package.json: a feature is on when its package is
|
|
45
|
+
* listed in any dependency section (dev dependencies count: `msw` lives there).
|
|
46
|
+
*/
|
|
47
|
+
function detectHudAuto(pkg) {
|
|
48
|
+
const names = listDependencies(pkg);
|
|
49
|
+
const detected = {
|
|
50
|
+
...NOTHING_DETECTED,
|
|
51
|
+
configured: true
|
|
52
|
+
};
|
|
53
|
+
for (const feature of AUTO_FEATURES) detected[feature] = names.has(AUTO_RULES[feature]);
|
|
54
|
+
return Object.freeze(detected);
|
|
55
|
+
}
|
|
56
|
+
/** Parses package.json text; a broken file detects nothing rather than crashing the dev server. */
|
|
57
|
+
function parsePackageJson(text) {
|
|
58
|
+
try {
|
|
59
|
+
const parsed = JSON.parse(text);
|
|
60
|
+
return typeof parsed === "object" && parsed !== null ? parsed : {};
|
|
61
|
+
} catch {
|
|
62
|
+
return {};
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
//#endregion
|
|
66
|
+
//#region src/auto/generate.ts
|
|
67
|
+
const PACKAGE = "@hansenexus/hud";
|
|
68
|
+
/** Which import each feature adds: `name` from `subpath`. */
|
|
69
|
+
const FEATURE_IMPORTS = {
|
|
70
|
+
configured: null,
|
|
71
|
+
next: ["routes", "plugins/routes"],
|
|
72
|
+
convex: ["inspectConvex", "plugins/inspect/convex"],
|
|
73
|
+
reactQuery: ["inspectReactQuery", "plugins/inspect/react-query"],
|
|
74
|
+
swr: ["inspectSwr", "plugins/inspect/swr"],
|
|
75
|
+
msw: ["data", "plugins/data"],
|
|
76
|
+
betterAuth: ["data", "plugins/data"],
|
|
77
|
+
convexAuth: ["data", "plugins/data"]
|
|
78
|
+
};
|
|
79
|
+
/** The base plugins every auto HUD carries. */
|
|
80
|
+
const BASE_IMPORTS = [
|
|
81
|
+
["a11y", "plugins/a11y"],
|
|
82
|
+
["forceState", "plugins/design"],
|
|
83
|
+
["inspect", "plugins/inspect"],
|
|
84
|
+
["observe", "plugins/observe"],
|
|
85
|
+
["seo", "plugins/seo"],
|
|
86
|
+
["vitals", "plugins/vitals"]
|
|
87
|
+
];
|
|
88
|
+
/** The factories the generated module hands `assembleAuto`, in import order. */
|
|
89
|
+
function autoImports(detected) {
|
|
90
|
+
const imports = new Map(BASE_IMPORTS);
|
|
91
|
+
for (const [feature, entry] of Object.entries(FEATURE_IMPORTS)) if (entry && detected[feature]) imports.set(entry[0], entry[1]);
|
|
92
|
+
return imports;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* The generated module. `source` names where detection read from, for the
|
|
96
|
+
* header comment. Exports match the stand-in in `src/auto/index.ts`
|
|
97
|
+
* (`detected`, `auto`, default), so the types in `dist/auto.d.ts` apply.
|
|
98
|
+
*/
|
|
99
|
+
function generateAutoModule(detected, source = "package.json") {
|
|
100
|
+
const imports = [...autoImports(detected)].sort(([, a], [, b]) => a < b ? -1 : a > b ? 1 : 0).map(([name, subpath]) => `import { ${name} } from "${PACKAGE}/${subpath}";`);
|
|
101
|
+
const factories = [...autoImports(detected).keys()].sort().join(", ");
|
|
102
|
+
return [
|
|
103
|
+
`// Generated by ${PACKAGE} from ${source}. Do not edit: it is rewritten on every start.`,
|
|
104
|
+
`import { assembleAuto } from "${PACKAGE}/auto/runtime";`,
|
|
105
|
+
...imports,
|
|
106
|
+
"",
|
|
107
|
+
`export const detected = Object.freeze(${JSON.stringify(detected)});`,
|
|
108
|
+
"",
|
|
109
|
+
"export function auto(options) {",
|
|
110
|
+
` return assembleAuto(detected, { ${factories} }, options);`,
|
|
111
|
+
"}",
|
|
112
|
+
"",
|
|
113
|
+
"export default auto;",
|
|
114
|
+
""
|
|
115
|
+
].join("\n");
|
|
116
|
+
}
|
|
117
|
+
//#endregion
|
|
118
|
+
//#region src/next/config.ts
|
|
119
|
+
/** What the app imports; the wrapper aliases it to the generated file. */
|
|
120
|
+
const AUTO_ID = "@hansenexus/hud/auto";
|
|
121
|
+
/** Where the generated module lives, relative to the app dir. Add it to .gitignore. */
|
|
122
|
+
const AUTO_FILE = ".hud/auto.mjs";
|
|
123
|
+
/**
|
|
124
|
+
* The client variables the loader gate and the env ladder read. Next inlines a
|
|
125
|
+
* `NEXT_PUBLIC_*` read only when the variable is set at build time; Turbopack
|
|
126
|
+
* leaves an unset one as a runtime `process.env` lookup, so the gate
|
|
127
|
+
* `NODE_ENV === "development" || NEXT_PUBLIC_HUD_ENABLED === "true"` does not
|
|
128
|
+
* fold and the dev HUD ships as a production chunk (hud#64). `withHud` pins
|
|
129
|
+
* each to a build-time literal, `""` when unset.
|
|
130
|
+
*/
|
|
131
|
+
const HUD_PUBLIC_ENV = [
|
|
132
|
+
"NEXT_PUBLIC_HUD_ENABLED",
|
|
133
|
+
"NEXT_PUBLIC_HUD_DISABLED",
|
|
134
|
+
"NEXT_PUBLIC_HUD_ENV"
|
|
135
|
+
];
|
|
136
|
+
/** Reads, detects and writes `.hud/auto.mjs`; returns the detection and the file's absolute path. */
|
|
137
|
+
function writeAutoModule({ dir = process.cwd(), packageJson } = {}) {
|
|
138
|
+
const manifest = packageJson ?? (0, node_path.resolve)(dir, "package.json");
|
|
139
|
+
let text = "{}";
|
|
140
|
+
try {
|
|
141
|
+
text = (0, node_fs.readFileSync)(manifest, "utf8");
|
|
142
|
+
} catch {
|
|
143
|
+
console.warn(`hud: ${manifest} not found; @hansenexus/hud/auto enables the base plugins only`);
|
|
144
|
+
}
|
|
145
|
+
const detected = detectHudAuto(parsePackageJson(text));
|
|
146
|
+
const file = (0, node_path.resolve)(dir, AUTO_FILE);
|
|
147
|
+
const source = generateAutoModule(detected, manifest);
|
|
148
|
+
let current;
|
|
149
|
+
try {
|
|
150
|
+
current = (0, node_fs.readFileSync)(file, "utf8");
|
|
151
|
+
} catch {}
|
|
152
|
+
if (current !== source) {
|
|
153
|
+
(0, node_fs.mkdirSync)((0, node_path.dirname)(file), { recursive: true });
|
|
154
|
+
(0, node_fs.writeFileSync)(file, source, "utf8");
|
|
155
|
+
}
|
|
156
|
+
return {
|
|
157
|
+
detected,
|
|
158
|
+
file
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
function withHud(config, options = {}) {
|
|
162
|
+
const base = config ?? {};
|
|
163
|
+
const { file } = writeAutoModule(options);
|
|
164
|
+
const webpack = base.webpack;
|
|
165
|
+
const pinned = {};
|
|
166
|
+
for (const key of HUD_PUBLIC_ENV) pinned[key] = process.env[key] ?? "";
|
|
167
|
+
return {
|
|
168
|
+
...base,
|
|
169
|
+
env: {
|
|
170
|
+
...pinned,
|
|
171
|
+
...base.env
|
|
172
|
+
},
|
|
173
|
+
turbopack: {
|
|
174
|
+
...base.turbopack,
|
|
175
|
+
resolveAlias: {
|
|
176
|
+
...base.turbopack?.resolveAlias,
|
|
177
|
+
[AUTO_ID]: `./${AUTO_FILE}`
|
|
178
|
+
}
|
|
179
|
+
},
|
|
180
|
+
webpack(webpackConfig, context) {
|
|
181
|
+
const own = webpack ? webpack.call(base, webpackConfig, context) : webpackConfig;
|
|
182
|
+
const resolveOptions = own.resolve ?? {};
|
|
183
|
+
const alias = resolveOptions.alias;
|
|
184
|
+
resolveOptions.alias = Array.isArray(alias) ? [...alias, {
|
|
185
|
+
name: AUTO_ID,
|
|
186
|
+
alias: file
|
|
187
|
+
}] : {
|
|
188
|
+
...alias,
|
|
189
|
+
[`${AUTO_ID}$`]: file
|
|
190
|
+
};
|
|
191
|
+
own.resolve = resolveOptions;
|
|
192
|
+
return own;
|
|
193
|
+
}
|
|
194
|
+
};
|
|
195
|
+
}
|
|
196
|
+
//#endregion
|
|
197
|
+
exports.AUTO_FILE = AUTO_FILE;
|
|
198
|
+
exports.AUTO_ID = AUTO_ID;
|
|
199
|
+
exports.HUD_PUBLIC_ENV = HUD_PUBLIC_ENV;
|
|
200
|
+
exports.withHud = withHud;
|
|
201
|
+
exports.writeAutoModule = writeAutoModule;
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
//#region src/auto/detect.d.ts
|
|
2
|
+
/** What the bundler plugin found in the app's package.json. */
|
|
3
|
+
interface HudAutoDetected {
|
|
4
|
+
/**
|
|
5
|
+
* False in the stand-in module the package ships: no bundler plugin read the
|
|
6
|
+
* app's package.json, so only the base plugins are on.
|
|
7
|
+
*/
|
|
8
|
+
configured: boolean;
|
|
9
|
+
/** `next`: the routes plugin (route index, `hud sweep`). */
|
|
10
|
+
next: boolean;
|
|
11
|
+
/** `convex`: the Convex tab of the inspect plugin. */
|
|
12
|
+
convex: boolean;
|
|
13
|
+
/** `@tanstack/react-query`: the Query tab. */
|
|
14
|
+
reactQuery: boolean;
|
|
15
|
+
/** `swr`: the SWR tab. */
|
|
16
|
+
swr: boolean;
|
|
17
|
+
/** `msw`: the data plugin (mock scenarios). */
|
|
18
|
+
msw: boolean;
|
|
19
|
+
/** `better-auth`: the data plugin (role switch). */
|
|
20
|
+
betterAuth: boolean;
|
|
21
|
+
/** `@convex-dev/auth`: the data plugin (role switch). */
|
|
22
|
+
convexAuth: boolean;
|
|
23
|
+
}
|
|
24
|
+
//#endregion
|
|
25
|
+
//#region src/next/config.d.ts
|
|
26
|
+
/** What the app imports; the wrapper aliases it to the generated file. */
|
|
27
|
+
export declare const AUTO_ID = "@hansenexus/hud/auto";
|
|
28
|
+
/** Where the generated module lives, relative to the app dir. Add it to .gitignore. */
|
|
29
|
+
export declare const AUTO_FILE = ".hud/auto.mjs";
|
|
30
|
+
export interface WithHudOptions {
|
|
31
|
+
/** The app directory. Default: `process.cwd()`, which is where Next loads next.config from. */
|
|
32
|
+
dir?: string;
|
|
33
|
+
/** The package.json detection reads. Default: `<dir>/package.json`. */
|
|
34
|
+
packageJson?: string;
|
|
35
|
+
}
|
|
36
|
+
interface WebpackConfigLike {
|
|
37
|
+
resolve?: {
|
|
38
|
+
alias?: Record<string, unknown> | unknown[] | undefined;
|
|
39
|
+
[key: string]: unknown;
|
|
40
|
+
};
|
|
41
|
+
[key: string]: unknown;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* The slice of `NextConfig` the wrapper touches, structurally, so `next` is
|
|
45
|
+
* neither imported nor a peer. No index signatures: Next's own `NextConfig`
|
|
46
|
+
* and `TurbopackOptions` are interfaces without one (hud#66). Method syntax
|
|
47
|
+
* keeps Next's own `webpack` signature assignable.
|
|
48
|
+
*/
|
|
49
|
+
export interface NextConfigLike {
|
|
50
|
+
env?: Record<string, string | undefined> | undefined;
|
|
51
|
+
turbopack?: {
|
|
52
|
+
resolveAlias?: Record<string, unknown> | undefined;
|
|
53
|
+
} | undefined;
|
|
54
|
+
webpack?(config: WebpackConfigLike, context: unknown): WebpackConfigLike;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* The client variables the loader gate and the env ladder read. Next inlines a
|
|
58
|
+
* `NEXT_PUBLIC_*` read only when the variable is set at build time; Turbopack
|
|
59
|
+
* leaves an unset one as a runtime `process.env` lookup, so the gate
|
|
60
|
+
* `NODE_ENV === "development" || NEXT_PUBLIC_HUD_ENABLED === "true"` does not
|
|
61
|
+
* fold and the dev HUD ships as a production chunk (hud#64). `withHud` pins
|
|
62
|
+
* each to a build-time literal, `""` when unset.
|
|
63
|
+
*/
|
|
64
|
+
export declare const HUD_PUBLIC_ENV: readonly ["NEXT_PUBLIC_HUD_ENABLED", "NEXT_PUBLIC_HUD_DISABLED", "NEXT_PUBLIC_HUD_ENV"];
|
|
65
|
+
/** Reads, detects and writes `.hud/auto.mjs`; returns the detection and the file's absolute path. */
|
|
66
|
+
export declare function writeAutoModule({ dir, packageJson }?: WithHudOptions): {
|
|
67
|
+
detected: HudAutoDetected;
|
|
68
|
+
file: string;
|
|
69
|
+
};
|
|
70
|
+
/**
|
|
71
|
+
* Wraps next.config: reads the app's package.json, writes `.hud/auto.mjs`
|
|
72
|
+
* (a module importing only the plugins the dependencies call for) and
|
|
73
|
+
* aliases `@hansenexus/hud/auto` to it, for Turbopack and webpack alike.
|
|
74
|
+
* Runs on every `next dev` and `next build`, so the file follows
|
|
75
|
+
* package.json; it belongs in .gitignore. It also pins the HUD's
|
|
76
|
+
* `NEXT_PUBLIC_*` variables (`HUD_PUBLIC_ENV`) through `env`, so the loader
|
|
77
|
+
* gate folds when they are unset; an app's own `env` entry wins.
|
|
78
|
+
*
|
|
79
|
+
* ```js
|
|
80
|
+
* // next.config.js (ESM), or next.config.ts through `require()`
|
|
81
|
+
* import { withHud } from "@hansenexus/hud/next/config";
|
|
82
|
+
* export default withHud({ reactStrictMode: true });
|
|
83
|
+
* ```
|
|
84
|
+
*/
|
|
85
|
+
export declare function withHud(config?: undefined, options?: WithHudOptions): NextConfigLike;
|
|
86
|
+
export declare function withHud<C extends object>(config: C, options?: WithHudOptions): C;
|
|
87
|
+
//#endregion
|
|
@@ -0,0 +1,64 @@
|
|
|
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. No index signatures: Next's own `NextConfig`
|
|
23
|
+
* and `TurbopackOptions` are interfaces without one (hud#66). Method syntax
|
|
24
|
+
* keeps Next's own `webpack` signature assignable.
|
|
25
|
+
*/
|
|
26
|
+
export interface NextConfigLike {
|
|
27
|
+
env?: Record<string, string | undefined> | undefined;
|
|
28
|
+
turbopack?: {
|
|
29
|
+
resolveAlias?: Record<string, unknown> | undefined;
|
|
30
|
+
} | undefined;
|
|
31
|
+
webpack?(config: WebpackConfigLike, context: unknown): WebpackConfigLike;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* The client variables the loader gate and the env ladder read. Next inlines a
|
|
35
|
+
* `NEXT_PUBLIC_*` read only when the variable is set at build time; Turbopack
|
|
36
|
+
* leaves an unset one as a runtime `process.env` lookup, so the gate
|
|
37
|
+
* `NODE_ENV === "development" || NEXT_PUBLIC_HUD_ENABLED === "true"` does not
|
|
38
|
+
* fold and the dev HUD ships as a production chunk (hud#64). `withHud` pins
|
|
39
|
+
* each to a build-time literal, `""` when unset.
|
|
40
|
+
*/
|
|
41
|
+
export declare const HUD_PUBLIC_ENV: readonly ["NEXT_PUBLIC_HUD_ENABLED", "NEXT_PUBLIC_HUD_DISABLED", "NEXT_PUBLIC_HUD_ENV"];
|
|
42
|
+
/** Reads, detects and writes `.hud/auto.mjs`; returns the detection and the file's absolute path. */
|
|
43
|
+
export declare function writeAutoModule({ dir, packageJson }?: WithHudOptions): {
|
|
44
|
+
detected: HudAutoDetected;
|
|
45
|
+
file: string;
|
|
46
|
+
};
|
|
47
|
+
/**
|
|
48
|
+
* Wraps next.config: reads the app's package.json, writes `.hud/auto.mjs`
|
|
49
|
+
* (a module importing only the plugins the dependencies call for) and
|
|
50
|
+
* aliases `@hansenexus/hud/auto` to it, for Turbopack and webpack alike.
|
|
51
|
+
* Runs on every `next dev` and `next build`, so the file follows
|
|
52
|
+
* package.json; it belongs in .gitignore. It also pins the HUD's
|
|
53
|
+
* `NEXT_PUBLIC_*` variables (`HUD_PUBLIC_ENV`) through `env`, so the loader
|
|
54
|
+
* gate folds when they are unset; an app's own `env` entry wins.
|
|
55
|
+
*
|
|
56
|
+
* ```js
|
|
57
|
+
* // next.config.js (ESM), or next.config.ts through `require()`
|
|
58
|
+
* import { withHud } from "@hansenexus/hud/next/config";
|
|
59
|
+
* export default withHud({ reactStrictMode: true });
|
|
60
|
+
* ```
|
|
61
|
+
*/
|
|
62
|
+
export declare function withHud(config?: undefined, options?: WithHudOptions): NextConfigLike;
|
|
63
|
+
export declare function withHud<C extends object>(config: C, options?: WithHudOptions): C;
|
|
64
|
+
//#endregion
|