Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

main property in bower.json #393

Closed
sindresorhus opened this issue Apr 12, 2013 · 9 comments
Closed

main property in bower.json #393

sindresorhus opened this issue Apr 12, 2013 · 9 comments

Comments

@sindresorhus
Copy link
Contributor

This one is still pretty ambiguous and the there hasn't been enough discussion in the spec, so bringing it out here.

See the spec and #46 for previous discussions.

Background

Right now it works naively and is just a field bower uses in eg. bower ls --sources, to feed other tools with paths from the field.

Current spec description:

The primary acting files necessary to use your package. While Bower does not directly use these files, they are listed with the commands bower list map and bower list --sources, so they can be used by build tools. Do not include minified files. Files should not be versioned (Bad: package.1.1.0.js; Good: package.js).

Proposal from spec

The spec currently contains a proposal, just going to leave it here, but don't focus just on it:

Q: Someone suggested that this main property could also be an object, where keys are feature names and values a string or an array of strings. This would allow things like:
{
  “main”: {
    “modal”: [“lib/modal.js, “css/modal.css”],
    “carrousel”: [“lib/carrousel.js”, “css/carrousel.css”]
  }
}
Of course the string|array of strings would still be allowed. Needs discussion!

Discussion

Instead of starting with what it should do, we should start by identifying current and potential consumers and real-world use-cases, and go from there.

Some other questions that eventually needs answering:

  • Why is it needed?
  • What problems should it solve?
  • How should it work?
  • Should it be required?
@desandro
Copy link
Member

main answers this question:

What files do I need to include in order for this package to work?


Use case

Draggabilly has several dependencies. To build a packaged version of the script, which includes all the necessary dependencies, I use bower list --sources to retrieve all the main files - see this Grunt task. These files are then concatenated to make the packaged script.

@Bartvds
Copy link

Bartvds commented Apr 13, 2013

+1

Using it should enable tooling to know the essential files needed to make this component work.

For example: today I wanted to use the requirejs component, but it comes with lot's of support files we don't need to bundle into the app. I expected bower list --paths or similar to list the essential files. But usage of main is not enforced and requirejs doesn't specify it in component.json so I had to manually find and copy the right file.

@timmfin
Copy link

timmfin commented Apr 16, 2013

+1 to allowing for separate "chunks" or modules that have js/css defined independently. I always thought it was a bummer (and not useful for our internal projects) to only be able to put one css file and one js file into main.

@jdeal
Copy link

jdeal commented Apr 16, 2013

I put a related in #367 (comment), which I'll copy here:

It seems that there is ambiguity or duplication of purpose between ignore and main. It seems that the only files a build tool can process are those in main. (Unless I'm missing something.) Most component developers (from a very unscientific sample) are not specifying ignore, so installing gives a dump of the whole repo, even though a build tool can only consume the files in main. If a component developer were to specify ignore to remove the junk, they would just be specifying the opposite of main, which would be redundant.

It seems that main from npm CommonJS modules is being emulated, but npm modules just sit on disk, and the main is always assumed to be a CommonJS module. They're not packaged up and delivered. And if they are packaged up and delivered, by something like browserify, the builder must parse the main and walk the require tree. I don't see how build tools can be expected to look at main and then be able to infer all other source files, given any possible module format.

@jdeal
Copy link

jdeal commented Apr 16, 2013

Another wrinkle here is that some components have specific build requirements. For example, angular scripts cannot survive obfuscation. As a component consumer, I would like to see errors point to raw source files rather than minified junk. But as a component developer, I may be the only one that knows how to optimally build my scripts.

@benschwarz
Copy link
Member

Heres the syntax that I suggested in 110
#110 (comment)

@klzns
Copy link

klzns commented Aug 9, 2013

I'm currently using bower-installer from @blittle to use Bower, it only install the files listed on the main property and it is working like a charm.

The proposal from spec and @benschwarz suggestion are really good for two reasons: creating one repo for many components distributions and breaking up minified files from not minified. Mainly the later, because it solves the problem from @jdeal and solves my problem which is: some of my projects just needs the minified version.

Another opinion, that I still don't know if it's a good idea, but I think all the main files should be inside a "dist" directory.

@klzns
Copy link

klzns commented Aug 9, 2013

Also, +1 removing ignore.

@germansokolov13
Copy link

Why does Bower support only one file of each type in "main"?

dotnetCarpenter referenced this issue in gtramontina/draggable.js Jan 8, 2014
CWSpear added a commit to CWSpear/engine that referenced this issue Mar 16, 2014
As per the spec for Bower, don't include minified files for `main` property, (and especially not both!) See bower/bower#393 for more.

In real-world use, I use a build script that uses the main property, and this fix fixes an error that includes both versions of the file where I would only want the min file.
techniq added a commit to techniq/angular-drag-drop that referenced this issue Apr 24, 2014
Bower [recommends](bower/bower#393) not to use minified files for your main scripts (leave it up to build tools to minify if desired).

```
The primary acting files necessary to use your package. While Bower does not directly use these files, they are listed with the commands bower list map and bower list --sources, so they can be used by build tools. Do not include minified files. Files should not be versioned (Bad: package.1.1.0.js; Good: package.js).
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

9 participants