diff --git a/packages/angular/migrations.json b/packages/angular/migrations.json index 20a934084cfcc..4b4b829bf63be 100644 --- a/packages/angular/migrations.json +++ b/packages/angular/migrations.json @@ -332,6 +332,12 @@ }, "description": "Remove the deprecated 'tailwindConfig' option from ng-packagr executors. Tailwind CSS configurations located at the project or workspace root will be picked up automatically.", "factory": "./src/migrations/update-20-2-0/remove-tailwind-config-from-ng-packagr-executors" + }, + "ensure-nx-module-federation-package": { + "cli": "nx", + "version": "20.3.0-beta.2", + "description": "If workspace includes Module Federation projects, ensure the new @nx/module-federation package is installed.", + "factory": "./src/migrations/update-20-3-0/ensure-nx-module-federation-package" } }, "packageJsonUpdates": { diff --git a/packages/angular/src/generators/setup-mf/setup-mf.ts b/packages/angular/src/generators/setup-mf/setup-mf.ts index bed23cc855fd9..9463f342d6f92 100644 --- a/packages/angular/src/generators/setup-mf/setup-mf.ts +++ b/packages/angular/src/generators/setup-mf/setup-mf.ts @@ -51,6 +51,7 @@ export async function setupMf(tree: Tree, rawOptions: Schema) { { '@nx/web': nxVersion, '@nx/webpack': nxVersion, + '@nx/module-federation': nxVersion, } ); } @@ -82,6 +83,7 @@ export async function setupMf(tree: Tree, rawOptions: Schema) { { '@nx/webpack': nxVersion, '@module-federation/enhanced': moduleFederationEnhancedVersion, + '@nx/module-federation': nxVersion, } ); } diff --git a/packages/angular/src/migrations/update-20-2-0/migrate-with-mf-import-to-new-package.ts b/packages/angular/src/migrations/update-20-2-0/migrate-with-mf-import-to-new-package.ts index 5f3f19edf93a7..c75d627b9b340 100644 --- a/packages/angular/src/migrations/update-20-2-0/migrate-with-mf-import-to-new-package.ts +++ b/packages/angular/src/migrations/update-20-2-0/migrate-with-mf-import-to-new-package.ts @@ -3,9 +3,11 @@ import { formatFiles, readProjectConfiguration, visitNotIgnoredFiles, + addDependenciesToPackageJson, } from '@nx/devkit'; import { forEachExecutorOptions } from '@nx/devkit/src/generators/executor-options-utils'; import { tsquery } from '@phenomnomnominal/tsquery'; +import { nxVersion } from '../../utils/versions'; const NX_ANGULAR_MODULE_FEDERATION_IMPORT_SELECTOR = 'ImportDeclaration > StringLiteral[value=@nx/angular/module-federation], VariableStatement CallExpression:has(Identifier[name=require]) > StringLiteral[value=@nx/angular/module-federation]'; @@ -53,5 +55,15 @@ export default async function migrateWithMfImport(tree: Tree) { }); } + if (projects.size !== 0) { + addDependenciesToPackageJson( + tree, + {}, + { + '@nx/module-federation': nxVersion, + } + ); + } + await formatFiles(tree); } diff --git a/packages/angular/src/migrations/update-20-3-0/ensure-nx-module-federation-package.ts b/packages/angular/src/migrations/update-20-3-0/ensure-nx-module-federation-package.ts new file mode 100644 index 0000000000000..3491a8aed90c2 --- /dev/null +++ b/packages/angular/src/migrations/update-20-3-0/ensure-nx-module-federation-package.ts @@ -0,0 +1,30 @@ +import { + type Tree, + readProjectConfiguration, + addDependenciesToPackageJson, +} from '@nx/devkit'; +import { forEachExecutorOptions } from '@nx/devkit/src/generators/executor-options-utils'; +import { nxVersion } from '../../utils/versions'; + +export default async function ensureMfPackage(tree: Tree) { + const projects = new Set(); + + forEachExecutorOptions( + tree, + '@nx/angular:module-federation-dev-server', + (options, project, target) => { + const projectConfig = readProjectConfiguration(tree, project); + projects.add(projectConfig.root); + } + ); + + if (projects.size !== 0) { + addDependenciesToPackageJson( + tree, + {}, + { + '@nx/module-federation': nxVersion, + } + ); + } +} diff --git a/packages/react/migrations.json b/packages/react/migrations.json index 83c5716ced6e8..47d3d672211fc 100644 --- a/packages/react/migrations.json +++ b/packages/react/migrations.json @@ -41,6 +41,12 @@ "version": "20.2.0-beta.2", "description": "Update the withModuleFederation import use @nx/module-federation/webpack.", "factory": "./src/migrations/update-20-2-0/migrate-with-mf-import-to-new-package" + }, + "ensure-nx-module-federation-package": { + "cli": "nx", + "version": "20.3.0-beta.2", + "description": "If workspace includes Module Federation projects, ensure the new @nx/module-federation package is installed.", + "factory": "./src/migrations/update-20-3-0/ensure-nx-module-federation-package" } }, "packageJsonUpdates": { diff --git a/packages/react/src/generators/host/host.ts b/packages/react/src/generators/host/host.ts index fcd302431dc26..eb0d9d7dfd57a 100644 --- a/packages/react/src/generators/host/host.ts +++ b/packages/react/src/generators/host/host.ts @@ -153,6 +153,7 @@ export async function hostGenerator( { '@module-federation/enhanced': moduleFederationEnhancedVersion }, { '@nx/web': nxVersion, + '@nx/module-federation': nxVersion, } ); tasks.push(installTask); diff --git a/packages/react/src/generators/remote/remote.ts b/packages/react/src/generators/remote/remote.ts index 88cde9458e483..cda1ba83d8d56 100644 --- a/packages/react/src/generators/remote/remote.ts +++ b/packages/react/src/generators/remote/remote.ts @@ -226,6 +226,7 @@ export async function remoteGenerator(host: Tree, schema: Schema) { { '@module-federation/enhanced': moduleFederationEnhancedVersion, '@nx/web': nxVersion, + '@nx/module-federation': nxVersion, } ); tasks.push(installTask); diff --git a/packages/react/src/migrations/update-20-2-0/migrate-with-mf-import-to-new-package.ts b/packages/react/src/migrations/update-20-2-0/migrate-with-mf-import-to-new-package.ts index bd297f5786d81..1392c83d69a35 100644 --- a/packages/react/src/migrations/update-20-2-0/migrate-with-mf-import-to-new-package.ts +++ b/packages/react/src/migrations/update-20-2-0/migrate-with-mf-import-to-new-package.ts @@ -3,9 +3,11 @@ import { formatFiles, readProjectConfiguration, visitNotIgnoredFiles, + addDependenciesToPackageJson, } from '@nx/devkit'; import { forEachExecutorOptions } from '@nx/devkit/src/generators/executor-options-utils'; import { tsquery } from '@phenomnomnominal/tsquery'; +import { nxVersion } from '../../utils/versions'; const NX_RSPACK_MODULE_FEDERATION_IMPORT_SELECTOR = 'ImportDeclaration > StringLiteral[value=@nx/react/module-federation], VariableStatement CallExpression:has(Identifier[name=require]) > StringLiteral[value=@nx/react/module-federation]'; @@ -53,5 +55,15 @@ export default async function migrateWithMfImport(tree: Tree) { }); } + if (projects.size !== 0) { + addDependenciesToPackageJson( + tree, + {}, + { + '@nx/module-federation': nxVersion, + } + ); + } + await formatFiles(tree); } diff --git a/packages/react/src/migrations/update-20-3-0/ensure-nx-module-federation-package.ts b/packages/react/src/migrations/update-20-3-0/ensure-nx-module-federation-package.ts new file mode 100644 index 0000000000000..4366f54cebee1 --- /dev/null +++ b/packages/react/src/migrations/update-20-3-0/ensure-nx-module-federation-package.ts @@ -0,0 +1,30 @@ +import { + type Tree, + readProjectConfiguration, + addDependenciesToPackageJson, +} from '@nx/devkit'; +import { forEachExecutorOptions } from '@nx/devkit/src/generators/executor-options-utils'; +import { nxVersion } from '../../utils/versions'; + +export default async function ensureMfPackage(tree: Tree) { + const projects = new Set(); + + forEachExecutorOptions( + tree, + '@nx/react:module-federation-dev-server', + (options, project, target) => { + const projectConfig = readProjectConfiguration(tree, project); + projects.add(projectConfig.root); + } + ); + + if (projects.size !== 0) { + addDependenciesToPackageJson( + tree, + {}, + { + '@nx/module-federation': nxVersion, + } + ); + } +} diff --git a/packages/rspack/migrations.json b/packages/rspack/migrations.json index f519d2c3b6d9b..c3beadc9fe1bc 100644 --- a/packages/rspack/migrations.json +++ b/packages/rspack/migrations.json @@ -5,6 +5,12 @@ "version": "20.2.0-beta.3", "description": "Update the withModuleFederation import use @nx/module-federation/rspack.", "factory": "./src/migrations/update-20-2-0/migrate-with-mf-import-to-new-package" + }, + "ensure-nx-module-federation-package": { + "cli": "nx", + "version": "20.3.0-beta.2", + "description": "If workspace includes Module Federation projects, ensure the new @nx/module-federation package is installed.", + "factory": "./src/migrations/update-20-3-0/ensure-nx-module-federation-package" } }, "packageJsonUpdates": { diff --git a/packages/rspack/src/migrations/update-20-2-0/migrate-with-mf-import-to-new-package.ts b/packages/rspack/src/migrations/update-20-2-0/migrate-with-mf-import-to-new-package.ts index 8e9461633c094..12c77741b568a 100644 --- a/packages/rspack/src/migrations/update-20-2-0/migrate-with-mf-import-to-new-package.ts +++ b/packages/rspack/src/migrations/update-20-2-0/migrate-with-mf-import-to-new-package.ts @@ -3,9 +3,11 @@ import { formatFiles, readProjectConfiguration, visitNotIgnoredFiles, + addDependenciesToPackageJson, } from '@nx/devkit'; import { forEachExecutorOptions } from '@nx/devkit/src/generators/executor-options-utils'; import { tsquery } from '@phenomnomnominal/tsquery'; +import { nxVersion } from '../../utils/versions'; const NX_RSPACK_MODULE_FEDERATION_IMPORT_SELECTOR = 'ImportDeclaration > StringLiteral[value=@nx/rspack/module-federation], VariableStatement CallExpression:has(Identifier[name=require]) > StringLiteral[value=@nx/rspack/module-federation]'; @@ -53,5 +55,15 @@ export default async function migrateWithMfImport(tree: Tree) { }); } + if (projects.size !== 0) { + addDependenciesToPackageJson( + tree, + {}, + { + '@nx/module-federation': nxVersion, + } + ); + } + await formatFiles(tree); } diff --git a/packages/rspack/src/migrations/update-20-3-0/ensure-nx-module-federation-package.ts b/packages/rspack/src/migrations/update-20-3-0/ensure-nx-module-federation-package.ts new file mode 100644 index 0000000000000..91cc0c4614bae --- /dev/null +++ b/packages/rspack/src/migrations/update-20-3-0/ensure-nx-module-federation-package.ts @@ -0,0 +1,30 @@ +import { + type Tree, + readProjectConfiguration, + addDependenciesToPackageJson, +} from '@nx/devkit'; +import { forEachExecutorOptions } from '@nx/devkit/src/generators/executor-options-utils'; +import { nxVersion } from '../../utils/versions'; + +export default async function ensureMfPackage(tree: Tree) { + const projects = new Set(); + + forEachExecutorOptions( + tree, + '@nx/rspack:module-federation-dev-server', + (options, project, target) => { + const projectConfig = readProjectConfiguration(tree, project); + projects.add(projectConfig.root); + } + ); + + if (projects.size !== 0) { + addDependenciesToPackageJson( + tree, + {}, + { + '@nx/module-federation': nxVersion, + } + ); + } +}