Skip to content

Commit 42c11da

Browse files
authored
build: Don't use cache for files depending on Release Registry (#15124)
1 parent 33c8c77 commit 42c11da

File tree

1 file changed

+34
-19
lines changed

1 file changed

+34
-19
lines changed

src/mdx.ts

Lines changed: 34 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -531,26 +531,41 @@ export async function getFileBySlug(slug: string): Promise<SlugFile> {
531531
const outdir = path.join(root, 'public', 'mdx-images');
532532
await mkdir(outdir, {recursive: true});
533533

534+
// If the file contains content that depends on the Release Registry (such as an SDK's latest version), avoid using the cache for that file, i.e. always rebuild it.
535+
// This is because the content from the registry might have changed since the last time the file was cached.
536+
// If a new component that injects content from the registry is introduced, it should be added to the patterns below.
537+
const skipCache =
538+
source.includes('@inject') ||
539+
source.includes('<PlatformSDKPackageName') ||
540+
source.includes('<LambdaLayerDetail');
541+
534542
if (process.env.CI) {
535-
cacheKey = md5(source);
536-
cacheFile = path.join(CACHE_DIR, `${cacheKey}.br`);
537-
assetsCacheDir = path.join(CACHE_DIR, cacheKey);
543+
if (skipCache) {
544+
// eslint-disable-next-line no-console
545+
console.info(
546+
`Not using cached version of ${sourcePath}, as its content depends on the Release Registry`
547+
);
548+
} else {
549+
cacheKey = md5(source);
550+
cacheFile = path.join(CACHE_DIR, `${cacheKey}.br`);
551+
assetsCacheDir = path.join(CACHE_DIR, cacheKey);
538552

539-
try {
540-
const [cached, _] = await Promise.all([
541-
readCacheFile<SlugFile>(cacheFile),
542-
cp(assetsCacheDir, outdir, {recursive: true}),
543-
]);
544-
return cached;
545-
} catch (err) {
546-
if (
547-
err.code !== 'ENOENT' &&
548-
err.code !== 'ABORT_ERR' &&
549-
err.code !== 'Z_BUF_ERROR'
550-
) {
551-
// If cache is corrupted, ignore and proceed
552-
// eslint-disable-next-line no-console
553-
console.warn(`Failed to read MDX cache: ${cacheFile}`, err);
553+
try {
554+
const [cached, _] = await Promise.all([
555+
readCacheFile<SlugFile>(cacheFile),
556+
cp(assetsCacheDir, outdir, {recursive: true}),
557+
]);
558+
return cached;
559+
} catch (err) {
560+
if (
561+
err.code !== 'ENOENT' &&
562+
err.code !== 'ABORT_ERR' &&
563+
err.code !== 'Z_BUF_ERROR'
564+
) {
565+
// If cache is corrupted, ignore and proceed
566+
// eslint-disable-next-line no-console
567+
console.warn(`Failed to read MDX cache: ${cacheFile}`, err);
568+
}
554569
}
555570
}
556571
}
@@ -685,7 +700,7 @@ export async function getFileBySlug(slug: string): Promise<SlugFile> {
685700
},
686701
};
687702

688-
if (assetsCacheDir && cacheFile) {
703+
if (assetsCacheDir && cacheFile && !skipCache) {
689704
await cp(assetsCacheDir, outdir, {recursive: true});
690705
writeCacheFile(cacheFile, JSON.stringify(resultObj)).catch(e => {
691706
// eslint-disable-next-line no-console

0 commit comments

Comments
 (0)