cdnizer icon indicating copy to clipboard operation
cdnizer copied to clipboard

minimatch (via ./lib/utils/findFileInfo.js) not working properly

Open joaocc opened this issue 10 years ago • 1 comments

I have been trying to get this to work with our project, but with no luck.

.tmp/serve/index.html

     <script src="../bower_components/angular/angular.js"></script>

cdnizer options

var cndizerOpts =
  {
    allowRev: false,
    allowMin: false,
    files: [
      'google:angular'
    ]
  };

folder structure

(root)
    packages.json
    bower.json
    .bowerrc
    gulpfile.js
    gulp
        cdnizer.js
    node_modules/
    bower_components/
    src/
        index.html    (not-injected)        
    .tmp/
        serve/
            index.html    (injected)

bower.json

{
  "dependencies": {
    "angular": "~1.4.5",

I added some console.log entries to try and troubleshoot the problem (./utils/findFileInfo()). It seems that the parsing is done correctly but minimatch says they are not matching:

in lib/util.js:findFileInfo, minimatch is called with what seem to be the right parameters, but returns null/false.

    url ===>>  "../bower_components/angular/angular.js"
    fileInfo.file ===>> "**/angular.js"

I also tried adding {dot: true} to the call to minimatch, but it still fails.

Any hints? Thx

joaocc avatar Sep 20 '15 09:09 joaocc

Not sure about fixing the specific issue, it looks like minimatch won't match ** against ../ unless it's explicitly included in the matcher.

The only solution I can think is to override the generated pattern by using:

files: [
    {
        // or you can be explicit and use `../bower_componentes/angular/angular.js`
        file: '../**/angular.js',
        cdn: 'google:angular'
    }
]

I can't find any practical way to fix it in a generic fashion within the code. I tried, but I couldn't make minimatch optionally match a relative parent (or, actually, any relative parent).

That really blows since relative paths aren't that uncommon. I'd basically have to make a special case for relative paths, and make extra matches. I suppose I could add an extra option for prefixing generated CDN paths, but it's pretty easy to override.

OverZealous avatar Sep 21 '15 02:09 OverZealous