question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Remove specialness of sub-plugins

See original GitHub issue

Summary

Make it so that the plugins config key in plugin options is not the only key that allows running gatsby-* in sub-plugins.

module.exports = {
  plugins: [{
    resolve: `some-plugin`,
    options: {
      // we're talking about this plugins key, not the top-level one above
      plugins: [...]
    }
  }]
}

Motivation

Continuation of: https://github.com/gatsbyjs/gatsby/issues/15486#issuecomment-515276649

Basically, sub-plugins are special in Gatsby, as seen below in load-plugins:

// Create a "flattened" array of plugins with all subplugins
// brought to the top-level. This simplifies running gatsby-* files
// for subplugins.
const flattenPlugins = plugins => {
  const flattened = []
  const extractPlugins = plugin => {
    plugin.pluginOptions.plugins.forEach(subPlugin => {
      flattened.push(subPlugin)
      extractPlugins(subPlugin)
    })
  }

  plugins.forEach(plugin => {
    flattened.push(plugin)
    extractPlugins(plugin)
  })

  return flattened
}

This presents a problem for plugins such as gatsby-plugin-mdx, which tries to support the existing ecosystem of gatsby-remark-plugins by using a gatsbyRemarkPlugins config key:

// gatsby-config
{
  resolve: `gatsby-plugin-mdx`,
  options: {
    gatsbyRemarkPlugins: [{
      resolve: `gatsby-remark-images`,
      options: {
        // It's important to specify the maxWidth (in pixels) of
        // the content container as this plugin uses this as the
        // base for generating different widths of each image.
        maxWidth: 590,
      },
    }]
  }
}

This is important because gatsby-plugin-mdx strives to make converting from remark as painless as possible and gatsbyRemarkPlugins isn’t handled the same way as plugins, making it a second-class experience that results in bugs.

gatsby-plugin-mdx also supports passthrough of @mdx-js/mdx core options which includes two plugin types: remarkPlugins and rehypePlugins. Looking forward to the future, I’d love to use this as a place to gradually evolve an API to unify the rehype, remark, and gatsby plugins ecosystems under the same plugin API. This would greatly reduce the complexity of gatsby-remark plugin support in gatsby-plugin-mdx and (hopefully) make it easier to work with the existing ecosystem of remark plugins and “enhanced” gatsby-remark plugins in the gatsby-remark sub-ecosystem. The issue here is required for that future work to be successful.

So, being an edge case, gatsby-plugin-mdx has 4 config keys where it makes sense to “activate” as gatsby plugins. Other plugins may have a more reasonable two config keys.

Basic example

User-side, code doesn’t change. The original bug described above would be fixed.

Internally, I’d imagine the change (conceptually) looks something like this, where plugins can define their own list of sub-keys that would be required into the plugins list for this. (I don’t know how we would do this automatically without additional config, so if someone knows that’d be cooool).

const extractPlugins = plugin => {
+  const { subPluginKeys } = require(plugin)
+  for (const plugins in subPluginKeys) {
      plugins.forEach(subPlugin => {
        flattened.push(subPlugin)
        extractPlugins(subPlugin)
    })
  }
}

cc/ @sidharthachatterjee @KyleAMathews who I’ve talked this through with a bit

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:2
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

11reactions
ChristopherBiscardicommented, Oct 10, 2019

going to make this change in gatsby-config itself which will be a simpler implementation. adding gatsbyRemarkPlugins to root plugins array by default.

3reactions
rheinardkorfcommented, Sep 10, 2019

Ping! Keeping this non-stale as its still an issue.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Special Characters Remove - Plugins - WordPress.org
This plugin allows you to remove all special characters from WordPress attachments without modifying the code and it works with most of the...
Read more >
How to remove characters from SpecialChar plugin in CKEditor?
I'm trying to remove few special characters from specialchar plugin ... file in plugins/specialchar/dialogs/lang/de.js and removed — and Ñ, ...
Read more >
Remove Special Characters on Upload plugin for Wordpress
Remove Special Characters on Upload for Wordpress ... App Details. A plugin that will help you remove special characters from the name of...
Read more >
Remove Special Characters on Upload 1.0.0 - PluginTests.com
Does "Remove Special Characters on Upload" work with WordPress 5.0.3 and PHP 7.0.16? A smoke test was performed on 2019-01-27 05:52:35 UTC ....
Read more >
Removing Special Characters from a string - BMC Communities
I have a 4k character field where we need to remove special characters. I have the following set of filters and filter guide....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found