@brickkit/cli 0.11.0 → 0.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dashboard-dist/CollapsiblePanel-CbUysOp5.js +2 -0
- package/dashboard-dist/CompositeRoot-D4sRkYq3.js +1 -0
- package/dashboard-dist/Geist-Variable.woff2 +0 -0
- package/dashboard-dist/GeistMono-Variable.woff2 +0 -0
- package/dashboard-dist/PopoverPopup-CiI2avT_.js +1 -0
- package/dashboard-dist/api-reference-B-bZRtNV.js +265 -0
- package/dashboard-dist/app.css +2 -2
- package/dashboard-dist/app.js +11 -11
- package/dashboard-dist/ccount-CcG1m-Yh.js +1 -0
- package/dashboard-dist/client-BJJtVSVr.js +1 -0
- package/dashboard-dist/core-Z7NJFk0K.js +1 -0
- package/dashboard-dist/docs-Dpfc0wJb.js +4 -0
- package/dashboard-dist/docs.css +1 -1
- package/dashboard-dist/kit.js +1 -1
- package/dashboard-dist/popover-BzejBolB.js +1 -0
- package/dist/app-entry2.js +2 -3
- package/dist/bin.d.ts +0 -2
- package/dist/bin.js +173 -12
- package/dist/bin.js.map +1 -1
- package/dist/client-contract-file2.js +1 -2
- package/dist/client-contract2.js +6 -4
- package/dist/client-contract2.js.map +1 -1
- package/dist/compiler.d.ts +1 -2
- package/dist/compiler.js +1 -1
- package/dist/compiler2.js +3 -4
- package/dist/config.js +5 -7
- package/dist/config.js.map +1 -1
- package/dist/dashboard-extension.d.ts +0 -2
- package/dist/dashboard.d.ts +4 -134
- package/dist/dev-reporter.d.ts +0 -2
- package/dist/dev-reporter.js +1 -2
- package/dist/dev-telemetry-store.js +9 -19
- package/dist/dev-telemetry-store.js.map +1 -1
- package/dist/dev-telemetry.js +3 -4
- package/dist/dev-telemetry.js.map +1 -1
- package/dist/dev-worker.js +1 -2
- package/dist/emit.d.ts +0 -2
- package/dist/index.d.ts +7 -17
- package/dist/index.js +3 -4
- package/dist/lint/oxlint.d.ts +0 -2
- package/dist/lint/oxlint.js +1 -2
- package/dist/plugin.d.ts +0 -6
- package/dist/plugin.js +2 -4
- package/dist/plugin.js.map +1 -1
- package/dist/presets.js +3 -7
- package/dist/presets.js.map +1 -1
- package/dist/runner.js +5 -9
- package/dist/runner.js.map +1 -1
- package/dist/vite.d.ts +0 -2
- package/dist/vite.js +5 -7
- package/dist/vite.js.map +1 -1
- package/dist/workflows.d.ts +0 -2
- package/dist/workflows2.js +2 -3
- package/inspector-dist/client/assets/api.rpc-BvRk9kiK.js +0 -0
- package/inspector-dist/client/assets/api.stream._streamId-BvRk9kiK.js +0 -0
- package/inspector-dist/client/assets/app-CCzpuUz_.css +2 -0
- package/inspector-dist/client/assets/dist-BK8w6xOr.js +3930 -0
- package/inspector-dist/client/assets/dist-CG2aVufI.js +197 -0
- package/inspector-dist/client/assets/entry.client-D9jbgmTR.js +9391 -0
- package/inspector-dist/client/assets/highlighted-body-B3W2YXNL-DYVdwGy2.js +34 -0
- package/inspector-dist/client/assets/home-CyjkvtII.js +2883 -0
- package/inspector-dist/client/assets/jsx-runtime-CPEah4WQ.js +7084 -0
- package/inspector-dist/client/assets/manifest-ba30b52d.js +1 -0
- package/inspector-dist/client/assets/mermaid-3ZIDBTTL-Dy6IVqPy.js +1 -0
- package/inspector-dist/client/assets/root-8BMab1lL.css +2 -0
- package/inspector-dist/client/assets/root-DX9wtogx.js +332 -0
- package/inspector-dist/client/assets/run-detail-C69EJGql.js +1549 -0
- package/inspector-dist/client/assets/tabs-B6B88IjT.js +75692 -0
- package/inspector-dist/client/assets/tabs-L5XKzOpP.css +1 -0
- package/inspector-dist/client/assets/world-config-context-C3BqXPIv.js +30 -0
- package/inspector-dist/client/assets/zstd-browser-decoder-ByUgcY9H.js +41 -0
- package/inspector-dist/server/assets/app-WoDoT62X.js +100155 -0
- package/inspector-dist/server/assets/chunk-RLXIAIE6-CbvDIAEa.js +42977 -0
- package/inspector-dist/server/assets/dist-BRxZSWUN.js +1140 -0
- package/inspector-dist/server/assets/dist-CQnQcIJg.js +199 -0
- package/inspector-dist/server/assets/dist-DqRd9pyS.js +1644 -0
- package/inspector-dist/server/assets/dist-qR-969AD.js +10327 -0
- package/inspector-dist/server/assets/encryption-_PuklZNX.js +888 -0
- package/inspector-dist/server/assets/event-metadata-BVakQJ_y.js +147 -0
- package/inspector-dist/server/assets/functions-CImcpqNl.js +1172 -0
- package/inspector-dist/server/assets/global-singleton-CPirHxFh.js +82 -0
- package/inspector-dist/server/assets/highlighted-body-B3W2YXNL-fPMB_t7F.js +36 -0
- package/inspector-dist/server/assets/mermaid-3ZIDBTTL-bADXySE3.js +3 -0
- package/inspector-dist/server/assets/parse-D9Vvgzt9.js +471 -0
- package/inspector-dist/server/assets/rolldown-runtime-CLg409Sh.js +44 -0
- package/inspector-dist/server/assets/serialization-format-DDtsVTU1.js +478 -0
- package/inspector-dist/server/assets/token-BW4GdQZh.js +62 -0
- package/inspector-dist/server/assets/token-D6FXdkJT.js +57 -0
- package/inspector-dist/server/assets/token-util-BoNmi-wE.js +457 -0
- package/inspector-dist/server/assets/wrapper-wiqsGXcE.js +3626 -0
- package/inspector-dist/server/assets/ws-transport-DV7oG4mL.js +29478 -0
- package/inspector-dist/server/assets/zstd-browser-decoder-Cswf0KO6.js +40 -0
- package/inspector-dist/server/index.js +2 -57
- package/package.json +29 -28
- package/vite-client.d.ts +1 -1
- package/dashboard-dist/CollapsiblePanel-BX79_W-b.js +0 -2
- package/dashboard-dist/CompositeRoot-xzybXjnx.js +0 -1
- package/dashboard-dist/PopoverPopup-CvlmC7EL.js +0 -1
- package/dashboard-dist/api-reference-BcAYVYwJ.js +0 -260
- package/dashboard-dist/core-BGO9JZ1r.js +0 -1
- package/dashboard-dist/docs-DHikPD2v.js +0 -4
- package/dashboard-dist/popover-DG498XHH.js +0 -1
- package/dist/bin.d.ts.map +0 -1
- package/dist/dashboard-extension.d.ts.map +0 -1
- package/dist/dev-reporter.d.ts.map +0 -1
- package/dist/emit.d.ts.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/lint/oxlint.d.ts.map +0 -1
- package/dist/plugin.d.ts.map +0 -1
- package/dist/vite.d.ts.map +0 -1
- package/dist/workflows.d.ts.map +0 -1
- package/inspector-dist/client/assets/api.rpc-l0sNRNKZ.js +0 -1
- package/inspector-dist/client/assets/api.stream._streamId-l0sNRNKZ.js +0 -1
- package/inspector-dist/client/assets/app-CvoGgWcV.css +0 -1
- package/inspector-dist/client/assets/entry.client-BJ6G3n5t.js +0 -11697
- package/inspector-dist/client/assets/highlighted-body-B3W2YXNL-C-3wZnxf.js +0 -19
- package/inspector-dist/client/assets/home-CSKAS4P2.js +0 -4979
- package/inspector-dist/client/assets/index-DECCyMR0.js +0 -4482
- package/inspector-dist/client/assets/index-Dot7CgrA.js +0 -9837
- package/inspector-dist/client/assets/index-HqNj_XIX.js +0 -200
- package/inspector-dist/client/assets/manifest-139c9319.js +0 -1
- package/inspector-dist/client/assets/mermaid-3ZIDBTTL-DC0K8uTy.js +0 -58626
- package/inspector-dist/client/assets/mermaid-3ZIDBTTL-F88p7PFX.css +0 -1
- package/inspector-dist/client/assets/root-BMHd_XHz.css +0 -1
- package/inspector-dist/client/assets/root-cbi6iYwg.js +0 -305
- package/inspector-dist/client/assets/run-detail-CWoGxu_0.css +0 -1
- package/inspector-dist/client/assets/run-detail-Cc7tSGNq.js +0 -6237
- package/inspector-dist/client/assets/world-config-context-BAD1QCrR.js +0 -26
- package/inspector-dist/client/assets/zstd-browser-decoder-BQoRpP7L.js +0 -28
- package/inspector-dist/server/assets/app-DUP5RybL.js +0 -174880
- package/inspector-dist/server/assets/highlighted-body-B3W2YXNL-D2g4hL2-.js +0 -71
- package/inspector-dist/server/assets/index-BfLBLRRi.js +0 -204
- package/inspector-dist/server/assets/index-BzrGWk7J.js +0 -1164
- package/inspector-dist/server/assets/index-D71yP6AL.js +0 -191
- package/inspector-dist/server/assets/index-wGSWRns3.js +0 -1296
- package/inspector-dist/server/assets/mermaid-3ZIDBTTL-DsvuKoEV.js +0 -58
- package/inspector-dist/server/assets/token-ClUZZwXl.js +0 -95
- package/inspector-dist/server/assets/token-util-DSxMZ6nI.js +0 -33
- package/inspector-dist/server/assets/wrapper-B3vstpCO.js +0 -67
- package/inspector-dist/server/assets/zstd-browser-decoder-Dn82m2BU.js +0 -77
package/dist/runner.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runner.js","names":["existsSync","sep","existsSync","resolve"],"sources":["../src/port-utils.ts","../src/manifest.ts","../src/production-dashboard.ts","../src/runner.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\n/** The dev port: CLI flag, then PORT, then the config file, then 4000. */\nexport function resolveDevPort(\n cliPort: number | undefined,\n configPort?: number,\n envPort = process.env.PORT,\n): number {\n if (cliPort !== undefined) return cliPort;\n if (configPort !== undefined && !envPort) return configPort;\n return parsePort(undefined, envPort);\n}\n","import { existsSync } from \"node:fs\";\nimport { join, relative, sep } from \"node:path\";\nimport { writeContractSource } from \"./client-contract-file\";\n\n/** File suffixes of definition files, as in the project structure. */\nexport const DEFINITION_SUFFIXES = [\n \"service\",\n \"events\",\n \"resource\",\n \"table\",\n \"action\",\n \"command\",\n \"tool\",\n \"socket\",\n \"listener\",\n \"workflow\",\n \"step\",\n] as const;\n\nexport const MANIFEST_FILE = \"services.gen.ts\";\n\nfunction rank(file: string) {\n if (/\\.service\\.[^.]+$/.test(file)) return 0;\n if (/\\.resource\\.[^.]+$/.test(file)) return 1;\n return 2;\n}\n\n/** Definition files under `services`: service files first, then resources, then the rest, each by path. */\nexport function scanDefinitionFiles(services: string): string[] {\n if (!existsSync(services)) return [];\n // Built per call: index.ts re-exports this module, and Node (ESLint loading\n // brick.config.ts) has no Bun global.\n const glob = new Bun.Glob(\n `**/*.{${DEFINITION_SUFFIXES.join(\",\")}}.{ts,tsx,mts,js,jsx,mjs}`,\n );\n const files = [...glob.scanSync({ cwd: services, onlyFiles: true })]\n .map((file) => file.split(sep).join(\"/\"))\n .filter((file) => !file.split(\"/\").includes(\"node_modules\"));\n return files.sort(\n (a, b) => rank(a) - rank(b) || (a < b ? -1 : a > b ? 1 : 0),\n );\n}\n\n/** The source of `services.gen.ts`, which imports every definition file so each registers itself. */\nexport function renderManifest(services: string, generated: string): string {\n const imports = scanDefinitionFiles(services).map((file) => {\n let specifier = relative(generated, join(services, file))\n .split(sep)\n .join(\"/\")\n .replace(/\\.(ts|tsx|mts|js|jsx|mjs)$/, \"\");\n if (!specifier.startsWith(\".\")) specifier = `./${specifier}`;\n return `import ${JSON.stringify(specifier)};\\n`;\n });\n return `// Generated by brick dev, brick build and brick gen. Do not edit.\n// Imports every definition file under the services folder, so each one\n// registers itself on its service. The app entry imports this file.\n${imports.join(\"\")}\nexport {};\n`;\n}\n\n/** Write `<generated>/services.gen.ts`, leaving it untouched when nothing changed. */\nexport async function writeServiceManifest(options: {\n services: string;\n generated: string;\n}): Promise<string> {\n const output = join(options.generated, MANIFEST_FILE);\n await writeContractSource(\n output,\n renderManifest(options.services, options.generated),\n );\n return output;\n}\n","import { existsSync } from \"node:fs\";\nimport { join, resolve } from \"node:path\";\nimport { getGlobalRegistry, type BrickApp } from \"@brickkit/core\";\nimport { isLoopbackHost } from \"./dashboard-access\";\nimport {\n themeCss,\n type DashboardExtensionOptions,\n} from \"./dashboard-extension\";\nimport { DEFAULT_DASHBOARD_PORT, startDevDashboard } from \"./dev-dashboard\";\nimport { openHistory } from \"./dev-history\";\nimport { installTracing } from \"./dev-telemetry\";\nimport { DevTelemetryStore } from \"./dev-telemetry-store\";\n\nexport interface ProductionDashboard {\n readonly host: string;\n readonly port: number;\n stop(): void;\n}\n\n/**\n * Serve the monitoring dashboard an app asks for with `brick({ dashboard })`,\n * in the process that serves the app. It listens on a port of its own, so it\n * stays up when the app's routes do not answer, and its `/_health` tells an\n * uptime monitor whether the app does. From here on `ctx.logger` and `console`\n * lines written during a request go to the dashboard, not the console.\n *\n * Call it before the app starts listening. Returns undefined when the app\n * asks for no dashboard, or when it cannot start (the app runs on without it,\n * and says so). A configuration that would leave the dashboard open to others\n * throws instead: the app must not start unprotected.\n */\nexport async function startProductionDashboard(\n app: BrickApp,\n options: {\n /** The port the app listens on, for the health probe. */\n appPort: number;\n /** Where `.brick/` history is kept; the working folder by default. */\n directory?: string;\n warn?: (message: string) => void;\n /**\n * The project's extension (source, or the folder `brick build` wrote) and\n * theme. The app's plugins' extensions join it, from source or as the\n * folder holds them. Only pages marked `production: true` are shown.\n */\n dashboard?: DashboardExtensionOptions;\n },\n): Promise<ProductionDashboard | undefined> {\n const config = app.definition.dashboard;\n if (!config) return undefined;\n const warn = options.warn ?? ((message) => console.warn(message));\n // A mistyped token is a configuration error, not a reason to run without the dashboard.\n themeCss(options.dashboard?.theme);\n const host = config.host ?? \"127.0.0.1\";\n const port = config.port ?? DEFAULT_DASHBOARD_PORT;\n if (!isLoopbackHost(host) && !config.auth) {\n throw new Error(\n `Brick: the dashboard would listen on ${host}, where others can reach it, so it needs access control. Set dashboard.auth with a token or an authorize function.`,\n );\n }\n\n const history = await openHistory({\n directory: options.directory ?? process.cwd(),\n days: config.historyDays ?? 0,\n warn,\n });\n const store = new DevTelemetryStore({ history });\n const extension = options.dashboard?.extension;\n let started;\n try {\n started = await startDevDashboard({\n port,\n host,\n mode: \"production\",\n auth: config.auth,\n store,\n history,\n dashboard: options.dashboard,\n // A `brick build` folder already holds the plugins' extensions.\n plugins:\n extension && existsSync(join(resolve(extension), \"extension.js\"))\n ? undefined\n : app.definition.plugins,\n appUrl: `http://127.0.0.1:${options.appPort}`,\n probe: async () => {\n const response = await fetch(\n `http://127.0.0.1:${options.appPort}/_health`,\n { signal: AbortSignal.timeout(2000) },\n );\n return response.ok;\n },\n });\n } catch (error) {\n history?.close();\n const reason = error instanceof Error ? error.message : String(error);\n warn(`[Brick-TS] ${reason} Continuing without the dashboard.`);\n return undefined;\n }\n\n const registered = installTracing((records) =>\n store.ingest(records, store.latestGeneration),\n );\n if (!registered) {\n warn(\n \"[Brick-TS] Another tracer provider is already registered, so the dashboard will show no requests or logs.\",\n );\n }\n const generation = store.startGeneration(\"application started\");\n store.setArchitecture(\n getGlobalRegistry().exportArchitecture(app.definition),\n generation,\n );\n return {\n host,\n port: started.port,\n stop() {\n started.stop();\n history?.close();\n },\n };\n}\n","import { existsSync } from \"fs\";\nimport { watch } from \"fs\";\nimport { resolve, dirname, basename, sep } from \"path\";\nimport { fileURLToPath } from \"node:url\";\nimport {\n brick,\n getActionRoute,\n isBrickApp,\n type ApiDocument,\n type ArchitectureSchema,\n type BrickApp,\n type DocumentationOptions,\n type EventsHub,\n} from \"@brickkit/core\";\nimport {\n DEFAULT_DASHBOARD_PORT,\n startDevDashboard,\n type DevDashboard,\n} from \"./dev-dashboard\";\nimport type { DashboardExtensionOptions } from \"./dashboard-extension\";\nimport { DocsHost } from \"./dev-docs\";\nimport { DEFAULT_HISTORY_DAYS, openHistory } from \"./dev-history\";\nimport { DevTelemetryStore } from \"./dev-telemetry-store\";\nimport { parsePort } from \"./port-utils\";\nimport { writeServiceManifest } from \"./manifest\";\nimport { buildAppWorkflows, registerWorkflowTransform } from \"./workflows\";\nimport { startProductionDashboard } from \"./production-dashboard\";\nimport type {\n SerializedError,\n TelemetryRecord,\n WorkerErrorPhase,\n} from \"./dev-telemetry\";\n\nexport interface DevServerOptions {\n port?: number;\n entry?: string;\n prefix?: string;\n /** Generate a browser contract before starting the backend and frontend. */\n clientOutput?: string;\n /** Frontend command, launched once after the first successful generation. */\n frontend?: string;\n /**\n * Local dashboard with live requests, traces, errors, and reloads. Needs an\n * entry. `port` defaults to 9400. `historyDays` is how long finished\n * requests are kept on disk (default 90); zero keeps live data only.\n * `extension` and `theme` customise it (see `DashboardExtensionOptions`);\n * `brick start` reads only those two, for the production dashboard.\n */\n dashboard?:\n | ({ port?: number; historyDays?: number } & DashboardExtensionOptions)\n | false;\n /**\n * Keep `<generated>/services.gen.ts` importing every definition file under\n * `services`: written before the app starts and again when files change.\n */\n manifest?: { services: string; generated: string };\n}\n\nasync function createServer(\n options: DevServerOptions,\n label: string,\n application?: BrickApp,\n) {\n let port: number;\n if (options.port !== undefined) {\n port = options.port;\n } else if (process.env.PORT !== undefined && process.env.PORT !== \"\") {\n port = Number(process.env.PORT);\n } else {\n port = 4000;\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\n const app =\n application ??\n brick({\n port,\n prefix: options.prefix,\n });\n\n await buildAppWorkflows(app, { reuse: label === \"Development\" });\n // Plugins open their connections before the first request.\n await app.start?.();\n await app.listen({ port });\n app.events?.start();\n\n const prefix = app.definition.prefix;\n const services = app.definition.services;\n\n console.log(`\\n🧱 Brick-TS ${label} Server`);\n console.log(` Registered Services: ${services.length}`);\n\n for (const svc of services) {\n const actions = svc.listActions();\n console.log(` • ${svc.name} (${actions.length} actions)`);\n for (const act of actions) {\n const route = getActionRoute(act, prefix);\n if (route === false) continue;\n console.log(` -> ${route.method.padEnd(6)} ${route.path}`);\n }\n }\n\n console.log(`\\n⚡ API Gateway running on: http://localhost:${port}`);\n console.log(`🩺 Health check: http://localhost:${port}/_health`);\n console.log(\n `🗺️ Architecture graph: http://localhost:${port}/_brick/services\\n`,\n );\n\n return app;\n}\n\n/**\n * Finish the deliveries in flight at SIGINT or SIGTERM, then exit. A second\n * signal exits at once, for a delivery that never finishes.\n */\nexport function finishDeliveriesOnSignal(\n events: Pick<EventsHub, \"stop\">,\n signals: NodeJS.Signals[] = [\"SIGINT\", \"SIGTERM\"],\n) {\n let stopping = false;\n const stop = (signal: NodeJS.Signals) => {\n if (stopping) return process.exit(signal === \"SIGINT\" ? 130 : 143);\n stopping = true;\n void events.stop().finally(() => process.exit(0));\n };\n // `on`, not `once`: the workflow bundle loads signal-exit, which re-raises the\n // signal itself when it finds no listener left, and `once` removes ours first.\n for (const signal of signals) process.on(signal, stop);\n}\n\nexport async function startProdServer(options: DevServerOptions = {}) {\n const entry = options.entry;\n\n let exported: BrickApp | undefined;\n if (entry) {\n const resolvedEntry = resolve(process.cwd(), entry);\n if (!existsSync(resolvedEntry)) {\n console.error(`[Brick-TS] Error: Entry file not found: ${resolvedEntry}`);\n process.exit(1);\n }\n console.log(`[Brick-TS] Loading application entry: ${resolvedEntry}`);\n await registerWorkflowTransform();\n const module = await import(resolvedEntry);\n // An entry that default-exports its app is served as it built it, with its\n // options (telemetry, dashboard, and the rest), as `brick dev` does.\n if (isBrickApp(module?.default)) exported = module.default;\n }\n if (exported && options.prefix !== undefined) {\n console.warn(\n `[Brick-TS] Ignoring prefix ${options.prefix}: exported BrickApp prefix ${exported.definition.prefix} takes precedence.`,\n );\n }\n\n const port =\n options.port !== undefined\n ? options.port\n : process.env.PORT !== undefined && process.env.PORT !== \"\"\n ? Number(process.env.PORT)\n : 4000;\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\n const app =\n exported ??\n brick({\n port,\n prefix: options.prefix,\n });\n\n const prefix = app.definition.prefix;\n const services = app.definition.services;\n\n console.log(`\\n🧱 Brick-TS Production Server`);\n console.log(` Registered Services: ${services.length}`);\n\n for (const svc of services) {\n const actions = svc.listActions();\n console.log(` • ${svc.name} (${actions.length} actions)`);\n for (const act of actions) {\n const route = getActionRoute(act, prefix);\n if (route === false) continue;\n console.log(` -> ${route.method.padEnd(6)} ${route.path}`);\n }\n }\n\n await buildAppWorkflows(app);\n // Before listening, so the first request is already traced and its logs kept.\n const dashboard = await startProductionDashboard(app, {\n appPort: port,\n dashboard: options.dashboard || undefined,\n });\n await app.start?.();\n app.listen(port);\n app.events?.start();\n // Finish deliveries, then stop the server and the plugins (reverse order).\n finishDeliveriesOnSignal({\n stop: async () => {\n await app.events?.stop();\n await app.stop();\n },\n });\n\n console.log(`\\n⚡ API Gateway running on: http://localhost:${port}`);\n console.log(`🩺 Health check: http://localhost:${port}/_health`);\n if (dashboard) {\n const shown =\n dashboard.host === \"0.0.0.0\" || dashboard.host === \"::\"\n ? \"localhost\"\n : dashboard.host.includes(\":\")\n ? `[${dashboard.host.replace(/^\\[|\\]$/g, \"\")}]`\n : dashboard.host;\n console.log(\n `📊 Dashboard: http://${shown}:${dashboard.port} (health: /_health)`,\n );\n }\n console.log(\n `🗺️ Architecture graph: http://localhost:${port}/_brick/services\\n`,\n );\n\n return app;\n}\n\n/**\n * What `brick worker` runs: load the app and deliver its events from this\n * process, without serving HTTP. Run it beside API processes that only record\n * events (`events: { dispatch: false }`), or alone for an app with no routes.\n * Workflow listeners run here too: the world starts and the steps of every run\n * in it execute in this process.\n *\n * @param options - `entry`: the app file, which must default-export a `brick()` app.\n * @returns The app.\n * @throws When the entry is missing, has no `events`, or only records events.\n */\nexport async function startWorker(options: { entry: string }) {\n const resolvedEntry = resolve(process.cwd(), options.entry);\n if (!existsSync(resolvedEntry)) {\n console.error(`[Brick-TS] Error: Entry file not found: ${resolvedEntry}`);\n process.exit(1);\n }\n console.log(`[Brick-TS] Loading application entry: ${resolvedEntry}`);\n await registerWorkflowTransform();\n const app = (await import(resolvedEntry))?.default;\n if (!isBrickApp(app))\n throw new Error(\n \"Brick: a worker needs an entry that default-exports a BrickApp.\",\n );\n if (!app.events)\n throw new Error(\n \"Brick: this app has no events, so a worker has nothing to deliver.\",\n );\n if (!app.events.describe().dispatch)\n throw new Error(\n \"Brick: this app only records events (events.dispatch is false), so a worker would deliver nothing. Enable dispatch for the worker process.\",\n );\n await buildAppWorkflows(app);\n const events = app.events;\n await app.start?.();\n events.start();\n finishDeliveriesOnSignal({\n stop: async () => {\n await events.stop();\n await app.stop();\n },\n });\n const listeners = app.events.describe().listeners;\n console.log(`\\n🧱 Brick-TS Worker`);\n console.log(\n ` Delivering events to ${listeners.length} ${listeners.length === 1 ? \"listener\" : \"listeners\"}: ${listeners.map((l) => l.name).join(\", \") || \"none\"}\\n`,\n );\n return app;\n}\n\nexport async function startDevApplication(options: DevServerOptions) {\n if (options.entry) await registerWorkflowTransform();\n const module = options.entry\n ? await import(resolve(options.entry))\n : undefined;\n if (isBrickApp(module?.default) && options.prefix !== undefined) {\n console.warn(\n `[Brick-TS] Ignoring prefix ${options.prefix}: exported BrickApp prefix ${module.default.definition.prefix} takes precedence.`,\n );\n }\n if (options.clientOutput) {\n if (!isBrickApp(module?.default))\n throw new Error(\n \"Brick: client generation requires a default-exported BrickApp.\",\n );\n const { generateClientContract } = await import(\"./client-contract\");\n const { writeContractSource } = await import(\"./client-contract-file\");\n const { requireBrickApp } = await import(\"./app-entry\");\n const output = resolve(options.clientOutput);\n if (output === resolve(options.entry!))\n throw new Error(\n \"Brick: contract output must not overwrite the app entry.\",\n );\n await writeContractSource(\n output,\n generateClientContract(requireBrickApp(module.default)),\n );\n process.send?.({ type: \"brick:contract-ready\" });\n }\n return createServer(\n options,\n \"Development\",\n isBrickApp(module?.default) ? module.default : undefined,\n );\n}\n\n/**\n * What `brick dev` runs: start the application, restart it when its files\n * change, and serve the dashboard beside it. With an `entry`, the app runs in\n * a worker process that restarts on every change to the entry or the files it\n * imports, and reports its requests to the dashboard; without one, a server\n * with the registered services starts in this process.\n *\n * @param options - `entry`, `port` (else `PORT`, else 4000), `prefix`,\n * `clientOutput` to regenerate the typed client's contract on each start,\n * `frontend` to launch a frontend command once, and `dashboard` (`port` and\n * `historyDays`, or `false`).\n * @returns The application, when started in this process.\n * @throws When `frontend` is given without `clientOutput`, or the dashboard\n * would use the app's port.\n */\nexport async function startDevServer(options: DevServerOptions = {}) {\n const entry = options.entry;\n if (!entry && (options.clientOutput || options.frontend))\n throw new Error(\"Brick: --client and --frontend require an app entry.\");\n if (!entry) return createServer(options, \"Development\");\n const resolvedEntry = resolve(entry);\n if (!existsSync(resolvedEntry)) {\n console.error(`[Brick-TS] Error: Entry file not found: ${resolvedEntry}`);\n process.exit(1);\n }\n\n const worker = new URL(\n import.meta.url.endsWith(\".ts\") ? \"./dev-worker.ts\" : \"./dev-worker.js\",\n import.meta.url,\n );\n if (options.frontend && !options.clientOutput)\n throw new Error(\"Brick: --frontend requires --client <file>.\");\n if (\n options.dashboard &&\n options.port !== undefined &&\n (options.dashboard.port ?? DEFAULT_DASHBOARD_PORT) === options.port\n )\n throw new Error(\n \"Brick: dashboard port must differ from the API port. Use --dashboard-port <number>.\",\n );\n // The worker resolves its port the same way, so this is where the app listens.\n const appPort = () =>\n parsePort(\n options.port === undefined ? undefined : String(options.port),\n process.env.PORT,\n );\n const manifest = options.manifest;\n if (manifest) await writeServiceManifest(manifest);\n const history = options.dashboard\n ? await openHistory({\n directory: process.cwd(),\n days: options.dashboard.historyDays ?? DEFAULT_HISTORY_DAYS,\n warn: (message) => console.warn(message),\n })\n : undefined;\n const telemetry = options.dashboard\n ? new DevTelemetryStore({ history })\n : undefined;\n const docs = telemetry\n ? new DocsHost(telemetry, (message) => console.warn(message))\n : undefined;\n let frontend: ReturnType<typeof Bun.spawn> | undefined;\n const dependencyFiles = new Set<string>();\n const dependencyWatchers = new Map<string, ReturnType<typeof watch>>();\n let stopped = false;\n const intentionalExits = new WeakSet<ReturnType<typeof Bun.spawn>>();\n let generationCount = 0;\n let childGeneration = 0;\n const launch = () => {\n const generation = ++generationCount;\n childGeneration = generation;\n // The new process serves its own inspector once it is up.\n telemetry?.setInspector(undefined);\n telemetry?.recordReload({ kind: \"started\", generation });\n const application = Bun.spawn(\n [\n process.execPath,\n fileURLToPath(worker),\n resolvedEntry,\n String(options.port ?? \"\"),\n options.prefix ?? \"\",\n options.clientOutput ? resolve(options.clientOutput) : \"\",\n telemetry ? \"1\" : \"\",\n ],\n {\n cwd: process.cwd(),\n stdout: \"inherit\",\n stderr: \"inherit\",\n ipc(message) {\n if (!message || typeof message !== \"object\" || !(\"type\" in message))\n return;\n if (\n telemetry &&\n message.type === \"brick:telemetry\" &&\n \"records\" in message &&\n Array.isArray(message.records)\n ) {\n telemetry.ingest(message.records as TelemetryRecord[], generation);\n }\n if (\n telemetry &&\n message.type === \"brick:error\" &&\n \"phase\" in message &&\n \"error\" in message\n ) {\n telemetry.recordWorkerError(\n message.phase as WorkerErrorPhase,\n message.error as SerializedError,\n generation,\n );\n }\n if (\n message.type === \"brick:contract-ready\" &&\n options.frontend &&\n !frontend &&\n !stopped\n ) {\n frontend = Bun.spawn(\n [process.env.SHELL ?? \"/bin/sh\", \"-c\", options.frontend],\n {\n detached: true,\n cwd: process.cwd(),\n stdout: \"inherit\",\n stderr: \"inherit\",\n },\n );\n }\n if (\n telemetry &&\n message.type === \"brick:architecture\" &&\n \"architecture\" in message\n ) {\n telemetry.setArchitecture(\n message.architecture as ArchitectureSchema,\n generation,\n );\n void dashboard?.setPluginExtensions(\n (message.architecture as ArchitectureSchema).plugins ?? [],\n );\n }\n if (\n telemetry &&\n message.type === \"brick:inspector\" &&\n generation === childGeneration &&\n \"port\" in message &&\n \"token\" in message\n ) {\n telemetry.setInspector({\n port: message.port as number,\n token: message.token as string,\n });\n }\n if (docs && message.type === \"brick:documentation\") {\n void docs.configure(\n dirname(resolvedEntry),\n \"documentation\" in message\n ? (message.documentation as DocumentationOptions | undefined)\n : undefined,\n );\n }\n if (\n telemetry &&\n message.type === \"brick:api-documents\" &&\n \"documents\" in message &&\n Array.isArray(message.documents)\n ) {\n telemetry.setApiDocuments(\n message.documents as ApiDocument[],\n `http://localhost:${appPort()}`,\n );\n }\n if (telemetry && message.type === \"brick:contract-ready\") {\n telemetry.recordReload({\n kind: \"contract-ready\",\n generation,\n detail: \"browser contract generated\",\n });\n }\n if (\n message.type === \"brick:dependencies\" &&\n \"files\" in message &&\n Array.isArray(message.files)\n ) {\n for (const file of message.files) {\n if (\n typeof file !== \"string\" ||\n file === resolve(options.clientOutput ?? \"_brick/contract.ts\")\n )\n continue;\n dependencyFiles.add(file);\n const directory = dirname(file);\n if (!dependencyWatchers.has(directory))\n dependencyWatchers.set(\n directory,\n watch(directory, (_event, filename) => {\n if (\n !filename ||\n !dependencyFiles.has(resolve(directory, filename))\n )\n return;\n scheduleRestart();\n }),\n );\n }\n }\n },\n },\n );\n void application.exited.then((code) => {\n if (generation === childGeneration) telemetry?.setInspector(undefined);\n if (!stopped && !intentionalExits.has(application)) {\n console.error(\n `[Brick-TS] Application process exited with code ${code}. Waiting for changes to restart.`,\n );\n telemetry?.recordReload({\n kind: \"exited\",\n generation,\n detail: `exit code ${code}`,\n });\n }\n telemetry?.interruptGeneration(generation);\n });\n return application;\n };\n // Bind the dashboard before the first worker starts, so a port conflict\n // does not leave an application process running.\n const dashboard: DevDashboard | undefined =\n telemetry && options.dashboard\n ? await startDevDashboard({\n port: options.dashboard.port ?? DEFAULT_DASHBOARD_PORT,\n store: telemetry,\n history,\n docs: () => docs?.current,\n dashboard: {\n extension: options.dashboard.extension,\n theme: options.dashboard.theme,\n },\n restart: () => {\n void restart(\"dashboard\");\n },\n }).catch((error: unknown) => {\n history?.close();\n throw error;\n })\n : undefined;\n if (dashboard) {\n console.log(`📊 Dev dashboard: http://127.0.0.1:${dashboard.port}`);\n }\n let child = launch();\n const watchDirs = [\n ...new Set([\n resolve(\"src\"),\n resolve(\"app\"),\n resolve(resolvedEntry, \"..\"),\n ...(manifest ? [manifest.services] : []),\n ]),\n ].filter(existsSync);\n let pending: ReturnType<typeof setTimeout> | undefined;\n let restarting = false;\n let dirty = false;\n\n async function restart(trigger: \"changes\" | \"dashboard\" = \"changes\") {\n dirty = true;\n if (restarting || stopped) return;\n restarting = true;\n try {\n while (dirty && !stopped) {\n dirty = false;\n console.log(\n trigger === \"changes\"\n ? \"\\n📝 Changes detected. Restarting server...\"\n : \"\\n🔄 Restart requested from the dashboard. Restarting server...\",\n );\n telemetry?.recordReload({\n kind: \"restarting\",\n generation: childGeneration,\n detail:\n trigger === \"changes\" ? \"source changed\" : \"restart from dashboard\",\n });\n intentionalExits.add(child);\n child.kill();\n await child.exited;\n if (!stopped) child = launch();\n }\n } finally {\n restarting = false;\n }\n }\n\n function scheduleRestart() {\n clearTimeout(pending);\n pending = setTimeout(() => {\n void restart();\n }, 100);\n }\n const extension = options.dashboard && options.dashboard.extension;\n const extensionDir =\n extension && !watchDirs.includes(dirname(resolve(extension)))\n ? `${dirname(resolve(extension))}${sep}`\n : undefined;\n const watchers = watchDirs.map((dir) =>\n watch(dir, { recursive: true }, (_event, filename) => {\n if (!filename || filename.split(/[\\\\/]/).includes(\"node_modules\")) return;\n const file = resolve(dir, filename);\n if (\n file === resolve(options.clientOutput ?? \"_brick/contract.ts\") ||\n basename(file).startsWith(\".brick-contract-\") ||\n // The dashboard rebuilds its extension itself; the app restarts only\n // for the files it imports.\n (extensionDir !== undefined &&\n file.startsWith(extensionDir) &&\n !dependencyFiles.has(file))\n )\n return;\n // A definition file was added or removed: refresh the import list first.\n if (manifest && file.startsWith(manifest.services + sep)) {\n void writeServiceManifest(manifest)\n .catch((error: unknown) =>\n console.error(\"[Brick-TS] Could not write services.gen.ts:\", error),\n )\n .finally(scheduleRestart);\n return;\n }\n scheduleRestart();\n }),\n );\n const stop = () => {\n if (stopped) return;\n stopped = true;\n clearTimeout(pending);\n for (const watcher of watchers) watcher.close();\n for (const watcher of dependencyWatchers.values()) watcher.close();\n if (frontend) {\n if (process.platform === \"win32\") {\n Bun.spawnSync([\"taskkill\", \"/pid\", String(frontend.pid), \"/t\", \"/f\"]);\n } else {\n try {\n process.kill(-frontend.pid, \"SIGTERM\");\n } catch (error) {\n if (\n !(\n error instanceof Error &&\n \"code\" in error &&\n error.code === \"ESRCH\"\n )\n )\n throw error;\n }\n }\n }\n dashboard?.stop();\n docs?.close();\n history?.close();\n child.kill();\n process.off(\"SIGINT\", onSignal);\n process.off(\"SIGTERM\", onSignal);\n process.off(\"exit\", stop);\n };\n const onSignal = (signal: NodeJS.Signals) => {\n if (stopped) {\n child.kill(\"SIGKILL\");\n process.exit(signal === \"SIGINT\" ? 130 : 143);\n }\n stop();\n process.on(\"SIGINT\", onSignal);\n process.on(\"SIGTERM\", onSignal);\n void child.exited.then(() => process.exit(0));\n };\n process.on(\"SIGINT\", onSignal);\n process.on(\"SIGTERM\", onSignal);\n process.on(\"exit\", stop);\n console.log(`\\n👀 Watching for changes in: ${watchDirs.join(\", \")}`);\n return { stop };\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;;AAGA,SAAgB,eACd,SACA,YACA,UAAU,QAAQ,IAAI,MACd;CACR,IAAI,YAAY,KAAA,GAAW,OAAO;CAClC,IAAI,eAAe,KAAA,KAAa,CAAC,SAAS,OAAO;CACjD,OAAO,UAAU,KAAA,GAAW,OAAO;AACrC;;;;ACzBA,MAAa,sBAAsB;CACjC;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF;AAEA,MAAa,gBAAgB;AAE7B,SAAS,KAAK,MAAc;CAC1B,IAAI,oBAAoB,KAAK,IAAI,GAAG,OAAO;CAC3C,IAAI,qBAAqB,KAAK,IAAI,GAAG,OAAO;CAC5C,OAAO;AACT;;AAGA,SAAgB,oBAAoB,UAA4B;CAC9D,IAAI,CAACA,aAAW,QAAQ,GAAG,OAAO,CAAC;CASnC,OAHc,CAAC,GAAG,IAHD,IAAI,KACnB,SAAS,oBAAoB,KAAK,GAAG,EAAE,0BAEpB,CAAC,CAAC,SAAS;EAAE,KAAK;EAAU,WAA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,QAAQ,IAAI,iCAAiC,UAAU,KAAK,IAAI,GAAG;CACnE,OAAO,EAAE,KAAK;AAChB"}
|
|
1
|
+
{"version":3,"file":"runner.js","names":["existsSync","sep","existsSync","resolve"],"sources":["../src/port-utils.ts","../src/manifest.ts","../src/production-dashboard.ts","../src/runner.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\n/** The dev port: CLI flag, then PORT, then the config file, then 4000. */\nexport function resolveDevPort(\n cliPort: number | undefined,\n configPort?: number,\n envPort = process.env.PORT,\n): number {\n if (cliPort !== undefined) return cliPort;\n if (configPort !== undefined && !envPort) return configPort;\n return parsePort(undefined, envPort);\n}\n","import { existsSync } from \"node:fs\";\nimport { join, relative, sep } from \"node:path\";\nimport { writeContractSource } from \"./client-contract-file\";\n\n/** File suffixes of definition files, as in the project structure. */\nexport const DEFINITION_SUFFIXES = [\n \"service\",\n \"events\",\n \"resource\",\n \"table\",\n \"action\",\n \"command\",\n \"tool\",\n \"socket\",\n \"listener\",\n \"workflow\",\n \"step\",\n] as const;\n\nexport const MANIFEST_FILE = \"services.gen.ts\";\n\nfunction rank(file: string) {\n if (/\\.service\\.[^.]+$/.test(file)) return 0;\n if (/\\.resource\\.[^.]+$/.test(file)) return 1;\n return 2;\n}\n\n/** Definition files under `services`: service files first, then resources, then the rest, each by path. */\nexport function scanDefinitionFiles(services: string): string[] {\n if (!existsSync(services)) return [];\n // Built per call: index.ts re-exports this module, and Node (ESLint loading\n // brick.config.ts) has no Bun global.\n const glob = new Bun.Glob(\n `**/*.{${DEFINITION_SUFFIXES.join(\",\")}}.{ts,tsx,mts,js,jsx,mjs}`,\n );\n const files = [...glob.scanSync({ cwd: services, onlyFiles: true })]\n .map((file) => file.split(sep).join(\"/\"))\n .filter((file) => !file.split(\"/\").includes(\"node_modules\"));\n return files.sort(\n (a, b) => rank(a) - rank(b) || (a < b ? -1 : a > b ? 1 : 0),\n );\n}\n\n/** The source of `services.gen.ts`, which imports every definition file so each registers itself. */\nexport function renderManifest(services: string, generated: string): string {\n const imports = scanDefinitionFiles(services).map((file) => {\n let specifier = relative(generated, join(services, file))\n .split(sep)\n .join(\"/\")\n .replace(/\\.(ts|tsx|mts|js|jsx|mjs)$/, \"\");\n if (!specifier.startsWith(\".\")) specifier = `./${specifier}`;\n return `import ${JSON.stringify(specifier)};\\n`;\n });\n return `// Generated by brick dev, brick build and brick gen. Do not edit.\n// Imports every definition file under the services folder, so each one\n// registers itself on its service. The app entry imports this file.\n${imports.join(\"\")}\nexport {};\n`;\n}\n\n/** Write `<generated>/services.gen.ts`, leaving it untouched when nothing changed. */\nexport async function writeServiceManifest(options: {\n services: string;\n generated: string;\n}): Promise<string> {\n const output = join(options.generated, MANIFEST_FILE);\n await writeContractSource(\n output,\n renderManifest(options.services, options.generated),\n );\n return output;\n}\n","import { existsSync } from \"node:fs\";\nimport { join, resolve } from \"node:path\";\nimport { getGlobalRegistry, type BrickApp } from \"@brickkit/core\";\nimport { isLoopbackHost } from \"./dashboard-access\";\nimport {\n themeCss,\n type DashboardExtensionOptions,\n} from \"./dashboard-extension\";\nimport { DEFAULT_DASHBOARD_PORT, startDevDashboard } from \"./dev-dashboard\";\nimport { openHistory } from \"./dev-history\";\nimport { installTracing } from \"./dev-telemetry\";\nimport { DevTelemetryStore } from \"./dev-telemetry-store\";\n\nexport interface ProductionDashboard {\n readonly host: string;\n readonly port: number;\n stop(): void;\n}\n\n/**\n * Serve the monitoring dashboard an app asks for with `brick({ dashboard })`,\n * in the process that serves the app. It listens on a port of its own, so it\n * stays up when the app's routes do not answer, and its `/_health` tells an\n * uptime monitor whether the app does. From here on `ctx.logger` and `console`\n * lines written during a request go to the dashboard, not the console.\n *\n * Call it before the app starts listening. Returns undefined when the app\n * asks for no dashboard, or when it cannot start (the app runs on without it,\n * and says so). A configuration that would leave the dashboard open to others\n * throws instead: the app must not start unprotected.\n */\nexport async function startProductionDashboard(\n app: BrickApp,\n options: {\n /** The port the app listens on, for the health probe. */\n appPort: number;\n /** Where `.brick/` history is kept; the working folder by default. */\n directory?: string;\n warn?: (message: string) => void;\n /**\n * The project's extension (source, or the folder `brick build` wrote) and\n * theme. The app's plugins' extensions join it, from source or as the\n * folder holds them. Only pages marked `production: true` are shown.\n */\n dashboard?: DashboardExtensionOptions;\n },\n): Promise<ProductionDashboard | undefined> {\n const config = app.definition.dashboard;\n if (!config) return undefined;\n const warn = options.warn ?? ((message) => console.warn(message));\n // A mistyped token is a configuration error, not a reason to run without the dashboard.\n themeCss(options.dashboard?.theme);\n const host = config.host ?? \"127.0.0.1\";\n const port = config.port ?? DEFAULT_DASHBOARD_PORT;\n if (!isLoopbackHost(host) && !config.auth) {\n throw new Error(\n `Brick: the dashboard would listen on ${host}, where others can reach it, so it needs access control. Set dashboard.auth with a token or an authorize function.`,\n );\n }\n\n const history = await openHistory({\n directory: options.directory ?? process.cwd(),\n days: config.historyDays ?? 0,\n warn,\n });\n const store = new DevTelemetryStore({ history });\n const extension = options.dashboard?.extension;\n let started;\n try {\n started = await startDevDashboard({\n port,\n host,\n mode: \"production\",\n auth: config.auth,\n store,\n history,\n dashboard: options.dashboard,\n // A `brick build` folder already holds the plugins' extensions.\n plugins:\n extension && existsSync(join(resolve(extension), \"extension.js\"))\n ? undefined\n : app.definition.plugins,\n appUrl: `http://127.0.0.1:${options.appPort}`,\n probe: async () => {\n const response = await fetch(\n `http://127.0.0.1:${options.appPort}/_health`,\n { signal: AbortSignal.timeout(2000) },\n );\n return response.ok;\n },\n });\n } catch (error) {\n history?.close();\n const reason = error instanceof Error ? error.message : String(error);\n warn(`[Brick-TS] ${reason} Continuing without the dashboard.`);\n return undefined;\n }\n\n const registered = installTracing((records) =>\n store.ingest(records, store.latestGeneration),\n );\n if (!registered) {\n warn(\n \"[Brick-TS] Another tracer provider is already registered, so the dashboard will show no requests or logs.\",\n );\n }\n const generation = store.startGeneration(\"application started\");\n store.setArchitecture(\n getGlobalRegistry().exportArchitecture(app.definition),\n generation,\n );\n return {\n host,\n port: started.port,\n stop() {\n started.stop();\n history?.close();\n },\n };\n}\n","import { existsSync } from \"fs\";\nimport { watch } from \"fs\";\nimport { resolve, dirname, basename, sep } from \"path\";\nimport { fileURLToPath } from \"node:url\";\nimport {\n brick,\n getActionRoute,\n isBrickApp,\n type ApiDocument,\n type ArchitectureSchema,\n type BrickApp,\n type DocumentationOptions,\n type EventsHub,\n} from \"@brickkit/core\";\nimport {\n DEFAULT_DASHBOARD_PORT,\n startDevDashboard,\n type DevDashboard,\n} from \"./dev-dashboard\";\nimport type { DashboardExtensionOptions } from \"./dashboard-extension\";\nimport { DocsHost } from \"./dev-docs\";\nimport { DEFAULT_HISTORY_DAYS, openHistory } from \"./dev-history\";\nimport { DevTelemetryStore } from \"./dev-telemetry-store\";\nimport { parsePort } from \"./port-utils\";\nimport { writeServiceManifest } from \"./manifest\";\nimport { buildAppWorkflows, registerWorkflowTransform } from \"./workflows\";\nimport { startProductionDashboard } from \"./production-dashboard\";\nimport type {\n SerializedError,\n TelemetryRecord,\n WorkerErrorPhase,\n} from \"./dev-telemetry\";\n\nexport interface DevServerOptions {\n port?: number;\n entry?: string;\n prefix?: string;\n /** Generate a browser contract before starting the backend and frontend. */\n clientOutput?: string;\n /** Frontend command, launched once after the first successful generation. */\n frontend?: string;\n /**\n * Local dashboard with live requests, traces, errors, and reloads. Needs an\n * entry. `port` defaults to 9400. `historyDays` is how long finished\n * requests are kept on disk (default 90); zero keeps live data only.\n * `extension` and `theme` customise it (see `DashboardExtensionOptions`);\n * `brick start` reads only those two, for the production dashboard.\n */\n dashboard?:\n | ({ port?: number; historyDays?: number } & DashboardExtensionOptions)\n | false;\n /**\n * Keep `<generated>/services.gen.ts` importing every definition file under\n * `services`: written before the app starts and again when files change.\n */\n manifest?: { services: string; generated: string };\n}\n\nasync function createServer(\n options: DevServerOptions,\n label: string,\n application?: BrickApp,\n) {\n let port: number;\n if (options.port !== undefined) {\n port = options.port;\n } else if (process.env.PORT !== undefined && process.env.PORT !== \"\") {\n port = Number(process.env.PORT);\n } else {\n port = 4000;\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\n const app =\n application ??\n brick({\n port,\n prefix: options.prefix,\n });\n\n await buildAppWorkflows(app, { reuse: label === \"Development\" });\n // Plugins open their connections before the first request.\n await app.start?.();\n await app.listen({ port });\n app.events?.start();\n\n const prefix = app.definition.prefix;\n const services = app.definition.services;\n\n console.log(`\\n🧱 Brick-TS ${label} Server`);\n console.log(` Registered Services: ${services.length}`);\n\n for (const svc of services) {\n const actions = svc.listActions();\n console.log(` • ${svc.name} (${actions.length} actions)`);\n for (const act of actions) {\n const route = getActionRoute(act, prefix);\n if (route === false) continue;\n console.log(` -> ${route.method.padEnd(6)} ${route.path}`);\n }\n }\n\n console.log(`\\n⚡ API Gateway running on: http://localhost:${port}`);\n console.log(`🩺 Health check: http://localhost:${port}/_health`);\n console.log(\n `🗺️ Architecture graph: http://localhost:${port}/_brick/services\\n`,\n );\n\n return app;\n}\n\n/**\n * Finish the deliveries in flight at SIGINT or SIGTERM, then exit. A second\n * signal exits at once, for a delivery that never finishes.\n */\nexport function finishDeliveriesOnSignal(\n events: Pick<EventsHub, \"stop\">,\n signals: NodeJS.Signals[] = [\"SIGINT\", \"SIGTERM\"],\n) {\n let stopping = false;\n const stop = (signal: NodeJS.Signals) => {\n if (stopping) return process.exit(signal === \"SIGINT\" ? 130 : 143);\n stopping = true;\n void events.stop().finally(() => process.exit(0));\n };\n // `on`, not `once`: the workflow bundle loads signal-exit, which re-raises the\n // signal itself when it finds no listener left, and `once` removes ours first.\n for (const signal of signals) process.on(signal, stop);\n}\n\nexport async function startProdServer(options: DevServerOptions = {}) {\n const entry = options.entry;\n\n let exported: BrickApp | undefined;\n if (entry) {\n const resolvedEntry = resolve(process.cwd(), entry);\n if (!existsSync(resolvedEntry)) {\n console.error(`[Brick-TS] Error: Entry file not found: ${resolvedEntry}`);\n process.exit(1);\n }\n console.log(`[Brick-TS] Loading application entry: ${resolvedEntry}`);\n await registerWorkflowTransform();\n const module = await import(resolvedEntry);\n // An entry that default-exports its app is served as it built it, with its\n // options (telemetry, dashboard, and the rest), as `brick dev` does.\n if (isBrickApp(module?.default)) exported = module.default;\n }\n if (exported && options.prefix !== undefined) {\n console.warn(\n `[Brick-TS] Ignoring prefix ${options.prefix}: exported BrickApp prefix ${exported.definition.prefix} takes precedence.`,\n );\n }\n\n const port =\n options.port !== undefined\n ? options.port\n : process.env.PORT !== undefined && process.env.PORT !== \"\"\n ? Number(process.env.PORT)\n : 4000;\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\n const app =\n exported ??\n brick({\n port,\n prefix: options.prefix,\n });\n\n const prefix = app.definition.prefix;\n const services = app.definition.services;\n\n console.log(`\\n🧱 Brick-TS Production Server`);\n console.log(` Registered Services: ${services.length}`);\n\n for (const svc of services) {\n const actions = svc.listActions();\n console.log(` • ${svc.name} (${actions.length} actions)`);\n for (const act of actions) {\n const route = getActionRoute(act, prefix);\n if (route === false) continue;\n console.log(` -> ${route.method.padEnd(6)} ${route.path}`);\n }\n }\n\n await buildAppWorkflows(app);\n // Before listening, so the first request is already traced and its logs kept.\n const dashboard = await startProductionDashboard(app, {\n appPort: port,\n dashboard: options.dashboard || undefined,\n });\n await app.start?.();\n app.listen(port);\n app.events?.start();\n // Finish deliveries, then stop the server and the plugins (reverse order).\n finishDeliveriesOnSignal({\n stop: async () => {\n await app.events?.stop();\n await app.stop();\n },\n });\n\n console.log(`\\n⚡ API Gateway running on: http://localhost:${port}`);\n console.log(`🩺 Health check: http://localhost:${port}/_health`);\n if (dashboard) {\n const shown =\n dashboard.host === \"0.0.0.0\" || dashboard.host === \"::\"\n ? \"localhost\"\n : dashboard.host.includes(\":\")\n ? `[${dashboard.host.replace(/^\\[|\\]$/g, \"\")}]`\n : dashboard.host;\n console.log(\n `📊 Dashboard: http://${shown}:${dashboard.port} (health: /_health)`,\n );\n }\n console.log(\n `🗺️ Architecture graph: http://localhost:${port}/_brick/services\\n`,\n );\n\n return app;\n}\n\n/**\n * What `brick worker` runs: load the app and deliver its events from this\n * process, without serving HTTP. Run it beside API processes that only record\n * events (`events: { dispatch: false }`), or alone for an app with no routes.\n * Workflow listeners run here too: the world starts and the steps of every run\n * in it execute in this process.\n *\n * @param options - `entry`: the app file, which must default-export a `brick()` app.\n * @returns The app.\n * @throws When the entry is missing, has no `events`, or only records events.\n */\nexport async function startWorker(options: { entry: string }) {\n const resolvedEntry = resolve(process.cwd(), options.entry);\n if (!existsSync(resolvedEntry)) {\n console.error(`[Brick-TS] Error: Entry file not found: ${resolvedEntry}`);\n process.exit(1);\n }\n console.log(`[Brick-TS] Loading application entry: ${resolvedEntry}`);\n await registerWorkflowTransform();\n const app = (await import(resolvedEntry))?.default;\n if (!isBrickApp(app))\n throw new Error(\n \"Brick: a worker needs an entry that default-exports a BrickApp.\",\n );\n if (!app.events)\n throw new Error(\n \"Brick: this app has no events, so a worker has nothing to deliver.\",\n );\n if (!app.events.describe().dispatch)\n throw new Error(\n \"Brick: this app only records events (events.dispatch is false), so a worker would deliver nothing. Enable dispatch for the worker process.\",\n );\n await buildAppWorkflows(app);\n const events = app.events;\n await app.start?.();\n events.start();\n finishDeliveriesOnSignal({\n stop: async () => {\n await events.stop();\n await app.stop();\n },\n });\n const listeners = app.events.describe().listeners;\n console.log(`\\n🧱 Brick-TS Worker`);\n console.log(\n ` Delivering events to ${listeners.length} ${listeners.length === 1 ? \"listener\" : \"listeners\"}: ${listeners.map((l) => l.name).join(\", \") || \"none\"}\\n`,\n );\n return app;\n}\n\nexport async function startDevApplication(options: DevServerOptions) {\n if (options.entry) await registerWorkflowTransform();\n const module = options.entry\n ? await import(resolve(options.entry))\n : undefined;\n if (isBrickApp(module?.default) && options.prefix !== undefined) {\n console.warn(\n `[Brick-TS] Ignoring prefix ${options.prefix}: exported BrickApp prefix ${module.default.definition.prefix} takes precedence.`,\n );\n }\n if (options.clientOutput) {\n if (!isBrickApp(module?.default))\n throw new Error(\n \"Brick: client generation requires a default-exported BrickApp.\",\n );\n const { generateClientContract } = await import(\"./client-contract\");\n const { writeContractSource } = await import(\"./client-contract-file\");\n const { requireBrickApp } = await import(\"./app-entry\");\n const output = resolve(options.clientOutput);\n if (output === resolve(options.entry!))\n throw new Error(\n \"Brick: contract output must not overwrite the app entry.\",\n );\n await writeContractSource(\n output,\n generateClientContract(requireBrickApp(module.default)),\n );\n process.send?.({ type: \"brick:contract-ready\" });\n }\n return createServer(\n options,\n \"Development\",\n isBrickApp(module?.default) ? module.default : undefined,\n );\n}\n\n/**\n * What `brick dev` runs: start the application, restart it when its files\n * change, and serve the dashboard beside it. With an `entry`, the app runs in\n * a worker process that restarts on every change to the entry or the files it\n * imports, and reports its requests to the dashboard; without one, a server\n * with the registered services starts in this process.\n *\n * @param options - `entry`, `port` (else `PORT`, else 4000), `prefix`,\n * `clientOutput` to regenerate the typed client's contract on each start,\n * `frontend` to launch a frontend command once, and `dashboard` (`port` and\n * `historyDays`, or `false`).\n * @returns The application, when started in this process.\n * @throws When `frontend` is given without `clientOutput`, or the dashboard\n * would use the app's port.\n */\nexport async function startDevServer(options: DevServerOptions = {}) {\n const entry = options.entry;\n if (!entry && (options.clientOutput || options.frontend))\n throw new Error(\"Brick: --client and --frontend require an app entry.\");\n if (!entry) return createServer(options, \"Development\");\n const resolvedEntry = resolve(entry);\n if (!existsSync(resolvedEntry)) {\n console.error(`[Brick-TS] Error: Entry file not found: ${resolvedEntry}`);\n process.exit(1);\n }\n\n const worker = new URL(\n import.meta.url.endsWith(\".ts\") ? \"./dev-worker.ts\" : \"./dev-worker.js\",\n import.meta.url,\n );\n if (options.frontend && !options.clientOutput)\n throw new Error(\"Brick: --frontend requires --client <file>.\");\n if (\n options.dashboard &&\n options.port !== undefined &&\n (options.dashboard.port ?? DEFAULT_DASHBOARD_PORT) === options.port\n )\n throw new Error(\n \"Brick: dashboard port must differ from the API port. Use --dashboard-port <number>.\",\n );\n // The worker resolves its port the same way, so this is where the app listens.\n const appPort = () =>\n parsePort(\n options.port === undefined ? undefined : String(options.port),\n process.env.PORT,\n );\n const manifest = options.manifest;\n if (manifest) await writeServiceManifest(manifest);\n const history = options.dashboard\n ? await openHistory({\n directory: process.cwd(),\n days: options.dashboard.historyDays ?? DEFAULT_HISTORY_DAYS,\n warn: (message) => console.warn(message),\n })\n : undefined;\n const telemetry = options.dashboard\n ? new DevTelemetryStore({ history })\n : undefined;\n const docs = telemetry\n ? new DocsHost(telemetry, (message) => console.warn(message))\n : undefined;\n let frontend: ReturnType<typeof Bun.spawn> | undefined;\n const dependencyFiles = new Set<string>();\n const dependencyWatchers = new Map<string, ReturnType<typeof watch>>();\n let stopped = false;\n const intentionalExits = new WeakSet<ReturnType<typeof Bun.spawn>>();\n let generationCount = 0;\n let childGeneration = 0;\n const launch = () => {\n const generation = ++generationCount;\n childGeneration = generation;\n // The new process serves its own inspector once it is up.\n telemetry?.setInspector(undefined);\n telemetry?.recordReload({ kind: \"started\", generation });\n const application = Bun.spawn(\n [\n process.execPath,\n fileURLToPath(worker),\n resolvedEntry,\n String(options.port ?? \"\"),\n options.prefix ?? \"\",\n options.clientOutput ? resolve(options.clientOutput) : \"\",\n telemetry ? \"1\" : \"\",\n ],\n {\n cwd: process.cwd(),\n stdout: \"inherit\",\n stderr: \"inherit\",\n ipc(message) {\n if (!message || typeof message !== \"object\" || !(\"type\" in message))\n return;\n if (\n telemetry &&\n message.type === \"brick:telemetry\" &&\n \"records\" in message &&\n Array.isArray(message.records)\n ) {\n telemetry.ingest(message.records as TelemetryRecord[], generation);\n }\n if (\n telemetry &&\n message.type === \"brick:error\" &&\n \"phase\" in message &&\n \"error\" in message\n ) {\n telemetry.recordWorkerError(\n message.phase as WorkerErrorPhase,\n message.error as SerializedError,\n generation,\n );\n }\n if (\n message.type === \"brick:contract-ready\" &&\n options.frontend &&\n !frontend &&\n !stopped\n ) {\n frontend = Bun.spawn(\n [process.env.SHELL ?? \"/bin/sh\", \"-c\", options.frontend],\n {\n detached: true,\n cwd: process.cwd(),\n stdout: \"inherit\",\n stderr: \"inherit\",\n },\n );\n }\n if (\n telemetry &&\n message.type === \"brick:architecture\" &&\n \"architecture\" in message\n ) {\n telemetry.setArchitecture(\n message.architecture as ArchitectureSchema,\n generation,\n );\n void dashboard?.setPluginExtensions(\n (message.architecture as ArchitectureSchema).plugins ?? [],\n );\n }\n if (\n telemetry &&\n message.type === \"brick:inspector\" &&\n generation === childGeneration &&\n \"port\" in message &&\n \"token\" in message\n ) {\n telemetry.setInspector({\n port: message.port as number,\n token: message.token as string,\n });\n }\n if (docs && message.type === \"brick:documentation\") {\n void docs.configure(\n dirname(resolvedEntry),\n \"documentation\" in message\n ? (message.documentation as DocumentationOptions | undefined)\n : undefined,\n );\n }\n if (\n telemetry &&\n message.type === \"brick:api-documents\" &&\n \"documents\" in message &&\n Array.isArray(message.documents)\n ) {\n telemetry.setApiDocuments(\n message.documents as ApiDocument[],\n `http://localhost:${appPort()}`,\n );\n }\n if (telemetry && message.type === \"brick:contract-ready\") {\n telemetry.recordReload({\n kind: \"contract-ready\",\n generation,\n detail: \"browser contract generated\",\n });\n }\n if (\n message.type === \"brick:dependencies\" &&\n \"files\" in message &&\n Array.isArray(message.files)\n ) {\n for (const file of message.files) {\n if (\n typeof file !== \"string\" ||\n file === resolve(options.clientOutput ?? \"_brick/contract.ts\")\n )\n continue;\n dependencyFiles.add(file);\n const directory = dirname(file);\n if (!dependencyWatchers.has(directory))\n dependencyWatchers.set(\n directory,\n watch(directory, (_event, filename) => {\n if (\n !filename ||\n !dependencyFiles.has(resolve(directory, filename))\n )\n return;\n scheduleRestart();\n }),\n );\n }\n }\n },\n },\n );\n void application.exited.then((code) => {\n if (generation === childGeneration) telemetry?.setInspector(undefined);\n if (!stopped && !intentionalExits.has(application)) {\n console.error(\n `[Brick-TS] Application process exited with code ${code}. Waiting for changes to restart.`,\n );\n telemetry?.recordReload({\n kind: \"exited\",\n generation,\n detail: `exit code ${code}`,\n });\n }\n telemetry?.interruptGeneration(generation);\n });\n return application;\n };\n // Bind the dashboard before the first worker starts, so a port conflict\n // does not leave an application process running.\n const dashboard: DevDashboard | undefined =\n telemetry && options.dashboard\n ? await startDevDashboard({\n port: options.dashboard.port ?? DEFAULT_DASHBOARD_PORT,\n store: telemetry,\n history,\n docs: () => docs?.current,\n dashboard: {\n extension: options.dashboard.extension,\n theme: options.dashboard.theme,\n },\n restart: () => {\n void restart(\"dashboard\");\n },\n }).catch((error: unknown) => {\n history?.close();\n throw error;\n })\n : undefined;\n if (dashboard) {\n console.log(`📊 Dev dashboard: http://127.0.0.1:${dashboard.port}`);\n }\n let child = launch();\n const watchDirs = [\n ...new Set([\n resolve(\"src\"),\n resolve(\"app\"),\n resolve(resolvedEntry, \"..\"),\n ...(manifest ? [manifest.services] : []),\n ]),\n ].filter(existsSync);\n let pending: ReturnType<typeof setTimeout> | undefined;\n let restarting = false;\n let dirty = false;\n\n async function restart(trigger: \"changes\" | \"dashboard\" = \"changes\") {\n dirty = true;\n if (restarting || stopped) return;\n restarting = true;\n try {\n while (dirty && !stopped) {\n dirty = false;\n console.log(\n trigger === \"changes\"\n ? \"\\n📝 Changes detected. Restarting server...\"\n : \"\\n🔄 Restart requested from the dashboard. Restarting server...\",\n );\n telemetry?.recordReload({\n kind: \"restarting\",\n generation: childGeneration,\n detail:\n trigger === \"changes\" ? \"source changed\" : \"restart from dashboard\",\n });\n intentionalExits.add(child);\n child.kill();\n await child.exited;\n if (!stopped) child = launch();\n }\n } finally {\n restarting = false;\n }\n }\n\n function scheduleRestart() {\n clearTimeout(pending);\n pending = setTimeout(() => {\n void restart();\n }, 100);\n }\n const extension = options.dashboard && options.dashboard.extension;\n const extensionDir =\n extension && !watchDirs.includes(dirname(resolve(extension)))\n ? `${dirname(resolve(extension))}${sep}`\n : undefined;\n const watchers = watchDirs.map((dir) =>\n watch(dir, { recursive: true }, (_event, filename) => {\n if (!filename || filename.split(/[\\\\/]/).includes(\"node_modules\")) return;\n const file = resolve(dir, filename);\n if (\n file === resolve(options.clientOutput ?? \"_brick/contract.ts\") ||\n basename(file).startsWith(\".brick-contract-\") ||\n // The dashboard rebuilds its extension itself; the app restarts only\n // for the files it imports.\n (extensionDir !== undefined &&\n file.startsWith(extensionDir) &&\n !dependencyFiles.has(file))\n )\n return;\n // A definition file was added or removed: refresh the import list first.\n if (manifest && file.startsWith(manifest.services + sep)) {\n void writeServiceManifest(manifest)\n .catch((error: unknown) =>\n console.error(\"[Brick-TS] Could not write services.gen.ts:\", error),\n )\n .finally(scheduleRestart);\n return;\n }\n scheduleRestart();\n }),\n );\n const stop = () => {\n if (stopped) return;\n stopped = true;\n clearTimeout(pending);\n for (const watcher of watchers) watcher.close();\n for (const watcher of dependencyWatchers.values()) watcher.close();\n if (frontend) {\n if (process.platform === \"win32\") {\n Bun.spawnSync([\"taskkill\", \"/pid\", String(frontend.pid), \"/t\", \"/f\"]);\n } else {\n try {\n process.kill(-frontend.pid, \"SIGTERM\");\n } catch (error) {\n if (\n !(\n error instanceof Error &&\n \"code\" in error &&\n error.code === \"ESRCH\"\n )\n )\n throw error;\n }\n }\n }\n dashboard?.stop();\n docs?.close();\n history?.close();\n child.kill();\n process.off(\"SIGINT\", onSignal);\n process.off(\"SIGTERM\", onSignal);\n process.off(\"exit\", stop);\n };\n const onSignal = (signal: NodeJS.Signals) => {\n if (stopped) {\n child.kill(\"SIGKILL\");\n process.exit(signal === \"SIGINT\" ? 130 : 143);\n }\n stop();\n process.on(\"SIGINT\", onSignal);\n process.on(\"SIGTERM\", onSignal);\n void child.exited.then(() => process.exit(0));\n };\n process.on(\"SIGINT\", onSignal);\n process.on(\"SIGTERM\", onSignal);\n process.on(\"exit\", stop);\n console.log(`\\n👀 Watching for changes in: ${watchDirs.join(\", \")}`);\n return { stop };\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;;AAGA,SAAgB,eACd,SACA,YACA,UAAU,QAAQ,IAAI,MACd;CACR,IAAI,YAAY,KAAA,GAAW,OAAO;CAClC,IAAI,eAAe,KAAA,KAAa,CAAC,SAAS,OAAO;CACjD,OAAO,UAAU,KAAA,GAAW,OAAO;AACrC;;;ACzBA,MAAa,sBAAsB;CACjC;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF;AAEA,MAAa,gBAAgB;AAE7B,SAAS,KAAK,MAAc;CAC1B,IAAI,oBAAoB,KAAK,IAAI,GAAG,OAAO;CAC3C,IAAI,qBAAqB,KAAK,IAAI,GAAG,OAAO;CAC5C,OAAO;AACT;;AAGA,SAAgB,oBAAoB,UAA4B;CAC9D,IAAI,CAACA,aAAW,QAAQ,GAAG,OAAO,CAAC;CASnC,OAHc,CAAC,GAAG,IAHD,IAAI,KACnB,SAAS,oBAAoB,KAAK,GAAG,EAAE,0BAEpB,CAAC,CAAC,SAAS;EAAE,KAAK;EAAU,WAAW;CAAK,CAAC,CAAC,CAAC,CACjE,KAAK,SAAS,KAAK,MAAMC,KAAG,CAAC,CAAC,KAAK,GAAG,CAAC,CAAC,CACxC,QAAQ,SAAS,CAAC,KAAK,MAAM,GAAG,CA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boardTheme, t as DashboardExtensionOptions } from "./dashboard-extension.js";
|
|
2
2
|
import { Plugin } from "vite";
|
|
3
|
-
//#region src/vite.d.ts
|
|
4
3
|
export interface BrickClientPluginOptions {
|
|
5
4
|
/** Any module whose default export is a BrickApp; do not call listen() there. */
|
|
6
5
|
entry: string;
|
|
@@ -21,6 +20,5 @@ export interface BrickClientPluginOptions {
|
|
|
21
20
|
}
|
|
22
21
|
/** Load a BrickApp through Vite's server module graph, including dependency HMR. */
|
|
23
22
|
export declare function brickClient(options: BrickClientPluginOptions): Plugin;
|
|
24
|
-
//#endregion
|
|
25
23
|
export type { DashboardTheme };
|
|
26
24
|
//# sourceMappingURL=vite.d.ts.map
|
package/dist/vite.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { n as writeContractSource } from "./client-contract-file2.js";
|
|
2
2
|
import { t as generateClientContract } from "./client-contract2.js";
|
|
3
3
|
import { n as requireBrickApp } from "./app-entry2.js";
|
|
4
|
-
import {
|
|
5
|
-
import { getGlobalRegistry } from "@brickkit/core";
|
|
4
|
+
import { c as openHistory, i as themeCss, o as DocsHost, r as startDevDashboard, t as DevTelemetryStore } from "./dev-telemetry-store.js";
|
|
6
5
|
import { fileURLToPath } from "node:url";
|
|
6
|
+
import { getGlobalRegistry } from "@brickkit/core";
|
|
7
7
|
import { dirname, resolve } from "node:path";
|
|
8
8
|
import { createServer, isRunnableDevEnvironment, normalizePath } from "vite";
|
|
9
9
|
import { ModuleRunner } from "vite/module-runner";
|
|
10
|
-
|
|
10
|
+
// src/dev-vite-dashboard.ts
|
|
11
11
|
/**
|
|
12
12
|
* Serve the dashboard from inside the Vite dev server. Dev servers run the app
|
|
13
13
|
* in a worker, which reports its spans here over HTTP. This process keeps the
|
|
@@ -69,8 +69,7 @@ async function startViteDashboard(options) {
|
|
|
69
69
|
}
|
|
70
70
|
};
|
|
71
71
|
}
|
|
72
|
-
|
|
73
|
-
//#region src/vite.ts
|
|
72
|
+
// src/vite.ts
|
|
74
73
|
/** Load a BrickApp through Vite's server module graph, including dependency HMR. */
|
|
75
74
|
function brickClient(options) {
|
|
76
75
|
const virtualId = "virtual:brick-app";
|
|
@@ -235,7 +234,6 @@ export default app;
|
|
|
235
234
|
}
|
|
236
235
|
};
|
|
237
236
|
}
|
|
238
|
-
//#endregion
|
|
239
237
|
export { brickClient };
|
|
240
238
|
|
|
241
239
|
//# sourceMappingURL=vite.js.map
|
package/dist/vite.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
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 type { DashboardExtensionOptions } from \"./dashboard-extension\";\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 /** The extension (an absolute path) and theme. */\n dashboard?: DashboardExtensionOptions;\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 dashboard: options.dashboard,\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 {\n themeCss,\n type DashboardExtensionOptions,\n type DashboardTheme,\n} from \"./dashboard-extension\";\n\nexport type { DashboardTheme };\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. `extension` (relative to the Vite root) and `theme`\n * customise it, as in `brick dev`.\n */\n dashboard?:\n | ({ port?: number; historyDays?: number } & DashboardExtensionOptions)\n | 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 if (options.dashboard) themeCss(options.dashboard.theme);\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 dashboard: {\n extension: options.dashboard?.extension\n ? resolve(server.config.root, options.dashboard.extension)\n : undefined,\n theme: options.dashboard?.theme,\n },\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":";;;;;;;;;;;;;;;AAoCA,eAAsB,mBAAmB,SAWF;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,OAAO,IAAI,SAAS,QAAQ,YAAY,QAAQ,OAAO,KAAK,OAAO,CAAC;CAC1E,IAAI;CACJ,IAAI;EACF,YAAY,MAAM,kBAAkB;GAClC,MAAM,QAAQ,QAAA;GACd;GACA;GACA,YAAY,KAAK;GACjB,WAAW,QAAQ;EACrB,CAAC;CACH,SAAS,OAAO;EACd,SAAS,MAAM;EACf,MAAM,SAAS,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK;EACpE,QAAQ,OAAO,KACb,cAAc,OAAO,mCACvB;EACA;CACF;CACA,QAAQ,OAAO,KACb,0CAA0C,UAAU,MACtD;CAEA,IAAI,UAAU;CACd,IAAI;CACJ,IAAI;CACJ,IAAI,QAAQ;CAGZ,MAAM,yBAAyB;EAC7B,IAAI,WAAW,MAAM,gBAAgB,WAAW,MAAM;CACxD;CACA,OAAO;EACL,WAAW,oBAAoB,U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}
|
|
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 type { DashboardExtensionOptions } from \"./dashboard-extension\";\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 /** The extension (an absolute path) and theme. */\n dashboard?: DashboardExtensionOptions;\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 dashboard: options.dashboard,\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 {\n themeCss,\n type DashboardExtensionOptions,\n type DashboardTheme,\n} from \"./dashboard-extension\";\n\nexport type { DashboardTheme };\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. `extension` (relative to the Vite root) and `theme`\n * customise it, as in `brick dev`.\n */\n dashboard?:\n | ({ port?: number; historyDays?: number } & DashboardExtensionOptions)\n | 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 if (options.dashboard) themeCss(options.dashboard.theme);\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 dashboard: {\n extension: options.dashboard?.extension\n ? resolve(server.config.root, options.dashboard.extension)\n : undefined,\n theme: options.dashboard?.theme,\n },\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":";;;;;;;;;;;;;;;AAoCA,eAAsB,mBAAmB,SAWF;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,OAAO,IAAI,SAAS,QAAQ,YAAY,QAAQ,OAAO,KAAK,OAAO,CAAC;CAC1E,IAAI;CACJ,IAAI;EACF,YAAY,MAAM,kBAAkB;GAClC,MAAM,QAAQ,QAAA;GACd;GACA;GACA,YAAY,KAAK;GACjB,WAAW,QAAQ;EACrB,CAAC;CACH,SAAS,OAAO;EACd,SAAS,MAAM;EACf,MAAM,SAAS,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK;EACpE,QAAQ,OAAO,KACb,cAAc,OAAO,mCACvB;EACA;CACF;CACA,QAAQ,OAAO,KACb,0CAA0C,UAAU,MACtD;CAEA,IAAI,UAAU;CACd,IAAI;CACJ,IAAI;CACJ,IAAI,QAAQ;CAGZ,MAAM,yBAAyB;EAC7B,IAAI,WAAW,MAAM,gBAAgB,WAAW,MAAM;CACxD;CACA,OAAO;EACL,WAAW,oBAAoB,UAAU,KAAK;EAC9C,aAAa,KAAK;GAChB,MAAM,gBACJ,kBAAkB,CAAC,CAAC,mBAAmB,IAAI,UAAU,GACrD,MAAM,gBACR;GACA,KAAU,UAAU,QAAQ,QAAQ,KAAK,GAAG,IAAI,WAAW,aAAa;GAExE,MAAM,OAAO,EAAE;GACf,IAAI,mBAAmB,CAAC,CAAC,MACtB,WAAW;IACV,IAAI,SAAS,SAAS,SAAS;IAC/B,YAAY;IACZ,iBAAiB;GACnB,IACC,UACC,QAAQ,OAA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AM,OAAO;KACb,QAAQ,OAAO;KACf,MAAM,OAAO;KACb,QAAQ,OAAO;KACf,UAAU;KACV,SAAS,EAAE,OAAO,OAAO,QAAQ,MAAM;KACvC,KAAK,OAAO;KACZ,QAAQ;MAAE,gBAAgB;MAAM,OAAO;KAAK;IAC9C,CAAC;IACD,IAAI;KACF,MAAM,cAAc,OAAO,aAAa;KACxC,IAAI,CAAC,eAAe,CAAC,yBAAyB,WAAW,GACvD,MAAM,IAAI,MAAM,uCAAuC;KACzD,MAAM,eAAe,MAAM,YAAY,OAAO,OAAO,KAAK,EAAA,CAAG,OAAO;IACtE,UAAU;KACR,MAAM,OAAO,MAAM;IACrB;GACF,EAAA,CAAG;GACH,MAAM;EACR;EACA,UAAU,IAAI;GACZ,IAAI,OAAO,aAAa,OAAO,YAAY;GAC3C,IAAI,KAAK,YAAY,OAAO,aAAa,UACvC,MAAM,IAAI,MACR,uFACF;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/dist/workflows.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { BrickApp } from "@brickkit/core";
|
|
2
|
-
//#region src/workflows.d.ts
|
|
3
2
|
type BunPlugin = Parameters<typeof Bun.plugin>[0];
|
|
4
3
|
/**
|
|
5
4
|
* The plugin that turns `"use workflow"` and `"use step"` files into workflows and
|
|
@@ -56,6 +55,5 @@ export declare function buildWorkflows(options?: {
|
|
|
56
55
|
export declare function buildAppWorkflows(app: BrickApp, options?: {
|
|
57
56
|
reuse?: boolean;
|
|
58
57
|
}): Promise<boolean>;
|
|
59
|
-
//#endregion
|
|
60
58
|
export {};
|
|
61
59
|
//# sourceMappingURL=workflows.d.ts.map
|
package/dist/workflows2.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { createRequire } from "node:module";
|
|
2
|
-
import { resolveWorkflowPaths } from "@brickkit/core";
|
|
3
2
|
import { pathToFileURL } from "node:url";
|
|
3
|
+
import { resolveWorkflowPaths } from "@brickkit/core";
|
|
4
4
|
import { readFile, rm, stat, writeFile } from "node:fs/promises";
|
|
5
5
|
import { dirname, isAbsolute, join, relative, resolve } from "node:path";
|
|
6
6
|
import { existsSync, readFileSync } from "node:fs";
|
|
7
|
-
|
|
7
|
+
// src/workflows.ts
|
|
8
8
|
const DIRECTIVE = /["']use (?:step|workflow)["']/;
|
|
9
9
|
/**
|
|
10
10
|
* Every project source file. Not the generated bundle: it holds the directives as
|
|
@@ -292,7 +292,6 @@ async function buildAppWorkflows(app, options = {}) {
|
|
|
292
292
|
})) console.log(`[Brick-TS] Built workflows in ${Math.round(performance.now() - started)}ms`);
|
|
293
293
|
return true;
|
|
294
294
|
}
|
|
295
|
-
//#endregion
|
|
296
295
|
export { workflowTransformPlugin as i, buildWorkflows as n, registerWorkflowTransform as r, buildAppWorkflows as t };
|
|
297
296
|
|
|
298
297
|
//# sourceMappingURL=workflows2.js.map
|
|
File without changes
|
|
File without changes
|