@hewel/zgui-cli 0.0.0-stage → 0.1.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/LICENSE +202 -0
- package/NOTICE +95 -0
- package/README.md +25 -2
- package/THIRD_PARTY_NOTICES.md +37 -0
- package/inspector-bundle/app.css +138 -0
- package/inspector-bundle/app.mjs +7317 -0
- package/inspector-bundle/app.mjs.map +1 -0
- package/inspector-bundle/build-info.json +345 -0
- package/inspector-bundle/components.css +1546 -0
- package/inspector-bundle/manifest.json +31 -0
- package/package.json +60 -4
- package/src/cli.ts +488 -0
- package/src/doctor.ts +278 -0
- package/src/index.ts +17 -0
- package/src/init.ts +458 -0
- package/src/inspect.ts +160 -0
package/src/doctor.ts
ADDED
|
@@ -0,0 +1,278 @@
|
|
|
1
|
+
import { existsSync, readdirSync, readFileSync } from "node:fs";
|
|
2
|
+
import { createRequire } from "node:module";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { resolveNativeHost, type ResolvedNativeHost } from "@hewel/zgui-build";
|
|
5
|
+
import {
|
|
6
|
+
EXPECTED_HOST_API_VERSION,
|
|
7
|
+
EXPECTED_SCHEMA_VERSION,
|
|
8
|
+
platformHostPackageName,
|
|
9
|
+
platformId,
|
|
10
|
+
} from "@hewel/zgui-build/internal";
|
|
11
|
+
|
|
12
|
+
export type DoctorCheckStatus = "ok" | "warn" | "fail";
|
|
13
|
+
|
|
14
|
+
export interface DoctorCheck {
|
|
15
|
+
id: string;
|
|
16
|
+
label: string;
|
|
17
|
+
status: DoctorCheckStatus;
|
|
18
|
+
detail: string;
|
|
19
|
+
remediation?: string;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export interface DoctorReport {
|
|
23
|
+
schemaVersion: 1;
|
|
24
|
+
ok: boolean;
|
|
25
|
+
platform: string;
|
|
26
|
+
checks: DoctorCheck[];
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export interface DoctorOptions {
|
|
30
|
+
cwd?: string;
|
|
31
|
+
hostRoot?: string;
|
|
32
|
+
hostExecutable?: string;
|
|
33
|
+
env?: Record<string, string | undefined>;
|
|
34
|
+
searchFrom?: readonly string[];
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function compareSemver(a: string, b: string): number {
|
|
38
|
+
const pa = a.split(".").map(part => Number.parseInt(part, 10) || 0);
|
|
39
|
+
const pb = b.split(".").map(part => Number.parseInt(part, 10) || 0);
|
|
40
|
+
for (let i = 0; i < 3; i++) {
|
|
41
|
+
const diff = (pa[i] ?? 0) - (pb[i] ?? 0);
|
|
42
|
+
if (diff !== 0) return diff;
|
|
43
|
+
}
|
|
44
|
+
return 0;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function resolveToolVersion(pkgName: string, searchBases: readonly string[]): string | undefined {
|
|
48
|
+
for (const base of searchBases) {
|
|
49
|
+
try {
|
|
50
|
+
const anchor = existsSync(path.join(base, "package.json"))
|
|
51
|
+
? path.join(base, "package.json")
|
|
52
|
+
: base;
|
|
53
|
+
const req = createRequire(anchor);
|
|
54
|
+
const manifestPath = req.resolve(`${pkgName}/package.json`);
|
|
55
|
+
const parsed = JSON.parse(readFileSync(manifestPath, "utf8")) as { version?: unknown };
|
|
56
|
+
if (typeof parsed.version === "string") return parsed.version;
|
|
57
|
+
} catch {
|
|
58
|
+
continue;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return undefined;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function findExecutableOnPath(name: string, pathEnv: string | undefined): string | undefined {
|
|
65
|
+
if (!pathEnv) return undefined;
|
|
66
|
+
for (const entry of pathEnv.split(path.delimiter)) {
|
|
67
|
+
if (!entry) continue;
|
|
68
|
+
const candidate = path.join(entry, name);
|
|
69
|
+
if (existsSync(candidate)) return candidate;
|
|
70
|
+
}
|
|
71
|
+
return undefined;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function collectVulkanIcds(env: Record<string, string | undefined>): string[] {
|
|
75
|
+
const found: string[] = [];
|
|
76
|
+
const raw = env.VK_DRIVER_FILES ?? env.VK_ICD_FILENAMES;
|
|
77
|
+
if (raw) {
|
|
78
|
+
for (const entry of raw.split(path.delimiter)) {
|
|
79
|
+
if (entry && existsSync(entry)) found.push(entry);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
for (const dir of ["/usr/share/vulkan/icd.d", "/etc/vulkan/icd.d"]) {
|
|
83
|
+
if (!existsSync(dir)) continue;
|
|
84
|
+
try {
|
|
85
|
+
for (const file of readdirSync(dir)) {
|
|
86
|
+
if (file.endsWith(".json")) found.push(path.join(dir, file));
|
|
87
|
+
}
|
|
88
|
+
} catch {
|
|
89
|
+
// Ignore unreadable system directories.
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
return [...new Set(found)];
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
export async function runDoctor({
|
|
96
|
+
cwd = process.cwd(),
|
|
97
|
+
hostRoot,
|
|
98
|
+
hostExecutable,
|
|
99
|
+
env = process.env,
|
|
100
|
+
searchFrom = [],
|
|
101
|
+
}: DoctorOptions = {}): Promise<DoctorReport> {
|
|
102
|
+
const checks: DoctorCheck[] = [];
|
|
103
|
+
const currentPlatform = platformId();
|
|
104
|
+
const resolvedCwd = path.resolve(cwd);
|
|
105
|
+
const searchBases = [...searchFrom, resolvedCwd, import.meta.url];
|
|
106
|
+
|
|
107
|
+
// 1. Bun runtime version.
|
|
108
|
+
const minBun = "1.4.4";
|
|
109
|
+
const bunOk = compareSemver(Bun.version, minBun) >= 0;
|
|
110
|
+
checks.push({
|
|
111
|
+
id: "bun",
|
|
112
|
+
label: "Bun runtime",
|
|
113
|
+
status: bunOk ? "ok" : "fail",
|
|
114
|
+
detail: `Bun ${Bun.version} (required >= ${minBun})`,
|
|
115
|
+
...(bunOk
|
|
116
|
+
? {}
|
|
117
|
+
: { remediation: `Upgrade Bun to ${minBun} or enter the repository nix-shell.` }),
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
// 2. zgui-host resolution + ABI handshake.
|
|
121
|
+
let hostCheck: DoctorCheck;
|
|
122
|
+
try {
|
|
123
|
+
const resolved: ResolvedNativeHost = await resolveNativeHost({
|
|
124
|
+
hostExecutable,
|
|
125
|
+
hostRoot,
|
|
126
|
+
cwd: resolvedCwd,
|
|
127
|
+
env,
|
|
128
|
+
searchFrom: [import.meta.url, ...searchFrom],
|
|
129
|
+
verifyAbi: true,
|
|
130
|
+
allowCargoBuild: false,
|
|
131
|
+
});
|
|
132
|
+
const abi = resolved.abi;
|
|
133
|
+
const abiSummary = abi
|
|
134
|
+
? `v${abi.version} hostApiVersion=${abi.hostApiVersion} schemaVersion=${abi.schemaVersion} (${abi.platform})`
|
|
135
|
+
: `expected hostApiVersion=${EXPECTED_HOST_API_VERSION} schemaVersion=${EXPECTED_SCHEMA_VERSION}`;
|
|
136
|
+
hostCheck = {
|
|
137
|
+
id: "zgui-host",
|
|
138
|
+
label: "zgui-host binary & ABI",
|
|
139
|
+
status: "ok",
|
|
140
|
+
detail: `${resolved.executable} [${resolved.source}] ${abiSummary}`,
|
|
141
|
+
};
|
|
142
|
+
} catch (error) {
|
|
143
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
144
|
+
const isUnbuiltCargo = message.includes("has not been built yet");
|
|
145
|
+
const expectedPkg = platformHostPackageName();
|
|
146
|
+
hostCheck = {
|
|
147
|
+
id: "zgui-host",
|
|
148
|
+
label: "zgui-host binary & ABI",
|
|
149
|
+
status: isUnbuiltCargo ? "warn" : "fail",
|
|
150
|
+
detail: message.split("\n")[0] ?? message,
|
|
151
|
+
remediation: isUnbuiltCargo
|
|
152
|
+
? "Run `cargo build -p zgui-host` or launch `zgui-js dev` to build the local Cargo host."
|
|
153
|
+
: expectedPkg
|
|
154
|
+
? `Install ${expectedPkg}, set ZGUI_JS_HOST_EXECUTABLE, or pass --host-executable / --host-root.`
|
|
155
|
+
: "Pass --host-executable <PATH> or --host-root <DIR> pointing to a zgui-js checkout.",
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
checks.push(hostCheck);
|
|
159
|
+
|
|
160
|
+
// 3. Wayland display socket.
|
|
161
|
+
const waylandDisplay = env.WAYLAND_DISPLAY?.trim();
|
|
162
|
+
const runtimeDir = env.XDG_RUNTIME_DIR?.trim();
|
|
163
|
+
const waylandSocket =
|
|
164
|
+
waylandDisplay && runtimeDir ? path.join(runtimeDir, waylandDisplay) : undefined;
|
|
165
|
+
if (waylandSocket && existsSync(waylandSocket)) {
|
|
166
|
+
checks.push({
|
|
167
|
+
id: "wayland",
|
|
168
|
+
label: "Wayland display",
|
|
169
|
+
status: "ok",
|
|
170
|
+
detail: `${waylandDisplay} (${waylandSocket})`,
|
|
171
|
+
});
|
|
172
|
+
} else {
|
|
173
|
+
checks.push({
|
|
174
|
+
id: "wayland",
|
|
175
|
+
label: "Wayland display",
|
|
176
|
+
status: "warn",
|
|
177
|
+
detail: waylandDisplay
|
|
178
|
+
? `WAYLAND_DISPLAY=${waylandDisplay} set, but socket ${waylandSocket ?? "(XDG_RUNTIME_DIR unset)"} was not found`
|
|
179
|
+
: "WAYLAND_DISPLAY is not set (desktop windowing unavailable; headless preview remains usable)",
|
|
180
|
+
remediation: "Run inside a Wayland compositor session for desktop `zgui-js dev`.",
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
// 4. Vulkan / Mesa ICDs.
|
|
185
|
+
const icds = collectVulkanIcds(env);
|
|
186
|
+
if (icds.length > 0) {
|
|
187
|
+
checks.push({
|
|
188
|
+
id: "vulkan",
|
|
189
|
+
label: "Vulkan / Mesa ICDs",
|
|
190
|
+
status: "ok",
|
|
191
|
+
detail: `${icds.length} ICD manifest(s) detected (${icds.slice(0, 2).join(", ")}${icds.length > 2 ? ", ..." : ""})`,
|
|
192
|
+
});
|
|
193
|
+
} else {
|
|
194
|
+
checks.push({
|
|
195
|
+
id: "vulkan",
|
|
196
|
+
label: "Vulkan / Mesa ICDs",
|
|
197
|
+
status: "warn",
|
|
198
|
+
detail:
|
|
199
|
+
"No Vulkan ICD manifests found in VK_DRIVER_FILES, VK_ICD_FILENAMES, or /usr/share/vulkan/icd.d",
|
|
200
|
+
remediation: "Enter `nix-shell` or install Mesa Vulkan drivers / set VK_DRIVER_FILES.",
|
|
201
|
+
});
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
// 5. XDG desktop portal reachability.
|
|
205
|
+
const dbusAddress = env.DBUS_SESSION_BUS_ADDRESS?.trim();
|
|
206
|
+
const portalBin =
|
|
207
|
+
findExecutableOnPath("xdg-desktop-portal", env.PATH) ??
|
|
208
|
+
(existsSync("/usr/libexec/xdg-desktop-portal")
|
|
209
|
+
? "/usr/libexec/xdg-desktop-portal"
|
|
210
|
+
: undefined) ??
|
|
211
|
+
(existsSync("/usr/lib/xdg-desktop-portal") ? "/usr/lib/xdg-desktop-portal" : undefined);
|
|
212
|
+
if (dbusAddress && portalBin) {
|
|
213
|
+
checks.push({
|
|
214
|
+
id: "xdg-portal",
|
|
215
|
+
label: "XDG desktop portal",
|
|
216
|
+
status: "ok",
|
|
217
|
+
detail: `D-Bus session active and portal binary found (${portalBin})`,
|
|
218
|
+
});
|
|
219
|
+
} else {
|
|
220
|
+
checks.push({
|
|
221
|
+
id: "xdg-portal",
|
|
222
|
+
label: "XDG desktop portal",
|
|
223
|
+
status: "warn",
|
|
224
|
+
detail: !dbusAddress
|
|
225
|
+
? "DBUS_SESSION_BUS_ADDRESS is unset (file picker portals unavailable in headless shells)"
|
|
226
|
+
: "DBUS_SESSION_BUS_ADDRESS is set, but xdg-desktop-portal binary was not detected in standard paths",
|
|
227
|
+
remediation:
|
|
228
|
+
"Ensure a desktop D-Bus session and xdg-desktop-portal backend are running for file dialogs.",
|
|
229
|
+
});
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
// 6. tsrs typechecker.
|
|
233
|
+
const tsrsVersion = resolveToolVersion("tsrs", [
|
|
234
|
+
...searchBases,
|
|
235
|
+
path.dirname(createRequire(import.meta.url).resolve("@hewel/zgui-build")),
|
|
236
|
+
]);
|
|
237
|
+
checks.push({
|
|
238
|
+
id: "tsrs",
|
|
239
|
+
label: "TypeScript checker (tsrs)",
|
|
240
|
+
status: tsrsVersion ? "ok" : "fail",
|
|
241
|
+
detail: tsrsVersion ? `tsrs ${tsrsVersion}` : "tsrs could not be resolved",
|
|
242
|
+
...(tsrsVersion ? {} : { remediation: "Install `tsrs` or `@hewel/zgui-build` dependencies." }),
|
|
243
|
+
});
|
|
244
|
+
|
|
245
|
+
// 7. oxlint linter.
|
|
246
|
+
const oxlintVersion = resolveToolVersion("oxlint", [
|
|
247
|
+
...searchBases,
|
|
248
|
+
path.resolve(import.meta.dir, "../../.."),
|
|
249
|
+
]);
|
|
250
|
+
checks.push({
|
|
251
|
+
id: "oxlint",
|
|
252
|
+
label: "Linter (oxlint)",
|
|
253
|
+
status: oxlintVersion ? "ok" : "warn",
|
|
254
|
+
detail: oxlintVersion ? `oxlint ${oxlintVersion}` : "oxlint not installed in this project",
|
|
255
|
+
...(oxlintVersion
|
|
256
|
+
? {}
|
|
257
|
+
: { remediation: "Install `oxlint` and extend `@hewel/zgui/oxlint/recommended`." }),
|
|
258
|
+
});
|
|
259
|
+
|
|
260
|
+
return {
|
|
261
|
+
schemaVersion: 1,
|
|
262
|
+
ok: checks.every(check => check.status !== "fail"),
|
|
263
|
+
platform: currentPlatform,
|
|
264
|
+
checks,
|
|
265
|
+
};
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
export function formatDoctorReport(report: DoctorReport): string {
|
|
269
|
+
const lines = [`zgui-js doctor (${report.platform}) — ${report.ok ? "OK" : "ISSUES FOUND"}`];
|
|
270
|
+
for (const check of report.checks) {
|
|
271
|
+
const tag = check.status === "ok" ? "[OK] " : check.status === "warn" ? "[WARN]" : "[FAIL]";
|
|
272
|
+
lines.push(` ${tag} ${check.label}: ${check.detail}`);
|
|
273
|
+
if (check.remediation) {
|
|
274
|
+
lines.push(` -> ${check.remediation}`);
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
return lines.join("\n");
|
|
278
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export {
|
|
2
|
+
initApplication,
|
|
3
|
+
runInitCli,
|
|
4
|
+
type InitApplicationOptions,
|
|
5
|
+
type InitApplicationResult,
|
|
6
|
+
type InitTemplate,
|
|
7
|
+
} from "./init.ts";
|
|
8
|
+
export {
|
|
9
|
+
runDoctor,
|
|
10
|
+
formatDoctorReport,
|
|
11
|
+
type DoctorCheck,
|
|
12
|
+
type DoctorCheckStatus,
|
|
13
|
+
type DoctorOptions,
|
|
14
|
+
type DoctorReport,
|
|
15
|
+
} from "./doctor.ts";
|
|
16
|
+
export { runInspect, type RunInspectOptions } from "./inspect.ts";
|
|
17
|
+
export { runCli } from "./cli.ts";
|