sordo 0.5.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 -126
- package/README.md +8 -178
- 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 -151
- 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 -128
- package/src/build/embedded.ts +0 -66
- package/src/build/hash.ts +0 -21
- package/src/build/index.ts +0 -505
- 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 -34
- 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 -135
- 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 -269
- package/src/router/match.ts +0 -91
- package/src/router/pattern.ts +0 -104
- package/src/server/index.ts +0 -250
- package/src/server/inline-assets.ts +0 -57
- 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
|
@@ -1,116 +0,0 @@
|
|
|
1
|
-
import { join } from "node:path";
|
|
2
|
-
import type { ComponentEntry } from "../../../ui/types.ts";
|
|
3
|
-
import { formatUnifiedDiff } from "./diff.ts";
|
|
4
|
-
import { INTERNAL_FILES } from "./internal.ts";
|
|
5
|
-
import type { Catalog } from "./load-catalog.ts";
|
|
6
|
-
import { extractBlock } from "./tokens.ts";
|
|
7
|
-
import { fileDest, type UiPaths } from "./ui-paths.ts";
|
|
8
|
-
|
|
9
|
-
export type DiffStatus = "not-stamped" | "up-to-date" | "drift";
|
|
10
|
-
|
|
11
|
-
export interface DiffItem {
|
|
12
|
-
label: string;
|
|
13
|
-
status: DiffStatus;
|
|
14
|
-
body: string; // unified diff, empty unless status === "drift"
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
async function diffPair(
|
|
18
|
-
label: string,
|
|
19
|
-
localPath: string,
|
|
20
|
-
templatePath: string,
|
|
21
|
-
color: boolean,
|
|
22
|
-
): Promise<DiffItem> {
|
|
23
|
-
if (!(await Bun.file(localPath).exists())) {
|
|
24
|
-
return { label, status: "not-stamped", body: "" };
|
|
25
|
-
}
|
|
26
|
-
const local = await Bun.file(localPath).text();
|
|
27
|
-
const incoming = await Bun.file(templatePath).text();
|
|
28
|
-
if (local === incoming) return { label, status: "up-to-date", body: "" };
|
|
29
|
-
const body = formatUnifiedDiff(local, incoming, {
|
|
30
|
-
fromLabel: `${label} (local)`,
|
|
31
|
-
toLabel: `${label} (catalog)`,
|
|
32
|
-
color,
|
|
33
|
-
});
|
|
34
|
-
return { label, status: "drift", body };
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
// Diff a component's files, helpers, and token block against the catalog.
|
|
38
|
-
export async function diffComponentItems(
|
|
39
|
-
entry: ComponentEntry,
|
|
40
|
-
uiPaths: UiPaths,
|
|
41
|
-
templatesDir: string,
|
|
42
|
-
color: boolean,
|
|
43
|
-
): Promise<DiffItem[]> {
|
|
44
|
-
const items: DiffItem[] = [];
|
|
45
|
-
|
|
46
|
-
for (const f of entry.files) {
|
|
47
|
-
items.push(
|
|
48
|
-
await diffPair(
|
|
49
|
-
f.to,
|
|
50
|
-
fileDest(uiPaths, f),
|
|
51
|
-
join(templatesDir, f.from),
|
|
52
|
-
color,
|
|
53
|
-
),
|
|
54
|
-
);
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
for (const h of entry.internalHelpers) {
|
|
58
|
-
const file = INTERNAL_FILES[h];
|
|
59
|
-
items.push(
|
|
60
|
-
await diffPair(
|
|
61
|
-
`_internal/${file}`,
|
|
62
|
-
join(uiPaths.internalDir, file),
|
|
63
|
-
join(templatesDir, "_internal", file),
|
|
64
|
-
color,
|
|
65
|
-
),
|
|
66
|
-
);
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
for (const group of entry.tokens ?? []) {
|
|
70
|
-
items.push(await diffTokenGroup(group, uiPaths, templatesDir, color));
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
return items;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
async function diffTokenGroup(
|
|
77
|
-
group: string,
|
|
78
|
-
uiPaths: UiPaths,
|
|
79
|
-
templatesDir: string,
|
|
80
|
-
color: boolean,
|
|
81
|
-
): Promise<DiffItem> {
|
|
82
|
-
const label = `tokens:${group}`;
|
|
83
|
-
const incoming = extractBlock(
|
|
84
|
-
await Bun.file(join(templatesDir, "tokens.css")).text(),
|
|
85
|
-
group,
|
|
86
|
-
);
|
|
87
|
-
if (incoming === null) return { label, status: "up-to-date", body: "" };
|
|
88
|
-
if (!(await Bun.file(uiPaths.tokensFile).exists())) {
|
|
89
|
-
return { label, status: "not-stamped", body: "" };
|
|
90
|
-
}
|
|
91
|
-
const local = extractBlock(await Bun.file(uiPaths.tokensFile).text(), group);
|
|
92
|
-
if (local === null) return { label, status: "not-stamped", body: "" };
|
|
93
|
-
if (local === incoming) return { label, status: "up-to-date", body: "" };
|
|
94
|
-
const body = formatUnifiedDiff(local, incoming, {
|
|
95
|
-
fromLabel: `${label} (local)`,
|
|
96
|
-
toLabel: `${label} (catalog)`,
|
|
97
|
-
color,
|
|
98
|
-
});
|
|
99
|
-
return { label, status: "drift", body };
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
// Components whose first file is already present under componentsDir.
|
|
103
|
-
export async function listStampedComponents(
|
|
104
|
-
catalog: Catalog,
|
|
105
|
-
uiPaths: UiPaths,
|
|
106
|
-
): Promise<ComponentEntry[]> {
|
|
107
|
-
const out: ComponentEntry[] = [];
|
|
108
|
-
for (const c of catalog.components) {
|
|
109
|
-
const first = c.files[0];
|
|
110
|
-
if (!first) continue;
|
|
111
|
-
if (await Bun.file(fileDest(uiPaths, first)).exists()) {
|
|
112
|
-
out.push(c);
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
return out;
|
|
116
|
-
}
|
|
@@ -1,153 +0,0 @@
|
|
|
1
|
-
// Minimal line-level unified diff. Bun-native (no diff dependency); inputs are
|
|
2
|
-
// single component files, so an O(N×M) LCS is more than adequate.
|
|
3
|
-
|
|
4
|
-
export type DiffOpType = "eq" | "del" | "add";
|
|
5
|
-
export interface DiffOp {
|
|
6
|
-
type: DiffOpType;
|
|
7
|
-
line: string;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
export interface DiffHunk {
|
|
11
|
-
oldStart: number;
|
|
12
|
-
oldLines: number;
|
|
13
|
-
newStart: number;
|
|
14
|
-
newLines: number;
|
|
15
|
-
ops: DiffOp[];
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
const RED = "\x1b[31m";
|
|
19
|
-
const GREEN = "\x1b[32m";
|
|
20
|
-
const CYAN = "\x1b[36m";
|
|
21
|
-
const RESET = "\x1b[0m";
|
|
22
|
-
|
|
23
|
-
function splitLines(s: string): string[] {
|
|
24
|
-
return s === "" ? [] : s.split("\n");
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
// LCS-based line diff. Returns an ordered op list (eq/del/add).
|
|
28
|
-
export function diffLines(current: string, incoming: string): DiffOp[] {
|
|
29
|
-
const a = splitLines(current);
|
|
30
|
-
const b = splitLines(incoming);
|
|
31
|
-
const n = a.length;
|
|
32
|
-
const m = b.length;
|
|
33
|
-
const w = m + 1;
|
|
34
|
-
// dp[i*w + j] = LCS length of a[i:] vs b[j:]
|
|
35
|
-
const dp = new Int32Array((n + 1) * w);
|
|
36
|
-
const at = (idx: number): number => dp[idx] ?? 0;
|
|
37
|
-
for (let i = n - 1; i >= 0; i--) {
|
|
38
|
-
const ai = a[i] ?? "";
|
|
39
|
-
for (let j = m - 1; j >= 0; j--) {
|
|
40
|
-
dp[i * w + j] =
|
|
41
|
-
ai === (b[j] ?? "")
|
|
42
|
-
? at((i + 1) * w + (j + 1)) + 1
|
|
43
|
-
: Math.max(at((i + 1) * w + j), at(i * w + (j + 1)));
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
const ops: DiffOp[] = [];
|
|
48
|
-
let i = 0;
|
|
49
|
-
let j = 0;
|
|
50
|
-
while (i < n && j < m) {
|
|
51
|
-
if ((a[i] ?? "") === (b[j] ?? "")) {
|
|
52
|
-
ops.push({ type: "eq", line: a[i] ?? "" });
|
|
53
|
-
i++;
|
|
54
|
-
j++;
|
|
55
|
-
} else if (at((i + 1) * w + j) >= at(i * w + (j + 1))) {
|
|
56
|
-
ops.push({ type: "del", line: a[i] ?? "" });
|
|
57
|
-
i++;
|
|
58
|
-
} else {
|
|
59
|
-
ops.push({ type: "add", line: b[j] ?? "" });
|
|
60
|
-
j++;
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
while (i < n) ops.push({ type: "del", line: a[i++] ?? "" });
|
|
64
|
-
while (j < m) ops.push({ type: "add", line: b[j++] ?? "" });
|
|
65
|
-
return ops;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
interface Annotated {
|
|
69
|
-
op: DiffOp;
|
|
70
|
-
oldNo: number;
|
|
71
|
-
newNo: number;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
// Group ops into unified-diff hunks with `context` lines of surrounding eq.
|
|
75
|
-
export function toHunks(ops: DiffOp[], context = 3): DiffHunk[] {
|
|
76
|
-
let o = 1;
|
|
77
|
-
let nw = 1;
|
|
78
|
-
const ann: Annotated[] = ops.map((op) => {
|
|
79
|
-
const e: Annotated = {
|
|
80
|
-
op,
|
|
81
|
-
oldNo: op.type !== "add" ? o : 0,
|
|
82
|
-
newNo: op.type !== "del" ? nw : 0,
|
|
83
|
-
};
|
|
84
|
-
if (op.type !== "add") o++;
|
|
85
|
-
if (op.type !== "del") nw++;
|
|
86
|
-
return e;
|
|
87
|
-
});
|
|
88
|
-
|
|
89
|
-
const changes: number[] = [];
|
|
90
|
-
for (let k = 0; k < ann.length; k++) {
|
|
91
|
-
if (ann[k]?.op.type !== "eq") changes.push(k);
|
|
92
|
-
}
|
|
93
|
-
if (changes.length === 0) return [];
|
|
94
|
-
|
|
95
|
-
const groups: Array<[number, number]> = [];
|
|
96
|
-
let start = changes[0] ?? 0;
|
|
97
|
-
let prev = start;
|
|
98
|
-
for (const idx of changes.slice(1)) {
|
|
99
|
-
if (idx - prev <= context * 2) {
|
|
100
|
-
prev = idx;
|
|
101
|
-
} else {
|
|
102
|
-
groups.push([start, prev]);
|
|
103
|
-
start = idx;
|
|
104
|
-
prev = idx;
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
groups.push([start, prev]);
|
|
108
|
-
|
|
109
|
-
const hunks: DiffHunk[] = [];
|
|
110
|
-
for (const [gStart, gEnd] of groups) {
|
|
111
|
-
const lo = Math.max(0, gStart - context);
|
|
112
|
-
const hi = Math.min(ann.length - 1, gEnd + context);
|
|
113
|
-
const slice = ann.slice(lo, hi + 1);
|
|
114
|
-
const hunkOps = slice.map((e) => e.op);
|
|
115
|
-
const oldStart = slice.find((e) => e.oldNo > 0)?.oldNo ?? 0;
|
|
116
|
-
const newStart = slice.find((e) => e.newNo > 0)?.newNo ?? 0;
|
|
117
|
-
const oldLines = hunkOps.filter((op) => op.type !== "add").length;
|
|
118
|
-
const newLines = hunkOps.filter((op) => op.type !== "del").length;
|
|
119
|
-
hunks.push({ oldStart, oldLines, newStart, newLines, ops: hunkOps });
|
|
120
|
-
}
|
|
121
|
-
return hunks;
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
// Render a unified diff. Colorized when `color`, plain otherwise.
|
|
125
|
-
export function formatUnifiedDiff(
|
|
126
|
-
current: string,
|
|
127
|
-
incoming: string,
|
|
128
|
-
opts: { fromLabel: string; toLabel: string; color: boolean },
|
|
129
|
-
): string {
|
|
130
|
-
const hunks = toHunks(diffLines(current, incoming));
|
|
131
|
-
if (hunks.length === 0) return "";
|
|
132
|
-
|
|
133
|
-
const c = opts.color;
|
|
134
|
-
const paint = (code: string, s: string) => (c ? `${code}${s}${RESET}` : s);
|
|
135
|
-
|
|
136
|
-
const out: string[] = [];
|
|
137
|
-
out.push(paint(RED, `--- ${opts.fromLabel}`));
|
|
138
|
-
out.push(paint(GREEN, `+++ ${opts.toLabel}`));
|
|
139
|
-
for (const h of hunks) {
|
|
140
|
-
out.push(
|
|
141
|
-
paint(
|
|
142
|
-
CYAN,
|
|
143
|
-
`@@ -${h.oldStart},${h.oldLines} +${h.newStart},${h.newLines} @@`,
|
|
144
|
-
),
|
|
145
|
-
);
|
|
146
|
-
for (const op of h.ops) {
|
|
147
|
-
if (op.type === "eq") out.push(` ${op.line}`);
|
|
148
|
-
else if (op.type === "del") out.push(paint(RED, `-${op.line}`));
|
|
149
|
-
else out.push(paint(GREEN, `+${op.line}`));
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
return out.join("\n");
|
|
153
|
-
}
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import { dirname, join } from "node:path";
|
|
2
|
-
import type { InternalHelper } from "../../../ui/types.ts";
|
|
3
|
-
import { log } from "../../log.ts";
|
|
4
|
-
import type { UiPaths } from "./ui-paths.ts";
|
|
5
|
-
|
|
6
|
-
export const INTERNAL_FILES: Record<InternalHelper, string> = {
|
|
7
|
-
cn: "cn.ts",
|
|
8
|
-
slot: "slot.ts",
|
|
9
|
-
variants: "variants.ts",
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
const FILES = INTERNAL_FILES;
|
|
13
|
-
|
|
14
|
-
export async function stampInternals(
|
|
15
|
-
helpers: InternalHelper[],
|
|
16
|
-
uiPaths: UiPaths,
|
|
17
|
-
templatesDir: string,
|
|
18
|
-
opts: { dryRun: boolean; force?: boolean },
|
|
19
|
-
): Promise<{ written: string[] }> {
|
|
20
|
-
if (helpers.length === 0) return { written: [] };
|
|
21
|
-
const written: string[] = [];
|
|
22
|
-
for (const h of helpers) {
|
|
23
|
-
const from = join(templatesDir, "_internal", FILES[h]);
|
|
24
|
-
const to = join(uiPaths.internalDir, FILES[h]);
|
|
25
|
-
if ((await Bun.file(to).exists()) && !opts.force) {
|
|
26
|
-
log.dim(` helper _internal/${FILES[h]} present`);
|
|
27
|
-
continue;
|
|
28
|
-
}
|
|
29
|
-
const src = Bun.file(from);
|
|
30
|
-
if (!(await src.exists())) {
|
|
31
|
-
throw new Error(`missing internal template: ${from}`);
|
|
32
|
-
}
|
|
33
|
-
if (!opts.dryRun) {
|
|
34
|
-
await Bun.$`mkdir -p ${dirname(to)}`.quiet();
|
|
35
|
-
await Bun.write(to, src);
|
|
36
|
-
}
|
|
37
|
-
log.success(` wrote ${to}`);
|
|
38
|
-
written.push(to);
|
|
39
|
-
}
|
|
40
|
-
return { written };
|
|
41
|
-
}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { resolve } from "node:path";
|
|
2
|
-
import type { ComponentEntry } from "../../../ui/types.ts";
|
|
3
|
-
|
|
4
|
-
export interface Catalog {
|
|
5
|
-
components: ComponentEntry[];
|
|
6
|
-
templatesDir: string;
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
// Shared helpers (`_internal/`), tokens, and theme presets ship with sordo
|
|
10
|
-
// itself. There is no built-in component catalog: components come from
|
|
11
|
-
// upstream shadcn (`@shadcn/<name>`), local paths, URLs, or `ui.registries`.
|
|
12
|
-
const TEMPLATES_DIR = resolve(import.meta.dir, "../../../../templates");
|
|
13
|
-
|
|
14
|
-
let testOverride: Catalog | undefined;
|
|
15
|
-
|
|
16
|
-
export function setCatalogForTest(catalog: Catalog | undefined): void {
|
|
17
|
-
testOverride = catalog;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export async function loadCatalog(_cwd: string): Promise<Catalog> {
|
|
21
|
-
return testOverride ?? { components: [], templatesDir: TEMPLATES_DIR };
|
|
22
|
-
}
|
|
@@ -1,115 +0,0 @@
|
|
|
1
|
-
import { join } from "node:path";
|
|
2
|
-
import { log } from "../../log.ts";
|
|
3
|
-
|
|
4
|
-
interface PackageJson {
|
|
5
|
-
dependencies?: Record<string, string>;
|
|
6
|
-
[key: string]: unknown;
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export interface DepPlan {
|
|
10
|
-
added: Record<string, string>;
|
|
11
|
-
conflicted: Array<{ name: string; user: string; requested: string }>;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export async function planDeps(
|
|
15
|
-
wanted: Record<string, string>,
|
|
16
|
-
cwd: string,
|
|
17
|
-
): Promise<DepPlan> {
|
|
18
|
-
const pkg = await readPkg(cwd);
|
|
19
|
-
const existing = pkg.dependencies ?? {};
|
|
20
|
-
const added: Record<string, string> = {};
|
|
21
|
-
const conflicted: DepPlan["conflicted"] = [];
|
|
22
|
-
const exact = await bunfigWantsExact(cwd);
|
|
23
|
-
for (const [name, range] of Object.entries(wanted)) {
|
|
24
|
-
const current = existing[name];
|
|
25
|
-
if (current === undefined) {
|
|
26
|
-
added[name] = await pinRange(name, range, cwd, exact);
|
|
27
|
-
} else if (current !== range) {
|
|
28
|
-
conflicted.push({ name, user: current, requested: range });
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
return { added, conflicted };
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
// Never write a floating range when an exact version is knowable: the
|
|
35
|
-
// installed copy wins when it satisfies the component's range, else the registry range's floor if bunfig sets
|
|
36
|
-
// `install.exact`.
|
|
37
|
-
export async function pinRange(
|
|
38
|
-
name: string,
|
|
39
|
-
range: string,
|
|
40
|
-
cwd: string,
|
|
41
|
-
exact: boolean,
|
|
42
|
-
): Promise<string> {
|
|
43
|
-
const installed = Bun.file(join(cwd, "node_modules", name, "package.json"));
|
|
44
|
-
if (await installed.exists()) {
|
|
45
|
-
try {
|
|
46
|
-
const { version } = (await installed.json()) as { version?: unknown };
|
|
47
|
-
if (
|
|
48
|
-
typeof version === "string" &&
|
|
49
|
-
EXACT.test(version) &&
|
|
50
|
-
(range === "latest" || Bun.semver.satisfies(version, range))
|
|
51
|
-
) {
|
|
52
|
-
return version;
|
|
53
|
-
}
|
|
54
|
-
} catch {}
|
|
55
|
-
}
|
|
56
|
-
if (exact) {
|
|
57
|
-
const floor = range.replace(/^[\^~]/, "");
|
|
58
|
-
if (EXACT.test(floor)) return floor;
|
|
59
|
-
}
|
|
60
|
-
return range;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
const EXACT = /^\d+\.\d+\.\d+(?:-[\w.]+)?$/;
|
|
64
|
-
|
|
65
|
-
async function bunfigWantsExact(cwd: string): Promise<boolean> {
|
|
66
|
-
const file = Bun.file(join(cwd, "bunfig.toml"));
|
|
67
|
-
if (!(await file.exists())) return false;
|
|
68
|
-
try {
|
|
69
|
-
const toml = Bun.TOML.parse(await file.text()) as {
|
|
70
|
-
install?: { exact?: unknown };
|
|
71
|
-
};
|
|
72
|
-
return toml.install?.exact === true;
|
|
73
|
-
} catch {
|
|
74
|
-
return false;
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
export async function applyDeps(plan: DepPlan, cwd: string): Promise<boolean> {
|
|
79
|
-
if (Object.keys(plan.added).length === 0) {
|
|
80
|
-
for (const c of plan.conflicted) {
|
|
81
|
-
log.warn(
|
|
82
|
-
`dep ${c.name}: keeping user range ${c.user} (component wants ${c.requested})`,
|
|
83
|
-
);
|
|
84
|
-
}
|
|
85
|
-
return false;
|
|
86
|
-
}
|
|
87
|
-
const path = join(cwd, "package.json");
|
|
88
|
-
const pkg = await readPkg(cwd);
|
|
89
|
-
pkg.dependencies = { ...(pkg.dependencies ?? {}), ...plan.added };
|
|
90
|
-
pkg.dependencies = sortKeys(pkg.dependencies);
|
|
91
|
-
await Bun.write(path, `${JSON.stringify(pkg, null, "\t")}\n`);
|
|
92
|
-
for (const [name, range] of Object.entries(plan.added)) {
|
|
93
|
-
log.success(` + ${name}@${range}`);
|
|
94
|
-
}
|
|
95
|
-
for (const c of plan.conflicted) {
|
|
96
|
-
log.warn(
|
|
97
|
-
` ${c.name}: keeping user range ${c.user} (component wants ${c.requested})`,
|
|
98
|
-
);
|
|
99
|
-
}
|
|
100
|
-
return true;
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
async function readPkg(cwd: string): Promise<PackageJson> {
|
|
104
|
-
const file = Bun.file(join(cwd, "package.json"));
|
|
105
|
-
return (await file.json()) as PackageJson;
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
function sortKeys(record: Record<string, string>): Record<string, string> {
|
|
109
|
-
const out: Record<string, string> = {};
|
|
110
|
-
for (const key of Object.keys(record).sort()) {
|
|
111
|
-
const v = record[key];
|
|
112
|
-
if (v !== undefined) out[key] = v;
|
|
113
|
-
}
|
|
114
|
-
return out;
|
|
115
|
-
}
|
|
@@ -1,122 +0,0 @@
|
|
|
1
|
-
import { z } from "zod";
|
|
2
|
-
import { ComponentEntrySchema, SafeRelPath } from "../../../ui/schema.ts";
|
|
3
|
-
import type { ComponentEntry } from "../../../ui/types.ts";
|
|
4
|
-
import { INTERNAL_FILES } from "./internal.ts";
|
|
5
|
-
|
|
6
|
-
// A self-contained component payload as emitted by `sordo ui build`: the entry
|
|
7
|
-
// plus every template source it references, keyed by the same relative paths
|
|
8
|
-
// used in `files[].from` / `_internal/<helper>.ts` / `tokens.css`. One fetch per
|
|
9
|
-
// component, no directory walking (cli/15).
|
|
10
|
-
export interface ComponentPayload {
|
|
11
|
-
entry: ComponentEntry;
|
|
12
|
-
templates: Record<string, string>;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export interface FetchOptions {
|
|
16
|
-
allowInsecure: boolean;
|
|
17
|
-
// Injectable for tests; defaults to the global fetch. Lets the suite avoid
|
|
18
|
-
// mutating `globalThis.fetch` (which would race other test files).
|
|
19
|
-
fetchImpl?: typeof fetch;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
// Raised for any fetch/validation failure. Callers map this to EXIT.USAGE and
|
|
23
|
-
// write nothing — fetched source is never executed, only validated and stamped.
|
|
24
|
-
export class RegistryError extends Error {
|
|
25
|
-
constructor(message: string) {
|
|
26
|
-
super(message);
|
|
27
|
-
this.name = "RegistryError";
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
const PayloadSchema = z.object({
|
|
32
|
-
entry: ComponentEntrySchema,
|
|
33
|
-
// Keys are relative paths written under a temp dir during materialize();
|
|
34
|
-
// SafeRelPath blocks `..`/absolute/backslash/null traversal at the boundary.
|
|
35
|
-
templates: z.record(SafeRelPath, z.string()),
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
// Every relative path an entry needs present in `templates`.
|
|
39
|
-
export function requiredTemplatePaths(entry: ComponentEntry): string[] {
|
|
40
|
-
const out = entry.files.map((f) => f.from);
|
|
41
|
-
for (const h of entry.internalHelpers) {
|
|
42
|
-
out.push(`_internal/${INTERNAL_FILES[h]}`);
|
|
43
|
-
}
|
|
44
|
-
if (entry.tokens && entry.tokens.length > 0) out.push("tokens.css");
|
|
45
|
-
return out;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
export function parsePayload(raw: unknown): ComponentPayload {
|
|
49
|
-
const parsed = PayloadSchema.safeParse(raw);
|
|
50
|
-
if (!parsed.success) {
|
|
51
|
-
throw new RegistryError(
|
|
52
|
-
`registry payload failed validation: ${parsed.error.issues
|
|
53
|
-
.map((i) => `${i.path.join(".") || "<root>"}: ${i.message}`)
|
|
54
|
-
.join("; ")}`,
|
|
55
|
-
);
|
|
56
|
-
}
|
|
57
|
-
const payload = parsed.data;
|
|
58
|
-
for (const rel of requiredTemplatePaths(payload.entry)) {
|
|
59
|
-
if (typeof payload.templates[rel] !== "string") {
|
|
60
|
-
throw new RegistryError(
|
|
61
|
-
`registry payload for "${payload.entry.name}" is missing inlined source for ${rel}`,
|
|
62
|
-
);
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
return payload;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
// Join a registry base with a component name into its payload URL/path.
|
|
69
|
-
export function componentTarget(base: string, name: string): string {
|
|
70
|
-
const trimmed = base.replace(/\/+$/, "");
|
|
71
|
-
return `${trimmed}/${name}.json`;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
function assertProtocol(url: URL, opts: FetchOptions): void {
|
|
75
|
-
if (url.protocol === "https:") return;
|
|
76
|
-
if (url.protocol === "http:") {
|
|
77
|
-
if (opts.allowInsecure) return;
|
|
78
|
-
throw new RegistryError(
|
|
79
|
-
`refusing to fetch over http (${url.href}); pass --allow-insecure to override`,
|
|
80
|
-
);
|
|
81
|
-
}
|
|
82
|
-
throw new RegistryError(`unsupported registry protocol: ${url.protocol}`);
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
// Fetch and JSON-decode a registry document (sordo payload or a shadcn
|
|
86
|
-
// registry item). Protocol policy is enforced here for every remote read.
|
|
87
|
-
export async function fetchJson(
|
|
88
|
-
target: string,
|
|
89
|
-
opts: FetchOptions,
|
|
90
|
-
): Promise<unknown> {
|
|
91
|
-
const url = new URL(target);
|
|
92
|
-
assertProtocol(url, opts);
|
|
93
|
-
const doFetch = opts.fetchImpl ?? fetch;
|
|
94
|
-
let res: Response;
|
|
95
|
-
try {
|
|
96
|
-
res = await doFetch(url);
|
|
97
|
-
} catch (err) {
|
|
98
|
-
throw new RegistryError(
|
|
99
|
-
`failed to fetch ${url.href}: ${err instanceof Error ? err.message : String(err)}`,
|
|
100
|
-
);
|
|
101
|
-
}
|
|
102
|
-
if (!res.ok) {
|
|
103
|
-
throw new RegistryError(`fetch ${url.href} returned HTTP ${res.status}`);
|
|
104
|
-
}
|
|
105
|
-
try {
|
|
106
|
-
return await res.json();
|
|
107
|
-
} catch {
|
|
108
|
-
throw new RegistryError(`response from ${url.href} is not valid JSON`);
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
export async function readJsonFile(path: string): Promise<unknown> {
|
|
113
|
-
const file = Bun.file(path);
|
|
114
|
-
if (!(await file.exists())) {
|
|
115
|
-
throw new RegistryError(`registry payload not found: ${path}`);
|
|
116
|
-
}
|
|
117
|
-
try {
|
|
118
|
-
return await file.json();
|
|
119
|
-
} catch {
|
|
120
|
-
throw new RegistryError(`registry payload is not valid JSON: ${path}`);
|
|
121
|
-
}
|
|
122
|
-
}
|