Skip to content

feat!: switch function bundling to esbuild #490

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Jul 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 19 additions & 6 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const { readdirSync, existsSync } = require('fs')
const path = require('path')

const makeDir = require('make-dir')
const { satisfies } = require('semver')

const { restoreCache, saveCache } = require('./helpers/cacheBuild')
const checkNxConfig = require('./helpers/checkNxConfig')
Expand All @@ -12,12 +13,16 @@ const getNextRoot = require('./helpers/getNextRoot')
const validateNextUsage = require('./helpers/validateNextUsage')
const verifyBuildTarget = require('./helpers/verifyBuildTarget')
const nextOnNetlify = require('./src')

// This is when the esbuild dynamic import support was added
const REQUIRED_BUILD_VERSION = '>=15.11.5'

// * Helpful Plugin Context *
// - Between the prebuild and build steps, the project's build command is run
// - Between the build and postbuild steps, any functions are bundled

module.exports = {
async onPreBuild({ netlifyConfig, packageJson, utils, constants }) {
async onPreBuild({ netlifyConfig, packageJson, utils, constants = {} }) {
const { failBuild } = utils.build

validateNextUsage({ failBuild, netlifyConfig })
Expand All @@ -30,6 +35,13 @@ module.exports = {
if (doesNotNeedPlugin({ netlifyConfig, packageJson, failBuild })) {
return
}
// 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
if (constants.IS_LOCAL && !satisfies(constants.NETLIFY_BUILD_VERSION, REQUIRED_BUILD_VERSION)) {
return failBuild(
`This version of the Essential Next.js plugin requires netlify-cli@4.4.2 or higher. Please upgrade and try again.
You can do this by running: "npm install -g netlify-cli@latest" or "yarn global add netlify-cli@latest"`,
)
}

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

const { distDir } = await getNextConfig(failBuild, nextRoot)

const { distDir, configFile } = await getNextConfig(failBuild, nextRoot)
const dist = path.resolve(nextRoot, distDir)

if (!existsSync(dist)) {
failBuild(`
Could not find "${distDir}" after building the site, which indicates that "next build" was not run.
Check that your build command includes "next build". If the site is a monorepo, see https://ntl.fyi/next-monorepo
for information on configuring the site. If this is not a Next.js site you should remove the Essential Next.js plugin.
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.
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
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
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.
See https://ntl.fyi/remove-plugin for instructions.
`)
}
Expand Down
Loading