Skip to content

Commit

Permalink
update mf v17
Browse files Browse the repository at this point in the history
  • Loading branch information
nthaidang authored and raknjarasoa committed Apr 4, 2024
1 parent 2cdad2b commit 46be0a6
Show file tree
Hide file tree
Showing 24 changed files with 83 additions and 79 deletions.
5 changes: 1 addition & 4 deletions apps/mfe1/src/app/demo/demo.component.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
import {
AuthService,
PlaygroundLibModule,
} from '@angular-architects/playground-lib';
import { AuthService, PlaygroundLibModule } from '@agorapulse/playground-lib';
import { CommonModule } from '@angular/common';
import { Component } from '@angular/core';

Expand Down
2 changes: 1 addition & 1 deletion apps/mfe1/src/main.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { initFederation } from '@angular-architects/native-federation';
import { initFederation } from '@agorapulse/native-federation';

initFederation()
.then(() => import('./bootstrap'))
Expand Down
2 changes: 1 addition & 1 deletion apps/mfe2/src/main.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { initFederation } from '@angular-architects/native-federation';
import { initFederation } from '@agorapulse/native-federation';

initFederation('/assets/federation.manifest.json')
.catch((err) => console.error(err))
Expand Down
10 changes: 5 additions & 5 deletions apps/native-federation-e2e/tests/native-federation.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ describe('native-federation e2e', () => {
// are not dependant on one another.
beforeAll(() => {
ensureNxProject(
'@angular-architects/native-federation',
'@agorapulse/native-federation',
'dist/libs/native-federation'
);
});
Expand All @@ -29,7 +29,7 @@ describe('native-federation e2e', () => {
it('should create native-federation', async () => {
const project = uniq('native-federation');
await runNxCommandAsync(
`generate @angular-architects/native-federation:native-federation ${project}`
`generate @agorapulse/native-federation:native-federation ${project}`
);
const result = await runNxCommandAsync(`build ${project}`);
expect(result.stdout).toContain('Executor ran');
Expand All @@ -39,7 +39,7 @@ describe('native-federation e2e', () => {
it('should create src in the specified directory', async () => {
const project = uniq('native-federation');
await runNxCommandAsync(
`generate @angular-architects/native-federation:native-federation ${project} --directory subdir`
`generate @agorapulse/native-federation:native-federation ${project} --directory subdir`
);
expect(() =>
checkFilesExist(`libs/subdir/${project}/src/index.ts`)
Expand All @@ -51,11 +51,11 @@ describe('native-federation e2e', () => {
it('should add tags to the project', async () => {
const projectName = uniq('native-federation');
ensureNxProject(
'@angular-architects/native-federation',
'@agorapulse/native-federation',
'dist/libs/native-federation'
);
await runNxCommandAsync(
`generate @angular-architects/native-federation:native-federation ${projectName} --tags e2etag,e2ePackage`
`generate @agorapulse/native-federation:native-federation ${projectName} --tags e2etag,e2ePackage`
);
const project = readJson(`libs/${projectName}/project.json`);
expect(project.tags).toEqual(['e2etag', 'e2ePackage']);
Expand Down
4 changes: 2 additions & 2 deletions apps/playground/src/app/app.component.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { loadRemoteModule } from '@angular-architects/native-federation';
import { AuthService } from '@angular-architects/playground-lib';
import { loadRemoteModule } from '@agorapulse/native-federation';
import { AuthService } from '@agorapulse/playground-lib';
import { Component, Type } from '@angular/core';

@Component({
Expand Down
2 changes: 1 addition & 1 deletion apps/playground/src/main.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { initFederation } from '@angular-architects/native-federation';
import { initFederation } from '@agorapulse/native-federation';

initFederation({
//'mfe1': 'http://localhost:3001/remoteEntry.json'
Expand Down
2 changes: 1 addition & 1 deletion libs/mf-runtime/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "@angular-architects/module-federation-runtime",
"name": "@agorapulse/module-federation-runtime",
"license": "MIT",
"version": "17.0.7",
"peerDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion libs/mf-tools/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "@angular-architects/module-federation-tools",
"name": "@agorapulse/module-federation-tools",
"version": "17.0.7",
"license": "MIT",
"peerDependencies": {},
Expand Down
2 changes: 1 addition & 1 deletion libs/mf-tools/src/lib/utils/global-state.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export const packageNamespace = '@angular-architects/module-federation-tools';
export const packageNamespace = '@agorapulse/module-federation-tools';

function getGlobalState<T>(): T {
const globalState = window as unknown as { [packageNamespace]: T };
Expand Down
2 changes: 1 addition & 1 deletion libs/mf-tools/src/lib/web-components/bootstrap-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export type Options = {
/**
* Deactivate support for legacy mode.
* Only recommanded if all used implementations depend on
* @angular-architects/module-federation-tools > 13.0.1.
* @agorapulse/module-federation-tools > 13.0.1.
* Default value true.
*/
activeLegacyMode?: boolean;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { ActivatedRoute } from '@angular/router';
import {
LoadRemoteModuleOptions,
loadRemoteModule,
} from '@angular-architects/module-federation-runtime';
} from '@agorapulse/module-federation-runtime';

export type WebComponentWrapperOptions = LoadRemoteModuleOptions & {
elementName: string;
Expand Down
6 changes: 3 additions & 3 deletions libs/mf/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "@angular-architects/module-federation",
"name": "@agorapulse/module-federation",
"version": "17.0.7",
"license": "MIT",
"repository": {
Expand All @@ -17,7 +17,7 @@
"schematics": "./collection.json",
"builders": "./builders.json",
"dependencies": {
"@angular-architects/module-federation-runtime": "17.0.7",
"@agorapulse/module-federation-runtime": "17.0.7",
"word-wrap": "^1.2.3",
"callsite": "^1.0.0",
"node-fetch": "^2.6.7",
Expand All @@ -27,7 +27,7 @@
"ng-update": {
"migrations": "./migrations.json",
"package-group": [
"@angular-architects/module-federation-tools",
"@agorapulse/module-federation-tools",
"ngx-build-plus"
]
}
Expand Down
2 changes: 1 addition & 1 deletion libs/mf/src/generators/mf/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export default async function (host: Tree, options: MfGeneratorSchema) {
sourceRoot: `${normalizedOptions.projectRoot}/src`,
targets: {
build: {
executor: '@angular-architects/mf:build',
executor: '@agorapulse/mf:build',
},
},
tags: normalizedOptions.parsedTags,
Expand Down
2 changes: 1 addition & 1 deletion libs/mf/src/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export * from '@angular-architects/module-federation-runtime';
export * from '@agorapulse/module-federation-runtime';
6 changes: 3 additions & 3 deletions libs/mf/src/schematics/mf/schematic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export function adjustSSR(sourceRoot: string, ssrMappings: string): Rule {
let content = tree.read(server).toString('utf-8');

const imports = `import { CustomResourceLoader } from '@nguniversal/common/clover/server/src/custom-resource-loader';
import { createFetch } from '@angular-architects/module-federation/nguniversal';
import { createFetch } from '@agorapulse/module-federation/nguniversal';
`;

content = imports + content;
Expand Down Expand Up @@ -84,7 +84,7 @@ function makeMainAsync(main: string, options: MfSchematicSchema): Rule {

let newMainContent = '';
if (options.type === 'dynamic-host') {
newMainContent = `import { initFederation } from '@angular-architects/module-federation';
newMainContent = `import { initFederation } from '@agorapulse/module-federation';
initFederation('/assets/mf.manifest.json')
.catch(err => console.error(err))
Expand Down Expand Up @@ -127,7 +127,7 @@ function updatePackageJson(tree: Tree): void {

if (!packageJson.scripts['run:all']) {
packageJson.scripts['run:all'] =
'node node_modules/@angular-architects/module-federation/src/server/mf-dev-server.js';
'node node_modules/@agorapulse/module-federation/src/server/mf-dev-server.js';
}

tree.overwrite('package.json', JSON.stringify(packageJson, null, 2));
Expand Down
5 changes: 2 additions & 3 deletions libs/mf/src/server/colors.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import crypt = require('crypto');
import chalk from 'chalk';
import wordWrap = require('word-wrap');

function correctColor(color: string): string {
Expand Down Expand Up @@ -39,7 +38,7 @@ export function print(
message = message.substring(0, message.length - 1);
}

const coloredPrefix = chalk.hex(color)(prefix) + ' | ';
const coloredPrefix = ' | ';
const lines = message.split('\n');

const lineSize = process.stdout.columns - prefixSize - 10;
Expand All @@ -49,7 +48,7 @@ export function print(
const sublines = wrapped.split('\n');
for (const subline of sublines) {
const trimmed = subline.trim();
const coloredSubline = error ? chalk.redBright(trimmed) : trimmed;
const coloredSubline = trimmed;
const output = coloredPrefix + coloredSubline;
console.log(output);
}
Expand Down
2 changes: 1 addition & 1 deletion libs/mf/src/utils/create-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export function createConfig(
root: string
): string {
return `const ModuleFederationPlugin = require("webpack/lib/container/ModuleFederationPlugin");
const mf = require("@angular-architects/module-federation/webpack");
const mf = require("@agorapulse/module-federation/webpack");
const path = require("path");
const share = mf.share;
Expand Down
56 changes: 36 additions & 20 deletions libs/mf/src/utils/modify-entry-plugin.ts
Original file line number Diff line number Diff line change
@@ -1,30 +1,46 @@
const PLUGIN_NAME = 'modify-entry-plugin';
export class ModifyEntryPlugin {
config: unknown;
constructor(config) {
this.config = config;
}

apply(compiler) {
const mergeEntry = (keyFn, key) => [
...(keyFn(this.config[key]) || []),
...(keyFn(compiler.options.entry[key]) || []),
];
const cfgOrRemove = (objFn, valueFn, key) => {
const values = mergeEntry(valueFn, key);
return values.length > 0 ? objFn(values) : {};
};
Object.keys(this.config).forEach((key) => {
compiler.options.entry[key] = {
...cfgOrRemove(
(v) => ({ import: v }),
(c) => c.import,
key
),
...cfgOrRemove(
(v) => ({ dependOn: v }),
(c) => c.dependOn,
key
),
compiler.hooks.afterEnvironment.tap(PLUGIN_NAME, () => {
const webpackOptions = compiler.options;
const entry =
typeof webpackOptions.entry === 'function'
? webpackOptions.entry()
: webpackOptions.entry;

webpackOptions.entry = async () => {
const entries = await entry;

const mergeEntry = (keyFn, key) => [
...(keyFn(this.config[key]) || []),
...(keyFn(entries[key]) || []),
];
const cfgOrRemove = (objFn, valueFn, key) => {
const values = mergeEntry(valueFn, key);
return values.length > 0 ? objFn(values) : {};
};

Object.keys(this.config).forEach((key) => {
entries[key] = {
...cfgOrRemove(
(v) => ({ import: v }),
(c) => c.import,
key
),
...cfgOrRemove(
(v) => ({ dependOn: v }),
(c) => c.dependOn,
key
),
};
});

return entries;
};
});
}
Expand Down
8 changes: 4 additions & 4 deletions libs/mf/src/utils/share-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ export const DEFAULT_SKIP_LIST = [
'@softarc/native-federation-runtime',
'@softarc/native-federation-core',
'@softarc/native-federation',
'@angular-architects/module-federation',
'@angular-architects/module-federation-runtime',
'@agorapulse/module-federation',
'@agorapulse/module-federation-runtime',
'tslib',
'zone.js',
];
Expand Down Expand Up @@ -79,8 +79,8 @@ function lookupVersion(key: string, versions: VersionMap): string {
key = parts[0];
}

if (key.toLowerCase() === '@angular-architects/module-federation-runtime') {
key = '@angular-architects/module-federation';
if (key.toLowerCase() === '@agorapulse/module-federation-runtime') {
key = '@agorapulse/module-federation';
}

if (!versions[key]) {
Expand Down
4 changes: 2 additions & 2 deletions libs/native-federation-core/src/lib/config/share-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@ function lookupVersionInMap(key: string, versions: VersionMap): string | null {
key = parts[0];
}

if (key.toLowerCase() === '@angular-architects/module-federation-runtime') {
key = '@angular-architects/module-federation';
if (key.toLowerCase() === '@agorapulse/module-federation-runtime') {
key = '@agorapulse/module-federation';
}

if (!versions[key]) {
Expand Down
4 changes: 2 additions & 2 deletions libs/native-federation-core/src/lib/core/default-skip-list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ export const DEFAULT_SKIP_LIST: SkipList = [
'@softarc/native-federation',
'@softarc/native-federation-core',
'@softarc/native-federation-esbuild',
'@angular-architects/native-federation',
'@angular-architects/native-federation-runtime',
'@agorapulse/native-federation',
'@agorapulse/native-federation-runtime',
'es-module-shims',
'zone.js',
'tslib/',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export default async function (
sourceRoot: `${normalizedOptions.projectRoot}/src`,
targets: {
build: {
executor: '@angular-architects/native-federation:build',
executor: '@agorapulse/native-federation:build',
},
},
tags: normalizedOptions.parsedTags,
Expand Down
10 changes: 5 additions & 5 deletions libs/native-federation/src/schematics/init/schematic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ function updateWorkspaceConfig(
projectConfig.architect.esbuild = originalBuild;

projectConfig.architect.build = {
builder: '@angular-architects/native-federation:build',
builder: '@agorapulse/native-federation:build',
options: {},
configurations: {
production: {
Expand Down Expand Up @@ -157,7 +157,7 @@ function updateWorkspaceConfig(
projectConfig.architect['serve-original'] = projectConfig.architect.serve;

projectConfig.architect.serve = {
builder: '@angular-architects/native-federation:build',
builder: '@agorapulse/native-federation:build',
options: {
target: `${projectName}:serve-original:development`,
rebuildDelay: 0,
Expand Down Expand Up @@ -314,7 +314,7 @@ function makeMainAsync(

let newMainContent = '';
if (options.type === 'dynamic-host') {
newMainContent = `import { initFederation } from '@angular-architects/native-federation';
newMainContent = `import { initFederation } from '@agorapulse/native-federation';
initFederation('/assets/federation.manifest.json')
.catch(err => console.error(err))
Expand All @@ -323,15 +323,15 @@ initFederation('/assets/federation.manifest.json')
`;
} else if (options.type === 'host') {
const manifest = JSON.stringify(remoteMap, null, 2).replace(/"/g, "'");
newMainContent = `import { initFederation } from '@angular-architects/native-federation';
newMainContent = `import { initFederation } from '@agorapulse/native-federation';
initFederation(${manifest})
.catch(err => console.error(err))
.then(_ => import('./bootstrap'))
.catch(err => console.error(err));
`;
} else {
newMainContent = `import { initFederation } from '@angular-architects/native-federation';
newMainContent = `import { initFederation } from '@agorapulse/native-federation';
initFederation()
.catch(err => console.error(err))
Expand Down
Loading

0 comments on commit 46be0a6

Please sign in to comment.