nx-labs
nx-labs copied to clipboard
@nx/rspack `withNx`, `withReact`, and `withWeb` are all broken with current `nx add` command
Current Behavior
If you follow the current @nx/rspack documentation, it's stated that users should execute nx add @nx/rspack
to Add Rspack to an existing workspace. However, if you execute nx add @nx/rspack
without NX_ADD_PLUGINS=false
, then a "crystal" plugin setup will be generated in the user's nx.json
file like so:
"plugins": [
{
"plugin": "@nx/rspack/plugin",
"options": {
"buildTargetName": "build",
"serveTargetName": "serve",
"previewTargetName": "preview"
}
}
],
If a "crystal" plugin setup for @nx/rspack
is located in a user's nx.json
file then the current implementations of withNx
, withReact
, and withWeb
are guaranteed to fail since they assume context.projectGraph
is defined - which it won't be for the initial run of composePlugins
's combined
function since composePlugin
is invoked (indirectly) by readRspackOptions
not runExecutor
. In other words, withNx
, withReact
, and withWeb
do not have a check for process.env['NX_TASK_TARGET_PROJECT']
to ensure that context.projectGraph
is defined by runExecutor
.
Expected Behavior
Either:
- The @nx/rspack documentation should be updated as to not mention
nx add @nx/rspack
(not great) - The
@nx/rspack
generators should be updated to prevent updating thenx.json
file (okayish) - The implementations for
withNx
,withReact
, andwithWeb
should add a basic check forprocess.env['NX_TASK_TARGET_PROJECT']
and skip their steps until it is safe to do so (better) - The implementations for
withNx
,withReact
, andwithWeb
should be updated to complete the crystal plugin integration (best)
Proposed Solution
Honestly, the quickest fix for the time being (until the crystal plugin integration is done) would be to something like this to withNx
, withReact
, and withWeb
:
if (!process.env['NX_TASK_TARGET_PROJECT']) {
return Object.assign({}, config)
}