Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -2,41 +2,6 @@

exports[`collatePluginAPIs Identifies APIs used by a site's plugins 1`] = `
Object {
"apiToPlugins": Object {
"browser-1": Array [
"foo-plugin",
],
"browser-2": Array [
"foo-plugin",
"default-site-plugin",
],
"browser-3": Array [
"default-site-plugin",
],
"browser-4": Array [],
"node-1": Array [
"foo-plugin",
],
"node-2": Array [
"foo-plugin",
"default-site-plugin",
],
"node-3": Array [
"default-site-plugin",
],
"node-4": Array [],
"ssr-1": Array [
"foo-plugin",
],
"ssr-2": Array [
"foo-plugin",
"default-site-plugin",
],
"ssr-3": Array [
"default-site-plugin",
],
"ssr-4": Array [],
},
"badExports": Object {
"browser": Array [],
"node": Array [],
Expand Down Expand Up @@ -91,32 +56,6 @@ Object {

exports[`collatePluginAPIs Identifies incorrect APIs used by a site's plugins 1`] = `
Object {
"apiToPlugins": Object {
"browser-1": Array [
"foo-plugin",
],
"browser-2": Array [
"foo-plugin",
],
"browser-3": Array [],
"browser-4": Array [],
"node-1": Array [
"foo-plugin",
],
"node-2": Array [
"foo-plugin",
],
"node-3": Array [],
"node-4": Array [],
"ssr-1": Array [
"foo-plugin",
],
"ssr-2": Array [
"foo-plugin",
],
"ssr-3": Array [],
"ssr-4": Array [],
},
"badExports": Object {
"browser": Array [
Object {
Expand Down
10 changes: 0 additions & 10 deletions packages/gatsby/src/bootstrap/load-plugins/__tests__/validate.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,6 @@ describe(`handleBadExports`, () => {

describe(`handleMultipleReplaceRenderers`, () => {
it(`Does nothing when replaceRenderers is implemented once`, async () => {
const apiToPlugins = {
replaceRenderer: [`foo-plugin`],
}

const flattenedPlugins = [
{
resolve: `___TEST___`,
Expand All @@ -156,18 +152,13 @@ describe(`handleMultipleReplaceRenderers`, () => {
]

const result = handleMultipleReplaceRenderers({
apiToPlugins,
flattenedPlugins,
})

expect(result).toMatchSnapshot()
})

it(`Sets skipSSR when replaceRenderers is implemented more than once`, async () => {
const apiToPlugins = {
replaceRenderer: [`foo-plugin`, `default-site-plugin`],
}

const flattenedPlugins = [
{
resolve: `___TEST___`,
Expand All @@ -192,7 +183,6 @@ describe(`handleMultipleReplaceRenderers`, () => {
]

const result = handleMultipleReplaceRenderers({
apiToPlugins,
flattenedPlugins,
})

Expand Down
13 changes: 0 additions & 13 deletions packages/gatsby/src/bootstrap/load-plugins/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,13 @@ module.exports = async (config = {}, rootDir = null) => {
// valid Gatsby APIs, aka 'badExports'
const x = collatePluginAPIs({ apis, flattenedPlugins })
flattenedPlugins = x.flattenedPlugins
const apiToPlugins = x.apiToPlugins
const badExports = x.badExports

// Show errors for any non-Gatsby APIs exported from plugins
handleBadExports({ apis, badExports })

// Show errors when ReplaceRenderer has been implemented multiple times
flattenedPlugins = handleMultipleReplaceRenderers({
apiToPlugins,
flattenedPlugins,
})

Expand All @@ -66,16 +64,5 @@ module.exports = async (config = {}, rootDir = null) => {
payload: flattenedPlugins,
})

store.dispatch({
type: `SET_SITE_API_TO_PLUGINS`,
payload: apiToPlugins,
})

// TODO: Is this used? plugins and flattenedPlugins may be out of sync
store.dispatch({
type: `SET_SITE_PLUGINS`,
payload: plugins,
})

return flattenedPlugins
}
22 changes: 6 additions & 16 deletions packages/gatsby/src/bootstrap/load-plugins/validate.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,6 @@ const handleBadExports = ({ apis, badExports }) => {
* Identify which APIs each plugin exports
*/
const collatePluginAPIs = ({ apis, flattenedPlugins }) => {
const allAPIs = [...apis.node, ...apis.browser, ...apis.ssr]
const apiToPlugins = allAPIs.reduce((acc, value) => {
acc[value] = []
return acc
}, {})

// Get a list of bad exports
const badExports = {
node: [],
Expand Down Expand Up @@ -137,39 +131,35 @@ const collatePluginAPIs = ({ apis, flattenedPlugins }) => {

if (pluginNodeExports.length > 0) {
plugin.nodeAPIs = _.intersection(pluginNodeExports, apis.node)
plugin.nodeAPIs.map(nodeAPI => apiToPlugins[nodeAPI].push(plugin.name))
badExports.node = badExports.node.concat(
getBadExports(plugin, pluginNodeExports, apis.node)
) // Collate any bad exports
}

if (pluginBrowserExports.length > 0) {
plugin.browserAPIs = _.intersection(pluginBrowserExports, apis.browser)
plugin.browserAPIs.map(browserAPI =>
apiToPlugins[browserAPI].push(plugin.name)
)
badExports.browser = badExports.browser.concat(
getBadExports(plugin, pluginBrowserExports, apis.browser)
) // Collate any bad exports
}

if (pluginSSRExports.length > 0) {
plugin.ssrAPIs = _.intersection(pluginSSRExports, apis.ssr)
plugin.ssrAPIs.map(ssrAPI => apiToPlugins[ssrAPI].push(plugin.name))
badExports.ssr = badExports.ssr.concat(
getBadExports(plugin, pluginSSRExports, apis.ssr)
) // Collate any bad exports
}
})

return { apiToPlugins, flattenedPlugins, badExports }
return { flattenedPlugins, badExports }
}

const handleMultipleReplaceRenderers = ({ apiToPlugins, flattenedPlugins }) => {
const handleMultipleReplaceRenderers = ({ flattenedPlugins }) => {
// multiple replaceRenderers may cause problems at build time
if (apiToPlugins.replaceRenderer.length > 1) {
const rendererPlugins = [...apiToPlugins.replaceRenderer]

const rendererPlugins = flattenedPlugins
.filter(plugin => plugin.ssrAPIs.includes(`replaceRenderer`))
.map(plugin => plugin.name)
if (rendererPlugins.length > 1) {
if (rendererPlugins.includes(`default-site-plugin`)) {
reporter.warn(`replaceRenderer API found in these plugins:`)
reporter.warn(rendererPlugins.join(`, `))
Expand Down
8 changes: 0 additions & 8 deletions packages/gatsby/src/redux/reducers/api-to-plugins.js

This file was deleted.

2 changes: 0 additions & 2 deletions packages/gatsby/src/redux/reducers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@ module.exports = {
resolvedNodesCache: require(`./resolved-nodes`),
nodesTouched: require(`./nodes-touched`),
lastAction: require(`./last-action`),
plugins: require(`./plugins`),
flattenedPlugins: require(`./flattened-plugins`),
apiToPlugins: require(`./api-to-plugins`),
config: require(`./config`),
pages: require(`./pages`),
schema: require(`./schema`),
Expand Down
8 changes: 0 additions & 8 deletions packages/gatsby/src/redux/reducers/plugins.js

This file was deleted.

30 changes: 9 additions & 21 deletions packages/gatsby/src/utils/api-runner-node.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
const Promise = require(`bluebird`)
const glob = require(`glob`)
const _ = require(`lodash`)
const chalk = require(`chalk`)

Expand Down Expand Up @@ -203,9 +202,6 @@ const runAPI = (plugin, api, args) => {
return null
}

let filteredPlugins
const hasAPIFile = plugin => glob.sync(`${plugin.resolve}/gatsby-node*`)[0]

let apisRunningById = new Map()
let apisRunningByTraceId = new Map()
let waitingForCasacadeToFinish = []
Expand All @@ -232,23 +228,15 @@ module.exports = async (api, args = {}, pluginSource) =>

const { store } = require(`../redux`)
const plugins = store.getState().flattenedPlugins
// Get the list of plugins that implement gatsby-node
if (!filteredPlugins) {
filteredPlugins = plugins.filter(plugin => hasAPIFile(plugin))
}

// Break infinite loops.
// Sometimes a plugin will implement an API and call an
// action which will trigger the same API being called.
// "onCreatePage" is the only example right now.
// In these cases, we should avoid calling the originating plugin
// again.
let noSourcePluginPlugins = filteredPlugins
if (pluginSource) {
noSourcePluginPlugins = filteredPlugins.filter(
p => p.name !== pluginSource
)
}
// Get the list of plugins that implement this API.
// Also: Break infinite loops. Sometimes a plugin will implement an API and
// call an action which will trigger the same API being called.
// `onCreatePage` is the only example right now. In these cases, we should
// avoid calling the originating plugin again.
const implementingPlugins = plugins.filter(
plugin => plugin.nodeAPIs.includes(api) && plugin.name !== pluginSource
)

const apiRunInstance = {
api,
Expand Down Expand Up @@ -313,7 +301,7 @@ module.exports = async (api, args = {}, pluginSource) =>
}
}

Promise.mapSeries(noSourcePluginPlugins, plugin => {
Promise.mapSeries(implementingPlugins, plugin => {
if (stopQueuedApiRuns) {
return null
}
Expand Down
12 changes: 8 additions & 4 deletions packages/gatsby/src/utils/source-nodes.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,14 @@ const { deleteNode } = boundActionCreators
*/
function discoverPluginsWithoutNodes(storeState) {
// Discover which plugins implement APIs which may create nodes
const nodeCreationPlugins = _.without(
_.union(storeState.apiToPlugins.sourceNodes),
`default-site-plugin`
)
const nodeCreationPlugins = storeState.flattenedPlugins
.filter(
plugin =>
plugin.nodeAPIs.includes(`sourceNodes`) &&
plugin.name !== `default-site-plugin`
)
.map(plugin => plugin.name)

// Find out which plugins own already created nodes
const nodeOwners = _.uniq(
Array.from(getNodes()).reduce((acc, node) => {
Expand Down