@@ -15,6 +15,9 @@ import {
1515} from "vscode" ;
1616import * as jsoncParser from "jsonc-parser/lib/esm/main.js" ;
1717import { semver } from "./semver" ;
18+ import type { DenoInfoJson } from "./types" ;
19+ import { spawnSync } from "child_process" ;
20+ import type * as vscode from "vscode" ;
1821
1922/** Assert that the condition is "truthy", otherwise throw. */
2023export function assert ( cond : unknown , msg = "Assertion failed." ) : asserts cond {
@@ -112,6 +115,37 @@ async function getDefaultDenoCommand() {
112115 }
113116}
114117
118+ export async function getDenoInfoJson (
119+ outputChannel : vscode . OutputChannel ,
120+ ) : Promise < DenoInfoJson | null > {
121+ try {
122+ const command = await getDenoCommandName ( ) ;
123+ const { stdout, stderr, status, error } = spawnSync ( command , [
124+ "info" ,
125+ "--json" ,
126+ ] , {
127+ encoding : "utf-8" ,
128+ stdio : [ "ignore" , "pipe" , "pipe" ] ,
129+ env : {
130+ ...process . env ,
131+ "NO_COLOR" : "1" ,
132+ } ,
133+ } ) ;
134+ if ( error ) {
135+ throw error ;
136+ }
137+ if ( status != 0 ) {
138+ throw `Command failed: ${ stderr } ` ;
139+ }
140+ return JSON . parse ( stdout ) ;
141+ } catch ( error ) {
142+ outputChannel . appendLine (
143+ `Couldn't get 'deno info --json' output: ${ error } ` ,
144+ ) ;
145+ return null ;
146+ }
147+ }
148+
115149function fileExists ( executableFilePath : string ) : Promise < boolean > {
116150 return new Promise < boolean > ( ( resolve ) => {
117151 fs . stat ( executableFilePath , ( err , stat ) => {
0 commit comments