Skip to content

Commit

Permalink
feat(gatsby): add initial webhook body env var to bootstrap context (#…
Browse files Browse the repository at this point in the history
…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 <tylerdbarnes@gmail.com>
  • Loading branch information
gatsbybot and TylerBarnes authored Feb 23, 2023
1 parent e0c6d25 commit 98c4d27
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions packages/gatsby/src/services/initialize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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<IGatsbyState, AnyAction>
workerPool: WorkerPool.GatsbyWorkerPool
webhookBody?: WebhookBody
}> {
if (process.env.GATSBY_DISABLE_CACHE_PERSISTENCE) {
reporter.info(
Expand Down Expand Up @@ -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,
}
}

0 comments on commit 98c4d27

Please sign in to comment.