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.
Files changed (152) hide show
  1. package/CHANGELOG.md +6 -126
  2. package/README.md +8 -178
  3. package/bin/sordo.ts +1 -4
  4. package/package.json +17 -41
  5. package/src/agents-md.ts +1 -0
  6. package/src/ai.ts +1 -0
  7. package/src/build.ts +1 -0
  8. package/src/client.ts +1 -0
  9. package/src/config.ts +1 -0
  10. package/src/dev.ts +1 -0
  11. package/src/index.ts +1 -55
  12. package/src/middleware.ts +1 -0
  13. package/src/plugin.ts +1 -0
  14. package/src/render.ts +1 -0
  15. package/src/router.ts +1 -0
  16. package/src/server.ts +1 -0
  17. package/CLAUDE.md +0 -124
  18. package/src/adapters/bun.ts +0 -59
  19. package/src/adapters/edge.ts +0 -75
  20. package/src/adapters/types.ts +0 -43
  21. package/src/agents-md/collect.ts +0 -113
  22. package/src/agents-md/generate.ts +0 -44
  23. package/src/agents-md/index.ts +0 -9
  24. package/src/agents-md/render.ts +0 -151
  25. package/src/agents-md/subprocess-entry.ts +0 -92
  26. package/src/agents-md/subprocess-runner.ts +0 -111
  27. package/src/agents-md/write.ts +0 -38
  28. package/src/agents-md/zod-to-json-schema.ts +0 -18
  29. package/src/ai/context.ts +0 -72
  30. package/src/ai/define.ts +0 -15
  31. package/src/ai/errors.ts +0 -51
  32. package/src/ai/index.ts +0 -36
  33. package/src/ai/middleware.ts +0 -21
  34. package/src/ai/registry.ts +0 -96
  35. package/src/ai/run.ts +0 -185
  36. package/src/ai/scan.ts +0 -42
  37. package/src/ai/stream.ts +0 -71
  38. package/src/ai/triggers.ts +0 -124
  39. package/src/ai/types.ts +0 -67
  40. package/src/ai/validate.ts +0 -82
  41. package/src/build/assets.ts +0 -48
  42. package/src/build/client-entry.ts +0 -43
  43. package/src/build/css.ts +0 -128
  44. package/src/build/embedded.ts +0 -66
  45. package/src/build/hash.ts +0 -21
  46. package/src/build/index.ts +0 -505
  47. package/src/build/macros/agents-hash.macro.ts +0 -9
  48. package/src/build/macros/agents.macro.ts +0 -21
  49. package/src/build/macros/env.macro.ts +0 -25
  50. package/src/build/macros/inline-assets.macro.ts +0 -34
  51. package/src/build/macros/manifest.macro.ts +0 -8
  52. package/src/build/macros/routes.macro.ts +0 -10
  53. package/src/build/page-entry.ts +0 -136
  54. package/src/build/scan-islands.ts +0 -39
  55. package/src/build/server-entry.ts +0 -256
  56. package/src/cli/ansi.ts +0 -41
  57. package/src/cli/build.ts +0 -195
  58. package/src/cli/commands/add/apply.ts +0 -31
  59. package/src/cli/commands/add/component-diff.ts +0 -116
  60. package/src/cli/commands/add/diff.ts +0 -153
  61. package/src/cli/commands/add/internal.ts +0 -41
  62. package/src/cli/commands/add/load-catalog.ts +0 -22
  63. package/src/cli/commands/add/peer-deps.ts +0 -115
  64. package/src/cli/commands/add/registry-fetch.ts +0 -122
  65. package/src/cli/commands/add/shadcn.ts +0 -285
  66. package/src/cli/commands/add/source.ts +0 -273
  67. package/src/cli/commands/add/stamper.ts +0 -73
  68. package/src/cli/commands/add/tokens.ts +0 -81
  69. package/src/cli/commands/add/ui-paths.ts +0 -113
  70. package/src/cli/commands/add.ts +0 -427
  71. package/src/cli/commands/deploy.ts +0 -143
  72. package/src/cli/commands/migrate.ts +0 -149
  73. package/src/cli/commands/secret.ts +0 -316
  74. package/src/cli/commands/ui/build.ts +0 -111
  75. package/src/cli/commands/ui/init.ts +0 -135
  76. package/src/cli/commands/ui/migrate/git-guard.ts +0 -19
  77. package/src/cli/commands/ui/migrate/radix.ts +0 -67
  78. package/src/cli/commands/ui/migrate/rtl.ts +0 -148
  79. package/src/cli/commands/ui/shadcn.ts +0 -82
  80. package/src/cli/commands/ui/view.ts +0 -63
  81. package/src/cli/commands/ui.ts +0 -86
  82. package/src/cli/commands/update.ts +0 -134
  83. package/src/cli/commands/upgrade.ts +0 -53
  84. package/src/cli/commands/view.ts +0 -34
  85. package/src/cli/dev.ts +0 -393
  86. package/src/cli/doctor/config-checks.ts +0 -63
  87. package/src/cli/doctor/deps.ts +0 -295
  88. package/src/cli/doctor/hydrate.ts +0 -65
  89. package/src/cli/doctor/monorepo.ts +0 -158
  90. package/src/cli/doctor/probes.ts +0 -16
  91. package/src/cli/doctor/report.ts +0 -72
  92. package/src/cli/doctor/toolchain.ts +0 -95
  93. package/src/cli/doctor/types.ts +0 -36
  94. package/src/cli/doctor.ts +0 -127
  95. package/src/cli/index.ts +0 -168
  96. package/src/cli/log.ts +0 -135
  97. package/src/cli/run/affected.ts +0 -79
  98. package/src/cli/run/cache-key.ts +0 -177
  99. package/src/cli/run/cache-store.ts +0 -0
  100. package/src/cli/run/files.ts +0 -96
  101. package/src/cli/run/git.ts +0 -13
  102. package/src/cli/run/runner.ts +0 -189
  103. package/src/cli/run/workspace.ts +0 -216
  104. package/src/cli/run.ts +0 -184
  105. package/src/cli/start.ts +0 -99
  106. package/src/cli/update-check.ts +0 -157
  107. package/src/client/index.ts +0 -65
  108. package/src/client/link.tsx +0 -61
  109. package/src/client/page.ts +0 -250
  110. package/src/config/define.ts +0 -5
  111. package/src/config/env.ts +0 -36
  112. package/src/config/load.ts +0 -152
  113. package/src/config/schema.ts +0 -135
  114. package/src/config/secrets.ts +0 -108
  115. package/src/dev/client.ts +0 -112
  116. package/src/dev/hot.ts +0 -24
  117. package/src/dev/index.ts +0 -4
  118. package/src/dev/tree.ts +0 -95
  119. package/src/dev/watcher.ts +0 -95
  120. package/src/internal/hmr-client.ts +0 -52
  121. package/src/internal/open-in-editor.ts +0 -23
  122. package/src/internal/runtime.ts +0 -30
  123. package/src/middleware/cookie-jar.ts +0 -135
  124. package/src/middleware/cookies.ts +0 -60
  125. package/src/middleware/index.ts +0 -135
  126. package/src/middleware/request-id.ts +0 -22
  127. package/src/middleware/response-helpers.ts +0 -25
  128. package/src/plugin/index.ts +0 -109
  129. package/src/render/bootstrap.ts +0 -44
  130. package/src/render/dev-error.tsx +0 -73
  131. package/src/render/index.tsx +0 -261
  132. package/src/render/island.tsx +0 -33
  133. package/src/render/meta.tsx +0 -48
  134. package/src/render/shell.tsx +0 -41
  135. package/src/router/conflict.ts +0 -20
  136. package/src/router/filesystem.ts +0 -37
  137. package/src/router/index.ts +0 -269
  138. package/src/router/match.ts +0 -91
  139. package/src/router/pattern.ts +0 -104
  140. package/src/server/index.ts +0 -250
  141. package/src/server/inline-assets.ts +0 -57
  142. package/src/types.ts +0 -53
  143. package/src/ui/schema.ts +0 -68
  144. package/src/ui/types.ts +0 -10
  145. package/templates/_internal/cn.ts +0 -6
  146. package/templates/_internal/slot.ts +0 -50
  147. package/templates/_internal/variants.ts +0 -1
  148. package/templates/themes/neutral/tokens.css +0 -46
  149. package/templates/themes/slate/tokens.css +0 -46
  150. package/templates/themes/stone/tokens.css +0 -46
  151. package/templates/themes/zinc/tokens.css +0 -46
  152. package/templates/tokens.css +0 -46
package/src/cli/run.ts DELETED
@@ -1,184 +0,0 @@
1
- // `sordo run <task>` — task runner + content-addressed output cache for
2
- // Bun-workspace monorepos (framework/27-task-runner-cache). Wraps each
3
- // (package, task) unit with the cache layer, in topological order. Bare
4
- // `sordo build` / `dev` are unchanged; `run` is the opt-in CI orchestrator.
5
-
6
- import { join } from "node:path";
7
- import pkg from "../../package.json" with { type: "json" };
8
- import { loadConfig } from "../config/load.ts";
9
- import type { TasksConfig } from "../config/schema.ts";
10
- import type { CliContext } from "./index.ts";
11
- import { EXIT, log } from "./log.ts";
12
- import { type Affected, computeAffected } from "./run/affected.ts";
13
- import { type KeyGlobals, sha256Hex } from "./run/cache-key.ts";
14
- import { CacheStore } from "./run/cache-store.ts";
15
- import { collectRepoFileHashes } from "./run/files.ts";
16
- import { runTasks } from "./run/runner.ts";
17
- import { discoverWorkspace, type Workspace } from "./run/workspace.ts";
18
-
19
- const FRAMEWORK_VERSION = (pkg as { version: string }).version;
20
-
21
- export interface RunArgs {
22
- taskName?: string;
23
- filter?: string;
24
- affected: boolean;
25
- since?: string;
26
- noCache: boolean;
27
- force: boolean;
28
- dryRun: boolean;
29
- concurrency?: number;
30
- remote: boolean;
31
- }
32
-
33
- export async function runRun(
34
- argv: string[],
35
- ctx: CliContext = { cwd: process.cwd(), verbose: false },
36
- ): Promise<number> {
37
- const args = parseArgs(argv);
38
-
39
- if (!args.taskName) {
40
- log.error("sordo run: missing <task> (e.g. `sordo run build`).");
41
- return EXIT.USAGE;
42
- }
43
- if (args.remote) {
44
- log.error(
45
- "sordo run: --remote (remote cache) is not yet implemented — it ships in Phase 2.",
46
- );
47
- return EXIT.USAGE;
48
- }
49
-
50
- let ws: Workspace;
51
- try {
52
- ws = await discoverWorkspace(ctx.cwd);
53
- } catch (err) {
54
- log.error((err as Error)?.message ?? String(err));
55
- return EXIT.ERROR;
56
- }
57
-
58
- // The root config carries the `tasks` block; treat its absence as "defaults".
59
- let tasksConfig: TasksConfig | undefined;
60
- let rootConfigPath: string | undefined;
61
- try {
62
- const loaded = await loadConfig({
63
- cwd: ctx.cwd,
64
- configPath: ctx.configPath,
65
- });
66
- tasksConfig = loaded.config.tasks;
67
- rootConfigPath = loaded.path ?? undefined;
68
- } catch {
69
- log.debug("sordo run: no root sordo.config — using task defaults.");
70
- }
71
-
72
- const selected = await select(ws, args);
73
- if (selected !== "all" && selected.size === 0) {
74
- log.info(`sordo run ${args.taskName}: nothing selected.`);
75
- return EXIT.OK;
76
- }
77
-
78
- const globals: KeyGlobals = {
79
- root: ws.root,
80
- fileHashes: await collectRepoFileHashes(ws.root),
81
- rootConfigHash: await hashFileIfExists(rootConfigPath),
82
- rootTsconfigHash: await hashFileIfExists(join(ws.root, "tsconfig.json")),
83
- bunLockHash: await hashLock(ws.root),
84
- sordoVersion: FRAMEWORK_VERSION,
85
- env: process.env,
86
- };
87
-
88
- const store = await CacheStore.open(join(ws.root, ".sordo", "cache"));
89
- try {
90
- const summary = await runTasks({
91
- ws,
92
- taskName: args.taskName,
93
- selected,
94
- globals,
95
- tasksConfig,
96
- store,
97
- flags: {
98
- force: args.force,
99
- noCache: args.noCache,
100
- dryRun: args.dryRun,
101
- },
102
- });
103
-
104
- if (!args.dryRun)
105
- log.success(
106
- `run ${args.taskName}: ${summary.hits} cached, ${summary.ran} ran`,
107
- );
108
- return summary.exitCode === 0 ? EXIT.OK : EXIT.ERROR;
109
- } finally {
110
- store.close();
111
- }
112
- }
113
-
114
- async function select(ws: Workspace, args: RunArgs): Promise<Affected> {
115
- let selected: Affected = "all";
116
- if (args.affected)
117
- selected = await computeAffected(ws, { since: args.since });
118
- if (args.filter) {
119
- const filtered = matchFilter(ws, args.filter);
120
- selected = selected === "all" ? filtered : intersect(selected, filtered);
121
- }
122
- return selected;
123
- }
124
-
125
- function matchFilter(ws: Workspace, pattern: string): Set<string> {
126
- const glob = new Bun.Glob(pattern);
127
- const out = new Set<string>();
128
- for (const pkgNode of ws.packages.values())
129
- if (
130
- pkgNode.name === pattern ||
131
- glob.match(pkgNode.name) ||
132
- glob.match(pkgNode.relDir)
133
- )
134
- out.add(pkgNode.name);
135
- return out;
136
- }
137
-
138
- function intersect(a: Set<string>, b: Set<string>): Set<string> {
139
- const out = new Set<string>();
140
- for (const x of a) if (b.has(x)) out.add(x);
141
- return out;
142
- }
143
-
144
- async function hashFileIfExists(path: string | undefined): Promise<string> {
145
- if (!path) return "";
146
- const file = Bun.file(path);
147
- return (await file.exists()) ? sha256Hex(await file.bytes()) : "";
148
- }
149
-
150
- async function hashLock(root: string): Promise<string> {
151
- for (const name of ["bun.lock", "bun.lockb"]) {
152
- const hash = await hashFileIfExists(join(root, name));
153
- if (hash !== "") return hash;
154
- }
155
- return "";
156
- }
157
-
158
- function parseArgs(argv: string[]): RunArgs {
159
- const out: RunArgs = {
160
- affected: false,
161
- noCache: false,
162
- force: false,
163
- dryRun: false,
164
- remote: false,
165
- };
166
- for (let i = 0; i < argv.length; i++) {
167
- const a = argv[i];
168
- if (a === undefined) continue;
169
- if (a === "--filter") out.filter = String(argv[++i]);
170
- else if (a.startsWith("--filter=")) out.filter = a.slice(9);
171
- else if (a === "--since") out.since = String(argv[++i]);
172
- else if (a.startsWith("--since=")) out.since = a.slice(8);
173
- else if (a === "--affected") out.affected = true;
174
- else if (a === "--no-cache") out.noCache = true;
175
- else if (a === "--force") out.force = true;
176
- else if (a === "--dry-run") out.dryRun = true;
177
- else if (a === "--remote") out.remote = true;
178
- else if (a === "--concurrency") out.concurrency = Number(argv[++i]);
179
- else if (a.startsWith("--concurrency="))
180
- out.concurrency = Number(a.slice(14));
181
- else if (!a.startsWith("-") && out.taskName === undefined) out.taskName = a;
182
- }
183
- return out;
184
- }
package/src/cli/start.ts DELETED
@@ -1,99 +0,0 @@
1
- import { resolve } from "node:path";
2
- import { loadConfig } from "../config/load.ts";
3
- import type { CliContext } from "./index.ts";
4
- import { EXIT, log } from "./log.ts";
5
-
6
- export interface StartArgs {
7
- port?: number;
8
- outDir?: string;
9
- }
10
-
11
- // Runs the production server from the last `sordo build`: the compiled binary
12
- // when the build used --compile, otherwise the bundled server entry.
13
- export async function runStart(
14
- argv: string[],
15
- ctx: CliContext = { cwd: process.cwd(), verbose: false },
16
- ): Promise<number> {
17
- let args: StartArgs;
18
- try {
19
- args = parseStartArgs(argv, ctx.cwd);
20
- } catch (err) {
21
- log.error((err as Error).message);
22
- return EXIT.USAGE;
23
- }
24
-
25
- let config: Awaited<ReturnType<typeof loadConfig>>["config"];
26
- try {
27
- ({ config } = await loadConfig({
28
- cwd: ctx.cwd,
29
- configPath: ctx.configPath,
30
- }));
31
- } catch (err) {
32
- log.error((err as Error)?.message ?? String(err));
33
- return EXIT.ERROR;
34
- }
35
-
36
- if (config.target === "edge") {
37
- log.error(
38
- "sordo start runs the bun target. An edge build (.sordo/worker.js) runs on its platform: e.g. `wrangler dev` with main = the built worker.js.",
39
- );
40
- return EXIT.USAGE;
41
- }
42
-
43
- const outDir = args.outDir ?? config.outDir;
44
- const cmd = await resolveServerCommand(outDir);
45
- if (!cmd) {
46
- log.error(
47
- `sordo start: no build found in ${outDir}. Run \`sordo build\` first.`,
48
- );
49
- return EXIT.ERROR;
50
- }
51
-
52
- const env: Record<string, string | undefined> = {
53
- ...process.env,
54
- NODE_ENV: process.env.NODE_ENV ?? "production",
55
- };
56
- if (args.port !== undefined) env.PORT = String(args.port);
57
-
58
- const proc = Bun.spawn(cmd, {
59
- cwd: ctx.cwd,
60
- env,
61
- stdio: ["inherit", "inherit", "inherit"],
62
- });
63
- const forward = (sig: NodeJS.Signals) => () => proc.kill(sig);
64
- process.on("SIGINT", forward("SIGINT"));
65
- process.on("SIGTERM", forward("SIGTERM"));
66
- return await proc.exited;
67
- }
68
-
69
- export async function resolveServerCommand(
70
- outDir: string,
71
- ): Promise<string[] | null> {
72
- const bin = `${outDir}/server-bin`;
73
- if (await Bun.file(bin).exists()) return [bin];
74
- const entry = `${outDir}/server/server-entry.js`;
75
- if (await Bun.file(entry).exists()) return [process.execPath, entry];
76
- return null;
77
- }
78
-
79
- export function parseStartArgs(argv: string[], cwd: string): StartArgs {
80
- const out: StartArgs = {};
81
- for (let i = 0; i < argv.length; i++) {
82
- const a = argv[i];
83
- if (a === undefined) continue;
84
- let port: string | undefined;
85
- if (a === "--port" || a === "-p") port = argv[++i];
86
- else if (a.startsWith("--port=")) port = a.slice(7);
87
- else if (a === "--out") out.outDir = resolve(cwd, String(argv[++i]));
88
- else if (a.startsWith("--out=")) out.outDir = resolve(cwd, a.slice(6));
89
- else throw new Error(`sordo start: unknown flag ${a}`);
90
- if (port !== undefined) {
91
- const n = Number(port);
92
- if (!Number.isInteger(n) || n < 0 || n > 65535) {
93
- throw new Error(`sordo start: invalid --port ${port}`);
94
- }
95
- out.port = n;
96
- }
97
- }
98
- return out;
99
- }
@@ -1,157 +0,0 @@
1
- import { homedir, tmpdir } from "node:os";
2
- import { join } from "node:path";
3
- import { isTTY } from "./log.ts";
4
-
5
- // Best-effort "a newer sordo is available" banner. Two hard rules:
6
- // 1. Never block the CLI on the network — the banner prints from a local
7
- // cache; a stale cache is refreshed in the background (fire-and-forget).
8
- // 2. Channel-aware — a stable install is compared against the `latest`
9
- // dist-tag, a prerelease (e.g. `0.1.0-next.3`) against its own pre tag,
10
- // so stable users are never nagged about release candidates.
11
-
12
- const DIST_TAGS_URL = "https://registry.npmjs.org/-/package/sordo/dist-tags";
13
- const TTL_MS = 24 * 60 * 60 * 1000;
14
- const FETCH_TIMEOUT_MS = 2000;
15
-
16
- interface UpdateCache {
17
- checkedAt: number;
18
- latest: string;
19
- }
20
-
21
- // Exported for unit tests.
22
- export function channelFor(version: string): string {
23
- const dash = version.indexOf("-");
24
- if (dash === -1) return "latest";
25
- const tag = version.slice(dash + 1).split(".")[0];
26
- return tag || "latest";
27
- }
28
-
29
- // Exported for unit tests. Uses Bun.semver when present (no-ops otherwise so a
30
- // non-Bun test runner never throws — mirrors assertPluginCompat).
31
- export function isNewerVersion(latest: string, current: string): boolean {
32
- const semver = (
33
- Bun as unknown as { semver?: { order(a: string, b: string): number } }
34
- ).semver;
35
- if (!semver || typeof semver.order !== "function") return false;
36
- try {
37
- return semver.order(latest, current) === 1;
38
- } catch {
39
- return false;
40
- }
41
- }
42
-
43
- function cacheFile(): string {
44
- const base =
45
- process.env.XDG_CACHE_HOME ??
46
- (homedir() ? join(homedir(), ".cache") : tmpdir());
47
- return join(base, "sordo", "update-check.json");
48
- }
49
-
50
- function optedOut(noUpdateCheck: boolean): boolean {
51
- if (noUpdateCheck) return true;
52
- if (process.env.CI) return true;
53
- if (process.env.NODE_ENV === "production") return true;
54
- if (process.env.NO_UPDATE_NOTIFIER) return true;
55
- if (process.env.SORDO_NO_UPDATE_NOTIFIER) return true;
56
- return !isTTY(process.stdout);
57
- }
58
-
59
- async function readCache(): Promise<UpdateCache | null> {
60
- try {
61
- const file = Bun.file(cacheFile());
62
- if (!(await file.exists())) return null;
63
- const data = (await file.json()) as Partial<UpdateCache>;
64
- if (typeof data.latest === "string" && typeof data.checkedAt === "number") {
65
- return { latest: data.latest, checkedAt: data.checkedAt };
66
- }
67
- } catch {
68
- // unreadable / malformed cache → treat as absent
69
- }
70
- return null;
71
- }
72
-
73
- async function fetchLatest(channel: string): Promise<string | null> {
74
- try {
75
- const res = await fetch(DIST_TAGS_URL, {
76
- signal: AbortSignal.timeout(FETCH_TIMEOUT_MS),
77
- headers: { accept: "application/json" },
78
- });
79
- if (!res.ok) return null;
80
- const tags = (await res.json()) as Record<string, string>;
81
- const v = tags[channel] ?? tags.latest;
82
- return typeof v === "string" ? v : null;
83
- } catch {
84
- return null;
85
- }
86
- }
87
-
88
- function printBanner(current: string, latest: string): void {
89
- const color = Boolean(process.stdout.isTTY) && !process.env.NO_COLOR;
90
- const paint = (code: string, s: string) =>
91
- color ? `\x1b[${code}m${s}\x1b[0m` : s;
92
-
93
- type Seg = { text: string; code?: string };
94
- const lines: Seg[][] = [
95
- [
96
- { text: "Update available " },
97
- { text: current, code: "2" },
98
- { text: " → ", code: "36" },
99
- { text: latest, code: "32" },
100
- ],
101
- [
102
- { text: "Run " },
103
- { text: "sordo upgrade", code: "36" },
104
- { text: " to update" },
105
- ],
106
- ];
107
-
108
- const visLen = (segs: Seg[]) => segs.reduce((n, s) => n + s.text.length, 0);
109
- const inner = Math.max(...lines.map(visLen));
110
- const pad = 3;
111
- const width = inner + pad * 2;
112
- const border = (s: string) => paint("2", s);
113
-
114
- const top = border(`╭${"─".repeat(width)}╮`);
115
- const bottom = border(`╰${"─".repeat(width)}╯`);
116
- const blank = `${border("│")}${" ".repeat(width)}${border("│")}`;
117
- const body = lines.map((segs) => {
118
- const painted = segs.map((s) => (s.code ? paint(s.code, s.text) : s.text));
119
- const trailing = " ".repeat(inner - visLen(segs));
120
- return `${border("│")}${" ".repeat(pad)}${painted.join("")}${trailing}${" ".repeat(pad)}${border("│")}`;
121
- });
122
-
123
- const box = [top, blank, ...body, blank, bottom]
124
- .map((l) => ` ${l}`)
125
- .join("\n");
126
- process.stdout.write(`\n${box}\n\n`);
127
- }
128
-
129
- export async function notifyUpdate(
130
- currentVersion: string,
131
- noUpdateCheck: boolean,
132
- ): Promise<void> {
133
- if (optedOut(noUpdateCheck)) return;
134
-
135
- const cached = await readCache();
136
- if (cached && isNewerVersion(cached.latest, currentVersion)) {
137
- printBanner(currentVersion, cached.latest);
138
- }
139
-
140
- const stale = !cached || Date.now() - cached.checkedAt > TTL_MS;
141
- if (stale) {
142
- // Fire-and-forget: long-running `dev` finishes this during its session;
143
- // commands that outlast the fetch refresh too. We never await it.
144
- void fetchLatest(channelFor(currentVersion)).then(async (latest) => {
145
- if (latest) {
146
- try {
147
- await Bun.write(
148
- cacheFile(),
149
- JSON.stringify({ checkedAt: Date.now(), latest }),
150
- );
151
- } catch {
152
- // best-effort cache write
153
- }
154
- }
155
- });
156
- }
157
- }
@@ -1,65 +0,0 @@
1
- import type { ComponentType } from "react";
2
- import * as React from "react";
3
- import { hydrateRoot } from "react-dom/client";
4
-
5
- export { Link, type LinkProps } from "./link.tsx";
6
- export {
7
- bootPage,
8
- getCurrentRoute,
9
- type HydratePageOptions,
10
- hydratePage,
11
- type NavigateOptions,
12
- navigate,
13
- type PageExports,
14
- prefetch,
15
- resetPageRuntime,
16
- } from "./page.ts";
17
-
18
- export interface SordoClient {
19
- register(
20
- name: string,
21
- component: ComponentType<Record<string, unknown>>,
22
- ): void;
23
- hydrateAll(): void;
24
- }
25
-
26
- export function createClient(): SordoClient {
27
- const components: Record<string, ComponentType<Record<string, unknown>>> = {};
28
-
29
- return {
30
- register(name, component) {
31
- components[name] = component;
32
- },
33
- hydrateAll() {
34
- const markers = document.querySelectorAll<HTMLElement>("[data-island]");
35
- markers.forEach((marker) => {
36
- const name = marker.getAttribute("data-island");
37
- if (!name) return;
38
- const Component = components[name];
39
- if (!Component) {
40
- console.error("[sordo] unknown island:", name);
41
- return;
42
- }
43
- let props: Record<string, unknown> = {};
44
- const propsTag = marker.nextElementSibling;
45
- if (
46
- propsTag &&
47
- (propsTag as Element).matches?.(
48
- `script[data-props][data-for="${name}"]`,
49
- )
50
- ) {
51
- try {
52
- props = JSON.parse(propsTag.textContent || "{}");
53
- } catch (e) {
54
- console.error(`[sordo] island props parse for '${name}':`, e);
55
- }
56
- }
57
- try {
58
- hydrateRoot(marker, React.createElement(Component, props));
59
- } catch (e) {
60
- console.error(`[sordo] hydrate failed for island '${name}':`, e);
61
- }
62
- });
63
- },
64
- };
65
- }
@@ -1,61 +0,0 @@
1
- import type * as React from "react";
2
- import { canSoftNavigate, navigate, prefetch } from "./page.ts";
3
-
4
- export interface LinkProps
5
- extends Omit<React.AnchorHTMLAttributes<HTMLAnchorElement>, "href"> {
6
- href: string;
7
- // Replace the current history entry instead of pushing a new one.
8
- replace?: boolean;
9
- // "intent" warms the target's payload + chunk on hover/focus.
10
- prefetch?: "intent" | "none";
11
- ref?: React.Ref<HTMLAnchorElement>;
12
- }
13
-
14
- // A plain <a> that upgrades to a client-side transition on hydrated pages.
15
- // Without a booted page runtime (zero-JS or island pages) it is an ordinary
16
- // link, so it SSRs and degrades without JavaScript.
17
- export function Link({
18
- href,
19
- replace,
20
- prefetch: prefetchMode = "intent",
21
- onClick,
22
- onMouseEnter,
23
- onFocus,
24
- ...rest
25
- }: LinkProps) {
26
- const warm = () => {
27
- if (prefetchMode === "intent") prefetch(href);
28
- };
29
- return (
30
- <a
31
- {...rest}
32
- href={href}
33
- onMouseEnter={(e) => {
34
- onMouseEnter?.(e);
35
- warm();
36
- }}
37
- onFocus={(e) => {
38
- onFocus?.(e);
39
- warm();
40
- }}
41
- onClick={(e) => {
42
- onClick?.(e);
43
- if (
44
- e.defaultPrevented ||
45
- e.button !== 0 ||
46
- e.metaKey ||
47
- e.ctrlKey ||
48
- e.shiftKey ||
49
- e.altKey ||
50
- (rest.target && rest.target !== "_self") ||
51
- rest.download !== undefined ||
52
- !canSoftNavigate(href)
53
- ) {
54
- return;
55
- }
56
- e.preventDefault();
57
- void navigate(href, { replace });
58
- }}
59
- />
60
- );
61
- }