Skip to content

Commit

Permalink
fix(detect): don't choke if devDependencies not defined
Browse files Browse the repository at this point in the history
Fixes #8
  • Loading branch information
balazsorban44 committed Jul 3, 2024
1 parent 6e7b4ca commit 9ab6c64
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions lib/detect.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ export async function detectFramework(path = "") {
/** @type {import("./meta").SupportedFramework[]} */
const foundFrameworks = []

if (packageJson.dependencies["next"]) foundFrameworks.push("next")
if (packageJson.dependencies["express"]) foundFrameworks.push("express")
if (packageJson.devDependencies["@sveltejs/kit"])
if (packageJson?.dependencies?.["next"]) foundFrameworks.push("next")
if (packageJson?.dependencies?.["express"]) foundFrameworks.push("express")
if (packageJson?.devDependencies?.["@sveltejs/kit"])
foundFrameworks.push("sveltekit")

if (foundFrameworks.length === 1) return foundFrameworks[0]
Expand All @@ -33,7 +33,8 @@ export async function detectFramework(path = "") {
return "unknown"
}
return "unknown"
} catch {
} catch (error) {
console.error(error)
return "unknown"
}
}
Expand All @@ -43,14 +44,15 @@ export async function requireFramework(path = "") {

if (framework === "unknown") {
console.error(
y.red(`No framework detected. Currently supported frameworks are: ${y.bold(
Object.keys(frameworks).join(", ")
)}`)
y.red(
`No framework detected. Currently supported frameworks are: ${y.bold(
Object.keys(frameworks).join(", ")
)}`
)
)

process.exit(0)
}

return framework
}

0 comments on commit 9ab6c64

Please sign in to comment.