From 007c0c85a96f44fe281ecfedc263ea34c606fbf8 Mon Sep 17 00:00:00 2001 From: Colum Ferry Date: Fri, 22 Nov 2024 14:08:28 -0500 Subject: [PATCH] fix(rspack): ensure generated app is picked up by crystal (#29048) ## Current Behavior Current projects are added to excludes of rspack plugin. Init is also not detecting rspack workspaces ## Expected Behavior Ensure excludes is not being set up when generating new apps as they are resilient to project graph creation now. Init should detect projects correctly ## Related Issue(s) Fixes # --- packages/nx/src/command-line/init/init-v2.ts | 1 + .../src/generators/application/application.ts | 3 -- .../src/generators/application/lib/add-e2e.ts | 2 ++ ...-project-root-to-rspack-plugin-excludes.ts | 32 ------------------- 4 files changed, 3 insertions(+), 35 deletions(-) delete mode 100644 packages/react/src/generators/application/lib/add-project-root-to-rspack-plugin-excludes.ts diff --git a/packages/nx/src/command-line/init/init-v2.ts b/packages/nx/src/command-line/init/init-v2.ts index d23a22818a4f9..711757a447afd 100644 --- a/packages/nx/src/command-line/init/init-v2.ts +++ b/packages/nx/src/command-line/init/init-v2.ts @@ -166,6 +166,7 @@ const npmPackageToPluginMap: Record = { vite: '@nx/vite', vitest: '@nx/vite', webpack: '@nx/webpack', + '@rspack/core': '@nx/rspack', rollup: '@nx/rollup', // Testing tools jest: '@nx/jest', diff --git a/packages/react/src/generators/application/application.ts b/packages/react/src/generators/application/application.ts index e3a49150dfa06..283e72c7a19a3 100644 --- a/packages/react/src/generators/application/application.ts +++ b/packages/react/src/generators/application/application.ts @@ -47,7 +47,6 @@ import { logShowProjectCommand } from '@nx/devkit/src/utils/log-show-project-com import { setupTailwindGenerator } from '../setup-tailwind/setup-tailwind'; import { useFlatConfig } from '@nx/eslint/src/utils/flat-config'; import { assertNotUsingTsSolutionSetup } from '@nx/js/src/utils/typescript/ts-solution-setup'; -import { addProjectRootToRspackPluginExcludesIfExists } from './lib/add-project-root-to-rspack-plugin-excludes'; async function addLinting(host: Tree, options: NormalizedSchema) { const tasks: GeneratorCallback[] = []; @@ -237,8 +236,6 @@ export async function applicationGeneratorInternal( }, false ); - } else if (options.bundler === 'rspack') { - addProjectRootToRspackPluginExcludesIfExists(host, options.appProjectRoot); } if (options.bundler !== 'vite' && options.unitTestRunner === 'vitest') { diff --git a/packages/react/src/generators/application/lib/add-e2e.ts b/packages/react/src/generators/application/lib/add-e2e.ts index c0c67f01ff9ee..e84ecea5f57a5 100644 --- a/packages/react/src/generators/application/lib/add-e2e.ts +++ b/packages/react/src/generators/application/lib/add-e2e.ts @@ -11,6 +11,7 @@ import { webStaticServeGenerator } from '@nx/web'; import { nxVersion } from '../../../utils/versions'; import { hasWebpackPlugin } from '../../../utils/has-webpack-plugin'; import { hasVitePlugin } from '../../../utils/has-vite-plugin'; +import { hasRspackPlugin } from '../../../utils/has-rspack-plugin'; import { NormalizedSchema } from '../schema'; import { findPluginForConfigFile } from '@nx/devkit/src/utils/find-plugin-for-config-file'; import { addE2eCiTargetDefaults } from '@nx/devkit/src/generators/target-defaults-utils'; @@ -22,6 +23,7 @@ export async function addE2e( ): Promise { const hasNxBuildPlugin = (options.bundler === 'webpack' && hasWebpackPlugin(tree)) || + (options.bundler === 'rspack' && hasRspackPlugin(tree)) || (options.bundler === 'vite' && hasVitePlugin(tree)); let e2eWebServerInfo: E2EWebServerDetails = { diff --git a/packages/react/src/generators/application/lib/add-project-root-to-rspack-plugin-excludes.ts b/packages/react/src/generators/application/lib/add-project-root-to-rspack-plugin-excludes.ts deleted file mode 100644 index 29b1090c02623..0000000000000 --- a/packages/react/src/generators/application/lib/add-project-root-to-rspack-plugin-excludes.ts +++ /dev/null @@ -1,32 +0,0 @@ -import { joinPathFragments, Tree, updateNxJson } from '@nx/devkit'; -import { readNxJson } from '@nx/devkit'; - -export function addProjectRootToRspackPluginExcludesIfExists( - tree: Tree, - projectRoot: string -) { - const excludeProjectGlob = joinPathFragments(projectRoot, '/**'); - const nxJson = readNxJson(tree); - if (!nxJson.plugins?.length) { - return; - } - for (let i = 0; i < nxJson.plugins.length; i++) { - let plugin = nxJson.plugins[i]; - const isRspackPlugin = - typeof plugin === 'string' - ? plugin === '@nx/rspack/plugin' - : plugin.plugin === '@nx/rspack/plugin'; - if (isRspackPlugin) { - if (typeof plugin === 'string') { - plugin = { - plugin: plugin, - exclude: [excludeProjectGlob], - }; - } else { - plugin.exclude = [...(plugin.exclude ?? []), excludeProjectGlob]; - } - nxJson.plugins[i] = plugin; - } - } - updateNxJson(tree, nxJson); -}