Skip to content

Commit fcd305e

Browse files
committed
fix(nf): Cache issue where metadata could not be found
1 parent ff8aa6c commit fcd305e

2 files changed

Lines changed: 6 additions & 3 deletions

File tree

libs/native-federation-core/src/lib/core/bundle-shared.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,6 @@ export async function bundleShared(
3838
? path.dirname(fedOptions.packageJson)
3939
: fedOptions.workspaceRoot;
4040

41-
fs.mkdirSync(cache.pathToCache, { recursive: true });
42-
4341
const sharedPackageInfoCache = getCachedMetadata(
4442
cache.pathToCache,
4543
cache.metaDataFile,
@@ -59,6 +57,7 @@ export async function bundleShared(
5957
}
6058

6159
purgeCacheFolder(cache.pathToCache, cache.metaDataFile);
60+
fs.mkdirSync(cache.pathToCache, { recursive: true });
6261

6362
const inferredPackageInfos = Object.keys(sharedBundles)
6463
.filter((packageName) => !sharedBundles[packageName].packageInfo)

libs/native-federation-core/src/lib/core/get-cache.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export const getCachedMetadata = (
3131
checksum: string
3232
): SharedInfo[] | false => {
3333
const metadataFile = path.join(pathToCache, file);
34-
if (!fs.existsSync(metadataFile)) return false;
34+
if (!fs.existsSync(pathToCache) || !fs.existsSync(metadataFile)) return false;
3535

3636
const cachedResult: {
3737
checksum: string;
@@ -85,10 +85,14 @@ export const copyCacheToDist = (
8585

8686
export const purgeCacheFolder = (pathToCache: string, file: string) => {
8787
const metadataFile = path.join(pathToCache, file);
88+
if (!fs.existsSync(pathToCache)) {
89+
return;
90+
}
8891
if (!fs.existsSync(metadataFile)) {
8992
logger.warn(
9093
`Could not purge cache, metadata file '${file}' could not be found.`
9194
);
95+
return;
9296
}
9397

9498
const cachedResult: {

0 commit comments

Comments
 (0)