Skip to content

Commit

Permalink
Refactor meta.state access in gatsby-source-filesystem (#36355)
Browse files Browse the repository at this point in the history
Co-authored-by: Lennart <lekoarts@gmail.com>
  • Loading branch information
Andarist and LekoArts committed Aug 10, 2022
1 parent efb5d12 commit 84db263
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions packages/gatsby-source-filesystem/src/gatsby-node.js
Original file line number Diff line number Diff line change
@@ -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`)
Expand Down Expand Up @@ -61,14 +61,17 @@ const createFSMachine = (
}

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

const fsMachine = createMachine(
{
predictableActionArguments: true,
context: {
bootstrapped: false,
},
id: `fs`,
type: `parallel`,
states: {
Expand All @@ -82,6 +85,7 @@ const createFSMachine = (
},
BOOTSTRAPPED: {
type: `final`,
entry: assign({ bootstrapped: true }),
},
},
},
Expand Down Expand Up @@ -151,8 +155,7 @@ const createFSMachine = (
},
}
)
const machineInstance = interpret(fsMachine).start()
return machineInstance
return interpret(fsMachine).start()
}

exports.pluginOptionsSchema = ({ Joi }) =>
Expand Down

0 comments on commit 84db263

Please sign in to comment.