Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(module-federation): ensure @nx/module-federation package is installed for users #29416

Merged
merged 1 commit into from
Dec 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions packages/angular/migrations.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
2 changes: 2 additions & 0 deletions packages/angular/src/generators/setup-mf/setup-mf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ export async function setupMf(tree: Tree, rawOptions: Schema) {
{
'@nx/web': nxVersion,
'@nx/webpack': nxVersion,
'@nx/module-federation': nxVersion,
}
);
}
Expand Down Expand Up @@ -82,6 +83,7 @@ export async function setupMf(tree: Tree, rawOptions: Schema) {
{
'@nx/webpack': nxVersion,
'@module-federation/enhanced': moduleFederationEnhancedVersion,
'@nx/module-federation': nxVersion,
}
);
}
Expand Down
Coly010 marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -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]';
Expand Down Expand Up @@ -53,5 +55,15 @@ export default async function migrateWithMfImport(tree: Tree) {
});
}

if (projects.size !== 0) {
addDependenciesToPackageJson(
tree,
{},
{
'@nx/module-federation': nxVersion,
}
);
}

await formatFiles(tree);
}
Original file line number Diff line number Diff line change
@@ -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<string>();

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,
}
);
}
}
6 changes: 6 additions & 0 deletions packages/react/migrations.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
1 change: 1 addition & 0 deletions packages/react/src/generators/host/host.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ export async function hostGenerator(
{ '@module-federation/enhanced': moduleFederationEnhancedVersion },
{
'@nx/web': nxVersion,
'@nx/module-federation': nxVersion,
}
);
tasks.push(installTask);
Expand Down
1 change: 1 addition & 0 deletions packages/react/src/generators/remote/remote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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]';
Expand Down Expand Up @@ -53,5 +55,15 @@ export default async function migrateWithMfImport(tree: Tree) {
});
}

if (projects.size !== 0) {
addDependenciesToPackageJson(
tree,
{},
{
'@nx/module-federation': nxVersion,
}
);
}

await formatFiles(tree);
}
Original file line number Diff line number Diff line change
@@ -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<string>();

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,
}
);
}
}
6 changes: 6 additions & 0 deletions packages/rspack/migrations.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Copy link
Member

@jaysoo jaysoo Dec 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is technically already handled by Angular and React plugins right? Is there a scenario where those aren't installed by Rspack is? We don't do this for Webpack.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Each plugin is finding its own set of module-federation-dev-server executors to determine if MF projects exists.

I could combine the rspack ones into the react one, i just had them separated based on location of the executor

"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": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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]';
Expand Down Expand Up @@ -53,5 +55,15 @@ export default async function migrateWithMfImport(tree: Tree) {
});
}

if (projects.size !== 0) {
addDependenciesToPackageJson(
tree,
{},
{
'@nx/module-federation': nxVersion,
}
);
}

await formatFiles(tree);
}
Original file line number Diff line number Diff line change
@@ -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<string>();

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,
}
);
}
}
Loading