Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 4aff708

Browse files
authored
feat!: switch function bundling to esbuild (#490)
* feat: switch function bundling to esbuild * chore: update tests * feat: inline entry-point file * fix: only copy js chunks * fix: remove non-working config mutation * fix: update test * feat: add cli version check * chore: add tests
1 parent 202b1c5 commit 4aff708

19 files changed

+10697
-501
lines changed

index.js

+19-6
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ const { readdirSync, existsSync } = require('fs')
22
const path = require('path')
33

44
const makeDir = require('make-dir')
5+
const { satisfies } = require('semver')
56

67
const { restoreCache, saveCache } = require('./helpers/cacheBuild')
78
const checkNxConfig = require('./helpers/checkNxConfig')
@@ -12,12 +13,16 @@ const getNextRoot = require('./helpers/getNextRoot')
1213
const validateNextUsage = require('./helpers/validateNextUsage')
1314
const verifyBuildTarget = require('./helpers/verifyBuildTarget')
1415
const nextOnNetlify = require('./src')
16+
17+
// This is when the esbuild dynamic import support was added
18+
const REQUIRED_BUILD_VERSION = '>=15.11.5'
19+
1520
// * Helpful Plugin Context *
1621
// - Between the prebuild and build steps, the project's build command is run
1722
// - Between the build and postbuild steps, any functions are bundled
1823

1924
module.exports = {
20-
async onPreBuild({ netlifyConfig, packageJson, utils, constants }) {
25+
async onPreBuild({ netlifyConfig, packageJson, utils, constants = {} }) {
2126
const { failBuild } = utils.build
2227

2328
validateNextUsage({ failBuild, netlifyConfig })
@@ -30,6 +35,13 @@ module.exports = {
3035
if (doesNotNeedPlugin({ netlifyConfig, packageJson, failBuild })) {
3136
return
3237
}
38+
// 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)) {
40+
return failBuild(
41+
`This version of the Essential Next.js plugin requires [email protected] or higher. Please upgrade and try again.
42+
You can do this by running: "npm install -g netlify-cli@latest" or "yarn global add netlify-cli@latest"`,
43+
)
44+
}
3345

3446
// Populates the correct config if needed
3547
await verifyBuildTarget({ netlifyConfig, packageJson, failBuild })
@@ -71,14 +83,15 @@ module.exports = {
7183
}
7284
console.log('Detected Next.js site. Copying files...')
7385

74-
const { distDir } = await getNextConfig(failBuild, nextRoot)
75-
86+
const { distDir, configFile } = await getNextConfig(failBuild, nextRoot)
7687
const dist = path.resolve(nextRoot, distDir)
88+
7789
if (!existsSync(dist)) {
7890
failBuild(`
79-
Could not find "${distDir}" after building the site, which indicates that "next build" was not run.
80-
Check that your build command includes "next build". If the site is a monorepo, see https://ntl.fyi/next-monorepo
81-
for information on configuring the site. If this is not a Next.js site you should remove the Essential Next.js plugin.
91+
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+
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+
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.
8295
See https://ntl.fyi/remove-plugin for instructions.
8396
`)
8497
}

0 commit comments

Comments
 (0)