chore(project-sync): Fix infinite looping due to package.json changes #11341
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Recently more of our build commands have adopted temporarily modifying the package.json file in order to generate the correct types. This has resulted in
yarn rwfw project:sync
going into an infinite loop as it detects changes as result of a build and triggers another build in response.Chokidar is debouncing events so we only receive them once the watcher function has completed. Here I simply add a small 8s period of time after a build completes where any events it registers for package.json files (which should include those gathered during the build itself) are ignored.
The false negative case here is that someone changes a package.json soon after a build completes or during when a build is running. In that case it won't be picked up. People will likely see that no sync happened and just hit save again triggering a build since the 8s will have elapsed.