warnAboutAnomalies = () => {
  const deferredWarnings = {
    calledOnceOnly:
      'LavaMoat: getRunModuleStatement was only called once instead of at least twice in quick succession, with react-native InitializeCore first and bundle entry second. This is suspicious. Lockdown might not be in effect.',
    neverCalledWithEntryModule:
      'LavaMoat: getRunModuleStatement was not called with moduleId 0. Lockdown was not applied.',
  }

  // Emit warnings only after Metro finishes bundling
  process.on('exit', () => {
    Object.values(deferredWarnings).forEach((message) => {
      if (message) warn(message)
    })
  })

  /**
   * Inspects the call log for anomalies.
   *
   * @param {(number | string)[]} callLog - Array of module IDs that were loaded
   * @returns {void}
   */
  return function inspectCallLog(callLog) {
    if (callLog.length > 1) {
      deferredWarnings.calledOnceOnly = false
    }

    if (callLog.includes(ENTRY_FILE_MODULE_ID)) {
      deferredWarnings.neverCalledWithEntryModule = false
    }

    if (callLog[0] === ENTRY_FILE_MODULE_ID) {
      warn(
        'LavaMoat: getRunModuleStatement was called with moduleId 0 first. That should represent the bundle entrypoint but react-native InitializeCore should run first. This is suspicious. Lockdown might not be in effect or might be breaking react-native core polyfills.'
      )
    }

    // Note: Metro loads React Native InitializeCore first, then the React Native app entry file index.js (moduleId: 0).
    // - React Native CLI calls Metro to bundle, which tends to call this sequence twice
    // - After bunding, React Native in Dev mode tends to call this sequence per hot-reload
    // - We warn rather than error on multiple calls, since this is expected behaviour
    if (new Set(callLog).size !== callLog.length) {
      warn(
        `LavaMoat: getRunModuleStatement was called with the same moduleId multiple times. It might be because some build is running twice with the same config instance. [${callLog.join(', ')}]`
      )
    }
  }
}
Creates a function to inspect for anomalies during module loading, then warns
when complete.

@returns {(callLog: (number | string)[]) => void} Function to inspect the
  call log