Skip to content

Commit 219002c

Browse files
committed
refactor to make valid part of class
1 parent 7116ed1 commit 219002c

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

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

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,17 @@ import { mergeResolvedShellPath } from '../../env/resolveEnv'
1616
interface SamLocation {
1717
path: string
1818
version: string
19-
verified?: boolean
2019
}
2120
export class SamCliLocationProvider {
2221
private static samCliLocator: BaseSamCliLocator | undefined
2322
protected static cachedSamLocation: SamLocation | undefined
23+
private static samLocationValid: boolean = false
2424

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

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

3840
// Avoid searching the system for `sam` (especially slow on Windows).
39-
if (cachedLoc && (cachedLoc.verified || (await SamCliLocationProvider.isValidSamLocation(cachedLoc.path)))) {
40-
cachedLoc.verified = true
41+
if (
42+
cachedLoc &&
43+
(SamCliLocationProvider.samLocationValid ||
44+
(await SamCliLocationProvider.isValidSamLocation(cachedLoc.path)))
45+
) {
4146
perflog.done()
4247
return cachedLoc
4348
}

0 commit comments

Comments
 (0)