mirror of
https://github.com/oven-sh/bun
synced 2026-02-09 10:28:47 +00:00
* Switch back to prettier * wip * Update .prettierignore * Update .prettierignore * ignores * Update .prettierignore * Rest * [autofix.ci] apply automated fixes --------- Co-authored-by: Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
98 lines
2.9 KiB
TypeScript
98 lines
2.9 KiB
TypeScript
import { spawnSync } from "node:child_process";
|
|
import { BuildCommand } from "./build-layer";
|
|
|
|
export class PublishCommand extends BuildCommand {
|
|
static summary = "Publish a custom Lambda layer for Bun.";
|
|
|
|
#aws(args: string[]): string {
|
|
this.debug("$", "aws", ...args);
|
|
const { status, stdout, stderr } = spawnSync("aws", args, {
|
|
stdio: "pipe",
|
|
});
|
|
const result = stdout.toString("utf-8").trim();
|
|
if (status === 0) {
|
|
return result;
|
|
}
|
|
const reason = stderr.toString("utf-8").trim() || result;
|
|
throw new Error(`aws ${args.join(" ")} exited with ${status}: ${reason}`);
|
|
}
|
|
|
|
async run() {
|
|
const { flags } = await this.parse(PublishCommand);
|
|
this.debug("Options:", flags);
|
|
try {
|
|
const version = this.#aws(["--version"]);
|
|
this.debug("AWS CLI:", version);
|
|
} catch (error) {
|
|
this.debug(error);
|
|
this.error(
|
|
"Install the `aws` CLI to continue: https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html",
|
|
{ exit: 1 },
|
|
);
|
|
}
|
|
const { layer, region, arch, output, public: isPublic } = flags;
|
|
if (region.includes("*")) {
|
|
// prettier-ignore
|
|
const result = this.#aws(["ec2", "describe-regions", "--query", "Regions[].RegionName", "--output", "json"]);
|
|
region.length = 0;
|
|
for (const name of JSON.parse(result)) {
|
|
region.push(name);
|
|
}
|
|
} else if (!region.length) {
|
|
// prettier-ignore
|
|
region.push(this.#aws(["configure", "get", "region"]));
|
|
}
|
|
this.log("Publishing...");
|
|
for (const regionName of region) {
|
|
for (const layerName of layer) {
|
|
// prettier-ignore
|
|
const result = this.#aws([
|
|
"lambda",
|
|
"publish-layer-version",
|
|
"--layer-name",
|
|
layerName,
|
|
"--region",
|
|
regionName,
|
|
"--description",
|
|
"Bun is an incredibly fast JavaScript runtime, bundler, transpiler, and package manager.",
|
|
"--license-info",
|
|
"MIT",
|
|
"--compatible-architectures",
|
|
arch === "x64" ? "x86_64" : "arm64",
|
|
"--compatible-runtimes",
|
|
"provided.al2",
|
|
"provided",
|
|
"--zip-file",
|
|
`fileb://${output}`,
|
|
"--output",
|
|
"json",
|
|
]);
|
|
const { LayerVersionArn } = JSON.parse(result);
|
|
this.log("Published", LayerVersionArn);
|
|
if (isPublic) {
|
|
// prettier-ignore
|
|
this.#aws([
|
|
"lambda",
|
|
"add-layer-version-permission",
|
|
"--layer-name",
|
|
layerName,
|
|
"--region",
|
|
regionName,
|
|
"--version-number",
|
|
LayerVersionArn.split(":").pop(),
|
|
"--statement-id",
|
|
`${layerName}-public`,
|
|
"--action",
|
|
"lambda:GetLayerVersion",
|
|
"--principal",
|
|
"*",
|
|
]);
|
|
}
|
|
}
|
|
}
|
|
this.log("Done");
|
|
}
|
|
}
|
|
|
|
await PublishCommand.run(process.argv.slice(2));
|