fix(module-federation): migration does not handle external nodes and errors (#29075)

## Current Behavior
The React + Angular migrations intended to update the path for the
`ModuleFederationConfig` imports in webpack and rspack config files will
fail on externalNodes in the project graph that have `@nx/webpack` or
`@nx/rspack` listed as a dependency.

## Expected Behavior
If the dependency is discovered in an `externalNode` we should skip that
node, instead of continuing with the migration.
This commit is contained in:
Colum Ferry 2024-11-26 14:55:02 +00:00 committed by GitHub
parent 30d722bd98
commit a5c5cbf326
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 42 additions and 0 deletions

View File

@ -22,6 +22,13 @@ jest.mock('@nx/devkit', () => {
type: 'static',
},
],
'npm:@nx/playwright': [
{
source: 'npm:@nx/playwright',
target: 'npm:@nx/webpack',
type: 'static',
},
],
},
nodes: {
shell: {
@ -43,6 +50,17 @@ jest.mock('@nx/devkit', () => {
},
},
},
externalNodes: {
'npm:@nx/playwright': {
type: 'npm',
name: 'npm:@nx/playwright',
data: {
version: '20.2.0-beta.3',
packageName: '@nx/playwright',
hash: 'sha512-8rzIZ8ljVfWsOqmSUSRPo0lT19oAhTR2nAI25V3wbFwhlErQ7kpgKd45W36Tja1aka729cO3mAH5ACKSujU6wQ==',
},
},
},
})
),
};

View File

@ -13,6 +13,9 @@ export default async function migrateMfImportsToNewPackage(tree: Tree) {
const graph = await createProjectGraphAsync();
for (const [project, dependencies] of Object.entries(graph.dependencies)) {
if (!graph.nodes[project]) {
continue;
}
const usesNxWebpack = dependencies.some(
(dep) => dep.target === 'npm:@nx/webpack'
);

View File

@ -27,6 +27,13 @@ jest.mock('@nx/devkit', () => {
type: 'static',
},
],
'npm:@nx/playwright': [
{
source: 'npm:@nx/playwright',
target: 'npm:@nx/webpack',
type: 'static',
},
],
},
nodes: {
shell: {
@ -48,6 +55,17 @@ jest.mock('@nx/devkit', () => {
},
},
},
externalNodes: {
'npm:@nx/playwright': {
type: 'npm',
name: 'npm:@nx/playwright',
data: {
version: '20.2.0-beta.3',
packageName: '@nx/playwright',
hash: 'sha512-8rzIZ8ljVfWsOqmSUSRPo0lT19oAhTR2nAI25V3wbFwhlErQ7kpgKd45W36Tja1aka729cO3mAH5ACKSujU6wQ==',
},
},
},
})
),
};

View File

@ -14,6 +14,9 @@ export default async function migrateMfImportsToNewPackage(tree: Tree) {
const graph = await createProjectGraphAsync();
for (const [project, dependencies] of Object.entries(graph.dependencies)) {
if (!graph.nodes[project]) {
continue;
}
const usesNxWebpackOrRspack = dependencies.some(
(dep) =>
dep.target === 'npm:@nx/webpack' || dep.target === 'npm:@nx/rspack'