@brickkit/cli 0.12.0 → 0.13.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dashboard-dist/{api-reference-B-bZRtNV.js → api-reference-mT9VNcPb.js} +69 -69
- package/dashboard-dist/app.css +1 -1
- package/dashboard-dist/app.js +12 -13
- package/dashboard-dist/{client-BJJtVSVr.js → client-CwATkLJa.js} +1 -1
- package/dashboard-dist/{core-Z7NJFk0K.js → core-BEUWp6B5.js} +1 -1
- package/dashboard-dist/docs-BRrtyxDB.js +4 -0
- package/dashboard-dist/kit.js +1 -1
- package/dashboard-dist/popover-Bj9x-88h.js +1 -0
- package/dist/bin.js +154 -217
- package/dist/bin.js.map +1 -1
- package/dist/build.js +463 -0
- package/dist/build.js.map +1 -0
- package/dist/client-contract-file.js +356 -1
- package/dist/client-contract-file.js.map +1 -0
- package/dist/compiler.d.ts +12 -2
- package/dist/compiler2.js +12 -5
- package/dist/compiler2.js.map +1 -1
- package/dist/config.d.ts +3 -0
- package/dist/config.js +1 -250
- package/dist/config2.d.ts +122 -0
- package/dist/config2.js +207 -0
- package/dist/config2.js.map +1 -0
- package/dist/dashboard-extension.d.ts +3 -0
- package/dist/{dev-telemetry-store.js → dashboard-host.js} +1533 -1574
- package/dist/dashboard-host.js.map +1 -0
- package/dist/dashboard-protocol.js +189 -0
- package/dist/dashboard-protocol.js.map +1 -0
- package/dist/dashboard.d.ts +4 -1
- package/dist/definitions.js +33 -0
- package/dist/definitions.js.map +1 -0
- package/dist/dev-application.js +34 -0
- package/dist/dev-application.js.map +1 -0
- package/dist/dev-protocol.js +21 -0
- package/dist/dev-protocol.js.map +1 -0
- package/dist/dev-reporter.js +2 -1
- package/dist/dev-reporter.js.map +1 -1
- package/dist/dev-telemetry.js +5 -20
- package/dist/dev-telemetry.js.map +1 -1
- package/dist/dev-worker.js +79 -19
- package/dist/dev-worker.js.map +1 -1
- package/dist/index.d.ts +15 -74
- package/dist/index.js +12 -5
- package/dist/index.js.map +1 -0
- package/dist/lint/oxlint.js +5 -3
- package/dist/lint/oxlint.js.map +1 -1
- package/dist/own-module.js +7 -0
- package/dist/own-module.js.map +1 -0
- package/dist/plugin.d.ts +6 -5
- package/dist/plugin.js +5 -39
- package/dist/plugin.js.map +1 -1
- package/dist/production-dashboard.d.ts +2 -0
- package/dist/production-dashboard.js +51 -0
- package/dist/production-dashboard.js.map +1 -0
- package/dist/production-dashboard2.d.ts +34 -0
- package/dist/{presets.js → project.js} +104 -106
- package/dist/project.js.map +1 -0
- package/dist/serve.d.ts +24 -0
- package/dist/serve.js +1 -0
- package/dist/serve2.js +49 -0
- package/dist/serve2.js.map +1 -0
- package/dist/vite.js +26 -47
- package/dist/vite.js.map +1 -1
- package/dist/workflows.d.ts +2 -2
- package/dist/workflows2.js +59 -37
- package/dist/workflows2.js.map +1 -1
- package/inspector-dist/client/assets/app-CeSwVsRm.css +2 -0
- package/inspector-dist/client/assets/{highlighted-body-B3W2YXNL-DYVdwGy2.js → highlighted-body-B3W2YXNL-CfRnuITN.js} +1 -1
- package/inspector-dist/client/assets/{home-CyjkvtII.js → home-hwPlkNhv.js} +1529 -378
- package/inspector-dist/client/assets/manifest-0e76e9ac.js +1 -0
- package/inspector-dist/client/assets/mermaid-3ZIDBTTL-ZDR2PNY_.js +1 -0
- package/inspector-dist/client/assets/root-ChBNTZd2.css +2 -0
- package/inspector-dist/client/assets/{root-DX9wtogx.js → root-SLeEf-sT.js} +17 -29
- package/inspector-dist/client/assets/{run-detail-C69EJGql.js → run-detail-DYbVkIFH.js} +398 -76
- package/inspector-dist/client/assets/{tabs-B6B88IjT.js → tabs-CaJisoyb.js} +189 -2130
- package/inspector-dist/client/assets/{zstd-browser-decoder-ByUgcY9H.js → zstd-browser-decoder-D94wmfAU.js} +1 -1
- package/inspector-dist/server/assets/{app-WoDoT62X.js → app-DGlfWVUI.js} +69783 -70608
- package/inspector-dist/server/assets/{chunk-RLXIAIE6-CbvDIAEa.js → chunk-RLXIAIE6-F0SJZlei.js} +4 -6
- package/inspector-dist/server/assets/{dist-qR-969AD.js → dist-BCbwm6jl.js} +2 -4
- package/inspector-dist/server/assets/{dist-CQnQcIJg.js → dist-CG2aVufI.js} +0 -2
- package/inspector-dist/server/assets/{dist-BRxZSWUN.js → dist-Ce0I2PUv.js} +2 -5
- package/inspector-dist/server/assets/{dist-DqRd9pyS.js → dist-DY0UlahA.js} +0 -2
- package/inspector-dist/server/assets/{encryption-_PuklZNX.js → encryption-DdQgC8Rk.js} +2 -4
- package/inspector-dist/server/assets/{event-metadata-BVakQJ_y.js → event-metadata-n7E4zEmT.js} +0 -2
- package/inspector-dist/server/assets/{functions-CImcpqNl.js → functions-CNVQtbgg.js} +2 -4
- package/inspector-dist/server/assets/{global-singleton-CPirHxFh.js → global-singleton-D8sIN5du.js} +0 -2
- package/inspector-dist/server/assets/{highlighted-body-B3W2YXNL-fPMB_t7F.js → highlighted-body-B3W2YXNL-CWRzMxYD.js} +2 -4
- package/inspector-dist/server/assets/mermaid-3ZIDBTTL-D0v0ngVr.js +1 -0
- package/inspector-dist/server/assets/{parse-D9Vvgzt9.js → parse-Begau9cA.js} +0 -2
- package/inspector-dist/server/assets/{rolldown-runtime-CLg409Sh.js → rolldown-runtime-C1I3wEg2.js} +1 -2
- package/inspector-dist/server/assets/{serialization-format-DDtsVTU1.js → serialization-format-BbuGfHog.js} +6 -8
- package/inspector-dist/server/assets/{token-BW4GdQZh.js → token-BgMmJNP5.js} +2 -4
- package/inspector-dist/server/assets/{token-D6FXdkJT.js → token-BrUX0bxz.js} +2 -4
- package/inspector-dist/server/assets/{token-util-BoNmi-wE.js → token-util-DZN32qmT.js} +1 -3
- package/inspector-dist/server/assets/{wrapper-wiqsGXcE.js → wrapper-CIC3w0oC.js} +1 -3
- package/inspector-dist/server/assets/{ws-transport-DV7oG4mL.js → ws-transport-CxTYB11n.js} +24094 -24096
- package/inspector-dist/server/assets/{zstd-browser-decoder-Cswf0KO6.js → zstd-browser-decoder-D7bCXbGg.js} +2 -4
- package/inspector-dist/server/index.js +1 -3
- package/package.json +12 -2
- package/dashboard-dist/docs-Dpfc0wJb.js +0 -4
- package/dashboard-dist/popover-BzejBolB.js +0 -1
- package/dist/app-entry.js +0 -1
- package/dist/app-entry2.js +0 -18
- package/dist/app-entry2.js.map +0 -1
- package/dist/client-contract-file2.js +0 -33
- package/dist/client-contract-file2.js.map +0 -1
- package/dist/client-contract.js +0 -1
- package/dist/client-contract2.js +0 -296
- package/dist/client-contract2.js.map +0 -1
- package/dist/config.js.map +0 -1
- package/dist/dev-telemetry-store.js.map +0 -1
- package/dist/emit.d.ts +0 -5
- package/dist/presets.js.map +0 -1
- package/dist/runner.js +0 -519
- package/dist/runner.js.map +0 -1
- package/inspector-dist/client/assets/app-CCzpuUz_.css +0 -2
- package/inspector-dist/client/assets/manifest-ba30b52d.js +0 -1
- package/inspector-dist/client/assets/mermaid-3ZIDBTTL-Dy6IVqPy.js +0 -1
- package/inspector-dist/client/assets/root-8BMab1lL.css +0 -2
- package/inspector-dist/client/assets/world-config-context-C3BqXPIv.js +0 -30
- package/inspector-dist/server/assets/mermaid-3ZIDBTTL-bADXySE3.js +0 -3
package/dist/build.js
ADDED
|
@@ -0,0 +1,463 @@
|
|
|
1
|
+
import { f as resolvePort, n as ConfigError, s as PROJECT_DEFAULTS } from "./config2.js";
|
|
2
|
+
import { i as workflowTransformPlugin, t as buildAppWorkflows } from "./workflows2.js";
|
|
3
|
+
import { i as writeFileIfChanged, o as importEntry, s as loadBrickApp } from "./client-contract-file.js";
|
|
4
|
+
import { n as themeCss, r as writeDashboardExtension, t as openDashboard } from "./dashboard-host.js";
|
|
5
|
+
import { t as ownModule } from "./own-module.js";
|
|
6
|
+
import { n as serveApp, r as shutdownOnSignal, t as printBanner } from "./serve2.js";
|
|
7
|
+
import { t as startDevApplication } from "./dev-application.js";
|
|
8
|
+
import { i as MANIFEST_FILE, n as DEFINITION_FILE, r as DEFINITION_KINDS, t as DEFINITION_EXTENSIONS } from "./definitions.js";
|
|
9
|
+
import { t as emitCompiledApplication } from "./compiler2.js";
|
|
10
|
+
import { existsSync, watch } from "node:fs";
|
|
11
|
+
import { basename, dirname, join, relative, resolve, sep } from "node:path";
|
|
12
|
+
import { brick, compileBrickApplication, isBrickApp } from "@brickkit/core";
|
|
13
|
+
import { mkdir, mkdtemp, rename, rm } from "node:fs/promises";
|
|
14
|
+
import { aot } from "elysia/plugin/aot/bun";
|
|
15
|
+
// src/manifest.ts
|
|
16
|
+
/** Services register before the resources that join them; every other kind after. */
|
|
17
|
+
const FIRST = ["service", "resource"];
|
|
18
|
+
function rank(file) {
|
|
19
|
+
const index = FIRST.indexOf(DEFINITION_FILE.exec(file)?.[2]);
|
|
20
|
+
return index === -1 ? FIRST.length : index;
|
|
21
|
+
}
|
|
22
|
+
/** Definition files under `services`: service files first, then resources, then the rest, each by path. */
|
|
23
|
+
function scanDefinitionFiles(services) {
|
|
24
|
+
if (!existsSync(services)) return [];
|
|
25
|
+
return [...new Bun.Glob(`**/*.{${DEFINITION_KINDS.join(",")}}.{${DEFINITION_EXTENSIONS.join(",")}}`).scanSync({
|
|
26
|
+
cwd: services,
|
|
27
|
+
onlyFiles: true
|
|
28
|
+
})].map((file) => file.split(sep).join("/")).filter((file) => !file.split("/").includes("node_modules")).sort((a, b) => rank(a) - rank(b) || (a < b ? -1 : a > b ? 1 : 0));
|
|
29
|
+
}
|
|
30
|
+
/** The source of `services.gen.ts`, which imports every definition file so each registers itself. */
|
|
31
|
+
function renderManifest(services, generated) {
|
|
32
|
+
return `// Generated by Brick. Do not edit.
|
|
33
|
+
// Imports every definition file under the services folder, so each one
|
|
34
|
+
// registers itself on its service. The app entry imports this file.
|
|
35
|
+
${scanDefinitionFiles(services).map((file) => {
|
|
36
|
+
let specifier = relative(generated, join(services, file)).split(sep).join("/").replace(DEFINITION_FILE, "$1.$2");
|
|
37
|
+
if (!specifier.startsWith(".")) specifier = `./${specifier}`;
|
|
38
|
+
return `import ${JSON.stringify(specifier)};\n`;
|
|
39
|
+
}).join("")}
|
|
40
|
+
export {};
|
|
41
|
+
`;
|
|
42
|
+
}
|
|
43
|
+
/** Write `<generated>/services.gen.ts`, leaving it untouched when nothing changed. */
|
|
44
|
+
async function writeServiceManifest(options) {
|
|
45
|
+
const output = join(options.generated, MANIFEST_FILE);
|
|
46
|
+
await writeFileIfChanged(output, renderManifest(options.services, options.generated));
|
|
47
|
+
return output;
|
|
48
|
+
}
|
|
49
|
+
// src/runner.ts
|
|
50
|
+
/**
|
|
51
|
+
* What `brick start` runs: serve the entry's default-exported app as it built
|
|
52
|
+
* it (else one with the registered services), with the monitoring dashboard
|
|
53
|
+
* it asks for, until SIGINT or SIGTERM.
|
|
54
|
+
*/
|
|
55
|
+
async function startProdServer(options) {
|
|
56
|
+
let exported;
|
|
57
|
+
if (options.entry) {
|
|
58
|
+
console.log(`[Brick-TS] Loading application entry: ${resolve(options.entry)}`);
|
|
59
|
+
exported = await importEntry(options.entry, { run: true });
|
|
60
|
+
}
|
|
61
|
+
const port = resolvePort(options.port);
|
|
62
|
+
const app = isBrickApp(exported) ? exported : brick();
|
|
63
|
+
await buildAppWorkflows(app);
|
|
64
|
+
const dashboard = await serveApp(app, {
|
|
65
|
+
port,
|
|
66
|
+
dashboard: options.dashboard
|
|
67
|
+
});
|
|
68
|
+
shutdownOnSignal(app);
|
|
69
|
+
printBanner(app, {
|
|
70
|
+
label: "Production",
|
|
71
|
+
port,
|
|
72
|
+
dashboard
|
|
73
|
+
});
|
|
74
|
+
return app;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* What `brick worker` runs: load the app and deliver its events from this
|
|
78
|
+
* process, without serving HTTP. Run it beside API processes that only record
|
|
79
|
+
* events (`events: { dispatch: false }`), or alone for an app with no routes.
|
|
80
|
+
* Workflow listeners run here too: the world starts and the steps of every run
|
|
81
|
+
* in it execute in this process.
|
|
82
|
+
*
|
|
83
|
+
* @param options - `entry`: the app file, which must default-export a `brick()` app.
|
|
84
|
+
* @returns The app.
|
|
85
|
+
* @throws When the entry is missing, has no `events`, or only records events.
|
|
86
|
+
*/
|
|
87
|
+
async function startWorker(options) {
|
|
88
|
+
console.log(`[Brick-TS] Loading application entry: ${resolve(options.entry)}`);
|
|
89
|
+
const app = await importEntry(options.entry, { run: true });
|
|
90
|
+
if (!isBrickApp(app)) throw new ConfigError("Brick: a worker needs an entry that default-exports a BrickApp.");
|
|
91
|
+
if (!app.events) throw new ConfigError("Brick: this app has no events, so a worker has nothing to deliver.");
|
|
92
|
+
if (!app.events.describe().dispatch) throw new ConfigError("Brick: this app only records events (events.dispatch is false), so a worker would deliver nothing. Enable dispatch for the worker process.");
|
|
93
|
+
await buildAppWorkflows(app);
|
|
94
|
+
await app.start();
|
|
95
|
+
app.events.start();
|
|
96
|
+
shutdownOnSignal(app);
|
|
97
|
+
const listeners = app.events.describe().listeners;
|
|
98
|
+
console.log(`\n🧱 Brick-TS Worker`);
|
|
99
|
+
console.log(` Delivering events to ${listeners.length} ${listeners.length === 1 ? "listener" : "listeners"}: ${listeners.map((l) => l.name).join(", ") || "none"}\n`);
|
|
100
|
+
return app;
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* What `brick dev` runs: start the application, restart it when its files
|
|
104
|
+
* change, and serve the dashboard beside it. With an `entry`, the app runs in
|
|
105
|
+
* a worker process that restarts on every change to the entry or the files it
|
|
106
|
+
* imports, and reports its requests to the dashboard; without one, a server
|
|
107
|
+
* with the registered services starts in this process.
|
|
108
|
+
*
|
|
109
|
+
* @param options - `entry`, `port` (else `PORT`, else 4000), `prefix`,
|
|
110
|
+
* `clientOutput` to regenerate the typed client's contract on each start,
|
|
111
|
+
* `frontend` to launch a frontend command once, and `dashboard` (`port` and
|
|
112
|
+
* `historyDays`, or `false`).
|
|
113
|
+
* @returns The application, when started in this process.
|
|
114
|
+
* @throws When `frontend` is given without `clientOutput`, or the dashboard
|
|
115
|
+
* would use the app's port.
|
|
116
|
+
*/
|
|
117
|
+
async function startDevServer(options = {}) {
|
|
118
|
+
const entry = options.entry;
|
|
119
|
+
if (!entry && (options.clientOutput || options.frontend)) throw new ConfigError("Brick: --client and --frontend require an app entry.");
|
|
120
|
+
if (options.frontend && !options.clientOutput) throw new ConfigError("Brick: --frontend requires --client <file>.");
|
|
121
|
+
const port = resolvePort(options.port);
|
|
122
|
+
if (!entry) return startDevApplication({
|
|
123
|
+
port,
|
|
124
|
+
prefix: options.prefix
|
|
125
|
+
});
|
|
126
|
+
const resolvedEntry = resolve(entry);
|
|
127
|
+
if (!existsSync(resolvedEntry)) throw new ConfigError(`[Brick-TS] Error: Entry file not found: ${resolvedEntry}`);
|
|
128
|
+
if (options.dashboard && (options.dashboard.port ?? 9400) === port) throw new ConfigError("Brick: dashboard port must differ from the API port. Use --dashboard-port <number>.");
|
|
129
|
+
const manifest = options.manifest;
|
|
130
|
+
if (manifest) await writeServiceManifest(manifest);
|
|
131
|
+
const contract = resolve(options.clientOutput ?? join(manifest?.generated ?? PROJECT_DEFAULTS.generated, "contract.ts"));
|
|
132
|
+
const workerOptions = {
|
|
133
|
+
entry: resolvedEntry,
|
|
134
|
+
port,
|
|
135
|
+
prefix: options.prefix,
|
|
136
|
+
clientOutput: options.clientOutput && contract,
|
|
137
|
+
telemetry: Boolean(options.dashboard)
|
|
138
|
+
};
|
|
139
|
+
const dashboard = options.dashboard ? await openDashboard({
|
|
140
|
+
port: options.dashboard.port,
|
|
141
|
+
directory: process.cwd(),
|
|
142
|
+
historyDays: options.dashboard.historyDays,
|
|
143
|
+
warn: (message) => console.warn(message),
|
|
144
|
+
docs: true,
|
|
145
|
+
dashboard: {
|
|
146
|
+
extension: options.dashboard.extension,
|
|
147
|
+
theme: options.dashboard.theme
|
|
148
|
+
},
|
|
149
|
+
restart: () => {
|
|
150
|
+
restart("dashboard");
|
|
151
|
+
},
|
|
152
|
+
portHint: "Use --dashboard-port <number> or --no-dashboard."
|
|
153
|
+
}) : void 0;
|
|
154
|
+
const telemetry = dashboard?.store;
|
|
155
|
+
let frontend;
|
|
156
|
+
const dependencyFiles = /* @__PURE__ */ new Set();
|
|
157
|
+
const dependencyWatchers = /* @__PURE__ */ new Map();
|
|
158
|
+
let stopped = false;
|
|
159
|
+
const intentionalExits = /* @__PURE__ */ new WeakSet();
|
|
160
|
+
const receive = (message, generation) => {
|
|
161
|
+
switch (message.type) {
|
|
162
|
+
case "brick:telemetry":
|
|
163
|
+
telemetry?.ingest(message.records, generation);
|
|
164
|
+
return;
|
|
165
|
+
case "brick:error":
|
|
166
|
+
telemetry?.recordWorkerError(message.phase, message.error, generation);
|
|
167
|
+
return;
|
|
168
|
+
case "brick:contract-ready":
|
|
169
|
+
if (options.frontend && !frontend && !stopped) frontend = Bun.spawn([
|
|
170
|
+
process.env.SHELL ?? "/bin/sh",
|
|
171
|
+
"-c",
|
|
172
|
+
options.frontend
|
|
173
|
+
], {
|
|
174
|
+
detached: true,
|
|
175
|
+
cwd: process.cwd(),
|
|
176
|
+
stdout: "inherit",
|
|
177
|
+
stderr: "inherit"
|
|
178
|
+
});
|
|
179
|
+
telemetry?.recordReload({
|
|
180
|
+
kind: "contract-ready",
|
|
181
|
+
generation,
|
|
182
|
+
detail: "browser contract generated"
|
|
183
|
+
});
|
|
184
|
+
return;
|
|
185
|
+
case "brick:architecture":
|
|
186
|
+
telemetry?.setArchitecture(message.architecture, generation);
|
|
187
|
+
dashboard?.setPluginExtensions(message.architecture.plugins ?? []);
|
|
188
|
+
return;
|
|
189
|
+
case "brick:inspector":
|
|
190
|
+
if (generation === telemetry?.latestGeneration) telemetry.setInspector({
|
|
191
|
+
port: message.port,
|
|
192
|
+
token: message.token
|
|
193
|
+
});
|
|
194
|
+
return;
|
|
195
|
+
case "brick:documentation":
|
|
196
|
+
dashboard?.docs?.configure(dirname(resolvedEntry), message.documentation);
|
|
197
|
+
return;
|
|
198
|
+
case "brick:api-documents":
|
|
199
|
+
telemetry?.setApiDocuments(message.documents, `http://localhost:${port}`);
|
|
200
|
+
return;
|
|
201
|
+
case "brick:dependencies":
|
|
202
|
+
for (const file of message.files) {
|
|
203
|
+
if (file === contract) continue;
|
|
204
|
+
dependencyFiles.add(file);
|
|
205
|
+
const directory = dirname(file);
|
|
206
|
+
if (!dependencyWatchers.has(directory)) dependencyWatchers.set(directory, watch(directory, (_event, filename) => {
|
|
207
|
+
if (!filename || !dependencyFiles.has(resolve(directory, filename))) return;
|
|
208
|
+
scheduleRestart();
|
|
209
|
+
}));
|
|
210
|
+
}
|
|
211
|
+
return;
|
|
212
|
+
}
|
|
213
|
+
};
|
|
214
|
+
const launch = () => {
|
|
215
|
+
telemetry?.setInspector(void 0);
|
|
216
|
+
const generation = telemetry?.startGeneration() ?? 0;
|
|
217
|
+
const application = Bun.spawn([
|
|
218
|
+
process.execPath,
|
|
219
|
+
ownModule("dev-worker"),
|
|
220
|
+
JSON.stringify(workerOptions)
|
|
221
|
+
], {
|
|
222
|
+
cwd: process.cwd(),
|
|
223
|
+
stdout: "inherit",
|
|
224
|
+
stderr: "inherit",
|
|
225
|
+
ipc: (message) => receive(message, generation)
|
|
226
|
+
});
|
|
227
|
+
application.exited.then((code) => {
|
|
228
|
+
if (generation === telemetry?.latestGeneration) telemetry.setInspector(void 0);
|
|
229
|
+
if (!stopped && !intentionalExits.has(application)) {
|
|
230
|
+
console.error(`[Brick-TS] Application process exited with code ${code}. Waiting for changes to restart.`);
|
|
231
|
+
telemetry?.recordReload({
|
|
232
|
+
kind: "exited",
|
|
233
|
+
generation,
|
|
234
|
+
detail: `exit code ${code}`
|
|
235
|
+
});
|
|
236
|
+
}
|
|
237
|
+
telemetry?.interruptGeneration(generation);
|
|
238
|
+
});
|
|
239
|
+
return application;
|
|
240
|
+
};
|
|
241
|
+
if (dashboard) console.log(`📊 Dev dashboard: http://127.0.0.1:${dashboard.port}`);
|
|
242
|
+
let child = launch();
|
|
243
|
+
const watchDirs = [.../* @__PURE__ */ new Set([dirname(resolvedEntry), ...manifest ? [manifest.services] : []])].filter(existsSync);
|
|
244
|
+
let pending;
|
|
245
|
+
let restarting = false;
|
|
246
|
+
let dirty = false;
|
|
247
|
+
async function restart(trigger = "changes") {
|
|
248
|
+
dirty = true;
|
|
249
|
+
if (restarting || stopped) return;
|
|
250
|
+
restarting = true;
|
|
251
|
+
try {
|
|
252
|
+
while (dirty && !stopped) {
|
|
253
|
+
dirty = false;
|
|
254
|
+
console.log(trigger === "changes" ? "\n📝 Changes detected. Restarting server..." : "\n🔄 Restart requested from the dashboard. Restarting server...");
|
|
255
|
+
telemetry?.recordReload({
|
|
256
|
+
kind: "restarting",
|
|
257
|
+
generation: telemetry.latestGeneration,
|
|
258
|
+
detail: trigger === "changes" ? "source changed" : "restart from dashboard"
|
|
259
|
+
});
|
|
260
|
+
intentionalExits.add(child);
|
|
261
|
+
child.kill();
|
|
262
|
+
await child.exited;
|
|
263
|
+
if (!stopped) child = launch();
|
|
264
|
+
}
|
|
265
|
+
} finally {
|
|
266
|
+
restarting = false;
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
function scheduleRestart() {
|
|
270
|
+
clearTimeout(pending);
|
|
271
|
+
pending = setTimeout(() => {
|
|
272
|
+
restart();
|
|
273
|
+
}, 100);
|
|
274
|
+
}
|
|
275
|
+
const extension = options.dashboard && options.dashboard.extension;
|
|
276
|
+
const extensionDir = extension && !watchDirs.includes(dirname(resolve(extension))) ? `${dirname(resolve(extension))}${sep}` : void 0;
|
|
277
|
+
const watchers = watchDirs.map((dir) => watch(dir, { recursive: true }, (_event, filename) => {
|
|
278
|
+
if (!filename || filename.split(/[\\/]/).includes("node_modules")) return;
|
|
279
|
+
const file = resolve(dir, filename);
|
|
280
|
+
if (file === contract || basename(file).startsWith(".brick-write-") || extensionDir !== void 0 && file.startsWith(extensionDir) && !dependencyFiles.has(file)) return;
|
|
281
|
+
if (manifest && file.startsWith(manifest.services + sep)) {
|
|
282
|
+
writeServiceManifest(manifest).catch((error) => console.error("[Brick-TS] Could not write services.gen.ts:", error)).finally(scheduleRestart);
|
|
283
|
+
return;
|
|
284
|
+
}
|
|
285
|
+
scheduleRestart();
|
|
286
|
+
}));
|
|
287
|
+
const stop = () => {
|
|
288
|
+
if (stopped) return;
|
|
289
|
+
stopped = true;
|
|
290
|
+
clearTimeout(pending);
|
|
291
|
+
for (const watcher of watchers) watcher.close();
|
|
292
|
+
for (const watcher of dependencyWatchers.values()) watcher.close();
|
|
293
|
+
if (frontend) {
|
|
294
|
+
if (process.platform === "win32") Bun.spawnSync([
|
|
295
|
+
"taskkill",
|
|
296
|
+
"/pid",
|
|
297
|
+
String(frontend.pid),
|
|
298
|
+
"/t",
|
|
299
|
+
"/f"
|
|
300
|
+
]);
|
|
301
|
+
else try {
|
|
302
|
+
process.kill(-frontend.pid, "SIGTERM");
|
|
303
|
+
} catch (error) {
|
|
304
|
+
if (!(error instanceof Error && "code" in error && error.code === "ESRCH")) throw error;
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
dashboard?.stop();
|
|
308
|
+
child.kill();
|
|
309
|
+
process.off("SIGINT", onSignal);
|
|
310
|
+
process.off("SIGTERM", onSignal);
|
|
311
|
+
process.off("exit", stop);
|
|
312
|
+
};
|
|
313
|
+
const onSignal = (signal) => {
|
|
314
|
+
if (stopped) {
|
|
315
|
+
child.kill("SIGKILL");
|
|
316
|
+
process.exit(signal === "SIGINT" ? 130 : 143);
|
|
317
|
+
}
|
|
318
|
+
stop();
|
|
319
|
+
process.on("SIGINT", onSignal);
|
|
320
|
+
process.on("SIGTERM", onSignal);
|
|
321
|
+
child.exited.then(() => process.exit(0));
|
|
322
|
+
};
|
|
323
|
+
process.on("SIGINT", onSignal);
|
|
324
|
+
process.on("SIGTERM", onSignal);
|
|
325
|
+
process.on("exit", stop);
|
|
326
|
+
console.log(`\n👀 Watching for changes in: ${watchDirs.join(", ")}`);
|
|
327
|
+
return { stop };
|
|
328
|
+
}
|
|
329
|
+
// src/compiler/aot.ts
|
|
330
|
+
/** Keep the pinned Elysia beta's incomplete stripping from breaking builds. */
|
|
331
|
+
function brickAot(entry, hasSockets) {
|
|
332
|
+
if (hasSockets) return aot(entry, {
|
|
333
|
+
target: "bun",
|
|
334
|
+
strip: false
|
|
335
|
+
});
|
|
336
|
+
return {
|
|
337
|
+
name: "brick-elysia-aot",
|
|
338
|
+
async setup(build) {
|
|
339
|
+
await aot(entry, {
|
|
340
|
+
target: "bun",
|
|
341
|
+
strip: true
|
|
342
|
+
}).setup({
|
|
343
|
+
...build,
|
|
344
|
+
onLoad(options, callback) {
|
|
345
|
+
return build.onLoad(options, async (args) => {
|
|
346
|
+
const result = await callback(args);
|
|
347
|
+
if (!result || !("contents" in result) || typeof result.contents !== "string") return result;
|
|
348
|
+
let contents = result.contents;
|
|
349
|
+
if (/[/\\]elysia[/\\]dist[/\\]ws[/\\]route\.m?js$/.test(args.path) && contents.includes("[elysia-aot] WebSocket route builder was stripped")) {
|
|
350
|
+
for (const name of ["resolveWSOptions", "accumulateWSOptions"]) if (!contents.includes(`export function ${name}`)) contents += `\nexport function ${name}() { throw new Error("WebSocket support was stripped"); }\n`;
|
|
351
|
+
}
|
|
352
|
+
return contents === result.contents ? result : {
|
|
353
|
+
...result,
|
|
354
|
+
contents
|
|
355
|
+
};
|
|
356
|
+
});
|
|
357
|
+
}
|
|
358
|
+
});
|
|
359
|
+
}
|
|
360
|
+
};
|
|
361
|
+
}
|
|
362
|
+
// src/build.ts
|
|
363
|
+
/**
|
|
364
|
+
* The production dashboard stays out of the bundle: it serves files that ship
|
|
365
|
+
* with @brickkit/cli, so a built server whose app asks for it imports it from
|
|
366
|
+
* there at run time. Without a dashboard the bundle needs nothing installed.
|
|
367
|
+
*/
|
|
368
|
+
const productionDashboardAtRunTime = {
|
|
369
|
+
name: "brick:production-dashboard",
|
|
370
|
+
setup(build) {
|
|
371
|
+
build.onResolve({ filter: /^\.\/production-dashboard(\.[jt]s)?$/ }, () => ({
|
|
372
|
+
path: "@brickkit/cli/production-dashboard",
|
|
373
|
+
external: true
|
|
374
|
+
}));
|
|
375
|
+
}
|
|
376
|
+
};
|
|
377
|
+
/** The files `brick build` writes to the output folder, `server.js` last. */
|
|
378
|
+
const OUTPUTS = [
|
|
379
|
+
"routes.js",
|
|
380
|
+
"brick-ir.json",
|
|
381
|
+
"server.js.map",
|
|
382
|
+
"server.js"
|
|
383
|
+
];
|
|
384
|
+
/** Bundle an exported BrickApp with its compiled IR and its original configuration. */
|
|
385
|
+
async function buildApplication(options) {
|
|
386
|
+
const entry = resolve(options.entry);
|
|
387
|
+
if (!await Bun.file(entry).exists()) throw new Error(`Brick compiler: entry not found: ${entry}`);
|
|
388
|
+
const outdir = resolve(options.outdir ?? "dist/brick");
|
|
389
|
+
if (OUTPUTS.some((name) => entry === join(outdir, name))) throw new Error("Brick compiler: output would overwrite the application entry");
|
|
390
|
+
const port = resolvePort(options.port, void 0, "");
|
|
391
|
+
themeCss(options.dashboard?.theme);
|
|
392
|
+
const extension = options.dashboard?.extension ? resolve(options.dashboard.extension) : void 0;
|
|
393
|
+
if (extension && !await Bun.file(extension).exists()) throw new Error(`Brick compiler: dashboard extension not found: ${extension}`);
|
|
394
|
+
const app = await loadBrickApp(entry);
|
|
395
|
+
await buildAppWorkflows(app);
|
|
396
|
+
const services = [...app.definition.services];
|
|
397
|
+
const compilation = compileBrickApplication({
|
|
398
|
+
services,
|
|
399
|
+
prefix: app.definition.prefix
|
|
400
|
+
});
|
|
401
|
+
await mkdir(dirname(outdir), { recursive: true });
|
|
402
|
+
const staging = await mkdtemp(join(dirname(outdir), ".brick-build-"));
|
|
403
|
+
try {
|
|
404
|
+
await Bun.write(join(staging, "routes.js"), emitCompiledApplication(compilation.ir));
|
|
405
|
+
const dashboard = await writeDashboardExtension(extension, app.definition.plugins ?? [], join(staging, "dashboard")) ? join(outdir, "dashboard") : void 0;
|
|
406
|
+
const theme = JSON.stringify(options.dashboard?.theme);
|
|
407
|
+
const source = `import { fileURLToPath } from "node:url";
|
|
408
|
+
import { loadCompiledBrickApp } from "@brickkit/core";
|
|
409
|
+
import { resolvePort } from ${JSON.stringify(ownModule("config"))};
|
|
410
|
+
import { serveApp, shutdownOnSignal } from ${JSON.stringify(ownModule("serve"))};
|
|
411
|
+
import { ir } from "./routes.js";
|
|
412
|
+
export const app = await loadCompiledBrickApp(() => import(${JSON.stringify(entry)}), ir);
|
|
413
|
+
if (import.meta.main) {
|
|
414
|
+
await serveApp(app, {
|
|
415
|
+
port: resolvePort(undefined, ${port}),
|
|
416
|
+
dashboard: { extension: ${dashboard ? "fileURLToPath(new URL(\"./dashboard\", import.meta.url))" : "undefined"}, theme: ${theme} },
|
|
417
|
+
});
|
|
418
|
+
console.log("Brick compiled server listening on http://localhost:" + app.server.port);
|
|
419
|
+
shutdownOnSignal(app);
|
|
420
|
+
}
|
|
421
|
+
`;
|
|
422
|
+
await Bun.write(join(staging, "entry.ts"), source);
|
|
423
|
+
const workflows = app.events?.workflows ? await workflowTransformPlugin(app.events.workflows.root) : void 0;
|
|
424
|
+
const result = await Bun.build({
|
|
425
|
+
entrypoints: [join(staging, "entry.ts")],
|
|
426
|
+
target: "bun",
|
|
427
|
+
format: "esm",
|
|
428
|
+
outdir: staging,
|
|
429
|
+
naming: "server.js",
|
|
430
|
+
sourcemap: "external",
|
|
431
|
+
plugins: [
|
|
432
|
+
...options.aot === false ? [] : [brickAot(join(staging, "entry.ts"), app.definition.sockets.length > 0)],
|
|
433
|
+
...workflows ? [workflows] : [],
|
|
434
|
+
productionDashboardAtRunTime
|
|
435
|
+
]
|
|
436
|
+
});
|
|
437
|
+
if (!result.success) throw new AggregateError(result.logs, "Brick compiler: bundling failed");
|
|
438
|
+
await Bun.write(join(staging, "brick-ir.json"), JSON.stringify(compilation.ir, null, 2) + "\n");
|
|
439
|
+
await mkdir(outdir, { recursive: true });
|
|
440
|
+
for (const name of OUTPUTS) await rename(join(staging, name), join(outdir, name));
|
|
441
|
+
if (dashboard) {
|
|
442
|
+
await rm(dashboard, {
|
|
443
|
+
recursive: true,
|
|
444
|
+
force: true
|
|
445
|
+
});
|
|
446
|
+
await rename(join(staging, "dashboard"), dashboard);
|
|
447
|
+
}
|
|
448
|
+
return {
|
|
449
|
+
outdir,
|
|
450
|
+
entry: join(outdir, "server.js"),
|
|
451
|
+
ir: compilation.ir,
|
|
452
|
+
dashboard
|
|
453
|
+
};
|
|
454
|
+
} finally {
|
|
455
|
+
await rm(staging, {
|
|
456
|
+
recursive: true,
|
|
457
|
+
force: true
|
|
458
|
+
});
|
|
459
|
+
}
|
|
460
|
+
}
|
|
461
|
+
export { writeServiceManifest as a, startWorker as i, startDevServer as n, startProdServer as r, buildApplication as t };
|
|
462
|
+
|
|
463
|
+
//# sourceMappingURL=build.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"build.js","names":[],"sources":["../src/manifest.ts","../src/runner.ts","../src/compiler/aot.ts","../src/build.ts"],"sourcesContent":["import { existsSync } from \"node:fs\";\nimport { join, relative, sep } from \"node:path\";\nimport { writeFileIfChanged } from \"./client-contract-file\";\n\nimport {\n DEFINITION_EXTENSIONS,\n DEFINITION_FILE,\n DEFINITION_KINDS,\n MANIFEST_FILE,\n type DefinitionKind,\n} from \"./definitions\";\n\n/** Services register before the resources that join them; every other kind after. */\nconst FIRST: readonly DefinitionKind[] = [\"service\", \"resource\"];\n\nfunction rank(file: string) {\n const index = FIRST.indexOf(\n DEFINITION_FILE.exec(file)?.[2] as DefinitionKind,\n );\n return index === -1 ? FIRST.length : index;\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 imports this module (through runner) and still\n // exports defineConfig, so Node may load it (ESLint reading brick.config.ts).\n const glob = new Bun.Glob(\n `**/*.{${DEFINITION_KINDS.join(\",\")}}.{${DEFINITION_EXTENSIONS.join(\",\")}}`,\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(DEFINITION_FILE, \"$1.$2\");\n if (!specifier.startsWith(\".\")) specifier = `./${specifier}`;\n return `import ${JSON.stringify(specifier)};\\n`;\n });\n return `// Generated by Brick. 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 writeFileIfChanged(\n output,\n renderManifest(options.services, options.generated),\n );\n return output;\n}\n","import { existsSync, watch } from \"node:fs\";\nimport { basename, dirname, join, resolve, sep } from \"node:path\";\nimport { brick, isBrickApp } from \"@brickkit/core\";\nimport { importEntry } from \"./app-entry\";\nimport { TEMPORARY_FILE_PREFIX } from \"./client-contract-file\";\nimport {\n ConfigError,\n CONTRACT_FILE,\n DEFAULT_DASHBOARD_PORT,\n PROJECT_DEFAULTS,\n resolvePort,\n} from \"./config\";\nimport { openDashboard } from \"./dashboard-host\";\nimport { ownModule } from \"./own-module\";\nimport type { DashboardExtensionOptions } from \"./dashboard-extension\";\nimport { startDevApplication } from \"./dev-application\";\nimport type { WorkerMessage, WorkerOptions } from \"./dev-protocol\";\nimport { writeServiceManifest } from \"./manifest\";\nimport { printBanner, serveApp, shutdownOnSignal } from \"./serve\";\nimport { buildAppWorkflows } from \"./workflows\";\n\nexport interface DevServerOptions {\n port?: number;\n entry?: string;\n /**\n * @deprecated Only used without an `entry`; an exported app sets its own\n * prefix in `brick({ prefix })`.\n */\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` is where it listens and `historyDays` how long finished\n * requests are kept on disk; zero keeps live data only. `extension` and\n * `theme` customise it (see `DashboardExtensionOptions`).\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\n/**\n * What `brick start` runs: serve the entry's default-exported app as it built\n * it (else one with the registered services), with the monitoring dashboard\n * it asks for, until SIGINT or SIGTERM.\n */\nexport async function startProdServer(options: {\n entry?: string;\n port?: number;\n /** The production dashboard's extension and theme. */\n dashboard?: DashboardExtensionOptions;\n}) {\n let exported: unknown;\n if (options.entry) {\n console.log(\n `[Brick-TS] Loading application entry: ${resolve(options.entry)}`,\n );\n exported = await importEntry(options.entry, { run: true });\n }\n const port = resolvePort(options.port);\n const app = isBrickApp(exported) ? exported : brick();\n await buildAppWorkflows(app);\n const dashboard = await serveApp(app, {\n port,\n dashboard: options.dashboard,\n });\n shutdownOnSignal(app);\n printBanner(app, { label: \"Production\", port, dashboard });\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 console.log(\n `[Brick-TS] Loading application entry: ${resolve(options.entry)}`,\n );\n const app = await importEntry(options.entry, { run: true });\n if (!isBrickApp(app))\n throw new ConfigError(\n \"Brick: a worker needs an entry that default-exports a BrickApp.\",\n );\n if (!app.events)\n throw new ConfigError(\n \"Brick: this app has no events, so a worker has nothing to deliver.\",\n );\n if (!app.events.describe().dispatch)\n throw new ConfigError(\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 await app.start();\n app.events.start();\n shutdownOnSignal(app);\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\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 ConfigError(\n \"Brick: --client and --frontend require an app entry.\",\n );\n if (options.frontend && !options.clientOutput)\n throw new ConfigError(\"Brick: --frontend requires --client <file>.\");\n const port = resolvePort(options.port);\n if (!entry) return startDevApplication({ port, prefix: options.prefix });\n const resolvedEntry = resolve(entry);\n if (!existsSync(resolvedEntry))\n throw new ConfigError(\n `[Brick-TS] Error: Entry file not found: ${resolvedEntry}`,\n );\n\n if (\n options.dashboard &&\n (options.dashboard.port ?? DEFAULT_DASHBOARD_PORT) === port\n )\n throw new ConfigError(\n \"Brick: dashboard port must differ from the API port. Use --dashboard-port <number>.\",\n );\n const manifest = options.manifest;\n if (manifest) await writeServiceManifest(manifest);\n const contract = resolve(\n options.clientOutput ??\n join(manifest?.generated ?? PROJECT_DEFAULTS.generated, CONTRACT_FILE),\n );\n const workerOptions: WorkerOptions = {\n entry: resolvedEntry,\n port,\n prefix: options.prefix,\n clientOutput: options.clientOutput && contract,\n telemetry: Boolean(options.dashboard),\n };\n // Bind the dashboard before the first worker starts, so the worker's spans\n // have somewhere to go.\n const dashboard = options.dashboard\n ? await openDashboard({\n port: options.dashboard.port,\n directory: process.cwd(),\n historyDays: options.dashboard.historyDays,\n warn: (message) => console.warn(message),\n docs: true,\n dashboard: {\n extension: options.dashboard.extension,\n theme: options.dashboard.theme,\n },\n restart: () => {\n void restart(\"dashboard\");\n },\n portHint: \"Use --dashboard-port <number> or --no-dashboard.\",\n })\n : undefined;\n const telemetry = dashboard?.store;\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 const receive = (message: WorkerMessage, generation: number) => {\n switch (message.type) {\n case \"brick:telemetry\":\n telemetry?.ingest(message.records, generation);\n return;\n case \"brick:error\":\n telemetry?.recordWorkerError(message.phase, message.error, generation);\n return;\n case \"brick:contract-ready\":\n if (options.frontend && !frontend && !stopped)\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 telemetry?.recordReload({\n kind: \"contract-ready\",\n generation,\n detail: \"browser contract generated\",\n });\n return;\n case \"brick:architecture\":\n telemetry?.setArchitecture(message.architecture, generation);\n void dashboard?.setPluginExtensions(message.architecture.plugins ?? []);\n return;\n case \"brick:inspector\":\n if (generation === telemetry?.latestGeneration)\n telemetry.setInspector({ port: message.port, token: message.token });\n return;\n case \"brick:documentation\":\n void dashboard?.docs?.configure(\n dirname(resolvedEntry),\n message.documentation,\n );\n return;\n case \"brick:api-documents\":\n telemetry?.setApiDocuments(\n message.documents,\n `http://localhost:${port}`,\n );\n return;\n case \"brick:dependencies\":\n for (const file of message.files) {\n if (file === contract) 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 return;\n }\n };\n const launch = () => {\n // The new process serves its own inspector once it is up.\n telemetry?.setInspector(undefined);\n const generation = telemetry?.startGeneration() ?? 0;\n const application = Bun.spawn(\n [\n process.execPath,\n ownModule(\"dev-worker\"),\n JSON.stringify(workerOptions),\n ],\n {\n cwd: process.cwd(),\n stdout: \"inherit\",\n stderr: \"inherit\",\n ipc: (message: WorkerMessage) => receive(message, generation),\n },\n );\n void application.exited.then((code) => {\n if (generation === telemetry?.latestGeneration)\n 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 if (dashboard) {\n console.log(`📊 Dev dashboard: http://127.0.0.1:${dashboard.port}`);\n }\n let child = launch();\n // The worker reports the other files the entry imports (brick:dependencies).\n const watchDirs = [\n ...new Set([\n dirname(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: telemetry.latestGeneration,\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 === contract ||\n basename(file).startsWith(TEMPORARY_FILE_PREFIX) ||\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 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","import { aot } from \"elysia/plugin/aot/bun\";\nimport type { BunPlugin } from \"bun\";\n\n/** Keep the pinned Elysia beta's incomplete stripping from breaking builds. */\nexport function brickAot(entry: string, hasSockets: boolean): BunPlugin {\n // WS routes still need cookie setup during reconstruction in beta.29.\n // Retain those modules while continuing to precompile HTTP handlers.\n if (hasSockets) return aot(entry, { target: \"bun\", strip: false });\n return {\n name: \"brick-elysia-aot\",\n async setup(build) {\n await aot(entry, { target: \"bun\", strip: true }).setup({\n ...build,\n onLoad(options, callback) {\n return build.onLoad(options, async (args) => {\n const result = await callback(args);\n if (\n !result ||\n !(\"contents\" in result) ||\n typeof result.contents !== \"string\"\n )\n return result;\n let contents = result.contents;\n if (\n /[/\\\\]elysia[/\\\\]dist[/\\\\]ws[/\\\\]route\\.m?js$/.test(args.path) &&\n contents.includes(\n \"[elysia-aot] WebSocket route builder was stripped\",\n )\n ) {\n for (const name of [\"resolveWSOptions\", \"accumulateWSOptions\"]) {\n if (!contents.includes(`export function ${name}`))\n contents += `\\nexport function ${name}() { throw new Error(\"WebSocket support was stripped\"); }\\n`;\n }\n }\n return contents === result.contents\n ? result\n : { ...result, contents };\n });\n },\n });\n },\n };\n}\n","import { mkdtemp, mkdir, rename, rm } from \"node:fs/promises\";\nimport { dirname, join, resolve } from \"node:path\";\nimport { compileBrickApplication } from \"@brickkit/core\";\nimport type { BunPlugin } from \"bun\";\nimport { emitCompiledApplication } from \"./compiler\";\nimport { brickAot } from \"./compiler/aot\";\nimport { loadBrickApp } from \"./app-entry\";\nimport { ownModule } from \"./own-module\";\nimport { DEFAULT_OUTDIR, resolvePort } from \"./config\";\nimport { buildAppWorkflows, workflowTransformPlugin } from \"./workflows\";\nimport {\n themeCss,\n writeDashboardExtension,\n type DashboardExtensionOptions,\n} from \"./dashboard-extension\";\n\nexport interface BuildApplicationOptions {\n /** A module whose default export is a BrickApp, without starting a server. */\n entry: string;\n outdir?: string;\n port?: number;\n /** Precompile Elysia's HTTP handlers at build time (default true). */\n aot?: boolean;\n /**\n * The dashboard's extension, built into `<outdir>/dashboard` with those of\n * the app's plugins for the production dashboard to serve; its theme is\n * checked here too.\n */\n dashboard?: DashboardExtensionOptions;\n}\n\n/**\n * The production dashboard stays out of the bundle: it serves files that ship\n * with @brickkit/cli, so a built server whose app asks for it imports it from\n * there at run time. Without a dashboard the bundle needs nothing installed.\n */\nconst productionDashboardAtRunTime: BunPlugin = {\n name: \"brick:production-dashboard\",\n setup(build) {\n build.onResolve({ filter: /^\\.\\/production-dashboard(\\.[jt]s)?$/ }, () => ({\n path: \"@brickkit/cli/production-dashboard\",\n external: true,\n }));\n },\n};\n\n/** The files `brick build` writes to the output folder, `server.js` last. */\nconst OUTPUTS = [\"routes.js\", \"brick-ir.json\", \"server.js.map\", \"server.js\"];\n\n/** Bundle an exported BrickApp with its compiled IR and its original configuration. */\nexport async function buildApplication(options: BuildApplicationOptions) {\n const entry = resolve(options.entry);\n if (!(await Bun.file(entry).exists()))\n throw new Error(`Brick compiler: entry not found: ${entry}`);\n const outdir = resolve(options.outdir ?? DEFAULT_OUTDIR);\n if (OUTPUTS.some((name) => entry === join(outdir, name)))\n throw new Error(\n \"Brick compiler: output would overwrite the application entry\",\n );\n const port = resolvePort(options.port, undefined, \"\");\n themeCss(options.dashboard?.theme);\n const extension = options.dashboard?.extension\n ? resolve(options.dashboard.extension)\n : undefined;\n if (extension && !(await Bun.file(extension).exists()))\n throw new Error(\n `Brick compiler: dashboard extension not found: ${extension}`,\n );\n const app = await loadBrickApp(entry);\n // The bundle stays in the project, where the server finds it from the working\n // directory, as `brick start` does.\n await buildAppWorkflows(app);\n const services = [...app.definition.services];\n const compilation = compileBrickApplication({\n services,\n prefix: app.definition.prefix,\n });\n await mkdir(dirname(outdir), { recursive: true });\n const staging = await mkdtemp(join(dirname(outdir), \".brick-build-\"));\n try {\n await Bun.write(\n join(staging, \"routes.js\"),\n emitCompiledApplication(compilation.ir),\n );\n const dashboard = (await writeDashboardExtension(\n extension,\n app.definition.plugins ?? [],\n join(staging, \"dashboard\"),\n ))\n ? join(outdir, \"dashboard\")\n : undefined;\n const theme = JSON.stringify(options.dashboard?.theme);\n const source = `import { fileURLToPath } from \"node:url\";\nimport { loadCompiledBrickApp } from \"@brickkit/core\";\nimport { resolvePort } from ${JSON.stringify(ownModule(\"config\"))};\nimport { serveApp, shutdownOnSignal } from ${JSON.stringify(ownModule(\"serve\"))};\nimport { ir } from \"./routes.js\";\nexport const app = await loadCompiledBrickApp(() => import(${JSON.stringify(entry)}), ir);\nif (import.meta.main) {\n await serveApp(app, {\n port: resolvePort(undefined, ${port}),\n dashboard: { extension: ${dashboard ? 'fileURLToPath(new URL(\"./dashboard\", import.meta.url))' : \"undefined\"}, theme: ${theme} },\n });\n console.log(\"Brick compiled server listening on http://localhost:\" + app.server.port);\n shutdownOnSignal(app);\n}\n`;\n await Bun.write(join(staging, \"entry.ts\"), source);\n const workflows = app.events?.workflows\n ? await workflowTransformPlugin(app.events.workflows.root)\n : undefined;\n const result = await Bun.build({\n entrypoints: [join(staging, \"entry.ts\")],\n target: \"bun\",\n format: \"esm\",\n outdir: staging,\n naming: \"server.js\",\n sourcemap: \"external\",\n // AOT first: the workflow plugin loads every project file it sees, so after\n // it the AOT plugin would never get to transform the entry.\n plugins: [\n ...(options.aot === false\n ? []\n : [\n brickAot(\n join(staging, \"entry.ts\"),\n app.definition.sockets.length > 0,\n ),\n ]),\n ...(workflows ? [workflows] : []),\n productionDashboardAtRunTime,\n ],\n });\n if (!result.success)\n throw new AggregateError(result.logs, \"Brick compiler: bundling failed\");\n await Bun.write(\n join(staging, \"brick-ir.json\"),\n JSON.stringify(compilation.ir, null, 2) + \"\\n\",\n );\n await mkdir(outdir, { recursive: true });\n for (const name of OUTPUTS)\n await rename(join(staging, name), join(outdir, name));\n if (dashboard) {\n await rm(dashboard, { recursive: true, force: true });\n await rename(join(staging, \"dashboard\"), dashboard);\n }\n return {\n outdir,\n entry: join(outdir, \"server.js\"),\n ir: compilation.ir,\n dashboard,\n };\n } finally {\n await rm(staging, { recursive: true, force: true });\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAaA,MAAM,QAAmC,CAAC,WAAW,UAAU;AAE/D,SAAS,KAAK,MAAc;CAC1B,MAAM,QAAQ,MAAM,QAClB,gBAAgB,KAAK,IAAI,CAAC,GAAG,EAC/B;CACA,OAAO,UAAU,KAAK,MAAM,SAAS;AACvC;;AAGA,SAAgB,oBAAoB,UAA4B;CAC9D,IAAI,CAAC,WAAW,QAAQ,GAAG,OAAO,CAAC;CASnC,OAHc,CAAC,GAAG,IAHD,IAAI,KACnB,SAAS,iBAAiB,KAAK,GAAG,EAAE,KAAK,sBAAsB,KAAK,GAAG,EAAE,EAEtD,CAAC,CAAC,SAAS;EAAE,KAAK;EAAU,WAAW;CAAK,CAAC,CAAC,CAAC,CACjE,KAAK,SAAS,KAAK,MAAM,GAAG,CAAC,CAAC,KAAK,GAAG,CAAC,CAAC,CACxC,QAAQ,SAAS,CAAC,KAAK,MAAM,GAAG,CAAC,CAAC,SAAS,cAAc,CACjD,CAAC,CAAC,MACV,GAAG,MAAM,KAAK,CAAC,IAAI,KAAK,CAAC,MAAM,IAAI,IAAI,KAAK,IAAI,IAAI,IAAI,EAC3D;AACF;;AAGA,SAAgB,eAAe,UAAkB,WAA2B;CAS1E,OAAO;;;EARS,oBAAoB,QAAQ,CAAC,CAAC,KAAK,SAAS;EAC1D,IAAI,YAAY,SAAS,WAAW,KAAK,UAAU,IAAI,CAAC,CAAC,CACtD,MAAM,GAAG,CAAC,CACV,KAAK,GAAG,CAAC,CACT,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