packages/bundler/src/commands/measure.js
async function findPackageFor(filepath) {
  let directory = filepath;

  while (directory !== '/') {
    const directoryToSearch = path.dirname(directory);
    const files = await fs.readdir(directoryToSearch);

    if (files.indexOf('package.json') !== -1) {
      const packageJson = await fs.readJson(
        path.join(directoryToSearch, 'package.json')
      );
      return packageJson.name;
    }

    directory = path.resolve(directory, '..');
  }

  throw new Error(`Unable to find package for: ${filepath}`);
}
async function findPackageFor(filepath) {
  let directory = filepath;

  while (directory !== '/') {
    const directoryToSearch = path.dirname(directory);
    const files = await fs.readdir(directoryToSearch);

    if (files.indexOf('package.json') !== -1) {
      const packageJson = await fs.readJson(
        path.join(directoryToSearch, 'package.json')
      );
      return packageJson.name;
    }

    directory = path.resolve(directory, '..');
  }

  throw new Error(`Unable to find package for: ${filepath}`);
}
Rough heuristic used to find the package name for a given file. Idea is to move upwards looking for directories that have a `package.json` file. Once we find one, we report back the name from that file.