diff --git a/packages/gatsby/src/services/initialize.ts b/packages/gatsby/src/services/initialize.ts index d1ee5d625b3b2..edbb546936837 100644 --- a/packages/gatsby/src/services/initialize.ts +++ b/packages/gatsby/src/services/initialize.ts @@ -21,6 +21,7 @@ import { IBuildContext } from "./types" import { loadConfig } from "../bootstrap/load-config" import { loadPlugins } from "../bootstrap/load-plugins" import type { InternalJob } from "../utils/jobs/types" +import type { IDataLayerContext } from "./../state-machines/data-layer/types" import { enableNodeMutationsDetection } from "../utils/detect-node-mutations" import { compileGatsbyFiles } from "../utils/parcel/compile-gatsby-files" import { resolveModule } from "../utils/module-resolver" @@ -71,12 +72,15 @@ process.on(`unhandledRejection`, (reason: unknown) => { // Otherwise leave commented out. // require(`../bootstrap/log-line-function`) +type WebhookBody = IDataLayerContext["webhookBody"] + export async function initialize({ program: args, parentSpan, }: IBuildContext): Promise<{ store: Store workerPool: WorkerPool.GatsbyWorkerPool + webhookBody?: WebhookBody }> { if (process.env.GATSBY_DISABLE_CACHE_PERSISTENCE) { reporter.info( @@ -651,8 +655,21 @@ export async function initialize({ } } + let initialWebhookBody: WebhookBody = undefined + + if (process.env.GATSBY_INITIAL_WEBHOOK_BODY) { + try { + initialWebhookBody = JSON.parse(process.env.GATSBY_INITIAL_WEBHOOK_BODY) + } catch (e) { + reporter.error( + `Failed to parse GATSBY_INITIAL_WEBHOOK_BODY as JSON:\n"${e.message}"` + ) + } + } + return { store, workerPool, + webhookBody: initialWebhookBody, } }