Skip to content
Permalink
Browse files

fix(generic): assume invalid semver package manager versions are inco…

…mpatible

ISSUES CLOSED: #376
  • Loading branch information
malept committed Nov 27, 2017
1 parent e118c05 commit 076c78e1bf9c64e3092369ef121ed48b53a726b0
Showing with 20 additions and 11 deletions.
  1. +12 −3 src/util/check-system.js
  2. +8 −8 test/fast/system_spec.js
@@ -1,8 +1,11 @@
import { exec } from 'child_process';
import debug from 'debug';
import semver from 'semver';

import { hasYarn, yarnOrNpmSpawn } from './yarn-or-npm';

const d = debug('electron-forge:check-system');

async function checkGitExists() {
return new Promise((resolve) => {
exec('git --version', (err) => {
@@ -27,15 +30,21 @@ const YARN_WHITELISTED_VERSIONS = {
linux: '0.27.5',
};

export function isNightlyYarnVersion(version) {
return /((?:\d\.?)+)-\d.*/.test(version);
export function validPackageManagerVersion(packageManager, version, whitelistedVersions, ora) {
try {
return semver.satisfies(version, whitelistedVersions);
} catch (e) {
ora.warn(`Could not check ${packageManager} version "${version}", assuming incompatible`);
d(`Exception while checking version: ${e}`);
return false;
}
}

function warnIfPackageManagerIsntAKnownGoodVersion(packageManager, version, whitelistedVersions, ora) {
const osVersions = whitelistedVersions[process.platform];
const versions = osVersions ? `${whitelistedVersions.all} || ${osVersions}` : whitelistedVersions.all;
const versionString = version.toString();
if (isNightlyYarnVersion(versionString) || !semver.satisfies(versionString, versions)) {
if (!validPackageManagerVersion(packageManager, versionString, versions, ora)) {
ora.warn(
`You are using ${packageManager}, but not a known good version.\n` +
`The known versions that work with Electron Forge are: ${versions}`
@@ -1,24 +1,24 @@
import { expect } from 'chai';

import checkSystem, { isNightlyYarnVersion } from '../../src/util/check-system';
import checkSystem, { validPackageManagerVersion } from '../../src/util/check-system';
import { fakeOra } from '../../src/util/ora';

describe('check-system', () => {
it('should succeed on valid agents', async () => {
expect(await checkSystem(fakeOra())).to.be.equal(true);
});

describe('isNightlyYarnVersion', () => {
it('should not match release versions', () => {
expect(isNightlyYarnVersion('0.10.0')).to.be.equal(false);
describe('validPackageManagerVersion', () => {
it('should consider whitelisted versions to be valid', () => {
expect(validPackageManagerVersion('NPM', '3.10.1', '^3.0.0', fakeOra())).to.be.equal(true);
});

it('should not match rc/beta/alpha versions', () => {
expect(isNightlyYarnVersion('0.10.0-beta.1')).to.be.equal(false);
it('should consider Yarn nightly versions to be invalid', () => {
expect(validPackageManagerVersion('Yarn', '0.23.0-20170311.0515', '0.23.0', fakeOra())).to.be.equal(false);
});

it('should match nightly versions', () => {
expect(isNightlyYarnVersion('0.23.0-20170311.0515')).to.be.equal(true);
it('should consider invalid semver versions to be invalid', () => {
expect(validPackageManagerVersion('Yarn', '0.22', '0.22.0', fakeOra())).to.be.equal(false);
});
});
});

0 comments on commit 076c78e

Please sign in to comment.
You can’t perform that action at this time.