Skip to content

Commit 7da721e

Browse files
committed
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
1 parent c60ac69 commit 7da721e

File tree

3 files changed

+19
-0
lines changed

3 files changed

+19
-0
lines changed

src/build/content/server.ts

+6
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,12 @@ export const copyNextDependencies = async (ctx: PluginContext): Promise<void> =>
306306
// exports map it still might be a problem in the future, so we are not breaking here
307307
}
308308

309+
if (nextVersion !== ctx.nextVersionFromVerification) {
310+
ctx.failBuild(
311+
`mismatched versions detected. Version found at verification is ${ctx.nextVersionFromVerification} but resolved version is ${nextVersion}.`,
312+
)
313+
}
314+
309315
if (nextVersion) {
310316
verifyNextVersion(ctx, nextVersion)
311317

src/build/plugin-context.ts

+2
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ export class PluginContext {
4343
pluginVersion: string
4444
utils: NetlifyPluginUtils
4545

46+
nextVersionFromVerification: string = 'n/a'
47+
4648
private constants: NetlifyPluginConstants
4749
private packageJSON: { name: string; version: string } & Record<string, unknown>
4850

src/build/verification.ts

+11
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import { existsSync } from 'node:fs'
2+
import { createRequire } from 'node:module'
23
import { join } from 'node:path'
4+
import { join as posixJoin } from 'node:path/posix'
35

46
import { satisfies } from 'semver'
57

@@ -47,6 +49,15 @@ export function verifyPublishDir(ctx: PluginContext) {
4749
`Your publish directory does not contain expected Next.js build output. Please make sure you are using Next.js version (${SUPPORTED_NEXT_VERSIONS})`,
4850
)
4951
}
52+
53+
try {
54+
const serverHandlerRequire = createRequire(posixJoin(ctx.standaloneRootDir, ':internal:'))
55+
const { version } = serverHandlerRequire('next/package.json')
56+
ctx.nextVersionFromVerification = version
57+
console.log({ version })
58+
} catch (e) {
59+
console.error('failed to grab next version', e)
60+
}
5061
}
5162
if (ctx.buildConfig.output === 'export') {
5263
if (!ctx.exportDetail?.success) {

0 commit comments

Comments
 (0)