Skip to content

Write HTML. Render video. Built for agents.

fix(lambda): define dirname in handler bundle

Miguel Ángelf999b40d73aa
diff --git a/packages/aws-lambda/scripts/build-zip.test.ts b/packages/aws-lambda/scripts/build-zip.test.ts
new file mode 100644
index 0000000000..f2c5c3a94b
--- /dev/null
+++ b/packages/aws-lambda/scripts/build-zip.test.ts
@@ -0,0 +1,14 @@
+import { describe, expect, it } from "bun:test";
+import { readFileSync } from "node:fs";
+import { fileURLToPath } from "node:url";
+
+describe("build-zip handler banner", () => {
+ it("defines CommonJS path globals for inlined CJS dependencies", () => {
+ const source = readFileSync(fileURLToPath(new URL("./build-zip.ts", import.meta.url)), "utf8");
+
+ expect(source).toContain('import { fileURLToPath as __hf_fileURLToPath } from "url";');
+ expect(source).toContain('import { dirname as __hf_dirname } from "path";');
+ expect(source).toContain("const __filename = __hf_fileURLToPath(import.meta.url);");
+ expect(source).toContain("const __dirname = __hf_dirname(__filename);");
+ });
+});
diff --git a/packages/aws-lambda/scripts/build-zip.ts b/packages/aws-lambda/scripts/build-zip.ts
index 0586c3ca63..09db81dbfe 100644
--- a/packages/aws-lambda/scripts/build-zip.ts
+++ b/packages/aws-lambda/scripts/build-zip.ts
@@ -252,6 +252,10 @@ async function bundleHandler(stagingDir: string): Promise<void> {
"// hyperframes-aws-lambda handler bundle",
'import { createRequire as __hf_createRequire } from "module";',
"const require = __hf_createRequire(import.meta.url);",
+ 'import { fileURLToPath as __hf_fileURLToPath } from "url";',
+ 'import { dirname as __hf_dirname } from "path";',
+ "const __filename = __hf_fileURLToPath(import.meta.url);",
+ "const __dirname = __hf_dirname(__filename);",
].join("\n"),
},
});