Skip to content

Commit 42ed5ef

Browse files
authored
fix(plugin-schema-snapshot): unlink file on init (#34527)
1 parent 195188c commit 42ed5ef

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

packages/gatsby-plugin-schema-snapshot/gatsby-node.js

+17-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,21 @@
11
const fs = require(`fs`)
22
const path = require(`path`)
33

4+
exports.onPluginInit = ({ reporter }, options = {}) => {
5+
const filePath = path.resolve(options.path || `schema.gql`)
6+
try {
7+
if (fs.existsSync(filePath) && options.update) {
8+
fs.unlinkSync(filePath)
9+
reporter.info("Removed schema file")
10+
}
11+
} catch (error) {
12+
reporter.error(
13+
`The plugin \`gatsby-plugin-schema-snapshot\` encountered an error`,
14+
error
15+
)
16+
}
17+
}
18+
419
exports.createSchemaCustomization = ({ actions, reporter }, options = {}) => {
520
const { createTypes, printTypeDefinitions } = actions
621

@@ -21,15 +36,15 @@ exports.createSchemaCustomization = ({ actions, reporter }, options = {}) => {
2136
createTypes(schema, { name: `default-site-plugin` })
2237

2338
if (options.update) {
24-
fs.unlinkSync(filePath)
2539
printTypeDefinitions(options)
2640
}
2741
} else {
2842
printTypeDefinitions(options)
2943
}
3044
} catch (error) {
3145
reporter.error(
32-
`The plugin \`gatsby-plugin-schema-snapshot\` encountered an error`, error
46+
`The plugin \`gatsby-plugin-schema-snapshot\` encountered an error`,
47+
error
3348
)
3449
}
3550
}

0 commit comments

Comments
 (0)