How to use the semver.SemVer function in semver

To help you get started, we’ve selected a few semver examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github flow-typed / flow-typed / definitions / npm / semver_v5.1.x / test_semver.js View on Github external
/* @flow */

import semver, {Comparator, Range, SemVer} from 'semver';

new SemVer('^3.2.0');

(semver.cmp('1.2.3', '>', '1.2.4'): boolean);

// Comparator
const comp = new Comparator('>=3.2.0');
comp.test('5.3.2');
(comp.operator: string);
(comp.value: string);

// comparator object as a ctor arg is okay
new Comparator(comp);

// static/exported properties
(semver.SEMVER_SPEC_VERSION: string);
semver.re.forEach(r => r.test('foo'));
semver.src.forEach(r => r.match(/foo/));
github angular / angular-cli / packages / @angular / cli / upgrade / version.ts View on Github external
} catch (_) {
      console.error(bold(red(stripIndents`
        You seem to not be depending on "@angular/core". This is an error.
      `)));
      process.exit(2);
    }

    // Just check @angular/core.
    if (pkgJson && pkgJson['version']) {
      const v = new Version(pkgJson['version']);
      if (v.isLocal()) {
        console.warn(yellow('Using a local version of angular. Proceeding with care...'));
      } else {
        // Check if major is not 0, so that we stay compatible with local compiled versions
        // of angular.
        if (!v.isGreaterThanOrEqualTo(new SemVer('2.3.1')) && v.major != 0) {
          console.error(bold(red(stripIndents`
            This version of CLI is only compatible with angular version 2.3.1 or better. Please
            upgrade your angular version, e.g. by running:

            npm install @angular/core@latest
          ` + '\n')));
          process.exit(3);
        }
      }
    } else {
      console.error(bold(red(stripIndents`
        You seem to not be depending on "@angular/core". This is an error.
      `)));
      process.exit(2);
    }
  }
github angular / angular-cli / packages / angular / cli / lib / init.ts View on Github external
function _fromPackageJson(cwd = process.cwd()): SemVer | null {
  do {
    const packageJsonPath = path.join(cwd, 'node_modules/@angular/cli/package.json');
    if (fs.existsSync(packageJsonPath)) {
      const content = fs.readFileSync(packageJsonPath, 'utf-8');
      if (content) {
        const { version } = JSON.parse(content);
        if (version) {
          return new SemVer(version);
        }
      }
    }

    // Check the parent.
    cwd = path.dirname(cwd);
  } while (cwd != path.dirname(cwd));

  return null;
}
github OpenZeppelin / openzeppelin-sdk / packages / cli / src / models / dependency / Dependency.ts View on Github external
public static async fetchVersionFromNpm(name: string): Promise {
    const execAsync = promisify(exec);
    try {
      const { stdout } = await execAsync(`npm view ${name}@latest version`);
      const version = new semver.SemVer(stdout.trim());
      return `${name}@^${version.major}.${version.minor}.0`;
    } catch (error) {
      return name;
    }
  }
github SAP / ui5-builder / lib / processors / manifestCreator.js View on Github external
function normalizeVersion(version) {
		if ( version == null ) {
			return version;
		}
		const v = new Version(version);
		return v.major + "." + v.minor;
	}
github rxweb / rxweb / rxweb.io / node_modules / @angular / cli / upgrade / version.js View on Github external
constructor(_version = null) {
        this._version = _version;
        this._semver = null;
        this._semver = _version ? new semver_1.SemVer(_version) : null;
    }
    isAlpha() { return this.qualifier == 'alpha'; }
github ArekSredzki / electron-release-server / api / services / WindowsReleaseService.js View on Github external
WindowsReleaseService.normVersion = function(tag) {
  var parts = new semver.SemVer(tag);
  var prerelease = '';

  if (parts.prerelease && parts.prerelease.length > 0) {
    prerelease = hashPrerelease(parts.prerelease);
  }

  return [
    parts.major,
    parts.minor,
    parts.patch
  ].join('.') + (prerelease ? '.' + prerelease : '');
};
github DevExpress / devextreme-cli / commands / application.angular.js View on Github external
const path = require('path');
const runCommand = require('../utility/run-command');
const semver = require('semver').SemVer;
const fs = require('fs');
const exec = require('child_process').exec;
const minNgCliVersion = new semver('8.0.0');

function runSchematicCommand(schematicCommand, options, evaluatingOptions) {
    const collectionName = 'devextreme-schematics';
    let collectionPath = collectionName;

    if(options['c']) {
        collectionPath = `${path.join(process.cwd(), options['c'])}`;
        delete options['c'];
    }

    const additionalOptions = [];
    for(let option in options) {
        const schematicOption = `--${option}=${options[option]}`;
        additionalOptions.push(schematicOption);
    };
github process-engine / bpmn-studio / src / modules / solution-explorer / solution-explorer-list / solution-explorer-list.ts View on Github external
public isProcessEngineOlderThanInternal(solutionEntry: ISolutionEntry): boolean {
    if (this.internalProcessEngineVersion === 'null') {
      return false;
    }

    const internalPEVersion = new SemVer(this.internalProcessEngineVersion);
    const solutionEntryPEVersion = new SemVer(solutionEntry.processEngineVersion);

    return internalPEVersion.major > solutionEntryPEVersion.major;
  }
github nrkno / tv-automation-server-core / meteor / server / coreSystem.ts View on Github external
if (currentVersion) currentVersion = semver.clean(currentVersion)

	if (expectVersion) {
		if (currentVersion) {

			if (semver.satisfies(currentVersion, expectVersion)) {
				return {
					statusCode: StatusCode.GOOD,
					messages: [`${meName} version: ${currentVersion}`]
				}
			} else {

				const currentV = new semver.SemVer(currentVersion, { includePrerelease: true })

				try {
					const expectV = new semver.SemVer(stripVersion(expectVersion), { includePrerelease: true })

					const message = `Version mismatch: ${meName} version: "${currentVersion}" does not satisfy expected version of ${theyName}: "${expectVersion}"` + (fixMessage ? ` (${fixMessage})` : '')

					if (!expectV || !currentV) {
						return {
							statusCode: StatusCode.BAD,
							messages: [message]
						}
					} else if (expectV.major !== currentV.major) {
						return {
							statusCode: StatusCode.BAD,
							messages: [message]
						}
					} else if (expectV.minor !== currentV.minor) {
						return {
							statusCode: StatusCode.WARNING_MAJOR,