Skip to content

Commit 0fda1e6

Browse files
authored
fix(gatsby-source-filesystem): fix add/change text (#20188)
1 parent 84139bf commit 0fda1e6

File tree

1 file changed

+33
-13
lines changed

1 file changed

+33
-13
lines changed

packages/gatsby-source-filesystem/src/gatsby-node.js

+33-13
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,12 @@ const createFSMachine = (
5353
)
5454
}
5555

56+
const log = expr => (ctx, action, meta) => {
57+
if (meta.state.matches(`BOOTSTRAP.BOOTSTRAPPED`)) {
58+
reporter.info(expr(ctx, action, meta))
59+
}
60+
}
61+
5662
const fsMachine = Machine(
5763
{
5864
id: `fs`,
@@ -85,9 +91,32 @@ const createFSMachine = (
8591
},
8692
READY: {
8793
on: {
88-
CHOKIDAR_ADD: { actions: `createAndProcessNode` },
89-
CHOKIDAR_CHANGE: { actions: `createAndProcessNode` },
90-
CHOKIDAR_UNLINK: { actions: `deletePathNode` },
94+
CHOKIDAR_ADD: {
95+
actions: [
96+
`createAndProcessNode`,
97+
log(
98+
(_, { pathType, path }) => `added ${pathType} at ${path}`
99+
),
100+
],
101+
},
102+
CHOKIDAR_CHANGE: {
103+
actions: [
104+
`createAndProcessNode`,
105+
log(
106+
(_, { pathType, path }) =>
107+
`changed ${pathType} at ${path}`
108+
),
109+
],
110+
},
111+
CHOKIDAR_UNLINK: {
112+
actions: [
113+
`deletePathNode`,
114+
log(
115+
(_, { pathType, path }) =>
116+
`deleted ${pathType} at ${path}`
117+
),
118+
],
119+
},
91120
},
92121
},
93122
},
@@ -96,16 +125,10 @@ const createFSMachine = (
96125
},
97126
{
98127
actions: {
99-
createAndProcessNode(_, { pathType, path }, { state }) {
100-
if (state.matches(`BOOTSTRAP.BOOTSTRAPPED`)) {
101-
reporter.info(`added ${pathType} at ${path}`)
102-
}
128+
createAndProcessNode(_, { pathType, path }) {
103129
createAndProcessNode(path).catch(err => reporter.error(err))
104130
},
105131
deletePathNode(_, { pathType, path }, { state }) {
106-
if (state.matches(`BOOTSTRAP.BOOTSTRAPPED`)) {
107-
reporter.info(`${pathType} deleted at ${path}`)
108-
}
109132
deletePathNode(path)
110133
},
111134
flushPathQueue(_, { resolve, reject }) {
@@ -128,11 +151,8 @@ exports.sourceNodes = (api, pluginOptions) => {
128151
if (!fs.existsSync(pluginOptions.path)) {
129152
api.reporter.panic(`
130153
The path passed to gatsby-source-filesystem does not exist on your file system:
131-
132154
${pluginOptions.path}
133-
134155
Please pick a path to an existing directory.
135-
136156
See docs here - https://www.gatsbyjs.org/packages/gatsby-source-filesystem/
137157
`)
138158
}

0 commit comments

Comments
 (0)