code: function resolveHasteName(
    context: HasteContext,
    moduleName: string,
    platform: string | null,
  ): Result<FileResolution, void> {
    const modulePath = context.resolveHasteModule(moduleName);
    if (modulePath != null) {
      return resolvedAs({type: 'sourceFile', filePath: modulePath});
    }
    let packageName = moduleName;
    let packageJsonPath = context.resolveHastePackage(packageName);
    while (packageJsonPath == null && packageName && packageName !== '.') {
      packageName = path.dirname(packageName);
      packageJsonPath = context.resolveHastePackage(packageName);
    }
    if (packageJsonPath == null) {
      return failedFor();
    }
    const packageDirPath = path.dirname(packageJsonPath);
    const pathInModule = moduleName.substring(packageName.length + 1);
    const potentialModulePath = path.join(packageDirPath, pathInModule);
    const result = resolveFileOrDir(context, potentialModulePath, platform);
    if (result.type === 'resolved') {
      return result;
    }
    const {candidates} = result;
    const opts = {moduleName, packageName, pathInModule, candidates};
    throw new MissingFileInHastePackageError(opts);
  }
docs: Resolve a module as a Haste module or package. For example we might try to
  resolve `Foo`, that is provided by file `/smth/Foo.js`. Or, in the case of
  a Haste package, it could be `/smth/Foo/index.js`.