get-requested.js 635 B

123456789101112131415
  1. 'use strict'
  2. const npa = require('npm-package-arg')
  3. const moduleName = require('../utils/module-name.js')
  4. const packageRelativePath = require('./deps').packageRelativePath
  5. module.exports = function (child, reqBy) {
  6. if (!child.requiredBy.length) return
  7. if (!reqBy) reqBy = child.requiredBy[0]
  8. const deps = reqBy.package.dependencies || {}
  9. const devDeps = reqBy.package.devDependencies || {}
  10. const optDeps = reqBy.package.optionalDependencies || {}
  11. const name = moduleName(child)
  12. const spec = deps[name] || devDeps[name] || optDeps[name]
  13. const where = packageRelativePath(reqBy)
  14. return npa.resolve(name, spec, where)
  15. }