@netlify/plugin-nextjs 3.9.2 → 4.0.0-beta.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +20 -55
- package/lib/constants.js +21 -0
- package/lib/helpers/cache.js +20 -0
- package/lib/helpers/config.js +119 -0
- package/lib/helpers/files.js +48 -0
- package/lib/helpers/functions.js +64 -0
- package/lib/helpers/verification.js +79 -0
- package/lib/index.js +47 -0
- package/lib/templates/getHandler.js +164 -0
- package/lib/templates/getPageResolver.js +24 -0
- package/lib/templates/ipx.js +8 -0
- package/manifest.yml +1 -1
- package/package.json +47 -54
- package/LICENSE.md +0 -7
- package/helpers/cacheBuild.js +0 -31
- package/helpers/checkNxConfig.js +0 -56
- package/helpers/copyUnstableIncludedDirs.js +0 -27
- package/helpers/doesNotNeedPlugin.js +0 -49
- package/helpers/doesSiteUseNextOnNetlify.js +0 -20
- package/helpers/getNextConfig.js +0 -46
- package/helpers/getNextRoot.js +0 -20
- package/helpers/isStaticExportProject.js +0 -20
- package/helpers/resolveNextModule.js +0 -30
- package/helpers/usesBuildCommand.js +0 -37
- package/helpers/validateNextUsage.js +0 -53
- package/helpers/verifyBuildTarget.js +0 -69
- package/index.js +0 -175
- package/src/index.js +0 -94
- package/src/lib/config.js +0 -58
- package/src/lib/constants/regex.js +0 -9
- package/src/lib/helpers/addDefaultLocaleRedirect.js +0 -25
- package/src/lib/helpers/addLocaleRedirects.js +0 -19
- package/src/lib/helpers/asyncForEach.js +0 -7
- package/src/lib/helpers/convertToBasePathRedirects.js +0 -80
- package/src/lib/helpers/copyDynamicImportChunks.js +0 -39
- package/src/lib/helpers/formatRedirectTarget.js +0 -9
- package/src/lib/helpers/getDataRouteForRoute.js +0 -30
- package/src/lib/helpers/getFilePathForRoute.js +0 -10
- package/src/lib/helpers/getI18n.js +0 -10
- package/src/lib/helpers/getNetlifyFunctionName.js +0 -38
- package/src/lib/helpers/getNetlifyRoutes.js +0 -45
- package/src/lib/helpers/getNextDistDir.js +0 -12
- package/src/lib/helpers/getNextSrcDir.js +0 -5
- package/src/lib/helpers/getPagesManifest.js +0 -19
- package/src/lib/helpers/getPrerenderManifest.js +0 -40
- package/src/lib/helpers/getPreviewModeFunctionName.js +0 -5
- package/src/lib/helpers/getRoutesManifest.js +0 -12
- package/src/lib/helpers/getSortedRedirects.js +0 -37
- package/src/lib/helpers/handleFileTracking.js +0 -61
- package/src/lib/helpers/isApiRoute.js +0 -4
- package/src/lib/helpers/isDynamicRoute.js +0 -6
- package/src/lib/helpers/isFrameworkRoute.js +0 -5
- package/src/lib/helpers/isHtmlFile.js +0 -4
- package/src/lib/helpers/isRootCatchAllRedirect.js +0 -6
- package/src/lib/helpers/isRouteInPrerenderManifest.js +0 -23
- package/src/lib/helpers/isRouteWithDataRoute.js +0 -13
- package/src/lib/helpers/isRouteWithFallback.js +0 -12
- package/src/lib/helpers/logger.js +0 -44
- package/src/lib/helpers/removeFileExtension.js +0 -4
- package/src/lib/helpers/runJobsQueue.js +0 -18
- package/src/lib/helpers/setupNetlifyFunctionForPage.js +0 -44
- package/src/lib/helpers/setupStaticFileForPage.js +0 -18
- package/src/lib/pages/api/pages.js +0 -22
- package/src/lib/pages/api/redirects.js +0 -13
- package/src/lib/pages/api/setup.js +0 -15
- package/src/lib/pages/getInitialProps/pages.js +0 -40
- package/src/lib/pages/getInitialProps/redirects.js +0 -26
- package/src/lib/pages/getInitialProps/setup.js +0 -15
- package/src/lib/pages/getServerSideProps/pages.js +0 -43
- package/src/lib/pages/getServerSideProps/redirects.js +0 -44
- package/src/lib/pages/getServerSideProps/setup.js +0 -15
- package/src/lib/pages/getStaticProps/pages.js +0 -26
- package/src/lib/pages/getStaticProps/redirects.js +0 -70
- package/src/lib/pages/getStaticProps/setup.js +0 -68
- package/src/lib/pages/getStaticPropsWithFallback/pages.js +0 -24
- package/src/lib/pages/getStaticPropsWithFallback/redirects.js +0 -51
- package/src/lib/pages/getStaticPropsWithFallback/setup.js +0 -29
- package/src/lib/pages/getStaticPropsWithRevalidate/pages.js +0 -45
- package/src/lib/pages/getStaticPropsWithRevalidate/redirects.js +0 -55
- package/src/lib/pages/getStaticPropsWithRevalidate/setup.js +0 -40
- package/src/lib/pages/withoutProps/pages.js +0 -27
- package/src/lib/pages/withoutProps/redirects.js +0 -51
- package/src/lib/pages/withoutProps/setup.js +0 -34
- package/src/lib/pages/worker.js +0 -19
- package/src/lib/steps/copyNextAssets.js +0 -31
- package/src/lib/steps/copyPublicFiles.js +0 -18
- package/src/lib/steps/prepareFolders.js +0 -39
- package/src/lib/steps/setupHeaders.js +0 -37
- package/src/lib/steps/setupImageFunction.js +0 -17
- package/src/lib/steps/setupPages.js +0 -25
- package/src/lib/steps/setupRedirects.js +0 -105
- package/src/lib/templates/getHandlerFunction.js +0 -209
- package/src/lib/templates/getTemplate.js +0 -15
- package/src/lib/templates/imageFunction.js +0 -135
- package/src/next-on-netlify.js +0 -22
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
const { logTitle } = require('../../helpers/logger')
|
|
2
|
-
|
|
3
|
-
const getPages = require('./pages')
|
|
4
|
-
|
|
5
|
-
// Create a Netlify Function for every API endpoint
|
|
6
|
-
const setup = async (functionsPath) => {
|
|
7
|
-
logTitle('💫 Setting up API endpoints as Netlify Functions in', functionsPath)
|
|
8
|
-
|
|
9
|
-
const pages = await getPages()
|
|
10
|
-
|
|
11
|
-
// Create Netlify Function job for every page
|
|
12
|
-
return pages.map(({ filePath }) => ({ type: 'function', filePath, functionsPath, isApiPage: true }))
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
module.exports = setup
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
const asyncForEach = require('../../helpers/asyncForEach')
|
|
2
|
-
const getPagesManifest = require('../../helpers/getPagesManifest')
|
|
3
|
-
const isApiRoute = require('../../helpers/isApiRoute')
|
|
4
|
-
const isFrameworkRoute = require('../../helpers/isFrameworkRoute')
|
|
5
|
-
const isHtmlFile = require('../../helpers/isHtmlFile')
|
|
6
|
-
const isRouteInPrerenderManifest = require('../../helpers/isRouteInPrerenderManifest')
|
|
7
|
-
const isRouteWithDataRoute = require('../../helpers/isRouteWithDataRoute')
|
|
8
|
-
|
|
9
|
-
const getPages = async () => {
|
|
10
|
-
// Get HTML and SSR pages and API endpoints from the NextJS pages manifest
|
|
11
|
-
const pagesManifest = await getPagesManifest()
|
|
12
|
-
|
|
13
|
-
// Collect pages
|
|
14
|
-
const pages = []
|
|
15
|
-
|
|
16
|
-
// Parse pages
|
|
17
|
-
await asyncForEach(Object.entries(pagesManifest), async ([route, filePath]) => {
|
|
18
|
-
// Ignore HTML files
|
|
19
|
-
if (isHtmlFile(filePath)) return
|
|
20
|
-
|
|
21
|
-
// Skip framework pages, such as _app and _error
|
|
22
|
-
if (isFrameworkRoute(route)) return
|
|
23
|
-
|
|
24
|
-
// Skip API endpoints
|
|
25
|
-
if (isApiRoute(route)) return
|
|
26
|
-
|
|
27
|
-
// Skip page if it is actually used with getStaticProps
|
|
28
|
-
if (await isRouteInPrerenderManifest(route)) return
|
|
29
|
-
|
|
30
|
-
// Skip page if it has a data route (because then it is a page with
|
|
31
|
-
// getServerSideProps)
|
|
32
|
-
if (await isRouteWithDataRoute(route)) return
|
|
33
|
-
|
|
34
|
-
// Add page
|
|
35
|
-
pages.push({ route, filePath })
|
|
36
|
-
})
|
|
37
|
-
return pages
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
module.exports = getPages
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
const addLocaleRedirects = require('../../helpers/addLocaleRedirects')
|
|
2
|
-
const asyncForEach = require('../../helpers/asyncForEach')
|
|
3
|
-
const getNetlifyFunctionName = require('../../helpers/getNetlifyFunctionName')
|
|
4
|
-
|
|
5
|
-
const getPages = require('./pages')
|
|
6
|
-
|
|
7
|
-
const getRedirects = async () => {
|
|
8
|
-
const redirects = []
|
|
9
|
-
const pages = await getPages()
|
|
10
|
-
|
|
11
|
-
await asyncForEach(pages, async ({ route, filePath }) => {
|
|
12
|
-
const functionName = getNetlifyFunctionName(filePath)
|
|
13
|
-
const target = `/.netlify/functions/${functionName}`
|
|
14
|
-
|
|
15
|
-
await addLocaleRedirects(redirects, route, target)
|
|
16
|
-
|
|
17
|
-
redirects.push({
|
|
18
|
-
route,
|
|
19
|
-
target,
|
|
20
|
-
})
|
|
21
|
-
})
|
|
22
|
-
|
|
23
|
-
return redirects
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
module.exports = getRedirects
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
const { logTitle } = require('../../helpers/logger')
|
|
2
|
-
|
|
3
|
-
const getPages = require('./pages')
|
|
4
|
-
|
|
5
|
-
// Create a Netlify Function for every page with getInitialProps
|
|
6
|
-
const setup = async (functionsPath) => {
|
|
7
|
-
logTitle('💫 Setting up pages with getInitialProps as Netlify Functions in', functionsPath)
|
|
8
|
-
|
|
9
|
-
const pages = await getPages()
|
|
10
|
-
|
|
11
|
-
// Create Netlify Function for every page
|
|
12
|
-
return pages.map(({ filePath }) => ({ type: 'function', filePath, functionsPath }))
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
module.exports = setup
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
const asyncForEach = require('../../helpers/asyncForEach')
|
|
2
|
-
const getPagesManifest = require('../../helpers/getPagesManifest')
|
|
3
|
-
const isApiRoute = require('../../helpers/isApiRoute')
|
|
4
|
-
const isFrameworkRoute = require('../../helpers/isFrameworkRoute')
|
|
5
|
-
const isHtmlFile = require('../../helpers/isHtmlFile')
|
|
6
|
-
const isRouteInPrerenderManifest = require('../../helpers/isRouteInPrerenderManifest')
|
|
7
|
-
const isRouteWithDataRoute = require('../../helpers/isRouteWithDataRoute')
|
|
8
|
-
|
|
9
|
-
const getPages = async () => {
|
|
10
|
-
// Collect pages
|
|
11
|
-
const pages = []
|
|
12
|
-
|
|
13
|
-
// Get HTML and SSR pages and API endpoints from the NextJS pages manifest
|
|
14
|
-
const pagesManifest = await getPagesManifest()
|
|
15
|
-
|
|
16
|
-
// Parse pages
|
|
17
|
-
await asyncForEach(Object.entries(pagesManifest), async ([route, filePath]) => {
|
|
18
|
-
// Ignore HTML files
|
|
19
|
-
if (isHtmlFile(filePath)) return
|
|
20
|
-
|
|
21
|
-
// Skip framework pages, such as _app and _error
|
|
22
|
-
if (isFrameworkRoute(route)) return
|
|
23
|
-
|
|
24
|
-
// Skip API endpoints
|
|
25
|
-
if (isApiRoute(route)) return
|
|
26
|
-
|
|
27
|
-
// Skip page if it is actually used with getStaticProps
|
|
28
|
-
const isInPrerenderManifest = await isRouteInPrerenderManifest(route)
|
|
29
|
-
if (isInPrerenderManifest) return
|
|
30
|
-
|
|
31
|
-
// Skip page if it has no data route (because then it is a page with
|
|
32
|
-
// getInitialProps)
|
|
33
|
-
const hasDataRoute = await isRouteWithDataRoute(route)
|
|
34
|
-
if (!hasDataRoute) return
|
|
35
|
-
|
|
36
|
-
// Add page
|
|
37
|
-
pages.push({ route, filePath })
|
|
38
|
-
})
|
|
39
|
-
|
|
40
|
-
return pages
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
module.exports = getPages
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
const addLocaleRedirects = require('../../helpers/addLocaleRedirects')
|
|
2
|
-
const asyncForEach = require('../../helpers/asyncForEach')
|
|
3
|
-
const getDataRouteForRoute = require('../../helpers/getDataRouteForRoute')
|
|
4
|
-
const getNetlifyFunctionName = require('../../helpers/getNetlifyFunctionName')
|
|
5
|
-
|
|
6
|
-
const getPages = require('./pages')
|
|
7
|
-
|
|
8
|
-
// getServerSideProps pages
|
|
9
|
-
//
|
|
10
|
-
// Page params {
|
|
11
|
-
// route -> '/ssr', '/ssr/[id]'
|
|
12
|
-
// filePath -> 'pages/ssr.js', 'pages/ssr/[id].js'
|
|
13
|
-
// }
|
|
14
|
-
//
|
|
15
|
-
|
|
16
|
-
const getRedirects = async () => {
|
|
17
|
-
const redirects = []
|
|
18
|
-
const pages = await getPages()
|
|
19
|
-
|
|
20
|
-
await asyncForEach(pages, async ({ route, filePath }) => {
|
|
21
|
-
const functionName = getNetlifyFunctionName(filePath)
|
|
22
|
-
const target = `/.netlify/functions/${functionName}`
|
|
23
|
-
|
|
24
|
-
await addLocaleRedirects(redirects, route, target)
|
|
25
|
-
|
|
26
|
-
// Add one redirect for the naked route
|
|
27
|
-
// i.e. /ssr
|
|
28
|
-
redirects.push({
|
|
29
|
-
route,
|
|
30
|
-
target,
|
|
31
|
-
})
|
|
32
|
-
|
|
33
|
-
// Add one redirect for the data route;
|
|
34
|
-
// pages-manifest doesn't provide the dataRoute for us so we
|
|
35
|
-
// construct it ourselves with getDataRouteForRoute
|
|
36
|
-
redirects.push({
|
|
37
|
-
route: await getDataRouteForRoute(route),
|
|
38
|
-
target,
|
|
39
|
-
})
|
|
40
|
-
})
|
|
41
|
-
return redirects
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
module.exports = getRedirects
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
const { logTitle } = require('../../helpers/logger')
|
|
2
|
-
|
|
3
|
-
const getPages = require('./pages')
|
|
4
|
-
|
|
5
|
-
// Create a Netlify Function for every page with getServerSideProps
|
|
6
|
-
const setup = async (functionsPath) => {
|
|
7
|
-
logTitle('💫 Setting up pages with getServerSideProps as Netlify Functions in', functionsPath)
|
|
8
|
-
|
|
9
|
-
const pages = await getPages()
|
|
10
|
-
|
|
11
|
-
// Create Netlify Function for every page
|
|
12
|
-
return pages.map(({ filePath }) => ({ type: 'function', filePath, functionsPath }))
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
module.exports = setup
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
const asyncForEach = require('../../helpers/asyncForEach')
|
|
2
|
-
const getPrerenderManifest = require('../../helpers/getPrerenderManifest')
|
|
3
|
-
const isRouteWithFallback = require('../../helpers/isRouteWithFallback')
|
|
4
|
-
|
|
5
|
-
// Get pages using getStaticProps
|
|
6
|
-
const getPages = async () => {
|
|
7
|
-
const { routes } = await getPrerenderManifest()
|
|
8
|
-
|
|
9
|
-
// Collect pages
|
|
10
|
-
const pages = []
|
|
11
|
-
|
|
12
|
-
await asyncForEach(Object.entries(routes), async ([route, { dataRoute, initialRevalidateSeconds, srcRoute }]) => {
|
|
13
|
-
// Ignore pages with revalidate (but no fallback), these will need to be SSRed
|
|
14
|
-
const isFallbackRoute = await isRouteWithFallback(srcRoute)
|
|
15
|
-
if (initialRevalidateSeconds && !isFallbackRoute) return
|
|
16
|
-
|
|
17
|
-
pages.push({
|
|
18
|
-
route,
|
|
19
|
-
dataRoute,
|
|
20
|
-
srcRoute,
|
|
21
|
-
})
|
|
22
|
-
})
|
|
23
|
-
return pages
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
module.exports = getPages
|
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
const { join } = require('path')
|
|
2
|
-
|
|
3
|
-
const slash = require('slash')
|
|
4
|
-
|
|
5
|
-
const addDefaultLocaleRedirect = require('../../helpers/addDefaultLocaleRedirect')
|
|
6
|
-
const asyncForEach = require('../../helpers/asyncForEach')
|
|
7
|
-
const getFilePathForRoute = require('../../helpers/getFilePathForRoute')
|
|
8
|
-
const getNetlifyFunctionName = require('../../helpers/getNetlifyFunctionName')
|
|
9
|
-
const getPreviewModeFunctionName = require('../../helpers/getPreviewModeFunctionName')
|
|
10
|
-
const isRouteWithFallback = require('../../helpers/isRouteWithFallback')
|
|
11
|
-
|
|
12
|
-
const getPages = require('./pages')
|
|
13
|
-
|
|
14
|
-
// getStaticProps pages
|
|
15
|
-
//
|
|
16
|
-
// Page params {
|
|
17
|
-
// route -> '/getStaticProps', '/getStaticProps/3'
|
|
18
|
-
// dataRoute -> '/_next/data/{BUILD_ID}/getStaticProps.json', '_next/data/{BUILD_ID}/getStaticProps/3.json'
|
|
19
|
-
// srcRoute -> null, /getStaticProps/[id]
|
|
20
|
-
// }
|
|
21
|
-
//
|
|
22
|
-
// Page params with i18n {
|
|
23
|
-
// route -> '/getStaticProps', '/en/getStaticProps/3'
|
|
24
|
-
// dataRoute -> '/_next/data/{BUILD_ID}/getStaticProps.json', '_next/data/{BUILD_ID}/en/getStaticProps/3.json'
|
|
25
|
-
// srcRoute -> null, /getStaticProps/[id]
|
|
26
|
-
// }
|
|
27
|
-
//
|
|
28
|
-
//
|
|
29
|
-
|
|
30
|
-
// Pages with getStaticProps (without fallback or revalidation) only need
|
|
31
|
-
// redirects for i18n and handling preview mode
|
|
32
|
-
const getRedirects = async () => {
|
|
33
|
-
const redirects = []
|
|
34
|
-
const pages = await getPages()
|
|
35
|
-
|
|
36
|
-
await asyncForEach(pages, async ({ route, dataRoute, srcRoute }) => {
|
|
37
|
-
const relativePath = getFilePathForRoute(srcRoute || route, 'js')
|
|
38
|
-
const filePath = slash(join('pages', relativePath))
|
|
39
|
-
const functionName = getNetlifyFunctionName(filePath)
|
|
40
|
-
const isODB = await isRouteWithFallback(srcRoute)
|
|
41
|
-
|
|
42
|
-
// Preview mode conditions
|
|
43
|
-
const conditions = ['Cookie=__prerender_bypass,__next_preview_data']
|
|
44
|
-
// ODB pages' preview mode needs a special flagged standard function because
|
|
45
|
-
// their default function (an ODB) is not functional for preview mode
|
|
46
|
-
const target = `/.netlify/functions/${functionName}`
|
|
47
|
-
const previewModeTarget = isODB ? `/.netlify/functions/${getPreviewModeFunctionName(functionName)}` : target
|
|
48
|
-
const previewModeRedirect = { conditions, force: true, target: previewModeTarget }
|
|
49
|
-
|
|
50
|
-
// Add a preview mode redirect for the standard route
|
|
51
|
-
redirects.push({
|
|
52
|
-
route,
|
|
53
|
-
...previewModeRedirect,
|
|
54
|
-
})
|
|
55
|
-
|
|
56
|
-
// Add a preview mode redirect for the data route, same conditions
|
|
57
|
-
redirects.push({
|
|
58
|
-
route: dataRoute,
|
|
59
|
-
...previewModeRedirect,
|
|
60
|
-
})
|
|
61
|
-
|
|
62
|
-
// Preview mode default locale redirect must precede normal default locale redirect
|
|
63
|
-
await addDefaultLocaleRedirect(redirects, route, target, { conditions, force: true })
|
|
64
|
-
await addDefaultLocaleRedirect(redirects, route)
|
|
65
|
-
})
|
|
66
|
-
|
|
67
|
-
return redirects
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
module.exports = getRedirects
|
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
const { join } = require('path')
|
|
2
|
-
|
|
3
|
-
const { copySync } = require('fs-extra')
|
|
4
|
-
const slash = require('slash')
|
|
5
|
-
|
|
6
|
-
const getFilePathForRoute = require('../../helpers/getFilePathForRoute')
|
|
7
|
-
const getI18n = require('../../helpers/getI18n')
|
|
8
|
-
const getNextDistDir = require('../../helpers/getNextDistDir')
|
|
9
|
-
const isRouteWithFallback = require('../../helpers/isRouteWithFallback')
|
|
10
|
-
const { logTitle } = require('../../helpers/logger')
|
|
11
|
-
|
|
12
|
-
const getPages = require('./pages')
|
|
13
|
-
|
|
14
|
-
// Copy pre-rendered SSG pages
|
|
15
|
-
const setup = async ({ functionsPath, publishPath }) => {
|
|
16
|
-
logTitle('🔥 Copying pre-rendered pages with getStaticProps and JSON data to', publishPath)
|
|
17
|
-
// Keep track of the functions that have been set up, so that we do not set up
|
|
18
|
-
// a function for the same file path twice
|
|
19
|
-
const filePathsDone = new Set()
|
|
20
|
-
const pages = await getPages()
|
|
21
|
-
const nextDistDir = await getNextDistDir()
|
|
22
|
-
const i18n = await getI18n()
|
|
23
|
-
|
|
24
|
-
const jobs = []
|
|
25
|
-
|
|
26
|
-
await Promise.all(
|
|
27
|
-
pages.map(async ({ route, dataRoute, srcRoute }) => {
|
|
28
|
-
// Copy pre-rendered HTML page
|
|
29
|
-
const htmlPath = getFilePathForRoute(route, 'html')
|
|
30
|
-
|
|
31
|
-
jobs.push({ type: 'static', inputPath: htmlPath, publishPath })
|
|
32
|
-
|
|
33
|
-
// Copy page's JSON data
|
|
34
|
-
const jsonPath = getFilePathForRoute(route, 'json')
|
|
35
|
-
jobs.push({
|
|
36
|
-
type: 'static',
|
|
37
|
-
inputPath: jsonPath,
|
|
38
|
-
outputPath: dataRoute,
|
|
39
|
-
publishPath,
|
|
40
|
-
})
|
|
41
|
-
|
|
42
|
-
// HACK: If i18n, 404.html needs to be at the top level of the publish directory
|
|
43
|
-
if (i18n.defaultLocale && route === `/${i18n.defaultLocale}/404`) {
|
|
44
|
-
copySync(join(nextDistDir, 'serverless', 'pages', htmlPath), join(publishPath, '404.html'))
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
// Set up the Netlify function (this is ONLY for preview mode)
|
|
48
|
-
const relativePath = getFilePathForRoute(srcRoute || route, 'js')
|
|
49
|
-
const filePath = slash(join('pages', relativePath))
|
|
50
|
-
|
|
51
|
-
// Skip if we have already set up a function for this file
|
|
52
|
-
|
|
53
|
-
if (filePathsDone.has(filePath)) {
|
|
54
|
-
return
|
|
55
|
-
}
|
|
56
|
-
filePathsDone.add(filePath)
|
|
57
|
-
|
|
58
|
-
// or if the source route has a fallback (handled by getStaticPropsWithFallback)
|
|
59
|
-
if (await isRouteWithFallback(srcRoute)) {
|
|
60
|
-
return
|
|
61
|
-
}
|
|
62
|
-
jobs.push({ type: 'function', filePath, functionsPath })
|
|
63
|
-
}),
|
|
64
|
-
)
|
|
65
|
-
return jobs
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
module.exports = setup
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
const getPrerenderManifest = require('../../helpers/getPrerenderManifest')
|
|
2
|
-
|
|
3
|
-
// Get pages using getStaticProps
|
|
4
|
-
const getPages = async () => {
|
|
5
|
-
const { dynamicRoutes } = await getPrerenderManifest()
|
|
6
|
-
|
|
7
|
-
// Collect pages
|
|
8
|
-
const pages = []
|
|
9
|
-
|
|
10
|
-
Object.entries(dynamicRoutes).forEach(([route, { dataRoute, fallback }]) => {
|
|
11
|
-
// Skip pages without fallback
|
|
12
|
-
if (fallback === false) return
|
|
13
|
-
|
|
14
|
-
// Add the page
|
|
15
|
-
pages.push({
|
|
16
|
-
route,
|
|
17
|
-
dataRoute,
|
|
18
|
-
})
|
|
19
|
-
})
|
|
20
|
-
|
|
21
|
-
return pages
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
module.exports = getPages
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
const { join } = require('path')
|
|
2
|
-
|
|
3
|
-
const slash = require('slash')
|
|
4
|
-
|
|
5
|
-
const { PREVIEW_MODE_COOKIES } = require('../../config')
|
|
6
|
-
const addLocaleRedirects = require('../../helpers/addLocaleRedirects')
|
|
7
|
-
const asyncForEach = require('../../helpers/asyncForEach')
|
|
8
|
-
const getFilePathForRoute = require('../../helpers/getFilePathForRoute')
|
|
9
|
-
const getNetlifyFunctionName = require('../../helpers/getNetlifyFunctionName')
|
|
10
|
-
const getPreviewModeFunctionName = require('../../helpers/getPreviewModeFunctionName')
|
|
11
|
-
|
|
12
|
-
const getPages = require('./pages')
|
|
13
|
-
|
|
14
|
-
const getRedirects = async () => {
|
|
15
|
-
const redirects = []
|
|
16
|
-
const pages = await getPages()
|
|
17
|
-
|
|
18
|
-
await asyncForEach(pages, async ({ route, dataRoute }) => {
|
|
19
|
-
const relativePath = getFilePathForRoute(route, 'js')
|
|
20
|
-
const filePath = slash(join('pages', relativePath))
|
|
21
|
-
const functionName = getNetlifyFunctionName(filePath)
|
|
22
|
-
const target = `/.netlify/functions/${functionName}`
|
|
23
|
-
const previewModeTarget = `/.netlify/functions/${getPreviewModeFunctionName(functionName)}`
|
|
24
|
-
|
|
25
|
-
await addLocaleRedirects(redirects, route, target)
|
|
26
|
-
|
|
27
|
-
// Add a redirect for preview mode pointing to the standard function
|
|
28
|
-
redirects.push({
|
|
29
|
-
route,
|
|
30
|
-
target: previewModeTarget,
|
|
31
|
-
conditions: PREVIEW_MODE_COOKIES,
|
|
32
|
-
force: true,
|
|
33
|
-
specialPreviewMode: true,
|
|
34
|
-
})
|
|
35
|
-
|
|
36
|
-
// Add one redirect pointing to the ODB
|
|
37
|
-
redirects.push({
|
|
38
|
-
route,
|
|
39
|
-
target,
|
|
40
|
-
})
|
|
41
|
-
|
|
42
|
-
// Add one redirect for the data route
|
|
43
|
-
redirects.push({
|
|
44
|
-
route: dataRoute,
|
|
45
|
-
target,
|
|
46
|
-
})
|
|
47
|
-
})
|
|
48
|
-
return redirects
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
module.exports = getRedirects
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
const { join } = require('path')
|
|
2
|
-
|
|
3
|
-
const slash = require('slash')
|
|
4
|
-
|
|
5
|
-
const getFilePathForRoute = require('../../helpers/getFilePathForRoute')
|
|
6
|
-
const { logTitle } = require('../../helpers/logger')
|
|
7
|
-
|
|
8
|
-
const getPages = require('./pages')
|
|
9
|
-
|
|
10
|
-
// Create a Netlify Function for every page with getStaticProps and fallback
|
|
11
|
-
const setup = async (functionsPath) => {
|
|
12
|
-
logTitle('💫 Setting up pages with getStaticProps and fallback: true', 'as Netlify Functions in', functionsPath)
|
|
13
|
-
|
|
14
|
-
const pages = await getPages()
|
|
15
|
-
|
|
16
|
-
// Create Netlify Function for every page
|
|
17
|
-
return pages.reduce((jobs, { route }) => {
|
|
18
|
-
const relativePath = getFilePathForRoute(route, 'js')
|
|
19
|
-
const filePath = slash(join('pages', relativePath))
|
|
20
|
-
// Need two different functions - one ODB for normal pages, one standard for preview mode
|
|
21
|
-
return [
|
|
22
|
-
...jobs,
|
|
23
|
-
{ type: 'function', filePath, functionsPath, isODB: true },
|
|
24
|
-
{ type: 'function', filePath, functionsPath, forFallbackPreviewMode: true },
|
|
25
|
-
]
|
|
26
|
-
}, [])
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
module.exports = setup
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
const { yellowBright } = require('chalk')
|
|
2
|
-
|
|
3
|
-
const asyncForEach = require('../../helpers/asyncForEach')
|
|
4
|
-
const getPrerenderManifest = require('../../helpers/getPrerenderManifest')
|
|
5
|
-
const isRouteWithFallback = require('../../helpers/isRouteWithFallback')
|
|
6
|
-
|
|
7
|
-
// Get pages using getStaticProps
|
|
8
|
-
const getPages = async () => {
|
|
9
|
-
const { routes } = await getPrerenderManifest()
|
|
10
|
-
|
|
11
|
-
// Collect pages
|
|
12
|
-
const pages = []
|
|
13
|
-
|
|
14
|
-
let usesRevalidateAtLeastOnce = false
|
|
15
|
-
|
|
16
|
-
await asyncForEach(Object.entries(routes), async ([route, { dataRoute, srcRoute, initialRevalidateSeconds }]) => {
|
|
17
|
-
// Skip pages without revalidate, these are handled by getStaticProps/pages
|
|
18
|
-
if (!initialRevalidateSeconds) return
|
|
19
|
-
|
|
20
|
-
usesRevalidateAtLeastOnce = true
|
|
21
|
-
|
|
22
|
-
// Skip pages with fallback, these are handled by
|
|
23
|
-
// getStaticPropsWithFallback/pages
|
|
24
|
-
if (await isRouteWithFallback(srcRoute)) return
|
|
25
|
-
|
|
26
|
-
// Add the page
|
|
27
|
-
pages.push({
|
|
28
|
-
route,
|
|
29
|
-
srcRoute,
|
|
30
|
-
dataRoute,
|
|
31
|
-
})
|
|
32
|
-
})
|
|
33
|
-
|
|
34
|
-
if (usesRevalidateAtLeastOnce) {
|
|
35
|
-
console.log(
|
|
36
|
-
yellowBright(
|
|
37
|
-
`Warning: It looks like you're using the 'revalidate' flag in one of your Next.js pages. Please read our docs about ISR on Netlify: https://ntl.fyi/next-isr-info`,
|
|
38
|
-
),
|
|
39
|
-
)
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
return pages
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
module.exports = getPages
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
const { join } = require('path')
|
|
2
|
-
|
|
3
|
-
const slash = require('slash')
|
|
4
|
-
|
|
5
|
-
const addDefaultLocaleRedirect = require('../../helpers/addDefaultLocaleRedirect')
|
|
6
|
-
const asyncForEach = require('../../helpers/asyncForEach')
|
|
7
|
-
const getFilePathForRoute = require('../../helpers/getFilePathForRoute')
|
|
8
|
-
const getNetlifyFunctionName = require('../../helpers/getNetlifyFunctionName')
|
|
9
|
-
|
|
10
|
-
const getPages = require('./pages')
|
|
11
|
-
|
|
12
|
-
// getStaticProps with revalidate pages
|
|
13
|
-
//
|
|
14
|
-
// Page params: {
|
|
15
|
-
// route -> '/getStaticProps', '/getStaticProps/3'
|
|
16
|
-
// dataRoute -> '/_next/data/{BUILD_ID}/getStaticProps.json', '_next/data/{BUILD_ID}/getStaticProps/3.json'
|
|
17
|
-
// srcRoute -> null, /getStaticProps/[id]
|
|
18
|
-
// }
|
|
19
|
-
//
|
|
20
|
-
// Page params in i18n {
|
|
21
|
-
// route -> '/getStaticProps', '/en/getStaticProps/3'
|
|
22
|
-
// dataRoute -> '/_next/data/{BUILD_ID}/getStaticProps.json', '_next/data/{BUILD_ID}/en/getStaticProps/3.json'
|
|
23
|
-
// srcRoute -> null, /getStaticProps/[id]
|
|
24
|
-
// }
|
|
25
|
-
//
|
|
26
|
-
|
|
27
|
-
const getRedirects = async () => {
|
|
28
|
-
const redirects = []
|
|
29
|
-
const pages = await getPages()
|
|
30
|
-
|
|
31
|
-
await asyncForEach(pages, async ({ route, srcRoute, dataRoute }) => {
|
|
32
|
-
const relativePath = getFilePathForRoute(srcRoute || route, 'js')
|
|
33
|
-
const filePath = slash(join('pages', relativePath))
|
|
34
|
-
const functionName = getNetlifyFunctionName(filePath)
|
|
35
|
-
const target = `/.netlify/functions/${functionName}`
|
|
36
|
-
|
|
37
|
-
// Add one redirect for the page
|
|
38
|
-
redirects.push({
|
|
39
|
-
route,
|
|
40
|
-
target,
|
|
41
|
-
})
|
|
42
|
-
|
|
43
|
-
// Add one redirect for the data route
|
|
44
|
-
redirects.push({
|
|
45
|
-
route: dataRoute,
|
|
46
|
-
target,
|
|
47
|
-
})
|
|
48
|
-
|
|
49
|
-
await addDefaultLocaleRedirect(redirects, route, target)
|
|
50
|
-
})
|
|
51
|
-
|
|
52
|
-
return redirects
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
module.exports = getRedirects
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
const { join } = require('path')
|
|
2
|
-
|
|
3
|
-
const slash = require('slash')
|
|
4
|
-
|
|
5
|
-
const getFilePathForRoute = require('../../helpers/getFilePathForRoute')
|
|
6
|
-
const { logTitle } = require('../../helpers/logger')
|
|
7
|
-
|
|
8
|
-
const getPages = require('./pages')
|
|
9
|
-
|
|
10
|
-
// Create a Netlify Function for every page with getStaticProps and revalidate
|
|
11
|
-
const setup = async (functionsPath) => {
|
|
12
|
-
logTitle(
|
|
13
|
-
'💫 Setting up pages with getStaticProps and revalidation interval',
|
|
14
|
-
'as Netlify Functions in',
|
|
15
|
-
functionsPath,
|
|
16
|
-
)
|
|
17
|
-
|
|
18
|
-
// Keep track of the functions that have been set up, so that we do not set up
|
|
19
|
-
// a function for the same file path twice
|
|
20
|
-
const filePathsDone = new Set()
|
|
21
|
-
|
|
22
|
-
const pages = await getPages()
|
|
23
|
-
|
|
24
|
-
// Create Netlify Function for every page
|
|
25
|
-
|
|
26
|
-
const jobs = []
|
|
27
|
-
|
|
28
|
-
pages.forEach(({ route, srcRoute }) => {
|
|
29
|
-
const relativePath = getFilePathForRoute(srcRoute || route, 'js')
|
|
30
|
-
const filePath = slash(join('pages', relativePath))
|
|
31
|
-
if (filePathsDone.has(filePath)) {
|
|
32
|
-
return
|
|
33
|
-
}
|
|
34
|
-
filePathsDone.add(filePath)
|
|
35
|
-
jobs.push({ type: 'function', filePath, functionsPath })
|
|
36
|
-
})
|
|
37
|
-
return jobs
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
module.exports = setup
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
const asyncForEach = require('../../helpers/asyncForEach')
|
|
2
|
-
const getPagesManifest = require('../../helpers/getPagesManifest')
|
|
3
|
-
const isHtmlFile = require('../../helpers/isHtmlFile')
|
|
4
|
-
const isRouteInPrerenderManifest = require('../../helpers/isRouteInPrerenderManifest')
|
|
5
|
-
|
|
6
|
-
// Collect pages
|
|
7
|
-
const getPages = async () => {
|
|
8
|
-
const pages = []
|
|
9
|
-
|
|
10
|
-
// Get HTML and SSR pages and API endpoints from the NextJS pages manifest
|
|
11
|
-
const pagesManifest = await getPagesManifest()
|
|
12
|
-
|
|
13
|
-
// Parse HTML pages
|
|
14
|
-
await asyncForEach(Object.entries(pagesManifest), async ([route, filePath]) => {
|
|
15
|
-
// Ignore non-HTML files
|
|
16
|
-
if (!isHtmlFile(filePath)) return
|
|
17
|
-
|
|
18
|
-
// Skip page if it is actually used with getStaticProps
|
|
19
|
-
if (await isRouteInPrerenderManifest(route)) return
|
|
20
|
-
|
|
21
|
-
// Add the HTML page
|
|
22
|
-
pages.push({ route, filePath })
|
|
23
|
-
})
|
|
24
|
-
return pages
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
module.exports = getPages
|