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

chore(gatsby-source-wordpress): remove runApisInSteps and call runApiSteps for each gatsby-node api #37039

Merged
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
2 changes: 0 additions & 2 deletions packages/gatsby-source-wordpress/ARCHITECTURE.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@ The file you're reading was created many months after the first stable version o

## `gatsby-node.ts` Steps

In `src/gatsby-node.ts` a helper (`runApisInSteps`) is being used to run different "steps" of the codebase one after another for each Gatsby Node API. Many parts of the codebase count on something else happening at an earlier point, so `runApisInSteps` is an easy way to visualize that.

`src/gatsby-node.ts` is the entry point for 99.999% of the plugin (`src/gatsby-browser.ts` only imports 1 css file) so it's a good jumping off point for looking at different areas of the plugin.

Each "step" is in it's own file in `src/steps`.
Expand Down
46 changes: 32 additions & 14 deletions packages/gatsby-source-wordpress/src/gatsby-node.ts
Original file line number Diff line number Diff line change
@@ -1,46 +1,64 @@
import { runApisInSteps } from "./utils/run-steps"
import { runApiSteps, findApiName } from "./utils/run-steps"
import * as steps from "./steps"

module.exports = runApisInSteps({
// eslint-disable-next-line @typescript-eslint/naming-convention
"onPluginInit|unstable_onPluginInit": [
const pluginInitApiName = findApiName(`onPluginInit|unstable_onPluginInit`)

exports[pluginInitApiName] = runApiSteps(
[
steps.setGatsbyApiToState,
steps.setErrorMap,
steps.tempPreventMultipleInstances,
steps.setRequestHeaders,
],
pluginInitApiName
)

pluginOptionsSchema: steps.pluginOptionsSchema,
exports.pluginOptionsSchema = steps.pluginOptionsSchema

createSchemaCustomization: [
exports.createSchemaCustomization = runApiSteps(
[
steps.setGatsbyApiToState,
steps.ensurePluginRequirementsAreMet,
steps.ingestRemoteSchema,
steps.createSchemaCustomization,
],
`createSchemaCustomization`
)

sourceNodes: [
exports.sourceNodes = runApiSteps(
[
steps.setGatsbyApiToState,
steps.persistPreviouslyCachedImages,
steps.sourceNodes,
steps.setImageNodeIdCache,
],
`sourceNodes`
)

onPreExtractQueries: [
steps.onPreExtractQueriesInvokeLeftoverPreviewCallbacks,
],
exports.onPreExtractQueries = runApiSteps(
[steps.onPreExtractQueriesInvokeLeftoverPreviewCallbacks],
`onPreExtractQueries`
)

onPostBuild: [steps.setImageNodeIdCache, steps.logPostBuildWarnings],
exports.onPostBuild = runApiSteps(
[steps.setImageNodeIdCache, steps.logPostBuildWarnings],
`onPostBuild`
)

onCreatePage: [
exports.onCreatePage = runApiSteps(
[
steps.onCreatepageSavePreviewNodeIdToPageDependency,
steps.onCreatePageRespondToPreviewStatusQuery,
],
`onCreatePage`
)

onCreateDevServer: [
exports.onCreateDevServer = runApiSteps(
[
steps.imageRoutes,
steps.setImageNodeIdCache,
steps.logPostBuildWarnings,
steps.startPollingForContentUpdates,
],
})
`onCreateDevServer`
)
20 changes: 1 addition & 19 deletions packages/gatsby-source-wordpress/src/utils/run-steps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,22 +116,4 @@ const runApiSteps =
): Promise<void> =>
runSteps(steps, helpers, pluginOptions, apiName)

const runApisInSteps = (nodeApis: {
[apiName: string]: Array<Step> | Step
}): { [apiName: string]: Promise<void> | void } =>
Object.entries(nodeApis).reduce(
(gatsbyNodeExportObject, [apiName, apiSteps]) => {
const normalizedApiName = findApiName(apiName)

return {
...gatsbyNodeExportObject,
[normalizedApiName]:
typeof apiSteps === `function`
? apiSteps
: runApiSteps(apiSteps, normalizedApiName),
}
},
{}
)

export { runSteps, runApisInSteps }
export { runSteps, runApiSteps, findApiName }