11const { readdirSync, existsSync } = require ( 'fs' )
22const path = require ( 'path' )
33
4+ const { yellowBright, greenBright } = require ( 'chalk' )
45const makeDir = require ( 'make-dir' )
56const { satisfies } = require ( 'semver' )
7+ const glob = require ( 'tiny-glob' )
68
79const { restoreCache, saveCache } = require ( './helpers/cacheBuild' )
810const checkNxConfig = require ( './helpers/checkNxConfig' )
@@ -23,6 +25,8 @@ const REQUIRED_BUILD_VERSION = '>=15.11.5'
2325
2426module . exports = {
2527 async onPreBuild ( { netlifyConfig, packageJson, utils, constants = { } } ) {
28+ const { FUNCTIONS_SRC = DEFAULT_FUNCTIONS_SRC , INTERNAL_FUNCTIONS_SRC , IS_LOCAL , NETLIFY_BUILD_VERSION } = constants
29+
2630 const { failBuild } = utils . build
2731
2832 validateNextUsage ( { failBuild, netlifyConfig } )
@@ -36,7 +40,7 @@ module.exports = {
3640 return
3741 }
3842 // 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 } ) ) {
4044 return failBuild (
4145 `This version of the Essential Next.js plugin requires netlify-cli@4.4.2 or higher. Please upgrade and try again.
4246You can do this by running: "npm install -g netlify-cli@latest" or "yarn global add netlify-cli@latest"` ,
@@ -66,6 +70,19 @@ You can do this by running: "npm install -g netlify-cli@latest" or "yarn global
6670 `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.` ,
6771 )
6872 }
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+
6986 await restoreCache ( { cache : utils . cache , distDir : nextConfig . distDir , nextRoot } )
7087
7188 // Exit the build process on unhandled promise rejection. This is the default in Node 15+, but earlier versions just warn.
@@ -75,7 +92,7 @@ You can do this by running: "npm install -g netlify-cli@latest" or "yarn global
7592 async onBuild ( {
7693 netlifyConfig,
7794 packageJson,
78- constants : { PUBLISH_DIR = DEFAULT_PUBLISH_DIR , FUNCTIONS_SRC = DEFAULT_FUNCTIONS_SRC } ,
95+ constants : { PUBLISH_DIR = DEFAULT_PUBLISH_DIR , INTERNAL_FUNCTIONS_SRC , FUNCTIONS_SRC = DEFAULT_FUNCTIONS_SRC } ,
7996 utils,
8097 } ) {
8198 const { failBuild } = utils . build
@@ -95,7 +112,7 @@ You can do this by running: "npm install -g netlify-cli@latest" or "yarn global
95112Could not find "${ distDir } " after building the site, which indicates that "next build" was not run or that we're looking in the wrong place.
96113We're using the config file ${ configFile } , and looking for the dist directory at ${ dist } . If this is incorrect, try deleting the config file, or
97114moving 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
98- 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.
115+ 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.
99116See https://ntl.fyi/remove-plugin for instructions.
100117 ` )
101118 }
@@ -104,7 +121,7 @@ See https://ntl.fyi/remove-plugin for instructions.
104121
105122 await makeDir ( PUBLISH_DIR )
106123 await nextOnNetlify ( {
107- functionsDir : path . resolve ( FUNCTIONS_SRC ) ,
124+ functionsDir : path . resolve ( INTERNAL_FUNCTIONS_SRC || FUNCTIONS_SRC ) ,
108125 publishDir : netlifyConfig . build . publish || PUBLISH_DIR ,
109126 nextRoot,
110127 } )
0 commit comments