inspectModuleRecords = (
  moduleRecords,
  { debug = false, log = defaultLog, trustRoot = true } = {}
) => {
  const inspector = createModuleInspector({
    isBuiltin: defaultIsBuiltin,
    includeDebugInfo: debug,
    trustRoot,
  })

  /** @type {Map<string, string[]>} */
  const perPackageWarnings = new Map()

  inspector.on('compat-warning', (data) => {
    const { moduleRecord, compatWarnings } = /**
     * @type {{
     *   moduleRecord: LavamoatModuleRecord
     *   compatWarnings: SesCompat
     * }}
     */ (data)

    const { primordialMutations, strictModeViolations, dynamicRequires } =
      compatWarnings
    const nicePath = hrPath(moduleRecord.file)

    /** @type {string[]} */
    const warnings = perPackageWarnings.get(moduleRecord.packageName) || []

    /**
     * Adds SES compat issues to {@link warnings}
     *
     * @param {SesCompatObj[]} sesCompatObjs
     * @param {string} type
     */
    const addWarnings = (sesCompatObjs, type) => {
      if (sesCompatObjs.length) {
        warnings.push(
          ...sesCompatObjs.map(
            ({
              node: {
                loc: {
                  start: { line, column },
                },
              },
            }) => {
              const plainPath = stripVTControlCharacters(nicePath)
              return `- ${chalk.yellowBright([plainPath, line, column].join(chalk.yellow(':')))} ${chalk.cyan(`(${type})`)}`
            }
          )
        )
      }
    }

    addWarnings(primordialMutations, 'primordial mutation')
    addWarnings(strictModeViolations, 'strict-mode violation')
    addWarnings(dynamicRequires, 'dynamic require')

    /* c8 ignore next */
    if (!warnings.length) {
      // unlikely, but just in case
      log.warning(
        'empty "compat-warning" event received from module inspector; this is a bug'
      )
      return
    }

    perPackageWarnings.set(moduleRecord.packageName, warnings)
  })

  for (const record of moduleRecords) {
    inspector.inspectModule(record)
  }

  if (perPackageWarnings.size) {
    for (const [packageName, warnings] of perPackageWarnings) {
      log.warning(
        `Package ${hrLabel(packageName)} contains potential SES incompatibilities at the following locations:\n${warnings.join('\n')}`
      )
    }
  }

  return inspector
}
Uses `inspector` to inspect a compartment map and sources.

If the `debug` option is `true`, the inspector will include debug
information.

@param {LavamoatModuleRecord[]} moduleRecords Module records
@param {InspectModuleRecordsOptions} [options] Options
@returns {ModuleInspector} The inspector