From d01acef76b10395e48cf819c7e4ba480ca001b88 Mon Sep 17 00:00:00 2001 From: Colum Ferry Date: Thu, 9 Jan 2025 12:12:37 +0000 Subject: [PATCH] fix(nextjs): ensure next 14 is installed if react 18 --- .../packages/react/generators/application.json | 2 +- .../packages/workspace/generators/preset.json | 2 +- packages/next/src/generators/init/init.ts | 10 ++++++++-- packages/next/src/utils/version-utils.ts | 3 ++- packages/react/src/generators/application/schema.json | 2 +- packages/workspace/src/generators/preset/schema.d.ts | 2 +- packages/workspace/src/generators/preset/schema.json | 2 +- 7 files changed, 15 insertions(+), 8 deletions(-) diff --git a/docs/generated/packages/react/generators/application.json b/docs/generated/packages/react/generators/application.json index 588918160327f..ca2d6d8128183 100644 --- a/docs/generated/packages/react/generators/application.json +++ b/docs/generated/packages/react/generators/application.json @@ -95,7 +95,7 @@ "bundler": { "description": "The bundler to use.", "type": "string", - "enum": ["vite", "webpack", "rspack", "rsbuild"], + "enum": ["vite", "rsbuild", "rspack", "webpack"], "x-prompt": "Which bundler do you want to use to build the application?", "default": "vite", "x-priority": "important" diff --git a/docs/generated/packages/workspace/generators/preset.json b/docs/generated/packages/workspace/generators/preset.json index 89a5aedc41643..9fa202b6f0670 100644 --- a/docs/generated/packages/workspace/generators/preset.json +++ b/docs/generated/packages/workspace/generators/preset.json @@ -69,7 +69,7 @@ "bundler": { "description": "The bundler to use for building the application.", "type": "string", - "enum": ["webpack", "vite", "rspack", "esbuild"], + "enum": ["vite", "rspack", "rsbuild", "esbuild", "webpack"], "default": "vite" }, "docker": { diff --git a/packages/next/src/generators/init/init.ts b/packages/next/src/generators/init/init.ts index 49fa77f47e8f9..9d1350cab9e89 100644 --- a/packages/next/src/generators/init/init.ts +++ b/packages/next/src/generators/init/init.ts @@ -8,7 +8,10 @@ import { createProjectGraphAsync, } from '@nx/devkit'; import { addPlugin } from '@nx/devkit/src/utils/add-plugin'; -import { getReactDependenciesVersionsToInstall } from '@nx/react/src/utils/version-utils'; +import { + getReactDependenciesVersionsToInstall, + isReact18, +} from '@nx/react/src/utils/version-utils'; import { addGitIgnoreEntry } from '../../utils/add-gitignore-entry'; import { nxVersion } from '../../utils/versions'; import { getNextDependenciesVersionsToInstall } from '../../utils/version-utils'; @@ -19,7 +22,10 @@ async function updateDependencies(host: Tree, schema: InitSchema) { tasks.push(removeDependenciesFromPackageJson(host, ['@nx/next'], [])); - const versions = await getNextDependenciesVersionsToInstall(host); + const versions = await getNextDependenciesVersionsToInstall( + host, + await isReact18(host) + ); const reactVersions = await getReactDependenciesVersionsToInstall(host); tasks.push( diff --git a/packages/next/src/utils/version-utils.ts b/packages/next/src/utils/version-utils.ts index 36904d7bfad3e..24472a912050d 100644 --- a/packages/next/src/utils/version-utils.ts +++ b/packages/next/src/utils/version-utils.ts @@ -7,7 +7,8 @@ type NextDependenciesVersions = { }; export async function getNextDependenciesVersionsToInstall( - tree: Tree + tree: Tree, + isReact18 = false ): Promise { if (await isNext14(tree)) { return { diff --git a/packages/react/src/generators/application/schema.json b/packages/react/src/generators/application/schema.json index 7fa75f15889f7..d384322b53be8 100644 --- a/packages/react/src/generators/application/schema.json +++ b/packages/react/src/generators/application/schema.json @@ -101,7 +101,7 @@ "bundler": { "description": "The bundler to use.", "type": "string", - "enum": ["vite", "webpack", "rspack", "rsbuild"], + "enum": ["vite", "rsbuild", "rspack", "webpack"], "x-prompt": "Which bundler do you want to use to build the application?", "default": "vite", "x-priority": "important" diff --git a/packages/workspace/src/generators/preset/schema.d.ts b/packages/workspace/src/generators/preset/schema.d.ts index b2a9c23e08f10..6587a027d7f7d 100644 --- a/packages/workspace/src/generators/preset/schema.d.ts +++ b/packages/workspace/src/generators/preset/schema.d.ts @@ -11,7 +11,7 @@ export interface Schema { standaloneConfig?: boolean; framework?: string; packageManager?: PackageManager; - bundler?: 'vite' | 'webpack' | 'rspack' | 'esbuild'; + bundler?: 'vite' | 'rsbuild' | 'webpack' | 'rspack' | 'esbuild'; docker?: boolean; nextAppDir?: boolean; nextSrcDir?: boolean; diff --git a/packages/workspace/src/generators/preset/schema.json b/packages/workspace/src/generators/preset/schema.json index e3fdb0fae07ad..91137092a9af2 100644 --- a/packages/workspace/src/generators/preset/schema.json +++ b/packages/workspace/src/generators/preset/schema.json @@ -72,7 +72,7 @@ "bundler": { "description": "The bundler to use for building the application.", "type": "string", - "enum": ["webpack", "vite", "rspack", "esbuild"], + "enum": ["vite", "rspack", "rsbuild", "esbuild", "webpack"], "default": "vite" }, "docker": {