-
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(react): add support for React 19 for new Workspaces (#29286)
## Current Behavior We currently have no support for React 19, generating only React 18 applications. ## Expected Behavior Add utils to determine what version of React is installed in the workspace. If React 18 is the main version of react installed, continue to generate React 18 projects. If React 19 is the main version of react installed, generate React 19 projects. If no React version is installed or can be determined, generate React 19 projects.
- Loading branch information
Showing
30 changed files
with
512 additions
and
155 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
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
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,55 @@ | ||
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, | ||
isReact18 = false | ||
): 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
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
Oops, something went wrong.