33 * SPDX-License-Identifier: Apache-2.0
44 */
55
6- import { extensionSettingsPrefix } from '../../constants'
76import { getLogger } from '../../logger'
8- import { DefaultSettingsConfiguration } from '../../settingsConfiguration'
97import { ChildProcess , ChildProcessResult } from '../../utilities/childProcess'
10- import { DefaultSamCliConfiguration , SamCliConfiguration } from './samCliConfiguration'
118import {
129 makeRequiredSamCliProcessInvokeOptions ,
1310 SamCliProcessInvokeOptions ,
1411 SamCliProcessInvoker ,
1512} from './samCliInvokerUtils'
16- import { DefaultSamCliLocationProvider } from './samCliLocator'
1713
1814import * as nls from 'vscode-nls'
15+ import { DefaultSamCliConfiguration , SamCliConfiguration } from './samCliConfiguration'
16+ import { DefaultSettingsConfiguration } from '../../settingsConfiguration'
17+ import { extensionSettingsPrefix } from '../../constants'
1918const localize = nls . loadMessageBundle ( )
2019
21- export interface SamCliProcessInvokerContext {
22- cliConfig : SamCliConfiguration
23- }
24-
25- export class DefaultSamCliProcessInvokerContext implements SamCliProcessInvokerContext {
26- public cliConfig : SamCliConfiguration = new DefaultSamCliConfiguration (
27- new DefaultSettingsConfiguration ( extensionSettingsPrefix ) ,
28- new DefaultSamCliLocationProvider ( )
29- )
30- }
31-
32- export function resolveSamCliProcessInvokerContext (
33- params : Partial < SamCliProcessInvokerContext > = { }
34- ) : SamCliProcessInvokerContext {
35- const defaults = new DefaultSamCliProcessInvokerContext ( )
36-
37- return {
38- cliConfig : params . cliConfig || defaults . cliConfig ,
39- }
40- }
41-
4220/**
4321 * Yet another `sam` CLI wrapper.
4422 *
4523 * TODO: Merge this with `DefaultSamLocalInvokeCommand`.
4624 */
4725export class DefaultSamCliProcessInvoker implements SamCliProcessInvoker {
4826 private childProcess ?: ChildProcess
49- public constructor ( private readonly context : SamCliProcessInvokerContext = resolveSamCliProcessInvokerContext ( ) ) { }
27+ private readonly context : SamCliConfiguration
28+ public constructor ( params : {
29+ preloadedConfig ?: SamCliConfiguration
30+ locationProvider ?: { getLocation ( ) : Promise < string | undefined > }
31+ } ) {
32+ if ( params . preloadedConfig && params . locationProvider ) {
33+ throw new Error ( 'Invalid constructor args for DefaultSamCliProcessInvoker' )
34+ }
35+ if ( params . preloadedConfig ) {
36+ this . context = params . preloadedConfig
37+ } else if ( params . locationProvider ) {
38+ this . context = new DefaultSamCliConfiguration (
39+ new DefaultSettingsConfiguration ( extensionSettingsPrefix ) ,
40+ params . locationProvider
41+ )
42+ } else {
43+ throw new Error ( 'Invalid constructor args for DefaultSamCliProcessInvoker' )
44+ }
45+ }
5046
5147 public stop ( ) : void {
5248 if ( ! this . childProcess ) {
@@ -59,7 +55,7 @@ export class DefaultSamCliProcessInvoker implements SamCliProcessInvoker {
5955 const invokeOptions = makeRequiredSamCliProcessInvokeOptions ( options )
6056 const logger = getLogger ( )
6157
62- const sam = await this . context . cliConfig . getOrDetectSamCli ( )
58+ const sam = await this . context . getOrDetectSamCli ( )
6359 if ( ! sam . path ) {
6460 logger . warn ( 'SAM CLI not found and not configured' )
6561 } else if ( sam . autoDetected ) {
0 commit comments