Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[1.0] During bootstrap, detect if plugins have changed and delete the cache #927

Merged
merged 8 commits into from
May 6, 2017
Prev Previous commit
Next Next commit
Add notice when the site's cache is deleted
  • Loading branch information
KyleAMathews committed May 6, 2017
commit 43a3774e91455f5b069cb0e2bbc9433c7d29c733
1 change: 1 addition & 0 deletions examples/gatsbygram/gatsby-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ exports.createPages = ({ graphql, boundActionCreators }) => {
},
})
})

resolve()
})
})
Expand Down
15 changes: 11 additions & 4 deletions packages/gatsby/lib/bootstrap/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,17 @@ module.exports = async (program: any) => {
const state = store.getState()
const oldPluginsHash = state && state.status ? state.status.PLUGINS_HASH : ``

// If there's an plugin hash stored in the cache already, check if
// anything has changed. If it has, delete the site's .cache directory
// and tell reducers to empty themselves.
if (oldPluginsHash && pluginsHash !== oldPluginsHash) {
// Check if anything has changed. If it has, delete the site's .cache
// directory and tell reducers to empty themselves.
//
// Also if the hash isn't there, then delete things just in case something
// is weird.
if (!oldPluginsHash || pluginsHash !== oldPluginsHash) {
console.log(`
One or more of your plugins have changed since the last time you ran Gatsby. As
a precaution, we're deleting your site's cache to ensure there's not any stale
data
`)
await fs.remove(`${program.directory}/.cache`)
// Tell reducers to delete their data (the store will already have
// been loaded from the file system cache).
Expand Down