Skip to content
This repository was archived by the owner on Jan 28, 2025. It is now read-only.

Commit e516e06

Browse files
fix(lambda-at-edge): don't include JSON static prop files in lambda artefact
2 parents b35135a + 2811fa4 commit e516e06

File tree

4 files changed

+16
-6
lines changed

4 files changed

+16
-6
lines changed

packages/lambda-at-edge/src/build.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -124,10 +124,16 @@ class Builder {
124124
join(this.nextConfigDir, ".next/serverless/pages"),
125125
join(this.outputDir, DEFAULT_LAMBDA_CODE_DIR, "pages"),
126126
{
127-
// skip api pages from default lambda code
128-
filter: file => {
129-
const isHTMLPage = path.extname(file) === ".html";
130-
return pathToPosix(file).indexOf("pages/api") === -1 && !isHTMLPage;
127+
filter: (file: string) => {
128+
const isNotPrerenderedHTMLPage = path.extname(file) !== ".html";
129+
const isNotStaticPropsJSONFile = path.extname(file) !== ".json";
130+
const isNotApiPage = pathToPosix(file).indexOf("pages/api") === -1;
131+
132+
return (
133+
isNotApiPage &&
134+
isNotPrerenderedHTMLPage &&
135+
isNotStaticPropsJSONFile
136+
);
131137
}
132138
}
133139
)

packages/lambda-at-edge/tests/build.test.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ describe("Builder Tests", () => {
152152

153153
describe("Default Handler Artefact Files", () => {
154154
it("copies build files", async () => {
155-
expect.assertions(5);
155+
expect.assertions(7);
156156

157157
const files = await fse.readdir(
158158
join(outputDir, `${DEFAULT_LAMBDA_CODE_DIR}`)
@@ -185,7 +185,11 @@ describe("Builder Tests", () => {
185185
// api pages should not be included in the default lambda
186186
expect(apiDirExists).toEqual(false);
187187

188-
// html pages should not be included in the default lambda
188+
// HTML Prerendered pages or JSON static props files
189+
// should not be included in the default lambda
190+
expect(pages).not.toContain(["blog.json"]);
191+
expect(pages).not.toContain(["about.html", "terms.html"]);
192+
189193
expect(pages).toEqual(["_error.js", "blog.js", "customers"]);
190194
expect(customerPages).toEqual(["[...catchAll].js", "[post].js"]);
191195
});

packages/lambda-at-edge/tests/fixtures/app-with-no-static-or-public-dir/.next/serverless/pages/blog.json

Whitespace-only changes.

packages/lambda-at-edge/tests/fixtures/simple-app/.next/serverless/pages/blog.json

Whitespace-only changes.

0 commit comments

Comments
 (0)