Skip to content

Commit

Permalink
fix(gatsby): Use xstate predictableActionArguments & update to 4.34 (
Browse files Browse the repository at this point in the history
…#36342)

* update version and fix types

* yolo add option

* Work around removal of meta.state

* Refactor `meta.state` access in `gatsby-source-filesystem` (#36355)

Co-authored-by: Lennart <lekoarts@gmail.com>

* fix ts-ignore

* Upgrade XState to the latest 4.33.3 (#36451)

* update to latest xstate

* Use `pendingQueryRuns` available on the event (#36393)

* Revert "Use `pendingQueryRuns` available on the event (#36393)"

This reverts commit 9460dd3.

Co-authored-by: tyhopp <hopp.ty.c@gmail.com>
Co-authored-by: Mateusz Burzyński <mateuszburzynski@gmail.com>
Co-authored-by: Ty Hopp <tyhopp@users.noreply.github.com>
  • Loading branch information
4 people committed Nov 17, 2022
1 parent aca64b7 commit 3032a1b
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 9 deletions.
2 changes: 1 addition & 1 deletion packages/gatsby-source-filesystem/package.json
Expand Up @@ -16,7 +16,7 @@
"mime": "^2.5.2",
"pretty-bytes": "^5.4.1",
"valid-url": "^1.0.9",
"xstate": "4.32.1"
"xstate": "^4.34.0"
},
"devDependencies": {
"@babel/cli": "^7.15.4",
Expand Down
11 changes: 8 additions & 3 deletions packages/gatsby-source-filesystem/src/gatsby-node.js
@@ -1,7 +1,7 @@
const chokidar = require(`chokidar`)
const fs = require(`fs`)
const path = require(`path`)
const { Machine, interpret } = require(`xstate`)
const { createMachine, interpret, assign } = require(`xstate`)

const { createFileNode } = require(`./create-file-node`)
const { ERROR_MAP } = require(`./error-utils`)
Expand Down Expand Up @@ -61,13 +61,17 @@ const createFSMachine = (
}

const log = expr => (ctx, action, meta) => {
if (meta.state.matches(`BOOTSTRAP.BOOTSTRAPPED`)) {
if (ctx.bootstrapped) {
reporter.info(expr(ctx, action, meta))
}
}

const fsMachine = Machine(
const fsMachine = createMachine(
{
predictableActionArguments: true,
context: {
bootstrapped: false,
},
id: `fs`,
type: `parallel`,
states: {
Expand All @@ -81,6 +85,7 @@ const createFSMachine = (
},
BOOTSTRAPPED: {
type: `final`,
entry: assign({ bootstrapped: true }),
},
},
},
Expand Down
2 changes: 1 addition & 1 deletion packages/gatsby/package.json
Expand Up @@ -173,7 +173,7 @@
"webpack-merge": "^5.8.0",
"webpack-stats-plugin": "^1.0.3",
"webpack-virtual-modules": "^0.3.2",
"xstate": "4.32.1",
"xstate": "^4.34.0",
"yaml-loader": "^0.6.0"
},
"devDependencies": {
Expand Down
3 changes: 3 additions & 0 deletions packages/gatsby/src/state-machines/data-layer/index.ts
Expand Up @@ -117,6 +117,7 @@ const options: Partial<MachineOptions<IDataLayerContext, any>> = {

export const initializeDataMachine = createMachine(
{
predictableActionArguments: true,
id: `initializeDataMachine`,
context: {},
initial: `customizingSchema`,
Expand All @@ -135,6 +136,7 @@ export const initializeDataMachine = createMachine(

export const reloadDataMachine = createMachine(
{
predictableActionArguments: true,
id: `reloadDataMachine`,
context: {},
initial: `customizingSchema`,
Expand All @@ -153,6 +155,7 @@ export const reloadDataMachine = createMachine(
*/
export const recreatePagesMachine = createMachine(
{
predictableActionArguments: true,
id: `recreatePagesMachine`,
context: {},
initial: `buildingSchema`,
Expand Down
1 change: 1 addition & 0 deletions packages/gatsby/src/state-machines/develop/index.ts
Expand Up @@ -21,6 +21,7 @@ const getGraphqlTypegenConfig = (ctx: IBuildContext): boolean =>
* This is the top-level state machine for the `gatsby develop` command
*/
const developConfig: MachineConfig<IBuildContext, any, AnyEventObject> = {
predictableActionArguments: true,
id: `build`,
initial: `initializing`,
// These are mutation events, sent to this machine by the mutation listener
Expand Down
1 change: 1 addition & 0 deletions packages/gatsby/src/state-machines/query-running/index.ts
Expand Up @@ -10,6 +10,7 @@ import { queryActions } from "./actions"
const PAGE_QUERY_ENQUEUING_TIMEOUT = 50

export const queryStates: MachineConfig<IQueryRunningContext, any, any> = {
predictableActionArguments: true,
initial: `extractingQueries`,
id: `queryRunningMachine`,
on: {
Expand Down
1 change: 1 addition & 0 deletions packages/gatsby/src/state-machines/waiting/index.ts
Expand Up @@ -14,6 +14,7 @@ export type WaitingResult = Pick<IWaitingContext, "nodeMutationBatch">
* mutations when we first start it
*/
export const waitingStates: MachineConfig<IWaitingContext, any, any> = {
predictableActionArguments: true,
id: `waitingMachine`,
initial: `idle`,
context: {
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Expand Up @@ -24750,10 +24750,10 @@ xmlhttprequest-ssl@~1.5.4:
version "1.5.5"
resolved "https://registry.yarnpkg.com/xmlhttprequest-ssl/-/xmlhttprequest-ssl-1.5.5.tgz#c2876b06168aadc40e57d97e81191ac8f4398b3e"

xstate@4.32.1:
version "4.32.1"
resolved "https://registry.yarnpkg.com/xstate/-/xstate-4.32.1.tgz#1a09c808a66072938861a3b4acc5b38460244b70"
integrity sha512-QYUd+3GkXZ8i6qdixnOn28bL3EvA++LONYL/EMWwKlFSh/hiLndJ8YTnz77FDs+JUXcwU7NZJg7qoezoRHc4GQ==
xstate@^4.34.0:
version "4.34.0"
resolved "https://registry.yarnpkg.com/xstate/-/xstate-4.34.0.tgz#401901c478f0b2a7f07576c020b6e6f750b5bd10"
integrity sha512-MFnYz7cJrWuXSZ8IPkcCyLB1a2T3C71kzMeShXKmNaEjBR/JQebKZPHTtxHKZpymESaWO31rA3IQ30TC6LW+sw==

xtend@^4.0.0, xtend@^4.0.1, xtend@^4.0.2, xtend@~4.0.0, xtend@~4.0.1:
version "4.0.2"
Expand Down

0 comments on commit 3032a1b

Please sign in to comment.