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

Fix the default-lambda filter by excluding the JSON files too #391

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
14 changes: 10 additions & 4 deletions packages/lambda-at-edge/src/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,16 @@ class Builder {
join(this.nextConfigDir, ".next/serverless/pages"),
join(this.outputDir, DEFAULT_LAMBDA_CODE_DIR, "pages"),
{
// skip api pages from default lambda code
filter: file => {
const isHTMLPage = path.extname(file) === ".html";
return pathToPosix(file).indexOf("pages/api") === -1 && !isHTMLPage;
filter: (file: string) => {
const isNotPrerenderedHTMLPage = path.extname(file) !== ".html";
const isNotStaticPropsJSONFile = path.extname(file) !== ".json";
const isNotApiPage = pathToPosix(file).indexOf("pages/api") === -1;

return (
isNotApiPage &&
isNotPrerenderedHTMLPage &&
isNotStaticPropsJSONFile
);
}
}
)
Expand Down
8 changes: 6 additions & 2 deletions packages/lambda-at-edge/tests/build.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ describe("Builder Tests", () => {

describe("Default Handler Artefact Files", () => {
it("copies build files", async () => {
expect.assertions(5);
expect.assertions(7);

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

// html pages should not be included in the default lambda
// HTML Prerendered pages or JSON static props files
// should not be included in the default lambda
expect(pages).not.toContain(["blog.json"]);
expect(pages).not.toContain(["about.html", "terms.html"]);

expect(pages).toEqual(["_error.js", "blog.js", "customers"]);
expect(customerPages).toEqual(["[...catchAll].js", "[post].js"]);
});
Expand Down