This repository has been archived by the owner. It is now read-only.

Bower: component.json requires #358

Merged
merged 6 commits into from Sep 19, 2012

Conversation

Projects
None yet
4 participants
@josh
Contributor

josh commented Sep 11, 2012

Its going to keep bugging me that people won't put index.js into their bower projects.

I hate #= require jquery/jquery. #= require jquery ought to just work.

But I'm kinda confused about bower's main property. It seems you can set it to an array of all the files in your package which doesn't make a whole lotta sense if you expect only one file to be returned. I think this just needs to be clarified.

Consider something like qunit. It'd be neat if it set:

"main":  ["./qunit.js", "./qunit.css"]

Then #= require qunit from js would pull in the js file, and @import "qunit" would pull in the css file. This means you'd only be able to have one file of each type in the main array.

/cc @maccman @fat

josh added a commit that referenced this pull request Sep 19, 2012

Merge pull request #358 from sstephenson/bower
Bower: component.json requires

@josh josh merged commit bc0808c into master Sep 19, 2012

1 check was pending

default The Travis build is in progress
Details

@grimen grimen referenced this pull request in nodeca/mincer Sep 23, 2012

Closed

Mincer vs Sprockets: Bower integration #37

@metaskills

This comment has been minimized.

Show comment
Hide comment
@metaskills

metaskills Mar 23, 2013

@josh Is there a place that shows how this works? I still have to keep doing stuff like require jquery.transit/jquery.transit.

@josh Is there a place that shows how this works? I still have to keep doing stuff like require jquery.transit/jquery.transit.

@josh

This comment has been minimized.

Show comment
Hide comment
@josh

josh Mar 23, 2013

Contributor

@metaskills looks like jquery.transit is missing a main definition. https://github.com/rstacruz/jquery.transit/blob/master/component.json

Contributor

josh commented Mar 23, 2013

@metaskills looks like jquery.transit is missing a main definition. https://github.com/rstacruz/jquery.transit/blob/master/component.json

@metaskills

This comment has been minimized.

Show comment
Hide comment
@metaskills

metaskills Mar 23, 2013

Thanks for taking the time to reply Josh. I did notice too that I had to do this with spin.js, which does have a main.

https://github.com/fgnass/spin.js/blob/gh-pages/component.json

Thanks for taking the time to reply Josh. I did notice too that I had to do this with spin.js, which does have a main.

https://github.com/fgnass/spin.js/blob/gh-pages/component.json

@mkitt mkitt referenced this pull request in modeset/bindable May 11, 2013

Open

package management for rails and javascript #1

@SaitoWu

This comment has been minimized.

Show comment
Hide comment
@SaitoWu

SaitoWu May 14, 2013

Hi, @josh . I have an issue when integrate sprockets with bower.

When a component has non-extension file like LICENSE or compress command in component folder, it will raise an ArgumentError.

diff --git a/lib/sprockets/asset.rb b/lib/sprockets/asset.rb
index cabf717..8a155f5 100644
--- a/lib/sprockets/asset.rb
+++ b/lib/sprockets/asset.rb
@@ -33,7 +33,7 @@ module Sprockets
     alias_method :bytesize, :length

     def initialize(environment, logical_path, pathname)
-      raise ArgumentError, "Asset logical path has no extension: #{logical_path}" if File.extname(logical_path) == ""
+      return if File.extname(logical_path) == ""

       @root         = environment.root
       @logical_path = logical_path.to_s

This is my quick and dirty fix. Is there any better ways to do it?

SaitoWu commented May 14, 2013

Hi, @josh . I have an issue when integrate sprockets with bower.

When a component has non-extension file like LICENSE or compress command in component folder, it will raise an ArgumentError.

diff --git a/lib/sprockets/asset.rb b/lib/sprockets/asset.rb
index cabf717..8a155f5 100644
--- a/lib/sprockets/asset.rb
+++ b/lib/sprockets/asset.rb
@@ -33,7 +33,7 @@ module Sprockets
     alias_method :bytesize, :length

     def initialize(environment, logical_path, pathname)
-      raise ArgumentError, "Asset logical path has no extension: #{logical_path}" if File.extname(logical_path) == ""
+      return if File.extname(logical_path) == ""

       @root         = environment.root
       @logical_path = logical_path.to_s

This is my quick and dirty fix. Is there any better ways to do it?

@josh

This comment has been minimized.

Show comment
Hide comment
@josh

josh May 14, 2013

Contributor

Sounds like your tring to require_tree an entire component, which isn't going to work.

Contributor

josh commented May 14, 2013

Sounds like your tring to require_tree an entire component, which isn't going to work.

@SaitoWu

This comment has been minimized.

Show comment
Hide comment
@SaitoWu

SaitoWu May 14, 2013

@josh Ha,

You make me solve the real problem.

I found all my appended_paths with a env.find_asset(logical_path) .

Very similar to require_tree, That's my fault.

👍 Thank you very much.

SaitoWu commented May 14, 2013

@josh Ha,

You make me solve the real problem.

I found all my appended_paths with a env.find_asset(logical_path) .

Very similar to require_tree, That's my fault.

👍 Thank you very much.

@bentacles bentacles referenced this pull request in stve/bower Oct 4, 2013

Open

Possible Readme/Wiki update #3

@ahacking

This comment has been minimized.

Show comment
Hide comment
@ahacking

ahacking Nov 14, 2013

@metaskills I had the same issue.

IMO bower + sprockets is just not worth the trouble and seems incomplete and unable to deal with the necessary requirements of providing a uniform way of integrating bower assets into the rails asset pipeline. The issue of no index.js or 'main' (present or not), and integration of additional assets like font and image assets or embedded font paths in css mean bower packages cannot be easily used as is.

I've ditched bower and switched back to using asset gems as the practical way of dealing with the inconsistencies and being able to nicely integrate css+fonts+images+js etc into the rails asset pipeline. Best of all I get the usual rails/bundler approach to managing and updating my projects dependencies.

@metaskills I had the same issue.

IMO bower + sprockets is just not worth the trouble and seems incomplete and unable to deal with the necessary requirements of providing a uniform way of integrating bower assets into the rails asset pipeline. The issue of no index.js or 'main' (present or not), and integration of additional assets like font and image assets or embedded font paths in css mean bower packages cannot be easily used as is.

I've ditched bower and switched back to using asset gems as the practical way of dealing with the inconsistencies and being able to nicely integrate css+fonts+images+js etc into the rails asset pipeline. Best of all I get the usual rails/bundler approach to managing and updating my projects dependencies.

@metaskills

This comment has been minimized.

Show comment
Hide comment
@metaskills

metaskills Nov 14, 2013

@ahacking I've been using Bower successfully for many months now and love it within my Rails setup. I simply have a project .bowerrc that looks like this.

{
  "directory" : "vendor/assets/components"
}

I then have a symlink to like this bower.json -> vendor/assets/components/bower.json. Works great. I don't mind doing things like //= require spin.js/dist/spin.

@ahacking I've been using Bower successfully for many months now and love it within my Rails setup. I simply have a project .bowerrc that looks like this.

{
  "directory" : "vendor/assets/components"
}

I then have a symlink to like this bower.json -> vendor/assets/components/bower.json. Works great. I don't mind doing things like //= require spin.js/dist/spin.

@ahacking

This comment has been minimized.

Show comment
Hide comment
@ahacking

ahacking Nov 14, 2013

@metaskills Yes Ive done pretty much that too, plus specifying a whole lot of guff in config.assets.precompile to get sprockets to pick up fonts, images and templates but its very coarse grained.

I don't like having to ferret around inside each bower package for things in every project, and still be left with asset path issues in the vendor css/scss as well. IMO gem asset packages are the only practical way for dealing with the variances and preserving both usability and my sanity.

There will never be uniformity in bower package that care about sprockets requires in index.js, or include main in bower.json, so by using rails asset gems I can get this uniformity across my projects using the simple approach covered here: http://prioritized.net/blog/gemify-assets-for-rails/ In rails 4 we need to use app/assets since vendor/assets is effectively dead due to undocumented breaking changes.

@metaskills Yes Ive done pretty much that too, plus specifying a whole lot of guff in config.assets.precompile to get sprockets to pick up fonts, images and templates but its very coarse grained.

I don't like having to ferret around inside each bower package for things in every project, and still be left with asset path issues in the vendor css/scss as well. IMO gem asset packages are the only practical way for dealing with the variances and preserving both usability and my sanity.

There will never be uniformity in bower package that care about sprockets requires in index.js, or include main in bower.json, so by using rails asset gems I can get this uniformity across my projects using the simple approach covered here: http://prioritized.net/blog/gemify-assets-for-rails/ In rails 4 we need to use app/assets since vendor/assets is effectively dead due to undocumented breaking changes.

@metaskills

This comment has been minimized.

Show comment
Hide comment
@metaskills

metaskills Nov 14, 2013

plus specifying a whole lot of guff in config.assets.precompile to get
sprockets to pick up fonts, images and templates

That does not sound right – I have not had to do any of those things. However, I do tend to follow a very clean asset structure. Basically, most of my apps only have one or two (at most) top level assets. For example, a site.js, site.css for like a marking layout and a application.js and application.js for the whole app. Creating tons of top level assets that perhaps require jquery/etc over and over again is not a good idea (YMMV). Also, images and fonts in a precompile list? I never heard of that, nor had to.

Don't get me wrong, I love me some asset gems and have published them, but they can become out of date quickly. Besides, it sounds like you are having issues further up. Maybe the foundation of your setup is off. Either way, good luck with it. Cheers!

plus specifying a whole lot of guff in config.assets.precompile to get
sprockets to pick up fonts, images and templates

That does not sound right – I have not had to do any of those things. However, I do tend to follow a very clean asset structure. Basically, most of my apps only have one or two (at most) top level assets. For example, a site.js, site.css for like a marking layout and a application.js and application.js for the whole app. Creating tons of top level assets that perhaps require jquery/etc over and over again is not a good idea (YMMV). Also, images and fonts in a precompile list? I never heard of that, nor had to.

Don't get me wrong, I love me some asset gems and have published them, but they can become out of date quickly. Besides, it sounds like you are having issues further up. Maybe the foundation of your setup is off. Either way, good luck with it. Cheers!

@ahacking

This comment has been minimized.

Show comment
Hide comment
@ahacking

ahacking Nov 14, 2013

@metaskills Theres no issue with my asset setup, its 100% working as designed, but completely unsuitable for
use with bower packages.

vendor/assets is not precompiled anymore .... See #36, rails/rails#9294, and the lack of consideration given to the breakage here rails/rails#7968

I used the config.assets.precompile configuration at https://gist.github.com/afeld/5704079 due to the asset pipeline changes referenced above, any images or fonts or templates in vendor/assets/components will not be included in production otherwise.

So with those precompile directives, ANY files in vendor/assets/components matching those extensions will be processed. Its still too coarse grained as there is so much stuff in bower packages unrelated to what our application actually needs as assets. Gems give you the ability to define exactly what should be included, using bower doesn't AND it requires every application that uses a bower package to analyse what they need to pluck out, and they can't ever get the correct font or image asset paths as you would get using sprocket helpers which resolve to the correct location. Really its a dead duck I'm afraid.

I'll go as far to say that bower support should be removed from sprockets because it can't ever really work properly when packages include more than just css/js it only leads to grief. Bower package authors do not write them cognisant of rails/sprockets asset pipeline requirements nor do they use sprocket helpers, so how can this ever work??

@metaskills Theres no issue with my asset setup, its 100% working as designed, but completely unsuitable for
use with bower packages.

vendor/assets is not precompiled anymore .... See #36, rails/rails#9294, and the lack of consideration given to the breakage here rails/rails#7968

I used the config.assets.precompile configuration at https://gist.github.com/afeld/5704079 due to the asset pipeline changes referenced above, any images or fonts or templates in vendor/assets/components will not be included in production otherwise.

So with those precompile directives, ANY files in vendor/assets/components matching those extensions will be processed. Its still too coarse grained as there is so much stuff in bower packages unrelated to what our application actually needs as assets. Gems give you the ability to define exactly what should be included, using bower doesn't AND it requires every application that uses a bower package to analyse what they need to pluck out, and they can't ever get the correct font or image asset paths as you would get using sprocket helpers which resolve to the correct location. Really its a dead duck I'm afraid.

I'll go as far to say that bower support should be removed from sprockets because it can't ever really work properly when packages include more than just css/js it only leads to grief. Bower package authors do not write them cognisant of rails/sprockets asset pipeline requirements nor do they use sprocket helpers, so how can this ever work??

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.