diff --git a/packages/gatsby-source-filesystem/src/gatsby-node.js b/packages/gatsby-source-filesystem/src/gatsby-node.js index 13f40ecb16af5..7a4a42d48b240 100644 --- a/packages/gatsby-source-filesystem/src/gatsby-node.js +++ b/packages/gatsby-source-filesystem/src/gatsby-node.js @@ -53,6 +53,12 @@ const createFSMachine = ( ) } + const log = expr => (ctx, action, meta) => { + if (meta.state.matches(`BOOTSTRAP.BOOTSTRAPPED`)) { + reporter.info(expr(ctx, action, meta)) + } + } + const fsMachine = Machine( { id: `fs`, @@ -85,9 +91,32 @@ const createFSMachine = ( }, READY: { on: { - CHOKIDAR_ADD: { actions: `createAndProcessNode` }, - CHOKIDAR_CHANGE: { actions: `createAndProcessNode` }, - CHOKIDAR_UNLINK: { actions: `deletePathNode` }, + CHOKIDAR_ADD: { + actions: [ + `createAndProcessNode`, + log( + (_, { pathType, path }) => `added ${pathType} at ${path}` + ), + ], + }, + CHOKIDAR_CHANGE: { + actions: [ + `createAndProcessNode`, + log( + (_, { pathType, path }) => + `changed ${pathType} at ${path}` + ), + ], + }, + CHOKIDAR_UNLINK: { + actions: [ + `deletePathNode`, + log( + (_, { pathType, path }) => + `deleted ${pathType} at ${path}` + ), + ], + }, }, }, }, @@ -96,16 +125,10 @@ const createFSMachine = ( }, { actions: { - createAndProcessNode(_, { pathType, path }, { state }) { - if (state.matches(`BOOTSTRAP.BOOTSTRAPPED`)) { - reporter.info(`added ${pathType} at ${path}`) - } + createAndProcessNode(_, { pathType, path }) { createAndProcessNode(path).catch(err => reporter.error(err)) }, deletePathNode(_, { pathType, path }, { state }) { - if (state.matches(`BOOTSTRAP.BOOTSTRAPPED`)) { - reporter.info(`${pathType} deleted at ${path}`) - } deletePathNode(path) }, flushPathQueue(_, { resolve, reject }) { @@ -128,11 +151,8 @@ exports.sourceNodes = (api, pluginOptions) => { if (!fs.existsSync(pluginOptions.path)) { api.reporter.panic(` The path passed to gatsby-source-filesystem does not exist on your file system: - ${pluginOptions.path} - Please pick a path to an existing directory. - See docs here - https://www.gatsbyjs.org/packages/gatsby-source-filesystem/ `) }