@@ -7,24 +7,34 @@ import {
77 saveAuthToken ,
88 readAuthToken ,
99} from "../utils/authenticate.ts" ;
10+ import { findLocalStack } from "../utils/cli.ts" ;
1011import { configureAwsProfiles } from "../utils/configure-aws.ts" ;
1112import { runInstallProcess } from "../utils/install.ts" ;
1213import {
1314 activateLicense ,
1415 checkIsLicenseValid ,
1516 activateLicenseUntilValid ,
1617} from "../utils/license.ts" ;
17- import { minDelay } from "../utils/promises .ts" ;
18+ import { minDelay } from "../utils/min-delay .ts" ;
1819import { updateDockerImage } from "../utils/setup.ts" ;
1920import { get_setup_ended } from "../utils/telemetry.ts" ;
2021
22+ async function getValidCliPath ( ) {
23+ const cli = await findLocalStack ( ) ;
24+ if ( ! cli . cliPath || ! cli . executable || ! cli . found || ! cli . upToDate ) {
25+ return ;
26+ }
27+ return cli . cliPath ;
28+ }
29+
2130export default createPlugin (
2231 "setup" ,
2332 ( {
2433 context,
2534 outputChannel,
2635 setupStatusTracker,
2736 localStackStatusTracker,
37+ cliStatusTracker,
2838 telemetry,
2939 } ) => {
3040 context . subscriptions . push (
@@ -43,7 +53,7 @@ export default createPlugin(
4353 } ,
4454 } ) ;
4555
46- window . withProgress (
56+ void window . withProgress (
4757 {
4858 location : ProgressLocation . Notification ,
4959 title : "Setup LocalStack" ,
@@ -55,13 +65,14 @@ export default createPlugin(
5565 let authenticationStatus : "COMPLETED" | "SKIPPED" = "COMPLETED" ;
5666 {
5767 const installationStartedAt = new Date ( ) . toISOString ( ) ;
58- const { cancelled, skipped } = await runInstallProcess (
68+ const { cancelled, skipped } = await runInstallProcess ( {
69+ cliPath : cliStatusTracker . cliPath ( ) ,
5970 progress,
6071 cancellationToken,
6172 outputChannel,
6273 telemetry,
63- origin_trigger ,
64- ) ;
74+ origin : origin_trigger ,
75+ } ) ;
6576 cliStatus = skipped === true ? "SKIPPED" : "COMPLETED" ;
6677 if ( cancelled || cancellationToken . isCancellationRequested ) {
6778 telemetry . track ( {
@@ -221,14 +232,52 @@ export default createPlugin(
221232 /////////////////////////////////////////////////////////////////////
222233 progress . report ( { message : "Checking LocalStack license..." } ) ;
223234
235+ // If the CLI status tracker doesn't have a valid CLI path yet,
236+ // we must find it manually. This may occur when installing the
237+ // CLI as part of the setup process: the CLI status tracker will
238+ // detect the CLI path the next tick.
239+ const cliPath =
240+ cliStatusTracker . cliPath ( ) ?? ( await getValidCliPath ( ) ) ;
241+ if ( ! cliPath ) {
242+ telemetry . track (
243+ get_setup_ended (
244+ cliStatus ,
245+ authenticationStatus ,
246+ "CANCELLED" ,
247+ "CANCELLED" ,
248+ "FAILED" ,
249+ origin_trigger ,
250+ await readAuthToken ( ) ,
251+ ) ,
252+ ) ;
253+ void window
254+ . showErrorMessage (
255+ "Could not access the LocalStack CLI." ,
256+ {
257+ title : "Restart Setup" ,
258+ command : "localstack.setup" ,
259+ } ,
260+ {
261+ title : "View Logs" ,
262+ command : "localstack.viewLogs" ,
263+ } ,
264+ )
265+ . then ( ( selection ) => {
266+ if ( selection ) {
267+ void commands . executeCommand ( selection . command ) ;
268+ }
269+ } ) ;
270+ return ;
271+ }
272+
224273 // If an auth token has just been obtained or LocalStack has never been started,
225274 // then there will be no license info to be reported by `localstack license info`.
226275 // Also, an expired license could be cached.
227276 // Activating the license pre-emptively to know its state during the setup process.
228277 const licenseCheckStartedAt = new Date ( ) . toISOString ( ) ;
229278 const licenseIsValid = await minDelay (
230- activateLicense ( outputChannel ) . then ( ( ) =>
231- checkIsLicenseValid ( outputChannel ) ,
279+ activateLicense ( cliPath , outputChannel ) . then ( ( ) =>
280+ checkIsLicenseValid ( cliPath , outputChannel ) ,
232281 ) ,
233282 ) ;
234283 if ( ! licenseIsValid ) {
@@ -240,6 +289,7 @@ export default createPlugin(
240289 await commands . executeCommand ( "localstack.openLicensePage" ) ;
241290
242291 await activateLicenseUntilValid (
292+ cliPath ,
243293 outputChannel ,
244294 cancellationToken ,
245295 ) ;
0 commit comments