How to use the semver.validRange 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 3rd-Eden / canihaz / index.js View on Github external
function install(cwd, name, version, cb) {
  var noRegistry;

  if (version) {
    // * installations is basically just an installation without a version, so
    // just ignore this version
    if (version === '*') version = '';

    // If it doesn't get through the `validRange` it's probably not a Semver but
    // an url like git@github or a tarball
    if (version && semver.validRange(version)) {
      // If the version number contains spaces we need to wrap it in double quotes
      // as we are most likely dealing with version range installation that contains
      // silly shit such as: >=0.1.0 <0.2.0
      if (version && /\s/.test(version)) version = '"'+ version +'"';
      if (version) version = '@'+ version;
    } else if (version) {
      // This is probably not a valid version but a tarbal or git url, we cannot
      // override the name variable or we cannot require it again so we have to
      // use a other variable to change the "name" that we want to install
      noRegistry = version;
      version = '';
    }
  }

  var installation = (noRegistry || name) + version;
github dylang / npm-check / lib / process-data.js View on Github external
// private
                isPrivate: isPrivate,

                // meta
                devDependency: _.has(packageJson.devDependencies, moduleName),
                usedInScripts: _.findKey(packageJson.scripts, function (script) {
                    return script.indexOf(moduleName) !== -1;
                }),
                mismatch: semver.validRange(packageJsonVersion) &&
                    semver.valid(versionToUse) &&
                    !semver.satisfies(versionToUse, packageJsonVersion),
                semverValidRange: semver.validRange(packageJsonVersion),
                semverValid:
                    semver.valid(versionToUse),
                easyUpgrade: semver.validRange(packageJsonVersion) &&
                    semver.valid(versionToUse) &&
                    semver.satisfies(latest, packageJsonVersion),
                bump: bump
            };
        });
}
github Akryum / nodepack / packages / @nodepack / app-migrator / src / util / mergeDeps.ts View on Github external
res[name] = r2
      sources[name] = id
    } else {
      const r1semver = extractSemver(r1)
      const r2semver = extractSemver(r2)
      const r = tryGetNewerRange(r1semver, r2semver)
      const didGetNewer = !!r
      // if failed to infer newer version, use existing one because it's likely
      // built-in
      res[name] = didGetNewer ? injectSemver(r2, r) : r1
      // if changed, update source
      if (res[name] === r2) {
        sources[name] = id
      }
      // warn incompatible version requirements
      if (!semver.validRange(r1semver) || !semver.validRange(r2semver) || !semver.intersects(r1semver, r2semver)) {
        consola.warn(
          `conflicting versions for project dependency "${name}":\n\n` +
          `- ${r1} injected by migration "${sourceMigrationId}"\n` +
          `- ${r2} injected by migration "${id}"\n\n` +
          `Using ${didGetNewer ? `newer ` : ``}version (${res[name]}), but this may cause build errors.`,
        )
      }
    }
  }
  return res
}
github teambit / bit / src / consumer / component / dependencies / dependency-resolver / dependencies-versions-resolver.js View on Github external
function getIdFromPackageJson(componentId: BitId): ?BitId {
    if (!componentId.scope) return null;
    // $FlowFixMe component.componentMap is set
    const rootDir: ?PathLinux = component.componentMap.rootDir;
    const consumerPath = consumer.getPath();
    const basePath = rootDir ? path.join(consumerPath, rootDir) : consumerPath;
    const packagePath = getNodeModulesPathOfComponent(component.bindingPrefix, componentId);
    const packageName = packagePath.replace(`node_modules${path.sep}`, '');
    const modulePath = consumer.driver.driver.resolveModulePath(packageName, basePath, consumerPath);
    if (!modulePath) return null; // e.g. it's author and wasn't exported yet, so there's no node_modules of that component
    const packageObject = consumer.driver.driver.resolveNodePackage(basePath, modulePath);
    if (!packageObject || R.isEmpty(packageObject)) return null;
    const packageId = Object.keys(packageObject)[0];
    const version = packageObject[packageId];
    if (!semver.valid(version) && !semver.validRange(version)) return null; // it's probably a relative path to the component
    const validVersion = version.replace(/[^0-9.]/g, ''); // allow only numbers and dots to get an exact version
    return componentId.changeVersion(validVersion);
  }
github fulcrumapp / fulcrum-desktop / resources / yarn / yarn / lib / cli / commands / check.js View on Github external
}

    const locationsVisited = new Set();
    while (dependenciesToCheckVersion.length) {
      const dep = dependenciesToCheckVersion.shift();
      const manifestLoc = path.join(dep.parentCwd, registry.folder, dep.name);
      if (locationsVisited.has(manifestLoc + `@${dep.version}`)) {
        continue;
      }
      locationsVisited.add(manifestLoc + `@${dep.version}`);
      if (!(yield (_fs || _load_fs()).exists(manifestLoc))) {
        reportError('packageNotInstalled', `${dep.originalKey}`);
        continue;
      }
      const pkg = yield config.readManifest(manifestLoc, registryName);
      if (semver.validRange(dep.version, config.looseSemver) && !semver.satisfies(pkg.version, dep.version, config.looseSemver)) {
        reportError('packageWrongVersion', dep.originalKey, dep.version, pkg.version);
        continue;
      }
      const dependencies = pkg.dependencies;
      if (dependencies) {
        for (const subdep in dependencies) {
          const subDepPath = path.join(manifestLoc, registry.folder, subdep);
          let found = false;
          const relative = path.relative(registry.cwd, subDepPath);
          const locations = path.normalize(relative).split(registry.folder + path.sep).filter(function (dir) {
            return !!dir;
          });
          locations.pop();
          while (locations.length >= 0) {
            let possiblePath;
            if (locations.length > 0) {
github frontarm / demoboard / packages / demoboard-worker / src / npm / npm.ts View on Github external
function getKnownMatchingVersion(name: string, range: string) {
  let rangeWithoutSymbol = range.slice(1)
  if (validRange(rangeWithoutSymbol)) {
    let versions = npmRequestedPackageVersions[name] || []
    for (let i = 0; i < versions.length; i++) {
      let version = versions[i]
      if (satisfies(version.slice(1), rangeWithoutSymbol)) {
        return version
      }
    }
  }
}
github microsoft / vscode-react-native / src / extension / appcenter / lib / codepush-node-sdk / dist / utils / validation-utils.js View on Github external
function isValidRange(semverRange) {
    return !!semver.validRange(semverRange);
}
exports.isValidRange = isValidRange;
github NativeScript / nativescript-cli / lib / services / livesync / playground / preview-app-plugins-service.ts View on Github external
private async getWarningForPluginCore(pluginName: string, localPluginVersion: string, devicePluginVersion: string, deviceId: string): Promise {
		this.$logger.trace(`Comparing plugin ${pluginName} with localPluginVersion ${localPluginVersion} and devicePluginVersion ${devicePluginVersion}`);

		if (!devicePluginVersion) {
			return util.format(PluginComparisonMessages.PLUGIN_NOT_INCLUDED_IN_PREVIEW_APP, pluginName, deviceId);
		}

		const shouldSkipCheck = !semver.valid(localPluginVersion) && !semver.validRange(localPluginVersion);
		if (shouldSkipCheck) {
			return null;
		}

		const localPluginVersionData = await this.$packageInstallationManager.getMaxSatisfyingVersionSafe(pluginName, localPluginVersion);
		const devicePluginVersionData = await this.$packageInstallationManager.getMaxSatisfyingVersionSafe(pluginName, devicePluginVersion);

		if (semver.valid(localPluginVersionData) && semver.valid(devicePluginVersionData)) {
			if (semver.major(localPluginVersionData) !== semver.major(devicePluginVersionData)) {
				return util.format(PluginComparisonMessages.LOCAL_PLUGIN_WITH_DIFFERENCE_IN_MAJOR_VERSION, pluginName, localPluginVersion, devicePluginVersion);
			} else if (semver.minor(localPluginVersionData) > semver.minor(devicePluginVersionData)) {
				return util.format(PluginComparisonMessages.LOCAL_PLUGIN_WITH_GREATHER_MINOR_VERSION, pluginName, localPluginVersion, devicePluginVersion);
			}

		}
github connyay / openshift-iojs / bin / iojs / lib / node_modules / npm / lib / cache / add-named.js View on Github external
function addNamed (name, version, data, cb_) {
  assert(typeof name === "string", "must have module name")
  assert(typeof cb_ === "function", "must have callback")

  var key = name + "@" + version
  log.silly("addNamed", key)

  function cb (er, data) {
    if (data && !data._fromGithub) data._from = key
    cb_(er, data)
  }

  if (semver.valid(version, true)) {
    log.verbose('addNamed', JSON.stringify(version), 'is a plain semver version for', name)
    addNameVersion(name, version, data, cb)
  } else if (semver.validRange(version, true)) {
    log.verbose('addNamed', JSON.stringify(version), 'is a valid semver range for', name)
    addNameRange(name, version, data, cb)
  } else {
    log.verbose('addNamed', JSON.stringify(version), 'is being treated as a dist-tag for', name)
    addNameTag(name, version, data, cb)
  }
}
github NodeBB / NodeBB / src / plugins / load.js View on Github external
function checkVersion(pluginData) {
		function add() {
			if (!Plugins.versionWarning.includes(pluginData.id)) {
				Plugins.versionWarning.push(pluginData.id);
			}
		}

		if (pluginData.nbbpm && pluginData.nbbpm.compatibility && semver.validRange(pluginData.nbbpm.compatibility)) {
			if (!semver.satisfies(nconf.get('version'), pluginData.nbbpm.compatibility)) {
				add();
			}
		} else {
			add();
		}
	}