Munter / grunt-reduce

A grunt kitchen that reduces your web ingredients down to their essence for optimal serving. Bon appétit!
MIT License
184 stars 13 forks source link

Invalid flags supplied to RegExp constructor 'div' #7

Closed matthewwithanm closed 10 years ago

matthewwithanm commented 10 years ago

I have a project for which I've used Bower to install Backbone. It pulls down a bunch of garbage files (examples, tests, and docs). Normally, these files don't do any harm, however, assetgraph seems to be including one of the HTML files (backbone.localstorage.html), trying to parse it as JavaScript, and failing.*

I'm not really sure why this file is being included in the first place (it's definitely not loaded by the file I'm specifying in the include option) and whether that's a bug. If not, is there a way to explicitly exclude files? My expectation was that I could use normal negated patterns in my minimatch list, but that doesn't appear to be the case.

Thanks!

* Invalid flags supplied to RegExp constructor 'div' include: [**/*.html', '!assets/vendor/**/*.html']

Munter commented 10 years ago

Ah, I can see how you would make that assumption. I'm pretty sure I've done that before as well.

The include list is a positive match only at the moment. However assetgraph populates all html-files that are linked together by anchors, so for most applications you can get away with just /*.html which would match index.html, any other html-ile in the root, like error pages, and then follow all links.

I think implementing a proper minimatch pattern with options of negative matching is a very god idea though. I'll take a look at it some time when my current project is done.

matthewwithanm commented 10 years ago

I figured that was the case when I got the error, so I tried just including my index, however it still (tried to) include Backbone's documentation HTML. (I'm definitely not linking to it anywhere in index or any of my files.)

Any idea why this would be happening? Also, any idea why it would be trying to parse it as JavaScript?

Thanks for the help!

Munter commented 10 years ago

Now that does sound quite wrong. Since I don't have your directory structure readily available I'm having difficulties getting a good intuition about why this might be. Could you try to install https://github.com/Munter/assetviz and run it with the same match pattern that you give grunt-reduce? That will output an assetviz.html for you with a force directed graph visualization of the assets that are in the graph before the build runs. You might find a stray relation, or at least an easier fix to your match pattern like that.

Note on assetviz: It doesn't follow anchor relations at the moment. i should really add that.

But if you could pate the output of tree in your app directory that might be helpful as well

matthewwithanm commented 10 years ago

Strangely, assetviz doesn't seem to include the backbone file.

As far as pasting the tree output, my project is ginormous. However, it seems like the issue is easily reproducible:

#!/usr/bin/env bash
mkdir app
npm install grunt grunt-cli grunt-reduce@0.1.8 bower
echo '{"directory": "app/bower_components"}' > .bowerrc
bower install backbone

Then create an empty index.html in app and a Gruntfile.coffee in the root like this:

module.exports = (grunt) ->

  grunt.initConfig
    reduce:
      root: 'app'
      outRoot: 'app-reduced'
      include: ['index.html']
      less: false
      optimizeImages: false
      asyncScripts: false

  grunt.loadNpmTasks 'grunt-reduce'

The structure will look like this:

.
├── .bowerrc
├── Gruntfile.coffee
└── app
    ├── bower_components
    └── index.html

When you run grunt reduce, you'll get the error.

Munter commented 10 years ago

Stupid me. The default configuration was always inherited, where it should only be used if no include array of match patterns is defined. Should be fixed in v1.1.10

matthewwithanm commented 10 years ago

Awesome, thanks!