caolan / jam

JavaScript package manager - using a browser-focused and RequireJS compatible repository
MIT License
1.5k stars 105 forks source link

Support `shimmed` package #111

Open SBoudrias opened 11 years ago

SBoudrias commented 11 years ago

Hi,

There's a lot of package manager out there (volo, bower, etc) and as so, sometime authors don't want to add configuration for each one into their project.

It would be great if we could shim package from github repo without waiting for a project author to add jam config to it's package.json.

For example, shimmed package could work as so: on our local project, we add a .jam file (or anything) and inside we define the way packages should be fetch.

.jam

{
    "shim_packages": {
        "handlebars": {
            "url"      : "https://github.com/documentcloud/backbone",
            "main" : "./backbone.js",
            "dependencies": {
                "jquery"           : ">1.4.2",
                "underscore" : ">1.3.1"
            },
            "shim": {
                "deps"      : ["jquery"],
                "exports"  : "Example"
            }
        }
    }
}

Basically, inside a shimmed package definition, we just add what could be the content of a package.json file for the particular repo.

Then, we would only need to type jam install backbone in the terminal.

What do you think?


I saw that some packages already seems to have been added through some shimmed way (Handlebars, Backbone, etc), but haven't find any documentation at this subject. Is there any?

vespakoen commented 11 years ago

Hey,

I was struggeling with the same problem today, and it would indeed be a great feature to have. So, first of all, +1 for this, if I will get some time on my hands I would be willing to participate.

Now for anyone looking for a "quick fix" to at least be able to continue development until the main repo has been updated / accepted your pull-request ;)

You can use the jam link option to point to a local, fixed version of the repository. Of course, after doing this, it will not work for other people downloading your repository.

Here is some more information on the feature http://jamjs.org/docs#Linking_packages

caolan commented 11 years ago

Yes, I'm open to this idea. I can see that it would be useful.

As @SBoudrias mentioned, packages such as Handlebars and Backbone have already been published to the repository as shimmed packages. We've been quite open to the idea of people adding shimmed packages when they may not be the author. We suggest they let the author know, and if the real author requests ownership of the package it will be transferred.

In the meantime, if you don't think it's worth publishing a shimmed package and you'd like a dependency just for your own project, there's nothing to say that Jam must manage all your dependencies. You could drop it into a 'deps' or 'vendor' directory and simply add that to your paths for requirejs... then just check that directory into your repository (or use git submodules if that's your thing).

Your suggested config looks pretty good. "url" should probably be "git" in the example you gave. I'd also like to be able to specify a tag or branch and specify which version of the package I'm shimming.

Pull requests gratefully accepted ;)