66import * as vscode from 'vscode'
77import * as path from 'path'
88import fs from '../../shared/fs/fs'
9- import { ChildProcess , ChildProcessOptions } from './processUtils'
109import { GitExtension } from '../extensions/git'
1110import { Settings } from '../settings'
12- import { getLogger } from '../logger/logger '
11+ import * as processUtils from './processUtils '
1312
1413/** Full path to VSCode CLI. */
1514let vscPath : string
1615let sshPath : string
1716let gitPath : string
1817let bashPath : string
1918
20- /**
21- * Tries to execute a program at path `p` with the given args and
22- * optionally checks the output for `expected`.
23- *
24- * @param p path to a program to execute
25- * @param args program args
26- * @param doLog log failures
27- * @param expected output must contain this string
28- */
29- export async function tryRun (
30- p : string ,
31- args : string [ ] ,
32- logging : 'yes' | 'no' | 'noresult' = 'yes' ,
33- expected ?: string ,
34- opt ?: ChildProcessOptions
35- ) : Promise < boolean > {
36- const proc = new ChildProcess ( p , args , { logging : 'no' } )
37- const r = await proc . run ( opt )
38- const ok = r . exitCode === 0 && ( expected === undefined || r . stdout . includes ( expected ) )
39- if ( logging === 'noresult' ) {
40- getLogger ( ) . info ( 'tryRun: %s: %s' , ok ? 'ok' : 'failed' , proc )
41- } else if ( logging !== 'no' ) {
42- getLogger ( ) . info ( 'tryRun: %s: %s %O' , ok ? 'ok' : 'failed' , proc , proc . result ( ) )
43- }
44- return ok
45- }
46-
4719/**
4820 * Gets the fullpath to `code` (VSCode CLI), or falls back to "code" (not
4921 * absolute) if it works.
@@ -78,7 +50,7 @@ export async function getVscodeCliPath(): Promise<string | undefined> {
7850 if ( ! vsc || ( vsc !== 'code' && ! ( await fs . exists ( vsc ) ) ) ) {
7951 continue
8052 }
81- if ( await tryRun ( vsc , [ '--version' ] ) ) {
53+ if ( await processUtils . tryRun ( vsc , [ '--version' ] ) ) {
8254 vscPath = vsc
8355 return vsc
8456 }
@@ -103,7 +75,7 @@ export async function findTypescriptCompiler(): Promise<string | undefined> {
10375
10476 for ( const tsc of tscPaths ) {
10577 // Try to run "tsc -v".
106- if ( await tryRun ( tsc , [ '-v' ] , 'yes' , 'Version' ) ) {
78+ if ( await processUtils . tryRun ( tsc , [ '-v' ] , 'yes' , 'Version' ) ) {
10779 return tsc
10880 }
10981 }
@@ -115,8 +87,8 @@ export async function findTypescriptCompiler(): Promise<string | undefined> {
11587 * Gets the configured `ssh` path, or falls back to "ssh" (not absolute),
11688 * or tries common locations, or returns undefined.
11789 */
118- export async function findSshPath ( ) : Promise < string | undefined > {
119- if ( sshPath !== undefined ) {
90+ export async function findSshPath ( useCache : boolean = true ) : Promise < string | undefined > {
91+ if ( useCache && sshPath !== undefined ) {
12092 return sshPath
12193 }
12294
@@ -132,7 +104,7 @@ export async function findSshPath(): Promise<string | undefined> {
132104 if ( ! p || ( 'ssh' !== p && ! ( await fs . exists ( p ) ) ) ) {
133105 continue
134106 }
135- if ( await tryRun ( p , [ '-G' , 'x' ] , 'noresult' /* "ssh -G" prints quasi-sensitive info. */ ) ) {
107+ if ( await processUtils . tryRun ( p , [ '-G' , 'x' ] , 'noresult' /* "ssh -G" prints quasi-sensitive info. */ ) ) {
136108 sshPath = p
137109 return p
138110 }
@@ -154,7 +126,7 @@ export async function findGitPath(): Promise<string | undefined> {
154126 if ( ! p || ( 'git' !== p && ! ( await fs . exists ( p ) ) ) ) {
155127 continue
156128 }
157- if ( await tryRun ( p , [ '--version' ] ) ) {
129+ if ( await processUtils . tryRun ( p , [ '--version' ] ) ) {
158130 gitPath = p
159131 return p
160132 }
@@ -174,7 +146,7 @@ export async function findBashPath(): Promise<string | undefined> {
174146 if ( ! p || ( 'bash' !== p && ! ( await fs . exists ( p ) ) ) ) {
175147 continue
176148 }
177- if ( await tryRun ( p , [ '--version' ] ) ) {
149+ if ( await processUtils . tryRun ( p , [ '--version' ] ) ) {
178150 bashPath = p
179151 return p
180152 }
0 commit comments