Closed iliakan closed 10 years ago
Hey, sorry it's taken me so long to get to this.
Could you please explain why it's necessary to delete from the cache for this to work?
Also, this feels like a change that would warrant a test or two, but I'm not sure how to test it. Going to have a play around with this myself at some point.
Thanks for the PR :)
Hi Jack,
Thanks again for your module, I really enjoy using it.
As to your question: modules in Node.JS are required and executed only the first time, then their objects are cached and when required from another place - the corresponding object is retrieved from the cache. We all rely on that.
So, module.parent
always corresponds to the parent at the time of the 1st require.
To see the right parent every time, I need to nuke the cache and make Node.JS reevaluate the module each time it is required.
That may seem an overhead, but we're talking about re-evaluating of a single js-file, not every module that it (in turn) may want to require. So, that's very fast anyway.
Right now I'm using the patch and can't see any problems. But I guess it deserves a version bump to 0.6, just because it changes the search order (to the correct one).
@iliakan sorry it's taken me so long to get back to you, huge apologies for that.
This all looks good to me but I'd love some second opinions on it just to make sure. @sindresorhus ?
:+1:
Thanks! I'll test this locally this evening and then publish a new version :)
@iliakan this is now published in 0.6. Thank you!
Make it search
package.json
for the module which required it, not for project root.Followup to #35, works for me.