Created
April 22, 2019 04:46
-
-
Save rheinardkorf/7be7f54c4dcd3b6d81159424f76a30b6 to your computer and use it in GitHub Desktop.
For posterity. Manually trying to implement component shadowing with Gatsby. So glad this is backed in by default. ย ๐
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
exports.withThemePath = (relativePath, root = __dirname) => { | |
const qualifiedPath = relativePath.replace('./src', `${root}/src`); | |
let qualifiedResolvedPath = path.resolve(qualifiedPath); | |
let finalPath = qualifiedResolvedPath; | |
const theme = path.basename(root); | |
const themedPath = relativePath.replace('./src', `./src/${theme}`); | |
let themedResolvedPath = path.resolve(themedPath); | |
try { | |
require.resolve(themedResolvedPath); | |
finalPath = themedResolvedPath; | |
} catch (e) { | |
try { | |
finalPath = require.resolve(qualifiedPath); | |
} catch (e) { | |
return relativePath; | |
} | |
} | |
return finalPath; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Don't use this. I am just preserving this code to remind me that in future if I want to go on a crazy component shadowing wild goose chase, I really should just check my file names properly. So easy to miss a simple misspelled filename. Curse you plurals! ๐