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(react): install @nrwl/web when module federation is used #14660

Merged
merged 1 commit into from
Jan 27, 2023
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
14 changes: 14 additions & 0 deletions packages/react/src/generators/host/host.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,20 @@ describe('hostGenerator', () => {
expect(tree.exists('apps/test/src/remotes.d.ts'));
});

it('should install @nrwl/web for the file-server executor', async () => {
const tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' });
await hostGenerator(tree, {
name: 'test',
style: 'css',
linter: Linter.None,
unitTestRunner: 'none',
e2eTestRunner: 'none',
});

const packageJson = readJson(tree, 'package.json');
expect(packageJson.devDependencies['@nrwl/web']).toBeDefined();
});

it('should generate host files and configs for SSR', async () => {
await hostGenerator(tree, {
name: 'test',
Expand Down
19 changes: 17 additions & 2 deletions packages/react/src/generators/remote/remote.spec.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,27 @@
import { readNxJson } from '@nrwl/devkit';
import { readJson, readNxJson } from '@nrwl/devkit';
import { createTreeWithEmptyWorkspace } from '@nrwl/devkit/testing';
import { Linter } from '@nrwl/linter';
import remote from './remote';

describe('remote generator', () => {
it('should not set the remote as the default project', async () => {
it('should install @nrwl/web for the file-server executor', async () => {
const tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' });
await remote(tree, {
name: 'test',
devServerPort: 4201,
e2eTestRunner: 'cypress',
linter: Linter.EsLint,
skipFormat: false,
style: 'css',
unitTestRunner: 'jest',
});

const packageJson = readJson(tree, 'package.json');
expect(packageJson.devDependencies['@nrwl/web']).toBeDefined();
});

it('should not set the remote as the default project', async () => {
const tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' });
await remote(tree, {
name: 'test',
devServerPort: 4201,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import {
addDependenciesToPackageJson,
GeneratorCallback,
readProjectConfiguration,
Tree,
updateProjectConfiguration,
} from '@nrwl/devkit';
import { nxVersion } from '../utils/versions';

export function updateModuleFederationProject(
host: Tree,
Expand All @@ -11,7 +14,7 @@ export function updateModuleFederationProject(
appProjectRoot: string;
devServerPort?: number;
}
) {
): GeneratorCallback {
const projectConfig = readProjectConfiguration(host, options.projectName);

projectConfig.targets.build.options = {
Expand Down Expand Up @@ -48,4 +51,6 @@ export function updateModuleFederationProject(
};

updateProjectConfiguration(host, options.projectName, projectConfig);

return addDependenciesToPackageJson(host, {}, { '@nrwl/web': nxVersion });
}