1
1
const { readdirSync, existsSync } = require ( 'fs' )
2
2
const path = require ( 'path' )
3
3
4
+ const { yellowBright, greenBright } = require ( 'chalk' )
4
5
const makeDir = require ( 'make-dir' )
5
6
const { satisfies } = require ( 'semver' )
7
+ const glob = require ( 'tiny-glob' )
6
8
7
9
const { restoreCache, saveCache } = require ( './helpers/cacheBuild' )
8
10
const checkNxConfig = require ( './helpers/checkNxConfig' )
@@ -23,6 +25,8 @@ const REQUIRED_BUILD_VERSION = '>=15.11.5'
23
25
24
26
module . exports = {
25
27
async onPreBuild ( { netlifyConfig, packageJson, utils, constants = { } } ) {
28
+ const { FUNCTIONS_SRC = DEFAULT_FUNCTIONS_SRC , INTERNAL_FUNCTIONS_SRC , IS_LOCAL , NETLIFY_BUILD_VERSION } = constants
29
+
26
30
const { failBuild } = utils . build
27
31
28
32
validateNextUsage ( { failBuild, netlifyConfig } )
@@ -36,7 +40,7 @@ module.exports = {
36
40
return
37
41
}
38
42
// We check for build version because that's what's available to us, but prompt about the cli because that's what they can upgrade
39
- if ( constants . IS_LOCAL && ! satisfies ( constants . NETLIFY_BUILD_VERSION , REQUIRED_BUILD_VERSION ) ) {
43
+ if ( IS_LOCAL && ! satisfies ( NETLIFY_BUILD_VERSION , REQUIRED_BUILD_VERSION , { includePrerelease : true } ) ) {
40
44
return failBuild (
41
45
`This version of the Essential Next.js plugin requires netlify-cli@4.4.2 or higher. Please upgrade and try again.
42
46
You can do this by running: "npm install -g netlify-cli@latest" or "yarn global add netlify-cli@latest"` ,
@@ -66,12 +70,25 @@ You can do this by running: "npm install -g netlify-cli@latest" or "yarn global
66
70
`The Essential Next.js plugin now supports reading image domains from your Next config, so using NEXT_IMAGE_ALLOWED_DOMAINS is now deprecated. Please set images.domains in next.config.js instead, and remove the NEXT_IMAGE_ALLOWED_DOMAINS variable.` ,
67
71
)
68
72
}
73
+
74
+ if ( INTERNAL_FUNCTIONS_SRC && existsSync ( FUNCTIONS_SRC ) ) {
75
+ const oldFunctions = await glob ( 'next_*' , { cwd : FUNCTIONS_SRC } )
76
+
77
+ if ( oldFunctions . length !== 0 ) {
78
+ console . log ( yellowBright `
79
+ Detected the following functions that seem to have been generated by an old version of the Essential Next.js plugin.
80
+ The plugin no longer uses these and they should be deleted to avoid conflicts.\n` )
81
+ console . log ( greenBright `• ${ oldFunctions . join ( '\n• ' ) }
82
+ ` )
83
+ }
84
+ }
85
+
69
86
await restoreCache ( { cache : utils . cache , distDir : nextConfig . distDir , nextRoot } )
70
87
} ,
71
88
async onBuild ( {
72
89
netlifyConfig,
73
90
packageJson,
74
- constants : { PUBLISH_DIR = DEFAULT_PUBLISH_DIR , FUNCTIONS_SRC = DEFAULT_FUNCTIONS_SRC } ,
91
+ constants : { PUBLISH_DIR = DEFAULT_PUBLISH_DIR , INTERNAL_FUNCTIONS_SRC , FUNCTIONS_SRC = DEFAULT_FUNCTIONS_SRC } ,
75
92
utils,
76
93
} ) {
77
94
const { failBuild } = utils . build
@@ -91,7 +108,7 @@ You can do this by running: "npm install -g netlify-cli@latest" or "yarn global
91
108
Could not find "${ distDir } " after building the site, which indicates that "next build" was not run or that we're looking in the wrong place.
92
109
We're using the config file ${ configFile } , and looking for the dist directory at ${ dist } . If this is incorrect, try deleting the config file, or
93
110
moving it to the correct place. Check that your build command includes "next build". If the site is a monorepo, see https://ntl.fyi/next-monorepo
94
- for information on configuring the site. If this is not a Next.js site, or if it uses static export, you should remove the Essential Next.js plugin.
111
+ for information on configuring the site. If this is not a Next.js site or if it uses static export, you should remove the Essential Next.js plugin.
95
112
See https://ntl.fyi/remove-plugin for instructions.
96
113
` )
97
114
}
@@ -100,7 +117,7 @@ See https://ntl.fyi/remove-plugin for instructions.
100
117
101
118
await makeDir ( PUBLISH_DIR )
102
119
await nextOnNetlify ( {
103
- functionsDir : path . resolve ( FUNCTIONS_SRC ) ,
120
+ functionsDir : path . resolve ( INTERNAL_FUNCTIONS_SRC || FUNCTIONS_SRC ) ,
104
121
publishDir : netlifyConfig . build . publish || PUBLISH_DIR ,
105
122
nextRoot,
106
123
} )
0 commit comments