How to use the semver.patch 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 teambit / bit / src / scope / network / check-version-compatibility.js View on Github external
export default function checkVersionCompatibility(remoteVersion: string) {
  // In case the client is newer than the server version don't check computability
  // (Should be change in the future, but right now we won't release a client which we don't support
  //  on the server)
  if (semver.gte(BIT_VERSION, remoteVersion)) {
    return;
  }

  const remoteMajor = semver.major(remoteVersion);
  const remoteMinor = semver.minor(remoteVersion);
  const remotePatch = semver.patch(remoteVersion);
  const localMajor = semver.major(BIT_VERSION);
  const localMinor = semver.minor(BIT_VERSION);
  const localPatch = semver.patch(BIT_VERSION);

  if (remoteMajor > localMajor) {
    if (localMajor < throwErrorFromServerSinceVersion) return;
    loader.stop();
    console.log(createMajorMessage(remoteVersion, BIT_VERSION)); // eslint-disable-line
    loader.start();
    return;
  }

  if (remoteMinor > localMinor) {
    loader.stop();
    console.log(createMajorMessage(remoteVersion, BIT_VERSION)); // eslint-disable-line
    loader.start();
github teambit / bit / src / scope / network / check-version-compatibility.ts View on Github external
export default function checkVersionCompatibility(remoteVersion: string) {
  // In case the client is newer than the server version don't check computability
  // (Should be change in the future, but right now we won't release a client which we don't support
  //  on the server)
  if (semver.gte(BIT_VERSION, remoteVersion)) {
    return;
  }

  const remoteMajor = semver.major(remoteVersion);
  const remoteMinor = semver.minor(remoteVersion);
  const remotePatch = semver.patch(remoteVersion);
  const localMajor = semver.major(BIT_VERSION);
  const localMinor = semver.minor(BIT_VERSION);
  const localPatch = semver.patch(BIT_VERSION);

  if (remoteMajor > localMajor) {
    if (localMajor < throwErrorFromServerSinceVersion) return;
    loader.stop();
    logger.console(createMajorMessage(remoteVersion, BIT_VERSION), 'error');
    // @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
    loader.start();
    return;
  }

  if (remoteMinor > localMinor) {
    loader.stop();
    logger.console(createMinorMessage(remoteVersion, BIT_VERSION), 'error');
    // @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
    loader.start();
    return;
github appcelerator / titanium_mobile / changelog / config.js View on Github external
// Major means EoS 12 months from now for last major line.
			// Minor/Patch means EoS 6 months from now for last minor
			const eosDate = new Date();
			if (context.isMajor) {
				eosDate.setMonth(eosDate.getMonth() + 12);
				// if isMajor, subtract one from major, add '.x', i.e. 8.0.0 -> '7.x'
				context.eosBranch = `${semver.major(context.version) - 1}.x`;
			} else {
				if (!context.isPatch) { // should be minor!
					// if isMinor, subtract one from minor, add .x, i.e. 8.1.0 -> 8.0.x
					context.eosBranch = `${semver.major(context.version)}.${semver.minor(context.version) - 1}.x`;
					context.patchBranch = `${semver.major(context.version)}.${semver.minor(context.version)}.x`;
					context.majorBranch = `${semver.major(context.version)}.x`;
				} else {
					// Patch, so mark previous patch release as EoS
					context.eosBranch = `${semver.major(context.version)}.${semver.minor(context.version)}.${semver.patch(context.version) - 1}`;
				}
				eosDate.setMonth(eosDate.getMonth() + 6);
			}
			context.eosDate = dateFormat(eosDate, 'yyyy-mm-dd', true);

			// Gather up the modules shipped with this version and toss into a variable we can put into the changelog
			const modules = gatherModules();
			context.modules = Array.from(modules.values());

			return context;
		},
		commitPartial: fs.readFileSync(path.join(__dirname, 'templates/commit.hbs'), 'utf8'),
github honestbleeps / Reddit-Enhancement-Suite / lib / core / metadata / packageInfo.js View on Github external
/* @flow */
/* eslint-disable import/no-commonjs, import/no-nodejs-modules */

const { execSync } = require('child_process');
const semver = require('semver');
const isBetaVersion = require('../../../build/isBetaVersion');
const packageInfo = require('../../../package.json');

const announcementsSubreddit /*: string */ = 'RESAnnouncements';
const name /*: string */ = packageInfo.title;
const version /*: string */ = packageInfo.version;
const isBeta /*: boolean */ = isBetaVersion(version);
const isPatch /*: boolean */ = semver.patch(version) !== 0;
const isMinor /*: boolean */ = !isPatch && semver.minor(version) !== 0;
const isMajor /*: boolean */ = !isPatch && !isMinor && semver.major(version) !== 0;
const updatedURL /*: string */ = isBeta ?
	// link to the release listing page instead of a specific release page
	// so if someone goes from the previous version to a hotfix (e.g. 5.10.3 -> 5.12.1)
	// they see the big release notes for the minor release in addition to the changes in the hotfix
	`https://redditenhancementsuite.com/releases/beta/#v${version}` :
	`https://redditenhancementsuite.com/releases/#v${version}`;
const homepageURL /*: string */ = packageInfo.homepage;
let gitDescription;
try {
	// `git describe` does not work if a tag isn't available
	// which may be the case when shallow cloning the repo
	gitDescription = execSync('git describe', { encoding: 'utf8' }).trim();
} catch (e) {
	// in that case, use the commit hash
github govau / pancake / bin / pancake-cream.js View on Github external
Log.error('Version is not a valid semver version: ' + Chalk.yellow(oldVersion));
	}

	if (!Semver.valid(newVersion)) {
		Log.error('Version is not a valid semver version: ' + Chalk.yellow(newVersion));
	}

	if (Semver.major(oldVersion) !== Semver.major(newVersion)) {
		return Chalk.magenta(newVersion);
	}

	if (Semver.minor(oldVersion) !== Semver.minor(newVersion)) {
		return Semver.major(newVersion) + '.' + Chalk.magenta(Semver.minor(newVersion) + '.' + Semver.patch(newVersion));
	}

	if (Semver.patch(oldVersion) !== Semver.patch(newVersion)) {
		return Semver.major(newVersion) + '.' + Semver.minor(newVersion) + '.' + Chalk.magenta('' + Semver.patch(newVersion));
	}
};
github electrode-io / electrode-native / ern-local-cli / src / lib / publication.js View on Github external
export function containsVersionMismatch (
  versions: Array,
  mismatchLevel: 'major' | 'minor' | 'patch') : boolean {
  const minVersion = semver.minSatisfying(versions, '*')
  const maxVersion = semver.maxSatisfying(versions, '*')
  const majorMismatch = semver.major(maxVersion) !== semver.major(minVersion)
  const minorMismatch = semver.minor(maxVersion) !== semver.minor(minVersion)
  const patchMismatch = semver.patch(maxVersion) !== semver.patch(minVersion)
  return majorMismatch ||
        (minorMismatch && (mismatchLevel === 'minor' || mismatchLevel === 'patch')) ||
        (patchMismatch && mismatchLevel === 'patch')
}
github instacart / Snacks / scripts / release / build_release.js View on Github external
const upVersion = ({ versioningType, packageVersion }) => {
  const major = semver.major(packageVersion)
  const minor = semver.minor(packageVersion)
  const patch = semver.patch(packageVersion)

  switch (versioningType) {
    case 'patch': {
      return `${major}.${minor}.${parseInt(patch) + 1}`
    }
    case 'minor': {
      return `${major}.${parseInt(minor) + 1}.${patch}`
    }
    case 'major': {
      return `${parseInt(major) + 1}.${minor}.${patch}`
    }
    default: {
      throw `bad npm versioning type! Acceptable types: patch, minor, major. Type passes: ${versioningType}`
    }
  }
}
github electrode-io / electrode-native / ern-core / src / resolveNativeDependenciesVersions.js View on Github external
export function containsVersionMismatch (
  versions: Array,
  mismatchLevel: 'major' | 'minor' | 'patch') : boolean {
  const minVersion = semver.minSatisfying(versions, '*')
  const maxVersion = semver.maxSatisfying(versions, '*')
  const majorMismatch = semver.major(maxVersion) !== semver.major(minVersion)
  const minorMismatch = semver.minor(maxVersion) !== semver.minor(minVersion)
  const patchMismatch = semver.patch(maxVersion) !== semver.patch(minVersion)
  return majorMismatch ||
        (minorMismatch && (mismatchLevel === 'minor' || mismatchLevel === 'patch')) ||
        (patchMismatch && mismatchLevel === 'patch')
}