Skip to content

Commit

Permalink
fix(gatsby-plugin-gatsby-cloud): emit file nodes after source updates (
Browse files Browse the repository at this point in the history
…gatsbyjs#33548)

* fix(gatsby-plugin-gatsby-cloud): emit file nodes after source updates

Co-authored-by: Vladimir Razuvaev <vladimir.razuvaev@gmail.com>

* promise awaited on in onPostBuild should resolve after all file nodes were emitted

Co-authored-by: Vladimir Razuvaev <vladimir.razuvaev@gmail.com>
  • Loading branch information
2 people authored and wardpeet committed Oct 29, 2021
1 parent d645f12 commit 52cab97
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 13 deletions.
37 changes: 24 additions & 13 deletions packages/gatsby-plugin-gatsby-cloud/src/gatsby-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ exports.onPostBuild = async (
}

await Promise.all([
ensureEmittingFileNodesFinished,
buildHeadersProgram(pluginData, pluginOptions),
createSiteConfig(pluginData, pluginOptions),
createRedirects(pluginData, redirects, rewrites),
Expand Down Expand Up @@ -156,18 +157,28 @@ const pluginOptionsSchema = function ({ Joi }) {

exports.pluginOptionsSchema = pluginOptionsSchema

exports.onPostBootstrap = async ({ getNodesByType }) => {
/**
* Emit via IPC absolute paths to files that should be stored
*/
const fileNodes = getNodesByType(`File`)
/**
* We emit File Nodes via IPC and we need to make sure build doesn't finish before all of
* messages were sent.
*/
let ensureEmittingFileNodesFinished
exports.onPreBootstrap = ({ emitter, getNodesByType }) => {
emitter.on(`API_FINISHED`, action => {
if (action.payload.apiName !== `sourceNodes`) {
return
}

// TODO: This is missing the cacheLocations .cache/caches + .cache/caches-lmdb
let fileNodesEmitted
for (const file of fileNodes) {
fileNodesEmitted = emitFileNodes({
path: file.absolutePath,
})
}
await fileNodesEmitted
async function doEmitFileNodes() {
const fileNodes = getNodesByType(`File`)

// TODO: This is missing the cacheLocations .cache/caches + .cache/caches-lmdb
for (const file of fileNodes) {
await emitFileNodes({
path: file.absolutePath,
})
}
}

ensureEmittingFileNodesFinished = doEmitFileNodes()
})
}
2 changes: 2 additions & 0 deletions packages/gatsby/src/utils/source-nodes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,4 +112,6 @@ export default async ({
warnForPluginsWithoutNodes(state, nodes)

deleteStaleNodes(state, nodes)

store.dispatch(actions.apiFinished({ apiName: `sourceNodes` }))
}

0 comments on commit 52cab97

Please sign in to comment.