Repository: gatsbyjs/gatsby
File: packages/gatsby/src/bootstrap/load-plugins/load.ts (TypeScript)

Code before:

    // If the path is absolute, resolve the directory of the internal plugin,
    // otherwise resolve the directory containing the package.json
    const resolvedPath = slash(
      path.dirname(
        requireSource.resolve(
          path.isAbsolute(pluginName)
            ? pluginName
            : `${pluginName}/package.json`
        )
      )
    )

    const packageJSON = JSON.parse(
      fs.readFileSync(`${resolvedPath}/package.json`, `utf-8`)
    )
    warnOnIncompatiblePeerDependency(packageJSON.name, packageJSON)

    return {
      resolve: resolvedPath,
      id: createPluginId(packageJSON.name),
      name: packageJSON.name,
      version: packageJSON.version,
    }
  } catch (err) {
    if (process.argv.includes(`--verbose`)) {
      reporter.panicOnBuild(
        `plugin "${pluginName} threw the following error:\n`,
        err
      )
    } else {
      reporter.panicOnBuild(
        `There was a problem loading plugin "${pluginName}". Perhaps you need to install its package?\nUse --verbose to see actual error.`
      )
    }
    throw new Error(`unreachable`)
  }
}

export function loadPlugins(
  config: ISiteConfig = {},
  rootDir: string | null = null
): Array<IPluginInfo> {
  // Instantiate plugins.
  const plugins: Array<IPluginInfo> = []

  // Create fake little site with a plugin for testing this
  // w/ snapshots. Move plugin processing to its own module.
  // Also test adding to redux store.
  function processPlugin(plugin: PluginRef): IPluginInfo {
    if (_.isString(plugin)) {

Review comment (suggestion):
I think you can also check against `gatsby_log_level`: https://github.com/gatsbyjs/gatsby/blob/1baed444e5573a679fd6327741f59299e6b714bc/packages/gatsby-cli/src/create-cli.ts#L112

Code after:

    // If the path is absolute, resolve the directory of the internal plugin,
    // otherwise resolve the directory containing the package.json
    const resolvedPath = slash(
      path.dirname(
        requireSource.resolve(
          path.isAbsolute(pluginName)
            ? pluginName
            : `${pluginName}/package.json`
        )
      )
    )

    const packageJSON = JSON.parse(
      fs.readFileSync(`${resolvedPath}/package.json`, `utf-8`)
    )
    warnOnIncompatiblePeerDependency(packageJSON.name, packageJSON)

    return {
      resolve: resolvedPath,
      id: createPluginId(packageJSON.name),
      name: packageJSON.name,
      version: packageJSON.version,
    }
  } catch (err) {
    if (process.env.gatsby_log_level === `verbose`) {
      reporter.panicOnBuild(
        `plugin "${pluginName} threw the following error:\n`,
        err
      )
    } else {
      reporter.panicOnBuild(
        `There was a problem loading plugin "${pluginName}". Perhaps you need to install its package?\nUse --verbose to see actual error.`
      )
    }
    throw new Error(`unreachable`)
  }
}

export function loadPlugins(
  config: ISiteConfig = {},
  rootDir: string | null = null
): Array<IPluginInfo> {
  // Instantiate plugins.
  const plugins: Array<IPluginInfo> = []

  // Create fake little site with a plugin for testing this
  // w/ snapshots. Move plugin processing to its own module.
  // Also test adding to redux store.
  function processPlugin(plugin: PluginRef): IPluginInfo {
    if (_.isString(plugin)) {