Skip to content

Commit

Permalink
fix: fail build when unsupported Next version is used
Browse files Browse the repository at this point in the history
This prevents surprises when people try to use this with a version that is not fully supported
  • Loading branch information
mraerino committed Oct 18, 2023
1 parent 2fca7b3 commit b742761
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/runtime/src/helpers/functionsMetaData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const getNextRuntimeVersion = async (packageJsonPath: string, useNodeModulesPath

const PLUGIN_PACKAGE_PATH = '.netlify/plugins/package.json'

const nextPluginVersion = async (module?: string) => {
export const nextPluginVersion = async (module?: string) => {
const moduleRoot = resolveModuleRoot(module || NEXT_PLUGIN)
const nodeModulesPath = moduleRoot ? join(moduleRoot, 'package.json') : null

Expand Down
8 changes: 8 additions & 0 deletions packages/runtime/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { bold, redBright } from 'chalk'
import destr from 'destr'
import { existsSync, readFileSync } from 'fs-extra'
import { outdent } from 'outdent'
import { satisfies } from 'semver'

import { HANDLER_FUNCTION_NAME, ODB_FUNCTION_NAME } from './constants'
import { restoreCache, saveCache } from './helpers/cache'
Expand All @@ -30,6 +31,7 @@ import {
APILambda,
getSSRLambdas,
} from './helpers/functions'
import { nextPluginVersion } from './helpers/functionsMetaData'
import { generateRedirects, generateStaticRedirects } from './helpers/redirects'
import {
shouldSkip,
Expand Down Expand Up @@ -79,6 +81,12 @@ const plugin: NetlifyPlugin = {
checkForRootPublish({ publish, failBuild })
verifyNetlifyBuildVersion({ failBuild, ...constants })

const nextVersion = await nextPluginVersion('next')
if (!satisfies(nextVersion, '< 13.5')) {
failBuild('NextJS 13.5 and newer is not yet supported.')
return
}

await restoreCache({ cache, publish })

netlifyConfig.build.environment ||= {}
Expand Down

0 comments on commit b742761

Please sign in to comment.