Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/light-pumas-call.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@opennextjs/aws": patch
---

fix(dev-overrides): Make fs-dev tagCache override work with BUILD_ID
28 changes: 18 additions & 10 deletions packages/open-next/src/overrides/tagCache/fs-dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,41 +16,49 @@ let tags = JSON.parse(tagContent) as {
revalidatedAt: { N: string };
}[];

const { NEXT_BUILD_ID } = process.env;

function buildKey(key: string) {
return path.posix.join(NEXT_BUILD_ID ?? "", key);
}

const tagCache: TagCache = {
name: "fs-dev",
mode: "original",
getByPath: async (path: string) => {
return tags
.filter((tagPathMapping) => tagPathMapping.path.S === path)
.map((tag) => tag.tag.S);
.filter((tagPathMapping) => tagPathMapping.path.S === buildKey(path))
.map((tag) => tag.tag.S.replace(`${NEXT_BUILD_ID}/`, ""));
},
getByTag: async (tag: string) => {
return tags
.filter((tagPathMapping) => tagPathMapping.tag.S === tag)
.map((tag) => tag.path.S);
.filter((tagPathMapping) => tagPathMapping.tag.S === buildKey(tag))
.map((tagEntry) => tagEntry.path.S.replace(`${NEXT_BUILD_ID}/`, ""));
},
getLastModified: async (path: string, lastModified?: number) => {
const revalidatedTags = tags.filter(
(tagPathMapping) =>
tagPathMapping.path.S === path &&
tagPathMapping.path.S === buildKey(path) &&
Number.parseInt(tagPathMapping.revalidatedAt.N) > (lastModified ?? 0),
);
return revalidatedTags.length > 0 ? -1 : (lastModified ?? Date.now());
},
writeTags: async (newTags) => {
const newTagsSet = new Set(
newTags.map(({ tag, path }) => `${tag}-${path}`),
newTags.map(({ tag, path }) => `${buildKey(tag)}-${buildKey(path)}`),
);
const unchangedTags = tags.filter(
({ tag, path }) => !newTagsSet.has(`${tag.S}-${path.S}`),
);
tags = unchangedTags.concat(
newTags.map((tag) => ({
tag: { S: tag.tag },
path: { S: tag.path },
revalidatedAt: { N: String(tag.revalidatedAt ?? 1) },
newTags.map((item) => ({
tag: { S: buildKey(item.tag) },
path: { S: buildKey(item.path) },
revalidatedAt: { N: `${item.revalidatedAt ?? Date.now()}` },
})),
);
// Should we write to the file here?
// fs.writeFileSync(tagFile, JSON.stringify(tags));
},
};

Expand Down
Loading