index.js 581 B

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