Skip to content

Commit

Permalink
tmp: test if getting next version earlier - at verification is feasib…
Browse files Browse the repository at this point in the history
…le so we don't have to wait for serverless handler creation to grab next version
  • Loading branch information
pieh committed Jun 14, 2024
1 parent c60ac69 commit 7da721e
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/build/content/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,12 @@ export const copyNextDependencies = async (ctx: PluginContext): Promise<void> =>
// 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)

Expand Down
2 changes: 2 additions & 0 deletions src/build/plugin-context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ export class PluginContext {
pluginVersion: string
utils: NetlifyPluginUtils

nextVersionFromVerification: string = 'n/a'

Check failure on line 46 in src/build/plugin-context.ts

View workflow job for this annotation

GitHub Actions / Lint

Type string trivially inferred from a string literal, remove type annotation.

private constants: NetlifyPluginConstants
private packageJSON: { name: string; version: string } & Record<string, unknown>

Expand Down
11 changes: 11 additions & 0 deletions src/build/verification.ts
Original file line number Diff line number Diff line change
@@ -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'

Expand Down Expand Up @@ -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) {

Check failure on line 58 in src/build/verification.ts

View workflow job for this annotation

GitHub Actions / Lint

Identifier name 'e' is too short (< 2).

Check failure on line 58 in src/build/verification.ts

View workflow job for this annotation

GitHub Actions / Lint

The catch parameter `e` should be named `error`.
console.error('failed to grab next version', e)
}
}
if (ctx.buildConfig.output === 'export') {
if (!ctx.exportDetail?.success) {
Expand Down

0 comments on commit 7da721e

Please sign in to comment.