Skip to content

Commit

Permalink
fix(react): install @nrwl/web when module federation is used
Browse files Browse the repository at this point in the history
  • Loading branch information
jaysoo committed Jan 27, 2023
1 parent 795e4d6 commit 06301f3
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 3 deletions.
17 changes: 17 additions & 0 deletions packages/react/src/generators/host/host.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { readJson } from '@nrwl/devkit';
import { createTreeWithEmptyWorkspace } from '@nrwl/devkit/testing';
import hostGenerator from './host';
import { Linter } from '@nrwl/linter';
import remote from '@nrwl/react/src/generators/remote/remote';

describe('hostGenerator', () => {
let tree: Tree;
Expand All @@ -28,6 +29,22 @@ 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 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 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
7 changes: 6 additions & 1 deletion packages/react/src/rules/update-module-federation-project.ts
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 });
}

0 comments on commit 06301f3

Please sign in to comment.