File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ /// This subcommand prints useful debug info to stdout
2+ import { readFile } from "fs/promises" ;
3+ import os from "os" ;
4+ type DebugInfo = {
5+ runtime : { name : string , version : string }
6+ os : { platform : string , release : string }
7+ packages : Record < string , string >
8+ }
9+ const getPackageJSON = async ( ) => {
10+ const f = await readFile ( "package.json" ) ;
11+ const parsed = JSON . parse ( f . toString ( ) ) ;
12+ return parsed ;
13+ }
14+ const prettyPrintRecord = ( record : Record < string , string > ) => {
15+ let str = "" ;
16+ for ( const key in record ) {
17+ const value = record [ key ] ;
18+ str += ` ${ key } : ${ value } \n`
19+ }
20+ return str ;
21+ }
22+
23+ export const prettyPrint = ( info : DebugInfo ) => {
24+ return `System:
25+ OS: ${ info . os . platform } ${ info . os . release }
26+ Runtime:
27+ ${ info . runtime . name } : v${ info . runtime . version }
28+ ${ Object . keys ( info . packages ) . length !== 0 ? `Dependencies:
29+ ${ prettyPrintRecord ( info . packages ) } ` : "" } `
30+ }
31+ export const fetchDebugInfo = async ( ) : Promise < DebugInfo > => {
32+ const parsed = await getPackageJSON ( ) ;
33+ const packages : Record < string , string > = parsed . dependencies ?? { } ;
34+ return {
35+ runtime : {
36+ name : "Node" ,
37+ version : "22.10.4"
38+ } ,
39+ os : {
40+ platform : os . platform ( ) ,
41+ release : os . release ( )
42+ } ,
43+ packages
44+ }
45+ }
Original file line number Diff line number Diff line change 1+ import { it } from "vitest" ;
2+ import { fetchDebugInfo , prettyPrint } from "../src/debug" ;
3+
4+ it ( "Runs" , async ( ) => {
5+ console . log ( prettyPrint ( await fetchDebugInfo ( ) ) )
6+ } )
You can’t perform that action at this time.
0 commit comments