Skip to content

Commit 07b67c0

Browse files
author
Alain Sollberger
committed
feat(nf-runtime): added cacheTag option to bust the remoteEntry file cache
- upgraded nx to the latest
1 parent 9761791 commit 07b67c0

File tree

2 files changed

+19
-8
lines changed

2 files changed

+19
-8
lines changed

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: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
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';
1111
import {
@@ -33,7 +33,10 @@ export async function initFederation(
3333
}`;
3434
const hostInfo = await loadFederationInfo(url);
3535
const hostImportMap = await processHostInfo(hostInfo);
36-
const remotesImportMap = await processRemoteInfos(remotes);
36+
const remotesImportMap = await processRemoteInfos(remotes, {
37+
throwIfRemoteNotFound: false,
38+
...options,
39+
});
3740

3841
const importMap = mergeImportMaps(hostImportMap, remotesImportMap);
3942
appendImportMap(importMap);

0 commit comments

Comments
 (0)