-
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.
fix(react): ensure rspack react app is added to exclude on rspack plu…
…gin #28464 (#28515) <!-- 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 --> When you create a react rspack app when there is a `@nx/rspack/plugin` definition in the nx.json, it causes the project graph to fail to create nodes. ## Expected Behavior <!-- This is the behavior we should expect with the changes in this PR --> Ensure the projects created via @nx/react:app --bundler=rspack are added to exclude array if the plugin exists ## Related Issue(s) <!-- Please link the issue being fixed so it gets closed when this is merged. --> Fixes #28464
- Loading branch information
Showing
3 changed files
with
115 additions
and
0 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
32 changes: 32 additions & 0 deletions
32
packages/react/src/generators/application/lib/add-project-root-to-rspack-plugin-excludes.ts
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,32 @@ | ||
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); | ||
} |