fix: return output if found version

This commit is contained in:
Jozef Steinhübl 2024-05-07 20:31:34 +02:00
parent 97de633240
commit ff32c47b98
No known key found for this signature in database
GPG key ID: E6BC90C91973B08F

View file

@ -35,8 +35,7 @@ export function readVersionFromFile(
if (!files) { if (!files) {
warning("No version file specified, trying all known files."); warning("No version file specified, trying all known files.");
readVersionFromFile(Object.keys(FILE_VERSION_READERS)); return readVersionFromFile(Object.keys(FILE_VERSION_READERS));
return;
} }
if (!Array.isArray(files)) files = [files]; if (!Array.isArray(files)) files = [files];
@ -54,11 +53,17 @@ export function readVersionFromFile(
const reader = FILE_VERSION_READERS[base] ?? (() => undefined); const reader = FILE_VERSION_READERS[base] ?? (() => undefined);
let output: string | undefined;
try { try {
return reader(readFileSync(path, "utf8")); output = reader(readFileSync(path, "utf8"));
} catch (error) { } catch (error) {
const { message } = error as Error; const { message } = error as Error;
warning(`Failed to read ${file}: ${message}`); warning(`Failed to read ${file}: ${message}`);
} finally {
if (output) {
debug(`Found version ${output}`);
return output;
}
} }
} }
} }