@@ -8,17 +8,30 @@ import { getExternalUrl, setExternalUrl } from './model/externals';
8
8
import { joinPaths , getDirectory } from './utils/path-utils' ;
9
9
import { addRemote } from './model/remotes' ;
10
10
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
+ */
13
22
export async function initFederation (
14
- remotesOrManifestUrl : Record < string , string > | string = { }
23
+ remotesOrManifestUrl : Record < string , string > | string = { } ,
24
+ options ?: InitFederationOptions
15
25
) : Promise < ImportMap > {
16
26
const remotes =
17
27
typeof remotesOrManifestUrl === 'string'
18
28
? await loadManifest ( remotesOrManifestUrl )
19
29
: remotesOrManifestUrl ;
20
30
21
- const hostInfo = await loadFederationInfo ( './remoteEntry.json' ) ;
31
+ const url = `./remoteEntry.json${
32
+ options ?. cacheTag ? `?t=${ options . cacheTag } ` : ''
33
+ } `;
34
+ const hostInfo = await loadFederationInfo ( url ) ;
22
35
const hostImportMap = await processHostInfo ( hostInfo ) ;
23
36
const remotesImportMap = await processRemoteInfos ( remotes ) ;
24
37
@@ -34,12 +47,17 @@ async function loadManifest(remotes: string): Promise<Record<string, string>> {
34
47
35
48
export async function processRemoteInfos (
36
49
remotes : Record < string , string > ,
37
- options : { throwIfRemoteNotFound : boolean } = { throwIfRemoteNotFound : false }
50
+ options : ProcessRemoteInfoOptions = { throwIfRemoteNotFound : false }
38
51
) : Promise < ImportMap > {
39
52
const processRemoteInfoPromises = Object . keys ( remotes ) . map (
40
53
async ( remoteName ) => {
41
54
try {
42
- const url = remotes [ remoteName ] ;
55
+ let url = remotes [ remoteName ] ;
56
+ if ( options . cacheTag ) {
57
+ const addAppend = remotes [ remoteName ] . includes ( '?' ) ? '&' : '?' ;
58
+ url += `${ addAppend } t=${ options . cacheTag } ` ;
59
+ }
60
+
43
61
return await processRemoteInfo ( url , remoteName ) ;
44
62
} catch ( e ) {
45
63
const error = `Error loading remote entry for ${ remoteName } from file ${ remotes [ remoteName ] } ` ;
0 commit comments