Skip to content

Commit

Permalink
[v2] small refactor of api-runner-browser to fix loader test (#5343)
Browse files Browse the repository at this point in the history
* small refactor of api-runner-browser to fix tests

* remove stray '$' and unneeded eslint-disable-next-line
  • Loading branch information
pieh authored and m-allanson committed May 9, 2018
1 parent 5e520a2 commit 8ff3cfb
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 27 deletions.
14 changes: 14 additions & 0 deletions packages/gatsby/cache-dir/api-runner-browser-plugins.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// During bootstrap, we write requires at top of this file which looks
// basically like:
// module.exports = [
// {
// plugin: require("/path/to/plugin1/gatsby-browser.js"),
// options: { ... },
// },
// {
// plugin: require("/path/to/plugin2/gatsby-browser.js"),
// options: { ... },
// },
// ]

module.exports = []
15 changes: 1 addition & 14 deletions packages/gatsby/cache-dir/api-runner-browser.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,6 @@
// During bootstrap, we write requires at top of this file which looks
// basically like:
// var plugins = [
// {
// plugin: require("/path/to/plugin1/gatsby-browser.js"),
// options: { ... },
// },
// {
// plugin: require("/path/to/plugin2/gatsby-browser.js"),
// options: { ... },
// },
// ]
const plugins = require(`./api-runner-browser-plugins`)

exports.apiRunner = (api, args, defaultReturn) => {
// eslint-disable-next-line no-undef
let results = plugins.map(plugin => {
if (!plugin.plugin[api]) {
return undefined
Expand All @@ -34,7 +22,6 @@ exports.apiRunner = (api, args, defaultReturn) => {
}

exports.apiRunnerAsync = (api, args, defaultReturn) =>
// eslint-disable-next-line no-undef
plugins.reduce(
(previous, next) =>
next.plugin[api]
Expand Down
15 changes: 2 additions & 13 deletions packages/gatsby/src/bootstrap/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -208,17 +208,6 @@ module.exports = async (args: BootstrapArgs) => {
plugin => plugin.resolve
)

let browserAPIRunner = ``

try {
browserAPIRunner = fs.readFileSync(
`${siteDir}/api-runner-browser.js`,
`utf-8`
)
} catch (err) {
report.panic(`Failed to read ${siteDir}/api-runner-browser.js`, err)
}

const browserPluginsRequires = browserPlugins
.map(
plugin =>
Expand All @@ -229,7 +218,7 @@ module.exports = async (args: BootstrapArgs) => {
)
.join(`,`)

browserAPIRunner = `var plugins = [${browserPluginsRequires}]\n${browserAPIRunner}`
const browserAPIRunner = `module.exports = [${browserPluginsRequires}]\n`

let sSRAPIRunner = ``

Expand All @@ -251,7 +240,7 @@ module.exports = async (args: BootstrapArgs) => {
sSRAPIRunner = `var plugins = [${ssrPluginsRequires}]\n${sSRAPIRunner}`

fs.writeFileSync(
`${siteDir}/api-runner-browser.js`,
`${siteDir}/api-runner-browser-plugins.js`,
browserAPIRunner,
`utf-8`
)
Expand Down

0 comments on commit 8ff3cfb

Please sign in to comment.