async function mergePlugins(config, configDir, flags) {
  const configPlugins = config.plugins || [];
  const flagPlugins = flags?.plugins || [];
  const pluginNames = new Set([...configPlugins, ...flagPlugins]);

  for (const pluginName of pluginNames) {
    validation.assertValidPluginName(config, pluginName);

    // In bundled contexts, `resolveModulePath` will fail, so use the raw pluginName directly.
    const pluginPath = isBundledEnvironment() ?
        pluginName :
        resolveModulePath(pluginName, configDir, 'plugin');
    const rawPluginJson = await requireWrapper(pluginPath);
    const pluginJson = ConfigPlugin.parsePlugin(rawPluginJson, pluginName);

    config = mergeConfigFragment(config, pluginJson);
  }

  return config;
}
@param {LH.Config} config
@param {string | undefined} configDir
@param {{plugins?: string[]} | undefined} flags
@return {Promise<LH.Config>}