From b0977357bf71eb1bd9048aa4d10882f7e79200ba Mon Sep 17 00:00:00 2001 From: Zachary Eisinger Date: Tue, 22 Sep 2020 08:11:11 -0700 Subject: [PATCH] Undo unnecessary checks --- dist/index.js | 16 ++++++++-------- src/installer.ts | 22 +++++++++------------- 2 files changed, 17 insertions(+), 21 deletions(-) diff --git a/dist/index.js b/dist/index.js index 769a937..f281026 100644 --- a/dist/index.js +++ b/dist/index.js @@ -16797,15 +16797,14 @@ class DotNetVersionInfo { constructor(version) { this.isExactVersionSet = false; this.inputVersion = version; - //Note: No support for previews when using generic - let parts = version.split('.'); - // Check for exact match, and that there are at least 3 parts to the version (preview/rc versions have more than 3 parts) - if (semver.valid(semver.clean(version) || '') != null && - parts.length >= 3) { + // Check for exact match + if (semver.valid(semver.clean(version) || '') != null) { this.fullversion = semver.clean(version); this.isExactVersionSet = true; return; } + //Note: No support for previews when using generic + let parts = version.split('.'); if (parts.length < 2 || parts.length > 3) this.throwInvalidVersionFormat(); if (parts.length == 3 && parts[2] !== 'x' && parts[2] !== '*') { @@ -16902,8 +16901,8 @@ class DotnetCoreInstaller { fs_1.chmodSync(escapedScript, '777'); const scriptPath = yield io.which(escapedScript, true); let scriptArguments = []; - if (this.version) { - scriptArguments.push('--version', this.version); + if (calculatedVersion) { + scriptArguments.push('--version', calculatedVersion); } // process.env must be explicitly passed in for DOTNET_INSTALL_DIR to be used resultCode = yield exec.exec(`"${scriptPath}"`, scriptArguments, { @@ -16976,7 +16975,8 @@ class DotnetCoreInstaller { releasesInfo = releasesInfo.filter((info) => { // channel-version is the first 2 elements of the version (e.g. 2.1), filter out versions that don't match 2.1.x. const sdkParts = info['channel-version'].split('.'); - if (versionParts.length == 2 || versionParts.length > 2 && !(versionParts[2] == 'x' || versionParts[2] == '*')) { + if (versionParts.length == 2 && + !(versionParts[2] == 'x' || versionParts[2] == '*')) { return versionParts[0] == sdkParts[0] && versionParts[1] == sdkParts[1]; } return versionParts[0] == sdkParts[0]; diff --git a/src/installer.ts b/src/installer.ts index 78f7e3b..7c13f23 100644 --- a/src/installer.ts +++ b/src/installer.ts @@ -21,20 +21,17 @@ export class DotNetVersionInfo { constructor(version: string) { this.inputVersion = version; - //Note: No support for previews when using generic - let parts: string[] = version.split('.'); - - // Check for exact match, and that there are at least 3 parts to the version (preview/rc versions have more than 3 parts) - if ( - semver.valid(semver.clean(version) || '') != null && - parts.length >= 3 - ) { + // Check for exact match + if (semver.valid(semver.clean(version) || '') != null) { this.fullversion = semver.clean(version) as string; this.isExactVersionSet = true; return; } + //Note: No support for previews when using generic + let parts: string[] = version.split('.'); + if (parts.length < 2 || parts.length > 3) this.throwInvalidVersionFormat(); if (parts.length == 3 && parts[2] !== 'x' && parts[2] !== '*') { @@ -149,8 +146,8 @@ export class DotnetCoreInstaller { const scriptPath = await io.which(escapedScript, true); let scriptArguments: string[] = []; - if (this.version) { - scriptArguments.push('--version', this.version); + if (calculatedVersion) { + scriptArguments.push('--version', calculatedVersion); } // process.env must be explicitly passed in for DOTNET_INSTALL_DIR to be used @@ -260,9 +257,8 @@ export class DotnetCoreInstaller { // channel-version is the first 2 elements of the version (e.g. 2.1), filter out versions that don't match 2.1.x. const sdkParts: string[] = info['channel-version'].split('.'); if ( - versionParts.length == 2 || - (versionParts.length > 2 && - !(versionParts[2] == 'x' || versionParts[2] == '*')) + versionParts.length == 2 && + !(versionParts[2] == 'x' || versionParts[2] == '*') ) { return versionParts[0] == sdkParts[0] && versionParts[1] == sdkParts[1]; }