Skip to content

Commit d348e37

Browse files
committed
feat(mf): update for angular 20
1 parent 31c8117 commit d348e37

File tree

11 files changed

+2296
-9285
lines changed

11 files changed

+2296
-9285
lines changed

libs/mf-runtime/enhanced/src/lib/init-federation.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ export async function initFederation(
4646
}
4747

4848
const runtimeConfig = toRuntimeConfig(config, options);
49-
return init(runtimeConfig);
49+
return init(runtimeConfig as any) as any;
5050
}
5151

5252
export function toRuntimeConfig(

libs/mf-runtime/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
22
"name": "@angular-architects/module-federation-runtime",
33
"license": "MIT",
4-
"version": "19.0.3",
4+
"version": "20.0.0",
55
"peerDependencies": {
6-
"@angular/common": ">=18.0.0",
7-
"@angular/core": ">=18.0.0",
6+
"@angular/common": ">=20.0.0",
7+
"@angular/core": ">=20.0.0",
88
"@module-federation/enhanced": "^0.9.0",
99
"@module-federation/runtime-core": "^0.6.21"
1010
},

libs/mf-tools/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@angular-architects/module-federation-tools",
3-
"version": "19.0.3",
3+
"version": "20.0.0",
44
"license": "MIT",
55
"peerDependencies": {},
66
"dependencies": {

libs/mf/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@angular-architects/module-federation",
3-
"version": "19.0.3",
3+
"version": "20.0.0",
44
"license": "MIT",
55
"repository": {
66
"type": "GitHub",
@@ -17,7 +17,7 @@
1717
"schematics": "./collection.json",
1818
"builders": "./builders.json",
1919
"dependencies": {
20-
"@angular-architects/module-federation-runtime": "19.0.3",
20+
"@angular-architects/module-federation-runtime": "20.0.0",
2121
"word-wrap": "^1.2.3",
2222
"callsite": "^1.0.0",
2323
"node-fetch": "^2.6.7",

libs/mf/src/schematics/init-rspack/files/federation.config.ts__tmpl__

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export default withFederation({
66
name: '<%=project%>',
77

88
exposes: {
9-
'./Component': './src/app/app.component.ts',
9+
'./Component': './<%=appComponent%>',
1010
},
1111
<% } else if (type === 'host') { %>
1212
remotes: {<% for (key in remoteMap) { %>
Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { createConfig } from '@ng-rsbuild/plugin-angular';
22
import applyFederation from './federation.config';
33

4-
const rsbuildConfig = createConfig(
4+
export default createConfig(
55
{
66
browser: './src/main.ts',
77
},
@@ -11,5 +11,3 @@ const rsbuildConfig = createConfig(
1111
},
1212
}
1313
);
14-
15-
export default applyFederation(rsbuildConfig);

libs/mf/src/schematics/init-rspack/schematic.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,11 @@ type PackageJson = {
4545
};
4646

4747
const RSPACK_DEPS = {
48-
'@module-federation/enhanced': '0.8.7',
48+
'@module-federation/enhanced': '0.14.3',
4949
};
5050

5151
const RSPACK_DEV_DEPS = {
52-
'@ng-rsbuild/plugin-angular': '19.0.0-alpha.14',
52+
'@ng-rsbuild/plugin-angular': '^21.0.0',
5353
};
5454

5555
export function init(options: MfSchematicSchema): Rule {
@@ -68,10 +68,20 @@ export function init(options: MfSchematicSchema): Rule {
6868

6969
const remoteMap = await generateRemoteMap(workspace, projectName);
7070

71+
const cand1 = path.join(projectSourceRoot, 'app', 'app.component.ts');
72+
const cand2 = path.join(projectSourceRoot, 'app', 'app.ts');
73+
74+
const appComponent = tree.exists(cand1)
75+
? cand1
76+
: tree.exists(cand2)
77+
? cand2
78+
: 'update-this.ts';
79+
7180
const generateRule = await generateRsBuildConfig(
7281
remoteMap,
7382
projectRoot,
7483
projectSourceRoot,
84+
appComponent,
7585
options
7686
);
7787

@@ -305,6 +315,7 @@ async function generateRsBuildConfig(
305315
remoteMap: Record<string, string>,
306316
projectRoot: string,
307317
projectSourceRoot: string,
318+
appComponent: string,
308319
options: MfSchematicSchema
309320
) {
310321
const tmpl = url('./files');
@@ -316,6 +327,7 @@ async function generateRsBuildConfig(
316327
remoteMap,
317328
...options,
318329
tmpl: '',
330+
appComponent,
319331
}),
320332
move(projectRoot),
321333
]);

libs/mf/src/schematics/init-webpack/files/webpack.config.js__tmpl__

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ module.exports = withModuleFederationPlugin({
55
name: '<%=project%>',
66

77
exposes: {
8-
'./Component': './<%=projectSourceRoot%>/app/app.component.ts',
8+
'./Component': './<%=appComponent%>',
99
},
1010
<% } else if (type === 'host') { %>
1111
remotes: {<% for (key in remoteMap) { %>

libs/mf/src/schematics/init-webpack/schematic.ts

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@ async function generateWebpackConfig(
168168
remoteMap: Record<string, string>,
169169
projectRoot: string,
170170
projectSourceRoot: string,
171+
appComponent: string,
171172
options: MfSchematicSchema
172173
) {
173174
const tmpl = url('./files');
@@ -178,6 +179,7 @@ async function generateWebpackConfig(
178179
projectSourceRoot,
179180
remoteMap,
180181
...options,
182+
appComponent,
181183
tmpl: '',
182184
}),
183185
move(projectRoot),
@@ -286,6 +288,15 @@ export default function config(options: MfSchematicSchema): Rule {
286288

287289
const remoteMap = await generateRemoteMap(workspace, projectName);
288290

291+
const cand1 = path.join(projectSourceRoot, 'app', 'app.component.ts');
292+
const cand2 = path.join(projectSourceRoot, 'app', 'app.ts');
293+
294+
const appComponent = tree.exists(cand1)
295+
? cand1
296+
: tree.exists(cand2)
297+
? cand2
298+
: 'update-this.ts';
299+
289300
let generateRule = null;
290301

291302
if (options.type === 'legacy') {
@@ -302,6 +313,7 @@ export default function config(options: MfSchematicSchema): Rule {
302313
remoteMap,
303314
projectRoot,
304315
projectSourceRoot,
316+
appComponent,
305317
options
306318
);
307319
}
@@ -353,6 +365,14 @@ export default function config(options: MfSchematicSchema): Rule {
353365
projectConfig.architect.serve.options = {};
354366
}
355367

368+
const indexPath = path.join(projectSourceRoot, 'index.html');
369+
370+
projectConfig.architect.build.options.outputPath =
371+
projectConfig.architect.build.options.outputPath ?? `dist/${projectName}`;
372+
373+
projectConfig.architect.build.options.index =
374+
projectConfig.architect.build.options.index ?? indexPath;
375+
356376
projectConfig.architect.build.builder = buildBuilder;
357377
projectConfig.architect.build.options[webpackProperty] =
358378
getWebpackConfigValue(options.nxBuilders, configPath);
@@ -403,14 +423,31 @@ export default function config(options: MfSchematicSchema): Rule {
403423

404424
const dep = getPackageJsonDependency(tree, 'ngx-build-plus');
405425

406-
if (!dep || !semver.satisfies(dep.version, '>=19.0.0')) {
426+
let installDeps = false;
427+
if (!dep || !semver.satisfies(dep.version, '>=20.0.0')) {
407428
addPackageJsonDependency(tree, {
408429
name: 'ngx-build-plus',
409430
type: NodeDependencyType.Dev,
410-
version: '^19.0.0',
431+
version: '^20.0.0',
411432
overwrite: true,
412433
});
413434

435+
installDeps = true;
436+
}
437+
438+
if (!getPackageJsonDependency(tree, '@angular-devkit/build-angular')) {
439+
addPackageJsonDependency(tree, {
440+
name: '@angular-devkit/build-angular',
441+
type: NodeDependencyType.Dev,
442+
version:
443+
getPackageJsonDependency(tree, '@angular/cli')?.version || 'latest',
444+
overwrite: false,
445+
});
446+
447+
installDeps = true;
448+
}
449+
450+
if (installDeps) {
414451
context.addTask(new NodePackageInstallTask());
415452
}
416453

libs/mf/src/schematics/init/schema.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
},
5050
{
5151
"value": "module-federation-rsbuild-experimental",
52-
"label": "Module Federation with rsbuild (experimental nextgen)"
52+
"label": "Module Federation with rsbuild (experimental nextgen); no Angular 20 support yet!"
5353
},
5454
{
5555
"value": "native-federation-esbuild",

0 commit comments

Comments
 (0)