Skip to content

Commit 57eb886

Browse files
committed
avoid circular dependency
1 parent b47c788 commit 57eb886

File tree

7 files changed

+45
-39
lines changed

7 files changed

+45
-39
lines changed

packages/core/src/awsService/ec2/sshKeyPair.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*/
55
import { fs } from '../../shared'
66
import { ToolkitError } from '../../shared/errors'
7-
import { tryRun } from '../../shared/utilities/processUtils'
7+
import { tryRun } from '../../shared/utilities/programUtils'
88
import { Timeout } from '../../shared/utilities/timeoutUtils'
99
import { findAsync } from '../../shared/utilities/collectionUtils'
1010
import { RunParameterContext } from '../../shared/utilities/processUtils'

packages/core/src/codewhisperer/commands/basicCommands.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ import { isBuilderIdConnection } from '../../auth/connection'
4343
import globals from '../../shared/extensionGlobals'
4444
import { getVscodeCliPath } from '../../shared/utilities/pathFind'
4545
import { setContext } from '../../shared/vscode/setContext'
46-
import { tryRun } from '../../shared/utilities/processUtils'
46+
import { tryRun } from '../../shared/utilities/programUtils'
4747

4848
const MessageTimeOut = 5_000
4949

packages/core/src/shared/sam/cli/samCliLocator.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { getLogger, Logger } from '../../logger'
1010
import { SamCliInfoInvocation } from './samCliInfo'
1111
import { DefaultSamCliValidator, SamCliValidatorContext, SamCliVersionValidation } from './samCliValidator'
1212
import { PerfLog } from '../../logger/perfLogger'
13-
import { tryRun } from '../../utilities/processUtils'
13+
import { tryRun } from '../../utilities/programUtils'
1414

1515
export class SamCliLocationProvider {
1616
private static samCliLocator: BaseSamCliLocator | undefined

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import * as path from 'path'
88
import fs from '../../shared/fs/fs'
99
import { GitExtension } from '../extensions/git'
1010
import { Settings } from '../settings'
11-
import * as processUtils from './processUtils'
11+
import * as programUtils from './programUtils'
1212

1313
/** Full path to VSCode CLI. */
1414
let vscPath: string
@@ -50,7 +50,7 @@ export async function getVscodeCliPath(): Promise<string | undefined> {
5050
if (!vsc || (vsc !== 'code' && !(await fs.exists(vsc)))) {
5151
continue
5252
}
53-
if (await processUtils.tryRun(vsc, ['--version'])) {
53+
if (await programUtils.tryRun(vsc, ['--version'])) {
5454
vscPath = vsc
5555
return vsc
5656
}
@@ -75,7 +75,7 @@ export async function findTypescriptCompiler(): Promise<string | undefined> {
7575

7676
for (const tsc of tscPaths) {
7777
// Try to run "tsc -v".
78-
if (await processUtils.tryRun(tsc, ['-v'], 'yes', 'Version')) {
78+
if (await programUtils.tryRun(tsc, ['-v'], 'yes', 'Version')) {
7979
return tsc
8080
}
8181
}
@@ -104,7 +104,7 @@ export async function findSshPath(useCache: boolean = true): Promise<string | un
104104
if (!p || ('ssh' !== p && !(await fs.exists(p)))) {
105105
continue
106106
}
107-
if (await processUtils.tryRun(p, ['-G', 'x'], 'noresult' /* "ssh -G" prints quasi-sensitive info. */)) {
107+
if (await programUtils.tryRun(p, ['-G', 'x'], 'noresult' /* "ssh -G" prints quasi-sensitive info. */)) {
108108
sshPath = p
109109
return p
110110
}
@@ -126,7 +126,7 @@ export async function findGitPath(): Promise<string | undefined> {
126126
if (!p || ('git' !== p && !(await fs.exists(p)))) {
127127
continue
128128
}
129-
if (await processUtils.tryRun(p, ['--version'])) {
129+
if (await programUtils.tryRun(p, ['--version'])) {
130130
gitPath = p
131131
return p
132132
}
@@ -146,7 +146,7 @@ export async function findBashPath(): Promise<string | undefined> {
146146
if (!p || ('bash' !== p && !(await fs.exists(p)))) {
147147
continue
148148
}
149-
if (await processUtils.tryRun(p, ['--version'])) {
149+
if (await programUtils.tryRun(p, ['--version'])) {
150150
bashPath = p
151151
return p
152152
}

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

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import * as proc from 'child_process'
77
import * as crossSpawn from 'cross-spawn'
88
import * as logger from '../logger'
99
import { Timeout, CancellationError, waitUntil } from './timeoutUtils'
10-
import { getLogger } from '..'
1110

1211
export interface RunParameterContext {
1312
/** Reports an error parsed from the stdin/stdout streams. */
@@ -369,30 +368,3 @@ export class ChildProcess {
369368
return `${pid} [${this.#command} ${noparams ? '...' : this.#args.join(' ')}]`
370369
}
371370
}
372-
373-
/**
374-
* Tries to execute a program at path `p` with the given args and
375-
* optionally checks the output for `expected`.
376-
*
377-
* @param p path to a program to execute
378-
* @param args program args
379-
* @param doLog log failures
380-
* @param expected output must contain this string
381-
*/
382-
export async function tryRun(
383-
p: string,
384-
args: string[],
385-
logging: 'yes' | 'no' | 'noresult' = 'yes',
386-
expected?: string,
387-
opt?: ChildProcessOptions
388-
): Promise<boolean> {
389-
const proc = new ChildProcess(p, args, { logging: 'no' })
390-
const r = await proc.run(opt)
391-
const ok = r.exitCode === 0 && (expected === undefined || r.stdout.includes(expected))
392-
if (logging === 'noresult') {
393-
getLogger().info('tryRun: %s: %s', ok ? 'ok' : 'failed', proc)
394-
} else if (logging !== 'no') {
395-
getLogger().info('tryRun: %s: %s %O', ok ? 'ok' : 'failed', proc, proc.result())
396-
}
397-
return ok
398-
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*!
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
import { getLogger } from '..'
7+
import { ChildProcess, ChildProcessOptions } from './processUtils'
8+
9+
/**
10+
* Tries to execute a program at path `p` with the given args and
11+
* optionally checks the output for `expected`.
12+
*
13+
* @param p path to a program to execute
14+
* @param args program args
15+
* @param doLog log failures
16+
* @param expected output must contain this string
17+
*/
18+
export async function tryRun(
19+
p: string,
20+
args: string[],
21+
logging: 'yes' | 'no' | 'noresult' = 'yes',
22+
expected?: string,
23+
opt?: ChildProcessOptions
24+
): Promise<boolean> {
25+
const proc = new ChildProcess(p, args, { logging: 'no' })
26+
const r = await proc.run(opt)
27+
const ok = r.exitCode === 0 && (expected === undefined || r.stdout.includes(expected))
28+
if (logging === 'noresult') {
29+
getLogger().info('tryRun: %s: %s', ok ? 'ok' : 'failed', proc)
30+
} else if (logging !== 'no') {
31+
getLogger().info('tryRun: %s: %s %O', ok ? 'ok' : 'failed', proc, proc.result())
32+
}
33+
return ok
34+
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import * as path from 'path'
1111
import * as testutil from '../../testUtil'
1212
import { fs } from '../../../shared'
1313
import { findSshPath, findTypescriptCompiler, getVscodeCliPath } from '../../../shared/utilities/pathFind'
14-
import * as processUtils from '../../../shared/utilities/processUtils'
14+
import * as programUtils from '../../../shared/utilities/programUtils'
1515

1616
describe('pathFind', function () {
1717
it('findTypescriptCompiler()', async function () {
@@ -47,7 +47,7 @@ describe('pathFind', function () {
4747
describe('findSshPath', function () {
4848
let tryRunStub: sinon.SinonStub
4949
before(function () {
50-
tryRunStub = sinon.stub(processUtils, 'tryRun')
50+
tryRunStub = sinon.stub(programUtils, 'tryRun')
5151
})
5252

5353
after(function () {

0 commit comments

Comments
 (0)