Skip to content

Commit

Permalink
fix regexp, add comments
Browse files Browse the repository at this point in the history
  • Loading branch information
kt3k committed Jul 5, 2024
1 parent 7094403 commit 2b693fd
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/version.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,16 @@ function getDenoVersionFromFile(versionFilePath) {

const contents = fs.readFileSync(versionFilePath, "utf8");

const found = contents.match(/^(?:deno?\s+)?v?(?<version>[^\s]+)$/m);

return (found && found.groups && found.groups.version) || contents.trim();
// .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 denoVersionInToolVersions?.groups?.version || contents.trim();
}

/**
Expand Down

0 comments on commit 2b693fd

Please sign in to comment.