Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/build/plugin-context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ export class PluginContext {
return (
this.requiredServerFiles.config.outputFileTracingRoot ??
// fallback for older Next.js versions that don't have outputFileTracingRoot in the config, but had it in config.experimental
this.requiredServerFiles.config.experimental.outputFileTracingRoot
this.requiredServerFiles.config.experimental.outputFileTracingRoot ??
process.cwd()
)
}

Expand Down
4 changes: 4 additions & 0 deletions tests/utils/fixture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,10 @@ export const createFixture = async (fixture: string, ctx: FixtureTestContext) =>
delete globalThis[Symbol.for('next-patch')]
}

// due to changes in https://github.com/vercel/next.js/pull/86591 , this global is specific to instance of application and we to clean it up
// from any previous function invocations that might have run in the same process
delete globalThis[Symbol.for('next.server.manifests')]

Comment on lines +109 to +112
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is integration test setup - only change, doesn't impact deployed apps

ctx.cwd = await mkdtemp(join(tmpdir(), 'opennextjs-netlify-'))
vi.spyOn(process, 'cwd').mockReturnValue(ctx.cwd)

Expand Down
18 changes: 13 additions & 5 deletions tests/utils/next-version-helpers.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import { readFile, writeFile } from 'node:fs/promises'

import fg from 'fast-glob'
import { coerce, gt, gte, satisfies, valid } from 'semver'
import { coerce, gt, gte, parse as parseSemver, satisfies, valid } from 'semver'
import { execaCommand } from 'execa'

const FUTURE_NEXT_PATCH_VERSION = '16.999.0'
Expand Down Expand Up @@ -193,7 +193,7 @@ export async function setNextVersionInFixture(
const nextPeerDependencies = JSON.parse(stdout)

if (updateReact && nextVersionRequiresReact19(checkVersion)) {
// canaries started reporting peerDependencies as `^18.2.0 || 19.0.0-rc-<hash>-<date>`
// canaries started reporting peerDependencies as `^18.2.0 || 19.0.0-rc-<hash>-<date> || ^19.0.0`
// with https://github.com/vercel/next.js/pull/70219 which is valid range for package managers
// but not for @nx/next which checks dependencies and tries to assure that at least React 18 is used
// but the check doesn't handle the alternative in version selector which thinks it's not valid:
Expand All @@ -205,14 +205,22 @@ export async function setNextVersionInFixture(
.split('||')
.map((alternative) => {
const selector = alternative.trim()
const coerced = coerce(selector)?.format()
// we need to pick the highest version from alternatives and to handle
// comparison of both range selectors (^) and pinned prerelease version (-rc-<hash>-<date>)
// we need to use couple of tricks:
// 1. we do try to parse semver - this only works for pinned versions and will handle prereleases, it will return null for ranges
// 2. if parsing returns null, we coerce
// this will allow us to preserve prerelease identifiers for comparisons (as coercing prerelease version strip those)

const versionToCompare = (parseSemver(selector) ?? coerce(selector))?.format()
Comment on lines +208 to +215
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not actually solving a particular problem (actually it doesn't solve any I could see), but as I was debugging I failures I did notice we were using react 19 rc instead of stable for our tests against next versions that allowed stable 19. The rc was over a year old and unlikely that would be used by users, so this is mostly to increase confidence in results.


return {
selector,
coerced,
versionToCompare,
}
})
.sort((a, b) => {
return gt(a.coerced, b.coerced) ? -1 : 1
return gt(a.versionToCompare, b.versionToCompare) ? -1 : 1
})[0].selector

const reactVersion =
Expand Down
Loading