Skip to content

Instantly share code, notes, and snippets.

@rheinardkorf
Created April 22, 2019 04:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rheinardkorf/7be7f54c4dcd3b6d81159424f76a30b6 to your computer and use it in GitHub Desktop.
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. ย ๐Ÿ˜…
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;
};
@rheinardkorf
Copy link
Author

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! ๐Ÿ˜‚

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment