fix regexp, add comments

This commit is contained in:
Yoshiya Hinosawa 2024-07-05 15:27:43 +09:00
parent 709440311d
commit 2b693fd8bf
No known key found for this signature in database
GPG Key ID: 9017DB4559488785

View File

@ -57,9 +57,16 @@ function getDenoVersionFromFile(versionFilePath) {
const contents = fs.readFileSync(versionFilePath, "utf8");
const found = contents.match(/^(?:deno?\s+)?v?(?<version>[^\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?(?<version>[^\s]+)$/m);
return (found && found.groups && found.groups.version) || contents.trim();
return denoVersionInToolVersions?.groups?.version || contents.trim();
}
/**