5

I'm using package.json file to define nodejs requirements, along with npm update, and of course is working fine.

How can I manage (update the easy way) other third party libraries with node? For example:

https://github.com/documentcloud/backbone.git
https://github.com/twitter/bootstrap.git

In vendor folder.

Mogsdad
  • 44,709
  • 21
  • 151
  • 275
gremo
  • 47,186
  • 75
  • 257
  • 421

3 Answers3

5

Summary: I think you want to use http://twitter.github.com/bower/

Details: There are two ways to understand your question:

  • how to manage/update non-npm code?
  • how to manage/update client-side javascript assets?

The question is worded as the former, but from your included examples I think what you want to ask the latter.

In case of server-side code, just insist all code gets shipped with npm-style package.json manifest. If the author of the code is unresponsive, fork it and add the manifest. There is no excuse.

For client-side code, the situation is different. There is no established standard for package management, however it's a widely recognized problem and very active field of development. Several challengers have risen recently, trying to grab the dominant position: BPM, Jam or Ender. It's your call which to pick, they are well summarized here: A package manager for web assets

However, all of the above address a slightly too ambitious problem - they try to sort out the transport of those modules to the browser (via lazy loading, require-js style, dependency resolution, concatenation/minification etc.) This also makes them more difficult to use.

A new entrant to the field is Bower from Twitter. It focuses just on download/update lifecycle in your vendor folder and ignores the browser delivery. I like that approach. You should check it out.

Community
  • 1
  • 1
zzen
  • 1,259
  • 10
  • 13
  • Bower seems the best way to manage client assets! Thanks for pointing me to it! – gremo Sep 12 '12 at 20:33
  • 1
    How am I supposed to use things like bootstrap with bower? There's no .css, just .less, and .js is split into lots of different files. – Farzher Nov 01 '12 at 03:24
2

You could go for git submodules:

http://git-scm.com/book/en/Git-Tools-Submodules

Using someone else's repo as a Git Submodule on GitHub

[UPDATE 1] Do this at the root of your repository:

git submodule add git://github.com/documentcloud/backbone.git vendors/backbone
git submodule add git://github.com/twitter/bootstrap.git vendors/bootstrap

Check this for more: http://skyl.org/log/post/skyl/2009/11/nested-git-repositories-with-github-using-submodule-in-three-minutes/

Community
  • 1
  • 1
fableal
  • 1,577
  • 10
  • 24
1

Although this may not be the nodejs way, and some purists may complain, Composer will do what you want. Even though Composer is used with PHP projects there is no reason why it cannot be used to manage 3rd party non-npm repos for nodejs projects too. Obviously it is preferable for the 3rd party library to include a package.json but thats not aways going to happen. I tried this on my current nodejs app and it worked perfectly for me.

Pros:

  • One json file specifies custom external dependancies that do not have package.json files
  • Customize where packages are stored in the project folder
  • Works with private repos and repos not originally intended for use with nodejs

Cons:

  • Requires php cli
  • An extra step for updating dependancies
  • An extra json file for dependancies

Here how to do it (You need to be able to run php from the cli):

1. Download Composer (directly into your root nodejs project folder)

curl -s https://getcomposer.org/composer.phar > composer.phar

2. Create a composer.json file (in the root of the project)

{
    "repositories": [
        {
            "type": "package",
            "package": {
                "name": "twitter/bootstrap",
                "version": "2.0.0",
                "dist": {
                    "url": "https://github.com/twitter/bootstrap/zipball/master",
                    "type": "zip"
                },
                "source": {
                    "url": "https://github.com/twitter/bootstrap.git",
                    "type": "git",
                    "reference": "master"
                }
            }
        }
    ],
    "require": {
        "twitter/bootstrap": "2.0.0"
    }
}

3. Run the Composer update

php composer.phar update 

This will download the package into the vendor folder as you requested:

├── vendor
│   ├── ...
│   ├── composer
│   │   └── installed.json
│   └── twitter
│       └── bootstrap
│           ├── LICENSE
│           ├── Makefile
│           ├── README.md
│           ├── docs
│           │   ├── assets
│           │   └── ...
│           ├── img
│           │   ├── glyphicons-halflings-white.png
│           │   └── glyphicons-halflings.png
│           ├── js
│           │   ├── bootstrap-affix.js
│           │   └── ...
│           ├── less
│           │   ├── accordion.less
│           │   └── ...
│           └── ...
Tim Santeford
  • 27,385
  • 16
  • 74
  • 101
  • This sounds good, but I already have `composer.json` file in the root of my project and it's used to manage node js dependencies (express, sequelize, etc...). – gremo Sep 14 '12 at 17:53
  • Wait do you mean `package.json`? This would be an additional composer.json file. – Tim Santeford Sep 14 '12 at 17:55