@hyperframes/aws-lambda 0.8.177 → 0.8.179
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +9 -4
- package/dist/_chunks/chunk-AK7J3QQN.js +1006 -0
- package/dist/_chunks/chunk-PK7PO3MH.js +596 -0
- package/dist/_chunks/chunk-YS3KY3C5.js +19 -0
- package/dist/_chunks/chunk-ZY5YIH5W.js +380 -0
- package/dist/cdk/index.js +13 -1
- package/dist/contentStore.d.ts +5 -0
- package/dist/handler.js +5 -1137
- package/dist/index.js +26 -1648
- package/dist/s3PlanV2Publisher.d.ts +1 -0
- package/dist/s3Transport.d.ts +14 -1
- package/dist/sdk/deploySite.d.ts +17 -17
- package/dist/sdk/index.d.ts +3 -2
- package/dist/sdk/index.js +38 -572
- package/dist/sdk/prebuiltHandler.d.ts +17 -0
- package/dist/sdk/renderToLambda.d.ts +8 -2
- package/dist/siteManifest.d.ts +18 -0
- package/package.json +4 -2
- package/prebuilt/handler-zip.json +6 -0
- package/prebuilt/template.yaml +782 -0
- package/scripts/build-zip.ts +3 -3
- package/scripts/pin-handler-zip.test.ts +101 -0
- package/scripts/pin-handler-zip.ts +59 -0
package/scripts/build-zip.ts
CHANGED
|
@@ -111,10 +111,10 @@ async function main(): Promise<void> {
|
|
|
111
111
|
const opts = parseArgs(process.argv);
|
|
112
112
|
const start = Date.now();
|
|
113
113
|
|
|
114
|
-
|
|
115
|
-
mkdirSync(distDir, { recursive: true });
|
|
116
|
-
|
|
114
|
+
// Leave the package build in dist/: the release job zips after `bun run build`.
|
|
117
115
|
const stagingDir = join(distDir, "staging");
|
|
116
|
+
rmSync(stagingDir, { recursive: true, force: true });
|
|
117
|
+
rmSync(join(distDir, "handler.zip"), { force: true });
|
|
118
118
|
mkdirSync(stagingDir, { recursive: true });
|
|
119
119
|
|
|
120
120
|
console.log(`[build-zip] source=${opts.source}`);
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { afterEach, describe, expect, it } from "bun:test";
|
|
2
|
+
import { createHash } from "node:crypto";
|
|
3
|
+
import { existsSync, mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";
|
|
4
|
+
import { tmpdir } from "node:os";
|
|
5
|
+
import { join } from "node:path";
|
|
6
|
+
import { adapterPackageRoot, prebuiltHandler } from "../src/sdk/prebuiltHandler.js";
|
|
7
|
+
import { pinHandlerZip } from "./pin-handler-zip.js";
|
|
8
|
+
|
|
9
|
+
const realTemplate = readFileSync(
|
|
10
|
+
join(import.meta.dir, "..", "..", "..", "examples", "aws-lambda", "template.yaml"),
|
|
11
|
+
"utf-8",
|
|
12
|
+
);
|
|
13
|
+
const dirs: string[] = [];
|
|
14
|
+
|
|
15
|
+
function fixtureRepo(): { root: string; pkgDir: string } {
|
|
16
|
+
const root = mkdtempSync(join(tmpdir(), "hf-pin-zip-"));
|
|
17
|
+
dirs.push(root);
|
|
18
|
+
const pkgDir = join(root, "packages", "aws-lambda");
|
|
19
|
+
mkdirSync(join(pkgDir, "dist"), { recursive: true });
|
|
20
|
+
writeFileSync(
|
|
21
|
+
join(pkgDir, "package.json"),
|
|
22
|
+
JSON.stringify({
|
|
23
|
+
name: "@hyperframes/aws-lambda",
|
|
24
|
+
version: "9.8.7",
|
|
25
|
+
repository: { url: "https://github.com/heygen-com/hyperframes" },
|
|
26
|
+
}),
|
|
27
|
+
);
|
|
28
|
+
mkdirSync(join(root, "examples", "aws-lambda"), { recursive: true });
|
|
29
|
+
writeFileSync(join(root, "examples", "aws-lambda", "template.yaml"), realTemplate);
|
|
30
|
+
return { root, pkgDir };
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
afterEach(() => {
|
|
34
|
+
for (const dir of dirs.splice(0)) rmSync(dir, { recursive: true, force: true });
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
describe("pinHandlerZip", () => {
|
|
38
|
+
it("moves the built zip out of the package and pins its URL and sha256 for this version", () => {
|
|
39
|
+
const { root, pkgDir } = fixtureRepo();
|
|
40
|
+
const zip = Buffer.from("zip bytes");
|
|
41
|
+
writeFileSync(join(pkgDir, "dist", "handler.zip"), zip);
|
|
42
|
+
writeFileSync(join(pkgDir, "dist", "handler.zip.manifest.json"), "{}");
|
|
43
|
+
const sha256 = createHash("sha256").update(zip).digest("hex");
|
|
44
|
+
|
|
45
|
+
const manifest = pinHandlerZip(root);
|
|
46
|
+
|
|
47
|
+
expect(manifest).toEqual({
|
|
48
|
+
version: "9.8.7",
|
|
49
|
+
url: "https://github.com/heygen-com/hyperframes/releases/download/v9.8.7/hyperframes-lambda-handler.zip",
|
|
50
|
+
sha256,
|
|
51
|
+
bytes: zip.length,
|
|
52
|
+
});
|
|
53
|
+
// Nothing large is left for npm to pack.
|
|
54
|
+
expect(existsSync(join(pkgDir, "dist", "handler.zip"))).toBe(false);
|
|
55
|
+
expect(existsSync(join(pkgDir, "dist", "handler.zip.manifest.json"))).toBe(false);
|
|
56
|
+
expect(readFileSync(join(root, "dist", "hyperframes-lambda-handler.zip"))).toEqual(zip);
|
|
57
|
+
expect(readFileSync(join(root, "dist", "hyperframes-lambda-handler.sha256"), "utf-8")).toBe(
|
|
58
|
+
`${sha256} hyperframes-lambda-handler.zip\n`,
|
|
59
|
+
);
|
|
60
|
+
|
|
61
|
+
const pinned = prebuiltHandler(pkgDir);
|
|
62
|
+
expect(pinned).toEqual({
|
|
63
|
+
...manifest,
|
|
64
|
+
templatePath: join(pkgDir, "prebuilt", "template.yaml"),
|
|
65
|
+
});
|
|
66
|
+
const template = readFileSync(pinned!.templatePath, "utf-8");
|
|
67
|
+
expect(template).toContain(" CodeUri: handler.zip\n");
|
|
68
|
+
expect(template).not.toContain("packages/aws-lambda/dist/handler.zip\n");
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
it("pins a zip a previous run already attached to the release", () => {
|
|
72
|
+
const { root, pkgDir } = fixtureRepo();
|
|
73
|
+
mkdirSync(join(root, "dist"));
|
|
74
|
+
writeFileSync(join(root, "dist", "hyperframes-lambda-handler.zip"), "attached");
|
|
75
|
+
|
|
76
|
+
expect(pinHandlerZip(root).sha256).toBe(createHash("sha256").update("attached").digest("hex"));
|
|
77
|
+
expect(prebuiltHandler(pkgDir)?.sha256).toBe(pinHandlerZip(root).sha256);
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
it("refuses a template whose CodeUri it cannot rewrite", () => {
|
|
81
|
+
const { root, pkgDir } = fixtureRepo();
|
|
82
|
+
writeFileSync(join(pkgDir, "dist", "handler.zip"), "zip");
|
|
83
|
+
writeFileSync(
|
|
84
|
+
join(root, "examples", "aws-lambda", "template.yaml"),
|
|
85
|
+
"CodeUri: elsewhere.zip\n",
|
|
86
|
+
);
|
|
87
|
+
|
|
88
|
+
expect(() => pinHandlerZip(root)).toThrow(/expected exactly one/);
|
|
89
|
+
});
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
describe("prebuiltHandler", () => {
|
|
93
|
+
it("reads from its own package root", () => {
|
|
94
|
+
expect(adapterPackageRoot()).toBe(join(import.meta.dir, ".."));
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
it("is undefined when the package carries no pinned zip", () => {
|
|
98
|
+
const { pkgDir } = fixtureRepo();
|
|
99
|
+
expect(prebuiltHandler(pkgDir)).toBeUndefined();
|
|
100
|
+
});
|
|
101
|
+
});
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
#!/usr/bin/env bun
|
|
2
|
+
// Release step: writes the handler ZIP's pin (asset URL + sha256) and the SAM template into the
|
|
3
|
+
// package. A retried release run reuses the ZIP already on the release.
|
|
4
|
+
import { createHash } from "node:crypto";
|
|
5
|
+
import { existsSync, mkdirSync, readFileSync, renameSync, rmSync, writeFileSync } from "node:fs";
|
|
6
|
+
import { dirname, join, resolve } from "node:path";
|
|
7
|
+
import { fileURLToPath } from "node:url";
|
|
8
|
+
import {
|
|
9
|
+
HANDLER_MANIFEST_FILE,
|
|
10
|
+
HANDLER_ZIP_ASSET,
|
|
11
|
+
type HandlerZipManifest,
|
|
12
|
+
PREBUILT_DIR,
|
|
13
|
+
} from "../src/sdk/prebuiltHandler.js";
|
|
14
|
+
|
|
15
|
+
const CHECKOUT_CODE_URI = "CodeUri: ../../packages/aws-lambda/dist/handler.zip";
|
|
16
|
+
|
|
17
|
+
export function pinHandlerZip(repoRoot: string): HandlerZipManifest {
|
|
18
|
+
const pkgDir = join(repoRoot, "packages", "aws-lambda");
|
|
19
|
+
const pkg = JSON.parse(readFileSync(join(pkgDir, "package.json"), "utf-8")) as {
|
|
20
|
+
version: string;
|
|
21
|
+
repository: { url: string };
|
|
22
|
+
};
|
|
23
|
+
const asset = join(repoRoot, "dist", HANDLER_ZIP_ASSET);
|
|
24
|
+
const built = join(pkgDir, "dist", "handler.zip");
|
|
25
|
+
if (existsSync(built)) {
|
|
26
|
+
mkdirSync(dirname(asset), { recursive: true });
|
|
27
|
+
renameSync(built, asset);
|
|
28
|
+
rmSync(`${built}.manifest.json`, { force: true });
|
|
29
|
+
}
|
|
30
|
+
const bytes = readFileSync(asset);
|
|
31
|
+
const sha256 = createHash("sha256").update(bytes).digest("hex");
|
|
32
|
+
writeFileSync(asset.replace(/\.zip$/, ".sha256"), `${sha256} ${HANDLER_ZIP_ASSET}\n`);
|
|
33
|
+
|
|
34
|
+
const template = readFileSync(join(repoRoot, "examples", "aws-lambda", "template.yaml"), "utf-8");
|
|
35
|
+
if (template.split(CHECKOUT_CODE_URI).length !== 2) {
|
|
36
|
+
throw new Error(
|
|
37
|
+
`[pin-handler-zip] expected exactly one "${CHECKOUT_CODE_URI}" in the template`,
|
|
38
|
+
);
|
|
39
|
+
}
|
|
40
|
+
const outDir = join(pkgDir, PREBUILT_DIR);
|
|
41
|
+
mkdirSync(outDir, { recursive: true });
|
|
42
|
+
writeFileSync(
|
|
43
|
+
join(outDir, "template.yaml"),
|
|
44
|
+
template.replace(CHECKOUT_CODE_URI, "CodeUri: handler.zip"),
|
|
45
|
+
);
|
|
46
|
+
const manifest: HandlerZipManifest = {
|
|
47
|
+
version: pkg.version,
|
|
48
|
+
url: `${pkg.repository.url}/releases/download/v${pkg.version}/${HANDLER_ZIP_ASSET}`,
|
|
49
|
+
sha256,
|
|
50
|
+
bytes: bytes.length,
|
|
51
|
+
};
|
|
52
|
+
writeFileSync(join(outDir, HANDLER_MANIFEST_FILE), `${JSON.stringify(manifest, null, 2)}\n`);
|
|
53
|
+
return manifest;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
if (import.meta.main) {
|
|
57
|
+
const repoRoot = resolve(dirname(fileURLToPath(import.meta.url)), "../../..");
|
|
58
|
+
console.log(JSON.stringify(pinHandlerZip(repoRoot), null, 2));
|
|
59
|
+
}
|