Skip to content

Commit 000e23e

Browse files
authoredJan 19, 2023
feat(gatsby): add initial webhook body env var to bootstrap context (#37478)
* add initial webhook body env var to bootstrap context * catch errors * add e message
1 parent 0017375 commit 000e23e

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed
 

‎packages/gatsby/src/services/initialize.ts

+17
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import { IBuildContext } from "./types"
2121
import { loadConfig } from "../bootstrap/load-config"
2222
import { loadPlugins } from "../bootstrap/load-plugins"
2323
import type { InternalJob } from "../utils/jobs/types"
24+
import type { IDataLayerContext } from "./../state-machines/data-layer/types"
2425
import { enableNodeMutationsDetection } from "../utils/detect-node-mutations"
2526
import { compileGatsbyFiles } from "../utils/parcel/compile-gatsby-files"
2627
import { resolveModule } from "../utils/module-resolver"
@@ -71,12 +72,15 @@ process.on(`unhandledRejection`, (reason: unknown) => {
7172
// Otherwise leave commented out.
7273
// require(`../bootstrap/log-line-function`)
7374

75+
type WebhookBody = IDataLayerContext["webhookBody"]
76+
7477
export async function initialize({
7578
program: args,
7679
parentSpan,
7780
}: IBuildContext): Promise<{
7881
store: Store<IGatsbyState, AnyAction>
7982
workerPool: WorkerPool.GatsbyWorkerPool
83+
webhookBody?: WebhookBody
8084
}> {
8185
if (process.env.GATSBY_DISABLE_CACHE_PERSISTENCE) {
8286
reporter.info(
@@ -651,8 +655,21 @@ export async function initialize({
651655
}
652656
}
653657

658+
let initialWebhookBody: WebhookBody = undefined
659+
660+
if (process.env.GATSBY_INITIAL_WEBHOOK_BODY) {
661+
try {
662+
initialWebhookBody = JSON.parse(process.env.GATSBY_INITIAL_WEBHOOK_BODY)
663+
} catch (e) {
664+
reporter.error(
665+
`Failed to parse GATSBY_INITIAL_WEBHOOK_BODY as JSON:\n"${e.message}"`
666+
)
667+
}
668+
}
669+
654670
return {
655671
store,
656672
workerPool,
673+
webhookBody: initialWebhookBody,
657674
}
658675
}

0 commit comments

Comments
 (0)
Please sign in to comment.