index.js 450 B

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