Skip to content
This repository was archived by the owner on May 10, 2021. It is now read-only.

Commit af532f0

Browse files
committed
Update code from serverless-next.js to v1.2.0-alpha.3
The package from which much of the code originates was originally called serverless-nextjs-component. It's now called lambda-at-edge. The npm package name is @sls-next/lambda-at-edge. This commit integrates the latest changes from that package into next-on-netlify.
1 parent 892343a commit af532f0

14 files changed

+507
-445
lines changed

lib/collectNextjsPages.js

+8-9
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
// Adapted from serverless-next.js (v1.8.0)
2-
// See original file in serverless-next.js folder.
1+
// Adapted from @sls-next/lambda-at-edge (v1.8.0)
2+
// See: https://github.com/danielcondemarin/serverless-next.js/blob/e6732895da50d11dcd296da39d35671b1bd6a33b/packages/lambda-at-edge/src/build.ts
33
// Changes:
44
// - Function is now collectNextjsPages (was prepareBuildManifests)
55
// - Function is now synchronous (used to be async)
@@ -8,13 +8,12 @@
88
// - Structure is an array of objects (was an object of objects)
99
// - Function now handles custom NextJS distDir
1010

11-
const readPagesManifest = require('./readPagesManifest')
12-
const getNetlifyRoute = require('./getNetlifyRoute')
13-
const isDynamicRoute = require("./serverless-next.js/isDynamicRoute")
14-
const expressifyDynamicRoute = require("./serverless-next.js/expressifyDynamicRoute")
15-
const pathToRegexStr = require("./serverless-next.js/pathToRegexStr")
16-
17-
const isHtmlPage = p => p.endsWith(".html");
11+
const readPagesManifest = require('./readPagesManifest')
12+
const getNetlifyRoute = require('./getNetlifyRoute')
13+
const { default: isDynamicRoute } = require("@sls-next/lambda-at-edge/dist/lib/isDynamicRoute")
14+
const { default: expressifyDynamicRoute } = require("@sls-next/lambda-at-edge/dist/lib/expressifyDynamicRoute")
15+
const { default: pathToRegexStr } = require("@sls-next/lambda-at-edge/dist/lib/pathToRegexStr")
16+
const isHtmlPage = p => p.endsWith(".html");
1817

1918
function collectNextjsPages({ nextDistDir }) {
2019
const pagesManifest = readPagesManifest({ nextDistDir });

lib/getNetlifyRoute.js

+7-6
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
1-
// Adapted from serverless-next.js (v1.9.10)
2-
// https://github.com/danielcondemarin/serverless-next.js/blob/master/packages/serverless-nextjs-component/lib/expressifyDynamicRoute.js
3-
// The original turns catch-all routes from /[...params] into /:params*
4-
// This adaptation turns catch-all routes from /[...params] into /:*
5-
// This is necessary for it to work with Netlify routing.
1+
// Adapted from @sls-next/lambda-at-edge (v1.2.0-alpha.3)
2+
// See: https://github.com/danielcondemarin/serverless-next.js/blob/57142970b08e6bc3faf0fc70749b3b0501ad7869/packages/lambda-at-edge/src/lib/expressifyDynamicRoute.ts#L4
3+
// Changes:
4+
// - The function now turns catch-all routes from /[...params] into /:*
5+
// The original turned catch-all routes from /[...params] into /:params*
6+
// The original does not work with Netlify routing.
67

78
// converts a nextjs dynamic route /[param]/ -> /:param
89
// also handles catch all routes /[...param]/ -> /:*
910
module.exports = dynamicRoute => {
1011
// replace any catch all group first
11-
let expressified = dynamicRoute.replace(/\[\.\.\.(.*)]$/, "*");
12+
const expressified = dynamicRoute.replace(/\[\.\.\.(.*)]$/, "*");
1213

1314
// now replace other dynamic route groups
1415
return expressified.replace(/\[(.*?)]/g, ":$1");

lib/readPagesManifest.js

+6-7
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
1-
// Adapted from serverless-next.js (v1.8.0)
2-
// See original file in serverless-next.js folder.
1+
// Adapted from @sls-next/lambda-at-edge (v1.2.0-alpha.3)
2+
// See: https://github.com/danielcondemarin/serverless-next.js/blob/e6732895da50d11dcd296da39d35671b1bd6a33b/packages/lambda-at-edge/src/build.ts
33
// Changes:
44
// - The function is now synchronous (it used to by async)
55
// - The function now handles custom NextJS distDir
66

7-
const { join } = require("path")
8-
const fse = require("fs-extra")
9-
const isDynamicRoute = require("./serverless-next.js/isDynamicRoute")
10-
const getSortedRoutes = require("./serverless-next.js/sortedRoutes")
11-
7+
const { join } = require("path")
8+
const fse = require("fs-extra")
9+
const { default: isDynamicRoute } = require("@sls-next/lambda-at-edge/dist/lib/isDynamicRoute")
10+
const { getSortedRoutes } = require("@sls-next/lambda-at-edge/dist/lib/sortedRoutes")
1211

1312
function readPagesManifest({ nextDistDir }) {
1413
const path = join(nextDistDir, "/serverless/pages-manifest.json");

lib/serverless-next.js/README.md

-7
This file was deleted.

lib/serverless-next.js/expressifyDynamicRoute.js

-12
This file was deleted.

lib/serverless-next.js/isDynamicRoute.js

-7
This file was deleted.

lib/serverless-next.js/pathToRegexStr.js

-9
This file was deleted.

lib/serverless-next.js/prepareBuildManifests.js

-78
This file was deleted.

lib/serverless-next.js/readPagesManifest.js

-40
This file was deleted.

lib/serverless-next.js/sortedRoutes.js

-153
This file was deleted.

0 commit comments

Comments
 (0)