Skip to content

Commit

Permalink
More permissively parse version
Browse files Browse the repository at this point in the history
  • Loading branch information
jakebailey committed Apr 12, 2024
1 parent 5859d5b commit f6c9e3a
Show file tree
Hide file tree
Showing 4 changed files with 440 additions and 11 deletions.
30 changes: 25 additions & 5 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9932,15 +9932,35 @@ function formatSemVerOrString(v) {
}
return v.format();
}
function parsePyrightVersionFromStdout(stdout) {
const prefix = "pyright ";
for (let line of stdout.trim().split(/\r?\n/)) {
line = line.trimEnd();
if (line.startsWith(prefix)) {
try {
return new import_semver2.SemVer(line.slice(prefix.length));
} catch {
}
}
}
throw new Error(`Failed to parse pyright version from ${JSON.stringify(stdout)}`);
}
async function getPyrightInfo() {
const version3 = await getPyrightVersion();
if (version3 === "PATH") {
const command = import_which.default.sync("pyright");
const versionOut = cp.execFileSync(command, ["--version"], { encoding: "utf8" });
const versionRaw = versionOut.trim().split(/\s+/).at(-1);
if (!versionRaw)
throw new Error(`Failed to parse pyright version from ${JSON.stringify(versionOut)}`);
const version4 = new import_semver2.SemVer(versionRaw);
let version4;
for (let i = 0; i < 2; i++) {
try {
const versionOut = cp.execFileSync(command, ["--version"], { encoding: "utf8" });
version4 = parsePyrightVersionFromStdout(versionOut);
break;
} catch (e) {
if (i === 1) {
throw e;
}
}
}
return {
kind: "path",
version: version4,
Expand Down

0 comments on commit f6c9e3a

Please sign in to comment.