From 3900c4d7df739dbeb398e3b2de4322206758a151 Mon Sep 17 00:00:00 2001 From: Enzo Innocenzi Date: Fri, 8 Nov 2024 17:26:20 +0100 Subject: [PATCH] fix: do not throw when there is no `package.json` --- src/context.ts | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/context.ts b/src/context.ts index e1c458d..5ada1fc 100644 --- a/src/context.ts +++ b/src/context.ts @@ -90,10 +90,15 @@ export async function loadHybridlyContext(extension: ExtensionContext): Promise< return false } - const pkg = JSON.parse(fs.readFileSync(path.resolve(extension.cwd, 'package.json'), { encoding: 'utf-8' })) - const deps = { ...pkg.dependencies, ...pkg.devDependencies } - if (!deps.hybridly) { - log.appendLine('Hybridly was not found in `package.json`.') + try { + const pkg = JSON.parse(fs.readFileSync(path.resolve(extension.cwd, 'package.json'), { encoding: 'utf-8' })) + const deps = { ...pkg.dependencies, ...pkg.devDependencies } + if (!deps.hybridly) { + log.appendLine('Hybridly was not found in `package.json`.') + return false + } + } catch (error) { + log.appendLine('Could not find `package.json`.') return false }