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
1 change: 1 addition & 0 deletions packages/aws-lambda/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"scripts/",
"!scripts/*.test.ts",
"!scripts/pin-handler-zip.ts",
"!scripts/stage-arm64-image.ts",
"README.md"
],
"type": "module",
Expand Down
54 changes: 54 additions & 0 deletions scripts/verify-packed-manifests.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ import {
mkdtempSync,
readdirSync,
readFileSync,
renameSync,
rmSync,
statSync,
truncateSync,
writeFileSync,
} from "node:fs";
import { extname, join, posix } from "node:path";
Expand Down Expand Up @@ -605,15 +607,67 @@ function packAndVerifyWorkspace(workspace, packDir) {
return { workspace, filename, packedPackage };
}

const LAMBDA_PIN_ASSETS = [
{ asset: "hyperframes-lambda-handler.zip", flags: [] },
{ asset: "hyperframes-lambda-video-arm64.oci.tar", flags: ["--video-image"] },
];

// The publish job pins the Lambda release assets before this check. Anywhere else, sparse stand-ins of release
// size go through the same pin script, so the size check packs the file list a release publishes. Files a
// developer already built (zip, image, their hashes and pins) are moved aside first and put back by the cleanup.
function pinStandInLambdaAssets() {
const lambda = join(PACKAGES_DIR, "aws-lambda");
const prebuilt = join(lambda, "prebuilt");
if (existsSync(join(prebuilt, "handler-zip.json"))) return () => {};
const dist = join(ROOT, "dist");
mkdirSync(dist, { recursive: true });
const built = join(lambda, "dist", "handler.zip");
const stands = LAMBDA_PIN_ASSETS.flatMap(({ asset }) => [
join(dist, asset),
join(dist, `${asset.split(".")[0]}.sha256`),
]);
const pins = [join(prebuilt, "handler-zip.json"), join(prebuilt, "video-image.json")];
const aside = mkdtempSync(join(dist, "aside-"));
const moved = [built, `${built}.manifest.json`, ...stands, ...pins]
.filter((path) => existsSync(path))
.map((path, index) => {
const to = join(aside, String(index));
renameSync(path, to);
return [path, to];
});
const restore = () => {
[...stands, ...pins].forEach((path) => rmSync(path, { force: true }));
moved.forEach(([path, to]) => renameSync(to, path));
rmSync(aside, { force: true, recursive: true });
};
try {
for (const { asset, flags } of LAMBDA_PIN_ASSETS) {
const path = join(dist, asset);
writeFileSync(path, "");
truncateSync(path, 150_000_000);
execFileSync("bun", [join(lambda, "scripts", "pin-handler-zip.ts"), ...flags], {
cwd: ROOT,
stdio: "ignore",
});
}
} catch (error) {
restore();
throw error;
}
return restore;
}

function main() {
const packDir = mkdtempSync(join(tmpdir(), "hyperframes-pack-"));
const unpinLambda = pinStandInLambdaAssets();
try {
const packedWorkspaces = listWorkspacePackageDirs()
.map((workspace) => packAndVerifyWorkspace(workspace, packDir))
.filter(Boolean);
verifyPackedConsumer(packDir, packedWorkspaces);
verifyPackageSizes(packedWorkspaces);
} finally {
unpinLambda();
rmSync(packDir, { force: true, recursive: true });
}
}
Expand Down
Loading