cli: fix linking with react-router

Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
This commit is contained in:
Patrik Oldsberg
2024-11-05 10:01:26 +01:00
parent 9c27b46a0a
commit e19c53c46e
2 changed files with 13 additions and 5 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'@backstage/cli': patch
---
Fix for the `--link` flag for `package start` to deduplicate `react-router` and `react-router-dom`.
@@ -48,10 +48,13 @@ export async function createWorkspaceLinkingPlugins(
}),
// react and react-dom are always resolved from the target directory
// Note: this often requires that the linked and target workspace use the same versions of React
new bundler.NormalModuleReplacementPlugin(/^react(?:-dom)?$/, resource => {
if (!relativePath(linkedRoot.dir, resource.context).startsWith('..')) {
resource.context = paths.targetDir;
}
}),
new bundler.NormalModuleReplacementPlugin(
/^react(?:-router)?(?:-dom)?$/,
resource => {
if (!relativePath(linkedRoot.dir, resource.context).startsWith('..')) {
resource.context = paths.targetDir;
}
},
),
];
}