Skip to content

Commit

Permalink
Switch around SemVer
Browse files Browse the repository at this point in the history
  • Loading branch information
jakebailey committed May 5, 2022
1 parent c60f537 commit 51418c7
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 48 deletions.
6 changes: 3 additions & 3 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6438,16 +6438,16 @@ function getBooleanInput(name, defaultValue) {
async function getPyrightVersion() {
const versionSpec = core.getInput("version");
if (versionSpec) {
return new import_semver2.default(versionSpec);
return new import_semver2.default(versionSpec).format();
}
const client = new httpClient.HttpClient();
const resp = await client.get("https://registry.npmjs.org/pyright/latest");
const body = await resp.readBody();
const obj = NpmRegistryResponse.parse(JSON.parse(body));
return new import_semver2.default(obj.version);
return obj.version;
}
async function downloadPyright(version2) {
const url = `https://registry.npmjs.org/pyright/-/pyright-${version2.format()}.tgz`;
const url = `https://registry.npmjs.org/pyright/-/pyright-${version2}.tgz`;
const pyrightTarball = await tc.downloadTool(url);
const pyright = await tc.extractTar(pyrightTarball);
return path.join(pyright, "package", "index.js");
Expand Down
39 changes: 3 additions & 36 deletions src/__snapshots__/helpers.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,7 @@ Object {
"/path/to/pyright/package/index.js",
],
"noComments": true,
"pyrightVersion": SemVer {
"build": Array [],
"includePrerelease": false,
"loose": false,
"major": 1,
"minor": 1,
"options": Object {},
"patch": 240,
"prerelease": Array [],
"raw": "1.1.240",
"version": "1.1.240",
},
"pyrightVersion": "1.1.240",
"workingDirectory": "",
}
`;
Expand All @@ -44,18 +33,7 @@ Object {
"--baz",
],
"noComments": false,
"pyrightVersion": SemVer {
"build": Array [],
"includePrerelease": false,
"loose": false,
"major": 1,
"minor": 1,
"options": Object {},
"patch": 240,
"prerelease": Array [],
"raw": "1.1.240",
"version": "1.1.240",
},
"pyrightVersion": "1.1.240",
"workingDirectory": "/path/to/project",
}
`;
Expand All @@ -69,18 +47,7 @@ Object {
"some.package",
],
"noComments": false,
"pyrightVersion": SemVer {
"build": Array [],
"includePrerelease": false,
"loose": false,
"major": 1,
"minor": 1,
"options": Object {},
"patch": 240,
"prerelease": Array [],
"raw": "1.1.240",
"version": "1.1.240",
},
"pyrightVersion": "1.1.240",
"workingDirectory": "",
}
`;
10 changes: 5 additions & 5 deletions src/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,23 +94,23 @@ function getBooleanInput(name: string, defaultValue: boolean): boolean {
return input.toUpperCase() === 'TRUE';
}

async function getPyrightVersion(): Promise<SemVer> {
async function getPyrightVersion(): Promise<string> {
const versionSpec = core.getInput('version');
if (versionSpec) {
return new SemVer(versionSpec);
return new SemVer(versionSpec).format();
}

const client = new httpClient.HttpClient();
const resp = await client.get('https://registry.npmjs.org/pyright/latest');
const body = await resp.readBody();
const obj = NpmRegistryResponse.parse(JSON.parse(body));
return new SemVer(obj.version);
return obj.version;
}

async function downloadPyright(version: SemVer): Promise<string> {
async function downloadPyright(version: string): Promise<string> {
// Note: this only works because the pyright package doesn't have any
// dependencies. If this ever changes, we'll have to actually install it.
const url = `https://registry.npmjs.org/pyright/-/pyright-${version.format()}.tgz`;
const url = `https://registry.npmjs.org/pyright/-/pyright-${version}.tgz`;
const pyrightTarball = await tc.downloadTool(url);
const pyright = await tc.extractTar(pyrightTarball);
return path.join(pyright, 'package', 'index.js');
Expand Down
8 changes: 4 additions & 4 deletions src/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ describe('no comments', () => {
return {
noComments: true,
workingDirectory: wd,
pyrightVersion: new SemVer(pyrightVersion),
args: args,
pyrightVersion,
args,
};
});
});
Expand Down Expand Up @@ -107,8 +107,8 @@ describe('with comments', () => {
return {
noComments: false,
workingDirectory: '',
pyrightVersion: new SemVer('1.1.240'),
args: args,
pyrightVersion,
args,
};
});
});
Expand Down

0 comments on commit 51418c7

Please sign in to comment.