Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(themes): Handle shared parent theme with component shadowing #12883

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,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) {
Expand Down