Skip to content

Commit

Permalink
Modify OS.isWindows to check platform before version (#2407)
Browse files Browse the repository at this point in the history
* Modify OS.isWindows to check if OS is Windows first before checking version.

Previously OS.isWindows checked if the windows version matched the one required. This worked fine, except for the fact that it would end up comparing a linux kernel version to a windows version as it didn't check if the platform was Windows in the first place before.

This caused issues as it would throw an error when comparing with non-semver linux kernels (such as Fedora). Now it checks if the current platform is Windows first, and if not, immediately returns false.

Resolves: #2396

* Fix formatting for OS.ts
  • Loading branch information
jython234 authored and scottnonnenberg-signal committed May 20, 2018
1 parent 877cbfc commit 84759d8
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions ts/OS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@ import semver from 'semver';
export const isMacOS = () => process.platform === 'darwin';
export const isLinux = () => process.platform === 'linux';
export const isWindows = (minVersion?: string) => {
const isPlatformValid = process.platform === 'win32';
if (process.platform !== 'win32') return false;

const osRelease = os.release();
const isVersionValid = is.undefined(minVersion)
? true
: semver.gte(osRelease, minVersion);

return isPlatformValid && isVersionValid;
return isVersionValid;
};

0 comments on commit 84759d8

Please sign in to comment.