sordo 0.4.0 → 1.0.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/CHANGELOG.md +6 -116
- package/README.md +8 -175
- package/bin/sordo.ts +1 -4
- package/package.json +17 -41
- package/src/agents-md.ts +1 -0
- package/src/ai.ts +1 -0
- package/src/build.ts +1 -0
- package/src/client.ts +1 -0
- package/src/config.ts +1 -0
- package/src/dev.ts +1 -0
- package/src/index.ts +1 -55
- package/src/middleware.ts +1 -0
- package/src/plugin.ts +1 -0
- package/src/render.ts +1 -0
- package/src/router.ts +1 -0
- package/src/server.ts +1 -0
- package/CLAUDE.md +0 -124
- package/src/adapters/bun.ts +0 -59
- package/src/adapters/edge.ts +0 -75
- package/src/adapters/types.ts +0 -43
- package/src/agents-md/collect.ts +0 -113
- package/src/agents-md/generate.ts +0 -44
- package/src/agents-md/index.ts +0 -9
- package/src/agents-md/render.ts +0 -150
- package/src/agents-md/subprocess-entry.ts +0 -92
- package/src/agents-md/subprocess-runner.ts +0 -111
- package/src/agents-md/write.ts +0 -38
- package/src/agents-md/zod-to-json-schema.ts +0 -18
- package/src/ai/context.ts +0 -72
- package/src/ai/define.ts +0 -15
- package/src/ai/errors.ts +0 -51
- package/src/ai/index.ts +0 -36
- package/src/ai/middleware.ts +0 -21
- package/src/ai/registry.ts +0 -96
- package/src/ai/run.ts +0 -185
- package/src/ai/scan.ts +0 -42
- package/src/ai/stream.ts +0 -71
- package/src/ai/triggers.ts +0 -124
- package/src/ai/types.ts +0 -67
- package/src/ai/validate.ts +0 -82
- package/src/build/assets.ts +0 -48
- package/src/build/client-entry.ts +0 -43
- package/src/build/css.ts +0 -102
- package/src/build/embedded.ts +0 -66
- package/src/build/hash.ts +0 -21
- package/src/build/index.ts +0 -480
- package/src/build/macros/agents-hash.macro.ts +0 -9
- package/src/build/macros/agents.macro.ts +0 -21
- package/src/build/macros/env.macro.ts +0 -25
- package/src/build/macros/inline-assets.macro.ts +0 -28
- package/src/build/macros/manifest.macro.ts +0 -8
- package/src/build/macros/routes.macro.ts +0 -10
- package/src/build/page-entry.ts +0 -136
- package/src/build/scan-islands.ts +0 -39
- package/src/build/server-entry.ts +0 -256
- package/src/cli/ansi.ts +0 -41
- package/src/cli/build.ts +0 -195
- package/src/cli/commands/add/apply.ts +0 -31
- package/src/cli/commands/add/component-diff.ts +0 -116
- package/src/cli/commands/add/diff.ts +0 -153
- package/src/cli/commands/add/internal.ts +0 -41
- package/src/cli/commands/add/load-catalog.ts +0 -22
- package/src/cli/commands/add/peer-deps.ts +0 -115
- package/src/cli/commands/add/registry-fetch.ts +0 -122
- package/src/cli/commands/add/shadcn.ts +0 -285
- package/src/cli/commands/add/source.ts +0 -273
- package/src/cli/commands/add/stamper.ts +0 -73
- package/src/cli/commands/add/tokens.ts +0 -81
- package/src/cli/commands/add/ui-paths.ts +0 -113
- package/src/cli/commands/add.ts +0 -427
- package/src/cli/commands/deploy.ts +0 -143
- package/src/cli/commands/migrate.ts +0 -149
- package/src/cli/commands/secret.ts +0 -316
- package/src/cli/commands/ui/build.ts +0 -111
- package/src/cli/commands/ui/init.ts +0 -135
- package/src/cli/commands/ui/migrate/git-guard.ts +0 -19
- package/src/cli/commands/ui/migrate/radix.ts +0 -67
- package/src/cli/commands/ui/migrate/rtl.ts +0 -148
- package/src/cli/commands/ui/shadcn.ts +0 -82
- package/src/cli/commands/ui/view.ts +0 -63
- package/src/cli/commands/ui.ts +0 -86
- package/src/cli/commands/update.ts +0 -134
- package/src/cli/commands/upgrade.ts +0 -53
- package/src/cli/commands/view.ts +0 -34
- package/src/cli/dev.ts +0 -393
- package/src/cli/doctor/config-checks.ts +0 -63
- package/src/cli/doctor/deps.ts +0 -295
- package/src/cli/doctor/hydrate.ts +0 -65
- package/src/cli/doctor/monorepo.ts +0 -158
- package/src/cli/doctor/probes.ts +0 -16
- package/src/cli/doctor/report.ts +0 -72
- package/src/cli/doctor/toolchain.ts +0 -95
- package/src/cli/doctor/types.ts +0 -36
- package/src/cli/doctor.ts +0 -127
- package/src/cli/index.ts +0 -168
- package/src/cli/log.ts +0 -135
- package/src/cli/run/affected.ts +0 -79
- package/src/cli/run/cache-key.ts +0 -177
- package/src/cli/run/cache-store.ts +0 -0
- package/src/cli/run/files.ts +0 -96
- package/src/cli/run/git.ts +0 -13
- package/src/cli/run/runner.ts +0 -189
- package/src/cli/run/workspace.ts +0 -216
- package/src/cli/run.ts +0 -184
- package/src/cli/start.ts +0 -99
- package/src/cli/update-check.ts +0 -157
- package/src/client/index.ts +0 -65
- package/src/client/link.tsx +0 -61
- package/src/client/page.ts +0 -250
- package/src/config/define.ts +0 -5
- package/src/config/env.ts +0 -36
- package/src/config/load.ts +0 -152
- package/src/config/schema.ts +0 -135
- package/src/config/secrets.ts +0 -108
- package/src/dev/client.ts +0 -112
- package/src/dev/hot.ts +0 -24
- package/src/dev/index.ts +0 -4
- package/src/dev/tree.ts +0 -95
- package/src/dev/watcher.ts +0 -95
- package/src/internal/hmr-client.ts +0 -52
- package/src/internal/open-in-editor.ts +0 -23
- package/src/internal/runtime.ts +0 -30
- package/src/middleware/cookie-jar.ts +0 -135
- package/src/middleware/cookies.ts +0 -60
- package/src/middleware/index.ts +0 -127
- package/src/middleware/request-id.ts +0 -22
- package/src/middleware/response-helpers.ts +0 -25
- package/src/plugin/index.ts +0 -109
- package/src/render/bootstrap.ts +0 -44
- package/src/render/dev-error.tsx +0 -73
- package/src/render/index.tsx +0 -261
- package/src/render/island.tsx +0 -33
- package/src/render/meta.tsx +0 -48
- package/src/render/shell.tsx +0 -41
- package/src/router/conflict.ts +0 -20
- package/src/router/filesystem.ts +0 -37
- package/src/router/index.ts +0 -247
- package/src/router/match.ts +0 -91
- package/src/router/pattern.ts +0 -88
- package/src/server/index.ts +0 -250
- package/src/server/inline-assets.ts +0 -39
- package/src/types.ts +0 -53
- package/src/ui/schema.ts +0 -68
- package/src/ui/types.ts +0 -10
- package/templates/_internal/cn.ts +0 -6
- package/templates/_internal/slot.ts +0 -50
- package/templates/_internal/variants.ts +0 -1
- package/templates/themes/neutral/tokens.css +0 -46
- package/templates/themes/slate/tokens.css +0 -46
- package/templates/themes/stone/tokens.css +0 -46
- package/templates/themes/zinc/tokens.css +0 -46
- package/templates/tokens.css +0 -46
package/src/cli/dev.ts
DELETED
|
@@ -1,393 +0,0 @@
|
|
|
1
|
-
import { existsSync, readFileSync, realpathSync } from "node:fs";
|
|
2
|
-
import { dirname, resolve } from "node:path";
|
|
3
|
-
import pkg from "../../package.json" with { type: "json" };
|
|
4
|
-
import { generateAgentsMd } from "../agents-md/generate.ts";
|
|
5
|
-
import { writeManifestToFile } from "../agents-md/write.ts";
|
|
6
|
-
import { MissingEnv, validateRequiredEnv } from "../config/env.ts";
|
|
7
|
-
import { loadConfig } from "../config/load.ts";
|
|
8
|
-
import { loadSecrets } from "../config/secrets.ts";
|
|
9
|
-
import { hotState } from "../dev/hot.ts";
|
|
10
|
-
import { watchAppTree } from "../dev/tree.ts";
|
|
11
|
-
import { createDevServer } from "../dev/watcher.ts";
|
|
12
|
-
import { assertPluginCompat, type Plugin } from "../plugin/index.ts";
|
|
13
|
-
import { startServer } from "../server/index.ts";
|
|
14
|
-
import type { CliContext } from "./index.ts";
|
|
15
|
-
import { EXIT, installSigintHandler, log } from "./log.ts";
|
|
16
|
-
|
|
17
|
-
const FRAMEWORK_VERSION = (pkg as { version: string }).version;
|
|
18
|
-
|
|
19
|
-
export interface DevArgs {
|
|
20
|
-
cold: boolean;
|
|
21
|
-
port: number | null;
|
|
22
|
-
host: string | null;
|
|
23
|
-
appDir: string | null;
|
|
24
|
-
noOpen: boolean;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
export const REEXEC_FLAG = "SORDO_DEV_HOT";
|
|
28
|
-
|
|
29
|
-
// Resolves to `null` once the dev server is up: the server owns the process
|
|
30
|
-
// from then on. The caller must not exit, and must not block on a promise that
|
|
31
|
-
// never settles either — `bun --hot` only reloads an entry whose top-level
|
|
32
|
-
// evaluation has finished.
|
|
33
|
-
export async function runDev(
|
|
34
|
-
argv: string[],
|
|
35
|
-
ctx: CliContext = { cwd: process.cwd(), verbose: false },
|
|
36
|
-
): Promise<number | null> {
|
|
37
|
-
const args = parseArgs(argv, ctx.cwd);
|
|
38
|
-
|
|
39
|
-
if (process.env[REEXEC_FLAG] !== "1") {
|
|
40
|
-
return reexecUnderBun(args, ctx);
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
return bootstrap(args, ctx);
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
function parseArgs(argv: string[], cwd: string): DevArgs {
|
|
47
|
-
const out: DevArgs = {
|
|
48
|
-
cold: false,
|
|
49
|
-
port: null,
|
|
50
|
-
host: null,
|
|
51
|
-
appDir: null,
|
|
52
|
-
noOpen: false,
|
|
53
|
-
};
|
|
54
|
-
for (let i = 0; i < argv.length; i++) {
|
|
55
|
-
const a = argv[i];
|
|
56
|
-
if (a === undefined) continue;
|
|
57
|
-
if (a === "--cold") out.cold = true;
|
|
58
|
-
else if (a === "--no-open") out.noOpen = true;
|
|
59
|
-
else if (a === "--port") out.port = Number(argv[++i]);
|
|
60
|
-
else if (a === "--host") out.host = String(argv[++i]);
|
|
61
|
-
else if (a === "--app") out.appDir = resolve(cwd, String(argv[++i]));
|
|
62
|
-
else if (a.startsWith("--port=")) out.port = Number(a.slice(7));
|
|
63
|
-
else if (a.startsWith("--host=")) out.host = a.slice(7);
|
|
64
|
-
else if (a.startsWith("--app=")) out.appDir = resolve(cwd, a.slice(6));
|
|
65
|
-
}
|
|
66
|
-
return out;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
interface ResolvedDev {
|
|
70
|
-
port: number;
|
|
71
|
-
host: string;
|
|
72
|
-
appDir: string;
|
|
73
|
-
unix: string | undefined;
|
|
74
|
-
reusePort: boolean | undefined;
|
|
75
|
-
requiredEnv: string[];
|
|
76
|
-
secrets: string[];
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
async function resolveDev(
|
|
80
|
-
args: DevArgs,
|
|
81
|
-
ctx: CliContext,
|
|
82
|
-
): Promise<ResolvedDev> {
|
|
83
|
-
const { config } = await loadConfig({
|
|
84
|
-
cwd: ctx.cwd,
|
|
85
|
-
configPath: ctx.configPath,
|
|
86
|
-
});
|
|
87
|
-
const envPort = process.env.PORT ? Number(process.env.PORT) : undefined;
|
|
88
|
-
const envHost = process.env.HOST;
|
|
89
|
-
return {
|
|
90
|
-
port: args.port ?? envPort ?? config.server.port,
|
|
91
|
-
host: args.host ?? envHost ?? config.server.hostname,
|
|
92
|
-
appDir: args.appDir ?? config.appDir,
|
|
93
|
-
unix: config.server.unix,
|
|
94
|
-
reusePort: config.server.reusePort,
|
|
95
|
-
requiredEnv: config.env.required,
|
|
96
|
-
secrets: config.secrets,
|
|
97
|
-
};
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
async function reexecUnderBun(args: DevArgs, ctx: CliContext): Promise<number> {
|
|
101
|
-
const { appDir } = await resolveDev(args, ctx);
|
|
102
|
-
const entry = resolveReexecEntry(ctx.cwd);
|
|
103
|
-
const mode = args.cold ? "--watch" : "--hot";
|
|
104
|
-
const passthrough: string[] = [];
|
|
105
|
-
if (ctx.cwd !== process.cwd()) passthrough.push("--cwd", ctx.cwd);
|
|
106
|
-
if (ctx.configPath) passthrough.push("--config", ctx.configPath);
|
|
107
|
-
if (ctx.verbose) passthrough.push("--verbose");
|
|
108
|
-
passthrough.push("dev");
|
|
109
|
-
if (args.cold) passthrough.push("--cold");
|
|
110
|
-
if (args.noOpen) passthrough.push("--no-open");
|
|
111
|
-
if (args.port !== null) passthrough.push("--port", String(args.port));
|
|
112
|
-
if (args.host !== null) passthrough.push("--host", args.host);
|
|
113
|
-
if (args.appDir !== null) passthrough.push("--app", args.appDir);
|
|
114
|
-
// `--preserve-symlinks` keeps module resolution rooted in the user's
|
|
115
|
-
// project when `sordo` is linked from a workspace / `bun link`. Without
|
|
116
|
-
// it, framework files realpath into the framework's own `node_modules`,
|
|
117
|
-
// loading a *second* copy of React alongside the app's — which breaks
|
|
118
|
-
// hooks during SSR ("Invalid hook call"). Paired with `resolveReexecEntry`'s
|
|
119
|
-
// upward search, this also anchors resolution to the hoisted workspace-root
|
|
120
|
-
// copy in a Bun-workspace monorepo, where `react`/`sordo` live at the root.
|
|
121
|
-
const spawn = () =>
|
|
122
|
-
Bun.spawn(["bun", "--preserve-symlinks", mode, entry, ...passthrough], {
|
|
123
|
-
stdio: ["inherit", "inherit", "inherit"],
|
|
124
|
-
env: { ...process.env, [REEXEC_FLAG]: "1" },
|
|
125
|
-
});
|
|
126
|
-
let proc = spawn();
|
|
127
|
-
let restartPending = false;
|
|
128
|
-
// A new or deleted file is invisible to `bun --hot` (it isn't in the module
|
|
129
|
-
// graph yet), so the route/island tables would stay stale. Restart the child;
|
|
130
|
-
// connected browsers see a new server id on reconnect and reload.
|
|
131
|
-
const tree = watchAppTree(appDir, () => {
|
|
132
|
-
if (restartPending) return;
|
|
133
|
-
restartPending = true;
|
|
134
|
-
log.dim(" ↻ app files added or removed — restarting dev server");
|
|
135
|
-
try {
|
|
136
|
-
proc.kill("SIGTERM");
|
|
137
|
-
} catch {}
|
|
138
|
-
});
|
|
139
|
-
// Forward termination signals to the child so it doesn't get orphaned
|
|
140
|
-
// (reparented to init) and keep holding the listen port.
|
|
141
|
-
const forward = (sig: NodeJS.Signals) => {
|
|
142
|
-
tree.close();
|
|
143
|
-
restartPending = false;
|
|
144
|
-
try {
|
|
145
|
-
proc.kill(sig);
|
|
146
|
-
} catch {}
|
|
147
|
-
};
|
|
148
|
-
const onInt = () => forward("SIGINT");
|
|
149
|
-
const onTerm = () => forward("SIGTERM");
|
|
150
|
-
const onHup = () => forward("SIGHUP");
|
|
151
|
-
process.on("SIGINT", onInt);
|
|
152
|
-
process.on("SIGTERM", onTerm);
|
|
153
|
-
process.on("SIGHUP", onHup);
|
|
154
|
-
try {
|
|
155
|
-
while (true) {
|
|
156
|
-
const code = await proc.exited;
|
|
157
|
-
if (!restartPending) return code ?? 0;
|
|
158
|
-
restartPending = false;
|
|
159
|
-
proc = spawn();
|
|
160
|
-
}
|
|
161
|
-
} finally {
|
|
162
|
-
tree.close();
|
|
163
|
-
process.off("SIGINT", onInt);
|
|
164
|
-
process.off("SIGTERM", onTerm);
|
|
165
|
-
process.off("SIGHUP", onHup);
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
// Prefer the user-project copy of the bin (under their `node_modules/sordo`)
|
|
170
|
-
// over `process.argv[1]`, which may have already been realpath'd to the linked
|
|
171
|
-
// framework checkout. Combined with `--preserve-symlinks`, this keeps module
|
|
172
|
-
// resolution anchored in the user's project so `react` / `react-dom` resolve
|
|
173
|
-
// to a single copy.
|
|
174
|
-
//
|
|
175
|
-
// In a Bun-workspace monorepo, `sordo` is hoisted to the workspace-root
|
|
176
|
-
// `node_modules`, so `<cwd>/node_modules/sordo` does not exist when `cwd` is
|
|
177
|
-
// an app dir (e.g. `apps/web`). Climb parent `node_modules` directories and
|
|
178
|
-
// return the nearest existing bin — the hoisted root copy — restoring the
|
|
179
|
-
// app-tree anchor. In a flat app the first iteration matches, so behavior is
|
|
180
|
-
// unchanged. Stop at the first hit: a nested install is intentional if present.
|
|
181
|
-
export function resolveReexecEntry(cwd: string): string {
|
|
182
|
-
let dir = cwd;
|
|
183
|
-
while (true) {
|
|
184
|
-
const candidate = `${dir}/node_modules/sordo/bin/sordo.ts`;
|
|
185
|
-
if (existsSync(candidate)) return candidate;
|
|
186
|
-
const parent = dirname(dir);
|
|
187
|
-
if (parent === dir) break; // reached filesystem root
|
|
188
|
-
dir = parent;
|
|
189
|
-
}
|
|
190
|
-
return process.argv[1] ?? "";
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
// SSR hooks read a module-level dispatcher inside `react`; if app components and
|
|
194
|
-
// the renderer (framework) resolve to *different* `react` instances, hooks crash
|
|
195
|
-
// with the cryptic "Invalid hook call." The real invariant is that the `react`
|
|
196
|
-
// reachable from the app equals the `react` reachable from the framework — in a
|
|
197
|
-
// hoisted monorepo a nested `apps/web/node_modules/react` makes the app resolve a
|
|
198
|
-
// copy the root-hoisted framework never sees. Detect that at boot and fail with
|
|
199
|
-
// both paths, instead of crashing later mid-render. Return-based so a future
|
|
200
|
-
// `sordo doctor` can reuse it. `projectDir` is the app *package* dir (e.g.
|
|
201
|
-
// `apps/web`), scanned for any extra nested copy as defense in depth.
|
|
202
|
-
export function assertSingleReact(
|
|
203
|
-
projectDir: string,
|
|
204
|
-
appDir: string,
|
|
205
|
-
frameworkDir: string,
|
|
206
|
-
): { ok: true } | { ok: false; message: string } {
|
|
207
|
-
// realpath → human label, deduped so a single shared copy collapses to one.
|
|
208
|
-
const copies = new Map<string, string>();
|
|
209
|
-
const add = (label: string, fromDir: string): void => {
|
|
210
|
-
try {
|
|
211
|
-
const real = realpathSync(Bun.resolveSync("react/package.json", fromDir));
|
|
212
|
-
if (!copies.has(real)) copies.set(real, label);
|
|
213
|
-
} catch {
|
|
214
|
-
// No React reachable from this anchor — a genuinely missing React
|
|
215
|
-
// surfaces elsewhere (the import itself); only duplicates concern us.
|
|
216
|
-
}
|
|
217
|
-
};
|
|
218
|
-
add(appDir, appDir);
|
|
219
|
-
add("framework", frameworkDir);
|
|
220
|
-
|
|
221
|
-
const glob = new Bun.Glob("**/node_modules/react/package.json");
|
|
222
|
-
for (const hit of glob.scanSync({ cwd: projectDir, onlyFiles: true })) {
|
|
223
|
-
try {
|
|
224
|
-
const real = realpathSync(resolve(projectDir, hit));
|
|
225
|
-
if (!copies.has(real)) copies.set(real, "nested");
|
|
226
|
-
} catch {}
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
if (copies.size <= 1) return { ok: true };
|
|
230
|
-
|
|
231
|
-
const lines = ["✗ Two copies of React detected — SSR hooks will crash."];
|
|
232
|
-
for (const [real, label] of copies) {
|
|
233
|
-
lines.push(` ${label} → ${real} (${readPkgVersion(real)})`);
|
|
234
|
-
}
|
|
235
|
-
lines.push(
|
|
236
|
-
" Align the version so Bun can hoist a single copy, then `bun install`.",
|
|
237
|
-
);
|
|
238
|
-
return { ok: false, message: lines.join("\n") };
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
function readPkgVersion(pkgJsonPath: string): string {
|
|
242
|
-
try {
|
|
243
|
-
const { version } = JSON.parse(readFileSync(pkgJsonPath, "utf8")) as {
|
|
244
|
-
version?: string;
|
|
245
|
-
};
|
|
246
|
-
return version ?? "unknown";
|
|
247
|
-
} catch {
|
|
248
|
-
return "unknown";
|
|
249
|
-
}
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
async function bootstrap(
|
|
253
|
-
args: DevArgs,
|
|
254
|
-
ctx: CliContext,
|
|
255
|
-
): Promise<number | null> {
|
|
256
|
-
const { config } = await loadConfig({
|
|
257
|
-
cwd: ctx.cwd,
|
|
258
|
-
configPath: ctx.configPath,
|
|
259
|
-
});
|
|
260
|
-
const resolved = await resolveDev(args, ctx);
|
|
261
|
-
// `bun --hot` re-runs this whole bootstrap (and the user's `start`) on every
|
|
262
|
-
// edit; `Bun.serve` hot-swaps its handlers in place on the second call.
|
|
263
|
-
const reloaded = ++hotState().generation > 1;
|
|
264
|
-
|
|
265
|
-
// `import.meta.dir` is where framework files resolve `react` from — the same
|
|
266
|
-
// upward walk the renderer uses — so it's the right "framework" anchor.
|
|
267
|
-
// The check walks `node_modules`, so it runs once per process, not per edit.
|
|
268
|
-
if (!reloaded) {
|
|
269
|
-
const react = assertSingleReact(ctx.cwd, resolved.appDir, import.meta.dir);
|
|
270
|
-
if (!react.ok) {
|
|
271
|
-
log.error(react.message);
|
|
272
|
-
return EXIT.ERROR;
|
|
273
|
-
}
|
|
274
|
-
}
|
|
275
|
-
|
|
276
|
-
await loadSecrets(config, { cwd: ctx.cwd });
|
|
277
|
-
try {
|
|
278
|
-
validateRequiredEnv(resolved.requiredEnv);
|
|
279
|
-
} catch (err) {
|
|
280
|
-
if (err instanceof MissingEnv) {
|
|
281
|
-
log.error(err.message);
|
|
282
|
-
return EXIT.ERROR;
|
|
283
|
-
}
|
|
284
|
-
throw err;
|
|
285
|
-
}
|
|
286
|
-
|
|
287
|
-
const plugins = (config.plugins ?? []) as Plugin[];
|
|
288
|
-
for (const p of plugins) assertPluginCompat(FRAMEWORK_VERSION, p);
|
|
289
|
-
|
|
290
|
-
const devServer = createDevServer({ appDir: resolved.appDir });
|
|
291
|
-
|
|
292
|
-
for (const p of plugins) {
|
|
293
|
-
const hook = p.hooks?.onDevStart;
|
|
294
|
-
if (typeof hook !== "function") continue;
|
|
295
|
-
try {
|
|
296
|
-
await hook(devServer);
|
|
297
|
-
} catch (err) {
|
|
298
|
-
const msg = (err as Error)?.message ?? String(err);
|
|
299
|
-
log.error(`[plugin ${p.name}] onDevStart: ${msg}`);
|
|
300
|
-
return EXIT.ERROR;
|
|
301
|
-
}
|
|
302
|
-
}
|
|
303
|
-
|
|
304
|
-
// Initial agent-manifest generation — fire-and-forget; never crashes dev.
|
|
305
|
-
const agentsMdTargets = Array.isArray(config.agentsMd.path)
|
|
306
|
-
? config.agentsMd.path
|
|
307
|
-
: [config.agentsMd.path];
|
|
308
|
-
generateAgentsMd(resolved.appDir, {
|
|
309
|
-
appDir: resolved.appDir,
|
|
310
|
-
env: { required: config.env.required, optional: config.env.public },
|
|
311
|
-
plugins,
|
|
312
|
-
})
|
|
313
|
-
.then(async (md) => {
|
|
314
|
-
for (const t of agentsMdTargets) {
|
|
315
|
-
await writeManifestToFile(`${ctx.cwd}/${t.replace(/^\/+/, "")}`, md);
|
|
316
|
-
}
|
|
317
|
-
})
|
|
318
|
-
.catch((err) =>
|
|
319
|
-
log.warn(
|
|
320
|
-
`agent manifest generation failed: ${(err as Error)?.message ?? String(err)}`,
|
|
321
|
-
),
|
|
322
|
-
);
|
|
323
|
-
|
|
324
|
-
if (!reloaded) installSigintHandler();
|
|
325
|
-
|
|
326
|
-
const entry = findUserEntry(resolved.appDir);
|
|
327
|
-
if (entry) {
|
|
328
|
-
const mod = (await import(entry)) as { default?: unknown };
|
|
329
|
-
const start = mod.default as
|
|
330
|
-
| ((opts: {
|
|
331
|
-
devServer: typeof devServer;
|
|
332
|
-
port: number;
|
|
333
|
-
host: string;
|
|
334
|
-
appDir: string;
|
|
335
|
-
}) => void | Promise<void>)
|
|
336
|
-
| undefined;
|
|
337
|
-
if (typeof start === "function") {
|
|
338
|
-
await start({
|
|
339
|
-
devServer,
|
|
340
|
-
port: resolved.port,
|
|
341
|
-
host: resolved.host,
|
|
342
|
-
appDir: resolved.appDir,
|
|
343
|
-
});
|
|
344
|
-
if (reloaded) {
|
|
345
|
-
log.dim(" ↻ reloaded");
|
|
346
|
-
devServer.notifyChange(resolved.appDir);
|
|
347
|
-
} else {
|
|
348
|
-
printReady(resolved);
|
|
349
|
-
}
|
|
350
|
-
return null;
|
|
351
|
-
}
|
|
352
|
-
log.warn(`${entry} has no default export; starting a stub dev server.`);
|
|
353
|
-
} else {
|
|
354
|
-
log.warn(
|
|
355
|
-
`no app entry found at ${resolved.appDir}/server.ts — starting a stub dev server.`,
|
|
356
|
-
);
|
|
357
|
-
}
|
|
358
|
-
|
|
359
|
-
startServer({
|
|
360
|
-
port: resolved.port,
|
|
361
|
-
hostname: resolved.host,
|
|
362
|
-
unix: resolved.unix,
|
|
363
|
-
reusePort: resolved.reusePort,
|
|
364
|
-
dev: true,
|
|
365
|
-
devServer,
|
|
366
|
-
routes: {
|
|
367
|
-
"/": (() =>
|
|
368
|
-
new Response("sordo dev: no app entry. Create app/server.ts.", {
|
|
369
|
-
status: 200,
|
|
370
|
-
})) as never,
|
|
371
|
-
},
|
|
372
|
-
fallback: () => new Response("not found", { status: 404 }),
|
|
373
|
-
});
|
|
374
|
-
if (!reloaded) printReady(resolved);
|
|
375
|
-
return null;
|
|
376
|
-
}
|
|
377
|
-
|
|
378
|
-
function printReady(resolved: ResolvedDev): void {
|
|
379
|
-
// URL banner is printed by startServer (Local + Network). Here we only
|
|
380
|
-
// confirm dev mode is up and show the app root for orientation.
|
|
381
|
-
log.success("▲ Sordo dev ready");
|
|
382
|
-
log.dim(` root: ${resolved.appDir}`);
|
|
383
|
-
}
|
|
384
|
-
|
|
385
|
-
function findUserEntry(appDir: string): string | null {
|
|
386
|
-
const candidates = [
|
|
387
|
-
`${appDir}/server.ts`,
|
|
388
|
-
`${appDir}/server.tsx`,
|
|
389
|
-
`${appDir}/index.ts`,
|
|
390
|
-
];
|
|
391
|
-
for (const c of candidates) if (existsSync(c)) return c;
|
|
392
|
-
return null;
|
|
393
|
-
}
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
// Group C — project config validity. C.7 loads sordo.config through the real
|
|
2
|
-
// loader (so a Zod violation surfaces with its issue path); C.8 confirms an
|
|
3
|
-
// existing biome.json is well-formed JSON. Validity only — biome owns lint.
|
|
4
|
-
|
|
5
|
-
import { join } from "node:path";
|
|
6
|
-
import { loadConfig } from "../../config/load.ts";
|
|
7
|
-
import type { Finding } from "./types.ts";
|
|
8
|
-
|
|
9
|
-
/** First ` - <path>: <msg>` line from a loader error, or the first line. */
|
|
10
|
-
function firstIssue(message: string): string {
|
|
11
|
-
const lines = message.split("\n");
|
|
12
|
-
const issue = lines.find((l) => l.trim().startsWith("- "));
|
|
13
|
-
return (issue ?? lines[0] ?? "").trim().replace(/^- /, "");
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export async function checkConfig(
|
|
17
|
-
cwd: string,
|
|
18
|
-
configPath?: string,
|
|
19
|
-
): Promise<Finding[]> {
|
|
20
|
-
const out: Finding[] = [];
|
|
21
|
-
|
|
22
|
-
try {
|
|
23
|
-
await loadConfig({ cwd, configPath });
|
|
24
|
-
out.push({
|
|
25
|
-
id: "config",
|
|
26
|
-
group: "Config",
|
|
27
|
-
status: "pass",
|
|
28
|
-
detail: "sordo.config.ts valid",
|
|
29
|
-
});
|
|
30
|
-
} catch (err) {
|
|
31
|
-
const message = err instanceof Error ? err.message : String(err);
|
|
32
|
-
out.push({
|
|
33
|
-
id: "config",
|
|
34
|
-
group: "Config",
|
|
35
|
-
status: "fail",
|
|
36
|
-
detail: `sordo.config.ts invalid — ${firstIssue(message)}`,
|
|
37
|
-
remedy: "fix sordo.config.ts and re-run",
|
|
38
|
-
});
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
const biomePath = join(cwd, "biome.json");
|
|
42
|
-
if (await Bun.file(biomePath).exists()) {
|
|
43
|
-
try {
|
|
44
|
-
JSON.parse(await Bun.file(biomePath).text());
|
|
45
|
-
out.push({
|
|
46
|
-
id: "biome",
|
|
47
|
-
group: "Config",
|
|
48
|
-
status: "pass",
|
|
49
|
-
detail: "biome.json valid",
|
|
50
|
-
});
|
|
51
|
-
} catch {
|
|
52
|
-
out.push({
|
|
53
|
-
id: "biome",
|
|
54
|
-
group: "Config",
|
|
55
|
-
status: "fail",
|
|
56
|
-
detail: "biome.json is not valid JSON",
|
|
57
|
-
remedy: "fix the JSON syntax in biome.json",
|
|
58
|
-
});
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
return out;
|
|
63
|
-
}
|