From 2b693fd8bf5a132bfe4a96afd1cac624b0dc822d Mon Sep 17 00:00:00 2001 From: Yoshiya Hinosawa Date: Fri, 5 Jul 2024 15:27:43 +0900 Subject: [PATCH] fix regexp, add comments --- src/version.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/version.js b/src/version.js index 460788e..763b560 100644 --- a/src/version.js +++ b/src/version.js @@ -57,9 +57,16 @@ function getDenoVersionFromFile(versionFilePath) { const contents = fs.readFileSync(versionFilePath, "utf8"); - const found = contents.match(/^(?:deno?\s+)?v?(?[^\s]+)$/m); + // .tool-versions typically looks like + // ``` + // ruby 2.6.5 + // deno 1.43.1 + // node 20.0.0 + // ``` + // This parses the version of Deno from the file + const denoVersionInToolVersions = contents.match(/^deno\s+v?(?[^\s]+)$/m); - return (found && found.groups && found.groups.version) || contents.trim(); + return denoVersionInToolVersions?.groups?.version || contents.trim(); } /**