aboutsummaryrefslogtreecommitdiff
path: root/node_modules/cosmiconfig/lib/loadPackageProp.js
blob: 01e759f3a75360abb9da614380a8a1a36caf691b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
'use strict';

var path = require('path');
var readFile = require('./readFile');
var parseJson = require('./parseJson');

module.exports = function (packageDir, options) {
  var packagePath = path.join(packageDir, 'package.json');

  return readFile(packagePath).then(function (content) {
    if (!content) return null;
    var parsedContent = parseJson(content, packagePath);
    var packagePropValue = parsedContent[options.packageProp];
    if (!packagePropValue) return null;

    return {
      config: packagePropValue,
      filepath: packagePath,
    };
  });
};