src/index.js
function getClosestPackage(modulePath) {
  let root;
  let pkg;

  // Catch findRoot or require errors
  try {
    root = findRoot(modulePath);
    pkg = require(path.join(root, "package.json"));
  } catch (e) {
    return null;
  }

  // If the package.json does not have a name property, try again from
  // one level higher.
  // https://github.com/jsdnxx/find-root/issues/2
  // https://github.com/date-fns/date-fns/issues/264#issuecomment-265128399
  if (!pkg.name) {
    return getClosestPackage(path.resolve(root, ".."));
  }

  return {
    package: pkg,
    path: root
  };
}
function getClosestPackage(modulePath) {
  let root;
  let pkg;

  // Catch findRoot or require errors
  try {
    root = findRoot(modulePath);
    pkg = require(path.join(root, "package.json"));
  } catch (e) {
    return null;
  }

  // If the package.json does not have a name property, try again from
  // one level higher.
  // https://github.com/jsdnxx/find-root/issues/2
  // https://github.com/date-fns/date-fns/issues/264#issuecomment-265128399
  if (!pkg.name) {
    return getClosestPackage(path.resolve(root, ".."));
  }

  return {
    package: pkg,
    path: root
  };
}
function getClosestPackage ( modulePath ) { let root ; let pkg ; // Catch findRoot or require errors try { root = findRoot ( modulePath ) ; pkg = require ( path . join ( root , "package.json" ) ) ; } catch ( e ) { return null ; } // If the package.json does not have a name property, try again from // one level higher. // https://github.com/jsdnxx/find-root/issues/2 // https://github.com/date-fns/date-fns/issues/264#issuecomment-265128399 if ( ! pkg . name ) { return getClosestPackage ( path . resolve ( root , ".." ) ) ; } return { package : pkg , path : root } ; }
Get closest package definition from path
Get closest package definition from path