@@ -74,10 +74,10 @@ export function createCacheAssets(options: buildHelper.BuildOptions) {
7474 const htmlPages = buildHelper . getHtmlPages ( dotNextPath ) ;
7575 buildHelper . removeFiles (
7676 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 ) ) ,
8181 ) ;
8282
8383 // Merge cache files into a single file
@@ -95,21 +95,21 @@ export function createCacheAssets(options: buildHelper.BuildOptions) {
9595 buildHelper . traverseFiles (
9696 outputPath ,
9797 ( ) => true ,
98- ( filepath ) => {
99- const ext = path . extname ( filepath ) ;
98+ ( { absolutePath } ) => {
99+ const ext = path . extname ( absolutePath ) ;
100100 switch ( ext ) {
101101 case ".meta" :
102102 case ".html" :
103103 case ".json" :
104104 case ".body" :
105105 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") ;
110110
111111 cacheFilesPath [ newFilePath ] = {
112- [ ext . slice ( 1 ) ] : filepath ,
112+ [ ext . slice ( 1 ) ] : absolutePath ,
113113 ...cacheFilesPath [ newFilePath ] ,
114114 } ;
115115 break ;
@@ -161,9 +161,9 @@ export function createCacheAssets(options: buildHelper.BuildOptions) {
161161 // Traverse files inside cache to find all meta files and cache tags associated with them
162162 buildHelper . traverseFiles (
163163 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" ) ;
167167 const fileData = JSON . parse ( fileContent ) ;
168168 if ( fileData . headers ?. [ "x-next-cache-tags" ] ) {
169169 fileData . headers [ "x-next-cache-tags" ]
@@ -175,7 +175,7 @@ export function createCacheAssets(options: buildHelper.BuildOptions) {
175175 path : {
176176 S : path . posix . join (
177177 buildId ,
178- path . relative ( outputPath , filePath ) . replace ( ".meta" , "" ) ,
178+ relativePath . replace ( ".meta" , "" ) ,
179179 ) ,
180180 } ,
181181 // 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) {
199199 buildHelper . traverseFiles (
200200 fetchCachePath ,
201201 ( ) => true ,
202- ( filepath ) => {
203- const fileContent = fs . readFileSync ( filepath , "utf8" ) ;
202+ ( { absolutePath , relativePath } ) => {
203+ const fileContent = fs . readFileSync ( absolutePath , "utf8" ) ;
204204 const fileData = JSON . parse ( fileContent ) ;
205205 fileData ?. tags ?. forEach ( ( tag : string ) => {
206206 metaFiles . push ( {
207207 tag : { S : path . posix . join ( buildId , tag ) } ,
208208 path : {
209- S : path . posix . join (
210- buildId ,
211- path . relative ( fetchCachePath , filepath ) ,
212- ) ,
209+ S : path . posix . join ( buildId , relativePath ) ,
213210 } ,
214211 revalidatedAt : { N : "1" } ,
215212 } ) ;
@@ -235,7 +232,10 @@ export function createCacheAssets(options: buildHelper.BuildOptions) {
235232 }
236233
237234 // 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+ ) ;
239239
240240 return { useTagCache } ;
241241}
0 commit comments