File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -5,10 +5,11 @@ import { createSolid } from "@solid-cli/create";
55import packageJson from "../package.json" with { type : "json" } ;
66import { intro } from "@clack/prompts" ;
77import * as color from "picocolors" ;
8+ import { debuginfo } from "./debug"
89intro ( `\n${ color . bgCyan ( color . black ( ` Solid CLI v${ packageJson . version } ` ) ) } ` ) ;
910
1011const main = defineCommand ( {
11- subCommands : { create : createSolid ( packageJson . version ) } ,
12+ subCommands : { create : createSolid ( packageJson . version ) , debug : debuginfo } ,
1213} ) ;
1314
1415runMain ( main ) ;
Original file line number Diff line number Diff line change 11/// This subcommand prints useful debug info to stdout
22import { readFile } from "fs/promises" ;
33import os from "os" ;
4+ import { defineCommand } from "citty" ;
5+ import { detectRuntime } from "./runtime-detector"
6+ import * as p from "@clack/prompts" ;
47type 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 }
2629Runtime:
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}
3134export 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+ } )
Original file line number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments