Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
103 changes: 52 additions & 51 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,8 @@
"package": "node build/extension.mjs --production",
"pretest": "npm run compile",
"check-types": "tsc",
"lint": "eslint .",
"lint": "eslint",
"format": "biome check",
"test": "vscode-test",
"compile:font": "node build/icon-font.mjs"
},
Expand All @@ -127,6 +128,7 @@
"@vscode/test-cli": "^0.0.11",
"@vscode/test-electron": "^2.5.2",
"@vscode/vsce": "^3.6.0",
"chokidar": "^4.0.3",
"esbuild": "^0.25.9",
"eslint": "^9.35.0",
"eslint-plugin-import": "^2.32.0",
Expand Down
2 changes: 1 addition & 1 deletion src/utils/authenticate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ async function redirectToLocalStack(): Promise<{ cancelled: boolean }> {
return { cancelled: !openSuccessful };
}

const LOCALSTACK_AUTH_FILENAME = `${os.homedir()}/.localstack/auth.json`;
export const LOCALSTACK_AUTH_FILENAME = `${os.homedir()}/.localstack/auth.json`;
const LOCALSTACK_AUTH_FILENAME_READABLE = LOCALSTACK_AUTH_FILENAME.replace(
`${os.homedir()}/`,
"~/",
Expand Down
14 changes: 8 additions & 6 deletions src/utils/configure-aws.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ const LOCALSTACK_CREDENTIALS_PROPERTIES = {
aws_secret_access_key: "test",
};

const AWS_DIRECTORY = path.join(os.homedir(), ".aws");
export const AWS_DIRECTORY = path.join(os.homedir(), ".aws");
export const AWS_CONFIG_FILENAME = path.join(AWS_DIRECTORY, "config");
export const AWS_CREDENTIALS_FILENAME = path.join(AWS_DIRECTORY, "credentials");

async function overrideSelection(
filesToModify: string[],
Expand Down Expand Up @@ -464,13 +466,13 @@ export async function configureAwsProfiles(options: {

export async function checkIsProfileConfigured(): Promise<boolean> {
try {
const awsConfigFilename = path.join(AWS_DIRECTORY, "config");
const awsCredentialsFilename = path.join(AWS_DIRECTORY, "credentials");

const [{ section: configSection }, { section: credentialsSection }] =
await Promise.all([
getProfile(awsConfigFilename, LOCALSTACK_CONFIG_PROFILE_NAME),
getProfile(awsCredentialsFilename, LOCALSTACK_CREDENTIALS_PROFILE_NAME),
getProfile(AWS_CONFIG_FILENAME, LOCALSTACK_CONFIG_PROFILE_NAME),
getProfile(
AWS_CREDENTIALS_FILENAME,
LOCALSTACK_CREDENTIALS_PROFILE_NAME,
),
]);

const [configNeedsOverride, credentialsNeedsOverride] = await Promise.all([
Expand Down
23 changes: 23 additions & 0 deletions src/utils/immediate-once.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/**
* Creates a function that calls the given callback immediately once.
*
* Multiple calls during the same tick are ignored.
*
* @param callback - The callback to call.
* @returns A function that calls the callback immediately once.
*/
export function immediateOnce<T>(callback: () => T): () => void {
let timeout: NodeJS.Immediate | undefined;

return () => {
if (timeout) {
return;
}

timeout = setImmediate(() => {
void Promise.resolve(callback()).finally(() => {
timeout = undefined;
});
});
};
}
29 changes: 29 additions & 0 deletions src/utils/license.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,36 @@
import { homedir, platform } from "node:os";
import { join } from "node:path";

import type { CancellationToken, LogOutputChannel } from "vscode";

import { execLocalStack } from "./cli.ts";

/**
* See https://github.com/localstack/localstack/blob/de861e1f656a52eaa090b061bd44fc1a7069715e/localstack-core/localstack/utils/files.py#L38-L55.
* @returns The cache directory for the current platform.
*/
const cacheDirectory = () => {
switch (platform()) {
case "win32":
return join(process.env.LOCALAPPDATA!, "cache");
case "darwin":
return join(homedir(), "Library", "Caches");
default:
return process.env.XDG_CACHE_HOME ?? join(homedir(), ".cache");
}
};

/**
* The file that contains the license information of the LocalStack CLI.
*
* The license file is stored in the cache directory for the current platform.
*/
export const LICENSE_FILENAME = join(
cacheDirectory(),
"localstack-cli",
"license.json",
);

const LICENSE_VALIDITY_MARKER = "license validity: valid";

export async function checkIsLicenseValid(outputChannel: LogOutputChannel) {
Expand Down
Loading
Loading