Skip to content

Commit 4cb7b3c

Browse files
committed
avoid moving function
1 parent c2e17bd commit 4cb7b3c

File tree

1 file changed

+30
-30
lines changed

1 file changed

+30
-30
lines changed

packages/core/src/shared/utilities/pathFind.ts

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,44 @@
66
import * as vscode from 'vscode'
77
import * as path from 'path'
88
import fs from '../../shared/fs/fs'
9+
import { ChildProcess, ChildProcessOptions } from './processUtils'
910
import { GitExtension } from '../extensions/git'
1011
import { Settings } from '../settings'
11-
import { ChildProcess, ChildProcessOptions } from './processUtils'
12-
import { getLogger } from '..'
12+
import { getLogger } from '../logger/logger'
1313

1414
/** Full path to VSCode CLI. */
1515
let vscPath: string
1616
let sshPath: string
1717
let gitPath: string
1818
let bashPath: string
1919

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+
2047
/**
2148
* Gets the fullpath to `code` (VSCode CLI), or falls back to "code" (not
2249
* absolute) if it works.
@@ -88,7 +115,7 @@ export async function findTypescriptCompiler(): Promise<string | undefined> {
88115
* Gets the configured `ssh` path, or falls back to "ssh" (not absolute),
89116
* or tries common locations, or returns undefined.
90117
*/
91-
export async function findSshPath(useCache: boolean = true): Promise<string | undefined> {
118+
export async function findSshPath(useCache: boolean): Promise<string | undefined> {
92119
if (useCache && sshPath !== undefined) {
93120
return sshPath
94121
}
@@ -153,30 +180,3 @@ export async function findBashPath(): Promise<string | undefined> {
153180
}
154181
}
155182
}
156-
157-
/**
158-
* Tries to execute a program at path `p` with the given args and
159-
* optionally checks the output for `expected`.
160-
*
161-
* @param p path to a program to execute
162-
* @param args program args
163-
* @param doLog log failures
164-
* @param expected output must contain this string
165-
*/
166-
export async function tryRun(
167-
p: string,
168-
args: string[],
169-
logging: 'yes' | 'no' | 'noresult' = 'yes',
170-
expected?: string,
171-
opt?: ChildProcessOptions
172-
): Promise<boolean> {
173-
const proc = new ChildProcess(p, args, { logging: 'no' })
174-
const r = await proc.run(opt)
175-
const ok = r.exitCode === 0 && (expected === undefined || r.stdout.includes(expected))
176-
if (logging === 'noresult') {
177-
getLogger().info('tryRun: %s: %s', ok ? 'ok' : 'failed', proc)
178-
} else if (logging !== 'no') {
179-
getLogger().info('tryRun: %s: %s %O', ok ? 'ok' : 'failed', proc, proc.result())
180-
}
181-
return ok
182-
}

0 commit comments

Comments
 (0)