Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Remove obsolete unstable_onPluginInit codepaths #37176

Merged
merged 2 commits into from
Dec 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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