Skip to content

Commit cd20d01

Browse files
committed
feat: add debug command to full CLI
This command allows for printing system information useful for debugging purposes
1 parent 9294c1b commit cd20d01

3 files changed

Lines changed: 36 additions & 7 deletions

File tree

packages/full-solid/src/bin.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@ import { createSolid } from "@solid-cli/create";
55
import packageJson from "../package.json" with { type: "json" };
66
import { intro } from "@clack/prompts";
77
import * as color from "picocolors";
8+
import { debuginfo } from "./debug"
89
intro(`\n${color.bgCyan(color.black(` Solid CLI v${packageJson.version}`))}`);
910

1011
const main = defineCommand({
11-
subCommands: { create: createSolid(packageJson.version) },
12+
subCommands: { create: createSolid(packageJson.version), debug: debuginfo },
1213
});
1314

1415
runMain(main);

packages/full-solid/src/debug/index.ts

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
/// This subcommand prints useful debug info to stdout
22
import { readFile } from "fs/promises";
33
import os from "os";
4+
import { defineCommand } from "citty";
5+
import { detectRuntime } from "./runtime-detector"
6+
import * as p from "@clack/prompts";
47
type DebugInfo = {
58
runtime: { name: string, version: string }
69
os: { platform: string, release: string }
@@ -24,22 +27,27 @@ export const prettyPrint = (info: DebugInfo) => {
2427
return `System:
2528
OS: ${info.os.platform} ${info.os.release}
2629
Runtime:
27-
${info.runtime.name}: v${info.runtime.version}
30+
${info.runtime.name}: ${info.runtime.version}
2831
${Object.keys(info.packages).length !== 0 ? `Dependencies:
2932
${prettyPrintRecord(info.packages)}` : ""}`
3033
}
3134
export const fetchDebugInfo = async (): Promise<DebugInfo> => {
3235
const parsed = await getPackageJSON();
3336
const packages: Record<string, string> = parsed.dependencies ?? {};
37+
const runtime = detectRuntime();
3438
return {
35-
runtime: {
36-
name: "Node",
37-
version: "22.10.4"
38-
},
39+
runtime,
3940
os: {
4041
platform: os.platform(),
4142
release: os.release()
4243
},
4344
packages
4445
}
45-
}
46+
}
47+
48+
export const debuginfo = defineCommand({
49+
async run(ctx) {
50+
const info = await fetchDebugInfo();
51+
p.log.info(prettyPrint(info));
52+
},
53+
})
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
type RuntimeName = "Bun" | "Node" | "Deno"
2+
type Runtime = { name: RuntimeName, version: string }
3+
declare global {
4+
var Bun: { version: string } | undefined
5+
var Deno: { version: { deno: string } } | undefined
6+
}
7+
export const detectRuntime = (): Runtime => {
8+
if (globalThis.Bun) {
9+
return { name: "Bun", version: globalThis.Bun?.version }
10+
}
11+
if (globalThis.Deno) {
12+
return { name: "Deno", version: globalThis.Deno?.version?.deno }
13+
}
14+
// @ts-ignore
15+
if (typeof process !== undefined && !!process.versions?.node) {
16+
// @ts-ignore
17+
return { name: "Node", version: process?.version }
18+
}
19+
throw new Error("Unable to detect")
20+
}

0 commit comments

Comments
 (0)