Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for 5.x notation #175

Merged
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 0 additions & 1 deletion __tests__/versionutil.test.ts
Expand Up @@ -42,7 +42,6 @@ describe('version tests', () => {
'.2.3',
'.2.x',
'1',
'2.x',
'*.*.1',
'*.1',
'*.',
Expand Down
16 changes: 9 additions & 7 deletions dist/index.js
Expand Up @@ -16869,14 +16869,16 @@ class DotNetVersionInfo {
return;
}
//Note: No support for previews when using generic
let parts = version.split('.');
const parts = version.split('.');
if (parts.length < 2 || parts.length > 3)
this.throwInvalidVersionFormat();
if (parts.length == 3 && parts[2] !== 'x' && parts[2] !== '*') {
this.throwInvalidVersionFormat();
}
let major = this.getVersionNumberOrThrow(parts[0]);
let minor = this.getVersionNumberOrThrow(parts[1]);
const major = this.getVersionNumberOrThrow(parts[0]);
const minor = ['x', '*'].includes(parts[1])
? parts[1]
: this.getVersionNumberOrThrow(parts[1]);
this.fullversion = major + '.' + minor;
}
getVersionNumberOrThrow(input) {
Expand All @@ -16894,7 +16896,7 @@ class DotNetVersionInfo {
}
}
throwInvalidVersionFormat() {
throw 'Invalid version format! Supported: 1.2.3, 1.2, 1.2.x, 1.2.*';
throw new Error('Invalid version format! Supported: 1.2.3, 1.2, 1.2.x, 1.2.*');
}
/**
* If true exacatly one version should be resolved
Expand Down Expand Up @@ -16997,7 +16999,7 @@ class DotnetCoreInstaller {
}
console.log(process.env['PATH']);
if (resultCode != 0) {
throw `Failed to install dotnet ${resultCode}. ${output}`;
throw new Error(`Failed to install dotnet ${resultCode}. ${output}`);
}
});
}
Expand Down Expand Up @@ -17025,7 +17027,7 @@ class DotnetCoreInstaller {
// Sort for latest version
releasesInfo = releasesInfo.sort((a, b) => semver.rcompare(a['sdk']['version'], b['sdk']['version']));
if (releasesInfo.length == 0) {
throw `Could not find dotnet core version. Please ensure that specified version ${versionInfo.inputVersion} is valid.`;
throw new Error(`Could not find dotnet core version. Please ensure that specified version ${versionInfo.inputVersion} is valid.`);
}
let release = releasesInfo[0];
return release['sdk']['version'];
Expand All @@ -17046,7 +17048,7 @@ class DotnetCoreInstaller {
return versionParts[0] == sdkParts[0];
});
if (releasesInfo.length === 0) {
throw `Could not find info for version ${versionParts.join('.')} at ${DotNetCoreIndexUrl}`;
throw new Error(`Could not find info for version ${versionParts.join('.')} at ${DotNetCoreIndexUrl}`);
}
return releasesInfo[0]['releases.json'];
});
Expand Down
26 changes: 17 additions & 9 deletions src/installer.ts
Expand Up @@ -30,16 +30,18 @@ export class DotNetVersionInfo {
}

//Note: No support for previews when using generic
let parts: string[] = version.split('.');
const parts: string[] = version.split('.');

if (parts.length < 2 || parts.length > 3) this.throwInvalidVersionFormat();

if (parts.length == 3 && parts[2] !== 'x' && parts[2] !== '*') {
this.throwInvalidVersionFormat();
}

let major = this.getVersionNumberOrThrow(parts[0]);
let minor = this.getVersionNumberOrThrow(parts[1]);
const major = this.getVersionNumberOrThrow(parts[0]);
const minor = ['x', '*'].includes(parts[1])
? parts[1]
: this.getVersionNumberOrThrow(parts[1]);

this.fullversion = major + '.' + minor;
}
Expand All @@ -60,7 +62,9 @@ export class DotNetVersionInfo {
}

private throwInvalidVersionFormat() {
throw 'Invalid version format! Supported: 1.2.3, 1.2, 1.2.x, 1.2.*';
throw new Error(
'Invalid version format! Supported: 1.2.3, 1.2, 1.2.x, 1.2.*'
);
}

/**
Expand Down Expand Up @@ -187,7 +191,7 @@ export class DotnetCoreInstaller {
console.log(process.env['PATH']);

if (resultCode != 0) {
throw `Failed to install dotnet ${resultCode}. ${output}`;
throw new Error(`Failed to install dotnet ${resultCode}. ${output}`);
}
}

Expand Down Expand Up @@ -236,7 +240,9 @@ export class DotnetCoreInstaller {
);

if (releasesInfo.length == 0) {
throw `Could not find dotnet core version. Please ensure that specified version ${versionInfo.inputVersion} is valid.`;
throw new Error(
`Could not find dotnet core version. Please ensure that specified version ${versionInfo.inputVersion} is valid.`
);
}

let release = releasesInfo[0];
Expand Down Expand Up @@ -264,9 +270,11 @@ export class DotnetCoreInstaller {
});

if (releasesInfo.length === 0) {
throw `Could not find info for version ${versionParts.join(
'.'
)} at ${DotNetCoreIndexUrl}`;
throw new Error(
`Could not find info for version ${versionParts.join(
'.'
)} at ${DotNetCoreIndexUrl}`
);
}

return releasesInfo[0]['releases.json'];
Expand Down