code: 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
    };
  }
docs: Get closest package definition from path