| 1234567891011121314151617181920212223242526272829303132 |
- //
- 'use strict';
- const path = require('path');
- const readFile = require('./readFile');
- const parseJson = require('./parseJson');
- module.exports = function loadPackageProp(
- packageDir ,
- options
-
-
-
- ) {
- const packagePath = path.join(packageDir, 'package.json');
- function parseContent(content ) {
- if (!content) return null;
- const parsedContent = parseJson(content, packagePath);
- const packagePropValue = parsedContent[options.packageProp];
- if (!packagePropValue) return null;
- return {
- config: packagePropValue,
- filepath: packagePath,
- };
- }
- return !options.sync
- ? readFile(packagePath).then(parseContent)
- : parseContent(readFile.sync(packagePath));
- };
|