Example #1
0
function resolveWithNewModule (pkg, tree, log, next) {
  validate('OOOF', arguments)
  if (pkg.type) {
    return fetchPackageMetadata(pkg, packageRelativePath(tree), log.newItem('fetchMetadata'), iferr(next, function (pkg) {
      resolveWithNewModule(pkg, tree, log, next)
    }))
  }

  if (!pkg._installable) {
    log.silly('resolveWithNewModule', packageId(pkg), 'checking installable status')
    return isInstallable(pkg, iferr(next, function () {
      pkg._installable = true
      resolveWithNewModule(pkg, tree, log, next)
    }))
  }

  if (!pkg._from) {
    pkg._from = pkg._requested.name + '@' + pkg._requested.spec
  }
  addShrinkwrap(pkg, iferr(next, function () {
    addBundled(pkg, iferr(next, function () {
      var parent = earliestInstallable(tree, tree, pkg) || tree
      var child = createChild({
        package: pkg,
        parent: parent,
        path: path.join(parent.path, 'node_modules', pkg.name),
        realpath: path.resolve(parent.realpath, 'node_modules', pkg.name),
        children: pkg._bundled || [],
        isLink: tree.isLink
      })
      delete pkg._bundled
      var hasBundled = child.children.length

      var replaced = replaceModuleByName(parent, 'children', child)
      if (replaced) removeObsoleteDep(replaced)
      addRequiredDep(tree, child, function () {
        child.location = flatNameFromTree(child)

        if (tree.parent && parent !== tree) updatePhantomChildren(tree.parent, child)

        if (hasBundled) {
          inflateBundled(child, child.children)
        }

        if (pkg._shrinkwrap && pkg._shrinkwrap.dependencies) {
          return inflateShrinkwrap(child, pkg._shrinkwrap.dependencies, function (er) {
            next(er, child, log)
          })
        }

        next(null, child, log)
      })
    }))
  }))
}
Example #2
0
  addShrinkwrap(pkg, iferr(next, function () {
    addBundled(pkg, iferr(next, function () {
      var parent = earliestInstallable(tree, tree, pkg) || tree
      var child = createChild({
        package: pkg,
        parent: parent,
        path: path.join(parent.path, 'node_modules', pkg.name),
        realpath: path.resolve(parent.realpath, 'node_modules', pkg.name),
        children: pkg._bundled || [],
        isLink: tree.isLink
      })

      var replaced = replaceModule(parent, 'children', child)
      if (replaced) removeObsoleteDep(replaced)
      addRequiredDep(tree, child)
      pkg._location = flatNameFromTree(child)

      if (tree.parent && parent !== tree) updatePhantomChildren(tree.parent, child)

      if (pkg._bundled) {
        inflateBundled(child, child.children)
      }

      if (pkg._shrinkwrap && pkg._shrinkwrap.dependencies) {
        return inflateShrinkwrap(child, pkg._shrinkwrap.dependencies, function (er) {
          next(er, child, log)
        })
      }

      next(null, child, log)
    }))
  }))
Example #3
0
function addDependency (name, versionSpec, tree, log, done) {
  validate('SSOOF', arguments)
  var next = andAddParentToErrors(tree, done)
  try {
    var req = childDependencySpecifier(tree, name, versionSpec)
    if (tree.swRequires && tree.swRequires[name]) {
      var swReq = childDependencySpecifier(tree, name, tree.swRequires[name], tree.package._where)
    }
  } catch (err) {
    return done(err)
  }
  var child = findRequirement(tree, name, req)
  if (!child && swReq) child = findRequirement(tree, name, swReq)
  if (hasModernMeta(child)) {
    resolveWithExistingModule(child, tree)
    if (child.package._shrinkwrap === undefined) {
      readShrinkwrap.andInflate(child, function (er) { next(er, child, log) })
    } else {
      next(null, child, log)
    }
  } else {
    if (child) {
      if (req.registry) {
        req = childDependencySpecifier(tree, name, child.package.version)
      }
      if (child.fromBundle) reportBundleOverride(child, log)
      removeObsoleteDep(child, log)
    }
    fetchPackageMetadata(req, packageRelativePath(tree), {tracker: log.newItem('fetchMetadata')}, iferr(next, function (pkg) {
      resolveWithNewModule(pkg, tree, log, next)
    }))
  }
}
Example #4
0
Installer.prototype.readLocalPackageData = function (cb) {
  validate('F', arguments)
  log.silly('install', 'readLocalPackageData')
  var self = this
  mkdirp(this.where, iferr(cb, function () {
    readPackageTree(self.where, iferr(cb, function (currentTree) {
      self.currentTree = currentTree
      self.currentTree.warnings = []
      if (!self.noPackageJsonOk && !currentTree.package) {
        log.error('install', "Couldn't read dependencies")
        var er = new Error("ENOENT, open '" + path.join(self.where, 'package.json') + "'")
        er.code = 'ENOPACKAGEJSON'
        er.errno = 34
        return cb(er)
      }
      if (!currentTree.package) currentTree.package = {}
      if (currentTree.package._shrinkwrap) return cb()
      fs.readFile(path.join(self.where, 'npm-shrinkwrap.json'), {encoding: 'utf8'}, function (er, data) {
        if (er) return cb()
        try {
          currentTree.package._shrinkwrap = JSON.parse(data)
        } catch (ex) {
          return cb(ex)
        }
        return cb()
      })
    }))
  }))

}
Example #5
0
Installer.prototype.readLocalPackageData = function (cb) {
  validate('F', arguments)
  log.silly('install', 'readLocalPackageData')
  var self = this
  mkdirp(this.where, iferr(cb, function () {
    readPackageTree(self.where, iferr(cb, function (currentTree) {
      self.currentTree = currentTree
      self.currentTree.warnings = []
      if (currentTree.error && currentTree.error.code === 'EJSONPARSE') {
        return cb(currentTree.error)
      }
      if (!self.noPackageJsonOk && !currentTree.package) {
        log.error('install', "Couldn't read dependencies")
        var er = new Error("ENOENT, open '" + path.join(self.where, 'package.json') + "'")
        er.code = 'ENOPACKAGEJSON'
        er.errno = 34
        return cb(er)
      }
      if (!currentTree.package) currentTree.package = {}
      readShrinkwrap(currentTree, function (err) {
        if (err) {
          cb(err)
        } else {
          self.loadArgMetadata(cb)
        }
      })
    }))
  }))
}
Example #6
0
Installer.prototype.loadArgMetadata = function (next) {
  var self = this
  getAllMetadata(this.args, this.currentTree, iferr(next, function (args) {
    self.args = args
    next()
  }))
}
Example #7
0
 mkdirp(this.where, iferr(cb, function () {
   readPackageTree(self.where, iferr(cb, function (currentTree) {
     self.currentTree = currentTree
     self.currentTree.warnings = []
     if (!self.noPackageJsonOk && !currentTree.package) {
       log.error('install', "Couldn't read dependencies")
       var er = new Error("ENOENT, open '" + path.join(self.where, 'package.json') + "'")
       er.code = 'ENOPACKAGEJSON'
       er.errno = 34
       return cb(er)
     }
     if (!currentTree.package) currentTree.package = {}
     self.loadArgMetadata(iferr(cb, function () {
       if (currentTree.package._shrinkwrap) return cb()
       fs.readFile(path.join(self.where, 'npm-shrinkwrap.json'), function (er, data) {
         if (er) return cb()
         try {
           currentTree.package._shrinkwrap = parseJSON(data)
         } catch (ex) {
           return cb(ex)
         }
         return cb()
       })
     }))
   }))
 }))
Example #8
0
File: tar.js Project: boneskull/npm
 readPackageTree(folder, pulseTillDone('pack:readTree:' + packageId(pkg), iferr(cb, function (tree) {
   var recalcGroup = log.newGroup('pack:recalc:' + packageId(pkg))
   recalculateMetadata(tree, recalcGroup, iferr(cb, function () {
     recalcGroup.finish()
     pack_(tarball, folder, tree, pkg, pulseTillDone('pack:' + packageId(pkg), cb))
   }))
 })))
Example #9
0
module.exports.addBundled = function addBundled (pkg, next) {
  validate('OF', arguments)
  if (pkg._bundled !== undefined) return next(null, pkg)
  if (!pkg.bundleDependencies) return next(null, pkg)
  if (retryWithCached(pkg, addBundled, next)) return
  pkg._bundled = null
  var pkgname = pkg.name
  var ver = pkg.version
  var tarball = path.join(cachedPackageRoot({name: pkgname, version: ver}), 'package.tgz')
  var target = tempFilename('unpack')
  getCacheStat(iferr(next, function (cs) {
    log.verbose('addBundled', 'extract', tarball)
    unpack(tarball, target, null, null, cs.uid, cs.gid, iferr(next, function () {
      log.silly('addBundled', 'read tarball')
      readPackageTree(target, function (er, tree) {
        log.silly('cleanup', 'remove extracted module')
        rimraf(target, function () {
          if (tree) {
            pkg._bundled = tree.children
          }
          next(null, pkg)
        })
      })
    }))
  }))
}
Example #10
0
Installer.prototype.printInstalled = function (cb) {
  validate('F', arguments)
  log.silly('install', 'printInstalled')
  var self = this
  log.clearProgress()
  this.differences.forEach(function (action) {
    var mutation = action[0]
    var child = action[1]
    var name = getPackageId(child)
    var where = path.relative(self.where, child.path)
    if (mutation === 'remove') {
      console.log('- ' + name + ' ' + where)
    } else if (mutation === 'move') {
      var oldWhere = path.relative(self.where, child.fromPath)
      console.log(name + ' ' + oldWhere + ' -> ' + where)
    }
  })
  var addedOrMoved = this.differences.filter(function (action) {
    var mutation = action[0]
    var child = action[1]
    return !child.failed && (mutation === 'add' || mutation === 'update')
  }).map(function (action) {
    var child = action[1]
    return getPackageId(child)
  })
  log.showProgress()
  if (!addedOrMoved.length) return cb()
  recalculateMetadata(this.idealTree, log, iferr(cb, function (tree) {
    log.clearProgress()
    ls.fromTree(self.where, tree, addedOrMoved, false, function () {
      log.showProgress()
      cb()
    })
  }))
}
module.exports = function fetchPackageMetadata (spec, where, tracker, done) {
  if (!done) {
    done = tracker || where
    tracker = null
    if (done === where) where = null
  }
  if (typeof spec === 'object') {
    var dep = spec
    spec = dep.raw
  }
  var logAndFinish = andLogAndFinish(spec, tracker, done)
  if (!dep) {
    log.silly('fetchPackageMetaData', spec)
    return realizePackageSpecifier(spec, where, iferr(logAndFinish, function (dep) {
      fetchPackageMetadata(dep, where, tracker, done)
    }))
  }
  if (dep.type === 'version' || dep.type === 'range' || dep.type === 'tag') {
    fetchNamedPackageData(dep, addRequestedAndFinish)
  } else if (dep.type === 'directory') {
    fetchDirectoryPackageData(dep, where, addRequestedAndFinish)
  } else {
    fetchOtherPackageData(spec, dep, where, addRequestedAndFinish)
  }
  function addRequestedAndFinish (er, pkg) {
    if (pkg) annotateMetadata(pkg, dep, spec, where)
    logAndFinish(er, pkg)
  }
}
Example #12
0
  asyncMap(args, function (pkg, done) {
    var depLoaded = andAddParentToErrors(tree, done)
    resolveWithNewModule(pkg, tree, log.newGroup('loadRequestedDeps'), iferr(depLoaded, function (child, tracker) {
      validate('OO', arguments)
      if (npm.config.get('global')) {
        child.isGlobal = true
      }
      var childName = moduleName(child)
      child.saveSpec = computeVersionSpec(tree, child)
      if (saveToDependencies) {
        tree.package[getSaveType(tree, child)][childName] = child.saveSpec
      }
      if (getSaveType(tree, child) === 'optionalDependencies') {
        tree.package.dependencies[childName] = child.saveSpec
      }
      child.userRequired = true
      child.save = saveToDependencies

      // For things the user asked to install, that aren't a dependency (or
      // won't be when we're done), flag it as "depending" on the user
      // themselves, so we don't remove it as a dep that no longer exists
      var childIsDep = addRequiredDep(tree, child)
      if (!childIsDep) child.userRequired = true
      depLoaded(null, child, tracker)
    }))
  }, andForEachChild(loadDeps, andFinishTracker(log, next)))
 actions[actionName] = limit(function (staging, pkg, log, next) {
 // top, buildpath, pkg, log
   validate('SOOF', arguments)
   // refuse to run actions for failed packages
   if (pkg.failed) return next()
   if (action.rollback) {
     if (!pkg.rollback) pkg.rollback = []
     pkg.rollback.unshift(action.rollback)
   }
   if (action.commit) {
     if (!pkg.commit) pkg.commit = []
     pkg.commit.push(action.commit)
   }
   if (pkg.knownInstallable) {
     return thenRunAction()
   } else {
     return isInstallable(pkg.package, iferr(andDone(next), andMarkInstallable(thenRunAction)))
   }
   function andMarkInstallable (cb) {
     return function () {
       pkg.knownInstallable = true
       cb()
     }
   }
   function thenRunAction () {
     action(staging, pkg, log, andDone(next))
   }
   function andDone (cb) {
     return andFinishTracker(log, andAddParentToErrors(pkg.parent, andHandleOptionalDepErrors(pkg, cb)))
   }
 }, npm.limit.action)
Example #14
0
    function pickVersionFromRegistryDocument (pkg) {
      if (!regCache[url]) regCache[url] = pkg
      var versions = Object.keys(pkg.versions)

      var invalidVersions = versions.filter(function (v) { return !semver.valid(v) })
      if (invalidVersions.length > 0) {
        log.warn('pickVersion', 'The package %s has invalid semver-version(s): %s. This usually only happens for unofficial private registries. ' +
            'You should delete or re-publish the invalid versions.', pkg.name, invalidVersions.join(', '))
      }

      versions = versions.filter(function (v) { return semver.valid(v) }).sort(semver.rcompare)

      if (dep.type === 'tag') {
        var tagVersion = pkg['dist-tags'][dep.spec]
        if (pkg.versions[tagVersion]) return returnAndAddMetadata(pkg.versions[tagVersion])
      } else {
        var latestVersion = pkg['dist-tags'][npm.config.get('tag')] || versions[0]

        // Find the the most recent version less than or equal
        // to latestVersion that satisfies our spec
        for (var ii = 0; ii < versions.length; ++ii) {
          if (semver.gt(versions[ii], latestVersion)) continue
          if (semver.satisfies(versions[ii], dep.spec)) {
            return returnAndAddMetadata(pkg.versions[versions[ii]])
          }
        }

        // Failing that, try finding the most recent version that matches
        // our spec
        for (var jj = 0; jj < versions.length; ++jj) {
          if (semver.satisfies(versions[jj], dep.spec)) {
            return returnAndAddMetadata(pkg.versions[versions[jj]])
          }
        }

        // Failing THAT, if the range was '*' uses latestVersion
        if (dep.spec === '*') {
          return returnAndAddMetadata(pkg.versions[latestVersion])
        }
      }

      // We didn't manage to find a compatible version
      // If this package was requested from cache, force hitting the network
      if (pkg._cached) {
        log.silly('fetchNamedPackageData', 'No valid target from cache, forcing network')
        return npm.registry.get(url, {
          auth: auth,
          skipCache: true
        }, pulseTillDone('fetchMetadata', iferr(next, pickVersionFromRegistryDocument)))
      }

      // And failing that, we error out
      var targets = versions.length
                  ? 'Valid install targets:\n' + versions.join(', ') + '\n'
                  : 'No valid targets found.'
      var er = new Error('No compatible version found: ' +
                         dep.raw + '\n' + targets)
      er.code = 'ETARGET'
      return next(er)
    }
Example #15
0
  ], function (er, results) {
    if (er) {
      if (er.code === 'ENOENT') return cb()
      return cb(er)
    }
    var parentInfo = {
      path: parent,
      managed: results[0]
    }
    var targetInfo = {
      path: targetPath,
      symlink: results[1],
      managed: results[2],
      inParent: results[3]
    }

    isSafeToRm(parentInfo, targetInfo, iferr(cb, thenRemove))

    function thenRemove (toRemove, removeBase) {
      if (!toRemove) return cb()
      if (removeBase) options.base = removeBase
      log.verbose('gentlyRm', options.purge ? 'Purging' : 'Vacuuming',
        toRemove, 'up to', options.base)
      return vacuum(toRemove, options, cb)
    }
  })
Example #16
0
Installer.prototype.loadArgMetadata = function (next) {
  getAllMetadata(this.args, this.currentTree, process.cwd(), iferr(next, (args) => {
    this.args = args
    if (args.length) this.fakeChildren = false
    next()
  }))
}
Example #17
0
function stageBundledModule (bundler, child, staging, parentPath, next) {
  var stageFrom = path.join(parentPath, 'node_modules', child.package.name)
  var stageTo = buildPath(staging, child)

  asyncMap(child.children, andStageBundledModule(bundler, staging, stageFrom), iferr(next, moveModule))

  function moveModule () {
    if (child.fromBundle) {
      return rename(stageFrom, stageTo, iferr(next, updateMovedPackageJson))
    } else {
      return fs.stat(stageFrom, function (notExists, exists) {
        if (exists) {
          warn(bundler, 'EBUNDLEOVERRIDE', 'In ' + packageId(bundler) +
            ' replacing bundled version of ' + moduleName(child) +
            ' with ' + packageId(child))
          return gentlyRm(stageFrom, next)
        } else {
          return next()
        }
      })
    }
  }

  function updateMovedPackageJson () {
    updatePackageJson(child, stageTo, next)
  }
}
Example #18
0
  asyncMap(args, function (pkg, done) {
    var depLoaded = andAddParentToErrors(tree, done)
    resolveWithNewModule(pkg, tree, log.newGroup('loadRequestedDeps'), iferr(depLoaded, function (child, tracker) {
      validate('OO', arguments)
      if (npm.config.get('global')) {
        child.isGlobal = true
      }
      var childName = moduleName(child)
      if (saveToDependencies) {
        tree.package[saveToDependencies][childName] =
          child.package._requested.rawSpec || child.package._requested.spec
      }
      if (saveToDependencies && saveToDependencies !== 'devDependencies') {
        tree.package.dependencies[childName] =
          child.package._requested.rawSpec || child.package._requested.spec
      }
      child.directlyRequested = true
      child.save = saveToDependencies

      // For things the user asked to install, that aren't a dependency (or
      // won't be when we're done), flag it as "depending" on the user
      // themselves, so we don't remove it as a dep that no longer exists
      if (!addRequiredDep(tree, child)) {
        replaceModuleName(child.package, '_requiredBy', '#USER')
        child.directlyRequested = true
      }
      depLoaded(null, child, tracker)
    }))
  }, andForEachChild(loadDeps, andFinishTracker(log, next)))
Example #19
0
 childDependencySpecifier(tree, name, versionSpec, iferr(done, function (req) {
   var child = findRequirement(tree, name, req)
   if (child) {
     resolveWithExistingModule(child, tree, log, iferr(next, function (child, log) {
       if (child.package._shrinkwrap === undefined) {
         readShrinkwrap.andInflate(child, function (er) { next(er, child, log) })
       } else {
         next(null, child, log)
       }
     }))
   } else {
     fetchPackageMetadata(req, packageRelativePath(tree), {tracker: log.newItem('fetchMetadata')}, iferr(next, function (pkg) {
       resolveWithNewModule(pkg, tree, log, next)
     }))
   }
 }))
Example #20
0
function fetchNamedPackageData (dep, next) {
  validate('OF', arguments)
  log.silly('fetchNamedPackageData', dep.name || dep.rawSpec)
  mapToRegistry(dep.name || dep.rawSpec, npm.config, iferr(next, function (url, auth) {
    if (regCache[url]) {
      pickVersionFromRegistryDocument(clone(regCache[url]))
    } else {
      npm.registry.get(url, {auth: auth}, pulseTillDone('fetchMetadata', iferr(next, pickVersionFromRegistryDocument)))
    }
    function returnAndAddMetadata (pkg) {
      pkg._from = dep.raw
      pkg._resolved = pkg.dist.tarball
      pkg._shasum = pkg.dist.shasum

      next(null, pkg)
    }
    function pickVersionFromRegistryDocument (pkg) {
      if (!regCache[url]) regCache[url] = pkg
      var versions = Object.keys(pkg.versions).sort(semver.rcompare)

      if (dep.type === 'tag') {
        var tagVersion = pkg['dist-tags'][dep.spec]
        if (pkg.versions[tagVersion]) return returnAndAddMetadata(pkg.versions[tagVersion])
      } else {
        var latestVersion = pkg['dist-tags'][npm.config.get('tag')] || versions[0]

        // Find the the most recent version less than or equal
        // to latestVersion that satisfies our spec
        for (var ii = 0; ii < versions.length; ++ii) {
          if (semver.gt(versions[ii], latestVersion)) continue
          if (semver.satisfies(versions[ii], dep.spec)) {
            return returnAndAddMetadata(pkg.versions[versions[ii]])
          }
        }

        // Failing that, try finding the most recent version that matches
        // our spec
        for (var jj = 0; jj < versions.length; ++jj) {
          if (semver.satisfies(versions[jj], dep.spec)) {
            return returnAndAddMetadata(pkg.versions[versions[jj]])
          }
        }

        // Failing THAT, if the range was '*' uses latestVersion
        if (dep.spec === '*') {
          return returnAndAddMetadata(pkg.versions[latestVersion])
        }
      }

      // And failing that, we error out
      var targets = versions.length
                  ? 'Valid install targets:\n' + versions.join(', ') + '\n'
                  : 'No valid targets found.'
      var er = new Error('No compatible version found: ' +
                         dep.raw + '\n' + targets)
      return next(er)
    }
  }))
}
Example #21
0
File: save.js Project: cemoulto/npm
function savePackageJson (args, tree, next) {
  validate('AOF', arguments)
  var saveBundle = npm.config.get('save-bundle')

  // each item in the tree is a top-level thing that should be saved
  // to the package.json file.
  // The relevant tree shape is { <folder>: {what:<pkg>} }
  var saveTarget = path.resolve(tree.path, 'package.json')
  // don't use readJson, because we don't want to do all the other
  // tricky npm-specific stuff that's in there.
  fs.readFile(saveTarget, iferr(next, function (packagejson) {
    try {
      packagejson = parseJSON(packagejson)
    } catch (ex) {
      return next(ex)
    }

    // If we're saving bundled deps, normalize the key before we start
    if (saveBundle) {
      var bundle = packagejson.bundleDependencies || packagejson.bundledDependencies
      delete packagejson.bundledDependencies
      if (!Array.isArray(bundle)) bundle = []
    }

    var toSave = getThingsToSave(tree)
    var toRemove = getThingsToRemove(args, tree)
    var savingTo = {}
    toSave.forEach(function (pkg) { savingTo[pkg.save] = true })
    toRemove.forEach(function (pkg) { savingTo[pkg.save] = true })

    Object.keys(savingTo).forEach(function (save) {
      if (!packagejson[save]) packagejson[save] = {}
    })

    log.verbose('saving', toSave)
    toSave.forEach(function (pkg) {
      packagejson[pkg.save][pkg.name] = pkg.spec
      if (saveBundle) {
        var ii = bundle.indexOf(pkg.name)
        if (ii === -1) bundle.push(pkg.name)
      }
    })

    toRemove.forEach(function (pkg) {
      delete packagejson[pkg.save][pkg.name]
      if (saveBundle) {
        bundle = without(bundle, pkg.name)
      }
    })

    Object.keys(packagejson).forEach(function (key) {
      packagejson[key] = deepSortObject(packagejson[key])
    })

    var json = JSON.stringify(packagejson, null, 2) + '\n'
    writeFileAtomic(saveTarget, json, next)
  }))
}
Example #22
0
      fs.stat(to, function (er, info) {
        if (er) return fs.rename(from, to, done)

        var shortname = pathToShortname(path.relative(getTree(pkg).path, to))
        warn(pkg, 'EBUNDLEOVERRIDE', 'Replacing bundled ' + shortname + ' with new installed version')
        rimraf(to, iferr(done, function () {
          fs.rename(from, to, done)
        }))
      })
function fetchNamedPackageData (dep, next) {
  validate('OF', arguments)
  log.silly('fetchNamedPackageData', dep.name || dep.rawSpec)
  mapToRegistry(dep.name || dep.rawSpec, npm.config, iferr(next, function (url, auth) {
    if (regCache[url]) {
      pickVersionFromRegistryDocument(clone(regCache[url]))
    } else {
      npm.registry.get(url, {auth: auth}, pulseTillDone('fetchMetadata', iferr(next, pickVersionFromRegistryDocument)))
    }
    function thenAddMetadata (pkg) {
      pkg._from = dep.raw
      pkg._resolved = pkg.dist.tarball
      pkg._shasum = pkg.dist.shasum

      next(null, pkg)
    }
    function pickVersionFromRegistryDocument (pkg) {
      if (!regCache[url]) regCache[url] = pkg
      var versions = Object.keys(pkg.versions)

      var invalidVersions = versions.filter(function (v) { return !semver.valid(v) })
      if (invalidVersions.length > 0) {
        log.warn('pickVersion', 'The package %s has invalid semver-version(s): %s. This usually only happens for unofficial private registries. ' +
            'You should delete or re-publish the invalid versions.', pkg.name, invalidVersions.join(', '))
      }

      versions = versions.filter(function (v) { return semver.valid(v) })

      if (dep.type === 'tag') {
        var tagVersion = pkg['dist-tags'][dep.spec]
        if (pkg.versions[tagVersion]) return thenAddMetadata(pkg.versions[tagVersion])
      } else {
        var picked = pickManifestFromRegistryMetadata(dep.spec, npm.config.get('tag'), versions, pkg)
        if (picked) return thenAddMetadata(picked.manifest)
      }

      // We didn't manage to find a compatible version
      // If this package was requested from cache, force hitting the network
      if (pkg._cached) {
        log.silly('fetchNamedPackageData', 'No valid target from cache, forcing network')
        return npm.registry.get(url, {
          auth: auth,
          skipCache: true
        }, pulseTillDone('fetchMetadata', iferr(next, pickVersionFromRegistryDocument)))
      }

      // And failing that, we error out
      var targets = versions.length
                  ? 'Valid install targets:\n' + versions.join(', ') + '\n'
                  : 'No valid targets found.'
      var er = new Error('No compatible version found: ' +
                         dep.raw + '\n' + targets)
      er.code = 'ETARGET'
      return next(er)
    }
  }))
}
Example #24
0
function fetchOtherPackageData (spec, dep, where, next) {
  validate('SOSF', arguments)
  log.silly('fetchOtherPackageData', spec)
  cache.add(spec, null, where, false, iferr(next, function (pkg) {
    var result = clone(pkg)
    result._inCache = true
    next(null, result)
  }))
}
Example #25
0
function andStageBundledChildren (pkg, buildpath, log, next) {
  var staging = path.resolve(buildpath, '..')
  return iferr(next, function () {
    asyncMap(pkg.children, andStageBundledModule(pkg, staging, buildpath), cleanupBundled)
  })
  function cleanupBundled () {
    gentlyRm(path.join(buildpath, 'node_modules'), next)
  }
}
Example #26
0
module.exports.andInflate = function (child, next) {
  readShrinkwrap(child, iferr(next, function () {
    if (child.package._shrinkwrap) {
      return inflateShrinkwrap(child, child.package._shrinkwrap || {}, next)
    } else {
      return next()
    }
  }))
}
Example #27
0
function ls (args, silent, cb) {
  if (typeof cb !== 'function') {
    cb = silent
    silent = false
  }
  var dir = path.resolve(npm.dir, '..')
  readPackageTree(dir, andRecalculateMetadata(iferr(cb, function (physicalTree) {
    lsFromTree(dir, physicalTree, args, silent, cb)
  })))
}
Example #28
0
 mkdirp(self.where, iferr(cb, function () {
   var pkgs = {}
   self.args.forEach(function (pkg) {
     pkgs[pkg.name] = true
   })
   readPackageTree(self.where, function (ctx, kid) { return ctx.parent || pkgs[kid] }, iferr(cb, function (currentTree) {
     self.currentTree = currentTree
     return cb()
   }))
 }))
Example #29
0
 function moveModule () {
   if (child.fromBundle) {
     return rename(stageFrom, stageTo, iferr(next, updateMovedPackageJson))
   } else {
     warn(bundler, 'EBUNDLEOVERRIDE', 'In ' + packageId(bundler) +
       ' replacing bundled version of ' + moduleName(child) +
       ' with ' + packageId(child))
     return gentlyRm(stageFrom, next)
   }
 }
Example #30
0
 lifecycle(tree.package, 'preshrinkwrap', tree.path, function () {
   const pkginfo = treeToShrinkwrap(tree)
   chain([
     [lifecycle, tree.package, 'shrinkwrap', tree.path],
     [shrinkwrap_, tree.path, pkginfo, opts],
     [lifecycle, tree.package, 'postshrinkwrap', tree.path]
   ], iferr(cb, function (data) {
     cb(null, pkginfo)
   }))
 })