From 129775eed00dcffdc5c025d6ac51d3d834c072d6 Mon Sep 17 00:00:00 2001 From: John Otander Date: Tue, 26 Mar 2019 13:53:34 -0600 Subject: [PATCH] fix(themes): Handle shared parent theme with component shadowing 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. --- .../webpack-theme-component-shadowing/index.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/packages/gatsby/src/internal-plugins/webpack-theme-component-shadowing/index.js b/packages/gatsby/src/internal-plugins/webpack-theme-component-shadowing/index.js index 3cebf97539bcf..0af131788065f 100644 --- a/packages/gatsby/src/internal-plugins/webpack-theme-component-shadowing/index.js +++ b/packages/gatsby/src/internal-plugins/webpack-theme-component-shadowing/index.js @@ -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 = {} @@ -14,10 +15,15 @@ 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 + + // The same theme can be included twice in the themes list causing multiple + // matches. This case should only be counted as a single match for that theme. + 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) {