index.js 401 B

1234567891011121314151617
  1. 'use strict';
  2. var path = require('path');
  3. var resolveFrom = require('resolve-from');
  4. module.exports = function (moduleId, opts) {
  5. opts = opts || {};
  6. var parts = moduleId.split(path.sep);
  7. var pkg = path.join(parts.shift(), 'package.json');
  8. var resolved = resolveFrom(opts.cwd || '.', pkg);
  9. if (!resolved) {
  10. return null;
  11. }
  12. return path.join(path.dirname(resolved), parts.join(path.sep));
  13. };