findPackage = async (readDescriptor, canonical, directory, name) => {
  await null;
  for (;;) {
    // eslint-disable-next-line no-await-in-loop
    const packageLocation = await canonical(
      resolveLocation(`node_modules/${name}/`, directory),
    );

    // eslint-disable-next-line no-await-in-loop
    const packageDescriptor = await readDescriptor(packageLocation);
    if (packageDescriptor !== undefined) {
      return { packageLocation, packageDescriptor };
    }

    const parent = resolveLocation('../', directory);
    if (parent === directory) {
      return undefined;
    }
    directory = parent;

    const base = basename(directory);
    if (base === 'node_modules') {
      directory = resolveLocation('../', directory);
      if (parent === directory) {
        return undefined;
      }
      directory = parent;
    }
  }
}
`findPackage` behaves as Node.js to find third-party modules by searching
parent to ancestor directories for a `node_modules` directory that contains
the name.

Node.js does not actually require these to be packages, but in practice,
these are the locations that package managers drop a package so Node.js can
find it efficiently.

@param {ReadDescriptorFn} readDescriptor
@param {CanonicalFn} canonical
@param {string} directory
@param {string} name
@returns {Promise<PackageDetails|undefined>}