Skip to content

Commit 50efd4d

Browse files
committed
disable mdx caching outside of CI
1 parent 08b3d8b commit 50efd4d

File tree

1 file changed

+21
-14
lines changed

1 file changed

+21
-14
lines changed

src/mdx.ts

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -523,17 +523,22 @@ export async function getFileBySlug(slug: string): Promise<SlugFile> {
523523
);
524524
}
525525

526-
const cacheKey = md5(source);
527-
const cacheFile = path.join(CACHE_DIR, cacheKey);
526+
let cacheKey: string | null = null;
527+
let cacheFile: string | null = null;
528528

529-
try {
530-
const cached = await readCacheFile<SlugFile>(cacheFile);
531-
return cached;
532-
} catch (err) {
533-
if (err.code !== 'ENOENT' && err.code !== 'ABORT_ERR') {
534-
// If cache is corrupted, ignore and proceed
535-
// eslint-disable-next-line no-console
536-
console.warn(`Failed to read MDX cache: ${cacheFile}`, err);
529+
if (process.env.CI === '1') {
530+
cacheKey = md5(source);
531+
cacheFile = path.join(CACHE_DIR, cacheKey);
532+
533+
try {
534+
const cached = await readCacheFile<SlugFile>(cacheFile);
535+
return cached;
536+
} catch (err) {
537+
if (err.code !== 'ENOENT' && err.code !== 'ABORT_ERR') {
538+
// If cache is corrupted, ignore and proceed
539+
// eslint-disable-next-line no-console
540+
console.warn(`Failed to read MDX cache: ${cacheFile}`, err);
541+
}
537542
}
538543
}
539544

@@ -662,10 +667,12 @@ export async function getFileBySlug(slug: string): Promise<SlugFile> {
662667
},
663668
};
664669

665-
writeCacheFile(cacheFile, JSON.stringify(resultObj)).catch(e => {
666-
// eslint-disable-next-line no-console
667-
console.warn(`Failed to write MDX cache: ${cacheFile}`, e);
668-
});
670+
if (cacheFile) {
671+
writeCacheFile(cacheFile, JSON.stringify(resultObj)).catch(e => {
672+
// eslint-disable-next-line no-console
673+
console.warn(`Failed to write MDX cache: ${cacheFile}`, e);
674+
});
675+
}
669676

670677
return resultObj;
671678
}

0 commit comments

Comments
 (0)