Improves compatibility with resolve
#665
Merged
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.
What's the problem this PR addresses?
The
resolve
package has a mechanism to allow for outsider resolvers to inject themselves into the resolution process, which is a specific file (namednormalize-options.js
) that they are allowed to modify as they wish.Our past implementation was injecting the logic within the PnP hook. While it worked mostly fine, it caused an interesting problem when using
resolve
from within Jest: Jest runs all code from within a sandbox it manages itself, preventing the PnP hook to patch the result of the require call. As a result,resolve
didn't knew anything about PnP when run from within a Jest process (browserify/resolve#199 (comment)).Additionally, my diff adding support for the
patch:
protocol caused regressions in the install time (in particular for large packages such asflow-bin
which took 6m+ just to be fetched, instead of the previous ~4m).How did you fix it?
As I seem to be doing a bit too much, this diff contains various changes:
The libzip is now compiled without
ASSERTIONS=1 SAFE_HEAP=1
. After removing those flags, the install time forflow-bin
went down to ... 40s 🤯 Don't leave debug flags if you don't need them for real, kids.The
normalize-options.js
file is now patched through thepatch:
protocol rather than being replaced at runtime. This way it'll work just fine in Jest, as Jest will run the patched code instead of the original one.Patch files applied with the
patch:
protocol now support a new file directive calledsemver exclusivity
. The way it works: if the target package doesn't match the specified semver range, the file operation will be dropped. This allow you to make patches targeting different versions of a same package (for example,normalize-options.js
isn't available pre-1.9).