Skip to content

Commit

Permalink
fix: fix call site detection in Router.write (#58)
Browse files Browse the repository at this point in the history
  • Loading branch information
yuhr authored Jan 28, 2025
1 parent d6ab13f commit 4fa78a9
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/Router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ const isFileUrl = (url: string | URL) => {
else return url.startsWith("file://")
}

const toUrl = (path: string | URL, callSite: CallSite) => {
const toUrl = (path: string | URL, callSite: CallSite): URL => {
if (path instanceof URL) return path
try {
return new URL(path)
} catch (error) {
if (isAbsolute(path)) return toFileUrl(path)
else return new URL(path, toFileUrl(callSite.getFileName()!))
else return new URL(path, toUrl(callSite.getFileName()!, callSite))
}
}

Expand Down Expand Up @@ -252,8 +252,8 @@ class Router {
): Promise<Router.Routes> {
const optionsNormalized = normalizeOptions(options, getCallSite())
const { root, write } = optionsNormalized
if (!write) throw new Error("`write` option is invalid.")
const routes = await Router.enumerate(options)
if (!write) throw new Error("`write` option cannot be falsy here.")
const routes = await enumerate(optionsNormalized)
await emit(root.pathname, routes, write)
return routes
}
Expand Down

0 comments on commit 4fa78a9

Please sign in to comment.