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
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
|
-
}
|
package/src/cli/update-check.ts
DELETED
|
@@ -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
|
-
}
|
package/src/client/index.ts
DELETED
|
@@ -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
|
-
}
|
package/src/client/link.tsx
DELETED
|
@@ -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
|
-
}
|