Skip to content

Commit

Permalink
feat(angular): use module-federation-dev-server for hosts (#9850)
Browse files Browse the repository at this point in the history
  • Loading branch information
Coly010 authored Apr 19, 2022
1 parent fc235de commit c560c80
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 73 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,45 +11,16 @@ export function setupServeTarget(host: Tree, options: Schema) {

appConfig.targets['serve'] = {
...appConfig.targets['serve'],
executor: '@nrwl/angular:webpack-server',
executor:
options.mfeType === 'host'
? '@nrwl/angular:module-federation-dev-server'
: '@nrwl/angular:webpack-server',
options: {
...appConfig.targets['serve'].options,
port: options.port ?? undefined,
publicHost: `http://localhost:${options.port ?? 4200}`,
},
};

if (options.mfeType === 'host') {
const remoteServeCommands = options.remotes
? options.remotes.map((r) => `nx serve ${r}`)
: undefined;
const commands = remoteServeCommands
? [...remoteServeCommands, `nx serve ${options.appName}`]
: [`nx serve ${options.appName}`];

appConfig.targets['serve-mfe'] = {
executor: '@nrwl/workspace:run-commands',
options: {
commands,
},
};
}
updateProjectConfiguration(host, options.appName, appConfig);

if (options.mfeType === 'remote' && options.host) {
const hostAppConfig = readProjectConfiguration(host, options.host);

hostAppConfig.targets['serve-mfe'] = {
...hostAppConfig.targets['serve-mfe'],
options: {
...hostAppConfig.targets['serve-mfe'].options,
commands: [
`nx serve ${options.appName}`,
...hostAppConfig.targets['serve-mfe'].options.commands,
],
},
};

updateProjectConfiguration(host, options.host, hostAppConfig);
}
}
45 changes: 5 additions & 40 deletions packages/angular/src/generators/setup-mfe/setup-mfe.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,11 @@ describe('Init MFE', () => {
// ASSERT
const { build, serve } = readProjectConfiguration(tree, app).targets;

expect(serve.executor).toEqual('@nrwl/angular:webpack-server');
expect(serve.executor).toEqual(
type === 'host'
? '@nrwl/angular:module-federation-dev-server'
: '@nrwl/angular:webpack-server'
);
expect(build.executor).toEqual('@nrwl/angular:webpack-browser');
expect(build.options.customWebpackConfig.path).toEqual(
`apps/${app}/webpack.config.js`
Expand Down Expand Up @@ -221,45 +225,6 @@ describe('Init MFE', () => {
expect(hostAppModule).toMatchSnapshot();
});

it('should add a remote application and add it to a specified host applications serve-mfe target', async () => {
// ARRANGE
await applicationGenerator(tree, {
name: 'remote2',
routing: true,
});

await setupMfe(tree, {
appName: 'app1',
mfeType: 'host',
routing: true,
});

await setupMfe(tree, {
appName: 'remote1',
mfeType: 'remote',
host: 'app1',
port: 4201,
routing: true,
});

// ACT
await setupMfe(tree, {
appName: 'remote2',
mfeType: 'remote',
host: 'app1',
port: 4202,
routing: true,
});

// ASSERT
const hostAppConfig = readProjectConfiguration(tree, 'app1');
const serveMfe = hostAppConfig.targets['serve-mfe'];

expect(serveMfe.options.commands).toContain('nx serve remote1');
expect(serveMfe.options.commands).toContain('nx serve remote2');
expect(serveMfe.options.commands).toContain('nx serve app1');
});

it('should modify the associated cypress project to add the workaround correctly', async () => {
// ARRANGE
await applicationGenerator(tree, {
Expand Down

0 comments on commit c560c80

Please sign in to comment.