@@ -14,7 +14,6 @@ import { type HandlerFn, isHandlerByMethod } from "../../handlers.ts";
1414import { HttpError } from "../../error.ts" ;
1515import { parseRootPath } from "../../config.ts" ;
1616import type { FreshReqContext , PageProps } from "../../context.ts" ;
17- import { isDirectory } from "../../fs.ts" ;
1817
1918const TEST_FILE_PATTERN = / [ . _ ] t e s t \. (?: [ t j ] s x ? | [ m c ] [ t j ] s ) $ / ;
2019const GROUP_REG = / ( ^ | [ / \\ \\ ] ) \( ( _ [ ^ / \\ \\ ] + ) \) [ / \\ \\ ] / ;
@@ -77,19 +76,26 @@ export async function fsRoutes<State>(
7776 const islandDir = path . join ( dir , "islands" ) ;
7877 const routesDir = path . join ( dir , "routes" ) ;
7978
80- const islandPaths = await isDirectory ( islandDir )
81- ? await Array . fromAsync (
82- internals . walk ( islandDir , {
79+ const islandPaths : string [ ] = [ ] ;
80+ const relRoutePaths : string [ ] = [ ] ;
81+
82+ try {
83+ for await (
84+ const entry of walk ( islandDir , {
8385 includeDirs : false ,
8486 exts : [ "tsx" , "jsx" , "ts" , "js" ] ,
8587 skip,
86- } ) ,
87- ( entry ) => entry . path ,
88- )
89- : [ ] ;
88+ } )
89+ ) {
90+ islandPaths . push ( entry . path ) ;
91+ }
92+ } catch ( error ) {
93+ if ( ! ( error instanceof Deno . errors . NotFound ) ) {
94+ throw error ;
95+ }
96+ }
9097
91- const relRoutePaths : string [ ] = [ ] ;
92- if ( await isDirectory ( routesDir ) ) {
98+ try {
9399 for await (
94100 const entry of internals . walk ( routesDir , {
95101 includeDirs : false ,
@@ -113,6 +119,11 @@ export async function fsRoutes<State>(
113119 const url = new URL ( relative , "http://localhost/" ) ;
114120 relRoutePaths . push ( url . pathname . slice ( 1 ) ) ;
115121 }
122+ } catch ( error ) {
123+ // `islandDir` or `routesDir` does not exist, so we can skip it
124+ if ( ! ( error instanceof Deno . errors . NotFound ) ) {
125+ throw error ;
126+ }
116127 }
117128
118129 await Promise . all ( islandPaths . map ( async ( islandPath ) => {
0 commit comments