-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(nextjs): add support for Next 15
- Loading branch information
Showing
6 changed files
with
75 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import { type Tree, readJson, createProjectGraphAsync } from '@nx/devkit'; | ||
import { clean, coerce, major } from 'semver'; | ||
import { nextVersion, next14Version } from './versions'; | ||
|
||
type NextDependenciesVersions = { | ||
next: string; | ||
}; | ||
|
||
export async function getNextDependenciesVersionsToInstall( | ||
tree: Tree | ||
): Promise<NextDependenciesVersions> { | ||
if (await isNext14(tree)) { | ||
return { | ||
next: next14Version, | ||
}; | ||
} else { | ||
return { | ||
next: nextVersion, | ||
}; | ||
} | ||
} | ||
|
||
export async function isNext14(tree: Tree) { | ||
let installedNextVersion = await getInstalledNextVersionFromGraph(); | ||
if (!installedNextVersion) { | ||
installedNextVersion = getInstalledNextVersion(tree); | ||
} | ||
return major(installedNextVersion) === 14; | ||
} | ||
|
||
export function getInstalledNextVersion(tree: Tree): string { | ||
const pkgJson = readJson(tree, 'package.json'); | ||
const installedNextVersion = | ||
pkgJson.dependencies && pkgJson.dependencies['next']; | ||
|
||
if ( | ||
!installedNextVersion || | ||
installedNextVersion === 'latest' || | ||
installedNextVersion === 'next' | ||
) { | ||
return clean(nextVersion) ?? coerce(nextVersion).version; | ||
} | ||
|
||
return clean(installedNextVersion) ?? coerce(installedNextVersion).version; | ||
} | ||
|
||
export async function getInstalledNextVersionFromGraph() { | ||
const graph = await createProjectGraphAsync(); | ||
const nextDep = graph.externalNodes?.['npm:next']; | ||
if (!nextDep) { | ||
return undefined; | ||
} | ||
return clean(nextDep.data.version) ?? coerce(nextDep.data.version).version; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters