Skip to content

Commit

Permalink
fix: Remove obsolete unstable_onPluginInit codepaths (#37176)
Browse files Browse the repository at this point in the history
  • Loading branch information
LekoArts authored Dec 5, 2022
1 parent 33976b3 commit bb42840
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 77 deletions.
24 changes: 1 addition & 23 deletions packages/gatsby-plugin-page-creator/src/gatsby-node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,6 @@ import { getCollectionRouteParams } from "./get-collection-route-params"
import { reverseLookupParams } from "./extract-query"
import { getMatchPath } from "gatsby-core-utils/match-path"

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 knownCollections = new Map()

export function createPages(_: CreatePagesArgs, pluginOptions: IOptions): void {
Expand Down Expand Up @@ -419,7 +406,7 @@ export function setFieldsOnGraphQLNodeType(
}
}

async function initializePlugin(
export async function onPluginInit(
{ reporter }: ParentSpanPluginArgs,
{ path: pagesPath }: IOptions
): Promise<void> {
Expand Down Expand Up @@ -463,12 +450,3 @@ async function initializePlugin(
})
}
}

if (coreSupportsOnPluginInit === `stable`) {
// need to conditionally export otherwise it throws an error for older versions
exports.onPluginInit = initializePlugin
} else if (coreSupportsOnPluginInit === `unstable`) {
exports.unstable_onPluginInit = initializePlugin
} else {
exports.onPreInit = initializePlugin
}
29 changes: 4 additions & 25 deletions packages/gatsby-source-shopify/src/gatsby-node.ts
Original file line number Diff line number Diff line change
@@ -1,34 +1,13 @@
import { NodePluginArgs } from "gatsby"

import type { GatsbyNode } from "gatsby"
import { ERROR_MAP } from "./error-map"

export { sourceNodes } from "./source-nodes"
export { createResolvers } from "./create-resolvers"
export { pluginOptionsSchema } from "./plugin-options-schema"
export { createSchemaCustomization } from "./create-schema-customization"

const initializePlugin = ({ reporter }: NodePluginArgs): void => {
export const onPluginInit: GatsbyNode["onPluginInit"] = ({
reporter,
}): void => {
reporter.setErrorMap(ERROR_MAP)
}

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`)
}

if (coreSupportsOnPluginInit === `unstable`) {
// need to conditionally export otherwise it throws an error for older versions
exports.unstable_onPluginInit = initializePlugin
} else if (coreSupportsOnPluginInit === `stable`) {
exports.onPluginInit = initializePlugin
} else {
exports.onPreInit = initializePlugin
}
2 changes: 1 addition & 1 deletion packages/gatsby-source-wordpress/src/gatsby-node.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { runApiSteps, findApiName } from "./utils/run-steps"
import * as steps from "./steps"

const pluginInitApiName = findApiName(`onPluginInit|unstable_onPluginInit`)
const pluginInitApiName = findApiName(`onPluginInit`)

exports[pluginInitApiName] = runApiSteps(
[
Expand Down
2 changes: 1 addition & 1 deletion packages/gatsby-source-wordpress/src/utils/run-steps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ const runSteps = async (
* Takes in a pipe delimited string of Gatsby Node API names and returns the first supported API name as a string
*
* Example input: "onPluginInit|unstable_onPluginInit"
* Example output: "unstable_onPluginInit"
* Example output: "onPluginInit"
*/
const findApiName = (initialApiNameString: string): string => {
if (!initialApiNameString.includes(`|`)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,8 @@ Array [
"nodeAPIs": Array [
"createPages",
"createPagesStatefully",
"setFieldsOnGraphQLNodeType",
"onPluginInit",
"setFieldsOnGraphQLNodeType",
],
"pluginOptions": Object {
"path": "<PROJECT_ROOT>/packages/gatsby/src/internal-plugins/dev-404-page/src/pages",
Expand All @@ -132,8 +132,8 @@ Array [
"nodeAPIs": Array [
"createPages",
"createPagesStatefully",
"setFieldsOnGraphQLNodeType",
"onPluginInit",
"setFieldsOnGraphQLNodeType",
],
"pluginOptions": Object {
"path": "<PROJECT_ROOT>/packages/gatsby/src/internal-plugins/load-babel-config/src/pages",
Expand All @@ -154,8 +154,8 @@ Array [
"nodeAPIs": Array [
"createPages",
"createPagesStatefully",
"setFieldsOnGraphQLNodeType",
"onPluginInit",
"setFieldsOnGraphQLNodeType",
],
"pluginOptions": Object {
"path": "<PROJECT_ROOT>/packages/gatsby/src/internal-plugins/internal-data-bridge/src/pages",
Expand All @@ -176,8 +176,8 @@ Array [
"nodeAPIs": Array [
"createPages",
"createPagesStatefully",
"setFieldsOnGraphQLNodeType",
"onPluginInit",
"setFieldsOnGraphQLNodeType",
],
"pluginOptions": Object {
"path": "<PROJECT_ROOT>/packages/gatsby/src/internal-plugins/prod-404-500/src/pages",
Expand All @@ -198,8 +198,8 @@ Array [
"nodeAPIs": Array [
"createPages",
"createPagesStatefully",
"setFieldsOnGraphQLNodeType",
"onPluginInit",
"setFieldsOnGraphQLNodeType",
],
"pluginOptions": Object {
"path": "<PROJECT_ROOT>/packages/gatsby/src/internal-plugins/webpack-theme-component-shadowing/src/pages",
Expand All @@ -220,8 +220,8 @@ Array [
"nodeAPIs": Array [
"createPages",
"createPagesStatefully",
"setFieldsOnGraphQLNodeType",
"onPluginInit",
"setFieldsOnGraphQLNodeType",
],
"pluginOptions": Object {
"path": "<PROJECT_ROOT>/packages/gatsby/src/internal-plugins/bundle-optimisations/src/pages",
Expand All @@ -242,8 +242,8 @@ Array [
"nodeAPIs": Array [
"createPages",
"createPagesStatefully",
"setFieldsOnGraphQLNodeType",
"onPluginInit",
"setFieldsOnGraphQLNodeType",
],
"pluginOptions": Object {
"path": "<PROJECT_ROOT>/packages/gatsby/src/internal-plugins/functions/src/pages",
Expand Down Expand Up @@ -300,8 +300,8 @@ Array [
"nodeAPIs": Array [
"createPages",
"createPagesStatefully",
"setFieldsOnGraphQLNodeType",
"onPluginInit",
"setFieldsOnGraphQLNodeType",
],
"pluginOptions": Object {
"path": "/src/pages",
Expand Down Expand Up @@ -458,8 +458,8 @@ Array [
"nodeAPIs": Array [
"createPages",
"createPagesStatefully",
"setFieldsOnGraphQLNodeType",
"onPluginInit",
"setFieldsOnGraphQLNodeType",
],
"pluginOptions": Object {
"path": "<PROJECT_ROOT>/packages/gatsby/src/internal-plugins/dev-404-page/src/pages",
Expand All @@ -480,8 +480,8 @@ Array [
"nodeAPIs": Array [
"createPages",
"createPagesStatefully",
"setFieldsOnGraphQLNodeType",
"onPluginInit",
"setFieldsOnGraphQLNodeType",
],
"pluginOptions": Object {
"path": "<PROJECT_ROOT>/packages/gatsby/src/internal-plugins/load-babel-config/src/pages",
Expand All @@ -502,8 +502,8 @@ Array [
"nodeAPIs": Array [
"createPages",
"createPagesStatefully",
"setFieldsOnGraphQLNodeType",
"onPluginInit",
"setFieldsOnGraphQLNodeType",
],
"pluginOptions": Object {
"path": "<PROJECT_ROOT>/packages/gatsby/src/internal-plugins/internal-data-bridge/src/pages",
Expand All @@ -524,8 +524,8 @@ Array [
"nodeAPIs": Array [
"createPages",
"createPagesStatefully",
"setFieldsOnGraphQLNodeType",
"onPluginInit",
"setFieldsOnGraphQLNodeType",
],
"pluginOptions": Object {
"path": "<PROJECT_ROOT>/packages/gatsby/src/internal-plugins/prod-404-500/src/pages",
Expand All @@ -546,8 +546,8 @@ Array [
"nodeAPIs": Array [
"createPages",
"createPagesStatefully",
"setFieldsOnGraphQLNodeType",
"onPluginInit",
"setFieldsOnGraphQLNodeType",
],
"pluginOptions": Object {
"path": "<PROJECT_ROOT>/packages/gatsby/src/internal-plugins/webpack-theme-component-shadowing/src/pages",
Expand All @@ -568,8 +568,8 @@ Array [
"nodeAPIs": Array [
"createPages",
"createPagesStatefully",
"setFieldsOnGraphQLNodeType",
"onPluginInit",
"setFieldsOnGraphQLNodeType",
],
"pluginOptions": Object {
"path": "<PROJECT_ROOT>/packages/gatsby/src/internal-plugins/bundle-optimisations/src/pages",
Expand All @@ -590,8 +590,8 @@ Array [
"nodeAPIs": Array [
"createPages",
"createPagesStatefully",
"setFieldsOnGraphQLNodeType",
"onPluginInit",
"setFieldsOnGraphQLNodeType",
],
"pluginOptions": Object {
"path": "<PROJECT_ROOT>/packages/gatsby/src/internal-plugins/functions/src/pages",
Expand All @@ -612,8 +612,8 @@ Array [
"nodeAPIs": Array [
"createPages",
"createPagesStatefully",
"setFieldsOnGraphQLNodeType",
"onPluginInit",
"setFieldsOnGraphQLNodeType",
],
"pluginOptions": Object {
"path": "__TEST__/src/pages",
Expand Down Expand Up @@ -670,8 +670,8 @@ Array [
"nodeAPIs": Array [
"createPages",
"createPagesStatefully",
"setFieldsOnGraphQLNodeType",
"onPluginInit",
"setFieldsOnGraphQLNodeType",
],
"pluginOptions": Object {
"path": "/src/pages",
Expand Down Expand Up @@ -816,8 +816,8 @@ Array [
"nodeAPIs": Array [
"createPages",
"createPagesStatefully",
"setFieldsOnGraphQLNodeType",
"onPluginInit",
"setFieldsOnGraphQLNodeType",
],
"pluginOptions": Object {
"ignore": Array [
Expand All @@ -840,8 +840,8 @@ Array [
"nodeAPIs": Array [
"createPages",
"createPagesStatefully",
"setFieldsOnGraphQLNodeType",
"onPluginInit",
"setFieldsOnGraphQLNodeType",
],
"pluginOptions": Object {
"path": "<PROJECT_ROOT>/packages/gatsby/src/internal-plugins/dev-404-page/src/pages",
Expand All @@ -862,8 +862,8 @@ Array [
"nodeAPIs": Array [
"createPages",
"createPagesStatefully",
"setFieldsOnGraphQLNodeType",
"onPluginInit",
"setFieldsOnGraphQLNodeType",
],
"pluginOptions": Object {
"path": "<PROJECT_ROOT>/packages/gatsby/src/internal-plugins/load-babel-config/src/pages",
Expand All @@ -884,8 +884,8 @@ Array [
"nodeAPIs": Array [
"createPages",
"createPagesStatefully",
"setFieldsOnGraphQLNodeType",
"onPluginInit",
"setFieldsOnGraphQLNodeType",
],
"pluginOptions": Object {
"path": "<PROJECT_ROOT>/packages/gatsby/src/internal-plugins/internal-data-bridge/src/pages",
Expand All @@ -906,8 +906,8 @@ Array [
"nodeAPIs": Array [
"createPages",
"createPagesStatefully",
"setFieldsOnGraphQLNodeType",
"onPluginInit",
"setFieldsOnGraphQLNodeType",
],
"pluginOptions": Object {
"path": "<PROJECT_ROOT>/packages/gatsby/src/internal-plugins/prod-404-500/src/pages",
Expand All @@ -928,8 +928,8 @@ Array [
"nodeAPIs": Array [
"createPages",
"createPagesStatefully",
"setFieldsOnGraphQLNodeType",
"onPluginInit",
"setFieldsOnGraphQLNodeType",
],
"pluginOptions": Object {
"path": "<PROJECT_ROOT>/packages/gatsby/src/internal-plugins/webpack-theme-component-shadowing/src/pages",
Expand All @@ -950,8 +950,8 @@ Array [
"nodeAPIs": Array [
"createPages",
"createPagesStatefully",
"setFieldsOnGraphQLNodeType",
"onPluginInit",
"setFieldsOnGraphQLNodeType",
],
"pluginOptions": Object {
"path": "<PROJECT_ROOT>/packages/gatsby/src/internal-plugins/bundle-optimisations/src/pages",
Expand All @@ -972,8 +972,8 @@ Array [
"nodeAPIs": Array [
"createPages",
"createPagesStatefully",
"setFieldsOnGraphQLNodeType",
"onPluginInit",
"setFieldsOnGraphQLNodeType",
],
"pluginOptions": Object {
"path": "<PROJECT_ROOT>/packages/gatsby/src/internal-plugins/functions/src/pages",
Expand All @@ -994,8 +994,8 @@ Array [
"nodeAPIs": Array [
"createPages",
"createPagesStatefully",
"setFieldsOnGraphQLNodeType",
"onPluginInit",
"setFieldsOnGraphQLNodeType",
],
"pluginOptions": Object {
"path": "<PROJECT_ROOT>/packages/gatsby-plugin-page-creator/src/pages",
Expand Down Expand Up @@ -1052,8 +1052,8 @@ Array [
"nodeAPIs": Array [
"createPages",
"createPagesStatefully",
"setFieldsOnGraphQLNodeType",
"onPluginInit",
"setFieldsOnGraphQLNodeType",
],
"pluginOptions": Object {
"path": "/src/pages",
Expand Down

0 comments on commit bb42840

Please sign in to comment.