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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(gatsby): Use xstate predictableActionArguments & update to 4.34 #36342

Merged
merged 13 commits into from Nov 17, 2022
Merged
2 changes: 1 addition & 1 deletion packages/gatsby-source-filesystem/package.json
Expand Up @@ -18,7 +18,7 @@
"pretty-bytes": "^5.4.1",
"progress": "^2.0.3",
"valid-url": "^1.0.9",
"xstate": "^4.26.1"
"xstate": "^4.33.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 @@ -168,7 +168,7 @@
"webpack-merge": "^5.8.0",
"webpack-stats-plugin": "^1.0.3",
"webpack-virtual-modules": "^0.3.2",
"xstate": "^4.26.0",
"xstate": "^4.33.0",
"yaml-loader": "^0.6.0"
},
"devDependencies": {
Expand Down
1 change: 1 addition & 0 deletions packages/gatsby/src/commands/develop-process.ts
Expand Up @@ -164,6 +164,7 @@ module.exports = async (program: IDevelopArgs): Promise<void> => {
const service = interpret(machine)

if (program.verbose) {
// @ts-ignore - I don't understand this failure
LekoArts marked this conversation as resolved.
Show resolved Hide resolved
logTransitions(service)
}

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
10 changes: 5 additions & 5 deletions packages/gatsby/src/state-machines/data-layer/services.ts
@@ -1,4 +1,4 @@
import { ServiceConfig } from "xstate"
import { MachineOptions } from "xstate"
import {
customizeSchema,
createPages,
Expand All @@ -8,10 +8,10 @@ import {
} from "../../services"
import { IDataLayerContext } from "./types"

export const dataLayerServices: Record<
string,
ServiceConfig<IDataLayerContext>
> = {
export const dataLayerServices: MachineOptions<
IDataLayerContext,
any
>["services"] = {
customizeSchema,
sourceNodes,
createPages,
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
4 changes: 2 additions & 2 deletions packages/gatsby/src/state-machines/develop/services.ts
Expand Up @@ -13,9 +13,9 @@ import {
} from "../data-layer"
import { queryRunningMachine } from "../query-running"
import { waitingMachine } from "../waiting"
import { ServiceConfig } from "xstate"
import { MachineOptions } from "xstate"

export const developServices: Record<string, ServiceConfig<IBuildContext>> = {
export const developServices: MachineOptions<IBuildContext, any>["services"] = {
initializeData: initializeDataMachine,
reloadData: reloadDataMachine,
recreatePages: recreatePagesMachine,
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
10 changes: 5 additions & 5 deletions packages/gatsby/src/state-machines/query-running/services.ts
@@ -1,4 +1,4 @@
import { ServiceConfig } from "xstate"
import { MachineOptions } from "xstate"
import {
extractQueries,
writeOutRequires,
Expand All @@ -10,10 +10,10 @@ import {
} from "../../services"
import { IQueryRunningContext } from "./types"

export const queryRunningServices: Record<
string,
ServiceConfig<IQueryRunningContext>
> = {
export const queryRunningServices: MachineOptions<
IQueryRunningContext,
any
>["services"] = {
extractQueries,
writeOutRequires,
calculateDirtyQueries,
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 @@ -26160,10 +26160,10 @@ xss@^1.0.6:
commander "^2.20.3"
cssfilter "0.0.10"

xstate@^4.26.0, xstate@^4.26.1:
version "4.26.1"
resolved "https://registry.yarnpkg.com/xstate/-/xstate-4.26.1.tgz#4fc1afd153f88cf302a9ee2b758f6629e6a829b6"
integrity sha512-JLofAEnN26l/1vbODgsDa+Phqa61PwDlxWu8+2pK+YbXf+y9pQSDLRvcYH2H1kkeUBA5fGp+xFL/zfE8jNMw4g==
xstate@^4.33.0:
version "4.33.0"
resolved "https://registry.yarnpkg.com/xstate/-/xstate-4.33.0.tgz#4377a11e92267ad01ea498c4fc69887f0eddf1c8"
integrity sha512-+oari/Nt2cBq79mklnGA9Tsb6kv7ln+cIMfrH6n642XpTEG6sMRHg4GkooAbGbcslG3Ff9uH2jmGRP+1uoZ/Xw==

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