How to use the npm/node_modules/semver.validRange function in npm

To help you get started, we’ve selected a few npm 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 arikon / npm2debian / lib / source.js View on Github external
function _source(pkg, reg, pkglist, cb) {
    log.verbose(pkg, "_source");

    // it's a local thing or a url if it has a / in it.
    if (pkg.indexOf("/") !== -1 || pkg === ".") {
        log.silly(pkg, "install local");
        return cache.add(pkg, finisher(pkg, reg, pkglist, cb));
    }

    // now we know it's not a URL or file,
    // so handle it like a tag, version, or range.
    pkg = pkg.split("@");
    var name = pkg[0],
        defTag = npm.config.get("tag"),
        ver = pkg.slice(1).join("@").trim() || defTag,
        range = semver.validRange(ver),
        exact = semver.valid(ver),
        tag = !exact && !range && range !== "" && ver,
        pkg = pkg.join("@");

    // at this point, assume that it has to be debianized
    if (exact) {
        log.verbose("exact", pkg);
        // just pull the data out of the cache to ensure it's there
        return cache.read(name, ver, finisher(pkg, reg, pkglist, cb));
    }

    getData(name, function (er, data) {
        if (er) return cb(er);
        log.silly(data, pkg);
        if (tag) {
            log.verbose(tag, pkg + " tag");
github arikon / npm2debian / lib / source.js View on Github external
if (seen[pkg]) return cb() // repeat, skip it
  seen[pkg] = true

  // it's a local thing or a url if it has a / in it.
  if (pkg.indexOf("/") !== -1 || pkg === ".") {
    log.silly(pkg, "install local")
    return cache.add(pkg, finisher(pkg, reg, pkglist, cb))
  }

  // now we know it's not a URL or file,
  // so handle it like a tag, version, or range.
  pkg = pkg.split("@")
  var name = pkg[0]
    , defTag = npm.config.get("tag")
    , ver = pkg.slice(1).join("@").trim() || defTag
    , range = semver.validRange(ver)
    , exact = semver.valid(ver)
    , tag = !exact && !range && range !== "" && ver
  log.verbose([pkg, mustHave], "must install?")
  pkg = pkg.join("@")
  seen[name+"@"+ver] = true

  // if there is a satisfying version already, then simply move on.
  if (!tag && findSatisfying(pkg, name, range, mustHave, reg)) {
    return cb()
  }

  // at this point, assume that it has to be installed.
  if (exact) {
    log.verbose("exact", pkg)
    // just pull the data out of the cache to ensure it's there
    return cache.read(name, ver, finisher(pkg, reg, pkglist, cb))