Skip to content

Commit

Permalink
fix(lambda-at-edge): don't include JSON static prop files in lambda a…
Browse files Browse the repository at this point in the history
…rtefact
  • Loading branch information
danielcondemarin authored May 7, 2020
2 parents b35135a + 2811fa4 commit e516e06
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 6 deletions.
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
Empty file.

0 comments on commit e516e06

Please sign in to comment.