What does `{,*/}` mean in paths of Gruntfile.js?
Asked Answered
F

4

17

In Gruntfile.js, I have got:

watch: {
    styles: {
      files: [
        '<%= yeoman.app %>/styles/{,*/}*.less'
      ],
      tasks: ['copy:styles', 'autoprefixer']
    }
}

For the path, what does {,*/} mean indeed? How does it differ to using double asterisks **/?

Frawley answered 21/10, 2013 at 3:26 Comment(0)
M
14

This pattern is widely used in yeoman templates: it means to look only one level deep inside folder hierarchy. It is used mostly for performance reasons since watching too many files simultaneously can be slow (or even impossible).

Minton answered 21/10, 2013 at 9:10 Comment(5)
Thanks for mentioning Yeoman specifically. Do you have a reference to the performance issues?Think
Thanks for the reference, though it appears that the concern was more about the total number of file watches, irrespective of the depth of the directories.Think
I guess so, but less depth => less files (generally). Anyway, I don't think this approach is any good, because it trades correctness for performance.Minton
So, based on this, whats the difference between using {,*/} and /*/ as I tried the single * and it worked fine in my grunt concat script...Rabblement
Can we use this pattern in grunt as well?Arris
R
28

These are globbing patterns for Grunt, supported by the node-glob and minimatch libraries.

Basically:

  • * matches any number of characters, but not /
  • ** matches any number of characters, including /, as long as it's the only thing in a path part
  • {} allows for a comma-separated list of "or" expressions

So, styles/{,*/}*.less matches the following files:

  • LESS files inside styles directory
  • LESS files inside direct sub-directories of styles directory (but no deeper)
Rowdyish answered 19/3, 2014 at 7:36 Comment(1)
Thank you! Save 2 hours for me. ;)Amero
M
14

This pattern is widely used in yeoman templates: it means to look only one level deep inside folder hierarchy. It is used mostly for performance reasons since watching too many files simultaneously can be slow (or even impossible).

Minton answered 21/10, 2013 at 9:10 Comment(5)
Thanks for mentioning Yeoman specifically. Do you have a reference to the performance issues?Think
Thanks for the reference, though it appears that the concern was more about the total number of file watches, irrespective of the depth of the directories.Think
I guess so, but less depth => less files (generally). Anyway, I don't think this approach is any good, because it trades correctness for performance.Minton
So, based on this, whats the difference between using {,*/} and /*/ as I tried the single * and it worked fine in my grunt concat script...Rabblement
Can we use this pattern in grunt as well?Arris
P
11

I believe you're using a minimatch pattern there.

The double asterisk is a glob that causes recursion into subdirectories.

The single asterisk only matches 0 or more characters in the current directory (it matches every character except the slash character).

For example, a/**/d will match a/b/c/d.

Pycnidium answered 21/10, 2013 at 4:5 Comment(0)
P
1

The answer is globbing-patterns .

The other answers had already answer what does{,*/}* mean.

But the different between **/ and {,*/}* is folder depth.

  • /styles/{,*/}*.less has been divided into two situation

    1. /styles/*.less
    2. /styles/*/*.less

For example

/styles/{,*/}*.less will match /styles/x.less (situation 1)

/styles/{,*/}*.less will also match /styles/test/x.less (situation 2)

But /styles/{,*/}*.less can't match /styles/test/test1/x.less

But /styles/**/*.less can do that

Pressey answered 16/8, 2017 at 7:39 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.