@netlify/plugin-nextjs 3.9.2 → 4.0.0-beta.12
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 +236 -0
- package/lib/helpers/functions.js +65 -0
- package/lib/helpers/verification.js +94 -0
- package/lib/index.js +55 -0
- package/lib/templates/getHandler.js +165 -0
- package/lib/templates/getPageResolver.js +24 -0
- package/lib/templates/handlerUtils.js +66 -0
- package/lib/templates/ipx.js +8 -0
- package/manifest.yml +1 -1
- package/package.json +56 -58
- 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,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
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
const getNextConfig = require('../../../../helpers/getNextConfig')
|
|
2
|
-
const addDefaultLocaleRedirect = require('../../helpers/addDefaultLocaleRedirect')
|
|
3
|
-
const asyncForEach = require('../../helpers/asyncForEach')
|
|
4
|
-
const isDynamicRoute = require('../../helpers/isDynamicRoute')
|
|
5
|
-
|
|
6
|
-
const getPages = require('./pages')
|
|
7
|
-
|
|
8
|
-
// withoutProps pages
|
|
9
|
-
//
|
|
10
|
-
// Page params {
|
|
11
|
-
// route -> '/about', '/initial/[id]'
|
|
12
|
-
// filePath -> 'pages/about.html', 'pages/initial[id].html'
|
|
13
|
-
// }
|
|
14
|
-
//
|
|
15
|
-
// Page params in i18n {
|
|
16
|
-
// route -> '/en/about', '/fr/initial/[id]'
|
|
17
|
-
// filePath -> 'pages/en/about.html', 'pages/fr/initial[id].html'
|
|
18
|
-
// }
|
|
19
|
-
//
|
|
20
|
-
|
|
21
|
-
const getRedirects = async () => {
|
|
22
|
-
const redirects = []
|
|
23
|
-
const pages = await getPages()
|
|
24
|
-
const { basePath } = await getNextConfig()
|
|
25
|
-
|
|
26
|
-
await asyncForEach(pages, async ({ route, filePath }) => {
|
|
27
|
-
const target = filePath.replace(/pages/, '')
|
|
28
|
-
|
|
29
|
-
await addDefaultLocaleRedirect(redirects, route, target)
|
|
30
|
-
|
|
31
|
-
// For sites that use basePath, manually add necessary redirects here specific
|
|
32
|
-
// only to this page type (which excludes static route redirects by default)
|
|
33
|
-
if (basePath && basePath !== '') {
|
|
34
|
-
redirects.push({
|
|
35
|
-
route: `${basePath}${route}`,
|
|
36
|
-
target: route,
|
|
37
|
-
})
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
// Only create normal redirects for pages with dynamic routing
|
|
41
|
-
if (!isDynamicRoute(route)) return
|
|
42
|
-
|
|
43
|
-
redirects.push({
|
|
44
|
-
route,
|
|
45
|
-
target: filePath.replace(/pages/, ''),
|
|
46
|
-
})
|
|
47
|
-
})
|
|
48
|
-
return redirects
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
module.exports = getRedirects
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
const { join, relative } = require('path')
|
|
2
|
-
|
|
3
|
-
const { copySync } = require('fs-extra')
|
|
4
|
-
|
|
5
|
-
const asyncForEach = require('../../helpers/asyncForEach')
|
|
6
|
-
const getI18n = require('../../helpers/getI18n')
|
|
7
|
-
const getNextDistDir = require('../../helpers/getNextDistDir')
|
|
8
|
-
const { logTitle, logItem } = require('../../helpers/logger')
|
|
9
|
-
|
|
10
|
-
const getPages = require('./pages')
|
|
11
|
-
|
|
12
|
-
// Identify all pages that have been pre-rendered and copy each one to the
|
|
13
|
-
// Netlify publish directory.
|
|
14
|
-
const setup = async (publishPath) => {
|
|
15
|
-
logTitle('🔥 Copying pre-rendered pages without props to', publishPath)
|
|
16
|
-
|
|
17
|
-
const i18n = await getI18n()
|
|
18
|
-
const nextDistDir = await getNextDistDir()
|
|
19
|
-
const pages = await getPages()
|
|
20
|
-
|
|
21
|
-
// Copy each page to the Netlify publish directory
|
|
22
|
-
return pages.map(({ filePath }) => {
|
|
23
|
-
// HACK: If i18n, 404.html needs to be at the top level of the publish directory
|
|
24
|
-
if (i18n.defaultLocale && filePath === `pages/${i18n.defaultLocale}/404.html`) {
|
|
25
|
-
copySync(join(nextDistDir, 'serverless', filePath), join(publishPath, '404.html'))
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
// The path to the file, relative to the pages directory
|
|
29
|
-
const relativePath = relative('pages', filePath)
|
|
30
|
-
return { type: 'static', inputPath: relativePath, publishPath }
|
|
31
|
-
})
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
module.exports = setup
|
package/src/lib/pages/worker.js
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
const setupNetlifyFunctionForPage = require('../helpers/setupNetlifyFunctionForPage')
|
|
2
|
-
const setupStaticFileForPage = require('../helpers/setupStaticFileForPage')
|
|
3
|
-
|
|
4
|
-
exports.processPage = function processPage(job) {
|
|
5
|
-
try {
|
|
6
|
-
switch (job.type) {
|
|
7
|
-
case 'function': {
|
|
8
|
-
return setupNetlifyFunctionForPage(job)
|
|
9
|
-
}
|
|
10
|
-
case 'static': {
|
|
11
|
-
return setupStaticFileForPage(job)
|
|
12
|
-
}
|
|
13
|
-
default:
|
|
14
|
-
console.log('Unknown job type', job.type)
|
|
15
|
-
}
|
|
16
|
-
} catch (error) {
|
|
17
|
-
console.error('Error in worker', error, 'Job', job)
|
|
18
|
-
}
|
|
19
|
-
}
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
const { join, resolve } = require('path')
|
|
2
|
-
|
|
3
|
-
const { copySync, existsSync } = require('fs-extra')
|
|
4
|
-
|
|
5
|
-
const getNextDistDir = require('../helpers/getNextDistDir')
|
|
6
|
-
const { logTitle } = require('../helpers/logger')
|
|
7
|
-
|
|
8
|
-
// Copy the NextJS static assets from NextJS distDir to Netlify publish folder.
|
|
9
|
-
// These need to be available for NextJS to work.
|
|
10
|
-
|
|
11
|
-
// Note: If you're using a custom build setup, such as a monorepo,
|
|
12
|
-
// you may need to explicitly set distDir in your next.config.js.
|
|
13
|
-
|
|
14
|
-
const copyNextAssets = async (publishPath) => {
|
|
15
|
-
const nextDistDir = await getNextDistDir()
|
|
16
|
-
const staticAssetsPath = join(nextDistDir, 'static')
|
|
17
|
-
if (!existsSync(staticAssetsPath)) {
|
|
18
|
-
throw new Error(
|
|
19
|
-
`No static assets found in your distDir (missing /static in ${resolve(
|
|
20
|
-
nextDistDir,
|
|
21
|
-
)}). Please check your project configuration. Your next.config.js must be one of \`serverless\` or \`experimental-serverless-trace\`. Your build command should include \`next build\`.`,
|
|
22
|
-
)
|
|
23
|
-
}
|
|
24
|
-
logTitle('💼 Copying static NextJS assets to', publishPath)
|
|
25
|
-
copySync(staticAssetsPath, join(publishPath, '_next', 'static'), {
|
|
26
|
-
overwrite: false,
|
|
27
|
-
errorOnExist: true,
|
|
28
|
-
})
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
module.exports = copyNextAssets
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
const { existsSync, copySync } = require('fs-extra')
|
|
2
|
-
|
|
3
|
-
const { PUBLIC_PATH } = require('../config')
|
|
4
|
-
const { logTitle } = require('../helpers/logger')
|
|
5
|
-
|
|
6
|
-
// Copy files from public folder to Netlify publish folder
|
|
7
|
-
const copyPublicFiles = (publishPath) => {
|
|
8
|
-
// Abort if no public/ folder
|
|
9
|
-
if (!existsSync(PUBLIC_PATH)) return
|
|
10
|
-
|
|
11
|
-
// Perform copy operation
|
|
12
|
-
if (publishPath !== PUBLIC_PATH) {
|
|
13
|
-
logTitle('🌍️ Copying', PUBLIC_PATH, 'folder to', publishPath)
|
|
14
|
-
copySync(PUBLIC_PATH, publishPath)
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
module.exports = copyPublicFiles
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
const { join } = require('path')
|
|
2
|
-
|
|
3
|
-
const findCacheDir = require('find-cache-dir')
|
|
4
|
-
const { emptyDirSync } = require('fs-extra')
|
|
5
|
-
|
|
6
|
-
const { NETLIFY_PUBLISH_PATH, NETLIFY_FUNCTIONS_PATH } = require('../config')
|
|
7
|
-
const handleFileTracking = require('../helpers/handleFileTracking')
|
|
8
|
-
const { logTitle, log } = require('../helpers/logger')
|
|
9
|
-
|
|
10
|
-
// Clean existing publish and functions folders
|
|
11
|
-
const prepareFolders = ({ functionsPath, publishPath }) => {
|
|
12
|
-
logTitle('🚀 Next on Netlify 🚀')
|
|
13
|
-
|
|
14
|
-
const isNotConfiguredFunctionsDir = functionsPath === NETLIFY_FUNCTIONS_PATH
|
|
15
|
-
const isNotConfiguredPublishDir = publishPath === NETLIFY_PUBLISH_PATH
|
|
16
|
-
|
|
17
|
-
if (isNotConfiguredFunctionsDir) {
|
|
18
|
-
log(' ', 'Functions directory: ', functionsPath)
|
|
19
|
-
}
|
|
20
|
-
if (isNotConfiguredPublishDir) {
|
|
21
|
-
log(' ', 'Publish directory: ', publishPath)
|
|
22
|
-
}
|
|
23
|
-
if (isNotConfiguredFunctionsDir || isNotConfiguredPublishDir) {
|
|
24
|
-
log(' ', 'Make sure these are set in your netlify.toml file.')
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
// We can empty these dirs knowing there will only be stale NoN-generated files inside
|
|
28
|
-
if (isNotConfiguredPublishDir) {
|
|
29
|
-
emptyDirSync(publishPath)
|
|
30
|
-
}
|
|
31
|
-
if (isNotConfiguredFunctionsDir) {
|
|
32
|
-
emptyDirSync(functionsPath)
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
// This returns a function that runs as the last step of nextOnNetlify()
|
|
36
|
-
return handleFileTracking({ functionsPath, publishPath })
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
module.exports = prepareFolders
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
const { join } = require('path')
|
|
2
|
-
|
|
3
|
-
const { existsSync, readFileSync, writeFileSync } = require('fs-extra')
|
|
4
|
-
|
|
5
|
-
const { CUSTOM_HEADERS_PATH } = require('../config')
|
|
6
|
-
const { logTitle, logItem } = require('../helpers/logger')
|
|
7
|
-
|
|
8
|
-
const indentNewLine = (s) => `\n ${s}`
|
|
9
|
-
|
|
10
|
-
// Setup _headers file to override specific header rules for next assets
|
|
11
|
-
const setupHeaders = (publishPath) => {
|
|
12
|
-
logTitle('🔀 Setting up headers')
|
|
13
|
-
|
|
14
|
-
// Collect custom redirects defined by the user
|
|
15
|
-
const headers = []
|
|
16
|
-
if (existsSync(CUSTOM_HEADERS_PATH)) {
|
|
17
|
-
logItem('# Prepending custom headers')
|
|
18
|
-
headers.push(readFileSync(CUSTOM_HEADERS_PATH, 'utf8'))
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
// Add NoN section heading
|
|
22
|
-
headers.push('# Next-on-Netlify Headers')
|
|
23
|
-
|
|
24
|
-
// Add rule to override cache control for static chunks
|
|
25
|
-
const staticChunkRule = [
|
|
26
|
-
`/_next/static/chunks/*`,
|
|
27
|
-
indentNewLine(`cache-control: public`),
|
|
28
|
-
indentNewLine(`cache-control: max-age=31536000`),
|
|
29
|
-
indentNewLine(`cache-control: immutable`),
|
|
30
|
-
].join('')
|
|
31
|
-
headers.push(staticChunkRule)
|
|
32
|
-
|
|
33
|
-
// Write redirects to _redirects file
|
|
34
|
-
writeFileSync(join(publishPath, '_headers'), headers.join('\n'))
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
module.exports = setupHeaders
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
const { join } = require('path')
|
|
2
|
-
|
|
3
|
-
const { copyFile, writeJSON, ensureDir } = require('fs-extra')
|
|
4
|
-
|
|
5
|
-
const { NEXT_IMAGE_FUNCTION_NAME, TEMPLATES_DIR } = require('../config')
|
|
6
|
-
|
|
7
|
-
// Move our next/image function into the correct functions directory
|
|
8
|
-
const setupImageFunction = async (functionsPath, imageconfig = {}) => {
|
|
9
|
-
const functionName = `${NEXT_IMAGE_FUNCTION_NAME}.js`
|
|
10
|
-
const functionDirectory = join(functionsPath, NEXT_IMAGE_FUNCTION_NAME)
|
|
11
|
-
|
|
12
|
-
await ensureDir(functionDirectory)
|
|
13
|
-
await writeJSON(join(functionDirectory, 'imageconfig.json'), imageconfig)
|
|
14
|
-
await copyFile(join(TEMPLATES_DIR, 'imageFunction.js'), join(functionDirectory, functionName))
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
module.exports = setupImageFunction
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
const runJobsQueue = require('../helpers/runJobsQueue')
|
|
2
|
-
const apiSetup = require('../pages/api/setup')
|
|
3
|
-
const getInitialPropsSetup = require('../pages/getInitialProps/setup')
|
|
4
|
-
const getServerSidePropsSetup = require('../pages/getServerSideProps/setup')
|
|
5
|
-
const getStaticPropsSetup = require('../pages/getStaticProps/setup')
|
|
6
|
-
const getSPFallbackSetup = require('../pages/getStaticPropsWithFallback/setup')
|
|
7
|
-
const getSPRevalidateSetup = require('../pages/getStaticPropsWithRevalidate/setup')
|
|
8
|
-
const withoutPropsSetup = require('../pages/withoutProps/setup')
|
|
9
|
-
|
|
10
|
-
// Set up all our NextJS pages according to the recipes defined in pages/
|
|
11
|
-
const setupPages = async ({ functionsPath, publishPath }) => {
|
|
12
|
-
const jobs = [
|
|
13
|
-
...(await apiSetup(functionsPath)),
|
|
14
|
-
...(await getInitialPropsSetup(functionsPath)),
|
|
15
|
-
...(await getServerSidePropsSetup(functionsPath)),
|
|
16
|
-
...(await getStaticPropsSetup({ functionsPath, publishPath })),
|
|
17
|
-
...(await getSPFallbackSetup(functionsPath)),
|
|
18
|
-
...(await getSPRevalidateSetup(functionsPath)),
|
|
19
|
-
...(await withoutPropsSetup(publishPath)),
|
|
20
|
-
]
|
|
21
|
-
|
|
22
|
-
return runJobsQueue(jobs)
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
module.exports = setupPages
|