@hop-top/kit 0.5.0-alpha.12 → 0.5.0-alpha.13
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 +29 -0
- package/README.md +5 -5
- package/dist/bus-D2bAOPYz.d.ts +55 -0
- package/dist/bus.d.ts +1 -0
- package/dist/bus.js +13 -0
- package/dist/chunk-74E6RNOI.js +82 -0
- package/dist/chunk-B7XTFDBB.js +17 -0
- package/dist/chunk-CAONBSPO.js +497 -0
- package/dist/chunk-F7RSL4N4.js +88 -0
- package/dist/chunk-I6XDPSXQ.js +75 -0
- package/dist/chunk-IDM6YZXN.js +204 -0
- package/dist/chunk-VKQCOVKI.js +880 -0
- package/dist/cli.js +3 -3
- package/dist/index-BqZ7WGQf.d.ts +731 -0
- package/dist/index.d.ts +4 -1
- package/dist/index.js +27 -13
- package/dist/upgrade/drivers/configfile.d.ts +45 -0
- package/dist/upgrade/drivers/configfile.js +78 -0
- package/dist/upgrade/drivers/fsdir.d.ts +61 -0
- package/dist/upgrade/drivers/fsdir.js +170 -0
- package/dist/upgrade/drivers/postgres.d.ts +121 -0
- package/dist/upgrade/drivers/postgres.js +195 -0
- package/dist/upgrade/drivers/sqlite.d.ts +101 -0
- package/dist/upgrade/drivers/sqlite.js +241 -0
- package/dist/upgrade/index.d.ts +2 -0
- package/dist/upgrade/index.js +73 -0
- package/dist/uri-IJ_AoY3d.d.ts +144 -0
- package/dist/uri.d.ts +1 -0
- package/dist/uri.js +37 -0
- package/dist/version-DEJ3pbiO.d.ts +10 -0
- package/dist/wizard-Bf_qHc31.d.ts +159 -0
- package/dist/wizard.d.ts +1 -0
- package/dist/wizard.js +39 -0
- package/package.json +74 -15
- package/skills/hop-top-kit-ts/.claude-plugin/plugin.json +19 -0
- package/skills/hop-top-kit-ts/SKILL.md +117 -0
- package/skills/hop-top-kit-ts/assets/snippets/mcp/mcp.expected +2 -0
- package/skills/hop-top-kit-ts/assets/snippets/mcp/mcp.ts +20 -0
- package/skills/hop-top-kit-ts/assets/snippets/quickstart/quickstart.expected +13 -0
- package/skills/hop-top-kit-ts/assets/snippets/quickstart/quickstart.ts +26 -0
- package/skills/hop-top-kit-ts/gym.json +5 -0
- package/skills/hop-top-kit-ts/references/ai-and-agents.md +45 -0
- package/skills/hop-top-kit-ts/references/cli-and-console.md +63 -0
- package/skills/hop-top-kit-ts/references/coverage.md +56 -0
- package/skills/hop-top-kit-ts/references/guardrails-and-trust.md +60 -0
- package/skills/hop-top-kit-ts/references/other-ports.md +31 -0
- package/skills/hop-top-kit-ts/references/serving-and-transports.md +49 -0
- package/skills/hop-top-kit-ts/scripts/detect-port.sh +168 -0
- package/src/index.test.ts +48 -2
- package/src/index.ts +6 -1
- package/src/published-types.test.ts +8 -0
- package/src/serve.stopped-order.test.ts +156 -0
- package/src/upgrade/README.md +42 -0
- package/src/upgrade/backup.ts +174 -0
- package/src/upgrade/conformance.test.ts +310 -0
- package/src/upgrade/document.ts +229 -0
- package/src/upgrade/driver.ts +66 -0
- package/src/upgrade/drivers/README.md +47 -0
- package/src/upgrade/drivers/configfile.test.ts +112 -0
- package/src/upgrade/drivers/configfile.ts +107 -0
- package/src/upgrade/drivers/fsdir.test.ts +188 -0
- package/src/upgrade/drivers/fsdir.ts +216 -0
- package/src/upgrade/drivers/isolation.test.ts +18 -0
- package/src/upgrade/drivers/postgres.integration.test.ts +395 -0
- package/src/upgrade/drivers/postgres.test.ts +272 -0
- package/src/upgrade/drivers/postgres.ts +284 -0
- package/src/upgrade/drivers/sqlite.integration.test.ts +492 -0
- package/src/upgrade/drivers/sqlite.ts +300 -0
- package/src/upgrade/drivers/version.ts +21 -0
- package/src/upgrade/errors.ts +117 -0
- package/src/upgrade/events.ts +117 -0
- package/src/{upgrade.test.ts → upgrade/index.test.ts} +1 -1
- package/src/{upgrade.ts → upgrade/index.ts} +20 -0
- package/src/upgrade/migration.ts +89 -0
- package/src/upgrade/migrator.test.ts +391 -0
- package/src/upgrade/migrator.ts +527 -0
- package/src/upgrade/options.ts +59 -0
- package/src/upgrade/semver.ts +90 -0
- package/test/skill-snippets.test.ts +60 -0
- package/test/upgrade/conformance-migrator.ts +439 -0
- package/test/upgrade/conformance-support.ts +44 -0
- package/test/upgrade/driver-support.ts +44 -0
- package/test/upgrade/pg-container.ts +64 -0
- package/test/upgrade/pg-race-worker.ts +48 -0
- package/test/upgrade/race-helper.ts +36 -0
- package/test/upgrade/sqlite-support.ts +41 -0
- package/test/upgrade/testdata/go-fsdir-mydata.tar.gz +0 -0
- package/vitest.config.ts +26 -0
- package/dist/chunk-X4E5QGEB.js +0 -171
- package/dist/upgrade-BJ2z6Oqf.d.ts +0 -156
- package/dist/upgrade.d.ts +0 -1
- package/dist/upgrade.js +0 -9
- package/dist/{chunk-MFVUENZR.js → chunk-KV7FYEAF.js} +2 -2
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
// The second process of the sqlite two-process test, bundled by the test
|
|
2
|
+
// with esbuild and run with node. Migrates `<RACE_DIR>/app.db` from 1.0.0
|
|
3
|
+
// to 1.2.0, each migration recording its version and pid in `applied`.
|
|
4
|
+
|
|
5
|
+
import Database from 'better-sqlite3';
|
|
6
|
+
|
|
7
|
+
import { Migrator, Registry } from '../../src/upgrade';
|
|
8
|
+
import { SqliteDriver } from '../../src/upgrade/drivers/sqlite';
|
|
9
|
+
|
|
10
|
+
const dir = process.env['RACE_DIR'] as string;
|
|
11
|
+
const dbPath = `${dir}/app.db`;
|
|
12
|
+
const data = `${dir}/data`;
|
|
13
|
+
const db = new Database(dbPath);
|
|
14
|
+
|
|
15
|
+
const reg = new Registry();
|
|
16
|
+
for (const v of ['1.1.0', '1.2.0']) {
|
|
17
|
+
reg.register({
|
|
18
|
+
version: v,
|
|
19
|
+
schema: 'appdb',
|
|
20
|
+
up: async () => {
|
|
21
|
+
await new Promise((r) => setTimeout(r, 200)); // a window for the other process
|
|
22
|
+
db.prepare('INSERT INTO applied (version, pid) VALUES (?, ?)').run(v, process.pid);
|
|
23
|
+
},
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
const m = new Migrator('tool', '1.2.0', { registry: reg, dataDir: data });
|
|
27
|
+
m.addDriver(new SqliteDriver(dbPath, { name: 'appdb', dataDir: data }));
|
|
28
|
+
m.run().then(
|
|
29
|
+
() => {
|
|
30
|
+
db.close();
|
|
31
|
+
},
|
|
32
|
+
(e: unknown) => {
|
|
33
|
+
console.error(e);
|
|
34
|
+
process.exit(1);
|
|
35
|
+
},
|
|
36
|
+
);
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
// Helpers of the sqlite driver tests. Loads better-sqlite3: import only
|
|
2
|
+
// from `*.integration.test.ts`.
|
|
3
|
+
|
|
4
|
+
import Database from 'better-sqlite3';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Opens (creating) a WAL-mode database with table t(x). Auto-checkpoint is
|
|
8
|
+
* off and the handle stays open, so committed rows stay in the -wal file:
|
|
9
|
+
* a plain copy of the database file does not hold them.
|
|
10
|
+
*/
|
|
11
|
+
export function openWAL(path: string): Database.Database {
|
|
12
|
+
const db = new Database(path);
|
|
13
|
+
db.pragma('journal_mode = WAL');
|
|
14
|
+
db.pragma('wal_autocheckpoint = 0');
|
|
15
|
+
db.exec('CREATE TABLE IF NOT EXISTS t (x INTEGER)');
|
|
16
|
+
return db;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function insert(db: Database.Database, ...xs: number[]): void {
|
|
20
|
+
const stmt = db.prepare('INSERT INTO t (x) VALUES (?)');
|
|
21
|
+
for (const x of xs) stmt.run(x);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/** Reads t(x) in order on a connection of its own, closed after. */
|
|
25
|
+
export function rows(path: string): number[] {
|
|
26
|
+
const db = new Database(path, { readonly: true, fileMustExist: true });
|
|
27
|
+
try {
|
|
28
|
+
return (db.prepare('SELECT x FROM t ORDER BY x').all() as { x: number }[]).map((r) => r.x);
|
|
29
|
+
} finally {
|
|
30
|
+
db.close();
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export function integrity(path: string): string {
|
|
35
|
+
const db = new Database(path, { readonly: true, fileMustExist: true });
|
|
36
|
+
try {
|
|
37
|
+
return db.pragma('integrity_check', { simple: true }) as string;
|
|
38
|
+
} finally {
|
|
39
|
+
db.close();
|
|
40
|
+
}
|
|
41
|
+
}
|
|
Binary file
|
package/vitest.config.ts
CHANGED
|
@@ -1,6 +1,32 @@
|
|
|
1
|
+
import { readFileSync } from "node:fs";
|
|
2
|
+
import { fileURLToPath } from "node:url";
|
|
1
3
|
import { defineConfig } from "vitest/config";
|
|
2
4
|
|
|
5
|
+
// Resolve the published package name to src/ so code written the way an
|
|
6
|
+
// adopter writes it (`import ... from "@hop-top/kit/output"`, as the agent
|
|
7
|
+
// skill snippets do) runs without a build. Aliases come from the exports map
|
|
8
|
+
// of package.json: "./dist/<x>.js" maps to "./src/<x>.ts". Exact matches
|
|
9
|
+
// only, so "@hop-top/kit/upgrade" does not swallow its drivers.
|
|
10
|
+
const here = (p: string): string => fileURLToPath(new URL(p, import.meta.url));
|
|
11
|
+
const exportsMap: Record<string, { default?: string }> = JSON.parse(
|
|
12
|
+
readFileSync(here("./package.json"), "utf8"),
|
|
13
|
+
).exports;
|
|
14
|
+
|
|
15
|
+
const escape = (s: string): string => s.replace(/[.*+?^${}()|[\]\\/]/g, "\\$&");
|
|
16
|
+
|
|
17
|
+
const kitAliases = Object.entries(exportsMap).flatMap(([sub, target]) => {
|
|
18
|
+
const dist = target.default;
|
|
19
|
+
if (!dist?.startsWith("./dist/") || !dist.endsWith(".js")) return [];
|
|
20
|
+
return [
|
|
21
|
+
{
|
|
22
|
+
find: new RegExp(`^${escape("@hop-top/kit" + sub.slice(1))}$`),
|
|
23
|
+
replacement: here(dist.replace("./dist/", "./src/").replace(/\.js$/, ".ts")),
|
|
24
|
+
},
|
|
25
|
+
];
|
|
26
|
+
});
|
|
27
|
+
|
|
3
28
|
export default defineConfig({
|
|
29
|
+
resolve: { alias: kitAliases },
|
|
4
30
|
test: {
|
|
5
31
|
// Every test file starts with an empty XDG config home, so no
|
|
6
32
|
// developer's llm.yaml (or other config) reaches a test.
|
package/dist/chunk-X4E5QGEB.js
DELETED
|
@@ -1,171 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
2
|
-
|
|
3
|
-
var _chunkR5U7XKVJjs = require('./chunk-R5U7XKVJ.js');
|
|
4
|
-
|
|
5
|
-
// src/upgrade.ts
|
|
6
|
-
var upgrade_exports = {};
|
|
7
|
-
_chunkR5U7XKVJjs.__export.call(void 0, upgrade_exports, {
|
|
8
|
-
UpgradeCheckError: () => UpgradeCheckError,
|
|
9
|
-
createChecker: () => createChecker
|
|
10
|
-
});
|
|
11
|
-
var _fs = require('fs'); var fs = _interopRequireWildcard(_fs);
|
|
12
|
-
var _os = require('os'); var os = _interopRequireWildcard(_os);
|
|
13
|
-
var _path = require('path'); var path = _interopRequireWildcard(_path);
|
|
14
|
-
var _semver = require('semver'); var _semver2 = _interopRequireDefault(_semver);
|
|
15
|
-
var UpgradeCheckError = class extends Error {
|
|
16
|
-
constructor(message, options) {
|
|
17
|
-
super(message, options);
|
|
18
|
-
this.name = "UpgradeCheckError";
|
|
19
|
-
}
|
|
20
|
-
};
|
|
21
|
-
var PAGE_SIZE = 100;
|
|
22
|
-
var MAX_PAGES = 3;
|
|
23
|
-
function createChecker(opts) {
|
|
24
|
-
const {
|
|
25
|
-
name,
|
|
26
|
-
currentVersion,
|
|
27
|
-
owner,
|
|
28
|
-
repo,
|
|
29
|
-
cacheTTL = 24 * 60 * 60 * 1e3,
|
|
30
|
-
stateDir = os.tmpdir(),
|
|
31
|
-
timeout = 1e4,
|
|
32
|
-
tagPrefix = "",
|
|
33
|
-
includePrereleases = false
|
|
34
|
-
} = opts;
|
|
35
|
-
const listMode = tagPrefix !== "" || includePrereleases;
|
|
36
|
-
const cacheFile = path.join(stateDir, `.upgrade-${name}-cache.json`);
|
|
37
|
-
const releaseURL = `https://api.github.com/repos/${owner}/${repo}/releases/latest`;
|
|
38
|
-
const listURL = `https://api.github.com/repos/${owner}/${repo}/releases`;
|
|
39
|
-
const releasesPageURL = `https://github.com/${owner}/${repo}/releases/latest`;
|
|
40
|
-
function noticeURL(tag) {
|
|
41
|
-
if (!listMode) return releasesPageURL;
|
|
42
|
-
const base = `https://github.com/${owner}/${repo}/releases`;
|
|
43
|
-
if (tag === void 0) return base;
|
|
44
|
-
return `${base}/tag/${tag.split("/").map(encodeURIComponent).join("/")}`;
|
|
45
|
-
}
|
|
46
|
-
function tagNamesVersion(tag, version) {
|
|
47
|
-
return typeof tag === "string" && tag.startsWith(tagPrefix) && _semver2.default.valid(tag.slice(tagPrefix.length).replace(/^v/, "")) === version;
|
|
48
|
-
}
|
|
49
|
-
function readCache() {
|
|
50
|
-
try {
|
|
51
|
-
const raw = fs.readFileSync(cacheFile, "utf8");
|
|
52
|
-
const parsed = JSON.parse(raw);
|
|
53
|
-
if (typeof parsed.version === "string" && typeof parsed.checkedAt === "number") {
|
|
54
|
-
if (listMode && !tagNamesVersion(parsed.tag, parsed.version)) {
|
|
55
|
-
return null;
|
|
56
|
-
}
|
|
57
|
-
return parsed;
|
|
58
|
-
}
|
|
59
|
-
} catch (e) {
|
|
60
|
-
}
|
|
61
|
-
return null;
|
|
62
|
-
}
|
|
63
|
-
function writeCache(version, tag) {
|
|
64
|
-
try {
|
|
65
|
-
const entry = { version, checkedAt: Date.now() };
|
|
66
|
-
if (tag !== void 0) entry.tag = tag;
|
|
67
|
-
fs.writeFileSync(cacheFile, JSON.stringify(entry), "utf8");
|
|
68
|
-
} catch (e2) {
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
async function fetchLatestVersion() {
|
|
72
|
-
const controller = new AbortController();
|
|
73
|
-
const timer = setTimeout(() => controller.abort(), timeout);
|
|
74
|
-
try {
|
|
75
|
-
if (listMode) return await fetchHighestRelease(controller.signal);
|
|
76
|
-
const res = await fetch(releaseURL, {
|
|
77
|
-
signal: controller.signal,
|
|
78
|
-
headers: { Accept: "application/vnd.github+json" }
|
|
79
|
-
});
|
|
80
|
-
if (!res.ok) throw new UpgradeCheckError(`release lookup failed: HTTP ${res.status}`);
|
|
81
|
-
const body = await res.json();
|
|
82
|
-
const tag = body.tag_name;
|
|
83
|
-
if (typeof tag !== "string") throw new UpgradeCheckError("release lookup failed: no tag_name");
|
|
84
|
-
return { version: tag.replace(/^v/, "") };
|
|
85
|
-
} finally {
|
|
86
|
-
clearTimeout(timer);
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
async function fetchHighestRelease(signal) {
|
|
90
|
-
let best = null;
|
|
91
|
-
for (let page = 1; page <= MAX_PAGES; page++) {
|
|
92
|
-
const res = await fetch(`${listURL}?per_page=${PAGE_SIZE}&page=${page}`, {
|
|
93
|
-
signal,
|
|
94
|
-
headers: { Accept: "application/vnd.github+json" }
|
|
95
|
-
});
|
|
96
|
-
if (!res.ok) {
|
|
97
|
-
if (page === 1) throw new UpgradeCheckError(`release lookup failed: HTTP ${res.status}`);
|
|
98
|
-
break;
|
|
99
|
-
}
|
|
100
|
-
const body = await res.json();
|
|
101
|
-
if (!Array.isArray(body)) {
|
|
102
|
-
if (page === 1) throw new UpgradeCheckError("release lookup failed: unexpected response");
|
|
103
|
-
break;
|
|
104
|
-
}
|
|
105
|
-
for (const rel of body) {
|
|
106
|
-
if (rel === null || typeof rel !== "object") continue;
|
|
107
|
-
if (rel.draft === true || typeof rel.tag_name !== "string") continue;
|
|
108
|
-
const tag = rel.tag_name;
|
|
109
|
-
if (!tag.startsWith(tagPrefix)) continue;
|
|
110
|
-
const version = _semver2.default.valid(tag.slice(tagPrefix.length).replace(/^v/, ""));
|
|
111
|
-
if (version === null) continue;
|
|
112
|
-
if (!includePrereleases && (rel.prerelease === true || _semver2.default.prerelease(version) !== null)) {
|
|
113
|
-
continue;
|
|
114
|
-
}
|
|
115
|
-
if (best === null || _semver2.default.gt(version, best.version)) best = { version, tag };
|
|
116
|
-
}
|
|
117
|
-
if (body.length < PAGE_SIZE) break;
|
|
118
|
-
}
|
|
119
|
-
if (best === null) throw new UpgradeCheckError("no matching release found");
|
|
120
|
-
return best;
|
|
121
|
-
}
|
|
122
|
-
async function check() {
|
|
123
|
-
try {
|
|
124
|
-
let latestVersion;
|
|
125
|
-
let latestTag;
|
|
126
|
-
const cached = readCache();
|
|
127
|
-
if (cached !== null && Date.now() - cached.checkedAt < cacheTTL) {
|
|
128
|
-
latestVersion = cached.version;
|
|
129
|
-
latestTag = cached.tag;
|
|
130
|
-
} else {
|
|
131
|
-
const latest = await fetchLatestVersion();
|
|
132
|
-
latestVersion = latest.version;
|
|
133
|
-
latestTag = latest.tag;
|
|
134
|
-
writeCache(latest.version, latest.tag);
|
|
135
|
-
}
|
|
136
|
-
return {
|
|
137
|
-
current: currentVersion,
|
|
138
|
-
latest: latestVersion,
|
|
139
|
-
// Only strictly greater counts as an update.
|
|
140
|
-
updateAvailable: _semver2.default.gt(latestVersion, currentVersion),
|
|
141
|
-
url: noticeURL(latestTag)
|
|
142
|
-
};
|
|
143
|
-
} catch (err) {
|
|
144
|
-
if (err instanceof UpgradeCheckError) throw err;
|
|
145
|
-
throw new UpgradeCheckError(
|
|
146
|
-
`upgrade check failed: ${err instanceof Error ? err.message : String(err)}`,
|
|
147
|
-
{ cause: err }
|
|
148
|
-
);
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
async function notifyIfAvailable(out) {
|
|
152
|
-
try {
|
|
153
|
-
const r = await check();
|
|
154
|
-
if (!r.updateAvailable) return;
|
|
155
|
-
out.write(
|
|
156
|
-
`
|
|
157
|
-
A new release of ${name} is available: v${r.current} \u2192 v${r.latest}
|
|
158
|
-
${r.url}
|
|
159
|
-
`
|
|
160
|
-
);
|
|
161
|
-
} catch (e3) {
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
return { check, notifyIfAvailable };
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
exports.UpgradeCheckError = UpgradeCheckError; exports.createChecker = createChecker; exports.upgrade_exports = upgrade_exports;
|
|
@@ -1,156 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @packageDocumentation
|
|
3
|
-
*
|
|
4
|
-
* Version check and notify — compares the running tool version against the
|
|
5
|
-
* latest GitHub release and writes a human-readable upgrade notice to any
|
|
6
|
-
* {@link https://nodejs.org/api/stream.html#class-streamwritable | Writable}
|
|
7
|
-
* stream when a newer release is available.
|
|
8
|
-
*
|
|
9
|
-
* ### Cache behaviour
|
|
10
|
-
* Results are persisted to `{stateDir}/.upgrade-{name}-cache.json`.
|
|
11
|
-
* The cache stores `{ version, checkedAt }`. On the next call within `cacheTTL`
|
|
12
|
-
* milliseconds the remote API is not contacted; the cached version is used
|
|
13
|
-
* directly. After the TTL expires the cache is refreshed on the next call.
|
|
14
|
-
* Cache I/O errors are swallowed — a stale or missing cache simply causes a
|
|
15
|
-
* fresh fetch.
|
|
16
|
-
*
|
|
17
|
-
* ### Error handling philosophy
|
|
18
|
-
* Version checking is a best-effort, non-critical operation. Any failure —
|
|
19
|
-
* network error, bad JSON, HTTP error, filesystem error, invalid semver — is
|
|
20
|
-
* silently discarded by `notifyIfAvailable`, which always resolves without
|
|
21
|
-
* throwing. `check()` is the strict variant: it rejects with an
|
|
22
|
-
* {@link UpgradeCheckError} so callers (e.g. `upgrade --check`) can tell a
|
|
23
|
-
* failed lookup from "up to date".
|
|
24
|
-
*
|
|
25
|
-
* ### Notice format
|
|
26
|
-
* ```
|
|
27
|
-
* \nA new release of {name} is available: v{current} → v{latest}\nhttps://github.com/{owner}/{repo}/releases/latest\n
|
|
28
|
-
* ```
|
|
29
|
-
*
|
|
30
|
-
* ### Component tags and prereleases
|
|
31
|
-
* By default the check reads `releases/latest` and strips a leading `v`.
|
|
32
|
-
* Set `tagPrefix` (e.g. `xray/v`) for a monorepo whose tags carry a
|
|
33
|
-
* component: releases are listed, tags without the prefix are ignored, and
|
|
34
|
-
* the notice links to the matching release. Set `includePrereleases` to
|
|
35
|
-
* consider prereleases; without it, prereleases are never offered. Both
|
|
36
|
-
* options list at most 3 pages of 100 releases, newest first, drafts
|
|
37
|
-
* skipped; the highest semver wins.
|
|
38
|
-
*
|
|
39
|
-
* ### Usage example
|
|
40
|
-
* ```ts
|
|
41
|
-
* import { createChecker } from '@hop-top/kit/upgrade';
|
|
42
|
-
*
|
|
43
|
-
* const checker = createChecker({
|
|
44
|
-
* name: 'my-cli',
|
|
45
|
-
* currentVersion: '1.2.3',
|
|
46
|
-
* owner: 'myorg',
|
|
47
|
-
* repo: 'my-cli',
|
|
48
|
-
* });
|
|
49
|
-
*
|
|
50
|
-
* // At the end of your CLI command:
|
|
51
|
-
* await checker.notifyIfAvailable(process.stderr);
|
|
52
|
-
* ```
|
|
53
|
-
*/
|
|
54
|
-
/**
|
|
55
|
-
* Static configuration for a version {@link Checker}.
|
|
56
|
-
*/
|
|
57
|
-
interface CheckerOptions {
|
|
58
|
-
/** Human-readable tool name shown in the upgrade notice. */
|
|
59
|
-
name: string;
|
|
60
|
-
/** Currently running version string (semver, without leading `v`). */
|
|
61
|
-
currentVersion: string;
|
|
62
|
-
/** GitHub organisation or username that owns the repository. */
|
|
63
|
-
owner: string;
|
|
64
|
-
/** GitHub repository name. */
|
|
65
|
-
repo: string;
|
|
66
|
-
/**
|
|
67
|
-
* How long (ms) a cached result stays valid before a fresh fetch is made.
|
|
68
|
-
* @defaultValue 86_400_000 (24 hours)
|
|
69
|
-
*/
|
|
70
|
-
cacheTTL?: number;
|
|
71
|
-
/**
|
|
72
|
-
* Directory used to store the cache file.
|
|
73
|
-
* @defaultValue `os.tmpdir()`
|
|
74
|
-
*/
|
|
75
|
-
stateDir?: string;
|
|
76
|
-
/**
|
|
77
|
-
* HTTP request timeout in milliseconds.
|
|
78
|
-
* @defaultValue 10_000
|
|
79
|
-
*/
|
|
80
|
-
timeout?: number;
|
|
81
|
-
/**
|
|
82
|
-
* Tag prefix identifying this tool's releases, stripped before the semver
|
|
83
|
-
* comparison (e.g. `'xray/v'` for tags like `xray/v0.2.0`). Tags without
|
|
84
|
-
* the prefix are not candidates. Setting it lists releases instead of
|
|
85
|
-
* reading `releases/latest`, which may belong to another component.
|
|
86
|
-
* @defaultValue `''` (no prefix; `releases/latest`)
|
|
87
|
-
*/
|
|
88
|
-
tagPrefix?: string;
|
|
89
|
-
/**
|
|
90
|
-
* Offer prereleases (e.g. `0.1.0-rc.1`) as upgrades. Setting it lists
|
|
91
|
-
* releases instead of reading `releases/latest`, which skips prereleases.
|
|
92
|
-
* @defaultValue false
|
|
93
|
-
*/
|
|
94
|
-
includePrereleases?: boolean;
|
|
95
|
-
}
|
|
96
|
-
/** Outcome of {@link Checker.check}. */
|
|
97
|
-
interface UpgradeCheckResult {
|
|
98
|
-
/** Running version, as configured. */
|
|
99
|
-
current: string;
|
|
100
|
-
/** Latest release version (no leading `v` / tag prefix). */
|
|
101
|
-
latest: string;
|
|
102
|
-
/** True when `latest` is strictly greater than `current`. */
|
|
103
|
-
updateAvailable: boolean;
|
|
104
|
-
/** Release page to link to. */
|
|
105
|
-
url: string;
|
|
106
|
-
}
|
|
107
|
-
/** Rejection of {@link Checker.check}; the underlying error is in `cause`. */
|
|
108
|
-
declare class UpgradeCheckError extends Error {
|
|
109
|
-
constructor(message: string, options?: {
|
|
110
|
-
cause?: unknown;
|
|
111
|
-
});
|
|
112
|
-
}
|
|
113
|
-
/**
|
|
114
|
-
* Returned by {@link createChecker}. Call {@link Checker.notifyIfAvailable}
|
|
115
|
-
* at the end of a CLI command to surface upgrade notices non-intrusively.
|
|
116
|
-
*/
|
|
117
|
-
interface Checker {
|
|
118
|
-
/**
|
|
119
|
-
* Looks up the latest release and resolves with the outcome. Unlike
|
|
120
|
-
* {@link Checker.notifyIfAvailable} it never swallows failures: network,
|
|
121
|
-
* HTTP, parse and "no matching release" errors reject with an
|
|
122
|
-
* {@link UpgradeCheckError}, so callers can tell a failed lookup from
|
|
123
|
-
* "up to date". Honours `tagPrefix`, `includePrereleases` and the cache;
|
|
124
|
-
* pass `cacheTTL: 0` to bypass the cache.
|
|
125
|
-
*/
|
|
126
|
-
check(): Promise<UpgradeCheckResult>;
|
|
127
|
-
/**
|
|
128
|
-
* Checks for a newer GitHub release and writes a one-line notice to `out`
|
|
129
|
-
* if one is available. Silently swallows all errors.
|
|
130
|
-
*
|
|
131
|
-
* @param out - Any Node.js writable stream (e.g. `process.stderr`).
|
|
132
|
-
*/
|
|
133
|
-
notifyIfAvailable(out: NodeJS.WritableStream): Promise<void>;
|
|
134
|
-
}
|
|
135
|
-
/**
|
|
136
|
-
* Creates a {@link Checker} configured with the provided options.
|
|
137
|
-
*
|
|
138
|
-
* The checker is stateless beyond what is persisted in the cache file; it is
|
|
139
|
-
* safe to create multiple instances with the same options.
|
|
140
|
-
*
|
|
141
|
-
* @param opts - Configuration options; see {@link CheckerOptions}.
|
|
142
|
-
* @returns A {@link Checker} ready to call.
|
|
143
|
-
*/
|
|
144
|
-
declare function createChecker(opts: CheckerOptions): Checker;
|
|
145
|
-
|
|
146
|
-
type upgrade_Checker = Checker;
|
|
147
|
-
type upgrade_CheckerOptions = CheckerOptions;
|
|
148
|
-
type upgrade_UpgradeCheckError = UpgradeCheckError;
|
|
149
|
-
declare const upgrade_UpgradeCheckError: typeof UpgradeCheckError;
|
|
150
|
-
type upgrade_UpgradeCheckResult = UpgradeCheckResult;
|
|
151
|
-
declare const upgrade_createChecker: typeof createChecker;
|
|
152
|
-
declare namespace upgrade {
|
|
153
|
-
export { type upgrade_Checker as Checker, type upgrade_CheckerOptions as CheckerOptions, upgrade_UpgradeCheckError as UpgradeCheckError, type upgrade_UpgradeCheckResult as UpgradeCheckResult, upgrade_createChecker as createChecker };
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
export { type Checker as C, UpgradeCheckError as U, type CheckerOptions as a, type UpgradeCheckResult as b, createChecker as c, upgrade as u };
|
package/dist/upgrade.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { C as Checker, a as CheckerOptions, U as UpgradeCheckError, b as UpgradeCheckResult, c as createChecker } from './upgrade-BJ2z6Oqf.js';
|
package/dist/upgrade.js
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
var _chunkX4E5QGEBjs = require('./chunk-X4E5QGEB.js');
|
|
5
|
-
require('./chunk-R5U7XKVJ.js');
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
exports.UpgradeCheckError = _chunkX4E5QGEBjs.UpgradeCheckError; exports.createChecker = _chunkX4E5QGEBjs.createChecker;
|
|
@@ -26,7 +26,6 @@ var _chunkGFRAYYRDjs = require('./chunk-GFRAYYRD.js');
|
|
|
26
26
|
var _chunkPOR5L2DGjs = require('./chunk-POR5L2DG.js');
|
|
27
27
|
|
|
28
28
|
|
|
29
|
-
var _chunkT6OZMPPVjs = require('./chunk-T6OZMPPV.js');
|
|
30
29
|
|
|
31
30
|
|
|
32
31
|
|
|
@@ -34,9 +33,10 @@ var _chunkT6OZMPPVjs = require('./chunk-T6OZMPPV.js');
|
|
|
34
33
|
|
|
35
34
|
|
|
36
35
|
|
|
36
|
+
var _chunkKVG7YCTSjs = require('./chunk-KVG7YCTS.js');
|
|
37
37
|
|
|
38
38
|
|
|
39
|
-
var
|
|
39
|
+
var _chunkT6OZMPPVjs = require('./chunk-T6OZMPPV.js');
|
|
40
40
|
|
|
41
41
|
|
|
42
42
|
var _chunk4UE5TCMQjs = require('./chunk-4UE5TCMQ.js');
|