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