1- import EventEmitter from "node:events" ;
21import { constants } from "node:fs" ;
32import { access } from "node:fs/promises" ;
43import { isAbsolute } from "node:path" ;
@@ -9,11 +8,9 @@ import type { CancellationToken, LogOutputChannel, Disposable } from "vscode";
98
109import { CLI_PATHS , LOCALSTACK_DOCKER_IMAGE_NAME } from "../constants.ts" ;
1110
12- import { createEmitter , createValueEmitter } from "./emitter.ts" ;
13- import type { Callback } from "./emitter.ts" ;
11+ import { createValueEmitter } from "./emitter.ts" ;
1412import { exec } from "./exec.ts" ;
1513import { immediateOnce } from "./immediate-once.ts" ;
16- import { setIntervalPromise } from "./promises.ts" ;
1714import type { SetupStatus } from "./setup-status.ts" ;
1815import { spawn } from "./spawn.ts" ;
1916import type { SpawnOptions } from "./spawn.ts" ;
@@ -100,16 +97,6 @@ async function findLocalStack(): Promise<CliCheckResult> {
10097 executable,
10198 upToDate,
10299 } ;
103- // const {found, executable, upToDate} = await verifyLocalStackCli(customLocation);
104- // if (!found) {
105- // throw new Error(`Configured LocalStack CLI location '${customLocation}' does not exist`);
106- // }
107- // if (!executable) {
108- // throw new Error(`Configured LocalStack CLI location '${customLocation}' is not executable`);
109- // }
110- // if (!upToDate) {
111- // throw new Error(`Configured LocalStack CLI location '${customLocation}' is outdated (version < 4)`);
112- // }
113100 }
114101
115102 // Fall back to default search paths
@@ -175,71 +162,17 @@ export const spawnLocalStack = async (
175162export type LocalStackCliStatus = "not_found" | "outdated" | "ok" ;
176163
177164export interface LocalStackCliTracker extends Disposable {
178- // setupStatus(): SetupStatus | undefined;
179- // onSetupStatusChange(
180- // callback: (status: SetupStatus | undefined) => void,
181- // ): void;
182- // cli(): CliCheckResult | undefined;
183- // onCliChange(callback: (cli: CliCheckResult | undefined) => void): void;
184- // cliStatus(): LocalStackCliStatus | undefined;
185- // onCliStatusChange(callback: (status: LocalStackCliStatus) => void): void;
186-
187165 status ( ) : SetupStatus | undefined ;
188166 onStatusChange ( callback : ( status : SetupStatus | undefined ) => void ) : void ;
189167 cliPath ( ) : string | undefined ;
190168 onCliPathChange ( callback : ( cliPath : string | undefined ) => void ) : void ;
191169}
192170
193- function areCliCheckResultsDifferent (
194- resultA : CliCheckResult | undefined ,
195- resultB : CliCheckResult | undefined ,
196- ) : boolean {
197- if ( resultA ?. cliPath !== resultB ?. cliPath ) {
198- return true ;
199- }
200- if ( resultA ?. found !== resultB ?. found ) {
201- return true ;
202- }
203- if ( resultA ?. executable !== resultB ?. executable ) {
204- return true ;
205- }
206- return false ;
207- }
208-
209- function statusFromCliCheckResult (
210- cli : CliCheckResult | undefined ,
211- ) : LocalStackCliStatus {
212- if ( ! cli ?. found || ! cli . executable ) {
213- return "not_found" ;
214- }
215- if ( cli . upToDate === false ) {
216- return "outdated" ;
217- }
218- return "ok" ;
219- }
220-
221171export function createCliStatusTracker (
222172 outputChannel : LogOutputChannel ,
223173) : LocalStackCliTracker {
224- // const emitter = new EventEmitter<{
225- // setupStatus: [SetupStatus | undefined];
226- // cliStatus: [LocalStackCliStatus | undefined];
227- // cli: [CliCheckResult | undefined];
228- // }>();
229-
230- // emitter.emit("setupStatus", )
231-
232174 const status = createValueEmitter < SetupStatus > ( ) ;
233175 const cliPath = createValueEmitter < string | undefined > ( ) ;
234- // const cliStatus = createValueEmitter<LocalStackCliStatus>();
235-
236- // const statusEmitter = createEmitter<LocalStackCliStatus>(outputChannel);
237- // let currentStatus: LocalStackCliStatus | undefined;
238-
239- // let currentCli: CliCheckResult | undefined;
240- // const cliPathEmitter = createEmitter<CliCheckResult | undefined>(
241- // outputChannel,
242- // );
243176
244177 const track = immediateOnce ( async ( ) => {
245178 const newCli = await findLocalStack ( ) . catch ( ( ) => undefined ) ;
@@ -251,17 +184,6 @@ export function createCliStatusTracker(
251184 : "setup_required" ,
252185 ) ;
253186 cliPath . setValue ( newCli ?. cliPath ) ;
254-
255- // if (areCliCheckResultsDifferent(currentCli, newCli)) {
256- // currentCli = newCli;
257- // void cliPathEmitter.emit(currentCli);
258- // }
259-
260- // const newStatus = statusFromCliCheckResult(newCli);
261- // if (currentStatus !== newStatus) {
262- // currentStatus = newStatus;
263- // void statusEmitter.emit(newStatus);
264- // }
265187 } ) ;
266188
267189 const watcher = watch (
@@ -290,35 +212,17 @@ export function createCliStatusTracker(
290212 track ( ) ;
291213
292214 return {
293- // cli() {
294- // return currentCli;
295- // },
296- // onCliChange(callback) {
297- // cliPathEmitter.on(callback);
298- // if (currentCli) {
299- // callback(currentCli);
300- // }
301- // },
302- // cliStatus() {
303- // return currentStatus;
304- // },
305- // onCliStatusChange(callback) {
306- // statusEmitter.on(callback);
307- // if (currentStatus) {
308- // callback(currentStatus);
309- // }
310- // },
311215 cliPath ( ) {
312216 return cliPath . value ( ) ;
313217 } ,
314218 onCliPathChange ( callback ) {
315- cliPath . on ( callback ) ;
219+ cliPath . onChange ( callback ) ;
316220 } ,
317221 status ( ) {
318222 return status . value ( ) ;
319223 } ,
320224 onStatusChange ( callback ) {
321- status . on ( callback ) ;
225+ status . onChange ( callback ) ;
322226 } ,
323227 async dispose ( ) {
324228 await watcher . close ( ) ;
0 commit comments