pick-manifest-from-registry-metadata.js 895 B

1234567891011121314151617181920212223242526
  1. 'use strict'
  2. module.exports = pickManifestFromRegistryMetadata
  3. var log = require('npmlog')
  4. var semver = require('semver')
  5. function pickManifestFromRegistryMetadata (spec, tag, versions, metadata) {
  6. log.silly('pickManifestFromRegistryMetadata', 'spec', spec, 'tag', tag, 'versions', versions)
  7. // if the tagged version satisfies, then use that.
  8. var tagged = metadata['dist-tags'][tag]
  9. if (tagged &&
  10. metadata.versions[tagged] &&
  11. semver.satisfies(tagged, spec, true)) {
  12. return {resolvedTo: tag, manifest: metadata.versions[tagged]}
  13. }
  14. // find the max satisfying version.
  15. var ms = semver.maxSatisfying(versions, spec, true)
  16. if (ms) {
  17. return {resolvedTo: ms, manifest: metadata.versions[ms]}
  18. } else if (spec === '*' && versions.length && tagged && metadata.versions[tagged]) {
  19. return {resolvedTo: tag, manifest: metadata.versions[tagged]}
  20. } else {
  21. }
  22. }