@@ -74,10 +74,10 @@ export function createCacheAssets(options: buildHelper.BuildOptions) {
74
74
const htmlPages = buildHelper . getHtmlPages ( dotNextPath ) ;
75
75
buildHelper . removeFiles (
76
76
outputPath ,
77
- ( file ) =>
78
- file . endsWith ( ".js" ) ||
79
- file . endsWith ( ".js.nft.json" ) ||
80
- ( file . endsWith ( ".html" ) && htmlPages . has ( file ) ) ,
77
+ ( { relativePath } ) =>
78
+ relativePath . endsWith ( ".js" ) ||
79
+ relativePath . endsWith ( ".js.nft.json" ) ||
80
+ ( relativePath . endsWith ( ".html" ) && htmlPages . has ( relativePath ) ) ,
81
81
) ;
82
82
83
83
// Merge cache files into a single file
@@ -95,21 +95,21 @@ export function createCacheAssets(options: buildHelper.BuildOptions) {
95
95
buildHelper . traverseFiles (
96
96
outputPath ,
97
97
( ) => true ,
98
- ( filepath ) => {
99
- const ext = path . extname ( filepath ) ;
98
+ ( { absolutePath } ) => {
99
+ const ext = path . extname ( absolutePath ) ;
100
100
switch ( ext ) {
101
101
case ".meta" :
102
102
case ".html" :
103
103
case ".json" :
104
104
case ".body" :
105
105
case ".rsc" :
106
- const newFilePath =
107
- filepath
108
- . substring ( 0 , filepath . length - ext . length )
109
- . replace ( / \. p r e f e t c h $ / , "" ) + " .cache";
106
+ const newFilePath = absolutePath
107
+ . substring ( 0 , absolutePath . length - ext . length )
108
+ . replace ( / \. p r e f e t c h $ / , "" )
109
+ . concat ( " .cache") ;
110
110
111
111
cacheFilesPath [ newFilePath ] = {
112
- [ ext . slice ( 1 ) ] : filepath ,
112
+ [ ext . slice ( 1 ) ] : absolutePath ,
113
113
...cacheFilesPath [ newFilePath ] ,
114
114
} ;
115
115
break ;
@@ -161,9 +161,9 @@ export function createCacheAssets(options: buildHelper.BuildOptions) {
161
161
// Traverse files inside cache to find all meta files and cache tags associated with them
162
162
buildHelper . traverseFiles (
163
163
outputPath ,
164
- ( file ) => file . endsWith ( ".meta" ) ,
165
- ( filePath ) => {
166
- const fileContent = fs . readFileSync ( filePath , "utf8" ) ;
164
+ ( { absolutePath } ) => absolutePath . endsWith ( ".meta" ) ,
165
+ ( { absolutePath , relativePath } ) => {
166
+ const fileContent = fs . readFileSync ( absolutePath , "utf8" ) ;
167
167
const fileData = JSON . parse ( fileContent ) ;
168
168
if ( fileData . headers ?. [ "x-next-cache-tags" ] ) {
169
169
fileData . headers [ "x-next-cache-tags" ]
@@ -175,7 +175,7 @@ export function createCacheAssets(options: buildHelper.BuildOptions) {
175
175
path : {
176
176
S : path . posix . join (
177
177
buildId ,
178
- path . relative ( outputPath , filePath ) . replace ( ".meta" , "" ) ,
178
+ relativePath . replace ( ".meta" , "" ) ,
179
179
) ,
180
180
} ,
181
181
// We don't care about the revalidation time here, we just need to make sure it's there
@@ -199,17 +199,14 @@ export function createCacheAssets(options: buildHelper.BuildOptions) {
199
199
buildHelper . traverseFiles (
200
200
fetchCachePath ,
201
201
( ) => true ,
202
- ( filepath ) => {
203
- const fileContent = fs . readFileSync ( filepath , "utf8" ) ;
202
+ ( { absolutePath , relativePath } ) => {
203
+ const fileContent = fs . readFileSync ( absolutePath , "utf8" ) ;
204
204
const fileData = JSON . parse ( fileContent ) ;
205
205
fileData ?. tags ?. forEach ( ( tag : string ) => {
206
206
metaFiles . push ( {
207
207
tag : { S : path . posix . join ( buildId , tag ) } ,
208
208
path : {
209
- S : path . posix . join (
210
- buildId ,
211
- path . relative ( fetchCachePath , filepath ) ,
212
- ) ,
209
+ S : path . posix . join ( buildId , relativePath ) ,
213
210
} ,
214
211
revalidatedAt : { N : "1" } ,
215
212
} ) ;
@@ -235,7 +232,10 @@ export function createCacheAssets(options: buildHelper.BuildOptions) {
235
232
}
236
233
237
234
// We need to remove files later because we need the metafiles for dynamodb tags cache
238
- buildHelper . removeFiles ( outputPath , ( file ) => ! file . endsWith ( ".cache" ) ) ;
235
+ buildHelper . removeFiles (
236
+ outputPath ,
237
+ ( { relativePath } ) => ! relativePath . endsWith ( ".cache" ) ,
238
+ ) ;
239
239
240
240
return { useTagCache } ;
241
241
}
0 commit comments