Skip to content

Commit

Permalink
fix: handle errors during searchFor* functions
Browse files Browse the repository at this point in the history
  • Loading branch information
sapphi-red committed Sep 17, 2023
1 parent 1c03172 commit 673497f
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions packages/vite/src/node/server/searchRoot.ts
Expand Up @@ -27,17 +27,31 @@ function hasWorkspacePackageJSON(root: string): boolean {
if (!isFileReadable(path)) {
return false
}
const content = JSON.parse(fs.readFileSync(path, 'utf-8')) || {}
return !!content.workspaces
try {
const content = JSON.parse(fs.readFileSync(path, 'utf-8')) || {}
return !!content.workspaces
} catch {
return false
}
}

function hasRootFile(root: string): boolean {
return ROOT_FILES.some((file) => fs.existsSync(join(root, file)))
return ROOT_FILES.some((file) => {
try {
return fs.existsSync(join(root, file))
} catch {
return false
}
})
}

function hasPackageJSON(root: string) {
const path = join(root, 'package.json')
return fs.existsSync(path)
try {
return fs.existsSync(path)
} catch {
return false
}
}

/**
Expand Down

0 comments on commit 673497f

Please sign in to comment.