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/ai/triggers.ts
DELETED
|
@@ -1,124 +0,0 @@
|
|
|
1
|
-
import type { BunRoutes, HTTPMethod, RouteEntry } from "../types.ts";
|
|
2
|
-
import { createAiContext } from "./context.ts";
|
|
3
|
-
import { listAgents } from "./registry.ts";
|
|
4
|
-
import type { AiContext } from "./types.ts";
|
|
5
|
-
|
|
6
|
-
// Wire opt-in agent triggers ("POST /api/booking/chat") into the Bun routes
|
|
7
|
-
// table. Filesystem routes always win; conflicts are logged.
|
|
8
|
-
export function registerAgentTriggers(
|
|
9
|
-
routes: BunRoutes,
|
|
10
|
-
entries: RouteEntry[],
|
|
11
|
-
): void {
|
|
12
|
-
const conflicts = new Set<string>();
|
|
13
|
-
for (const e of entries) {
|
|
14
|
-
const mod = (e as RouteEntry & { __mod?: Record<string, unknown> }).__mod;
|
|
15
|
-
if (e.kind === "api" && mod) {
|
|
16
|
-
for (const m of [
|
|
17
|
-
"GET",
|
|
18
|
-
"POST",
|
|
19
|
-
"PUT",
|
|
20
|
-
"DELETE",
|
|
21
|
-
"PATCH",
|
|
22
|
-
"OPTIONS",
|
|
23
|
-
"HEAD",
|
|
24
|
-
] as HTTPMethod[]) {
|
|
25
|
-
if (typeof mod[m] === "function") conflicts.add(`${m} ${e.bunPattern}`);
|
|
26
|
-
}
|
|
27
|
-
} else if (e.kind === "page") {
|
|
28
|
-
conflicts.add(`GET ${e.bunPattern}`);
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
// Without __mod we approximate: any route entry claims at least GET (pages)
|
|
33
|
-
// or all-exported methods (api). Build emits __mod-less entries so be
|
|
34
|
-
// conservative — treat *every* route file as claiming any method on its
|
|
35
|
-
// pattern. This errs toward the spec rule: "filesystem route always wins".
|
|
36
|
-
const conservativeConflicts = new Set<string>();
|
|
37
|
-
for (const e of entries) conservativeConflicts.add(e.bunPattern);
|
|
38
|
-
|
|
39
|
-
for (const a of listAgents()) {
|
|
40
|
-
for (const trig of a.config.triggers ?? []) {
|
|
41
|
-
const parsed = parseTrigger(trig);
|
|
42
|
-
if (!parsed) {
|
|
43
|
-
console.warn(
|
|
44
|
-
`[sordo] agent "${a.config.name}": invalid trigger "${trig}" (expected "METHOD /path").`,
|
|
45
|
-
);
|
|
46
|
-
continue;
|
|
47
|
-
}
|
|
48
|
-
const { method, path } = parsed;
|
|
49
|
-
const key = `${method} ${path}`;
|
|
50
|
-
if (conflicts.has(key) || conservativeConflicts.has(path)) {
|
|
51
|
-
console.warn(
|
|
52
|
-
`[sordo] trigger conflict: agent "${a.config.name}" trigger "${trig}" overlaps a filesystem route. ` +
|
|
53
|
-
`The filesystem route wins; trigger handler not registered.`,
|
|
54
|
-
);
|
|
55
|
-
continue;
|
|
56
|
-
}
|
|
57
|
-
const handler = makeTriggerHandler(a.config.name);
|
|
58
|
-
attachTrigger(routes, path, method, handler);
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
function parseTrigger(t: string): { method: HTTPMethod; path: string } | null {
|
|
64
|
-
const m = t.match(/^(GET|POST|PUT|DELETE|PATCH)\s+(\/[^\s]*)$/);
|
|
65
|
-
if (!m?.[1] || !m[2]) return null;
|
|
66
|
-
return { method: m[1] as HTTPMethod, path: m[2] };
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
function makeTriggerHandler(agentName: string) {
|
|
70
|
-
return async (
|
|
71
|
-
req: Request & { params?: Record<string, string> },
|
|
72
|
-
): Promise<Response> => {
|
|
73
|
-
const { getAgent } = await import("./registry.ts");
|
|
74
|
-
const agent = getAgent(agentName);
|
|
75
|
-
const body = (await req.json().catch(() => ({}))) as Record<
|
|
76
|
-
string,
|
|
77
|
-
unknown
|
|
78
|
-
>;
|
|
79
|
-
const message = typeof body.message === "string" ? body.message : "";
|
|
80
|
-
const ctx: AiContext = createAiContext({ signal: req.signal });
|
|
81
|
-
try {
|
|
82
|
-
const result = await agent.run({ message, ...body }, ctx);
|
|
83
|
-
return new Response(result.stream, {
|
|
84
|
-
headers: { "Content-Type": "text/event-stream" },
|
|
85
|
-
});
|
|
86
|
-
} catch (err) {
|
|
87
|
-
const e = err as { name?: string; issues?: unknown; message?: string };
|
|
88
|
-
if (e.name === "ToolInputInvalid") {
|
|
89
|
-
return new Response(
|
|
90
|
-
JSON.stringify({ error: "ToolInputInvalid", issues: e.issues }),
|
|
91
|
-
{
|
|
92
|
-
status: 400,
|
|
93
|
-
headers: { "Content-Type": "application/json" },
|
|
94
|
-
},
|
|
95
|
-
);
|
|
96
|
-
}
|
|
97
|
-
throw err;
|
|
98
|
-
}
|
|
99
|
-
};
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
function attachTrigger(
|
|
103
|
-
routes: BunRoutes,
|
|
104
|
-
pattern: string,
|
|
105
|
-
method: HTTPMethod,
|
|
106
|
-
handler: (
|
|
107
|
-
req: Request & { params?: Record<string, string> },
|
|
108
|
-
) => Promise<Response>,
|
|
109
|
-
): void {
|
|
110
|
-
const existing = routes[pattern];
|
|
111
|
-
const wrapped = { [method]: handler } as Record<string, typeof handler>;
|
|
112
|
-
if (
|
|
113
|
-
existing &&
|
|
114
|
-
typeof existing === "object" &&
|
|
115
|
-
!(existing instanceof Response)
|
|
116
|
-
) {
|
|
117
|
-
routes[pattern] = {
|
|
118
|
-
...(existing as object),
|
|
119
|
-
...wrapped,
|
|
120
|
-
} as (typeof routes)[string];
|
|
121
|
-
} else {
|
|
122
|
-
routes[pattern] = wrapped as (typeof routes)[string];
|
|
123
|
-
}
|
|
124
|
-
}
|
package/src/ai/types.ts
DELETED
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
import type { z } from "zod";
|
|
2
|
-
|
|
3
|
-
export interface AiContext {
|
|
4
|
-
requestId: string;
|
|
5
|
-
user?: unknown;
|
|
6
|
-
anthropic: AnthropicLike;
|
|
7
|
-
signal?: AbortSignal;
|
|
8
|
-
vars: Record<string, unknown>;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
// Minimal structural type — avoids hard-importing @anthropic-ai/sdk at module
|
|
12
|
-
// load time. The real SDK is a peer dep populated by users that need agents.
|
|
13
|
-
export interface AnthropicLike {
|
|
14
|
-
messages: {
|
|
15
|
-
stream: (opts: unknown) => unknown;
|
|
16
|
-
create: (opts: unknown) => Promise<unknown>;
|
|
17
|
-
};
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export type AgentTrigger =
|
|
21
|
-
`${"GET" | "POST" | "PUT" | "DELETE" | "PATCH"} /${string}`;
|
|
22
|
-
|
|
23
|
-
export interface AgentConfig {
|
|
24
|
-
name: string;
|
|
25
|
-
model: string;
|
|
26
|
-
tools?: string[];
|
|
27
|
-
systemPrompt?: string;
|
|
28
|
-
triggers?: AgentTrigger[];
|
|
29
|
-
maxTokens?: number;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
export interface ToolConfig<TInput = unknown, TOutput = unknown> {
|
|
33
|
-
name: string;
|
|
34
|
-
description: string;
|
|
35
|
-
input: z.ZodType<TInput>;
|
|
36
|
-
handler: (input: TInput, ctx: AiContext) => Promise<TOutput> | TOutput;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
export interface JobConfig {
|
|
40
|
-
name: string;
|
|
41
|
-
schedule: string;
|
|
42
|
-
tz: string;
|
|
43
|
-
handler: (ctx: AiContext) => Promise<void> | void;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
export interface AgentRunResult {
|
|
47
|
-
stream: ReadableStream<Uint8Array>;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
export interface RegisteredAgent {
|
|
51
|
-
config: AgentConfig;
|
|
52
|
-
filePath?: string;
|
|
53
|
-
run: (
|
|
54
|
-
input: { message: string } & Record<string, unknown>,
|
|
55
|
-
ctx: AiContext,
|
|
56
|
-
) => Promise<AgentRunResult>;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
export interface RegisteredTool {
|
|
60
|
-
config: ToolConfig;
|
|
61
|
-
filePath?: string;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
export interface RegisteredJob {
|
|
65
|
-
config: JobConfig;
|
|
66
|
-
filePath?: string;
|
|
67
|
-
}
|
package/src/ai/validate.ts
DELETED
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
import type { AgentConfig, JobConfig, ToolConfig } from "./types.ts";
|
|
2
|
-
|
|
3
|
-
export interface NamedModule<T> {
|
|
4
|
-
expectedName: string;
|
|
5
|
-
filePath: string;
|
|
6
|
-
config: T;
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
// Verifies filename basename === config.name, and collects duplicates. Throws
|
|
10
|
-
// one combined error listing every problem so devs see them all at once.
|
|
11
|
-
export function validateNamedModules(
|
|
12
|
-
kind: "agent" | "tool" | "job",
|
|
13
|
-
mods: NamedModule<{ name: string }>[],
|
|
14
|
-
): void {
|
|
15
|
-
const problems: string[] = [];
|
|
16
|
-
const byName = new Map<string, NamedModule<{ name: string }>>();
|
|
17
|
-
|
|
18
|
-
for (const m of mods) {
|
|
19
|
-
if (m.config.name !== m.expectedName) {
|
|
20
|
-
problems.push(
|
|
21
|
-
`${m.filePath}: ${kind} name "${m.config.name}" does not match filename basename "${m.expectedName}".`,
|
|
22
|
-
);
|
|
23
|
-
continue;
|
|
24
|
-
}
|
|
25
|
-
const prior = byName.get(m.config.name);
|
|
26
|
-
if (prior) {
|
|
27
|
-
problems.push(
|
|
28
|
-
`Duplicate ${kind} name "${m.config.name}" in ${prior.filePath} and ${m.filePath}.`,
|
|
29
|
-
);
|
|
30
|
-
continue;
|
|
31
|
-
}
|
|
32
|
-
byName.set(m.config.name, m);
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
if (problems.length > 0) {
|
|
36
|
-
throw new Error(
|
|
37
|
-
`sordo: ${kind} validation failed\n ${problems.join("\n ")}`,
|
|
38
|
-
);
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
export function validateAgentToolReferences(
|
|
43
|
-
agents: NamedModule<AgentConfig>[],
|
|
44
|
-
tools: NamedModule<ToolConfig>[],
|
|
45
|
-
): void {
|
|
46
|
-
const toolNames = new Set(tools.map((t) => t.config.name));
|
|
47
|
-
const problems: string[] = [];
|
|
48
|
-
for (const a of agents) {
|
|
49
|
-
for (const tname of a.config.tools ?? []) {
|
|
50
|
-
if (!toolNames.has(tname)) {
|
|
51
|
-
problems.push(
|
|
52
|
-
`${a.filePath}: agent "${a.config.name}" references unknown tool "${tname}".`,
|
|
53
|
-
);
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
if (problems.length > 0) {
|
|
58
|
-
throw new Error(
|
|
59
|
-
"sordo: agent tool reference validation failed\n " +
|
|
60
|
-
problems.join("\n "),
|
|
61
|
-
);
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
export function validateJobs(jobs: NamedModule<JobConfig>[]): void {
|
|
66
|
-
const problems: string[] = [];
|
|
67
|
-
for (const j of jobs) {
|
|
68
|
-
if (!j.config.schedule || typeof j.config.schedule !== "string") {
|
|
69
|
-
problems.push(
|
|
70
|
-
`${j.filePath}: job "${j.config.name}" missing "schedule".`,
|
|
71
|
-
);
|
|
72
|
-
}
|
|
73
|
-
if (!j.config.tz || typeof j.config.tz !== "string") {
|
|
74
|
-
problems.push(
|
|
75
|
-
`${j.filePath}: job "${j.config.name}" missing required "tz" (explicit timezone required — no implicit process TZ).`,
|
|
76
|
-
);
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
if (problems.length > 0) {
|
|
80
|
-
throw new Error(`sordo: job validation failed\n ${problems.join("\n ")}`);
|
|
81
|
-
}
|
|
82
|
-
}
|
package/src/build/assets.ts
DELETED
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import { xxh64 } from "./hash.ts";
|
|
2
|
-
|
|
3
|
-
export interface BuiltAsset {
|
|
4
|
-
src: string; // absolute source path
|
|
5
|
-
dest: string; // absolute destination path
|
|
6
|
-
publicPath: string; // URL path under /_sordo/assets/
|
|
7
|
-
hash: string;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
export interface CopyAssetsOptions {
|
|
11
|
-
/** When false, enumerate + hash assets but do not write them to outDir.
|
|
12
|
-
* Compile mode embeds assets into the binary, so the disk copy is skipped. */
|
|
13
|
-
write?: boolean;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export async function copyAssets(
|
|
17
|
-
appDir: string,
|
|
18
|
-
outDir: string,
|
|
19
|
-
options: CopyAssetsOptions = {},
|
|
20
|
-
): Promise<BuiltAsset[]> {
|
|
21
|
-
const write = options.write ?? true;
|
|
22
|
-
const publicDir = `${appDir.replace(/\/+$/, "")}/public`;
|
|
23
|
-
const destDir = `${outDir.replace(/\/+$/, "")}/assets`;
|
|
24
|
-
const glob = new Bun.Glob("**/*");
|
|
25
|
-
const out: BuiltAsset[] = [];
|
|
26
|
-
|
|
27
|
-
try {
|
|
28
|
-
for await (const rel of glob.scan({ cwd: publicDir, onlyFiles: true })) {
|
|
29
|
-
const src = `${publicDir}/${rel}`;
|
|
30
|
-
const bytes = await Bun.file(src).bytes();
|
|
31
|
-
const hash = xxh64(bytes);
|
|
32
|
-
const dest = `${destDir}/${rel}`;
|
|
33
|
-
if (write) await Bun.write(dest, bytes);
|
|
34
|
-
out.push({
|
|
35
|
-
src,
|
|
36
|
-
dest,
|
|
37
|
-
publicPath: `/_sordo/assets/${rel}`,
|
|
38
|
-
hash,
|
|
39
|
-
});
|
|
40
|
-
}
|
|
41
|
-
} catch (err) {
|
|
42
|
-
const msg = (err as Error)?.message ?? "";
|
|
43
|
-
if (/ENOENT|no such file/i.test(msg)) return [];
|
|
44
|
-
throw err;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
return out;
|
|
48
|
-
}
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import type { IslandEntry } from "./scan-islands.ts";
|
|
2
|
-
|
|
3
|
-
export interface ClientEntryOptions {
|
|
4
|
-
// Absolute path to the framework's `src/` root. Used to import `client/index.ts`
|
|
5
|
-
// via an absolute path so the generated entry resolves correctly from genDir,
|
|
6
|
-
// independent of where the fixture/app sits in the node_modules tree.
|
|
7
|
-
frameworkRoot: string;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
export function generateClientEntry(
|
|
11
|
-
islands: IslandEntry[],
|
|
12
|
-
options: ClientEntryOptions,
|
|
13
|
-
): string {
|
|
14
|
-
if (islands.length === 0) {
|
|
15
|
-
// Empty entry — Bun.build will produce a near-empty bundle. Build()
|
|
16
|
-
// short-circuits before invoking Bun.build for the zero-island case, but
|
|
17
|
-
// the file is still generated so dev paths can reference it uniformly.
|
|
18
|
-
return `export {}\n`;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
const clientModule = `${options.frameworkRoot}/client/index.ts`;
|
|
22
|
-
|
|
23
|
-
const imports = islands
|
|
24
|
-
.map((i, idx) => `import I${idx} from ${JSON.stringify(i.filePath)}`)
|
|
25
|
-
.join("\n");
|
|
26
|
-
|
|
27
|
-
const registrations = islands
|
|
28
|
-
.map((i, idx) => `client.register(${JSON.stringify(i.name)}, I${idx})`)
|
|
29
|
-
.join("\n");
|
|
30
|
-
|
|
31
|
-
return `import { createClient } from ${JSON.stringify(clientModule)}
|
|
32
|
-
${imports}
|
|
33
|
-
|
|
34
|
-
const client = createClient()
|
|
35
|
-
${registrations}
|
|
36
|
-
|
|
37
|
-
if (document.readyState === "loading") {
|
|
38
|
-
document.addEventListener("DOMContentLoaded", () => client.hydrateAll())
|
|
39
|
-
} else {
|
|
40
|
-
client.hydrateAll()
|
|
41
|
-
}
|
|
42
|
-
`;
|
|
43
|
-
}
|
package/src/build/css.ts
DELETED
|
@@ -1,102 +0,0 @@
|
|
|
1
|
-
import type { BunPlugin } from "bun";
|
|
2
|
-
import type { CssConfig } from "../config/schema.ts";
|
|
3
|
-
|
|
4
|
-
export type CssOption = CssConfig;
|
|
5
|
-
|
|
6
|
-
export interface CssBuildOutput {
|
|
7
|
-
// Public URL of the hashed stylesheet; what the renderer links.
|
|
8
|
-
href: string;
|
|
9
|
-
// Every file the CSS build emitted (the sheet plus any url() assets too
|
|
10
|
-
// large to inline), as public URL → absolute path on disk.
|
|
11
|
-
files: Array<{ url: string; path: string }>;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export interface CssBuildInput {
|
|
15
|
-
css: CssOption;
|
|
16
|
-
appDir: string;
|
|
17
|
-
clientOutDir: string;
|
|
18
|
-
publicPrefix: string;
|
|
19
|
-
mode: "development" | "production";
|
|
20
|
-
loadTailwind?: (fromDir: string) => Promise<BunPlugin>;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
const TAILWIND_RE = /@import\s+(?:url\(\s*)?["']tailwindcss["']|@tailwind\s/;
|
|
24
|
-
|
|
25
|
-
const TAILWIND_MISSING =
|
|
26
|
-
'sordo build: the css entry imports Tailwind but "bun-plugin-tailwind" is not installed. Run `bun add -D bun-plugin-tailwind`, or set `css: { entry, tailwind: false }` to build it as plain CSS.';
|
|
27
|
-
|
|
28
|
-
export function usesTailwind(source: string): boolean {
|
|
29
|
-
return TAILWIND_RE.test(source);
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
// Resolved from the app (not the framework) so a linked or hoisted sordo
|
|
33
|
-
// still finds the plugin the user installed next to their project.
|
|
34
|
-
export async function loadTailwindPlugin(
|
|
35
|
-
fromDir: string,
|
|
36
|
-
deps: {
|
|
37
|
-
resolve?: (id: string, from: string) => string;
|
|
38
|
-
importModule?: (path: string) => Promise<unknown>;
|
|
39
|
-
} = {},
|
|
40
|
-
): Promise<BunPlugin> {
|
|
41
|
-
const resolve = deps.resolve ?? Bun.resolveSync;
|
|
42
|
-
const importModule = deps.importModule ?? ((p: string) => import(p));
|
|
43
|
-
let path: string;
|
|
44
|
-
try {
|
|
45
|
-
path = resolve("bun-plugin-tailwind", fromDir);
|
|
46
|
-
} catch {
|
|
47
|
-
throw new Error(TAILWIND_MISSING);
|
|
48
|
-
}
|
|
49
|
-
const mod = (await importModule(path)) as { default?: unknown };
|
|
50
|
-
const plugin = (mod.default ?? mod) as Partial<BunPlugin>;
|
|
51
|
-
if (typeof plugin?.setup !== "function") {
|
|
52
|
-
throw new Error(
|
|
53
|
-
`sordo build: "bun-plugin-tailwind" at ${path} does not export a Bun plugin`,
|
|
54
|
-
);
|
|
55
|
-
}
|
|
56
|
-
return plugin as BunPlugin;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
export async function buildCss(input: CssBuildInput): Promise<CssBuildOutput> {
|
|
60
|
-
const opt =
|
|
61
|
-
typeof input.css === "string" ? { entry: input.css } : { ...input.css };
|
|
62
|
-
const entry = opt.entry;
|
|
63
|
-
const file = Bun.file(entry);
|
|
64
|
-
if (!(await file.exists())) {
|
|
65
|
-
throw new Error(`sordo build: css entry not found: ${entry}`);
|
|
66
|
-
}
|
|
67
|
-
const tailwind = opt.tailwind ?? usesTailwind(await file.text());
|
|
68
|
-
const plugins: BunPlugin[] = tailwind
|
|
69
|
-
? [await (input.loadTailwind ?? loadTailwindPlugin)(input.appDir)]
|
|
70
|
-
: [];
|
|
71
|
-
|
|
72
|
-
const result = await Bun.build({
|
|
73
|
-
entrypoints: [entry],
|
|
74
|
-
outdir: input.clientOutDir,
|
|
75
|
-
naming: "[name]-[hash].[ext]",
|
|
76
|
-
minify: input.mode === "production",
|
|
77
|
-
plugins,
|
|
78
|
-
});
|
|
79
|
-
if (!result.success) {
|
|
80
|
-
const msgs = result.logs.map((l) => l.message ?? String(l)).join("\n");
|
|
81
|
-
throw new Error(`sordo build: css build failed\n${msgs}`);
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
const files = result.outputs.map((o) => ({
|
|
85
|
-
url: input.publicPrefix + relativeTo(o.path, input.clientOutDir),
|
|
86
|
-
path: o.path,
|
|
87
|
-
}));
|
|
88
|
-
const sheet = files.find((f) => f.path.endsWith(".css"));
|
|
89
|
-
if (!sheet) {
|
|
90
|
-
throw new Error(
|
|
91
|
-
`sordo build: css build emitted no stylesheet for ${entry}`,
|
|
92
|
-
);
|
|
93
|
-
}
|
|
94
|
-
return { href: sheet.url, files };
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
function relativeTo(abs: string, dir: string): string {
|
|
98
|
-
const rel = abs.startsWith(dir)
|
|
99
|
-
? abs.slice(dir.length)
|
|
100
|
-
: (abs.split("/").pop() ?? "");
|
|
101
|
-
return rel.replace(/^\/+/, "");
|
|
102
|
-
}
|
package/src/build/embedded.ts
DELETED
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
// Build-time generator for the embedded-files manifest used by single-binary
|
|
2
|
-
// (`bun build --compile`) deploys. Each entry becomes a `with { type: "file" }`
|
|
3
|
-
// import so Bun embeds the bytes into the binary; at runtime the server entry
|
|
4
|
-
// resolves them via `Bun.embeddedFiles`. Enumeration happens here, at build
|
|
5
|
-
// time — the binary never globs `app/public` (build-time-discovery rule).
|
|
6
|
-
//
|
|
7
|
-
// URL convention follows sordo' actual scheme — public assets at
|
|
8
|
-
// `/_sordo/assets/<rel>`, client chunks at `/_sordo/client/<file>` — not
|
|
9
|
-
// the spec's illustrative `/favicon.ico`.
|
|
10
|
-
|
|
11
|
-
const CLIENT_PREFIX = "/_sordo/client/";
|
|
12
|
-
|
|
13
|
-
export interface EmbeddedEntry {
|
|
14
|
-
/** Public URL the embedded file is served at. */
|
|
15
|
-
url: string;
|
|
16
|
-
/** Absolute path used as the `with { type: "file" }` import source. */
|
|
17
|
-
src: string;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* Enumerate every file in the built client output dir. All client chunks
|
|
22
|
-
* (js / css / maps) are embedded so the compiled binary serves them with no
|
|
23
|
-
* `dist/client` sidecar. Returns [] when the dir is absent (zero-island app).
|
|
24
|
-
*/
|
|
25
|
-
export async function collectClientChunks(
|
|
26
|
-
clientOutDir: string,
|
|
27
|
-
): Promise<EmbeddedEntry[]> {
|
|
28
|
-
const glob = new Bun.Glob("**/*");
|
|
29
|
-
const out: EmbeddedEntry[] = [];
|
|
30
|
-
try {
|
|
31
|
-
for await (const rel of glob.scan({ cwd: clientOutDir, onlyFiles: true })) {
|
|
32
|
-
out.push({
|
|
33
|
-
url: `${CLIENT_PREFIX}${rel}`,
|
|
34
|
-
src: `${clientOutDir}/${rel}`,
|
|
35
|
-
});
|
|
36
|
-
}
|
|
37
|
-
} catch (err) {
|
|
38
|
-
const msg = (err as Error)?.message ?? "";
|
|
39
|
-
if (/ENOENT|no such file/i.test(msg)) return [];
|
|
40
|
-
throw err;
|
|
41
|
-
}
|
|
42
|
-
return out;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
* Emit the source for `<genDir>/embedded-manifest.ts`. Each entry becomes a
|
|
47
|
-
* `with { type: "file" }` import; `EMBEDDED_ASSET_PATHS` maps the public URL to
|
|
48
|
-
* the imported value (which equals the embedded file's Bun identity / `.name`).
|
|
49
|
-
*/
|
|
50
|
-
export function generateEmbeddedManifest(entries: EmbeddedEntry[]): string {
|
|
51
|
-
const imports = entries
|
|
52
|
-
.map(
|
|
53
|
-
(e, i) =>
|
|
54
|
-
`import a${i} from ${JSON.stringify(e.src)} with { type: "file" };`,
|
|
55
|
-
)
|
|
56
|
-
.join("\n");
|
|
57
|
-
const mapEntries = entries
|
|
58
|
-
.map((e, i) => `\t${JSON.stringify(e.url)}: a${i},`)
|
|
59
|
-
.join("\n");
|
|
60
|
-
return `${imports}
|
|
61
|
-
|
|
62
|
-
export const EMBEDDED_ASSET_PATHS: Record<string, string> = {
|
|
63
|
-
${mapEntries}
|
|
64
|
-
};
|
|
65
|
-
`;
|
|
66
|
-
}
|
package/src/build/hash.ts
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
// Spec calls for xxh64 — non-cryptographic, fast, stable. Bun's CryptoHasher
|
|
2
|
-
// does not expose xxh64 on every release; fall back to a truncated sha1 (also
|
|
3
|
-
// fast and stable) when xxh64 is unavailable. For SRI-grade hashes, the caller
|
|
4
|
-
// uses sha256 directly.
|
|
5
|
-
const ALGO = pickAlgo();
|
|
6
|
-
|
|
7
|
-
export function xxh64(bytes: Uint8Array | string): string {
|
|
8
|
-
return new Bun.CryptoHasher(ALGO as never)
|
|
9
|
-
.update(bytes)
|
|
10
|
-
.digest("hex")
|
|
11
|
-
.slice(0, 16);
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
function pickAlgo(): string {
|
|
15
|
-
try {
|
|
16
|
-
new Bun.CryptoHasher("xxh64" as never);
|
|
17
|
-
return "xxh64";
|
|
18
|
-
} catch {
|
|
19
|
-
return "sha1";
|
|
20
|
-
}
|
|
21
|
-
}
|