Skip to content

Commit

Permalink
fix: webFS#fileExists needs to await file check
Browse files Browse the repository at this point in the history
  • Loading branch information
Skn0tt committed Sep 1, 2023
1 parent 9726ed2 commit 5d34ed2
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 13 deletions.
4 changes: 2 additions & 2 deletions packages/build-info/src/browser/file-system.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export class GithubProvider {
if (response.headers?.get('Content-Type')?.match(/json/)) {
const json = await response.json()
if (!response.ok) {
Promise.reject(json)
throw new Error(JSON.stringify(json))
}
return json
}
Expand Down Expand Up @@ -55,7 +55,7 @@ export class WebFS extends FileSystem {

async fileExists(path: string): Promise<boolean> {
try {
this.readFile(path)
await this.readFile(path)
return true
} catch {
return false
Expand Down
17 changes: 6 additions & 11 deletions packages/build-info/tests/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,16 +68,11 @@ export const createWebFixture = async (fixture: string) => {
const info = await stat(src)
if (info.isDirectory()) {
const entries = await readdir(src, { withFileTypes: true })
return new Response(
JSON.stringify(
entries.map((entry) => ({
path: entry.name,
type: entry.isDirectory() ? 'dir' : 'file',
})),
),
{
headers: { 'Content-Type': 'application/json' },
},
return Response.json(
entries.map((entry) => ({
path: entry.name,
type: entry.isDirectory() ? 'dir' : 'file',
})),
)
} else {
const file = await readFile(src, 'utf-8')
Expand All @@ -87,7 +82,7 @@ export const createWebFixture = async (fixture: string) => {
// noop
}

throw new Error(`404 ${url} not found!`)
return Response.json({ error: 'not found' }, { status: 404 })
})

return { cwd: '/' }
Expand Down

0 comments on commit 5d34ed2

Please sign in to comment.