@brickkit/cli 0.7.3 → 0.8.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 (39) hide show
  1. package/README.md +173 -1
  2. package/dashboard-dist/CollapsiblePanel-DM8J3g8m.js +2 -0
  3. package/dashboard-dist/Geist-Variable.woff2 +0 -0
  4. package/dashboard-dist/GeistMono-Variable.woff2 +0 -0
  5. package/dashboard-dist/PopoverPopup-B6eMOlOC.js +1 -0
  6. package/dashboard-dist/api-reference-wTdT1AVt.js +260 -0
  7. package/dashboard-dist/app.css +2 -0
  8. package/dashboard-dist/app.js +18 -0
  9. package/dashboard-dist/core-CHWYtApw.js +1 -0
  10. package/dashboard-dist/docs-DflzpIIh.js +4 -0
  11. package/dashboard-dist/docs.css +1 -0
  12. package/dashboard-dist/preload-helper-CVJ-D494.js +1 -0
  13. package/dashboard-dist/react-jsx-runtime.js +4 -0
  14. package/dashboard-dist/react.js +3 -0
  15. package/dashboard-dist/rolldown-runtime-XKyaHtl9.js +1 -0
  16. package/dist/bin.d.ts.map +1 -1
  17. package/dist/bin.js +17 -6
  18. package/dist/bin.js.map +1 -1
  19. package/dist/dev-reporter.d.ts +15 -0
  20. package/dist/dev-reporter.d.ts.map +1 -0
  21. package/dist/dev-reporter.js +28 -0
  22. package/dist/dev-reporter.js.map +1 -0
  23. package/dist/dev-telemetry-store.js +1897 -0
  24. package/dist/dev-telemetry-store.js.map +1 -0
  25. package/dist/dev-telemetry.js +199 -0
  26. package/dist/dev-telemetry.js.map +1 -0
  27. package/dist/dev-worker.js +54 -9
  28. package/dist/dev-worker.js.map +1 -1
  29. package/dist/index.d.ts +24 -0
  30. package/dist/index.d.ts.map +1 -1
  31. package/dist/runner.js +157 -8
  32. package/dist/runner.js.map +1 -1
  33. package/dist/vite.d.ts +11 -0
  34. package/dist/vite.d.ts.map +1 -1
  35. package/dist/vite.js +104 -6
  36. package/dist/vite.js.map +1 -1
  37. package/package.json +42 -4
  38. package/dist/port-utils.js +0 -13
  39. package/dist/port-utils.js.map +0 -1
package/dist/vite.js CHANGED
@@ -1,19 +1,88 @@
1
+ import { i as startDevDashboard, n as DocsHost, o as openHistory, t as DevTelemetryStore } from "./dev-telemetry-store.js";
1
2
  import { n as requireBrickApp } from "./app-entry2.js";
2
3
  import { t as generateClientContract } from "./client-contract2.js";
3
4
  import { n as writeContractSource } from "./client-contract-file2.js";
4
- import { resolve } from "node:path";
5
+ import { getGlobalRegistry } from "@brickkit/core";
6
+ import { fileURLToPath } from "node:url";
7
+ import { dirname, resolve } from "node:path";
5
8
  import { createServer, isRunnableDevEnvironment, normalizePath } from "vite";
6
9
  import { ModuleRunner } from "vite/module-runner";
10
+ //#region src/dev-vite-dashboard.ts
11
+ /**
12
+ * Serve the dashboard from inside the Vite dev server. Dev servers run the app
13
+ * in a worker, which reports its spans here over HTTP. This process keeps the
14
+ * history, so it survives worker restarts.
15
+ */
16
+ async function startViteDashboard(options) {
17
+ const history = await openHistory({
18
+ directory: options.directory,
19
+ days: options.historyDays ?? 90,
20
+ warn: (message) => options.logger.warn(message)
21
+ });
22
+ const store = new DevTelemetryStore({ history });
23
+ const docs = new DocsHost(store, (message) => options.logger.warn(message));
24
+ let dashboard;
25
+ try {
26
+ dashboard = await startDevDashboard({
27
+ port: options.port ?? 9400,
28
+ store,
29
+ history,
30
+ docs: () => docs.current
31
+ });
32
+ } catch (error) {
33
+ history?.close();
34
+ const reason = error instanceof Error ? error.message : String(error);
35
+ options.logger.warn(`[Brick-TS] ${reason} Continuing without the dashboard.`);
36
+ return;
37
+ }
38
+ options.logger.info(` ➜ Brick dashboard: http://127.0.0.1:${dashboard.port}`);
39
+ let stopped = false;
40
+ let origin;
41
+ let documents;
42
+ let loads = 0;
43
+ const publishDocuments = () => {
44
+ if (documents) store.setApiDocuments(documents, origin);
45
+ };
46
+ return {
47
+ ingestUrl: `http://127.0.0.1:${dashboard.port}/api/ingest`,
48
+ architecture(app) {
49
+ store.setArchitecture(getGlobalRegistry().exportArchitecture(app.definition), store.latestGeneration);
50
+ docs.configure(dirname(options.entry), app.definition.documentation);
51
+ const load = ++loads;
52
+ app.referenceDocuments().then((loaded) => {
53
+ if (load !== loads || stopped) return;
54
+ documents = loaded;
55
+ publishDocuments();
56
+ }, (error) => options.logger.warn(`[Brick-TS] Could not load the API documents: ${error instanceof Error ? error.message : String(error)}`));
57
+ },
58
+ origin(url) {
59
+ origin = url;
60
+ publishDocuments();
61
+ },
62
+ stop() {
63
+ if (stopped) return;
64
+ stopped = true;
65
+ dashboard.stop();
66
+ docs.close();
67
+ history?.close();
68
+ }
69
+ };
70
+ }
71
+ //#endregion
7
72
  //#region src/vite.ts
8
73
  /** Load a BrickApp through Vite's server module graph, including dependency HMR. */
9
74
  function brickClient(options) {
10
75
  const virtualId = "virtual:brick-app";
11
76
  const resolvedId = "\0" + virtualId;
77
+ const reporterId = "virtual:brick-dev-reporter";
78
+ const resolvedReporterId = "\0" + reporterId;
79
+ const reporterModule = fileURLToPath(new URL(import.meta.url.endsWith(".ts") ? "./dev-reporter.ts" : "./dev-reporter.js", import.meta.url));
12
80
  let entry;
13
81
  let output;
14
82
  let config;
15
83
  let buildGeneration;
16
84
  let runner;
85
+ let dashboard;
17
86
  let reload = Promise.resolve();
18
87
  const dependencies = /* @__PURE__ */ new Set();
19
88
  let revision = 0;
@@ -44,7 +113,27 @@ function brickClient(options) {
44
113
  hmr: false,
45
114
  transport: { invoke: (payload) => environment.hot.handleInvoke(payload) }
46
115
  });
47
- await writeContract((await runner.import(entry)).default);
116
+ if (options.dashboard !== false) {
117
+ const started = await startViteDashboard({
118
+ port: options.dashboard?.port,
119
+ historyDays: options.dashboard?.historyDays,
120
+ directory: server.config.root,
121
+ entry,
122
+ logger: server.config.logger
123
+ });
124
+ dashboard = started;
125
+ server.httpServer?.once("close", () => started?.stop());
126
+ server.httpServer?.once("listening", () => {
127
+ const address = server.httpServer?.address();
128
+ if (address && typeof address === "object") {
129
+ const scheme = server.config.server.https ? "https" : "http";
130
+ started?.origin(`${scheme}://localhost:${address.port}`);
131
+ }
132
+ });
133
+ }
134
+ const app = (await runner.import(entry)).default;
135
+ await writeContract(app);
136
+ dashboard?.architecture(requireBrickApp(app));
48
137
  dependencies.clear();
49
138
  collectDependencies(environment.moduleGraph.getModuleById(entry));
50
139
  dependencies.add(entry);
@@ -74,7 +163,9 @@ function brickClient(options) {
74
163
  changedFiles.clear();
75
164
  invalidate(entry);
76
165
  try {
77
- await writeContract((await currentRunner.import(entry)).default);
166
+ const app = (await currentRunner.import(entry)).default;
167
+ await writeContract(app);
168
+ dashboard?.architecture(requireBrickApp(app));
78
169
  } finally {
79
170
  collectDependencies(this.environment.moduleGraph.getModuleById(entry));
80
171
  }
@@ -86,6 +177,7 @@ function brickClient(options) {
86
177
  },
87
178
  async closeBundle() {
88
179
  await runner?.close();
180
+ dashboard?.stop();
89
181
  },
90
182
  async buildStart() {
91
183
  if (config.command !== "build") return;
@@ -116,13 +208,19 @@ function brickClient(options) {
116
208
  await buildGeneration;
117
209
  },
118
210
  resolveId(id) {
119
- if (id !== virtualId) return;
211
+ if (id !== virtualId && id !== reporterId) return;
120
212
  if (this.environment.config.consumer === "client") throw new Error("Brick: virtual:brick-app is server-only; never import the backend app in the browser.");
121
- return resolvedId;
213
+ return id === virtualId ? resolvedId : resolvedReporterId;
122
214
  },
123
215
  load(id) {
216
+ if (id === resolvedReporterId) {
217
+ if (!dashboard) return "";
218
+ return `import { installDevReporter } from ${JSON.stringify(reporterModule)};
219
+ installDevReporter({ url: ${JSON.stringify(dashboard.ingestUrl)} });
220
+ `;
221
+ }
124
222
  if (id !== resolvedId) return;
125
- return `import app from ${JSON.stringify(entry)};
223
+ return `${dashboard ? `import ${JSON.stringify(reporterId)};\n` : ""}import app from ${JSON.stringify(entry)};
126
224
  if (!app || typeof app.fetch !== "function" || typeof app.endpoint !== "function") {
127
225
  throw new Error("Brick: the entry module must default-export a BrickApp created by brick().");
128
226
  }
package/dist/vite.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"vite.js","names":[],"sources":["../src/vite.ts"],"sourcesContent":["import { resolve } from \"node:path\";\nimport { writeContractSource } from \"./client-contract-file\";\nimport {\n createServer,\n isRunnableDevEnvironment,\n normalizePath,\n type Plugin,\n type ResolvedConfig,\n type EnvironmentModuleNode,\n} from \"vite\";\nimport { generateClientContract } from \"./client-contract\";\nimport { requireBrickApp } from \"./app-entry\";\nimport { ModuleRunner } from \"vite/module-runner\";\n\nexport interface BrickClientPluginOptions {\n /** Any module whose default export is a BrickApp; do not call listen() there. */\n entry: string;\n /** Generated browser contract, relative to the Vite root (default _brick/contract.ts). */\n output?: string;\n}\n\n/** Load a BrickApp through Vite's server module graph, including dependency HMR. */\nexport function brickClient(options: BrickClientPluginOptions): Plugin {\n const virtualId = \"virtual:brick-app\";\n const resolvedId = \"\\0\" + virtualId;\n let entry: string;\n let output: string;\n let config: ResolvedConfig;\n let buildGeneration: Promise<void> | undefined;\n let runner: ModuleRunner | undefined;\n let reload = Promise.resolve();\n const dependencies = new Set<string>();\n let revision = 0;\n const changedFiles = new Set<string>();\n\n async function writeContract(value: unknown) {\n const source = generateClientContract(requireBrickApp(value));\n await writeContractSource(output, source);\n }\n\n function collectDependencies(\n node: EnvironmentModuleNode | undefined,\n seen = new Set<EnvironmentModuleNode>(),\n ) {\n if (!node || seen.has(node)) return;\n seen.add(node);\n if (node.file) dependencies.add(node.file);\n for (const imported of node.importedModules)\n collectDependencies(imported, seen);\n }\n\n return {\n name: \"brick:client\",\n enforce: \"pre\",\n configResolved(resolved) {\n config = resolved;\n entry = normalizePath(resolve(config.root, options.entry));\n output = normalizePath(\n resolve(config.root, options.output ?? \"_brick/contract.ts\"),\n );\n if (entry === output)\n throw new Error(\n \"Brick: contract output must not overwrite the app entry.\",\n );\n },\n async configureServer(server) {\n const environment = server.environments.ssr;\n if (!environment)\n throw new Error(\n \"Brick: client generation requires a Vite SSR environment.\",\n );\n // Frameworks such as Start own their SSR runner. Use an independent runner\n // on the same transform graph to read app metadata without changing theirs.\n runner = new ModuleRunner({\n hmr: false,\n transport: {\n invoke: (payload) => environment.hot.handleInvoke(payload),\n },\n });\n await writeContract((await runner.import(entry)).default);\n dependencies.clear();\n collectDependencies(environment.moduleGraph.getModuleById(entry));\n dependencies.add(entry);\n },\n async hotUpdate(context) {\n if (\n this.environment.name !== \"ssr\" ||\n !dependencies.has(context.file) ||\n context.file === output\n )\n return;\n if (!runner) return;\n const currentRunner = runner;\n const currentRevision = ++revision;\n changedFiles.add(context.file);\n reload = reload\n .catch(() => {})\n .then(async () => {\n await new Promise((done) => setTimeout(done, 30));\n if (currentRevision !== revision) return;\n for (const module of context.modules)\n this.environment.moduleGraph.invalidateModule(module);\n const graph = currentRunner.evaluatedModules;\n const seen = new Set<string>();\n const invalidate = (id: string) => {\n if (seen.has(id)) return;\n seen.add(id);\n const node = graph.getModuleById(id);\n if (!node) return;\n for (const importer of node.importers) invalidate(importer);\n // Registration modules mutate imported services. Reevaluate their\n // dependencies too so removed actions cannot survive in a singleton.\n for (const imported of node.imports) invalidate(imported);\n graph.invalidateModule(node);\n };\n for (const file of changedFiles) {\n for (const node of graph.getModulesByFile(file) ?? [])\n invalidate(node.id);\n }\n changedFiles.clear();\n invalidate(entry);\n try {\n await writeContract((await currentRunner.import(entry)).default);\n } finally {\n collectDependencies(\n this.environment.moduleGraph.getModuleById(entry),\n );\n }\n dependencies.clear();\n collectDependencies(\n this.environment.moduleGraph.getModuleById(entry),\n );\n dependencies.add(entry);\n });\n await reload;\n },\n async closeBundle() {\n await runner?.close();\n },\n async buildStart() {\n if (config.command !== \"build\") return;\n buildGeneration ??= (async () => {\n // Evaluate the server entry through Vite's TS/alias resolver before client compilation.\n // This loader has no app plugins, so it cannot recursively trigger generation.\n const loader = await createServer({\n configFile: false,\n root: config.root,\n mode: config.mode,\n envDir: config.envDir,\n base: config.base,\n define: config.define,\n logLevel: \"silent\",\n resolve: { alias: config.resolve.alias },\n ssr: config.ssr,\n server: { middlewareMode: true, watch: null },\n });\n try {\n const environment = loader.environments.ssr;\n if (!environment || !isRunnableDevEnvironment(environment))\n throw new Error(\"Brick: missing build-time SSR loader.\");\n await writeContract((await environment.runner.import(entry)).default);\n } finally {\n await loader.close();\n }\n })();\n await buildGeneration;\n },\n resolveId(id) {\n if (id !== virtualId) return;\n if (this.environment.config.consumer === \"client\") {\n throw new Error(\n \"Brick: virtual:brick-app is server-only; never import the backend app in the browser.\",\n );\n }\n return resolvedId;\n },\n load(id) {\n if (id !== resolvedId) return;\n return `import app from ${JSON.stringify(entry)};\nif (!app || typeof app.fetch !== \"function\" || typeof app.endpoint !== \"function\") {\n throw new Error(\"Brick: the entry module must default-export a BrickApp created by brick().\");\n}\nexport default app;\n`;\n },\n };\n}\n"],"mappings":";;;;;;;;AAsBA,SAAgB,YAAY,SAA2C;CACrE,MAAM,YAAY;CAClB,MAAM,aAAa,OAAO;CAC1B,IAAI;CACJ,IAAI;CACJ,IAAI;CACJ,IAAI;CACJ,IAAI;CACJ,IAAI,SAAS,QAAQ,QAAQ;CAC7B,MAAM,+BAAe,IAAI,IAAY;CACrC,IAAI,WAAW;CACf,MAAM,+BAAe,IAAI,IAAY;CAErC,eAAe,cAAc,OAAgB;EAC3C,MAAM,SAAS,uBAAuB,gBAAgB,KAAK,CAAC;EAC5D,MAAM,oBAAoB,QAAQ,MAAM;CAC1C;CAEA,SAAS,oBACP,MACA,uBAAO,IAAI,IAA2B,GACtC;EACA,IAAI,CAAC,QAAQ,KAAK,IAAI,IAAI,GAAG;EAC7B,KAAK,IAAI,IAAI;EACb,IAAI,KAAK,MAAM,aAAa,IAAI,KAAK,IAAI;EACzC,KAAK,MAAM,YAAY,KAAK,iBAC1B,oBAAoB,UAAU,IAAI;CACtC;CAEA,OAAO;EACL,MAAM;EACN,SAAS;EACT,eAAe,UAAU;GACvB,SAAS;GACT,QAAQ,cAAc,QAAQ,OAAO,MAAM,QAAQ,KAAK,CAAC;GACzD,SAAS,cACP,QAAQ,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;CACF;AACF"}
1
+ {"version":3,"file":"vite.js","names":[],"sources":["../src/dev-vite-dashboard.ts","../src/vite.ts"],"sourcesContent":["import { dirname } from \"node:path\";\nimport {\n getGlobalRegistry,\n type ApiDocument,\n type BrickApp,\n} from \"@brickkit/core\";\nimport {\n DEFAULT_DASHBOARD_PORT,\n startDevDashboard,\n type DevDashboard,\n} from \"./dev-dashboard\";\nimport { DocsHost } from \"./dev-docs\";\nimport { DEFAULT_HISTORY_DAYS, openHistory } from \"./dev-history\";\nimport { DevTelemetryStore } from \"./dev-telemetry-store\";\n\nexport interface DashboardLogger {\n info(message: string): void;\n warn(message: string): void;\n}\n\nexport interface ViteDashboard {\n /** Where the app reports its spans; see installDevReporter. */\n readonly ingestUrl: string;\n /** Record the architecture of the application module Vite loaded. */\n architecture(app: BrickApp): void;\n /** Where the dev server is reachable, once it is listening. */\n origin(url: string): void;\n stop(): void;\n}\n\n/**\n * Serve the dashboard from inside the Vite dev server. Dev servers run the app\n * in a worker, which reports its spans here over HTTP. This process keeps the\n * history, so it survives worker restarts.\n */\nexport async function startViteDashboard(options: {\n port?: number;\n /** The project folder; history is kept in `.brick/` inside it. */\n directory: string;\n /** The app entry module; the paths in `documentation` start at its folder. */\n entry: string;\n /** Days of requests to keep on disk; zero for none. */\n historyDays?: number;\n logger: DashboardLogger;\n}): Promise<ViteDashboard | undefined> {\n const history = await openHistory({\n directory: options.directory,\n days: options.historyDays ?? DEFAULT_HISTORY_DAYS,\n warn: (message) => options.logger.warn(message),\n });\n const store = new DevTelemetryStore({ history });\n const docs = new DocsHost(store, (message) => options.logger.warn(message));\n let dashboard: DevDashboard;\n try {\n dashboard = await startDevDashboard({\n port: options.port ?? DEFAULT_DASHBOARD_PORT,\n store,\n history,\n docs: () => docs.current,\n });\n } catch (error) {\n history?.close();\n const reason = error instanceof Error ? error.message : String(error);\n options.logger.warn(\n `[Brick-TS] ${reason} Continuing without the dashboard.`,\n );\n return undefined;\n }\n options.logger.info(\n ` ➜ Brick dashboard: http://127.0.0.1:${dashboard.port}`,\n );\n\n let stopped = false;\n let origin: string | undefined;\n let documents: ApiDocument[] | undefined;\n let loads = 0;\n // The server starts listening after the app first loads, so the documents\n // are published again once its address is known.\n const publishDocuments = () => {\n if (documents) store.setApiDocuments(documents, origin);\n };\n return {\n ingestUrl: `http://127.0.0.1:${dashboard.port}/api/ingest`,\n architecture(app) {\n store.setArchitecture(\n getGlobalRegistry().exportArchitecture(app.definition),\n store.latestGeneration,\n );\n void docs.configure(dirname(options.entry), app.definition.documentation);\n // A later load supersedes this one if it finishes first.\n const load = ++loads;\n app.referenceDocuments().then(\n (loaded) => {\n if (load !== loads || stopped) return;\n documents = loaded;\n publishDocuments();\n },\n (error: unknown) =>\n options.logger.warn(\n `[Brick-TS] Could not load the API documents: ${error instanceof Error ? error.message : String(error)}`,\n ),\n );\n },\n origin(url) {\n origin = url;\n publishDocuments();\n },\n stop() {\n if (stopped) return;\n stopped = true;\n dashboard.stop();\n docs.close();\n history?.close();\n },\n };\n}\n","import { resolve } from \"node:path\";\nimport { fileURLToPath } from \"node:url\";\nimport { writeContractSource } from \"./client-contract-file\";\nimport {\n createServer,\n isRunnableDevEnvironment,\n normalizePath,\n type Plugin,\n type ResolvedConfig,\n type EnvironmentModuleNode,\n} from \"vite\";\nimport { generateClientContract } from \"./client-contract\";\nimport { requireBrickApp } from \"./app-entry\";\nimport { startViteDashboard, type ViteDashboard } from \"./dev-vite-dashboard\";\nimport { ModuleRunner } from \"vite/module-runner\";\n\nexport interface BrickClientPluginOptions {\n /** Any module whose default export is a BrickApp; do not call listen() there. */\n entry: string;\n /** Generated browser contract, relative to the Vite root (default _brick/contract.ts). */\n output?: string;\n /**\n * Local dashboard for the app's requests, traces, errors, and reloads, served\n * during `vite dev` (default: on at port 9400). Apps must pass\n * `telemetry: true` to brick() to record requests. `historyDays` is how long\n * finished requests are kept in `.brick/` (default 90, 0 for none). Set to\n * false to disable.\n */\n dashboard?: { port?: number; historyDays?: number } | false;\n}\n\n/** Load a BrickApp through Vite's server module graph, including dependency HMR. */\nexport function brickClient(options: BrickClientPluginOptions): Plugin {\n const virtualId = \"virtual:brick-app\";\n const resolvedId = \"\\0\" + virtualId;\n const reporterId = \"virtual:brick-dev-reporter\";\n const resolvedReporterId = \"\\0\" + reporterId;\n // Imported by file path: the package name may not resolve from the app's root.\n const reporterModule = fileURLToPath(\n new URL(\n import.meta.url.endsWith(\".ts\")\n ? \"./dev-reporter.ts\"\n : \"./dev-reporter.js\",\n import.meta.url,\n ),\n );\n let entry: string;\n let output: string;\n let config: ResolvedConfig;\n let buildGeneration: Promise<void> | undefined;\n let runner: ModuleRunner | undefined;\n let dashboard: ViteDashboard | undefined;\n let reload = Promise.resolve();\n const dependencies = new Set<string>();\n let revision = 0;\n const changedFiles = new Set<string>();\n\n async function writeContract(value: unknown) {\n const source = generateClientContract(requireBrickApp(value));\n await writeContractSource(output, source);\n }\n\n function collectDependencies(\n node: EnvironmentModuleNode | undefined,\n seen = new Set<EnvironmentModuleNode>(),\n ) {\n if (!node || seen.has(node)) return;\n seen.add(node);\n if (node.file) dependencies.add(node.file);\n for (const imported of node.importedModules)\n collectDependencies(imported, seen);\n }\n\n return {\n name: \"brick:client\",\n enforce: \"pre\",\n configResolved(resolved) {\n config = resolved;\n entry = normalizePath(resolve(config.root, options.entry));\n output = normalizePath(\n resolve(config.root, options.output ?? \"_brick/contract.ts\"),\n );\n if (entry === output)\n throw new Error(\n \"Brick: contract output must not overwrite the app entry.\",\n );\n },\n async configureServer(server) {\n const environment = server.environments.ssr;\n if (!environment)\n throw new Error(\n \"Brick: client generation requires a Vite SSR environment.\",\n );\n // Frameworks such as Start own their SSR runner. Use an independent runner\n // on the same transform graph to read app metadata without changing theirs.\n runner = new ModuleRunner({\n hmr: false,\n transport: {\n invoke: (payload) => environment.hot.handleInvoke(payload),\n },\n });\n // The dashboard starts before the app is evaluated, so its tracer is\n // registered before the app's first request can be made.\n if (options.dashboard !== false) {\n const started = await startViteDashboard({\n port: options.dashboard?.port,\n historyDays: options.dashboard?.historyDays,\n directory: server.config.root,\n entry,\n logger: server.config.logger,\n });\n dashboard = started;\n server.httpServer?.once(\"close\", () => started?.stop());\n server.httpServer?.once(\"listening\", () => {\n const address = server.httpServer?.address();\n if (address && typeof address === \"object\") {\n const scheme = server.config.server.https ? \"https\" : \"http\";\n started?.origin(`${scheme}://localhost:${address.port}`);\n }\n });\n }\n const app = (await runner.import(entry)).default;\n await writeContract(app);\n dashboard?.architecture(requireBrickApp(app));\n dependencies.clear();\n collectDependencies(environment.moduleGraph.getModuleById(entry));\n dependencies.add(entry);\n },\n async hotUpdate(context) {\n if (\n this.environment.name !== \"ssr\" ||\n !dependencies.has(context.file) ||\n context.file === output\n )\n return;\n if (!runner) return;\n const currentRunner = runner;\n const currentRevision = ++revision;\n changedFiles.add(context.file);\n reload = reload\n .catch(() => {})\n .then(async () => {\n await new Promise((done) => setTimeout(done, 30));\n if (currentRevision !== revision) return;\n for (const module of context.modules)\n this.environment.moduleGraph.invalidateModule(module);\n const graph = currentRunner.evaluatedModules;\n const seen = new Set<string>();\n const invalidate = (id: string) => {\n if (seen.has(id)) return;\n seen.add(id);\n const node = graph.getModuleById(id);\n if (!node) return;\n for (const importer of node.importers) invalidate(importer);\n // Registration modules mutate imported services. Reevaluate their\n // dependencies too so removed actions cannot survive in a singleton.\n for (const imported of node.imports) invalidate(imported);\n graph.invalidateModule(node);\n };\n for (const file of changedFiles) {\n for (const node of graph.getModulesByFile(file) ?? [])\n invalidate(node.id);\n }\n changedFiles.clear();\n invalidate(entry);\n try {\n const app = (await currentRunner.import(entry)).default;\n await writeContract(app);\n dashboard?.architecture(requireBrickApp(app));\n } finally {\n collectDependencies(\n this.environment.moduleGraph.getModuleById(entry),\n );\n }\n dependencies.clear();\n collectDependencies(\n this.environment.moduleGraph.getModuleById(entry),\n );\n dependencies.add(entry);\n });\n await reload;\n },\n async closeBundle() {\n await runner?.close();\n dashboard?.stop();\n },\n async buildStart() {\n if (config.command !== \"build\") return;\n buildGeneration ??= (async () => {\n // Evaluate the server entry through Vite's TS/alias resolver before client compilation.\n // This loader has no app plugins, so it cannot recursively trigger generation.\n const loader = await createServer({\n configFile: false,\n root: config.root,\n mode: config.mode,\n envDir: config.envDir,\n base: config.base,\n define: config.define,\n logLevel: \"silent\",\n resolve: { alias: config.resolve.alias },\n ssr: config.ssr,\n server: { middlewareMode: true, watch: null },\n });\n try {\n const environment = loader.environments.ssr;\n if (!environment || !isRunnableDevEnvironment(environment))\n throw new Error(\"Brick: missing build-time SSR loader.\");\n await writeContract((await environment.runner.import(entry)).default);\n } finally {\n await loader.close();\n }\n })();\n await buildGeneration;\n },\n resolveId(id) {\n if (id !== virtualId && id !== reporterId) return;\n if (this.environment.config.consumer === \"client\") {\n throw new Error(\n \"Brick: virtual:brick-app is server-only; never import the backend app in the browser.\",\n );\n }\n return id === virtualId ? resolvedId : resolvedReporterId;\n },\n load(id) {\n if (id === resolvedReporterId) {\n // The app imports the reporter only while the dashboard is running.\n if (!dashboard) return \"\";\n return `import { installDevReporter } from ${JSON.stringify(reporterModule)};\ninstallDevReporter({ url: ${JSON.stringify(dashboard.ingestUrl)} });\n`;\n }\n if (id !== resolvedId) return;\n // The reporter is imported first so tracing is installed before the app is built.\n const reporter = dashboard\n ? `import ${JSON.stringify(reporterId)};\\n`\n : \"\";\n return `${reporter}import app from ${JSON.stringify(entry)};\nif (!app || typeof app.fetch !== \"function\" || typeof app.endpoint !== \"function\") {\n throw new Error(\"Brick: the entry module must default-export a BrickApp created by brick().\");\n}\nexport default app;\n`;\n },\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;AAmCA,eAAsB,mBAAmB,SASF;CACrC,MAAM,UAAU,MAAM,YAAY;EAChC,WAAW,QAAQ;EACnB,MAAM,QAAQ,eAAA;EACd,OAAO,YAAY,QAAQ,OAAO,KAAK,OAAO;CAChD,CAAC;CACD,MAAM,QAAQ,IAAI,kBAAkB,EAAE,QAAQ,CAAC;CAC/C,MAAM,OAA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;GAEF,OAAO,OAAO,YAAY,aAAa;EACzC;EACA,KAAK,IAAI;GACP,IAAI,OAAO,oBAAoB;IAE7B,IAAI,CAAC,WAAW,OAAO;IACvB,OAAO,sCAAsC,KAAK,UAAU,cAAc,EAAE;4BACxD,KAAK,UAAU,UAAU,SAAS,EAAE;;GAE1D;GACA,IAAI,OAAO,YAAY;GAKvB,OAAO,GAHU,YACb,UAAU,KAAK,UAAU,UAAU,EAAE,OACrC,GACe,kBAAkB,KAAK,UAAU,KAAK,EAAE;;;;;;EAM7D;CACF;AACF"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@brickkit/cli",
3
- "version": "0.7.3",
3
+ "version": "0.8.0",
4
4
  "description": "CLI and server engine for Brick-TS",
5
5
  "keywords": [
6
6
  "typescript",
@@ -31,6 +31,10 @@
31
31
  "import": "./dist/compiler.js",
32
32
  "types": "./dist/compiler.d.ts"
33
33
  },
34
+ "./dev-reporter": {
35
+ "import": "./dist/dev-reporter.js",
36
+ "types": "./dist/dev-reporter.d.ts"
37
+ },
34
38
  "./vite": {
35
39
  "import": "./dist/vite.js",
36
40
  "types": "./dist/vite.d.ts"
@@ -44,6 +48,7 @@
44
48
  },
45
49
  "files": [
46
50
  "dist",
51
+ "dashboard-dist",
47
52
  "vite-client.d.ts"
48
53
  ],
49
54
  "repository": {
@@ -52,32 +57,65 @@
52
57
  "directory": "packages/cli"
53
58
  },
54
59
  "scripts": {
55
- "build": "tsdown",
60
+ "build": "bun scripts/build-dashboard.ts && tsdown",
56
61
  "prepublishOnly": "bun run build",
57
- "typecheck": "tsc --noEmit -p tsconfig.build.json",
62
+ "typecheck": "tsc --noEmit -p tsconfig.build.json && tsc --noEmit -p dashboard/tsconfig.json",
58
63
  "lint": "oxlint .",
59
64
  "lint:fix": "oxlint --fix .",
60
65
  "format": "oxfmt .",
61
66
  "format:check": "oxfmt --check ."
62
67
  },
63
68
  "dependencies": {
64
- "@brickkit/core": "^0.7.3",
69
+ "@brickkit/core": "^0.8.0",
70
+ "@opentelemetry/api": "^1.9.1",
71
+ "@opentelemetry/context-async-hooks": "^2.12.0",
72
+ "@opentelemetry/core": "^2.12.0",
73
+ "@opentelemetry/sdk-trace-base": "^2.12.0",
65
74
  "@sinclair/typebox": "^0.34.52",
66
75
  "commander": "^15.0.0",
67
76
  "elysia": "2.0.0-beta.29"
68
77
  },
69
78
  "devDependencies": {
79
+ "@base-ui/react": "^1.9.0",
80
+ "@fumadocs/base-ui": "16.17.2",
81
+ "@mdx-js/mdx": "^3.1.1",
82
+ "@tailwindcss/vite": "^4.3.3",
70
83
  "@types/bun": "^1.4.3",
84
+ "@types/react": "^19.3.0",
85
+ "@types/react-dom": "^19.3.0",
86
+ "@vitejs/plugin-react": "^6.1.2",
87
+ "class-variance-authority": "^0.7.1",
88
+ "clsx": "^2.1.1",
89
+ "fumadocs-core": "16.17.2",
90
+ "fumadocs-openapi": "12.5.2",
91
+ "fumadocs-ui": "npm:@fumadocs/base-ui@16.17.2",
92
+ "geist": "^1.8.1",
93
+ "lucide-react": "^1.56.0",
71
94
  "oxfmt": "^0.73.0",
72
95
  "oxlint": "^1.88.0",
96
+ "react": "^19.3.0",
97
+ "react-dom": "^19.3.0",
98
+ "shadcn": "^4.22.0",
99
+ "shiki": "^4.5.0",
100
+ "tailwind-merge": "^3.7.0",
101
+ "tailwindcss": "^4.3.3",
73
102
  "tsdown": "^0.23.1",
103
+ "tw-animate-css": "^1.4.0",
74
104
  "typescript": "^5.7.0",
75
105
  "vite": "^8.3.4"
76
106
  },
77
107
  "peerDependencies": {
108
+ "@mdx-js/mdx": "^3.0.0",
109
+ "fumadocs-core": "^16.0.0",
78
110
  "vite": "^8.0.0"
79
111
  },
80
112
  "peerDependenciesMeta": {
113
+ "@mdx-js/mdx": {
114
+ "optional": true
115
+ },
116
+ "fumadocs-core": {
117
+ "optional": true
118
+ },
81
119
  "vite": {
82
120
  "optional": true
83
121
  }
@@ -1,13 +0,0 @@
1
- //#region src/port-utils.ts
2
- function parsePort(portStr, envPort) {
3
- let port;
4
- if (portStr !== void 0) port = Number(portStr);
5
- else if (envPort !== void 0 && envPort !== "") port = Number(envPort);
6
- else port = 4e3;
7
- if (!Number.isInteger(port) || port < 1 || port > 65535) throw new Error(`Invalid port: ${port}. Port must be an integer between 1 and 65535`);
8
- return port;
9
- }
10
- //#endregion
11
- export { parsePort as t };
12
-
13
- //# sourceMappingURL=port-utils.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"port-utils.js","names":[],"sources":["../src/port-utils.ts"],"sourcesContent":["export function parsePort(\n portStr: string | undefined,\n envPort?: string | undefined,\n): number {\n let port: number | undefined;\n if (portStr !== undefined) {\n port = Number(portStr);\n } else if (envPort !== undefined && envPort !== \"\") {\n port = Number(envPort);\n } else {\n port = 4000;\n }\n\n if (!Number.isInteger(port) || port < 1 || port > 65535) {\n throw new Error(\n `Invalid port: ${port}. Port must be an integer between 1 and 65535`,\n );\n }\n return port;\n}\n"],"mappings":";AAAA,SAAgB,UACd,SACA,SACQ;CACR,IAAI;CACJ,IAAI,YAAY,KAAA,GACd,OAAO,OAAO,OAAO;MAChB,IAAI,YAAY,KAAA,KAAa,YAAY,IAC9C,OAAO,OAAO,OAAO;MAErB,OAAO;CAGT,IAAI,CAAC,OAAO,UAAU,IAAI,KAAK,OAAO,KAAK,OAAO,OAChD,MAAM,IAAI,MACR,iBAAiB,KAAK,8CACxB;CAEF,OAAO;AACT"}