From a7ab4a97060c6c45dc8504a69947ff9081fe2ccb Mon Sep 17 00:00:00 2001 From: dumbmoron Date: Sat, 3 Aug 2024 16:28:43 +0000 Subject: [PATCH] version-info: don't throw on import if git does not exist --- packages/version-info/index.js | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/packages/version-info/index.js b/packages/version-info/index.js index 0df3b855..3ac1bd3e 100644 --- a/packages/version-info/index.js +++ b/packages/version-info/index.js @@ -17,13 +17,14 @@ const findFile = (file) => { const root = findFile('.git'); const pack = findFile('package.json'); -if (!root) { - throw 'no git repository root found'; -} else if (!pack) { - throw 'no package root found'; -} -const readGit = (filename) => readFile(join(root, filename), 'utf8'); +const readGit = (filename) => { + if (!root) { + throw 'no git repository root found'; + } + + return readFile(join(root, filename), 'utf8'); +} export const getCommit = async () => { return (await readGit('.git/logs/HEAD')) @@ -65,6 +66,10 @@ export const getRemote = async () => { } export const getVersion = async () => { + if (!pack) { + throw 'no package root found'; + } + const { version } = JSON.parse( await readFile(join(pack, 'package.json'), 'utf8') );