UNPKG

748 BJavaScriptView Raw
1'use strict';
2var resolvePkg = require('./resolve-pkg.js');
3var moduleBaseDir = require('./module-base-dir.js');
4
5/* @private
6 *
7 * given the name of a descendent module this module locates and returns its
8 * package.json. In addition, it provides the path and baseDir.
9 *
10 * @method pkg
11 * @param {String} name
12 * @param {String} dir (optional) root directory to begin resolution
13 */
14module.exports = function pkg(name, dir) {
15 if (name !== './') { name += '/'; }
16
17 var modulePath = resolvePkg(name, dir);
18 if (modulePath === null) { return null; }
19
20 var baseDir = moduleBaseDir(modulePath, name);
21 var thePackage = require(baseDir + '/package.json');
22
23 thePackage.path = modulePath;
24 thePackage.baseDir = baseDir;
25
26 return thePackage;
27};