@netlify/plugin-nextjs 3.9.1 → 4.0.0-beta.11
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 +32 -51
- package/lib/constants.js +21 -0
- package/lib/helpers/cache.js +20 -0
- package/lib/helpers/config.js +174 -0
- package/lib/helpers/files.js +187 -0
- package/lib/helpers/functions.js +65 -0
- package/lib/helpers/verification.js +93 -0
- package/lib/index.js +50 -0
- package/lib/templates/getHandler.js +161 -0
- package/lib/templates/getPageResolver.js +24 -0
- package/lib/templates/handlerUtils.js +36 -0
- package/lib/templates/ipx.js +8 -0
- package/manifest.yml +1 -1
- package/package.json +50 -55
- 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,13 +0,0 @@
|
|
|
1
|
-
const getRoutesManifest = require('./getRoutesManifest')
|
|
2
|
-
|
|
3
|
-
// Return true if the route has a data route in the routes manifest
|
|
4
|
-
const isRouteWithDataRoute = async (route) => {
|
|
5
|
-
const { dataRoutes } = await getRoutesManifest()
|
|
6
|
-
|
|
7
|
-
// If no data routes exist, return false
|
|
8
|
-
if (dataRoutes == null) return false
|
|
9
|
-
|
|
10
|
-
return dataRoutes.find((dataRoute) => dataRoute.page === route)
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
module.exports = isRouteWithDataRoute
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
const getPrerenderManifest = require('./getPrerenderManifest')
|
|
2
|
-
|
|
3
|
-
const isRouteWithFallback = async (route) => {
|
|
4
|
-
if (!route) return false
|
|
5
|
-
|
|
6
|
-
const { dynamicRoutes } = await getPrerenderManifest()
|
|
7
|
-
|
|
8
|
-
// Fallback "blocking" routes will have fallback: null in manifest
|
|
9
|
-
return dynamicRoutes[route] && dynamicRoutes[route].fallback !== false
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
module.exports = isRouteWithFallback
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
// Helpers for writing info to console.log
|
|
2
|
-
const { program } = require('commander')
|
|
3
|
-
|
|
4
|
-
// Number of items processed in current build step
|
|
5
|
-
let itemsCount = 0
|
|
6
|
-
|
|
7
|
-
// Format in bold
|
|
8
|
-
const logTitle = (...args) => {
|
|
9
|
-
// Finish previous log section
|
|
10
|
-
finishLogForBuildStep()
|
|
11
|
-
|
|
12
|
-
// Print title
|
|
13
|
-
log(`\x1b[1m${args.join(' ')}\x1b[22m`)
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
// Indent by three spaces
|
|
17
|
-
const logItem = (...args) => {
|
|
18
|
-
// Display item if within max log lines
|
|
19
|
-
if (itemsCount < program.maxLogLines) log(' ', ...args)
|
|
20
|
-
|
|
21
|
-
itemsCount += 1
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
// Just console.log
|
|
25
|
-
const log = (...args) => console.log(...args)
|
|
26
|
-
|
|
27
|
-
// Finish log section: Write a single line for any suppressed/hidden items
|
|
28
|
-
// and reset the item counter
|
|
29
|
-
const finishLogForBuildStep = () => {
|
|
30
|
-
// Display number of suppressed log lines
|
|
31
|
-
if (itemsCount > program.maxLogLines) {
|
|
32
|
-
const hiddenLines = itemsCount - program.maxLogLines
|
|
33
|
-
log(' ', '+', hiddenLines, 'more', '(run next-on-netlify with --max-log-lines XX to', 'show more or fewer lines)')
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
// Reset counter
|
|
37
|
-
itemsCount = 0
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
module.exports = {
|
|
41
|
-
logTitle,
|
|
42
|
-
logItem,
|
|
43
|
-
log,
|
|
44
|
-
}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
const os = require('os')
|
|
2
|
-
|
|
3
|
-
const fastq = require('fastq')
|
|
4
|
-
|
|
5
|
-
const { processPage } = require('../pages/worker')
|
|
6
|
-
|
|
7
|
-
// TODO: benchmark a large site to find a good value for this
|
|
8
|
-
const PAGE_CONCURRENCY = 4
|
|
9
|
-
|
|
10
|
-
const runJobsQueue = (jobs) => {
|
|
11
|
-
console.log(`Building ${jobs.length} pages`)
|
|
12
|
-
|
|
13
|
-
const queue = fastq.promise(processPage, PAGE_CONCURRENCY)
|
|
14
|
-
|
|
15
|
-
return Promise.all(jobs.map((job) => queue.push(job)))
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
module.exports = runJobsQueue
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
const { join } = require('path')
|
|
2
|
-
|
|
3
|
-
const { copySync, writeFile, ensureDir, copy } = require('fs-extra')
|
|
4
|
-
|
|
5
|
-
const { TEMPLATES_DIR } = require('../config')
|
|
6
|
-
const getTemplate = require('../templates/getTemplate')
|
|
7
|
-
|
|
8
|
-
const copyDynamicImportChunks = require('./copyDynamicImportChunks')
|
|
9
|
-
const getNetlifyFunctionName = require('./getNetlifyFunctionName')
|
|
10
|
-
const getNextDistDir = require('./getNextDistDir')
|
|
11
|
-
const getPreviewModeFunctionName = require('./getPreviewModeFunctionName')
|
|
12
|
-
const { logItem } = require('./logger')
|
|
13
|
-
|
|
14
|
-
// Create a Netlify Function for the page with the given file path
|
|
15
|
-
const setupNetlifyFunctionForPage = async ({ filePath, functionsPath, isApiPage, isODB, forFallbackPreviewMode }) => {
|
|
16
|
-
// Set function name based on file path
|
|
17
|
-
const defaultFunctionName = getNetlifyFunctionName(filePath, isApiPage)
|
|
18
|
-
const functionName = forFallbackPreviewMode ? getPreviewModeFunctionName(defaultFunctionName) : defaultFunctionName
|
|
19
|
-
const functionDirectory = join(functionsPath, functionName)
|
|
20
|
-
|
|
21
|
-
await ensureDir(functionDirectory)
|
|
22
|
-
|
|
23
|
-
if (isApiPage && functionName.endsWith('-background')) {
|
|
24
|
-
logItem(`👁 Setting up API page ${functionName} as a Netlify background function`)
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
// Write entry point to function directory
|
|
28
|
-
const entryPointPath = join(functionDirectory, `${functionName}.js`)
|
|
29
|
-
await writeFile(entryPointPath, getTemplate({ filePath, isODB }))
|
|
30
|
-
|
|
31
|
-
// Copy function helper
|
|
32
|
-
await copy(join(TEMPLATES_DIR, 'getHandlerFunction.js'), join(functionDirectory, 'getHandlerFunction.js'))
|
|
33
|
-
|
|
34
|
-
// Copy any dynamic import chunks
|
|
35
|
-
await copyDynamicImportChunks(functionDirectory)
|
|
36
|
-
|
|
37
|
-
// Copy page to our custom path
|
|
38
|
-
const nextPageCopyPath = join(functionDirectory, 'nextPage', filePath)
|
|
39
|
-
const nextDistDir = await getNextDistDir()
|
|
40
|
-
|
|
41
|
-
copySync(join(nextDistDir, 'serverless', filePath), nextPageCopyPath)
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
module.exports = setupNetlifyFunctionForPage
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
const { join } = require('path')
|
|
2
|
-
|
|
3
|
-
const { copySync } = require('fs-extra')
|
|
4
|
-
|
|
5
|
-
const getNextDistDir = require('./getNextDistDir')
|
|
6
|
-
|
|
7
|
-
// Copy the static asset from pages/inputPath to out_publish/outputPath
|
|
8
|
-
const setupStaticFileForPage = async ({ inputPath, outputPath = null, publishPath }) => {
|
|
9
|
-
const nextDistDir = await getNextDistDir()
|
|
10
|
-
|
|
11
|
-
// Perform copy operation
|
|
12
|
-
copySync(join(nextDistDir, 'serverless', 'pages', inputPath), join(publishPath, outputPath || inputPath), {
|
|
13
|
-
overwrite: false,
|
|
14
|
-
errorOnExist: true,
|
|
15
|
-
})
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
module.exports = setupStaticFileForPage
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
const getPagesManifest = require('../../helpers/getPagesManifest')
|
|
2
|
-
const isApiRoute = require('../../helpers/isApiRoute')
|
|
3
|
-
|
|
4
|
-
const getPages = async () => {
|
|
5
|
-
// Get HTML and SSR pages and API endpoints from the NextJS pages manifest
|
|
6
|
-
const pagesManifest = await getPagesManifest()
|
|
7
|
-
|
|
8
|
-
// Collect pages
|
|
9
|
-
const pages = []
|
|
10
|
-
|
|
11
|
-
// Parse pages
|
|
12
|
-
Object.entries(pagesManifest).forEach(([route, filePath]) => {
|
|
13
|
-
// Skip non-API endpoints
|
|
14
|
-
if (!isApiRoute(route)) return
|
|
15
|
-
|
|
16
|
-
// Add page
|
|
17
|
-
pages.push({ route, filePath })
|
|
18
|
-
})
|
|
19
|
-
return pages
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
module.exports = getPages
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
const getNetlifyFunctionName = require('../../helpers/getNetlifyFunctionName')
|
|
2
|
-
|
|
3
|
-
const getPages = require('./pages')
|
|
4
|
-
|
|
5
|
-
const getRedirects = async () => {
|
|
6
|
-
const pages = await getPages()
|
|
7
|
-
return pages.map(({ route, filePath }) => ({
|
|
8
|
-
route,
|
|
9
|
-
target: `/.netlify/functions/${getNetlifyFunctionName(filePath, true)}`,
|
|
10
|
-
}))
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
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 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
|