jashkenas/coffee-script — pull request #3000 by sgentle (2013-05-25 13:56:27+00:00)
Title: Patch module.prototype.load to enable multiple extensions like .coffee.md

Okay, here it is.

I spent a bit of time thinking about how best to make this both past and future safe. I don't want to clobber anyone else's patch to the module loader, in case they're doing that for some good reason. I also want to have it fail gracefully if (heaven forfend!) the module loader code is ever changed in node.

The last modification to module.prototype.load was joyent/node@46513483cd96438f33a67fb870b784d1d1f55dd0 - 2 years ago on node 0.3.8 for the inclusion of node_modules. So in the end I just included the source for the original function and did a string comparison. If someone wants to run coffee-script on a node earlier than that I suspect they will have other problems.

Obviously this will get a little hairy if multiple projects end up using the same technique. In that case, mediating between them would need to fall to some more complex arrangement which is a bit out of scope for what we need. If a system like that were implemented in another module, though, it would correctly trip the string comparison here, so I feel like this is fairly future-proof.

The only other thing is testing. I've just basically copied tests/importing.coffee to importing.coffee.md which failed and now passes, but that's not exactly comprehensive. I ran the original code through the node tests when it was a pull request against node. Should I attempt to duplicate some of those tests here?

Comments welcome!