Skip to content

Commit

Permalink
Split code out into smaller functions and add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
m-allanson committed Feb 26, 2018
1 parent 68cfa35 commit a4807ee
Show file tree
Hide file tree
Showing 10 changed files with 921 additions and 382 deletions.
19 changes: 19 additions & 0 deletions packages/gatsby/src/bootstrap/__mocks__/resolve-module-exports.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
'use strict'

let mockResults = {}

module.exports = input => {
// return a mocked result
if (typeof input === `string`) {
return mockResults[input]
}

// return default result
if (typeof input !== `object`) {
return []
}

// set mock results
mockResults = Object.assign({}, input)
return undefined
}
7 changes: 6 additions & 1 deletion packages/gatsby/src/bootstrap/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,12 @@ module.exports = async (args: BootstrapArgs) => {
// Find plugins which implement gatsby-browser and gatsby-ssr and write
// out api-runners for them.
const hasAPIFile = (env, plugin) => {
if (plugin[`${env}APIs`].length > 0 ) {
// The plugin loader has disabled SSR APIs for this plugin. Usually due to
// multiple implementations of an API that can only be implemented once
if (env === `ssr` && plugin.skipSSR === true) return undefined

const envAPIs = plugin[`${env}APIs`]
if (envAPIs && Array.isArray(envAPIs) && envAPIs.length > 0 ) {
return path.join(plugin.resolve, `gatsby-${env}.js`)
}
return undefined
Expand Down
Loading

0 comments on commit a4807ee

Please sign in to comment.