Improve support for custom require hooks#65
Merged
Conversation
Let the custom hook decide which modules it wants to ignore. For example Babel lets you customize this beyond node_modules. Custom hooks often store the hook they're replacing, and may call this hook when loading a module (e.g. if they decide to ignore that particular module). Hooks may also be removed, restoring the original hook. Libraries like proxyquire always fall back to the original hook but modify the module object. The implementation was changed to: * always pass the original module object to the custom hook * support restoring older hooks * correctly compile the code by using Module.prototype._compile
Member
|
@novemberborn this is looking great, thanks for the contribution! I'll have some comments after the work day today. |
Member
There was a problem hiding this comment.
I love this approach, much cleaner than what I was doing before -- also I think that it fixes the issue I was originally having that required me to ignore the node_modules folder -- great job.
Member
|
@novemberborn this is great work, and I think we're sufficiently covered by the existing test cases -- I also tested it on several libraries I've instrumented with nyc (yargs, async, pageres, yarsay). I say |
bcoe
added a commit
that referenced
this pull request
Dec 1, 2015
Improve support for custom require hooks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
First of, thanks for adding source map support! I've been trying to use
nyc@4with the project that lead to my code coverage article from last week. I got it working but had to make some changes. This is the first PR which covers the custom require hook implementation.The custom hook should decide which modules it wants to ignore. For example Babel lets you customize this beyond just
node_modulesusing theonlyandignoreoptions.Custom hooks often store the hook they're replacing, and may call this hook when loading a module (e.g. if they decide to ignore that particular module). Hooks may also be removed, restoring the original hook. Libraries like proxyquire always fall back to the original hook but modify the module object.
The implementation was changed to:
Module.prototype._compileIt's getting late in the day in my timezone so I haven't had a chance to update the tests to cover this new behavior. The test suite in my own project passes though when run under
nycso that's encouraging.