splithub 0.1.9 → 0.2.1
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/README.md +11 -0
- package/dist/chunk-3RVNT2HA.js +54 -0
- package/dist/chunk-3RVNT2HA.js.map +1 -0
- package/dist/chunk-5C24F2ZN.js +113 -0
- package/dist/chunk-5C24F2ZN.js.map +1 -0
- package/dist/chunk-B6FITBWN.js +384 -0
- package/dist/chunk-B6FITBWN.js.map +1 -0
- package/dist/chunk-BJQJGLOB.js +160 -0
- package/dist/chunk-BJQJGLOB.js.map +1 -0
- package/dist/chunk-DDWYTOX4.js +565 -0
- package/dist/chunk-DDWYTOX4.js.map +1 -0
- package/dist/chunk-DUIJ5DTV.js +170 -0
- package/dist/chunk-DUIJ5DTV.js.map +1 -0
- package/dist/chunk-E5VH4BQX.js +326 -0
- package/dist/chunk-E5VH4BQX.js.map +1 -0
- package/dist/chunk-EYYLDI5J.js +195 -0
- package/dist/chunk-EYYLDI5J.js.map +1 -0
- package/dist/chunk-GVARYUL3.js +28 -0
- package/dist/chunk-GVARYUL3.js.map +1 -0
- package/dist/chunk-KMO5GGGC.js +185 -0
- package/dist/chunk-KMO5GGGC.js.map +1 -0
- package/dist/chunk-LT4JP3IF.js +119 -0
- package/dist/chunk-LT4JP3IF.js.map +1 -0
- package/dist/chunk-NMN5YGNP.js +72 -0
- package/dist/chunk-NMN5YGNP.js.map +1 -0
- package/dist/chunk-OHA2M7QR.js +264 -0
- package/dist/chunk-OHA2M7QR.js.map +1 -0
- package/dist/chunk-OYM64FMD.js +63 -0
- package/dist/chunk-OYM64FMD.js.map +1 -0
- package/dist/chunk-PLXDG4B5.js +134 -0
- package/dist/chunk-PLXDG4B5.js.map +1 -0
- package/dist/chunk-PNPOOAHF.js +393 -0
- package/dist/chunk-PNPOOAHF.js.map +1 -0
- package/dist/chunk-RYDA7PQF.js +97 -0
- package/dist/chunk-RYDA7PQF.js.map +1 -0
- package/dist/chunk-V3DLUVOE.js +112 -0
- package/dist/chunk-V3DLUVOE.js.map +1 -0
- package/dist/ci-ZQZ6RBUJ.js +16 -0
- package/dist/ci-ZQZ6RBUJ.js.map +1 -0
- package/dist/create-AEJVXN25.js +18 -0
- package/dist/create-AEJVXN25.js.map +1 -0
- package/dist/dev-W2JGUV2A.js +11 -0
- package/dist/dev-W2JGUV2A.js.map +1 -0
- package/dist/doctor-D3KOGOX6.js +14 -0
- package/dist/doctor-D3KOGOX6.js.map +1 -0
- package/dist/holdout-BWVTTLEY.js +44 -0
- package/dist/holdout-BWVTTLEY.js.map +1 -0
- package/dist/index.js +94 -2240
- package/dist/index.js.map +1 -1
- package/dist/init-UBUDSJBD.js +15 -0
- package/dist/init-UBUDSJBD.js.map +1 -0
- package/dist/lifecycle-ZLZUTASA.js +12 -0
- package/dist/lifecycle-ZLZUTASA.js.map +1 -0
- package/dist/login-TIIX5V4O.js +18 -0
- package/dist/login-TIIX5V4O.js.map +1 -0
- package/dist/menu-S3WDS4JY.js +163 -0
- package/dist/menu-S3WDS4JY.js.map +1 -0
- package/dist/plan-G2A55FR7.js +135 -0
- package/dist/plan-G2A55FR7.js.map +1 -0
- package/dist/push-OJX4F2BH.js +16 -0
- package/dist/push-OJX4F2BH.js.map +1 -0
- package/dist/refs-RY7H3J7L.js +44 -0
- package/dist/refs-RY7H3J7L.js.map +1 -0
- package/dist/remove-EQQCDJRU.js +54 -0
- package/dist/remove-EQQCDJRU.js.map +1 -0
- package/dist/report-6WNO576N.js +69 -0
- package/dist/report-6WNO576N.js.map +1 -0
- package/dist/results-ZDOCWN6U.js +21 -0
- package/dist/results-ZDOCWN6U.js.map +1 -0
- package/dist/review-7E7JVMMV.js +34 -0
- package/dist/review-7E7JVMMV.js.map +1 -0
- package/dist/ship-MRBHWFZR.js +450 -0
- package/dist/ship-MRBHWFZR.js.map +1 -0
- package/dist/skills-JJOKGNO5.js +13 -0
- package/dist/skills-JJOKGNO5.js.map +1 -0
- package/dist/status-SATP23WK.js +12 -0
- package/dist/status-SATP23WK.js.map +1 -0
- package/dist/update-67QDJ6GF.js +37 -0
- package/dist/update-67QDJ6GF.js.map +1 -0
- package/package.json +22 -5
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import {
|
|
3
|
+
findRefs
|
|
4
|
+
} from "./chunk-GVARYUL3.js";
|
|
5
|
+
import {
|
|
6
|
+
versionReport
|
|
7
|
+
} from "./chunk-OHA2M7QR.js";
|
|
8
|
+
import {
|
|
9
|
+
loadConfig
|
|
10
|
+
} from "./chunk-B6FITBWN.js";
|
|
11
|
+
import {
|
|
12
|
+
resolveTarget
|
|
13
|
+
} from "./chunk-BJQJGLOB.js";
|
|
14
|
+
import {
|
|
15
|
+
detectProject,
|
|
16
|
+
grepFiles,
|
|
17
|
+
listSourceFiles
|
|
18
|
+
} from "./chunk-PLXDG4B5.js";
|
|
19
|
+
import {
|
|
20
|
+
c,
|
|
21
|
+
printJson
|
|
22
|
+
} from "./chunk-V3DLUVOE.js";
|
|
23
|
+
|
|
24
|
+
// src/commands/doctor.ts
|
|
25
|
+
import { existsSync, readFileSync } from "fs";
|
|
26
|
+
import { join, relative } from "path";
|
|
27
|
+
async function doctor(flags) {
|
|
28
|
+
const checks = [];
|
|
29
|
+
const add = (level, message) => checks.push({ level, message });
|
|
30
|
+
const project = detectProject();
|
|
31
|
+
add("ok", `project "${project.name}" \xB7 ${project.framework} \xB7 ${project.packageManager}`);
|
|
32
|
+
await versionChecks(project.root, add);
|
|
33
|
+
if (!project.configFile) {
|
|
34
|
+
add("error", "splithub.config.ts not found. Run `npx splithub init`.");
|
|
35
|
+
return report(checks, flags);
|
|
36
|
+
}
|
|
37
|
+
add("ok", `config: ${relative(project.root, project.configFile)}`);
|
|
38
|
+
let config;
|
|
39
|
+
try {
|
|
40
|
+
config = await loadConfig(project.configFile);
|
|
41
|
+
add("ok", `config loads \xB7 ${config.experiments.length} experiment(s) \xB7 storage ${config.storage.mode}`);
|
|
42
|
+
} catch (error) {
|
|
43
|
+
add("error", `config does not load: ${error instanceof Error ? error.message : String(error)}`);
|
|
44
|
+
return report(checks, flags);
|
|
45
|
+
}
|
|
46
|
+
const files = listSourceFiles(project.root);
|
|
47
|
+
const providerHits = grepFiles(files, "SplitHubProvider").concat(grepFiles(files, "SplitHubNextProvider"));
|
|
48
|
+
if (providerHits.length === 0) add("error", "no <SplitHubProvider> found in source. Wrap your app once.");
|
|
49
|
+
else add("ok", `provider in ${relative(project.root, providerHits[0])}`);
|
|
50
|
+
if (project.framework === "next") {
|
|
51
|
+
const mw = ["middleware.ts", "src/middleware.ts", "middleware.js", "src/middleware.js"].map((f) => join(project.root, f)).find((f) => existsSync(f));
|
|
52
|
+
const hasRedirects = config.experiments.some((e) => e.kind === "redirect");
|
|
53
|
+
if (!mw) add(hasRedirects ? "error" : "warn", "no middleware.ts: visitor cookie is not set on the server (SSR may flicker)" + (hasRedirects ? "; redirect experiments will not run" : ""));
|
|
54
|
+
else if (!readFileSync(mw, "utf8").includes("splithubMiddleware")) add("warn", `${relative(project.root, mw)} does not call splithubMiddleware()`);
|
|
55
|
+
else add("ok", `middleware: ${relative(project.root, mw)}`);
|
|
56
|
+
if (config.storage.mode === "self" && project.appDir) {
|
|
57
|
+
const catchAll = join(project.root, project.appDir, "api/splithub/[[...path]]/route.ts");
|
|
58
|
+
const plain = join(project.root, project.appDir, "api/splithub/route.ts");
|
|
59
|
+
if (existsSync(catchAll)) add("ok", `ingest route: ${relative(project.root, catchAll)}`);
|
|
60
|
+
else if (existsSync(plain)) add("error", `${relative(project.root, plain)} only serves POST /api/splithub; move it to api/splithub/[[...path]]/route.ts so /status and /results work`);
|
|
61
|
+
else add("error", `self mode but ${relative(project.root, catchAll)} is missing (ingest endpoint)`);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
for (const exp of config.experiments) {
|
|
65
|
+
const label = `${exp.key} (${exp.kind}, ${exp.status})`;
|
|
66
|
+
if (!exp.goal) add(exp.status === "running" ? "error" : "warn", `${label}: no goal; the verdict cannot be computed`);
|
|
67
|
+
if (exp.kind !== "redirect") {
|
|
68
|
+
const used = findRefs(project.root, config, exp.key, files).refs.filter((r) => r.match === "experiment").length;
|
|
69
|
+
if (used === 0) add(exp.status === "running" ? "error" : "warn", `${label}: not referenced in code (useValue/useVariant/<Experiment id>)`);
|
|
70
|
+
}
|
|
71
|
+
if (exp.status === "running" && exp.variants.every((v) => v.weight === 0)) add("error", `${label}: all weights are 0`);
|
|
72
|
+
}
|
|
73
|
+
for (const goal of config.goals) {
|
|
74
|
+
if (goal.type === "event" && grepFiles(files, `'${goal.key}'`).length + grepFiles(files, `"${goal.key}"`).length === 0) {
|
|
75
|
+
add("warn", `goal "${goal.key}": track('${goal.key}') is never called`);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
const target = resolveTarget(flags, project);
|
|
79
|
+
try {
|
|
80
|
+
const ctrl = new AbortController();
|
|
81
|
+
const t = setTimeout(() => ctrl.abort(), 2500);
|
|
82
|
+
const res = await fetch(`${target.url}/health`, { signal: ctrl.signal });
|
|
83
|
+
clearTimeout(t);
|
|
84
|
+
add(res.ok ? "ok" : "warn", `endpoint ${target.url}/health \u2192 ${res.status}`);
|
|
85
|
+
} catch {
|
|
86
|
+
add("warn", `endpoint ${target.url} not reachable (is the dev server running?)`);
|
|
87
|
+
}
|
|
88
|
+
return report(checks, flags);
|
|
89
|
+
}
|
|
90
|
+
async function versionChecks(root, add) {
|
|
91
|
+
const v = await versionReport(root);
|
|
92
|
+
const list = v.rows.map((r) => `${r.name} ${r.installed ?? "not installed"}`).join(", ");
|
|
93
|
+
if (v.mismatch) add("warn", `versions differ: ${list}. Update them together: ${v.command}`);
|
|
94
|
+
else add("ok", `versions: ${list}`);
|
|
95
|
+
if (v.offline) add("warn", "couldn't reach npm, so the latest versions weren't checked");
|
|
96
|
+
else if (v.outdated.length) {
|
|
97
|
+
const what = v.rows.filter((r) => v.outdated.includes(r.name)).map((r) => `${r.name} ${r.installed} \u2192 ${r.latest}`).join(", ");
|
|
98
|
+
add("warn", `updates available: ${what}` + (v.mismatch ? "" : `. Run ${v.command}`));
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
function report(checks, flags) {
|
|
102
|
+
const errors = checks.filter((x) => x.level === "error").length;
|
|
103
|
+
if (flags.json) {
|
|
104
|
+
printJson({ ok: errors === 0, errors, warnings: checks.filter((x) => x.level === "warn").length, checks });
|
|
105
|
+
} else {
|
|
106
|
+
for (const x of checks) {
|
|
107
|
+
const icon = x.level === "ok" ? c.green("\u2714") : x.level === "warn" ? c.yellow("!") : c.red("\u2716");
|
|
108
|
+
console.log(`${icon} ${x.message}`);
|
|
109
|
+
}
|
|
110
|
+
console.log();
|
|
111
|
+
console.log(errors === 0 ? c.green("All good.") : c.red(`${errors} problem(s) to fix.`));
|
|
112
|
+
}
|
|
113
|
+
if (errors > 0) process.exitCode = 1;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
export {
|
|
117
|
+
doctor
|
|
118
|
+
};
|
|
119
|
+
//# sourceMappingURL=chunk-LT4JP3IF.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/commands/doctor.ts"],"sourcesContent":["import { existsSync, readFileSync } from 'node:fs';\nimport { join, relative } from 'node:path';\nimport { resolveTarget } from '../api';\nimport { loadConfig } from '../config-file';\nimport { printJson } from '../errors';\nimport { detectProject, grepFiles, listSourceFiles } from '../project';\nimport { findRefs } from '../refs';\nimport { c } from '../ui';\nimport { versionReport } from '../update';\nimport type { Flags } from './init';\n\ntype Level = 'ok' | 'warn' | 'error';\ninterface Check {\n level: Level;\n message: string;\n}\n\nexport async function doctor(flags: Flags): Promise<void> {\n const checks: Check[] = [];\n const add = (level: Level, message: string) => checks.push({ level, message });\n const project = detectProject();\n\n add('ok', `project \"${project.name}\" · ${project.framework} · ${project.packageManager}`);\n await versionChecks(project.root, add);\n\n if (!project.configFile) {\n add('error', 'splithub.config.ts not found. Run `npx splithub init`.');\n return report(checks, flags);\n }\n add('ok', `config: ${relative(project.root, project.configFile)}`);\n\n let config;\n try {\n config = await loadConfig(project.configFile);\n add('ok', `config loads · ${config.experiments.length} experiment(s) · storage ${config.storage.mode}`);\n } catch (error) {\n add('error', `config does not load: ${error instanceof Error ? error.message : String(error)}`);\n return report(checks, flags);\n }\n\n const files = listSourceFiles(project.root);\n const providerHits = grepFiles(files, 'SplitHubProvider').concat(grepFiles(files, 'SplitHubNextProvider'));\n if (providerHits.length === 0) add('error', 'no <SplitHubProvider> found in source. Wrap your app once.');\n else add('ok', `provider in ${relative(project.root, providerHits[0]!)}`);\n\n if (project.framework === 'next') {\n const mw = ['middleware.ts', 'src/middleware.ts', 'middleware.js', 'src/middleware.js'].map((f) => join(project.root, f)).find((f) => existsSync(f));\n const hasRedirects = config.experiments.some((e) => e.kind === 'redirect');\n if (!mw) add(hasRedirects ? 'error' : 'warn', 'no middleware.ts: visitor cookie is not set on the server (SSR may flicker)' + (hasRedirects ? '; redirect experiments will not run' : ''));\n else if (!readFileSync(mw, 'utf8').includes('splithubMiddleware')) add('warn', `${relative(project.root, mw)} does not call splithubMiddleware()`);\n else add('ok', `middleware: ${relative(project.root, mw)}`);\n if (config.storage.mode === 'self' && project.appDir) {\n const catchAll = join(project.root, project.appDir, 'api/splithub/[[...path]]/route.ts');\n const plain = join(project.root, project.appDir, 'api/splithub/route.ts');\n if (existsSync(catchAll)) add('ok', `ingest route: ${relative(project.root, catchAll)}`);\n else if (existsSync(plain)) add('error', `${relative(project.root, plain)} only serves POST /api/splithub; move it to api/splithub/[[...path]]/route.ts so /status and /results work`);\n else add('error', `self mode but ${relative(project.root, catchAll)} is missing (ingest endpoint)`);\n }\n }\n\n for (const exp of config.experiments) {\n const label = `${exp.key} (${exp.kind}, ${exp.status})`;\n if (!exp.goal) add(exp.status === 'running' ? 'error' : 'warn', `${label}: no goal; the verdict cannot be computed`);\n if (exp.kind !== 'redirect') {\n const used = findRefs(project.root, config, exp.key, files).refs.filter((r) => r.match === 'experiment').length;\n if (used === 0) add(exp.status === 'running' ? 'error' : 'warn', `${label}: not referenced in code (useValue/useVariant/<Experiment id>)`);\n }\n if (exp.status === 'running' && exp.variants.every((v) => v.weight === 0)) add('error', `${label}: all weights are 0`);\n }\n for (const goal of config.goals) {\n if (goal.type === 'event' && grepFiles(files, `'${goal.key}'`).length + grepFiles(files, `\"${goal.key}\"`).length === 0) {\n add('warn', `goal \"${goal.key}\": track('${goal.key}') is never called`);\n }\n }\n\n const target = resolveTarget(flags, project);\n try {\n const ctrl = new AbortController();\n const t = setTimeout(() => ctrl.abort(), 2500);\n const res = await fetch(`${target.url}/health`, { signal: ctrl.signal });\n clearTimeout(t);\n add(res.ok ? 'ok' : 'warn', `endpoint ${target.url}/health → ${res.status}`);\n } catch {\n add('warn', `endpoint ${target.url} not reachable (is the dev server running?)`);\n }\n\n return report(checks, flags);\n}\n\nasync function versionChecks(root: string, add: (level: Level, message: string) => void): Promise<void> {\n const v = await versionReport(root);\n const list = v.rows.map((r) => `${r.name} ${r.installed ?? 'not installed'}`).join(', ');\n if (v.mismatch) add('warn', `versions differ: ${list}. Update them together: ${v.command}`);\n else add('ok', `versions: ${list}`);\n if (v.offline) add('warn', \"couldn't reach npm, so the latest versions weren't checked\");\n else if (v.outdated.length) {\n const what = v.rows.filter((r) => v.outdated.includes(r.name)).map((r) => `${r.name} ${r.installed} → ${r.latest}`).join(', ');\n add('warn', `updates available: ${what}` + (v.mismatch ? '' : `. Run ${v.command}`));\n }\n}\n\nfunction report(checks: Check[], flags: Flags): void {\n const errors = checks.filter((x) => x.level === 'error').length;\n if (flags.json) {\n printJson({ ok: errors === 0, errors, warnings: checks.filter((x) => x.level === 'warn').length, checks });\n } else {\n for (const x of checks) {\n const icon = x.level === 'ok' ? c.green('✔') : x.level === 'warn' ? c.yellow('!') : c.red('✖');\n console.log(`${icon} ${x.message}`);\n }\n console.log();\n console.log(errors === 0 ? c.green('All good.') : c.red(`${errors} problem(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";
|
|
12
|
+
|
|
13
|
+
// src/commands/dev.ts
|
|
14
|
+
import { spawn } from "child_process";
|
|
15
|
+
function openBrowser(url) {
|
|
16
|
+
const [cmd, args] = process.platform === "win32" ? ["cmd", ["/c", "start", "", url]] : process.platform === "darwin" ? ["open", [url]] : ["xdg-open", [url]];
|
|
17
|
+
try {
|
|
18
|
+
spawn(cmd, args, { stdio: "ignore", detached: true }).unref();
|
|
19
|
+
} catch {
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
async function dev(flags) {
|
|
23
|
+
const project = detectProject();
|
|
24
|
+
const port = project?.framework === "next" ? 3e3 : 5173;
|
|
25
|
+
const page = typeof flags.url === "string" && flags.url || `http://localhost:${port}/`;
|
|
26
|
+
const u = new URL(page);
|
|
27
|
+
u.searchParams.set("sh_debug", flags.hold ? "hold" : "1");
|
|
28
|
+
const link = u.toString();
|
|
29
|
+
console.log(`${c.bold("SplitHub dev mode")}
|
|
30
|
+
`);
|
|
31
|
+
console.log(` ${c.cyan(link)}
|
|
32
|
+
`);
|
|
33
|
+
console.log(c.dim(" In the browser: the console shows every assignment (variant + reason), exposure and goal; the panel"));
|
|
34
|
+
console.log(c.dim(" in the corner forces variants, starts a new visitor and can hold redirects. Add ?sh_debug=0 to stop.\n"));
|
|
35
|
+
if (!flags["no-open"]) openBrowser(link);
|
|
36
|
+
const target = resolveTarget(flags, project);
|
|
37
|
+
console.log(c.dim(` Watching ${target.url} every 5 s. Ctrl+C to stop.
|
|
38
|
+
`));
|
|
39
|
+
const seen = /* @__PURE__ */ new Map();
|
|
40
|
+
let first = true;
|
|
41
|
+
const poll = async () => {
|
|
42
|
+
let data;
|
|
43
|
+
try {
|
|
44
|
+
data = await fetchStatus(target);
|
|
45
|
+
} catch (e) {
|
|
46
|
+
if (first) console.log(c.yellow(` results endpoint not reachable yet (${e instanceof Error ? e.message : String(e)}); is the dev server running?`));
|
|
47
|
+
first = false;
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
const now = (/* @__PURE__ */ new Date()).toLocaleTimeString();
|
|
51
|
+
for (const e of data.experiments) {
|
|
52
|
+
const prev = seen.get(e.experiment);
|
|
53
|
+
if (!prev) console.log(` ${c.dim(now)} ${c.bold(e.experiment)} ${c.dim(e.status)} \xB7 ${e.visitors} visitors${e.headline ? ` \xB7 ${e.headline}` : ""}`);
|
|
54
|
+
else if (prev.visitors !== e.visitors || prev.headline !== (e.headline ?? null)) console.log(` ${c.dim(now)} ${c.bold(e.experiment)} ${c.green(`+${e.visitors - prev.visitors}`)} \u2192 ${e.visitors} visitors${e.headline ? ` \xB7 ${e.headline}` : ""}`);
|
|
55
|
+
seen.set(e.experiment, { visitors: e.visitors, headline: e.headline ?? null });
|
|
56
|
+
}
|
|
57
|
+
first = false;
|
|
58
|
+
};
|
|
59
|
+
await poll();
|
|
60
|
+
await new Promise((resolve) => {
|
|
61
|
+
const t = setInterval(() => void poll(), 5e3);
|
|
62
|
+
process.on("SIGINT", () => {
|
|
63
|
+
clearInterval(t);
|
|
64
|
+
resolve();
|
|
65
|
+
});
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export {
|
|
70
|
+
dev
|
|
71
|
+
};
|
|
72
|
+
//# sourceMappingURL=chunk-NMN5YGNP.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/commands/dev.ts"],"sourcesContent":["// splithub dev — test experiments locally with full visibility.\n//\n// splithub dev opens the app (localhost:3000 for Next.js, 5173 for Vite) with ?sh_debug=1\n// splithub dev --url http://… a different page\n// splithub dev --hold redirect experiments log the target instead of navigating\n// splithub dev --no-open only print the link and watch\n//\n// With ?sh_debug the SDK and the drop-in script log every decision (which\n// variant and why), every exposure and goal with its payload, and the remote\n// overrides they applied, in the browser console and in a floating panel that\n// can force a variant, start a new visitor or hold redirects. Meanwhile this\n// command polls `status` and prints new visitors / conversions as they land.\n\nimport { spawn } from 'node:child_process';\nimport { fetchStatus, resolveTarget } from '../api';\nimport { detectProject } from '../project';\nimport { c } from '../ui';\n\nfunction openBrowser(url: string): void {\n const [cmd, args] = process.platform === 'win32' ? ['cmd', ['/c', 'start', '', url]] : process.platform === 'darwin' ? ['open', [url]] : ['xdg-open', [url]];\n try {\n spawn(cmd, args, { stdio: 'ignore', detached: true }).unref();\n } catch {\n // no browser available: the link is printed anyway\n }\n}\n\nexport async function dev(flags: Record<string, unknown>): Promise<void> {\n const project = detectProject();\n const port = project?.framework === 'next' ? 3000 : 5173;\n const page = (typeof flags.url === 'string' && flags.url) || `http://localhost:${port}/`;\n const u = new URL(page);\n u.searchParams.set('sh_debug', flags.hold ? 'hold' : '1');\n const link = u.toString();\n\n console.log(`${c.bold('SplitHub dev mode')}\\n`);\n console.log(` ${c.cyan(link)}\\n`);\n console.log(c.dim(' In the browser: the console shows every assignment (variant + reason), exposure and goal; the panel'));\n console.log(c.dim(' in the corner forces variants, starts a new visitor and can hold redirects. Add ?sh_debug=0 to stop.\\n'));\n if (!flags['no-open']) openBrowser(link);\n\n const target = resolveTarget(flags, project);\n console.log(c.dim(` Watching ${target.url} every 5 s. Ctrl+C to stop.\\n`));\n const seen = new Map<string, { visitors: number; headline: string | null }>();\n let first = true;\n const poll = async () => {\n let data: Awaited<ReturnType<typeof fetchStatus>>;\n try {\n data = await fetchStatus(target);\n } catch (e) {\n if (first) console.log(c.yellow(` results endpoint not reachable yet (${e instanceof Error ? e.message : String(e)}); is the dev server running?`));\n first = false;\n return;\n }\n const now = new Date().toLocaleTimeString();\n for (const e of data.experiments) {\n const prev = seen.get(e.experiment);\n if (!prev) console.log(` ${c.dim(now)} ${c.bold(e.experiment)} ${c.dim(e.status)} · ${e.visitors} visitors${e.headline ? ` · ${e.headline}` : ''}`);\n else if (prev.visitors !== e.visitors || prev.headline !== (e.headline ?? null)) console.log(` ${c.dim(now)} ${c.bold(e.experiment)} ${c.green(`+${e.visitors - prev.visitors}`)} → ${e.visitors} visitors${e.headline ? ` · ${e.headline}` : ''}`);\n seen.set(e.experiment, { visitors: e.visitors, headline: e.headline ?? null });\n }\n first = false;\n };\n await poll();\n await new Promise<void>((resolve) => {\n const t = setInterval(() => void poll(), 5000);\n process.on('SIGINT', () => {\n clearInterval(t);\n resolve();\n });\n });\n}\n"],"mappings":";;;;;;;;;;;;;AAaA,SAAS,aAAa;AAKtB,SAAS,YAAY,KAAmB;AACtC,QAAM,CAAC,KAAK,IAAI,IAAI,QAAQ,aAAa,UAAU,CAAC,OAAO,CAAC,MAAM,SAAS,IAAI,GAAG,CAAC,IAAI,QAAQ,aAAa,WAAW,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC;AAC3J,MAAI;AACF,UAAM,KAAK,MAAM,EAAE,OAAO,UAAU,UAAU,KAAK,CAAC,EAAE,MAAM;AAAA,EAC9D,QAAQ;AAAA,EAER;AACF;AAEA,eAAsB,IAAI,OAA+C;AACvE,QAAM,UAAU,cAAc;AAC9B,QAAM,OAAO,SAAS,cAAc,SAAS,MAAO;AACpD,QAAM,OAAQ,OAAO,MAAM,QAAQ,YAAY,MAAM,OAAQ,oBAAoB,IAAI;AACrF,QAAM,IAAI,IAAI,IAAI,IAAI;AACtB,IAAE,aAAa,IAAI,YAAY,MAAM,OAAO,SAAS,GAAG;AACxD,QAAM,OAAO,EAAE,SAAS;AAExB,UAAQ,IAAI,GAAG,EAAE,KAAK,mBAAmB,CAAC;AAAA,CAAI;AAC9C,UAAQ,IAAI,KAAK,EAAE,KAAK,IAAI,CAAC;AAAA,CAAI;AACjC,UAAQ,IAAI,EAAE,IAAI,uGAAuG,CAAC;AAC1H,UAAQ,IAAI,EAAE,IAAI,0GAA0G,CAAC;AAC7H,MAAI,CAAC,MAAM,SAAS,EAAG,aAAY,IAAI;AAEvC,QAAM,SAAS,cAAc,OAAO,OAAO;AAC3C,UAAQ,IAAI,EAAE,IAAI,cAAc,OAAO,GAAG;AAAA,CAA+B,CAAC;AAC1E,QAAM,OAAO,oBAAI,IAA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,264 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import {
|
|
3
|
+
c
|
|
4
|
+
} from "./chunk-V3DLUVOE.js";
|
|
5
|
+
|
|
6
|
+
// src/update.ts
|
|
7
|
+
import { execSync, spawn } from "child_process";
|
|
8
|
+
import { existsSync, readFileSync, realpathSync } from "fs";
|
|
9
|
+
import { createRequire } from "module";
|
|
10
|
+
import { dirname, join, resolve } from "path";
|
|
11
|
+
var REGISTRY = "https://registry.npmjs.org";
|
|
12
|
+
var CHECK_TIMEOUT_MS = 1500;
|
|
13
|
+
function currentVersion() {
|
|
14
|
+
return createRequire(import.meta.url)("../package.json").version;
|
|
15
|
+
}
|
|
16
|
+
function parse(v) {
|
|
17
|
+
const m = /^v?(\d+)\.(\d+)\.(\d+)(?:-([0-9A-Za-z.-]+))?(?:\+.*)?$/.exec(v.trim());
|
|
18
|
+
if (!m) return null;
|
|
19
|
+
return { nums: [Number(m[1]), Number(m[2]), Number(m[3])], pre: m[4] ? m[4].split(".") : [] };
|
|
20
|
+
}
|
|
21
|
+
function compareSemver(a, b) {
|
|
22
|
+
const x = parse(a);
|
|
23
|
+
const y = parse(b);
|
|
24
|
+
if (!x || !y) return (x ? 1 : 0) - (y ? 1 : 0);
|
|
25
|
+
for (let i = 0; i < 3; i++) if (x.nums[i] !== y.nums[i]) return x.nums[i] - y.nums[i];
|
|
26
|
+
if (!x.pre.length || !y.pre.length) return (x.pre.length ? 0 : 1) - (y.pre.length ? 0 : 1);
|
|
27
|
+
for (let i = 0; i < Math.max(x.pre.length, y.pre.length); i++) {
|
|
28
|
+
const p = x.pre[i];
|
|
29
|
+
const q = y.pre[i];
|
|
30
|
+
if (p === void 0) return -1;
|
|
31
|
+
if (q === void 0) return 1;
|
|
32
|
+
if (p === q) continue;
|
|
33
|
+
const pn = /^\d+$/.test(p);
|
|
34
|
+
const qn = /^\d+$/.test(q);
|
|
35
|
+
if (pn && qn) return Number(p) - Number(q);
|
|
36
|
+
if (pn !== qn) return pn ? -1 : 1;
|
|
37
|
+
return p < q ? -1 : 1;
|
|
38
|
+
}
|
|
39
|
+
return 0;
|
|
40
|
+
}
|
|
41
|
+
function isNewer(latest, current) {
|
|
42
|
+
const l = parse(latest);
|
|
43
|
+
const cur = parse(current);
|
|
44
|
+
if (!l || !cur) return false;
|
|
45
|
+
if (l.pre.length && !cur.pre.length) return false;
|
|
46
|
+
return compareSemver(latest, current) > 0;
|
|
47
|
+
}
|
|
48
|
+
async function fetchLatest(name, opts = {}) {
|
|
49
|
+
const fetchImpl = opts.fetchImpl ?? fetch;
|
|
50
|
+
const signal = opts.signal ?? AbortSignal.timeout(opts.timeoutMs ?? CHECK_TIMEOUT_MS);
|
|
51
|
+
try {
|
|
52
|
+
const res = await fetchImpl(`${REGISTRY}/${name.replace("/", "%2f")}/latest`, { signal, headers: { accept: "application/json" } });
|
|
53
|
+
if (!res.ok) return null;
|
|
54
|
+
const body = await res.json();
|
|
55
|
+
return typeof body?.version === "string" && parse(body.version) ? body.version : null;
|
|
56
|
+
} catch {
|
|
57
|
+
return null;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
var CI_VARS = ["CI", "CONTINUOUS_INTEGRATION", "GITHUB_ACTIONS", "GITLAB_CI", "BUILDKITE", "CIRCLECI", "TRAVIS", "JENKINS_URL", "TEAMCITY_VERSION", "TF_BUILD", "BITBUCKET_BUILD_NUMBER", "CODEBUILD_BUILD_ID", "BUILD_NUMBER", "RUN_ID"];
|
|
61
|
+
function isCi(env) {
|
|
62
|
+
return CI_VARS.some((k) => {
|
|
63
|
+
const v = env[k];
|
|
64
|
+
return v !== void 0 && v !== "" && v !== "0" && v.toLowerCase() !== "false";
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
function shouldCheckForUpdates({ argv, env, stdinTTY, stdoutTTY }) {
|
|
68
|
+
if (!stdinTTY || !stdoutTTY) return false;
|
|
69
|
+
if (argv.includes("--json")) return false;
|
|
70
|
+
if (env.SPLITHUB_NO_UPDATE_CHECK === "1" || env.SPLITHUB_MCP === "1") return false;
|
|
71
|
+
if (isCi(env)) return false;
|
|
72
|
+
const command = argv.find((a) => !a.startsWith("-"));
|
|
73
|
+
return command !== "update" && command !== "dev";
|
|
74
|
+
}
|
|
75
|
+
var isOurs = (name) => name === "splithub" || name.startsWith("@splithub/");
|
|
76
|
+
function readPkg(file) {
|
|
77
|
+
try {
|
|
78
|
+
return JSON.parse(readFileSync(file, "utf8"));
|
|
79
|
+
} catch {
|
|
80
|
+
return null;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
function findProjectRoot(cwd) {
|
|
84
|
+
let dir = resolve(cwd);
|
|
85
|
+
for (; ; ) {
|
|
86
|
+
if (existsSync(join(dir, "package.json"))) return dir;
|
|
87
|
+
const up = dirname(dir);
|
|
88
|
+
if (up === dir) return null;
|
|
89
|
+
dir = up;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
function detectPackageManager(root) {
|
|
93
|
+
let dir = resolve(root);
|
|
94
|
+
for (; ; ) {
|
|
95
|
+
const has = (f) => existsSync(join(dir, f));
|
|
96
|
+
if (has("pnpm-lock.yaml")) return "pnpm";
|
|
97
|
+
if (has("yarn.lock")) return "yarn";
|
|
98
|
+
if (has("bun.lockb") || has("bun.lock")) return "bun";
|
|
99
|
+
if (has("package-lock.json")) return "npm";
|
|
100
|
+
const up = dirname(dir);
|
|
101
|
+
if (up === dir) return "npm";
|
|
102
|
+
dir = up;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
function projectPackages(root) {
|
|
106
|
+
const pkg = readPkg(join(root, "package.json"));
|
|
107
|
+
if (!pkg) return [];
|
|
108
|
+
const prod = Object.keys(pkg.dependencies ?? {}).filter(isOurs).map((name) => ({ name, dev: false }));
|
|
109
|
+
const dev = Object.keys(pkg.devDependencies ?? {}).filter((n) => isOurs(n) && !prod.some((p) => p.name === n)).map((name) => ({ name, dev: true }));
|
|
110
|
+
return [...prod, ...dev];
|
|
111
|
+
}
|
|
112
|
+
function npmGlobalPrefix() {
|
|
113
|
+
if (process.env.npm_config_prefix) return process.env.npm_config_prefix;
|
|
114
|
+
try {
|
|
115
|
+
return execSync("npm prefix -g", { encoding: "utf8", stdio: ["ignore", "pipe", "ignore"], timeout: 3e3 }).trim() || null;
|
|
116
|
+
} catch {
|
|
117
|
+
return null;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
var norm = (p) => p.replace(/[\\/]+/g, "/").toLowerCase();
|
|
121
|
+
function detectInstall({ scriptPath, cwd, globalPrefix = npmGlobalPrefix }) {
|
|
122
|
+
let real = scriptPath;
|
|
123
|
+
try {
|
|
124
|
+
real = realpathSync(scriptPath);
|
|
125
|
+
} catch {
|
|
126
|
+
}
|
|
127
|
+
const script = norm(real);
|
|
128
|
+
if (/\/_npx\//.test(script) || /\/dlx-[^/]*\//.test(script)) return { mode: "npx" };
|
|
129
|
+
const root = findProjectRoot(cwd);
|
|
130
|
+
const packages = root ? projectPackages(root) : [];
|
|
131
|
+
const local = root !== null && (() => {
|
|
132
|
+
let dir = root;
|
|
133
|
+
for (; ; ) {
|
|
134
|
+
if (script.startsWith(norm(join(dir, "node_modules")) + "/")) return true;
|
|
135
|
+
const up = dirname(dir);
|
|
136
|
+
if (up === dir) return false;
|
|
137
|
+
dir = up;
|
|
138
|
+
}
|
|
139
|
+
})();
|
|
140
|
+
if (root && local && packages.length) return { mode: "project", root, pm: detectPackageManager(root), packages };
|
|
141
|
+
const prefix = globalPrefix();
|
|
142
|
+
if (prefix) {
|
|
143
|
+
const p = norm(prefix);
|
|
144
|
+
if (script.startsWith(`${p}/lib/node_modules/`) || script.startsWith(`${p}/node_modules/`)) return { mode: "global" };
|
|
145
|
+
}
|
|
146
|
+
if (root && packages.length) return { mode: "project", root, pm: detectPackageManager(root), packages };
|
|
147
|
+
return { mode: "unknown" };
|
|
148
|
+
}
|
|
149
|
+
var commandText = (x) => [x.cmd, ...x.args].join(" ");
|
|
150
|
+
function buildUpdateCommands(install) {
|
|
151
|
+
if (install.mode === "npx") return [];
|
|
152
|
+
if (install.mode !== "project") return [{ cmd: "npm", args: ["install", "-g", "splithub@latest"] }];
|
|
153
|
+
const list = install.packages.some((p) => p.name === "splithub") ? install.packages : [...install.packages, { name: "splithub", dev: true }];
|
|
154
|
+
const add = { pnpm: ["add"], yarn: ["add"], bun: ["add"], npm: ["install"] }[install.pm];
|
|
155
|
+
const devFlag = { pnpm: "-D", yarn: "--dev", bun: "--dev", npm: "-D" }[install.pm];
|
|
156
|
+
const out = [];
|
|
157
|
+
for (const dev of [false, true]) {
|
|
158
|
+
const names = list.filter((p) => p.dev === dev).map((p) => `${p.name}@latest`);
|
|
159
|
+
if (names.length) out.push({ cmd: install.pm, args: [...add, ...dev ? [devFlag] : [], ...names], cwd: install.root });
|
|
160
|
+
}
|
|
161
|
+
return out;
|
|
162
|
+
}
|
|
163
|
+
function run(x) {
|
|
164
|
+
return new Promise((done) => {
|
|
165
|
+
const child = spawn(x.cmd, x.args, { cwd: x.cwd, stdio: "inherit", shell: process.platform === "win32" });
|
|
166
|
+
child.on("error", () => done(false));
|
|
167
|
+
child.on("exit", (code) => done(code === 0));
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
function startUpdateCheck(input, fetchImpl) {
|
|
171
|
+
if (!shouldCheckForUpdates(input)) return null;
|
|
172
|
+
const ctrl = new AbortController();
|
|
173
|
+
const timer = setTimeout(() => ctrl.abort(), CHECK_TIMEOUT_MS);
|
|
174
|
+
timer.unref?.();
|
|
175
|
+
let latest;
|
|
176
|
+
void fetchLatest("splithub", { signal: ctrl.signal, ...fetchImpl ? { fetchImpl } : {} }).then((v) => {
|
|
177
|
+
latest = v;
|
|
178
|
+
});
|
|
179
|
+
return {
|
|
180
|
+
settled: () => latest,
|
|
181
|
+
stop: () => {
|
|
182
|
+
clearTimeout(timer);
|
|
183
|
+
ctrl.abort();
|
|
184
|
+
}
|
|
185
|
+
};
|
|
186
|
+
}
|
|
187
|
+
async function offerUpdateAfterCommand(check) {
|
|
188
|
+
if (!check) return;
|
|
189
|
+
const latest = check.settled();
|
|
190
|
+
check.stop();
|
|
191
|
+
const current = currentVersion();
|
|
192
|
+
if (!latest || !isNewer(latest, current)) return;
|
|
193
|
+
try {
|
|
194
|
+
console.log();
|
|
195
|
+
await updateFlow({ current, latest, yes: false, install: detectInstall({ scriptPath: process.argv[1] ?? "", cwd: process.cwd() }) });
|
|
196
|
+
} catch {
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
async function updateFlow({ current, latest, yes, install }) {
|
|
200
|
+
const news = `splithub ${latest} is out (you have ${current}).`;
|
|
201
|
+
if (install.mode === "npx") {
|
|
202
|
+
console.log(`${c.cyan(news)} Run npx splithub@latest next time to get it.`);
|
|
203
|
+
return;
|
|
204
|
+
}
|
|
205
|
+
const commands = buildUpdateCommands(install);
|
|
206
|
+
const text = commands.map(commandText).join(" && ");
|
|
207
|
+
if (!yes) {
|
|
208
|
+
if (!process.stdin.isTTY || !process.stdout.isTTY) {
|
|
209
|
+
console.log(`${news} Update with: ${text}`);
|
|
210
|
+
return;
|
|
211
|
+
}
|
|
212
|
+
const p = await import("@clack/prompts");
|
|
213
|
+
const go = await p.confirm({ message: `${news} Update now?`, initialValue: true });
|
|
214
|
+
if (p.isCancel(go) || !go) return;
|
|
215
|
+
}
|
|
216
|
+
for (const x of commands) {
|
|
217
|
+
console.log(c.dim(`$ ${commandText(x)}`));
|
|
218
|
+
if (!await run(x)) {
|
|
219
|
+
console.log(c.red("The update didn't finish."), `Run it by hand: ${text}`);
|
|
220
|
+
process.exitCode = 1;
|
|
221
|
+
return;
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
console.log(c.green(`Updated to splithub ${latest}.`));
|
|
225
|
+
}
|
|
226
|
+
function installedVersion(root, name) {
|
|
227
|
+
let dir = resolve(root);
|
|
228
|
+
for (; ; ) {
|
|
229
|
+
const pkg = readPkg(join(dir, "node_modules", ...name.split("/"), "package.json"));
|
|
230
|
+
if (pkg?.version) return pkg.version;
|
|
231
|
+
const up = dirname(dir);
|
|
232
|
+
if (up === dir) return null;
|
|
233
|
+
dir = up;
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
async function versionReport(root, opts = {}) {
|
|
237
|
+
const listed = projectPackages(root);
|
|
238
|
+
const names = listed.map((p) => p.name);
|
|
239
|
+
if (!names.includes("splithub")) names.push("splithub");
|
|
240
|
+
const latest = await Promise.all(names.map((n) => fetchLatest(n, { timeoutMs: opts.timeoutMs ?? 2500, ...opts.fetchImpl ? { fetchImpl: opts.fetchImpl } : {} })));
|
|
241
|
+
const cli = opts.cliVersion ?? currentVersion();
|
|
242
|
+
const rows = names.map((name, i) => ({ name, installed: installedVersion(root, name) ?? (name === "splithub" ? cli : null), latest: latest[i] ?? null }));
|
|
243
|
+
const offline = latest.every((v) => v === null);
|
|
244
|
+
const installed = new Set(rows.map((r) => r.installed).filter((v) => v !== null));
|
|
245
|
+
const outdated = rows.filter((r) => r.installed && r.latest && isNewer(r.latest, r.installed)).map((r) => r.name);
|
|
246
|
+
const install = listed.length ? { mode: "project", root, pm: detectPackageManager(root), packages: listed } : { mode: "global" };
|
|
247
|
+
const mismatch = installed.size > 1;
|
|
248
|
+
const command = mismatch || outdated.length ? buildUpdateCommands(install).map(commandText).join(" && ") : null;
|
|
249
|
+
return { rows, offline, mismatch, outdated, command };
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
export {
|
|
253
|
+
currentVersion,
|
|
254
|
+
isNewer,
|
|
255
|
+
fetchLatest,
|
|
256
|
+
detectInstall,
|
|
257
|
+
commandText,
|
|
258
|
+
buildUpdateCommands,
|
|
259
|
+
startUpdateCheck,
|
|
260
|
+
offerUpdateAfterCommand,
|
|
261
|
+
updateFlow,
|
|
262
|
+
versionReport
|
|
263
|
+
};
|
|
264
|
+
//# sourceMappingURL=chunk-OHA2M7QR.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/update.ts"],"sourcesContent":["// Update check and self-update. One GET to the npm registry per run, started at\n// startup in parallel with the command; the answer is used only if it arrived\n// before the command finished, so a slow network never delays anything. Nothing\n// is written to disk.\nimport { execSync, spawn } from 'node:child_process';\nimport { existsSync, readFileSync, realpathSync } from 'node:fs';\nimport { createRequire } from 'node:module';\nimport { dirname, join, resolve, sep } from 'node:path';\nimport { c } from './ui';\n\nexport const REGISTRY = 'https://registry.npmjs.org';\nconst CHECK_TIMEOUT_MS = 1500;\n\ntype FetchLike = (url: string, init?: { signal?: AbortSignal; headers?: Record<string, string> }) => Promise<{ ok: boolean; json(): Promise<unknown> }>;\n\nexport function currentVersion(): string {\n // From src/ and from dist/ alike, ../package.json is the CLI's own.\n return (createRequire(import.meta.url)('../package.json') as { version: string }).version;\n}\n\n// ---------- semver ----------\n\ninterface Semver {\n nums: [number, number, number];\n pre: string[];\n}\n\nfunction parse(v: string): Semver | null {\n const m = /^v?(\\d+)\\.(\\d+)\\.(\\d+)(?:-([0-9A-Za-z.-]+))?(?:\\+.*)?$/.exec(v.trim());\n if (!m) return null;\n return { nums: [Number(m[1]), Number(m[2]), Number(m[3])], pre: m[4] ? m[4].split('.') : [] };\n}\n\n/** Negative when a < b, 0 when equal, positive when a > b (semver precedence). Unparseable sorts lowest. */\nexport function compareSemver(a: string, b: string): number {\n const x = parse(a);\n const y = parse(b);\n if (!x || !y) return (x ? 1 : 0) - (y ? 1 : 0);\n for (let i = 0; i < 3; i++) if (x.nums[i] !== y.nums[i]) return x.nums[i]! - y.nums[i]!;\n if (!x.pre.length || !y.pre.length) return (x.pre.length ? 0 : 1) - (y.pre.length ? 0 : 1);\n for (let i = 0; i < Math.max(x.pre.length, y.pre.length); i++) {\n const p = x.pre[i];\n const q = y.pre[i];\n if (p === undefined) return -1;\n if (q === undefined) return 1;\n if (p === q) continue;\n const pn = /^\\d+$/.test(p);\n const qn = /^\\d+$/.test(q);\n if (pn && qn) return Number(p) - Number(q);\n if (pn !== qn) return pn ? -1 : 1;\n return p < q ? -1 : 1;\n }\n return 0;\n}\n\n/** Whether `latest` is worth offering: newer, and not a prerelease unless the user already runs one. */\nexport function isNewer(latest: string, current: string): boolean {\n const l = parse(latest);\n const cur = parse(current);\n if (!l || !cur) return false;\n if (l.pre.length && !cur.pre.length) return false;\n return compareSemver(latest, current) > 0;\n}\n\n// ---------- registry ----------\n\n/** The `latest` dist-tag of a package, or null on any error or timeout. */\nexport async function fetchLatest(name: string, opts: { signal?: AbortSignal; timeoutMs?: number; fetchImpl?: FetchLike } = {}): Promise<string | null> {\n const fetchImpl = opts.fetchImpl ?? (fetch as unknown as FetchLike);\n const signal = opts.signal ?? AbortSignal.timeout(opts.timeoutMs ?? CHECK_TIMEOUT_MS);\n try {\n const res = await fetchImpl(`${REGISTRY}/${name.replace('/', '%2f')}/latest`, { signal, headers: { accept: 'application/json' } });\n if (!res.ok) return null;\n const body = (await res.json()) as { version?: unknown } | null;\n return typeof body?.version === 'string' && parse(body.version) ? body.version : null;\n } catch {\n return null;\n }\n}\n\n// ---------- gating ----------\n\nconst CI_VARS = ['CI', 'CONTINUOUS_INTEGRATION', 'GITHUB_ACTIONS', 'GITLAB_CI', 'BUILDKITE', 'CIRCLECI', 'TRAVIS', 'JENKINS_URL', 'TEAMCITY_VERSION', 'TF_BUILD', 'BITBUCKET_BUILD_NUMBER', 'CODEBUILD_BUILD_ID', 'BUILD_NUMBER', 'RUN_ID'];\n\nexport function isCi(env: NodeJS.ProcessEnv): boolean {\n return CI_VARS.some((k) => {\n const v = env[k];\n return v !== undefined && v !== '' && v !== '0' && v.toLowerCase() !== 'false';\n });\n}\n\nexport interface GateInput {\n argv: string[];\n env: NodeJS.ProcessEnv;\n stdinTTY: boolean | undefined;\n stdoutTTY: boolean | undefined;\n}\n\n/** The automatic check runs only for a person at a terminal: never for agents, CI, the MCP server or pipes. */\nexport function shouldCheckForUpdates({ argv, env, stdinTTY, stdoutTTY }: GateInput): boolean {\n if (!stdinTTY || !stdoutTTY) return false;\n if (argv.includes('--json')) return false;\n if (env.SPLITHUB_NO_UPDATE_CHECK === '1' || env.SPLITHUB_MCP === '1') return false;\n if (isCi(env)) return false;\n // `update` checks on its own; `dev` never finishes, so there is no \"after\" to ask in.\n const command = argv.find((a) => !a.startsWith('-'));\n return command !== 'update' && command !== 'dev';\n}\n\n// ---------- install mode ----------\n\nexport type PackageManager = 'pnpm' | 'yarn' | 'bun' | 'npm';\n\nexport type InstallMode =\n | { mode: 'project'; root: string; pm: PackageManager; packages: { name: string; dev: boolean }[] }\n | { mode: 'global' }\n | { mode: 'npx' }\n | { mode: 'unknown' };\n\ninterface PackageJson {\n dependencies?: Record<string, string>;\n devDependencies?: Record<string, string>;\n}\n\nconst isOurs = (name: string) => name === 'splithub' || name.startsWith('@splithub/');\n\nfunction readPkg(file: string): PackageJson | null {\n try {\n return JSON.parse(readFileSync(file, 'utf8')) as PackageJson;\n } catch {\n return null;\n }\n}\n\n/** Nearest directory at or above `cwd` with a package.json. */\nexport function findProjectRoot(cwd: string): string | null {\n let dir = resolve(cwd);\n for (;;) {\n if (existsSync(join(dir, 'package.json'))) return dir;\n const up = dirname(dir);\n if (up === dir) return null;\n dir = up;\n }\n}\n\n/** Package manager from the nearest lockfile at or above `root` (workspaces keep it at the top). */\nexport function detectPackageManager(root: string): PackageManager {\n let dir = resolve(root);\n for (;;) {\n const has = (f: string) => existsSync(join(dir, f));\n if (has('pnpm-lock.yaml')) return 'pnpm';\n if (has('yarn.lock')) return 'yarn';\n if (has('bun.lockb') || has('bun.lock')) return 'bun';\n if (has('package-lock.json')) return 'npm';\n const up = dirname(dir);\n if (up === dir) return 'npm';\n dir = up;\n }\n}\n\n/** splithub and every @splithub/* package the project lists, with its section. */\nexport function projectPackages(root: string): { name: string; dev: boolean }[] {\n const pkg = readPkg(join(root, 'package.json'));\n if (!pkg) return [];\n const prod = Object.keys(pkg.dependencies ?? {}).filter(isOurs).map((name) => ({ name, dev: false }));\n const dev = Object.keys(pkg.devDependencies ?? {})\n .filter((n) => isOurs(n) && !prod.some((p) => p.name === n))\n .map((name) => ({ name, dev: true }));\n return [...prod, ...dev];\n}\n\nfunction npmGlobalPrefix(): string | null {\n if (process.env.npm_config_prefix) return process.env.npm_config_prefix;\n try {\n return execSync('npm prefix -g', { encoding: 'utf8', stdio: ['ignore', 'pipe', 'ignore'], timeout: 3000 }).trim() || null;\n } catch {\n return null;\n }\n}\n\nconst norm = (p: string) => p.replace(/[\\\\/]+/g, '/').toLowerCase();\n\nexport interface DetectInput {\n /** Path of the running CLI (process.argv[1]). */\n scriptPath: string;\n cwd: string;\n /** npm's global prefix; looked up lazily when omitted. */\n globalPrefix?: () => string | null;\n}\n\nexport function detectInstall({ scriptPath, cwd, globalPrefix = npmGlobalPrefix }: DetectInput): InstallMode {\n let real = scriptPath;\n try {\n real = realpathSync(scriptPath);\n } catch {\n // keep the path as given\n }\n const script = norm(real);\n if (/\\/_npx\\//.test(script) || /\\/dlx-[^/]*\\//.test(script)) return { mode: 'npx' };\n\n const root = findProjectRoot(cwd);\n const packages = root ? projectPackages(root) : [];\n // Running from node_modules of this project (or a workspace root above it).\n const local = root !== null && (() => {\n let dir = root;\n for (;;) {\n if (script.startsWith(norm(join(dir, 'node_modules')) + '/')) return true;\n const up = dirname(dir);\n if (up === dir) return false;\n dir = up;\n }\n })();\n if (root && local && packages.length) return { mode: 'project', root, pm: detectPackageManager(root), packages };\n\n const prefix = globalPrefix();\n if (prefix) {\n const p = norm(prefix);\n if (script.startsWith(`${p}/lib/node_modules/`) || script.startsWith(`${p}/node_modules/`)) return { mode: 'global' };\n }\n if (root && packages.length) return { mode: 'project', root, pm: detectPackageManager(root), packages };\n return { mode: 'unknown' };\n}\n\n// ---------- commands ----------\n\nexport interface Command {\n cmd: string;\n args: string[];\n cwd?: string;\n}\n\nexport const commandText = (x: Command): string => [x.cmd, ...x.args].join(' ');\n\n/** Commands that move this install to the latest release (empty for npx: nothing to install). */\nexport function buildUpdateCommands(install: InstallMode): Command[] {\n if (install.mode === 'npx') return [];\n if (install.mode !== 'project') return [{ cmd: 'npm', args: ['install', '-g', 'splithub@latest'] }];\n const list = install.packages.some((p) => p.name === 'splithub') ? install.packages : [...install.packages, { name: 'splithub', dev: true }];\n const add = { pnpm: ['add'], yarn: ['add'], bun: ['add'], npm: ['install'] }[install.pm];\n const devFlag = { pnpm: '-D', yarn: '--dev', bun: '--dev', npm: '-D' }[install.pm];\n const out: Command[] = [];\n for (const dev of [false, true]) {\n const names = list.filter((p) => p.dev === dev).map((p) => `${p.name}@latest`);\n if (names.length) out.push({ cmd: install.pm, args: [...add, ...(dev ? [devFlag] : []), ...names], cwd: install.root });\n }\n return out;\n}\n\nfunction run(x: Command): Promise<boolean> {\n return new Promise((done) => {\n // npm, pnpm and yarn are .cmd shims on Windows; the arguments are package names only.\n const child = spawn(x.cmd, x.args, { cwd: x.cwd, stdio: 'inherit', shell: process.platform === 'win32' });\n child.on('error', () => done(false));\n child.on('exit', (code) => done(code === 0));\n });\n}\n\n// ---------- flows ----------\n\n/** The update check started at launch: read its answer without waiting, then stop it. */\nexport interface StartedCheck {\n settled(): string | null | undefined;\n stop(): void;\n}\n\nexport function startUpdateCheck(input: GateInput, fetchImpl?: FetchLike): StartedCheck | null {\n if (!shouldCheckForUpdates(input)) return null;\n const ctrl = new AbortController();\n const timer = setTimeout(() => ctrl.abort(), CHECK_TIMEOUT_MS);\n timer.unref?.();\n let latest: string | null | undefined;\n void fetchLatest('splithub', { signal: ctrl.signal, ...(fetchImpl ? { fetchImpl } : {}) }).then((v) => {\n latest = v;\n });\n return {\n settled: () => latest,\n stop: () => {\n clearTimeout(timer);\n ctrl.abort();\n },\n };\n}\n\n/** After the command: if the registry answered in time with a newer version, offer it. */\nexport async function offerUpdateAfterCommand(check: StartedCheck | null): Promise<void> {\n if (!check) return;\n const latest = check.settled();\n check.stop();\n const current = currentVersion();\n if (!latest || !isNewer(latest, current)) return;\n try {\n console.log();\n await updateFlow({ current, latest, yes: false, install: detectInstall({ scriptPath: process.argv[1] ?? '', cwd: process.cwd() }) });\n } catch {\n // An update offer must never turn a finished command into a failure.\n }\n}\n\nexport async function updateFlow({ current, latest, yes, install }: { current: string; latest: string; yes: boolean; install: InstallMode }): Promise<void> {\n const news = `splithub ${latest} is out (you have ${current}).`;\n if (install.mode === 'npx') {\n console.log(`${c.cyan(news)} Run npx splithub@latest next time to get it.`);\n return;\n }\n const commands = buildUpdateCommands(install);\n const text = commands.map(commandText).join(' && ');\n if (!yes) {\n if (!process.stdin.isTTY || !process.stdout.isTTY) {\n console.log(`${news} Update with: ${text}`);\n return;\n }\n const p = await import('@clack/prompts');\n const go = await p.confirm({ message: `${news} Update now?`, initialValue: true });\n if (p.isCancel(go) || !go) return;\n }\n for (const x of commands) {\n console.log(c.dim(`$ ${commandText(x)}`));\n if (!(await run(x))) {\n console.log(c.red(\"The update didn't finish.\"), `Run it by hand: ${text}`);\n process.exitCode = 1;\n return;\n }\n }\n console.log(c.green(`Updated to splithub ${latest}.`));\n}\n\n// ---------- doctor ----------\n\n/** Installed version of a package, from the nearest node_modules at or above `root`. */\nexport function installedVersion(root: string, name: string): string | null {\n let dir = resolve(root);\n for (;;) {\n const pkg = readPkg(join(dir, 'node_modules', ...name.split('/'), 'package.json')) as { version?: string } | null;\n if (pkg?.version) return pkg.version;\n const up = dirname(dir);\n if (up === dir) return null;\n dir = up;\n }\n}\n\nexport interface VersionRow {\n name: string;\n installed: string | null;\n latest: string | null;\n}\n\nexport interface VersionReport {\n rows: VersionRow[];\n offline: boolean;\n /** Installed SDK packages and the CLI disagree. */\n mismatch: boolean;\n outdated: string[];\n command: string | null;\n}\n\n/** Versions of splithub and @splithub/* in the project vs npm, for `splithub doctor`. */\nexport async function versionReport(root: string, opts: { fetchImpl?: FetchLike; cliVersion?: string; timeoutMs?: number } = {}): Promise<VersionReport> {\n const listed = projectPackages(root);\n const names = listed.map((p) => p.name);\n if (!names.includes('splithub')) names.push('splithub');\n const latest = await Promise.all(names.map((n) => fetchLatest(n, { timeoutMs: opts.timeoutMs ?? 2500, ...(opts.fetchImpl ? { fetchImpl: opts.fetchImpl } : {}) })));\n const cli = opts.cliVersion ?? currentVersion();\n const rows = names.map((name, i) => ({ name, installed: installedVersion(root, name) ?? (name === 'splithub' ? cli : null), latest: latest[i] ?? null }));\n const offline = latest.every((v) => v === null);\n const installed = new Set(rows.map((r) => r.installed).filter((v): v is string => v !== null));\n const outdated = rows.filter((r) => r.installed && r.latest && isNewer(r.latest, r.installed)).map((r) => r.name);\n const install: InstallMode = listed.length ? { mode: 'project', root, pm: detectPackageManager(root), packages: listed } : { mode: 'global' };\n const mismatch = installed.size > 1;\n const command = mismatch || outdated.length ? buildUpdateCommands(install).map(commandText).join(' && ') : null;\n return { rows, offline, mismatch, outdated, command };\n}\n"],"mappings":";;;;;;AAIA,SAAS,UAAU,aAAa;AAChC,SAAS,YAAY,cAAc,oBAAoB;AACvD,SAAS,qBAAqB;AAC9B,SAAS,SAAS,MAAM,eAAoB;AAGrC,IAAM,WAAW;AACxB,IAAM,mBAAmB;AAIlB,SAAS,iBAAyB;AAEvC,SAAQ,cAAc,YAAY,GAAG,EAAE,iBAAiB,EAA0B;AACpF;AASA,SAAS,MAAM,GAA0B;AACvC,QAAM,IAAI,yDAAyD,KAAK,EAAE,KAAK,CAAC;AAChF,MAAI,CAAC,EAAG,QAAO;AACf,SAAO,EAAE,MAAM,CAAC,OAAO,EAAE,CAAC,CAAC,GAAG,OAAO,EAAE,CAAC,CAAC,GAAG,OAAO,EAAE,CAAC,CAAC,CAAC,GAAG,KAAK,EAAE,CAAC,IAAI,EAAE,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC,EAAE;AAC9F;AAGO,SAAS,cAAc,GAAW,GAAmB;AAC1D,QAAM,IAAI,MAAM,CAAC;AACjB,QAAM,IAAI,MAAM,CAAC;AACjB,MAAI,CAAC,KAAK,CAAC,EAAG,SAAQ,IAAI,IAAI,MAAM,IAAI,IAAI;AAC5C,WAAS,IAAI,GAAG,IAAI,GAAG,IAAK,KAA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AC,MAAM,OAAO,EAAE,MAAM,WAAW,iBAAiB,MAAM,IAAI,MAAM,SAAS,aAAa,MAAM,OAAO,QAAQ,OAAO,CAAC,KAAK,KAAK,EAAE;AACxJ,QAAM,UAAU,OAAO,MAAM,CAAC,MAAM,MAAM,IAAI;AAC9C,QAAM,YAAY,IAAI,IAAI,KAAK,IAAI,CAAC,MAAM,EAAE,SAAS,EAAE,OAAO,CAAC,MAAmB,MAAM,IAAI,CAAC;AAC7F,QAAM,WAAW,KAAK,OAAO,CAAC,MAAM,EAAE,aAAa,EAAE,UAAU,QAAQ,EAAE,QAAQ,EAAE,SAAS,CAAC,EAAE,IAAI,CAAC,MAAM,EAAE,IAAI;AAChH,QAAM,UAAuB,OAAO,SAAS,EAAE,MAAM,WAAW,MAAM,IAAI,qBAAqB,IAAI,GAAG,UAAU,OAAO,IAAI,EAAE,MAAM,SAAS;AAC5I,QAAM,WAAW,UAAU,OAAO;AAClC,QAAM,UAAU,YAAY,SAAS,SAAS,oBAAoB,OAAO,EAAE,IAAI,WAAW,EAAE,KAAK,MAAM,IAAI;AAC3G,SAAO,EAAE,MAAM,SAAS,UAAU,UAAU,QAAQ;AACtD;","names":[]}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import {
|
|
3
|
+
starText
|
|
4
|
+
} from "./chunk-DUIJ5DTV.js";
|
|
5
|
+
import {
|
|
6
|
+
fetchStatus,
|
|
7
|
+
resolveTarget
|
|
8
|
+
} from "./chunk-BJQJGLOB.js";
|
|
9
|
+
import {
|
|
10
|
+
detectProject
|
|
11
|
+
} from "./chunk-PLXDG4B5.js";
|
|
12
|
+
import {
|
|
13
|
+
bar,
|
|
14
|
+
c,
|
|
15
|
+
printJson,
|
|
16
|
+
statusColor,
|
|
17
|
+
table,
|
|
18
|
+
verdictColor,
|
|
19
|
+
verdictIcon
|
|
20
|
+
} from "./chunk-V3DLUVOE.js";
|
|
21
|
+
|
|
22
|
+
// src/commands/status.ts
|
|
23
|
+
async function status(flags) {
|
|
24
|
+
const target = resolveTarget(flags, detectProject());
|
|
25
|
+
const data = await fetchStatus(target);
|
|
26
|
+
const finished = data.experiments.filter((e) => e.status === "finished").map((e) => e.experiment);
|
|
27
|
+
const next = finished.length ? `Finished but still in the code: ${finished.join(", ")}. Decide which variant to keep, then run npx splithub ship <id> --keep <variant> (agents: the splithub-ship skill).` : null;
|
|
28
|
+
if (flags.json) {
|
|
29
|
+
printJson(next ? { ...data, next } : data);
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
console.log(`${c.bold("SplitHub")} ${c.dim("\xB7")} project ${c.cyan(data.project)} ${c.dim(`\xB7 ${target.url}`)}
|
|
33
|
+
`);
|
|
34
|
+
if (data.experiments.length === 0) {
|
|
35
|
+
console.log(c.dim("No experiments in splithub.config.ts yet. Run `splithub create`."));
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
const maxVisitors = Math.max(1, ...data.experiments.map((e) => e.visitors));
|
|
39
|
+
console.log(
|
|
40
|
+
table(
|
|
41
|
+
["EXPERIMENT", "KIND", "STATUS", "VISITORS", "", "DAYS", "VERDICT", "SAMPLE", "DATA", "NEXT CHECK"],
|
|
42
|
+
data.experiments.map((e) => [
|
|
43
|
+
e.experiment === "__holdout" ? c.bold("Holdout: long-term impact") : c.bold(e.experiment),
|
|
44
|
+
e.kind,
|
|
45
|
+
statusColor(e.status),
|
|
46
|
+
String(e.visitors),
|
|
47
|
+
bar(e.visitors, maxVisitors, 12, e.status === "running" ? c.green : c.dim),
|
|
48
|
+
e.days ? String(e.days) : "\u2013",
|
|
49
|
+
verdictColor(e.verdict, `${verdictIcon(e.goal ? e.verdict : null)} ${e.headline ?? (e.goal ? "no data" : "no goal")}`),
|
|
50
|
+
e.sample === "good" ? c.green("good") : e.sample === "ok" ? "ok" : e.sample === "small" ? c.dim("small") : "",
|
|
51
|
+
typeof e.stars === "number" ? c.yellow(starText(e.stars)) : "",
|
|
52
|
+
e.status === "running" && e.daysToVerdict && e.daysToVerdict > 0 ? c.dim(`in ~${Math.ceil(e.daysToVerdict)}d`) : ""
|
|
53
|
+
])
|
|
54
|
+
)
|
|
55
|
+
);
|
|
56
|
+
if (next) console.log(`
|
|
57
|
+
${c.dim(next)}`);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export {
|
|
61
|
+
status
|
|
62
|
+
};
|
|
63
|
+
//# sourceMappingURL=chunk-OYM64FMD.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/commands/status.ts"],"sourcesContent":["import { fetchStatus, resolveTarget } from '../api';\nimport { detectProject } from '../project';\nimport { printJson } from '../errors';\nimport { bar, c, statusColor, table, verdictColor, verdictIcon } from '../ui';\nimport { starText } from './results';\n\nexport async function status(flags: Record<string, unknown>): Promise<void> {\n const target = resolveTarget(flags, detectProject());\n const data = await fetchStatus(target);\n const finished = data.experiments.filter((e) => e.status === 'finished').map((e) => e.experiment);\n const next = finished.length ? `Finished but still in the code: ${finished.join(', ')}. Decide which variant to keep, then run npx splithub ship <id> --keep <variant> (agents: the splithub-ship skill).` : null;\n if (flags.json) {\n printJson(next ? { ...data, next } : data);\n return;\n }\n console.log(`${c.bold('SplitHub')} ${c.dim('·')} project ${c.cyan(data.project)} ${c.dim(`· ${target.url}`)}\\n`);\n if (data.experiments.length === 0) {\n console.log(c.dim('No experiments in splithub.config.ts yet. Run `splithub create`.'));\n return;\n }\n // Visitors as a bar relative to the busiest experiment, verdict with its icon.\n const maxVisitors = Math.max(1, ...data.experiments.map((e) => e.visitors));\n console.log(\n table(\n ['EXPERIMENT', 'KIND', 'STATUS', 'VISITORS', '', 'DAYS', 'VERDICT', 'SAMPLE', 'DATA', 'NEXT CHECK'],\n data.experiments.map((e) => [\n e.experiment === '__holdout' ? c.bold('Holdout: long-term impact') : c.bold(e.experiment),\n e.kind,\n statusColor(e.status),\n String(e.visitors),\n bar(e.visitors, maxVisitors, 12, e.status === 'running' ? c.green : c.dim),\n e.days ? String(e.days) : '–',\n verdictColor(e.verdict, `${verdictIcon(e.goal ? e.verdict : null)} ${e.headline ?? (e.goal ? 'no data' : 'no goal')}`),\n e.sample === 'good' ? c.green('good') : e.sample === 'ok' ? 'ok' : e.sample === 'small' ? c.dim('small') : '',\n typeof e.stars === 'number' ? c.yellow(starText(e.stars)) : '',\n e.status === 'running' && e.daysToVerdict && e.daysToVerdict > 0 ? c.dim(`in ~${Math.ceil(e.daysToVerdict)}d`) : '',\n ])\n )\n );\n if (next) console.log(`\\n${c.dim(next)}`);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAMA,eAAsB,OAAO,OAA+C;AAC1E,QAAM,SAAS,cAAc,OAAO,cAAc,CAAC;AACnD,QAAM,OAAO,MAAM,YAAY,MAAM;AACrC,QAAM,WAAW,KAAK,YAAY,OAAO,CAAC,MAAM,EAAE,WAAW,UAAU,EAAE,IAAI,CAAC,MAAM,EAAE,UAAU;AAChG,QAAM,OAAO,SAAS,SAAS,mCAAmC,SAAS,KAAK,IAAI,CAAC,wHAAwH;AAC7M,MAAI,MAAM,MAAM;AACd,cAAU,OAAO,EAAE,GAAG,MAAM,KAAK,IAAI,IAAI;AACzC;AAAA,EACF;AACA,UAAQ,IAAI,GAAG,EAAE,KAAK,UAAU,CAAC,IAAI,EAAE,IAAI,MAAG,CAAC,YAAY,EAAE,KAAK,KAAK,OAAO,CAAC,IAAI,EAAE,IAAI,QAAK,OAAO,GAAG,EAAE,CAAC;AAAA,CAAI;AAC/G,MAAI,KAAK,YAAY,WAAW,GAAG;AACjC,YAAQ,IAAI,EAAE,IAAI,kEAAkE,CAAC;AACrF;AAAA,EACF;AAEA,QAAM,cAAc,KAAK,IAAI,GAAG,GAAG,KAAK,YAAY,IAAI,CAAC,MAAM,EAAE,QAAQ,CAAC;AAC1E,UAAQ;AAAA,IACN;AAAA,MACE,CAAC,cAAc,QAAQ,UAAU,YAAY,IAAI,QAAQ,WAAW,UAAU,QAAQ,YAAY;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