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

fix(gatsby): invalidate cache in more conditions, e.g. require statements #9

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

DSchau
Copy link
Owner

@DSchau DSchau commented Mar 14, 2019

Description

This is a very WIP PR that will use babel-traverse to parse the AST of various files (e.g. gatsby-config.js, gatsby-node.js, etc.) and invalidate the cache when require'd files change, rather than just if the files themselves change.

For instance, given the following gatsby-node.js:

exports.createPages = require('./gatsby/create-pages')

Prior to this functionality, if we were to make a change to ./gatsby/create-pages, gatsby is none the wiser and will not invalidate the cache.

I did this pretty briefly, so I know it's not ready for prime time, but if someone wants to take this and run with it--would be great!

Known Issues

  • In brief (manual) testing, did not seem to invalidate appropriately in all cases
  • Should have some type of integration/e2e test to validate functionality
  • algorithm is slightly naive in some circumstances, e.g. it presumes gatsby-config.js require statements are in the export, rather than just looking for all relative require statements

Related Issues

gatsbyjs/gatsby@11952

This PR improves the cache invalidation algorithm. Rather than merely
relying on the content of the files, it now will attempt to parse
require statements in gatsby-config.js or gatsby-node.js, and add those
required files as hashes used to invalidate.

Particularly, this will help solve cache invalidation on something like
reactjs/reactjs.org, where pieces of gatsby-node.js are in disparate
require'd files, which will not currently invalidate the cache upon
changing
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant