From f6ecf36e339fb86a5fc2b65c56f509b847cc8ed7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Burzy=C5=84ski?= Date: Wed, 10 Aug 2022 14:26:54 +0200 Subject: [PATCH 1/2] Refactor `meta.state` access in `gatsby-source-filesystem` --- .../gatsby-source-filesystem/src/gatsby-node.js | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/packages/gatsby-source-filesystem/src/gatsby-node.js b/packages/gatsby-source-filesystem/src/gatsby-node.js index b3e2c2ba1d32e..059ec701ab36e 100644 --- a/packages/gatsby-source-filesystem/src/gatsby-node.js +++ b/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 { createMachine, interpret } = require(`xstate`) +const { createMachine, interpret, assign } = require(`xstate`) const { createFileNode } = require(`./create-file-node`) const { ERROR_MAP } = require(`./error-utils`) @@ -60,8 +60,8 @@ const createFSMachine = ( ) } - const log = expr => (ctx, action, meta) => { - if (machineInstance.state.matches(`BOOTSTRAP.BOOTSTRAPPED`)) { + const log = expr => (ctx, action) => { + if (ctx.bootstrapped) { reporter.info(expr(ctx, action, meta)) } } @@ -69,6 +69,9 @@ const createFSMachine = ( const fsMachine = createMachine( { predictableActionArguments: true, + context: { + bootstrapped: false, + }, id: `fs`, type: `parallel`, states: { @@ -82,6 +85,7 @@ const createFSMachine = ( }, BOOTSTRAPPED: { type: `final`, + entry: assign({ bootstrapped: true }), }, }, }, @@ -151,8 +155,7 @@ const createFSMachine = ( }, } ) - const machineInstance = interpret(fsMachine).start() - return machineInstance + return interpret(fsMachine).start() } exports.pluginOptionsSchema = ({ Joi }) => From 071009709234ec1a85dbf805a2ac18e0bf1ddc4d Mon Sep 17 00:00:00 2001 From: Lennart Date: Wed, 10 Aug 2022 15:09:31 +0200 Subject: [PATCH 2/2] Update gatsby-node.js --- packages/gatsby-source-filesystem/src/gatsby-node.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/gatsby-source-filesystem/src/gatsby-node.js b/packages/gatsby-source-filesystem/src/gatsby-node.js index 059ec701ab36e..15ddd7e514033 100644 --- a/packages/gatsby-source-filesystem/src/gatsby-node.js +++ b/packages/gatsby-source-filesystem/src/gatsby-node.js @@ -60,7 +60,7 @@ const createFSMachine = ( ) } - const log = expr => (ctx, action) => { + const log = expr => (ctx, action, meta) => { if (ctx.bootstrapped) { reporter.info(expr(ctx, action, meta)) }