Skip to content

Commit 5ef33ac

Browse files
committed
feat: use file watchers to track some setup statuses
Setup statuses for LS CLI authentication and AWS profile configuration are now checked via file watchers instead of periodic checks.
1 parent 6dd75db commit 5ef33ac

File tree

7 files changed

+251
-75
lines changed

7 files changed

+251
-75
lines changed

package-lock.json

Lines changed: 52 additions & 51 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@
127127
"@vscode/test-cli": "^0.0.11",
128128
"@vscode/test-electron": "^2.5.2",
129129
"@vscode/vsce": "^3.6.0",
130+
"chokidar": "^4.0.3",
130131
"esbuild": "^0.25.9",
131132
"eslint": "^9.35.0",
132133
"eslint-plugin-import": "^2.32.0",

src/utils/authenticate.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ async function redirectToLocalStack(): Promise<{ cancelled: boolean }> {
8484
return { cancelled: !openSuccessful };
8585
}
8686

87-
const LOCALSTACK_AUTH_FILENAME = `${os.homedir()}/.localstack/auth.json`;
87+
export const LOCALSTACK_AUTH_FILENAME = `${os.homedir()}/.localstack/auth.json`;
8888
const LOCALSTACK_AUTH_FILENAME_READABLE = LOCALSTACK_AUTH_FILENAME.replace(
8989
`${os.homedir()}/`,
9090
"~/",

src/utils/configure-aws.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@ const LOCALSTACK_CREDENTIALS_PROPERTIES = {
3434
aws_secret_access_key: "test",
3535
};
3636

37-
const AWS_DIRECTORY = path.join(os.homedir(), ".aws");
37+
export const AWS_DIRECTORY = path.join(os.homedir(), ".aws");
38+
export const AWS_CONFIG_FILENAME = path.join(AWS_DIRECTORY, "config");
39+
export const AWS_CREDENTIALS_FILENAME = path.join(AWS_DIRECTORY, "credentials");
3840

3941
async function overrideSelection(
4042
filesToModify: string[],
@@ -456,13 +458,13 @@ export async function configureAwsProfiles(options: {
456458

457459
export async function checkIsProfileConfigured(): Promise<boolean> {
458460
try {
459-
const awsConfigFilename = path.join(AWS_DIRECTORY, "config");
460-
const awsCredentialsFilename = path.join(AWS_DIRECTORY, "credentials");
461-
462461
const [{ section: configSection }, { section: credentialsSection }] =
463462
await Promise.all([
464-
getProfile(awsConfigFilename, LOCALSTACK_CONFIG_PROFILE_NAME),
465-
getProfile(awsCredentialsFilename, LOCALSTACK_CREDENTIALS_PROFILE_NAME),
463+
getProfile(AWS_CONFIG_FILENAME, LOCALSTACK_CONFIG_PROFILE_NAME),
464+
getProfile(
465+
AWS_CREDENTIALS_FILENAME,
466+
LOCALSTACK_CREDENTIALS_PROFILE_NAME,
467+
),
466468
]);
467469

468470
const [configNeedsOverride, credentialsNeedsOverride] = await Promise.all([

src/utils/once-immediate.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/**
2+
* Creates a function that calls the given callback once immediately.
3+
*
4+
* Multiple calls during the same tick are ignored.
5+
*
6+
* @param callback - The callback to call.
7+
* @returns A function that calls the callback once immediately.
8+
*/
9+
export function createOnceImmediate<T>(callback: () => T): () => void {
10+
let timeout: NodeJS.Immediate | undefined;
11+
12+
return () => {
13+
if (timeout) {
14+
return;
15+
}
16+
17+
timeout = setImmediate(() => {
18+
void Promise.resolve(callback()).finally(() => {
19+
timeout = undefined;
20+
});
21+
});
22+
};
23+
}

0 commit comments

Comments
 (0)