curist / grunt-bower

grunt task to copy bower installed packages to other folder(s)
MIT License
93 stars 27 forks source link

Problems with relative paths for packages with single files #39

Closed sikoried closed 10 years ago

sikoried commented 10 years ago

I'm using bower to install jquery (2.1.0) and (e.g.) bootstrap, and then grunt bower with

build: {
    dest: 'build/bower_components',
    options: {
      expand: true
    }
  }

to install those components in build/bower_components. It works as expected for bootstrap, copying bower_components/bootstrap/{less,dist/css,dist/js}/* to build/bower_components/bootstrap/{less,dist/css,dist/js}/*, but it fails for jquery, copying bower_components/jquery/dist/jquery.js to build/bower_components/jquery/jquery.js, which in turn leads to problems when using grunt-wiredep (which expects jquery.js in dist/).

I tracked down the issue to tasks/bower.json:126, where there is an if-statement that treats those libs special, that only have one entry in src_path. For this (rare?) case, the subdirectory structure is (accidentally?) dropped. I managed to fix it by eliminating the if block and defaulting the else block (i.e. every lib is handled the same way, regardless of 1 or more src_path entries). As a result, subdirectory structure is preserved also for src_path.length===1.

Sorry, no pull-request, as I didn't run any tests on this, nor know if this would be the intended behavior. But it would be great if you could verify and patch this issue.

Thanks!

PS: I couldn't track down where the task gets it's list of files, and changes in the jquery's bower.json:main variable didn't affect the behavior. Would you mind pointing that out?

curist commented 10 years ago

It's actually something I always want to refactor. Features creep, and some code paths got forgotten. I'll try to get that code path to respect some options added lately.

For the list of files, you may want to check tasks/lib/helpers.js:40.

curist commented 10 years ago

Well, it seems eliminating the if block is the way to go, tests are good.