@@ -16,39 +16,45 @@ let tags = JSON.parse(tagContent) as {
16
16
revalidatedAt : { N : string } ;
17
17
} [ ] ;
18
18
19
+ const { NEXT_BUILD_ID } = process . env ;
20
+
21
+ function buildKey ( key : string ) {
22
+ return path . posix . join ( NEXT_BUILD_ID ?? "" , key ) ;
23
+ }
24
+
19
25
const tagCache : TagCache = {
20
26
name : "fs-dev" ,
21
27
mode : "original" ,
22
28
getByPath : async ( path : string ) => {
23
29
return tags
24
- . filter ( ( tagPathMapping ) => tagPathMapping . path . S === path )
25
- . map ( ( tag ) => tag . tag . S ) ;
30
+ . filter ( ( tagPathMapping ) => tagPathMapping . path . S === buildKey ( path ) )
31
+ . map ( ( tag ) => tag . tag . S . replace ( ` ${ NEXT_BUILD_ID } /` , "" ) ) ;
26
32
} ,
27
33
getByTag : async ( tag : string ) => {
28
34
return tags
29
- . filter ( ( tagPathMapping ) => tagPathMapping . tag . S === tag )
30
- . map ( ( tag ) => tag . path . S ) ;
35
+ . filter ( ( tagPathMapping ) => tagPathMapping . tag . S === buildKey ( tag ) )
36
+ . map ( ( tagEntry ) => tagEntry . path . S . replace ( ` ${ NEXT_BUILD_ID } /` , "" ) ) ;
31
37
} ,
32
38
getLastModified : async ( path : string , lastModified ?: number ) => {
33
39
const revalidatedTags = tags . filter (
34
40
( tagPathMapping ) =>
35
- tagPathMapping . path . S === path &&
41
+ tagPathMapping . path . S === buildKey ( path ) &&
36
42
Number . parseInt ( tagPathMapping . revalidatedAt . N ) > ( lastModified ?? 0 ) ,
37
43
) ;
38
44
return revalidatedTags . length > 0 ? - 1 : ( lastModified ?? Date . now ( ) ) ;
39
45
} ,
40
46
writeTags : async ( newTags ) => {
41
47
const newTagsSet = new Set (
42
- newTags . map ( ( { tag, path } ) => `${ tag } -${ path } ` ) ,
48
+ newTags . map ( ( { tag, path } ) => `${ buildKey ( tag ) } -${ buildKey ( path ) } ` ) ,
43
49
) ;
44
50
const unchangedTags = tags . filter (
45
51
( { tag, path } ) => ! newTagsSet . has ( `${ tag . S } -${ path . S } ` ) ,
46
52
) ;
47
53
tags = unchangedTags . concat (
48
- newTags . map ( ( tag ) => ( {
49
- tag : { S : tag . tag } ,
50
- path : { S : tag . path } ,
51
- revalidatedAt : { N : String ( tag . revalidatedAt ?? 1 ) } ,
54
+ newTags . map ( ( item ) => ( {
55
+ tag : { S : buildKey ( item . tag ) } ,
56
+ path : { S : buildKey ( item . path ) } ,
57
+ revalidatedAt : { N : ` ${ item . revalidatedAt ?? Date . now ( ) } ` } ,
52
58
} ) ) ,
53
59
) ;
54
60
} ,
0 commit comments