From 7da721e3fc990e8d0cd19e76740fb35f3ab9c48b Mon Sep 17 00:00:00 2001 From: Michal Piechowiak Date: Fri, 14 Jun 2024 11:50:57 +0200 Subject: [PATCH] tmp: test if getting next version earlier - at verification is feasible so we don't have to wait for serverless handler creation to grab next version --- src/build/content/server.ts | 6 ++++++ src/build/plugin-context.ts | 2 ++ src/build/verification.ts | 11 +++++++++++ 3 files changed, 19 insertions(+) diff --git a/src/build/content/server.ts b/src/build/content/server.ts index dc38fce665..e89571e7c4 100644 --- a/src/build/content/server.ts +++ b/src/build/content/server.ts @@ -306,6 +306,12 @@ export const copyNextDependencies = async (ctx: PluginContext): Promise => // exports map it still might be a problem in the future, so we are not breaking here } + if (nextVersion !== ctx.nextVersionFromVerification) { + ctx.failBuild( + `mismatched versions detected. Version found at verification is ${ctx.nextVersionFromVerification} but resolved version is ${nextVersion}.`, + ) + } + if (nextVersion) { verifyNextVersion(ctx, nextVersion) diff --git a/src/build/plugin-context.ts b/src/build/plugin-context.ts index feedfcfeed..2a3dfe8ec8 100644 --- a/src/build/plugin-context.ts +++ b/src/build/plugin-context.ts @@ -43,6 +43,8 @@ export class PluginContext { pluginVersion: string utils: NetlifyPluginUtils + nextVersionFromVerification: string = 'n/a' + private constants: NetlifyPluginConstants private packageJSON: { name: string; version: string } & Record diff --git a/src/build/verification.ts b/src/build/verification.ts index 269838daf3..c36ac149a1 100644 --- a/src/build/verification.ts +++ b/src/build/verification.ts @@ -1,5 +1,7 @@ import { existsSync } from 'node:fs' +import { createRequire } from 'node:module' import { join } from 'node:path' +import { join as posixJoin } from 'node:path/posix' import { satisfies } from 'semver' @@ -47,6 +49,15 @@ export function verifyPublishDir(ctx: PluginContext) { `Your publish directory does not contain expected Next.js build output. Please make sure you are using Next.js version (${SUPPORTED_NEXT_VERSIONS})`, ) } + + try { + const serverHandlerRequire = createRequire(posixJoin(ctx.standaloneRootDir, ':internal:')) + const { version } = serverHandlerRequire('next/package.json') + ctx.nextVersionFromVerification = version + console.log({ version }) + } catch (e) { + console.error('failed to grab next version', e) + } } if (ctx.buildConfig.output === 'export') { if (!ctx.exportDetail?.success) {