Skip to content

Commit 98c4d27

Browse files
feat(gatsby): add initial webhook body env var to bootstrap context (#37478) (#37692)
* add initial webhook body env var to bootstrap context * catch errors * add e message (cherry picked from commit 000e23e) Co-authored-by: Tyler Barnes <[email protected]>
1 parent e0c6d25 commit 98c4d27

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
@@ -23,6 +23,7 @@ import { detectLmdbStore } from "../datastore"
2323
import { loadConfig } from "../bootstrap/load-config"
2424
import { loadPlugins } from "../bootstrap/load-plugins"
2525
import type { InternalJob } from "../utils/jobs/types"
26+
import type { IDataLayerContext } from "./../state-machines/data-layer/types"
2627
import { enableNodeMutationsDetection } from "../utils/detect-node-mutations"
2728
import { compileGatsbyFiles } from "../utils/parcel/compile-gatsby-files"
2829
import { resolveModule } from "../utils/module-resolver"
@@ -74,12 +75,15 @@ process.on(`unhandledRejection`, (reason: unknown) => {
7475
// Otherwise leave commented out.
7576
// require(`../bootstrap/log-line-function`)
7677

78+
type WebhookBody = IDataLayerContext["webhookBody"]
79+
7780
export async function initialize({
7881
program: args,
7982
parentSpan,
8083
}: IBuildContext): Promise<{
8184
store: Store<IGatsbyState, AnyAction>
8285
workerPool: WorkerPool.GatsbyWorkerPool
86+
webhookBody?: WebhookBody
8387
}> {
8488
if (process.env.GATSBY_DISABLE_CACHE_PERSISTENCE) {
8589
reporter.info(
@@ -663,8 +667,21 @@ export async function initialize({
663667
}
664668
}
665669

670+
let initialWebhookBody: WebhookBody = undefined
671+
672+
if (process.env.GATSBY_INITIAL_WEBHOOK_BODY) {
673+
try {
674+
initialWebhookBody = JSON.parse(process.env.GATSBY_INITIAL_WEBHOOK_BODY)
675+
} catch (e) {
676+
reporter.error(
677+
`Failed to parse GATSBY_INITIAL_WEBHOOK_BODY as JSON:\n"${e.message}"`
678+
)
679+
}
680+
}
681+
666682
return {
667683
store,
668684
workerPool,
685+
webhookBody: initialWebhookBody,
669686
}
670687
}

0 commit comments

Comments
 (0)