Skip to content

Commit 367490b

Browse files
committed
Readme
1 parent 47da23f commit 367490b

File tree

1 file changed

+101
-0
lines changed

1 file changed

+101
-0
lines changed

README.md

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
NPM Git Install
2+
===============
3+
4+
Clones and (re)installs packages from remote git repos. It is meant as a temporary solution until [npm/npm#3055][3055] is resolved.
5+
6+
Install
7+
-------
8+
9+
```sh
10+
npm install --save npm-git-install
11+
```
12+
13+
Use
14+
---
15+
16+
In your `pacakge.json` add:
17+
18+
```javascript
19+
{
20+
"scripts": {
21+
"install": "npm-git-install"
22+
}
23+
"gitDependencies": {
24+
"private-package-name": "git@private.git.server:user/repo.git#revision",
25+
"public-package-name": "https://github.com/user/repo.git#revision"
26+
}
27+
}
28+
```
29+
30+
Obviously replace `*-pacakge-name` and git URLs with values relevant to your project. URLs has to be in cannonical form (i.e. one that you would provide to `git clone` on command line) - no fancy NPM shortcuts like "user/repo" or "bitbucket:user/repo". If you want this, I'm open for PR. Actually I started to implement this, but gave up - see `messy-auto-discovery` branch.
31+
32+
Why
33+
---
34+
35+
IMO there is a serious defect in current versions of NPM regarding installation process of dependencies from git repositories. It basically prevents us from installing anything that needs build from git repos, or forcing us to keep build artifacts in the repos. Here is [relevant issue with ongoing discussion][3055].
36+
37+
### TL/DR:
38+
39+
If you `npm install ../some-local-directory/my-package` then npm will run `prepublish` script of the `package-from-local-directory` and then install it in current project. This is fine.
40+
41+
One would expect that running `npm install git@remote-git-server:me/my-package.git` would also run `prepublish` before installing. Unfortunately it won't. Further more, it will apply `.npmignore`, which will most likely remove all your source files and make it hard to recover. Boo...
42+
43+
How
44+
---
45+
46+
### From command line
47+
48+
```sh
49+
npm-git-install
50+
```
51+
52+
This simple script will `git clone` anything it finds in `gitDependencies` section of `package.json` into temporary directory, run `npm install` in this directory (which will trigger `prepublish`) and then `npm install <temporary directory>` in your project. In effect you will get your dependency properly installed.
53+
54+
You can optionally specify file different then `package.json`, e.g.:
55+
56+
```sh
57+
npm-git-install git-dependencies.json
58+
```
59+
60+
You may want to do this if you find it offensive to put non-standard section in your `package.json`.
61+
62+
Also try `--help` for more options.
63+
64+
### API
65+
66+
You can also use it programmatically. Just require `npm-git-install`. It exposes three methods:
67+
68+
* `discover (path)`
69+
70+
Reads list of packages from file at given path and returns array of `{url, revision}` objects. You can supply this to `reinstall_all` method.
71+
72+
* `reinstall_all (options, packages)`
73+
74+
Executes `reinstall` in series for each package in `packages`. Options are also passed to each `reinstall` call.
75+
76+
Returns a `Promise`.
77+
78+
* `reinstall (oprions, package)`
79+
80+
Clones the repo at `package.url`, checks out `package.revisios`, runs `npm install` at cloned repos directory and installs the package from there.
81+
82+
Options are:
83+
84+
* `silent`: Suppress child processes standard output. Boolean. Default is `false`.
85+
* `verbose`: Print debug messages. Boolean. Default is `false`.
86+
87+
Returns a `Promise`.
88+
89+
You probably don't want to use it directly. Just call `reinstall_all` with relevant options.
90+
91+
If you are a [Gulp][] user, then it should be easy enough to integrate it with your gulpfile.
92+
93+
### Why not use `dependencies` and `gitDependencies`
94+
95+
I tried and it's hard, because NPM supports [fancy things as Git URLs][URLs]. See `messy-auto-discovery` branch. You are welcome to take it from where I left. There is `--all` CLI option reserved that should do that. It is currently not supported.
96+
97+
There is also another reason. User may not want to reinstall all Git dependencies this way. For example I use gulp version 4, which is only available from GitHub and it is perfectly fine to install it with standard NPM. I don't want to rebuild it on my machine every time I install it. Now I can leave it in `devDependencies` and only use `npm-git-install` for stuff that needs it.
98+
99+
[URLs]: https://docs.npmjs.com/files/package.json#git-urls-as-dependencies
100+
[3055]: https://github.com/npm/npm/issues/3055
101+
[Gulp]: http://gulpjs.com/

0 commit comments

Comments
 (0)