istanbuljs / append-transform

handle multiple require hooks
MIT License
21 stars 4 forks source link

Fix the API #3

Closed jamestalmage closed 8 years ago

jamestalmage commented 8 years ago

Right now, this is the API:

var captureRequire = require('capture-require');
var transform = require('my-transform');

captureRequire(function(module, source, file) {
  module._compile(transform(source), file);
});

I don't like it. It suggests your allowed to do some shenanigans like replace module._compile.

I think it should be more like pirates, with just a simple transform:

captureRequire(function(source, filename) {
  return transform(source);
});

I think I will avoid a filter function option though, since you can just do this:

captureRequire(function(source, filename) {
  if (shouldApply(filename)) {
    source =  transform(source);
  }
  return source;
});

I will put something about node-modules-regexp in the docs for people who want to avoid node_modules. I just think almost anyone who uses this isn't going to be well served by a boolean avoidNodeModules setting (nyc would certainly disable that feature).

// @novemberborn, @bcoe

novemberborn commented 8 years ago

:+1:

sindresorhus commented 8 years ago

:+1:

jamestalmage commented 8 years ago

Just published append-transform@0.2.0 with these changes. Thanks.