Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(angular): add dynamic federation support to mfe generator (#9551)
- Loading branch information
Showing
17 changed files
with
334 additions
and
103 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,5 @@ | ||
export { setRemoteUrlResolver, loadRemoteModule } from './mfe'; | ||
export { | ||
setRemoteUrlResolver, | ||
setRemoteDefinitions, | ||
loadRemoteModule, | ||
} from './mfe'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
export interface Schema { | ||
name: string; | ||
remotes?: string[]; | ||
dynamic?: boolean; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 17 additions & 5 deletions
22
packages/angular/src/generators/setup-mfe/lib/fix-bootstrap.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,26 @@ | ||
import type { Tree } from '@nrwl/devkit'; | ||
import type { Schema } from '../schema'; | ||
|
||
import { joinPathFragments } from '@nrwl/devkit'; | ||
|
||
export function fixBootstrap(host: Tree, appRoot: string) { | ||
export function fixBootstrap(tree: Tree, appRoot: string, options: Schema) { | ||
const mainFilePath = joinPathFragments(appRoot, 'src/main.ts'); | ||
const bootstrapCode = host.read(mainFilePath, 'utf-8'); | ||
host.write(joinPathFragments(appRoot, 'src/bootstrap.ts'), bootstrapCode); | ||
const bootstrapCode = tree.read(mainFilePath, 'utf-8'); | ||
tree.write(joinPathFragments(appRoot, 'src/bootstrap.ts'), bootstrapCode); | ||
|
||
host.write( | ||
const bootstrapImportCode = `import('./bootstrap').catch(err => console.error(err))`; | ||
|
||
const fetchMfeManifestCode = `import { setRemoteDefinitions } from '@nrwl/angular/mfe'; | ||
fetch('/assets/mfe.manifest.json') | ||
.then((res) => res.json()) | ||
.then(definitions => setRemoteDefinitions(definitions)) | ||
.then(() => ${bootstrapImportCode})`; | ||
|
||
tree.write( | ||
mainFilePath, | ||
`import('./bootstrap').catch(err => console.error(err));` | ||
options.mfeType === 'host' && options.federationType === 'dynamic' | ||
? fetchMfeManifestCode | ||
: bootstrapImportCode | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
packages/angular/src/generators/setup-mfe/lib/setup-host-if-dynamic.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import type { Tree } from '@nrwl/devkit'; | ||
import type { Schema } from '../schema'; | ||
|
||
import { readProjectConfiguration, joinPathFragments } from '@nrwl/devkit'; | ||
|
||
export function setupHostIfDynamic(tree: Tree, options: Schema) { | ||
if (options.federationType === 'static' || options.mfeType === 'remote') { | ||
return; | ||
} | ||
|
||
const pathToMfeManifest = joinPathFragments( | ||
readProjectConfiguration(tree, options.appName).sourceRoot, | ||
'assets/mfe.manifest.json' | ||
); | ||
|
||
if (!tree.exists(pathToMfeManifest)) { | ||
tree.write(pathToMfeManifest, '{}'); | ||
} | ||
} |
Oops, something went wrong.
5378128
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs: