2020-03-07 11:45:40 +08:00
|
|
|
'use strict';
|
2020-03-31 20:40:00 +08:00
|
|
|
const path = require('path');
|
2020-03-07 11:45:40 +08:00
|
|
|
const findUp = require('find-up');
|
|
|
|
const readPkg = require('read-pkg');
|
|
|
|
|
2020-03-31 20:40:00 +08:00
|
|
|
module.exports = async options => {
|
|
|
|
const filePath = await findUp('package.json', options);
|
2020-03-07 11:45:40 +08:00
|
|
|
|
2020-03-31 20:40:00 +08:00
|
|
|
if (!filePath) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
packageJson: await readPkg({...options, cwd: path.dirname(filePath)}),
|
|
|
|
path: filePath
|
|
|
|
};
|
2020-03-07 11:45:40 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
module.exports.sync = options => {
|
2020-03-31 20:40:00 +08:00
|
|
|
const filePath = findUp.sync('package.json', options);
|
2020-03-07 11:45:40 +08:00
|
|
|
|
2020-03-31 20:40:00 +08:00
|
|
|
if (!filePath) {
|
|
|
|
return;
|
2020-03-07 11:45:40 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
2020-03-31 20:40:00 +08:00
|
|
|
packageJson: readPkg.sync({...options, cwd: path.dirname(filePath)}),
|
|
|
|
path: filePath
|
2020-03-07 11:45:40 +08:00
|
|
|
};
|
|
|
|
};
|