-
-
Notifications
You must be signed in to change notification settings - Fork 27
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Some proposals for changes before this module starts getting used everywhere #3
Comments
Also while we are at it, why do you need the |
I agree with |
@gotwarlost: I agree too, This looks great. I'll do impliment this first thing tomorrow morning. |
Thinking about this some more, it seems to me that we don't need a separate |
@ariporad nice! Great to see a common solution rather than each project reinventing the wheel. Why does Agreed with @gotwarlost to implement exclusions using custom matchers. As Babel, nyc etc have their own config, only they know how to do correctly exclude modules. But if each library using If the default exclusions are kept then it should match on the path separators, e.g. The code calls From #1:
Could you elaborate on this? nyc uses the setter to detect the custom require hooks. If it switches to pirates` it won't be compatible with code that does not (yet) use pirates. Why makes that code "naughty"? |
The tests involve some stuff which should be hooked, and some which shouldn't. I agree the regex is iffy, (that's why it's undocumented). I'd like to remove it, but I'm not sure how. Noted, will do. Yes, the log is a problem, I'll fix it. No, I don't think it should crash, because as someone who has had to deal with misbehaving require hooks before, I'd rather it scream but still work. Maybe there can be a Actually, NYC is one of the bad ones. Here's the way to properly implement a require hook (it's what pirates does): var oldLoader = Module.extensions[ext] || Module.extensions['.js'];
Module.extensions[ext] = function (mod, filename) {
var _compile = mod._compile;
mod._compile = function (code, filename) {
code = this.instrument(code);
_compile(code, filename);
}
oldLoader(mod, filename);
} This will work for any number of hooks, because it's just injecting a step in between the loader and _compile. NYC does something similar, but it does it in a way so that only two hooks (nyc and something else) can be active at any time. It does this by basically intercepting new loaders, then wrapping that new loader as above. The part that they do wrong is they call Babel does even worse. Babel never calls old loader (which means it never even goes into the node.js code), it just calls fs.readFileSync, then transpiles the result, then So by switching to pirates, nyc would actually gain compatibility, not loose it. And over the course of doing this, I've noticed that the problem is not that require hooks don't work together, it's that most are implemented wrong (Shout out to istanbul, who did it 110% perfectly). |
To the point made by @novemberborn - I think we should leave out the node_modules logic out of pirates. Also the regexp can have unintended consequences - for example if the hook is applied after bundling a bunch of files through browserify for example , the entire bundle will be ignored because one file has the Pirates comment in it. Not to mention that running a regexp over a massive bundle is likely to be horribly expensive. I don't think we should support the Pirates comment for these reasons |
@gotwarlost: As I said, I agree. I think what I'll do for V2 is get rid of the regex. The reason it was there is that I needed a way to ignore the test compilers. I wanted to put them in |
Ok, @gotwarlost, @jamestalmage @novemberborn: I think I've properly implemented all your suggestions, take a look at the |
Also, here's a todo list, for the milestone:
|
Could we simplify the method signature of the hook function and make it extensible for future changes instead of doing the dance in the parse args method? I like the idea of moving the matcher into a configuration setting, and default to perhaps @ariporad great work so far, I think it's great to be pulling this logic into a common module., a couple initial comments:
This is looking slick! |
@bcoe: agree on the tests, but your bit about adoption is incorrect. If everyone had a properly written require hook, like istanbul, there would be no need for this, but everyone doesn't. Both babel and nyc have require hooks that are implemented improperly. (See above for a more detailed explanation). So NYC's getters and setters are actually hurting compatibility, not helping it. |
@ariporad I now fully grok what you're getting at. As soon as we get babel using a more compliant require hook I'd happily simply |
EDIT: I am wrong, never mind. |
Wrong on the first part (it uses |
@jamestalmage: Oops! You're right! My bad! |
@ariporad |
If I happen to catch the log message, even though my program appears to work correctly, I'm going to have to investigate to make sure. If I don't catch the message I won't investigate and my program may not work correctly. Thus I'd rather it crashes. Fixing it should be easy enough (remember: I should be investigating the problem anyway) and then I can have more confidence in my program. A strict option doesn't really help here, now I need to know that some dependency used pirates and I need to somehow configure it to be strict if it doesn't do so already.
nyc hacks child process spawning to inject itself at the very top of the new process. Consequently it's require override is meant to be the first, no earlier hooks can exist. I appreciate it's not a perfect hook implementation but it's sufficient for its purposes. Without observing getters and setters for |
@novemberborn: Ok, I see what you mean on the crashing. I'll make it As for the getters/setters for NYC:
|
Cool!
Yea, @jamestalmage's write-up made that a lot clearer for me. |
where
hook
is the hook to be added, the only required argument (that hooks.js
files by default) andopts
is an optional object withextensions
andmatcher
properties supported on it.node_modules
logic in your code. istanbul, for instance, allows you to disregard its default excludes and hook all files under node_modules as well. You could support ahookNodeModules
property that is false by default but can be turned on by the caller.cc @bcoe @jamestalmage @novemberborn for inputs
The text was updated successfully, but these errors were encountered: