This repository was archived by the owner on Feb 26, 2024. It is now read-only.
Invalidate require cache when loading config files
#5728
Closed
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.
PR description
This PR solves an issue related with
TruffleConfig.loadwhen@truffle/configis used as a package. The issue happens when re-requiring Truffle config files in webpacked versions. More specifically, when trying torequirethe same config file more than once, the second time does not reflect any changes made since first therequire.The solution involves using the same
original-requireto both invalidate therequirecache and re-load the Truffle config file. The problem was thatoriginal-requirewas only used to load the Truffle config file, but not to invalidate its cache.Background
The
deletecache was in from the very beginning, see this blame https://github.com/trufflesuite/truffle/blame/15e7eb87d4659f7b520ea1658e9a833f132567d4/packages/truffle-config/index.js#L244.And in this commit fc455d9, the
require("require-nocache")was removed and replaced with the current code.Testing instructions
The issue with testing this PR end-to-end is that it only manifest in the bundled version, but not using the CLI.. For this reason I've created a gist containing a sample repo
https://gist.github.com/acuarica/c9c1ae1e4da22ef78d56b48e9757a67c
The unbundled and bundle versions return different results. The unbundled version works as expected, i.e., reflects changes made to Truffle config, however the bundled version does not. You can check this by running the following in the above repo
and then
should have the same output, but displays different networks.
For completion, a unit test is included to check for re-loading config files.
Documentation
doc-change-requiredlabel to this PR if documentation updates are required.Breaking changes and new features
breaking-changeandnew-featurelabels for the appropriate packages.