function getPackageEntryPoint(
  context: ResolutionContext,
  packageInfo: PackageInfo,
  platform: string | null,
): string {
  const {mainFields} = context;
  const pkg = packageInfo.packageJson;

  let main = 'index';

  for (const name of mainFields) {
    // $FlowFixMe[invalid-computed-prop]
    if (typeof pkg[name] === 'string' && pkg[name].length) {
      main = pkg[name];
      break;
    }
  }

  // NOTE: Additional variants are used when checking for subpath replacements
  // against the main entry point. This inconsistent with those matched by
  // `redirectModulePath`, but we are preserving this long-standing behaviour.
  const variants = [
    main,
    main.slice(0, 2) === './' ? main.slice(2) : './' + main,
  ].flatMap(variant => [
    variant,
    variant + '.js',
    variant + '.json',
    variant.replace(/(\.js|\.json)$/, ''),
  ]);

  const replacement = matchSubpathFromMainFields(variants, pkg, mainFields);

  if (typeof replacement === 'string') {
    return replacement;
  }

  return main;
}
Resolve the main entry point subpath for a package.

Implements legacy (non-exports) package resolution behaviour based on the
["browser" field spec](https://github.com/defunctzombie/package-browser-field-spec).