lib/version.js
function findPackage(directory) {
  const file = path.resolve(directory, 'package.json')
  if (fs.existsSync(file) && fs.statSync(file).isFile()) {
    return require(file)
  }

  const parent = path.resolve(directory, '..')
  return parent === directory ? null : findPackage(parent)
}
function findPackage(directory) {
  const file = path.resolve(directory, 'package.json')
  if (fs.existsSync(file) && fs.statSync(file).isFile()) {
    return require(file)
  }

  const parent = path.resolve(directory, '..')
  return parent === directory ? null : findPackage(parent)
}
Retrieves the main module package.json information.

@param {string} directory
The directory to start looking in.

@return {Object|null}
An object containing the package.json contents or NULL if it could not be found.