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): Migrate src/redux/plugin-runner to TypeScript #22476

Merged
merged 3 commits into from
Mar 30, 2020
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
3 changes: 2 additions & 1 deletion packages/gatsby/src/bootstrap/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const telemetry = require(`gatsby-telemetry`)
const apiRunnerNode = require(`../utils/api-runner-node`)
import { getBrowsersList } from "../utils/browserslist"
import { createSchemaCustomization } from "../utils/create-schema-customization"
import { startPluginRunner } from "../redux/plugin-runner"
const { store, emitter } = require(`../redux`)
const loadPlugins = require(`./load-plugins`)
const loadThemes = require(`./load-themes`)
Expand Down Expand Up @@ -66,7 +67,7 @@ module.exports = async (args: BootstrapArgs) => {

// Start plugin runner which listens to the store
// and invokes Gatsby API based on actions.
require(`../redux/plugin-runner`)
startPluginRunner()

const directory = slash(args.directory)

Expand Down
13 changes: 0 additions & 13 deletions packages/gatsby/src/redux/plugin-runner.js

This file was deleted.

51 changes: 51 additions & 0 deletions packages/gatsby/src/redux/plugin-runner.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import { Span } from "opentracing"
import { emitter } from "./index"
import apiRunnerNode from "../utils/api-runner-node"
import { ActivityTracker } from "../../"

type Plugin = any // TODO

// This might make sense to live somewhere else
interface ICreatePageAction {
graphql<TData, TVariables = any>(
query: string,
variables?: TVariables
): Promise<{
errors?: any
data?: TData
}>
traceId: "initial-createPages"
waitForCascadingActions: boolean
parentSpan: Span
activity: ActivityTracker
type: `CREATE_PAGE`
contextModified: boolean
plugin: Plugin
payload: {
internalComponentName: string
path: string
matchPath: string | undefined
component: string
componentChunkName: string
isCreatedByStatefulCreatePages: boolean
context: {
slug: string
id: string
}
updatedAt: number
pluginCreator__NODE: string
pluginCreatorId: string
componentPath: string
}
}

export const startPluginRunner = (): void => {
emitter.on(`CREATE_PAGE`, (action: ICreatePageAction) => {
const page = action.payload
apiRunnerNode(
`onCreatePage`,
{ page, traceId: action.traceId, parentSpan: action.parentSpan },
{ pluginSource: action.plugin.name, activity: action.activity }
)
})
}