yeoman / bower-requirejs

[DEPRECATED] Automagically wire-up installed Bower components into your RequireJS config
375 stars 68 forks source link

Read component's `"main"` from `package.json`, if `bower.json` doesn't have it #37

Closed anodynos closed 10 years ago

anodynos commented 11 years ago

I think it would be a good automation and safe assumption (?) for "main" of component's package.json's to come into play, if bower.json doesn't have a "main" or is missing completelly. For example, knockout has

  "name": "knockout",
  "version": "2.3.0",
  "repository": {
    "type": "git",
    "url": "git://github.com/SteveSanderson/knockout"

but no "main".

jQuery (1.9.1) is even worse, it doesnt have a bower.json. EDIT: jquery does work, through the look for a top level .js file tactic. Is there some reason package.json can't be used as a fall back ?

Also it would be usefull to display which components failed to be associated with a .js

sindresorhus commented 11 years ago

Is there some reason package.json can't be used as a fall back ?

This has been brought up many times in the Bower issue tracker and has been declined. This is not the place to implement it.

Also it would be usefull to display which components failed to be associated with a .js

Sure, that could be useful. @robdodson what do you think?

robdodson commented 11 years ago

Yeah it would be easy to list out the components that didn't make the cut. I'll see if I can put together a PR sometime this week.

mlmorg commented 11 years ago

I don't see why this isn't the place to implement grabbing main from a package.json file. You're already assuming a top-level js file is the main file; how is that any better?

sindresorhus commented 11 years ago

@mlmorg because package.json is for node and its main might not be the same as the browser one or even work.

mlmorg commented 11 years ago

Sure, but doesn't a top-level js file run the same risk?

sindresorhus commented 11 years ago

@mlmorg you're right.

robdodson commented 11 years ago

I'm not opposed to adding it. Although I think the task itself could probably use some house cleaning. It's starting to turn into two giant callbacks.

sindresorhus commented 11 years ago

@robdodson definitely

robdodson commented 11 years ago

Does anyone have an example of a library that defines a main js file in package.json but not bower.json? Just so I can put together a test fixture. @anodynos @mlmorg ?

mlmorg commented 11 years ago

Backbone.js?

robdodson commented 11 years ago

@mlmorg perfect, thanks!

tiger-seo commented 11 years ago

also Underscore.js has no bower.json, but has package.json and main in it, though both of them work fine at the moment, since they have main js-file names same way as package, but for example backbone-forms doesn't have bower.json and has no main js-file named as package, so it's simply ignored, though it has main in package.json, which can be used by bower-requirejs to provide path for Require.js

robdodson commented 11 years ago

This should be addressed by this commit in the postinstall-refactor branch (https://github.com/robdodson/grunt-bower-requirejs/commit/1779f4d4e7633c4d6e0e47629921d491f95d7e2c). There's a test for backbone-amd which doesn't have a bower.json but does have a package.json which properly specifies the location of the main file. Feel free to PR additional tests if you'd like.

robdodson commented 10 years ago

Fixed in v0.8.0