mirror of
https://github.com/OpenRouterTeam/spawn.git
synced 2026-05-20 01:11:18 +00:00
refactor: deduplicate PkgVersionSchema to shared/parse.ts (#2357)
Move the PkgVersionSchema (v.object({ version: v.string() })) from its
duplicate definitions in commands/shared.ts and update-check.ts into the
shared parse module. Both consumers now import from the single source.
Bump CLI version to 0.15.22.
Co-authored-by: spawn-qa-bot <qa@openrouter.ai>
Co-authored-by: L <6723574+louisgv@users.noreply.github.com>
This commit is contained in:
parent
8bc5581e62
commit
62e1df9be5
4 changed files with 9 additions and 13 deletions
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "@openrouter/spawn",
|
||||
"version": "0.15.21",
|
||||
"version": "0.15.22",
|
||||
"type": "module",
|
||||
"bin": {
|
||||
"spawn": "cli.js"
|
||||
|
|
|
|||
|
|
@ -4,10 +4,10 @@ import type { Manifest } from "../manifest.js";
|
|||
import * as fs from "node:fs";
|
||||
import * as p from "@clack/prompts";
|
||||
import pc from "picocolors";
|
||||
import * as v from "valibot";
|
||||
import pkg from "../../package.json" with { type: "json" };
|
||||
import { agentKeys, cloudKeys, isStaleCache, loadManifest, matrixStatus } from "../manifest.js";
|
||||
import { validateIdentifier, validatePrompt } from "../security.js";
|
||||
import { PkgVersionSchema } from "../shared/parse.js";
|
||||
import { getErrorMessage, isString } from "../shared/type-guards.js";
|
||||
import { getSpawnCloudConfigPath } from "../shared/ui.js";
|
||||
|
||||
|
|
@ -17,9 +17,7 @@ export const VERSION = pkg.version;
|
|||
export const FETCH_TIMEOUT = 10_000; // 10 seconds
|
||||
export const NAME_COLUMN_WIDTH = 18;
|
||||
|
||||
export const PkgVersionSchema = v.object({
|
||||
version: v.string(),
|
||||
});
|
||||
export { PkgVersionSchema };
|
||||
|
||||
// ── Helpers ──────────────────────────────────────────────────────────────────
|
||||
|
||||
|
|
|
|||
|
|
@ -17,6 +17,11 @@ export function parseJsonWith<T extends v.BaseSchema<unknown, unknown, v.BaseIss
|
|||
}
|
||||
}
|
||||
|
||||
/** Schema for responses containing a `version` field (npm registry, GitHub releases). */
|
||||
export const PkgVersionSchema = v.object({
|
||||
version: v.string(),
|
||||
});
|
||||
|
||||
/**
|
||||
* Parse a JSON string and return it as a Record<string, unknown> or null.
|
||||
* Rejects non-object results (arrays, primitives).
|
||||
|
|
|
|||
|
|
@ -6,10 +6,9 @@ import fs from "node:fs";
|
|||
import { homedir } from "node:os";
|
||||
import path from "node:path";
|
||||
import pc from "picocolors";
|
||||
import * as v from "valibot";
|
||||
import pkg from "../package.json" with { type: "json" };
|
||||
import { RAW_BASE, SPAWN_CDN, VERSION_URL } from "./manifest.js";
|
||||
import { parseJsonWith } from "./shared/parse";
|
||||
import { PkgVersionSchema, parseJsonWith } from "./shared/parse";
|
||||
import { hasStatus } from "./shared/type-guards";
|
||||
|
||||
const VERSION = pkg.version;
|
||||
|
|
@ -24,12 +23,6 @@ export const executor = {
|
|||
const FETCH_TIMEOUT = 10000; // 10 seconds
|
||||
const UPDATE_BACKOFF_MS = 60 * 60 * 1000; // 1 hour
|
||||
|
||||
// ── Schemas ──────────────────────────────────────────────────────────────────
|
||||
|
||||
const PkgVersionSchema = v.object({
|
||||
version: v.string(),
|
||||
});
|
||||
|
||||
// Use ASCII-safe symbols when unicode is disabled (SSH, dumb terminals)
|
||||
const isAscii = process.env.TERM === "linux";
|
||||
const CHECK_MARK = isAscii ? "*" : "\u2713";
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue