Skip to content

Commit 2e542b5

Browse files
committed
2 parents 3daa0a8 + 336ef2c commit 2e542b5

File tree

12 files changed

+14585
-12671
lines changed

12 files changed

+14585
-12671
lines changed

.eslintrc.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,12 @@
3838
"files": "*.json",
3939
"parser": "jsonc-eslint-parser",
4040
"rules": {}
41+
},
42+
{
43+
"files": ["*.ts"],
44+
"rules": {
45+
"@angular-eslint/prefer-standalone": "off"
46+
}
4147
}
4248
],
4349
"extends": ["./.eslintrc.base.json"]

apps/mfe1/.eslintrc.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@
2424
"prefix": "angular-architects",
2525
"style": "kebab-case"
2626
}
27-
]
27+
],
28+
"@angular-eslint/prefer-standalone": "off"
2829
}
2930
},
3031
{

apps/mfe2/.eslintrc.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@
2424
"prefix": "angular-architects",
2525
"style": "kebab-case"
2626
}
27-
]
27+
],
28+
"@angular-eslint/prefer-standalone": "off"
2829
}
2930
},
3031
{

apps/playground/.eslintrc.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@
2424
"prefix": "angular-architects",
2525
"style": "kebab-case"
2626
}
27-
]
27+
],
28+
"@angular-eslint/prefer-standalone": "off"
2829
}
2930
},
3031
{

libs/mf-runtime/.eslintrc.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@
2424
"prefix": "angular-architects",
2525
"style": "kebab-case"
2626
}
27-
]
27+
],
28+
"@angular-eslint/prefer-standalone": "off"
2829
}
2930
},
3031
{

libs/mf-tools/.eslintrc.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@
2424
"prefix": "angular-architects",
2525
"style": "kebab-case"
2626
}
27-
]
27+
],
28+
"@angular-eslint/prefer-standalone": "off"
2829
}
2930
},
3031
{

libs/native-federation-node/src/lib/node/init-node-federation.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,21 @@ import * as fs from 'node:fs/promises';
44
import * as path from 'node:path';
55

66
import {
7+
FederationInfo,
8+
ImportMap,
9+
InitFederationOptions,
10+
mergeImportMaps,
711
processHostInfo,
812
processRemoteInfos,
9-
FederationInfo,
1013
} from '@softarc/native-federation-runtime';
11-
import { ImportMap, mergeImportMaps } from '@softarc/native-federation-runtime';
1214
import { IMPORT_MAP_FILE_NAME } from '../utils/import-map-loader';
1315
import { resolver } from '../utils/loader-as-data-url';
1416

1517
export type InitNodeFederationOptions = {
1618
remotesOrManifestUrl: Record<string, string> | string;
1719
relBundlePath: string;
1820
throwIfRemoteNotFound: boolean;
21+
cacheTag?: string;
1922
};
2023

2124
const defaultOptions: InitNodeFederationOptions = {
@@ -53,6 +56,7 @@ async function createNodeImportMap(
5356
const hostImportMap = await processHostInfo(hostInfo, relBundlePath);
5457
const remotesImportMap = await processRemoteInfos(remotes, {
5558
throwIfRemoteNotFound: options.throwIfRemoteNotFound,
59+
cacheTag: options.cacheTag,
5660
});
5761

5862
const importMap = mergeImportMaps(hostImportMap, remotesImportMap);
@@ -69,9 +73,13 @@ async function loadFsManifest(
6973
}
7074

7175
async function loadFsFederationInfo(
72-
relBundlePath: string
76+
relBundlePath: string,
77+
options?: InitFederationOptions
7378
): Promise<FederationInfo> {
74-
const manifestPath = path.join(relBundlePath, 'remoteEntry.json');
79+
const manifestPath = path.join(
80+
relBundlePath,
81+
'remoteEntry.json' + options?.cacheTag ? `?t=${options.cacheTag}` : ''
82+
);
7583
const content = await fs.readFile(manifestPath, 'utf-8');
7684
const manifest = JSON.parse(content) as FederationInfo;
7785
return manifest;

libs/native-federation-runtime/src/lib/init-federation.ts

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,41 @@
11
import {
2-
Scopes,
3-
Imports,
42
ImportMap,
3+
Imports,
54
mergeImportMaps,
5+
Scopes,
66
} from './model/import-map';
77
import { getExternalUrl, setExternalUrl } from './model/externals';
8-
import { joinPaths, getDirectory } from './utils/path-utils';
8+
import { getDirectory, joinPaths } from './utils/path-utils';
99
import { addRemote } from './model/remotes';
1010
import { appendImportMap } from './utils/add-import-map';
11-
import { FederationInfo } from './model/federation-info';
12-
11+
import {
12+
FederationInfo,
13+
InitFederationOptions,
14+
ProcessRemoteInfoOptions,
15+
} from './model/federation-info';
16+
17+
/**
18+
* Initialize the federation runtime
19+
* @param remotesOrManifestUrl
20+
* @param options The cacheTag allows you to invalidate the cache of the remoteEntry.json files, pass a new value with every release (f.ex. the version number)
21+
*/
1322
export async function initFederation(
14-
remotesOrManifestUrl: Record<string, string> | string = {}
23+
remotesOrManifestUrl: Record<string, string> | string = {},
24+
options?: InitFederationOptions
1525
): Promise<ImportMap> {
26+
const cacheOption = options?.cacheTag ? `?t=${options.cacheTag}` : '';
1627
const remotes =
1728
typeof remotesOrManifestUrl === 'string'
18-
? await loadManifest(remotesOrManifestUrl)
29+
? await loadManifest(remotesOrManifestUrl + cacheOption)
1930
: remotesOrManifestUrl;
2031

21-
const hostInfo = await loadFederationInfo('./remoteEntry.json');
32+
const url = './remoteEntry.json' + cacheOption;
33+
const hostInfo = await loadFederationInfo(url);
2234
const hostImportMap = await processHostInfo(hostInfo);
23-
const remotesImportMap = await processRemoteInfos(remotes);
35+
const remotesImportMap = await processRemoteInfos(remotes, {
36+
throwIfRemoteNotFound: false,
37+
...options,
38+
});
2439

2540
const importMap = mergeImportMaps(hostImportMap, remotesImportMap);
2641
appendImportMap(importMap);
@@ -34,12 +49,17 @@ async function loadManifest(remotes: string): Promise<Record<string, string>> {
3449

3550
export async function processRemoteInfos(
3651
remotes: Record<string, string>,
37-
options: { throwIfRemoteNotFound: boolean } = { throwIfRemoteNotFound: false }
52+
options: ProcessRemoteInfoOptions = { throwIfRemoteNotFound: false }
3853
): Promise<ImportMap> {
3954
const processRemoteInfoPromises = Object.keys(remotes).map(
4055
async (remoteName) => {
4156
try {
42-
const url = remotes[remoteName];
57+
let url = remotes[remoteName];
58+
if (options.cacheTag) {
59+
const addAppend = remotes[remoteName].includes('?') ? '&' : '?';
60+
url += `${addAppend}t=${options.cacheTag}`;
61+
}
62+
4363
return await processRemoteInfo(url, remoteName);
4464
} catch (e) {
4565
const error = `Error loading remote entry for ${remoteName} from file ${remotes[remoteName]}`;

libs/native-federation-runtime/src/lib/model/federation-info.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,11 @@ export interface FederationInfo {
2323
exposes: ExposesInfo[];
2424
shared: SharedInfo[];
2525
}
26+
27+
export interface InitFederationOptions {
28+
cacheTag?: string;
29+
}
30+
31+
export interface ProcessRemoteInfoOptions extends InitFederationOptions {
32+
throwIfRemoteNotFound: boolean;
33+
}

libs/playground-lib/.eslintrc.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@
2424
"prefix": "angular-architects",
2525
"style": "kebab-case"
2626
}
27-
]
27+
],
28+
"@angular-eslint/prefer-standalone": "off"
2829
}
2930
},
3031
{

0 commit comments

Comments
 (0)