Skip to content

Commit

Permalink
fix(themes): Handle shared parent theme with component shadowing
Browse files Browse the repository at this point in the history
If gatsby-theme-a and gatsby-theme-b both install and use
gatsby-theme-c (as a parent theme) this would cause an error
to be raised when either sibling theme shadowed a component
from gatsby-theme-c when it should be ignored.
  • Loading branch information
johno committed Mar 26, 2019
1 parent 966145a commit 53dcbf7
Showing 1 changed file with 9 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const path = require(`path`)
const debug = require(`debug`)(`gatsby:component-shadowing`)
const fs = require(`fs`)
const _ = require(`lodash`)

module.exports = class GatsbyThemeComponentShadowingResolverPlugin {
cache = {}
Expand All @@ -14,10 +15,16 @@ module.exports = class GatsbyThemeComponentShadowingResolverPlugin {
apply(resolver) {
resolver.plugin(`relative`, (request, callback) => {
// find out which theme's src/components dir we're requiring from
const matchingThemes = this.themes.filter(name =>
const allMatchingThemes = this.themes.filter(name =>
request.path.includes(path.join(name, `src`))
)
// 0 matching themes happens a lot fo rpaths we don't want to handle

// Two sibling themes can each have the same parent theme, when
// this occurs it shouldn't cause an error because when shadowing
// because they'll typically resolve to the same module.
const matchingThemes = _.uniq(allMatchingThemes)

// 0 matching themes happens a lot for paths we don't want to handle
// > 1 matching theme means we have a path like
// `gatsby-theme-blog/src/components/gatsby-theme-something/src/components`
if (matchingThemes.length > 1) {
Expand Down

0 comments on commit 53dcbf7

Please sign in to comment.