Skip to content

Commit 61f95f0

Browse files
committed
refactor pathfinder
1 parent 24919b7 commit 61f95f0

File tree

8 files changed

+221
-199
lines changed

8 files changed

+221
-199
lines changed

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

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44
*/
55
import { fs } from '../../shared'
66
import { ToolkitError } from '../../shared/errors'
7-
import { tryRun } from '../../shared/utilities/pathFind'
87
import { Timeout } from '../../shared/utilities/timeoutUtils'
98
import { findAsync } from '../../shared/utilities/collectionUtils'
109
import { RunParameterContext } from '../../shared/utilities/processUtils'
10+
import { PathFinder } from '../../shared/utilities/pathFinder'
1111

1212
type sshKeyType = 'rsa' | 'ed25519'
1313

@@ -48,9 +48,15 @@ export class SshKeyPair {
4848
const overrideKeys = async (_t: string, proc: RunParameterContext) => {
4949
await proc.send('yes')
5050
}
51-
return !(await tryRun('ssh-keygen', ['-t', keyType, '-N', '', '-q', '-f', keyPath], 'yes', 'unknown key type', {
52-
onStdout: overrideKeys,
53-
}))
51+
return !(await PathFinder.tryRun(
52+
'ssh-keygen',
53+
['-t', keyType, '-N', '', '-q', '-f', keyPath],
54+
'yes',
55+
'unknown key type',
56+
{
57+
onStdout: overrideKeys,
58+
}
59+
))
5460
}
5561

5662
public static async tryKeyTypes(keyPath: string, keyTypes: sshKeyType[]): Promise<boolean> {

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ import { ToolkitError, getTelemetryReason, getTelemetryReasonDesc } from '../../
4141
import { isRemoteWorkspace } from '../../shared/vscode/env'
4242
import { isBuilderIdConnection } from '../../auth/connection'
4343
import globals from '../../shared/extensionGlobals'
44-
import { getVscodeCliPath, tryRun } from '../../shared/utilities/pathFind'
4544
import { setContext } from '../../shared/vscode/setContext'
45+
import pathFinder, { PathFinder } from '../../shared/utilities/pathFinder'
4646

4747
const MessageTimeOut = 5_000
4848

@@ -315,7 +315,7 @@ export const installAmazonQExtension = Commands.declare(
315315
* installExtension will fail on remote environments when the amazon q extension is already installed locally.
316316
* Until thats fixed we need to manually install the amazon q extension using the cli
317317
*/
318-
const vscPath = await getVscodeCliPath()
318+
const vscPath = await pathFinder.getVscodeCliPath()
319319
if (!vscPath) {
320320
throw new ToolkitError('installAmazonQ: Unable to find VSCode CLI path', {
321321
code: 'CodeCLINotFound',
@@ -328,7 +328,7 @@ export const installAmazonQExtension = Commands.declare(
328328
},
329329
(progress, token) => {
330330
progress.report({ message: 'Installing Amazon Q' })
331-
return tryRun(vscPath, ['--install-extension', VSCODE_EXTENSION_ID.amazonq])
331+
return PathFinder.tryRun(vscPath, ['--install-extension', VSCODE_EXTENSION_ID.amazonq])
332332
}
333333
)
334334
return

packages/core/src/shared/remoteSession.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ import { getLogger } from './logger/logger'
1818
import { getOrInstallCli } from './utilities/cliUtils'
1919
import { pushIf } from './utilities/collectionUtils'
2020
import { ChildProcess } from './utilities/processUtils'
21-
import { findSshPath, getVscodeCliPath } from './utilities/pathFind'
2221
import { IamClient } from './clients/iamClient'
2322
import { IAM } from 'aws-sdk'
2423
import { getIdeProperties } from './extensionUtilities'
24+
import { pathFinder } from './utilities/pathFinder'
2525

2626
const policyAttachDelay = 5000
2727

@@ -139,7 +139,7 @@ async function ensureSsmCli() {
139139
}
140140

141141
export async function ensureTools() {
142-
const [vsc, ssh, ssm] = await Promise.all([getVscodeCliPath(), findSshPath(), ensureSsmCli()])
142+
const [vsc, ssh, ssm] = await Promise.all([pathFinder.getVscodeCliPath(), pathFinder.findSshPath(), ensureSsmCli()])
143143

144144
const missing: MissingTool[] = []
145145
pushIf(missing, vsc === undefined, { name: 'code' })

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@ 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/pathFind'
13+
import { PathFinder } from '../../utilities/pathFinder'
1414

1515
export class SamCliLocationProvider {
1616
private static samCliLocator: BaseSamCliLocator | undefined
1717
protected static cachedSamLocation: { path: string; version: string } | undefined
1818

1919
/** Checks that the given `sam` actually works by invoking `sam --version`. */
2020
private static async isValidSamLocation(samPath: string) {
21-
return await tryRun(samPath, ['--version'], 'no', 'SAM CLI')
21+
return await PathFinder.tryRun(samPath, ['--version'], 'no', 'SAM CLI')
2222
}
2323

2424
/**

packages/core/src/shared/sam/debugger/typescriptSamDebug.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import { findParentProjectFile } from '../../utilities/workspaceUtils'
1616
import { DefaultSamLocalInvokeCommand, waitForDebuggerMessages } from '../cli/samCliLocalInvoke'
1717
import { runLambdaFunction, waitForPort } from '../localLambdaRunner'
1818
import { SamLaunchRequestArgs } from './awsSamDebugger'
19-
import { findTypescriptCompiler } from '../../utilities/pathFind'
19+
import { findTypescriptCompiler } from '../../utilities/pathFinder'
2020
import fs from '../../fs/fs'
2121

2222
const tsConfigFile = 'aws-toolkit-tsconfig.json'

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

Lines changed: 0 additions & 182 deletions
This file was deleted.

0 commit comments

Comments
 (0)