1'use strict' 2const npa = require('npm-package-arg') 3const moduleName = require('../utils/module-name.js') 4const packageRelativePath = require('./deps').packageRelativePath 5module.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} 16