-
Notifications
You must be signed in to change notification settings - Fork 10.3k
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
Add ability to locally define plugins #1126
Conversation
Deploy preview ready! Built with commit 9b822cb |
Deploy preview ready! Built with commit 9b822cb |
Deploy preview ready! Built with commit 9b822cb |
Couple notes:
|
I agree on your second point, but can you explain why we need a fixed convention for a plugins folder? Currently you give a relative path to the plugin in the config. I was placing mine in src/plugins for example because I still see it as part of my source. But I don't yet see a need to define this for the user. |
Hmmm I guess I like the idea of just putting the plugin names in the config not intermixing paths and names which seems confusing. I'm not 100% sure I like |
@KyleAMathews OK let's limit loading to plugins folder then. I see your points, and I don't think it can hurt really. It would make things a bit more concise and robust probably. |
@KyleAMathews I've limited the plugins to the A few things I'm not completely certain / happy about yet:
What do you think? |
What Hapi.js does is their index.js returns the plugin name usually taken straight from the package.json but not necessarily. That's one possibility. Another could be using the folder name as the plugin name if a package.json doesn't exist. But in any case, let's just leave the package.json requirement for now and get this in and discuss changing plugin requirements later.
The default site gatsby-node.js has the same problem. For that, in bootstrap.js I added some code which generates the md5 hash of the gatsby-node.js and gatsby-config.js files and kills the cache when they change. We should do the same for other local plugins.
Yeah, we haven't added yet a pattern for capturing internal errors... |
OK the way I solved it now is that package.json is required for local plugins, but it doesn't have to contain anything real. If the package file has no name, it is inferred from the directory. I used the same md5 creation function on the "site" plugin instead of setting its version to "n/a". If I understand things correctly this would make the hashing in bootstrap redundant. Let me know if you want me to remove that. While I was trying to use async functions I messed up the bootstrap a few times, leading to vague graphql errors or an empty pages store. I added some checks to give clearer error messages. |
Looks like snapshots need updated. |
Deploy preview failed. Built with commit 89eafc7 https://app.netlify.com/sites/image-processing/deploys/593ef432424ef22861f6c4f0 |
@KyleAMathews I updated the snapshots, and fixed a load-plugins test I had broken. I am seeing a lot of other tests failing about GraphQL like below, but I'm assuming those are unrelated. They also fail for me on the master. I switched back to Node 7 also because I couldn't get the tests to work with version 8.
|
This crops all the time and you kinda have to ignore it locally. It's kinda the same thing as the "two react" problem. GraphQL will get installed multiple times and then the identity checks it uses will fail because it's comparing an object from one install of GraphQL to a different install. Either you can go hunting for the extra package and remove it, reinstall everything from scratch, or ignore it unless you're working on graphql related code and trust the test results from TravisCI. As it is, tests are passing on TravisCI so it looks like we're good :-) |
Could you also add a bit of documentation to https://www.gatsbyjs.org/docs/plugins/ as well real quick? |
@KyleAMathews Sure, I'll write something... |
Deploy preview failed. Built with commit 9b822cb https://app.netlify.com/sites/using-glamor/deploys/593f9df3424ef24d84f6c540 |
Looks awesome! Thanks so much for taking this on! Let's get babel support for local plugins as well soon. |
Additionally I cleaned up the test plugin logic to make it more readable.