async function runAllowedPackages({ rootDir }) {
  const {
    configs: { lifecycle, bin },
    somePoliciesAreMissing,
  } = await loadAllPackageConfigurations({ rootDir })

  if (somePoliciesAreMissing) {
    console.log(
      '\n@lavamoat/allow-scripts has detected dependencies without configuration. explicit configuration required.'
    )
    console.log(
      'run "allow-scripts auto" to automatically populate the configuration.\n'
    )

    printMissingPoliciesIfAny(lifecycle)

    // exit with error
    process.exit(1)
  }

  if (FEATURE.bins && bin.allowConfig) {
    // Consider: Might as well delete entire .bin and recreate in case it was left there
    // install bins
    if (bin.binCandidates.size > 0) {
      console.log('installing bin scripts')
      await installBinScripts(bin.allowedBins)
      await installBinFirewall(
        bin.firewalledBins,
        path.join(__dirname, './whichbin.js')
      )
    } else {
      console.log('no bin scripts found in dependencies')
    }
  }

  // run scripts in dependencies
  if (lifecycle.allowedPatterns.length) {
    const allowedPackagesWithScriptsLifecycleScripts = Array.from(
      lifecycle.packagesWithScripts.entries()
    )
      .filter(([pattern]) => lifecycle.allowedPatterns.includes(pattern))
      .flatMap(([, packages]) => packages)

    console.log('running lifecycle scripts for event "preinstall"')
    await runAllScriptsForEvent({
      event: 'preinstall',
      packages: allowedPackagesWithScriptsLifecycleScripts,
    })
    console.log('running lifecycle scripts for event "install"')
    await runAllScriptsForEvent({
      event: 'install',
      packages: allowedPackagesWithScriptsLifecycleScripts,
    })
    console.log('running lifecycle scripts for event "postinstall"')
    await runAllScriptsForEvent({
      event: 'postinstall',
      packages: allowedPackagesWithScriptsLifecycleScripts,
    })
  } else {
    console.log('no allowed lifecycle scripts found in configuration')
  }

  // run scripts in top-level package
  console.log('running lifecycle scripts for top level package')
  await runScript({ event: 'install', path: rootDir })
  await runScript({ event: 'postinstall', path: rootDir })
  await runScript({ event: 'prepublish', path: rootDir })
  // TODO: figure out if we should be doing this:
  await runScript({ event: 'prepare', path: rootDir })
}
@param {RunAllowedPackagesParams} params
@returns {Promise<void>}