How to use the pkginfo.read function in pkginfo

To help you get started, we’ve selected a few pkginfo examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github mwolson / jest-webpack-alias / lib / webpackInfo.js View on Github external
function read(pmodule, dir) {
  var packageJson = pkginfo.read(pmodule, dir);
  var pkgJsonFile = packageJson.dir; // misleading name from pkginfo library
  var pkgJsonDir = path.dirname(pkgJsonFile);

  var profile = _.get(packageJson['package'], 'jest-webpack-alias.profile');
  var configFile = _.get(packageJson['package'], 'jest-webpack-alias.configFile', 'webpack.config.js');
  var webpackFile = path.join(pkgJsonDir, configFile);
  var webpackSettings = extractES6DefaultExportsObject(require(webpackFile));

  if (profile) {
    if (!_.isArray(webpackSettings)) {
      throw new Error(genProfileError(profile, webpackFile + ' does not export an array'));
    }
    webpackSettings = _.find(webpackSettings, ['name', profile]);
    if (!webpackSettings) {
      throw new Error(genProfileError(profile, webpackFile + ' does not contain this profile'));
    }

pkginfo

An easy way to expose properties on a module from a package.json

MIT
Latest version published 7 years ago

Package Health Score

67 / 100
Full package analysis

Popular pkginfo functions