Skip to content

Commit

Permalink
feat(gatsby-source-wordpress): Support on plugin init (#33080)
Browse files Browse the repository at this point in the history
* use onplugininit if core supports it

* fix name
  • Loading branch information
DanielSLew authored Sep 8, 2021
1 parent 721b2dc commit b9f114f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
4 changes: 4 additions & 0 deletions packages/gatsby-source-wordpress/src/constants.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
export const CREATED_NODE_IDS = `WPGQL-created-node-ids`
export const LAST_COMPLETED_SOURCE_TIME = `WPGQL-last-completed-source-time`
export const MD5_CACHE_KEY = `introspection-node-query-md5`
export const INITIALIZE_PLUGIN_LIFECYCLE_NAME_MAP = {
unstable: `unstable_onPluginInit`,
stable: `onPluginInit`,
}
19 changes: 18 additions & 1 deletion packages/gatsby-source-wordpress/src/gatsby-node.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,25 @@
import { runApisInSteps } from "./utils/run-steps"
import * as steps from "./steps"
import { INITIALIZE_PLUGIN_LIFECYCLE_NAME_MAP } from "./constants"

let coreSupportsOnPluginInit: `unstable` | `stable` | undefined

try {
const { isGatsbyNodeLifecycleSupported } = require(`gatsby-plugin-utils`)
if (isGatsbyNodeLifecycleSupported(`onPluginInit`)) {
coreSupportsOnPluginInit = `stable`
} else if (isGatsbyNodeLifecycleSupported(`unstable_onPluginInit`)) {
coreSupportsOnPluginInit = `unstable`
}
} catch (e) {
console.error(`Could not check if Gatsby supports onPluginInit lifecycle`)
}

const initializePluginLifeCycleName: string =
INITIALIZE_PLUGIN_LIFECYCLE_NAME_MAP[coreSupportsOnPluginInit] || `onPreInit`

module.exports = runApisInSteps({
onPreInit: [
[initializePluginLifeCycleName]: [
steps.setGatsbyApiToState,
steps.setErrorMap,
steps.tempPreventMultipleInstances,
Expand Down

0 comments on commit b9f114f

Please sign in to comment.