Skip to content

Commit ee64584

Browse files
authored
fix: Revert "feat: improve cli detection" (#65)
Reverts #60 Step 2 in bringing main back to the state before #60 that introduced a regression. Changes from #60 are to be reapplied in a different manner to prevent the regression. This bring `main` to a releaseable state again. Note: step 1 is #64, had to be reverted as well because its changes were made on top of #60 ones and cannot be isolated.
1 parent dfef829 commit ee64584

25 files changed

+720
-1086
lines changed

package.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,12 @@
5555
"title": "Run Setup Wizard",
5656
"category": "LocalStack"
5757
},
58+
{
59+
"command": "localstack.refreshStatusBar",
60+
"title": "Refresh Status Bar",
61+
"category": "LocalStack",
62+
"enablement": "false"
63+
},
5864
{
5965
"command": "localstack.showCommands",
6066
"title": "Show Commands",

src/constants.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,26 +15,20 @@ export const GLOBAL_CLI_INSTALLATION_DIRNAME = join(
1515
);
1616

1717
const CLI_UNIX_PATHS = [
18-
// The local installation path takes precedence.
19-
join(LOCAL_CLI_INSTALLATION_DIRNAME, "localstack"),
20-
// Check if it's in the PATH.
2118
"localstack",
22-
// Common installation paths.
2319
join("/", "usr", "bin", "localstack"),
2420
join("/", "usr", "local", "bin", "localstack"),
2521
join("/", "opt", "homebrew", "bin", "localstack"),
2622
join("/", "home", "linuxbrew", ".linuxbrew", "bin", "localstack"),
2723
join(homedir(), ".linuxbrew", "bin", "localstack"),
2824
join(homedir(), ".local", "bin", "localstack"),
25+
join(LOCAL_CLI_INSTALLATION_DIRNAME, "localstack"),
2926
];
3027

3128
const CLI_WINDOWS_PATHS = [
32-
// The local installation path takes precedence.
33-
join(LOCAL_CLI_INSTALLATION_DIRNAME, "localstack.exe"),
34-
// Check if it's in the PATH.
3529
"localstack.exe",
36-
// Common installation paths.
3730
join(GLOBAL_CLI_INSTALLATION_DIRNAME, "localstack", "localstack.exe"),
31+
join(LOCAL_CLI_INSTALLATION_DIRNAME, "localstack.exe"),
3832
];
3933

4034
export const CLI_PATHS =

src/extension.ts

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,10 @@ import manage from "./plugins/manage.ts";
88
import setup from "./plugins/setup.ts";
99
import statusBar from "./plugins/status-bar.ts";
1010
import { PluginManager } from "./plugins.ts";
11-
import { createCliStatusTracker } from "./utils/cli.ts";
12-
import { createLocalStackContainerStatusTracker } from "./utils/localstack-container.ts";
13-
import {
14-
createHealthStatusTracker,
15-
createLocalStackInstanceStatusTracker,
16-
} from "./utils/localstack-instance.ts";
11+
import { createContainerStatusTracker } from "./utils/container-status.ts";
12+
import { createLocalStackStatusTracker } from "./utils/localstack-status.ts";
1713
import { getOrCreateExtensionSessionId } from "./utils/manage.ts";
18-
import { createSetupStatusTracker } from "./utils/setup.ts";
14+
import { createSetupStatusTracker } from "./utils/setup-status.ts";
1915
import { createTelemetry } from "./utils/telemetry.ts";
2016
import { createTimeTracker } from "./utils/time-tracker.ts";
2117

@@ -33,9 +29,6 @@ export async function activate(context: ExtensionContext) {
3329
});
3430
context.subscriptions.push(outputChannel);
3531

36-
const cliStatusTracker = createCliStatusTracker(outputChannel);
37-
context.subscriptions.push(cliStatusTracker);
38-
3932
const timeTracker = createTimeTracker({ outputChannel });
4033

4134
const {
@@ -53,37 +46,45 @@ export async function activate(context: ExtensionContext) {
5346
statusBarItem.text = "$(loading~spin) LocalStack";
5447
statusBarItem.show();
5548

56-
const containerStatusTracker = createLocalStackContainerStatusTracker(
49+
const containerStatusTracker = await createContainerStatusTracker(
5750
"localstack-main",
5851
outputChannel,
5952
timeTracker,
6053
);
6154
context.subscriptions.push(containerStatusTracker);
6255

63-
const healthCheckStatusTracker = createHealthStatusTracker(timeTracker);
64-
const localStackStatusTracker = createLocalStackInstanceStatusTracker(
56+
const localStackStatusTracker = createLocalStackStatusTracker(
6557
containerStatusTracker,
66-
healthCheckStatusTracker,
6758
outputChannel,
59+
timeTracker,
6860
);
6961
context.subscriptions.push(localStackStatusTracker);
7062

71-
const setupStatusTracker = await timeTracker.run(
72-
"setup-status",
73-
async () => {
74-
return await createSetupStatusTracker(
75-
outputChannel,
76-
timeTracker,
77-
cliStatusTracker,
78-
);
79-
},
63+
outputChannel.trace(`[setup-status]: Starting...`);
64+
const startStatusTracker = Date.now();
65+
const setupStatusTracker = await createSetupStatusTracker(
66+
outputChannel,
67+
timeTracker,
8068
);
8169
context.subscriptions.push(setupStatusTracker);
70+
const endStatusTracker = Date.now();
71+
outputChannel.trace(
72+
`[setup-status]: Completed in ${ms(
73+
endStatusTracker - startStatusTracker,
74+
{ long: true },
75+
)}`,
76+
);
8277

83-
const telemetry = await timeTracker.run("telemetry", async () => {
84-
const sessionId = await getOrCreateExtensionSessionId(context);
85-
return createTelemetry(outputChannel, sessionId);
86-
});
78+
const startTelemetry = Date.now();
79+
outputChannel.trace(`[telemetry]: Starting...`);
80+
const sessionId = await getOrCreateExtensionSessionId(context);
81+
const telemetry = createTelemetry(outputChannel, sessionId);
82+
const endTelemetry = Date.now();
83+
outputChannel.trace(
84+
`[telemetry]: Completed in ${ms(endTelemetry - startTelemetry, {
85+
long: true,
86+
})}`,
87+
);
8788

8889
return {
8990
statusBarItem,
@@ -99,7 +100,6 @@ export async function activate(context: ExtensionContext) {
99100
context,
100101
outputChannel,
101102
statusBarItem,
102-
cliStatusTracker,
103103
containerStatusTracker,
104104
localStackStatusTracker,
105105
setupStatusTracker,

src/plugins.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
import ms from "ms";
22
import type { ExtensionContext, LogOutputChannel, StatusBarItem } from "vscode";
33

4-
import type { CliStatusTracker } from "./utils/cli.ts";
5-
import type { LocalStackContainerStatusTracker } from "./utils/localstack-container.ts";
6-
import type { LocalStackInstanceStatusTracker } from "./utils/localstack-instance.ts";
7-
import type { SetupStatusTracker } from "./utils/setup.ts";
4+
import type { ContainerStatusTracker } from "./utils/container-status.ts";
5+
import type { LocalStackStatusTracker } from "./utils/localstack-status.ts";
6+
import type { SetupStatusTracker } from "./utils/setup-status.ts";
87
import type { Telemetry } from "./utils/telemetry.ts";
98
import type { TimeTracker } from "./utils/time-tracker.ts";
109

@@ -14,9 +13,8 @@ export interface PluginOptions {
1413
context: ExtensionContext;
1514
outputChannel: LogOutputChannel;
1615
statusBarItem: StatusBarItem;
17-
cliStatusTracker: CliStatusTracker;
18-
containerStatusTracker: LocalStackContainerStatusTracker;
19-
localStackStatusTracker: LocalStackInstanceStatusTracker;
16+
containerStatusTracker: ContainerStatusTracker;
17+
localStackStatusTracker: LocalStackStatusTracker;
2018
setupStatusTracker: SetupStatusTracker;
2119
telemetry: Telemetry;
2220
timeTracker: TimeTracker;

src/plugins/manage.ts

Lines changed: 3 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -9,30 +9,16 @@ import {
99

1010
export default createPlugin(
1111
"manage",
12-
({
13-
context,
14-
outputChannel,
15-
telemetry,
16-
localStackStatusTracker,
17-
cliStatusTracker,
18-
}) => {
12+
({ context, outputChannel, telemetry, localStackStatusTracker }) => {
1913
context.subscriptions.push(
2014
commands.registerCommand("localstack.start", async () => {
21-
const cliPath = cliStatusTracker.cliPath();
22-
if (!cliPath) {
23-
void window.showInformationMessage(
24-
"LocalStack CLI could not be found. Please, run the setup wizard.",
25-
);
26-
return;
27-
}
28-
2915
if (localStackStatusTracker.status() !== "stopped") {
3016
window.showInformationMessage("LocalStack is already running.");
3117
return;
3218
}
3319
localStackStatusTracker.forceContainerStatus("running");
3420
try {
35-
await startLocalStack(cliPath, outputChannel, telemetry);
21+
await startLocalStack(outputChannel, telemetry);
3622
} catch {
3723
localStackStatusTracker.forceContainerStatus("stopped");
3824
}
@@ -41,20 +27,12 @@ export default createPlugin(
4127

4228
context.subscriptions.push(
4329
commands.registerCommand("localstack.stop", () => {
44-
const cliPath = cliStatusTracker.cliPath();
45-
if (!cliPath) {
46-
void window.showInformationMessage(
47-
"LocalStack CLI could not be found. Please, run the setup wizard.",
48-
);
49-
return;
50-
}
51-
5230
if (localStackStatusTracker.status() !== "running") {
5331
window.showInformationMessage("LocalStack is not running.");
5432
return;
5533
}
5634
localStackStatusTracker.forceContainerStatus("stopping");
57-
void stopLocalStack(cliPath, outputChannel, telemetry);
35+
void stopLocalStack(outputChannel, telemetry);
5836
}),
5937
);
6038

src/plugins/setup.ts

Lines changed: 7 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -7,34 +7,24 @@ import {
77
saveAuthToken,
88
readAuthToken,
99
} from "../utils/authenticate.ts";
10-
import { findLocalStack } from "../utils/cli.ts";
1110
import { configureAwsProfiles } from "../utils/configure-aws.ts";
1211
import { runInstallProcess } from "../utils/install.ts";
1312
import {
1413
activateLicense,
1514
checkIsLicenseValid,
1615
activateLicenseUntilValid,
1716
} from "../utils/license.ts";
18-
import { minDelay } from "../utils/min-delay.ts";
17+
import { minDelay } from "../utils/promises.ts";
1918
import { updateDockerImage } from "../utils/setup.ts";
2019
import { get_setup_ended } from "../utils/telemetry.ts";
2120

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-
3021
export default createPlugin(
3122
"setup",
3223
({
3324
context,
3425
outputChannel,
3526
setupStatusTracker,
3627
localStackStatusTracker,
37-
cliStatusTracker,
3828
telemetry,
3929
}) => {
4030
context.subscriptions.push(
@@ -53,7 +43,7 @@ export default createPlugin(
5343
},
5444
});
5545

56-
void window.withProgress(
46+
window.withProgress(
5747
{
5848
location: ProgressLocation.Notification,
5949
title: "Setup LocalStack",
@@ -65,14 +55,13 @@ export default createPlugin(
6555
let authenticationStatus: "COMPLETED" | "SKIPPED" = "COMPLETED";
6656
{
6757
const installationStartedAt = new Date().toISOString();
68-
const { cancelled, skipped } = await runInstallProcess({
69-
cliPath: cliStatusTracker.cliPath(),
58+
const { cancelled, skipped } = await runInstallProcess(
7059
progress,
7160
cancellationToken,
7261
outputChannel,
7362
telemetry,
74-
origin: origin_trigger,
75-
});
63+
origin_trigger,
64+
);
7665
cliStatus = skipped === true ? "SKIPPED" : "COMPLETED";
7766
if (cancelled || cancellationToken.isCancellationRequested) {
7867
telemetry.track({
@@ -232,52 +221,14 @@ export default createPlugin(
232221
/////////////////////////////////////////////////////////////////////
233222
progress.report({ message: "Checking LocalStack license..." });
234223

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-
273224
// If an auth token has just been obtained or LocalStack has never been started,
274225
// then there will be no license info to be reported by `localstack license info`.
275226
// Also, an expired license could be cached.
276227
// Activating the license pre-emptively to know its state during the setup process.
277228
const licenseCheckStartedAt = new Date().toISOString();
278229
const licenseIsValid = await minDelay(
279-
activateLicense(cliPath, outputChannel).then(() =>
280-
checkIsLicenseValid(cliPath, outputChannel),
230+
activateLicense(outputChannel).then(() =>
231+
checkIsLicenseValid(outputChannel),
281232
),
282233
);
283234
if (!licenseIsValid) {
@@ -289,7 +240,6 @@ export default createPlugin(
289240
await commands.executeCommand("localstack.openLicensePage");
290241

291242
await activateLicenseUntilValid(
292-
cliPath,
293243
outputChannel,
294244
cancellationToken,
295245
);

0 commit comments

Comments
 (0)