Skip to content

Commit

Permalink
refactor to make valid part of class
Browse files Browse the repository at this point in the history
  • Loading branch information
Hweinstock committed Nov 11, 2024
1 parent 7116ed1 commit 219002c
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions packages/core/src/shared/sam/cli/samCliLocator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,17 @@ import { mergeResolvedShellPath } from '../../env/resolveEnv'
interface SamLocation {
path: string
version: string
verified?: boolean
}
export class SamCliLocationProvider {
private static samCliLocator: BaseSamCliLocator | undefined
protected static cachedSamLocation: SamLocation | undefined
private static samLocationValid: boolean = false

/** Checks that the given `sam` actually works by invoking `sam --version`. */
private static async isValidSamLocation(samPath: string) {
return await tryRun(samPath, ['--version'], 'no', 'SAM CLI')
const isValid = await tryRun(samPath, ['--version'], 'no', 'SAM CLI')
this.samLocationValid = isValid
return isValid
}

/**
Expand All @@ -36,8 +38,11 @@ export class SamCliLocationProvider {
const cachedLoc = forceSearch ? undefined : SamCliLocationProvider.cachedSamLocation

// Avoid searching the system for `sam` (especially slow on Windows).
if (cachedLoc && (cachedLoc.verified || (await SamCliLocationProvider.isValidSamLocation(cachedLoc.path)))) {
cachedLoc.verified = true
if (
cachedLoc &&
(SamCliLocationProvider.samLocationValid ||
(await SamCliLocationProvider.isValidSamLocation(cachedLoc.path)))
) {
perflog.done()
return cachedLoc
}
Expand Down

0 comments on commit 219002c

Please sign in to comment.