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(gatsby-plugin-gatsby-cloud): emit file nodes after source updates #33548

Merged
merged 2 commits into from
Oct 18, 2021
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
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` }))
wardpeet marked this conversation as resolved.
Show resolved Hide resolved
}