@@ -18,6 +18,7 @@ import {
1818 playgroundAppCache ,
1919 problemAppCache ,
2020 solutionAppCache ,
21+ directoryEmptyCache ,
2122} from './cache.server.js'
2223import { compileMdx } from './compile-mdx.server.js'
2324import { getAppConfig , getStackBlitzUrl } from './config.server.js'
@@ -222,19 +223,24 @@ function exists(file: string) {
222223}
223224
224225async function isDirectoryEmpty ( dirPath : string ) : Promise < boolean > {
225- try {
226- const files = await fs . promises . readdir ( dirPath )
227- if ( files . length === 0 ) return true
228-
229- // Check if all files are gitignored
230- const isIgnored = await isGitIgnored ( { cwd : dirPath } )
231- const nonIgnoredFiles = files . filter ( ( file ) => ! isIgnored ( file ) )
232-
233- return nonIgnoredFiles . length === 0
234- } catch {
235- // If we can't read the directory, consider it empty
236- return true
237- }
226+ return cachified ( {
227+ key : dirPath ,
228+ cache : directoryEmptyCache ,
229+ ttl : 1000 * 60 * 5 ,
230+ swr : 1000 * 60 * 20 ,
231+ forceFresh : getForceFreshForDir ( directoryEmptyCache . get ( dirPath ) , dirPath ) ,
232+ getFreshValue : async ( ) => {
233+ try {
234+ const files = await fs . promises . readdir ( dirPath )
235+ if ( files . length === 0 ) return true
236+ const isIgnored = await isGitIgnored ( { cwd : dirPath } )
237+ const nonIgnoredFiles = files . filter ( ( file ) => ! isIgnored ( file ) )
238+ return nonIgnoredFiles . length === 0
239+ } catch {
240+ return true
241+ }
242+ } ,
243+ } )
238244}
239245
240246async function firstToExist ( ...files : Array < string > ) {
0 commit comments