From b742761c86944f502e19335cdc184f605a74358e Mon Sep 17 00:00:00 2001 From: Marcus Weiner Date: Wed, 18 Oct 2023 17:50:13 +0200 Subject: [PATCH] fix: fail build when unsupported Next version is used This prevents surprises when people try to use this with a version that is not fully supported --- packages/runtime/src/helpers/functionsMetaData.ts | 2 +- packages/runtime/src/index.ts | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/packages/runtime/src/helpers/functionsMetaData.ts b/packages/runtime/src/helpers/functionsMetaData.ts index 477a88f0b7..4e22c8653d 100644 --- a/packages/runtime/src/helpers/functionsMetaData.ts +++ b/packages/runtime/src/helpers/functionsMetaData.ts @@ -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 diff --git a/packages/runtime/src/index.ts b/packages/runtime/src/index.ts index 7dca0b8c9e..88e01ea7b5 100644 --- a/packages/runtime/src/index.ts +++ b/packages/runtime/src/index.ts @@ -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' @@ -30,6 +31,7 @@ import { APILambda, getSSRLambdas, } from './helpers/functions' +import { nextPluginVersion } from './helpers/functionsMetaData' import { generateRedirects, generateStaticRedirects } from './helpers/redirects' import { shouldSkip, @@ -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 ||= {}