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 plugin loader checks #4023

Merged
merged 2 commits into from
Feb 13, 2018
Merged
Show file tree
Hide file tree
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
27 changes: 17 additions & 10 deletions packages/gatsby/src/bootstrap/load-plugins.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ const glob = require(`glob`)

const { store } = require(`../redux`)
const nodeAPIs = require(`../utils/api-node-docs`)
const browserAPIs = require(`../utils/api-browser-docs`)
const ssrAPIs = require(`../../cache-dir/api-ssr-docs`)
const testRequireError = require(`../utils/test-require-error`)
const report = require(`gatsby-cli/lib/reporter`)

Expand Down Expand Up @@ -270,13 +272,18 @@ module.exports = async (config = {}) => {
// APIs that a plugin supports are saved along with the plugin in the store for
// easier filtering later. If there are bad exports (either typos, outdated, or
// plain incorrect), then we output a readable error & quit.
const apis = _.keys(nodeAPIs)
const apiToPlugins = apis.reduce((acc, value) => {
const apis = {}
apis.node = _.keys(nodeAPIs)
apis.browser = _.keys(browserAPIs)
apis.ssr = _.keys(ssrAPIs)

const allAPIs = [...apis.node, ...apis.browser, ...apis.ssr]

const apiToPlugins = allAPIs.reduce((acc, value) => {
acc[value] = []
return acc
}, {})


const badExports = {
node: [],
browser: [],
Expand All @@ -297,23 +304,23 @@ module.exports = async (config = {}) => {
// later.
if (gatsbyNode) {
const gatsbyNodeKeys = _.keys(gatsbyNode)
plugin.nodeAPIs = _.intersection(gatsbyNodeKeys, apis)
plugin.nodeAPIs = _.intersection(gatsbyNodeKeys, apis.node)
plugin.nodeAPIs.map(nodeAPI => apiToPlugins[nodeAPI].push(plugin.name))
badExports.node = getBadExports(plugin, gatsbyNodeKeys, apis) // Collate any bad exports
badExports.node = getBadExports(plugin, gatsbyNodeKeys, apis.node) // Collate any bad exports
}

if (gatsbyBrowser) {
const gatsbyBrowserKeys = _.keys(gatsbyBrowser)
plugin.browserAPIs = _.intersection(gatsbyBrowserKeys, apis)
plugin.browserAPIs = _.intersection(gatsbyBrowserKeys, apis.browser)
plugin.browserAPIs.map(browserAPI => apiToPlugins[browserAPI].push(plugin.name))
badExports.browser = getBadExports(plugin, gatsbyBrowserKeys, apis) // Collate any bad exports
badExports.browser = getBadExports(plugin, gatsbyBrowserKeys, apis.browser) // Collate any bad exports
}

if (gatsbySSR) {
const gatsbySSRKeys = _.keys(gatsbySSR)
plugin.ssrAPIs = _.intersection(gatsbySSRKeys, apis)
plugin.ssrAPIs = _.intersection(gatsbySSRKeys, apis.ssr)
plugin.ssrAPIs.map(ssrAPI => apiToPlugins[ssrAPI].push(plugin.name))
badExports.ssr = getBadExports(plugin, gatsbySSRKeys, apis) // Collate any bad exports
badExports.ssr = getBadExports(plugin, gatsbySSRKeys, apis.ssr) // Collate any bad exports
}
})

Expand All @@ -323,7 +330,7 @@ module.exports = async (config = {}) => {
const [exportType, entries] = bad
if (entries.length > 0) {
bad = true
console.log(getBadExportsMessage(entries, exportType, apis))
console.log(getBadExportsMessage(entries, exportType, apis[exportType]))
}
})

Expand Down
7 changes: 7 additions & 0 deletions packages/gatsby/src/utils/api-browser-docs.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,13 @@ exports.onRouteUpdate = true
*/
exports.shouldUpdateScroll = true

/**
* Allow a plugin to register a Service Worker. Should be a function that returns true.
* @example
* exports.registerServiceWorker = () => true
*/
exports.registerServiceWorker = true

/**
* Allow a plugin to replace the router component e.g. to use a custom history version.
* @param {object} $0
Expand Down