Skip to content

Invalidate cache on config and environment variable changes#521

Merged
devongovett merged 3 commits intomasterfrom
config-cache
Jan 10, 2018
Merged

Invalidate cache on config and environment variable changes#521
devongovett merged 3 commits intomasterfrom
config-cache

Conversation

@devongovett
Copy link
Member

Closes #297. Fixes #66.

This PR does three things:

  1. Adds config files as dependencies. This means that they are automatically watched, so for example if you change your .babelrc, Parcel will immediately recompile all files that depend on it. Also, if you restart Parcel after making changes, those files will also be recompiled (since Invalidate cache when dependencies included in parent change #514).
  2. Adds a cacheData object to assets, and a shouldInvalidate method which accepts a cacheData object to compare. If it returns false, the asset is re-generated. JSAsset uses this to implement environment variable cache invalidation. If your JS file has process.env.MY_ENV, and you change MY_ENV to a new value, the cache will be invalidated.
  3. Fixes an issue where assets that have multiple parents that include them weren't recompiled on change. For example, if you had a stylus file that was @imported by several parents, only one of them would get recompiled when that file changed. This also affected .babelrc and other config changes, etc.

so they are watched and invalidate the cache
This adds a cacheData object to Assets, and a shouldInvalidate method which accepts a cacheData object to compare. If it returns false, the asset is re-generated. JSAsset uses this to implement environment variable cache invalidation.
For example, if you had a stylus file that was @imported by several parents, only one of them would get recompiled when that file changed. This also affected .babelrc and other config changes, etc.
this.cacheData.env = {};
}

shouldInvalidate(cacheData) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This causes an error on existing builds (as they already have cache files) and cacheData is undefined in these files.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm yeah, but should be ok with the npm version since the parcel version is part of the cache key right? so when people update parcel, everything will be invalidated already.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ow forgot about that, yeah should be fine

@devongovett devongovett merged commit 6c3d34f into master Jan 10, 2018
@devongovett devongovett deleted the config-cache branch January 10, 2018 07:04
devongovett added a commit that referenced this pull request Oct 15, 2018
Invalidate cache on config and environment variable changes
devongovett added a commit that referenced this pull request Oct 15, 2018
Invalidate cache on config and environment variable changes
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.

2 participants