Skip to content
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

Initial Discussion #1

Closed
ariporad opened this issue Dec 4, 2015 · 1 comment
Closed

Initial Discussion #1

ariporad opened this issue Dec 4, 2015 · 1 comment

Comments

@ariporad
Copy link
Collaborator

ariporad commented Dec 4, 2015

Hi All,
Just continuing istanbuljs/nyc#70 and babel/babel#3062.

To recap: I will be taking ideas from istanbul's and nyc's require-hook implementations, and trying to make something that:

  1. Super easy require-hook injection, with a super simple API that Just Works(tm), feeding hooks into each other in the order they are added. API concept:

    var pirates = require('pirates');
    
    // ...
    
    pirates.addCompiler('.js', function (filename) {
       return filename.indexOf('foo') !== -1;
    }, function (module, filename) {
        return this.addFile(module, filename).content; // Just return the new source for the module.
    });
  2. Using getters/setters, automatic fixing of hooks that don't use pirates, and still passing all requires through the hooks in order. API concept:

    require('pirates/register');
    // For some weird reason, part of my app is in coffee script, and some is in ES6.
    require('coffee-script/register');
    require('babel-core/regsister');
    require('some-bad-module/register');
  3. ???

Discuss.

cc @bcoe, @gotwarlost, @stefanpenner, @jamestalmage, @sebmck

@ariporad
Copy link
Collaborator Author

ariporad commented Dec 6, 2015

Ok everyone, I got pirates mostly done! It's now available on npm, and I've opened pull requests for babel (babel/babel#3139) and istanbul (istanbuljs-archived-repos/istanbul-lib-hook#5), and a PR for nyc is in the works. If you have any other modules you like that use require hooks, convince them to adopt pirates! It's super easy and reduces complexity!

After looking into having getters and setters for dealing with naughty require hooks, I ended up dropping that idea (for now), because basically any hook that misbehaves is using Module.prototype._compile instead of module._compile, which I haven't been able to figure out how to fix.

Since Pirates@1.0.0 has been released, I'm going to close this.

Enjoy!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant