Skip to content

Commit 5d11eaf

Browse files
committed
feat: use internal functions dir
1 parent e3e7cd1 commit 5d11eaf

File tree

4 files changed

+10460
-208
lines changed

4 files changed

+10460
-208
lines changed

index.js

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
const { readdirSync, existsSync } = require('fs')
22
const path = require('path')
33

4+
const { yellowBright, greenBright } = require('chalk')
45
const makeDir = require('make-dir')
56
const { satisfies } = require('semver')
7+
const glob = require('tiny-glob')
68

79
const { restoreCache, saveCache } = require('./helpers/cacheBuild')
810
const checkNxConfig = require('./helpers/checkNxConfig')
@@ -23,6 +25,8 @@ const REQUIRED_BUILD_VERSION = '>=15.11.5'
2325

2426
module.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.
4246
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
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
async onBuild({
7289
netlifyConfig,
7390
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 },
7592
utils,
7693
}) {
7794
const { failBuild } = utils.build
@@ -91,7 +108,7 @@ You can do this by running: "npm install -g netlify-cli@latest" or "yarn global
91108
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.
92109
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
93110
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.
95112
See https://ntl.fyi/remove-plugin for instructions.
96113
`)
97114
}
@@ -100,7 +117,7 @@ See https://ntl.fyi/remove-plugin for instructions.
100117

101118
await makeDir(PUBLISH_DIR)
102119
await nextOnNetlify({
103-
functionsDir: path.resolve(FUNCTIONS_SRC),
120+
functionsDir: path.resolve(INTERNAL_FUNCTIONS_SRC || FUNCTIONS_SRC),
104121
publishDir: netlifyConfig.build.publish || PUBLISH_DIR,
105122
nextRoot,
106123
})

0 commit comments

Comments
 (0)