fix(rspack): ensure generated app is picked up by crystal (#29048)

<!-- Please make sure you have read the submission guidelines before
posting an PR -->
<!--
https://github.com/nrwl/nx/blob/master/CONTRIBUTING.md#-submitting-a-pr
-->

<!-- Please make sure that your commit message follows our format -->
<!-- Example: `fix(nx): must begin with lowercase` -->

<!-- If this is a particularly complex change or feature addition, you
can request a dedicated Nx release for this pull request branch. Mention
someone from the Nx team or the `@nrwl/nx-pipelines-reviewers` and they
will confirm if the PR warrants its own release for testing purposes,
and generate it for you if appropriate. -->

## Current Behavior
<!-- This is the behavior we have today -->
Current projects are added to excludes of rspack plugin.
Init is also not detecting rspack workspaces

## Expected Behavior
<!-- This is the behavior we should expect with the changes in this PR
-->
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)
<!-- Please link the issue being fixed so it gets closed when this is
merged. -->

Fixes #
This commit is contained in:
Colum Ferry 2024-11-22 14:08:28 -05:00 committed by GitHub
parent 840d935d2e
commit 007c0c85a9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 3 additions and 35 deletions

View File

@ -166,6 +166,7 @@ const npmPackageToPluginMap: Record<string, `@nx/${string}`> = {
vite: '@nx/vite',
vitest: '@nx/vite',
webpack: '@nx/webpack',
'@rspack/core': '@nx/rspack',
rollup: '@nx/rollup',
// Testing tools
jest: '@nx/jest',

View File

@ -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') {

View File

@ -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<GeneratorCallback> {
const hasNxBuildPlugin =
(options.bundler === 'webpack' && hasWebpackPlugin(tree)) ||
(options.bundler === 'rspack' && hasRspackPlugin(tree)) ||
(options.bundler === 'vite' && hasVitePlugin(tree));
let e2eWebServerInfo: E2EWebServerDetails = {

View File

@ -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);
}