Skip to content

Commit 944c4d1

Browse files
authored
chore: remove unused code (#46)
Removes functions that are not used anymore, and cascading to other code that was used by these functions. Also removes some unused imports.
1 parent a20e424 commit 944c4d1

File tree

4 files changed

+3
-148
lines changed

4 files changed

+3
-148
lines changed

src/plugins/status-bar.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { commands, QuickPickItemKind, ThemeColor, window } from "vscode";
22
import type { QuickPickItem } from "vscode";
33

44
import { createPlugin } from "../plugins.ts";
5-
import { checkLocalstackInstalled } from "../utils/install.ts";
65

76
export default createPlugin(
87
"status-bar",

src/utils/exec.ts

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,4 @@
11
import * as childProcess from "node:child_process";
22
import * as util from "node:util";
33

4-
// import { appendToEnvPath } from "./env-path.ts";
5-
6-
export const COMMAND_NOT_FOUND_EXIT_CODE = 127;
7-
84
export const exec = util.promisify(childProcess.exec);
9-
10-
// const execAsync = util.promisify(childProcess.exec);
11-
12-
// export const exec = (command: string, options?: childProcess.ExecOptions) => {
13-
// return execAsync(command, {
14-
// env: {
15-
// ...options?.env,
16-
// //
17-
// PATH: appendToEnvPath(options?.env.PATH ?? "", ""),
18-
// },
19-
// ...options,
20-
// });
21-
// };
22-
23-
export interface ExecException extends Error {
24-
cmd: string;
25-
code: number;
26-
stdout: string;
27-
stderr: string;
28-
}
29-
30-
export function isExecException(error: unknown): error is ExecException {
31-
return (
32-
typeof error === "object" &&
33-
error !== null &&
34-
"code" in error &&
35-
"cmd" in error &&
36-
"stderr" in error &&
37-
"stdout" in error
38-
);
39-
}

src/utils/manage.ts

Lines changed: 3 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,13 @@ import { commands, env, Uri, window } from "vscode";
44

55
import { readAuthToken } from "./authenticate.ts";
66
import { spawnLocalStack } from "./cli.ts";
7-
import { exec } from "./exec.ts";
87
import { checkIsLicenseValid } from "./license.ts";
98
import type { Telemetry } from "./telemetry.ts";
109

11-
export type LocalstackStatus = "running" | "starting" | "stopping" | "stopped";
12-
13-
let previousStatus: LocalstackStatus | undefined;
14-
1510
export async function fetchHealth(): Promise<boolean> {
16-
// health is ok in the majority of use cases, however, determining status based on it can be flaky.
17-
// for example, if localstack becomes unhealthy while running for reasons other that stop then reporting "stopping" may be misleading.
18-
// though we don't know if it happens often.
11+
// Health is OK in the majority of use cases, however, determining status based on it can be flaky.
12+
// For example, if localstack becomes unhealthy while running for reasons other than the stop,
13+
// then reporting "stopping" may be misleading.
1914
try {
2015
const response = await fetch("http://127.0.0.1:4566/_localstack/health");
2116
return response.ok;
@@ -42,50 +37,6 @@ async function fetchLocalStackSessionId(): Promise<string> {
4237
return "";
4338
}
4439

45-
async function getStatusFromCLI(): Promise<LocalstackStatus | undefined> {
46-
try {
47-
const result = await exec(
48-
"docker inspect -f '{{.State.Status}}' localstack-main",
49-
);
50-
if (result.stdout.includes("running")) {
51-
return "running";
52-
} else if (result.stdout.includes("stopped")) {
53-
return "stopped";
54-
}
55-
} catch {
56-
return undefined;
57-
}
58-
}
59-
60-
export async function getLocalstackStatus(): Promise<LocalstackStatus> {
61-
const [healthOk, status] = await Promise.all([
62-
fetchHealth(),
63-
getStatusFromCLI(),
64-
]);
65-
66-
if (healthOk && status === "running") {
67-
previousStatus = "running";
68-
return "running";
69-
}
70-
71-
if (!healthOk && status !== "running") {
72-
previousStatus = "stopped";
73-
return "stopped";
74-
}
75-
76-
if (previousStatus === "stopped" && !healthOk && status === "running") {
77-
previousStatus = "starting";
78-
return "starting";
79-
}
80-
81-
if (previousStatus === "running" && !healthOk) {
82-
previousStatus = "stopping";
83-
return "stopping";
84-
}
85-
86-
return previousStatus ?? "stopped";
87-
}
88-
8940
export async function startLocalStack(
9041
outputChannel: LogOutputChannel,
9142
telemetry: Telemetry,
@@ -236,25 +187,6 @@ async function showErrorMessage(
236187
}
237188
}
238189

239-
export async function getLocalstackVersion(
240-
outputChannel: LogOutputChannel,
241-
): Promise<string | undefined> {
242-
try {
243-
const { stdout } = await exec("localstack --version");
244-
const versionMatch = stdout.match(/\d+\.\d+\.\d+/);
245-
if (!versionMatch) {
246-
outputChannel.error(
247-
`Failed to parse LocalStack from version output: ${stdout}`,
248-
);
249-
return undefined;
250-
}
251-
252-
return versionMatch[0];
253-
} catch {
254-
return undefined;
255-
}
256-
}
257-
258190
// Checks for session_id in workspaceState, creates if missing
259191
export async function getOrCreateExtensionSessionId(
260192
context: ExtensionContext,

src/utils/prompts.ts

Lines changed: 0 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -6,47 +6,6 @@ import type { CancellationToken, LogOutputChannel } from "vscode";
66

77
import { spawn, SpawnError } from "./spawn.ts";
88

9-
export interface DarwinPromptOptions {
10-
message: string;
11-
title: string;
12-
icon: "note";
13-
buttons: string[];
14-
outputChannel: LogOutputChannel;
15-
outputLabel?: string;
16-
cancellationToken?: CancellationToken;
17-
}
18-
19-
export async function darwinPrompt(
20-
options: DarwinPromptOptions,
21-
): Promise<{ cancelled: boolean }> {
22-
try {
23-
await spawn(
24-
"osascript",
25-
[
26-
"-e",
27-
`'display dialog ${JSON.stringify(options.message)} with title ${JSON.stringify(options.title)} with icon ${options.icon} buttons {${options.buttons.map((button) => JSON.stringify(button)).join(",")}} default button 1'`,
28-
],
29-
{
30-
outputChannel: options.outputChannel,
31-
outputLabel: options.outputLabel,
32-
cancellationToken: options.cancellationToken,
33-
},
34-
);
35-
return {
36-
cancelled: false,
37-
};
38-
} catch (error) {
39-
options.outputChannel.error(error instanceof Error ? error : String(error));
40-
41-
// osascript will terminate with code 1 if the user cancels the dialog.
42-
if (error instanceof SpawnError && error.code === 1) {
43-
return { cancelled: true };
44-
}
45-
46-
throw error;
47-
}
48-
}
49-
509
export interface SpawnElevatedDarwinOptions {
5110
script: string;
5211
outputChannel: LogOutputChannel;

0 commit comments

Comments
 (0)