joeybaker / remapify

Alias directories for browserify
Other
117 stars 23 forks source link

adds filter option for filename tweaks #9

Closed zachwolf closed 10 years ago

zachwolf commented 10 years ago

While working with browserify, I've found it useful to prefix files that I don't want being compiled with an underscore like _avatar.js or _description.js mentioned in your readme. However, I don't want to have to have the underscores in the require statements like require('_avatar.js');. I couldn't find a way to do this as of now, so I added an option with the task to tweak file names and add them to expandedAliases.

For example:

b.plugin(remapify, [
  {
    src: './**/*.js'
    , filter: function(fileName) {     // fileName is passed as something like `./foo-dir/_bar-file.js`
      return (/\/?((?:.(?!\/))+)$/)    // regex for everything after the last '/' in the file name
                .exec(fileName)[1]     // get file name from `exec` method
                .replace(/^\_/, '')    // replace leading underscore
                .replace(/\.js$/, ''); // replace file extension
    }
  }
]);

I played around with using the remapify:file event, but I felt like this was a cleaner way. What are your thoughts on this? Is there an easier way that I missed?

joeybaker commented 10 years ago

Interesting – thanks! I hadn't considered this use case. I just published v1.0.0 which changed some things and this can no longer merge cleanly. Can you resolve the conflicts and I'll take a look?

zachwolf commented 10 years ago

I pulled your repo to get the latest and re added the filter option changes so it should be able to merge cleanly. I'm not familiar with the Travis build process, is there something else I need to do to make sure everything is working?

joeybaker commented 10 years ago

@zachwolf I like this idea. I played around with switching to multi-glob in the multi-glob branch, but that turns out to be more complex in many ways.

Problems I encountered:

@zachwolf I'd like to merge this, but it looks like your merge didn't quite go smoothly (you've got some of my commits in there. Can you maybe rebase and get everything into one commit?

zachwolf commented 10 years ago

I pushed the rebased commits. It looks like Travis is complaining about tests not passing, but I'm un able to duplicate the issue locally. So, I'm not sure what I can do to fix that.

Were the issues you mentioned about issues with my solution or with the multi-glob solution?

joeybaker commented 10 years ago

@zachwolf Thanks!. Looks like travis is saying one of your newly added tests failed in node 0.10 https://travis-ci.org/joeybaker/remapify/jobs/33766841. I'll try it myself to see it if was just a weird travis error.

The problems I was talking about were with multi-glob, not your stuff!

I'll take a look at the tests later and merge. Thanks!

zachwolf commented 10 years ago

Awesome :)

That's odd, I ran all the travis commands in order to get the repo in the same state and it still is passing for me. If you're able to replicate the issue I will spend some time trying to get it to break for me as well.

joeybaker commented 10 years ago

Hey @zachwolf I finally got around to checking this out. There is a failing test for me locally too. . It looks like this is a simple merge error. There are two tests for the filter option. Can you fix?

zachwolf commented 10 years ago

That makes sense, it was my first attempt at rebase. Fixed and pushed, looks like travis is passing now.

joeybaker commented 10 years ago

Merged. Thanks @zachwolf!