index.js 432 B

1234567891011121314151617181920212223242526
  1. 'use strict';
  2. const findUp = require('find-up');
  3. const readPkg = require('read-pkg');
  4. module.exports = opts => {
  5. return findUp('package.json', opts).then(fp => {
  6. if (!fp) {
  7. return {};
  8. }
  9. return readPkg(fp, opts).then(pkg => ({pkg, path: fp}));
  10. });
  11. };
  12. module.exports.sync = opts => {
  13. const fp = findUp.sync('package.json', opts);
  14. if (!fp) {
  15. return {};
  16. }
  17. return {
  18. pkg: readPkg.sync(fp, opts),
  19. path: fp
  20. };
  21. };