From 98c4d27fbac98155692691388db54c5e31314570 Mon Sep 17 00:00:00 2001 From: GatsbyJS Bot Date: Thu, 23 Feb 2023 06:48:53 -0500 Subject: [PATCH] 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 000e23e0f1247af61b8ecdc2f7274e53e89e82bf) Co-authored-by: Tyler Barnes --- packages/gatsby/src/services/initialize.ts | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/packages/gatsby/src/services/initialize.ts b/packages/gatsby/src/services/initialize.ts index 572db6f6593b8..f48200b65ed45 100644 --- a/packages/gatsby/src/services/initialize.ts +++ b/packages/gatsby/src/services/initialize.ts @@ -23,6 +23,7 @@ import { detectLmdbStore } from "../datastore" 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" @@ -74,12 +75,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( @@ -663,8 +667,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, } }