Skip to content
This repository was archived by the owner on Dec 4, 2017. It is now read-only.

Commit 31a5c40

Browse files
committed
add dep management
1 parent 4ae0aae commit 31a5c40

File tree

1 file changed

+55
-3
lines changed

1 file changed

+55
-3
lines changed

public/docs/ts/latest/cookbook/third-party-lib.jade

Lines changed: 55 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,9 @@ code-example(language="json").
289289
In addition to integration tests, you can also run unit tests in watch mode via `npm run test`,
290290
or single-run via `npm run test:once`.
291291

292+
You can also test your library by installing it in another local repository you have.
293+
To do so, first build your lib via `npm run build`.
294+
Then install it from your other repo using a relative path: `npm install relative/path/to/lib`.
292295

293296
.l-main-section
294297
:marked
@@ -327,9 +330,15 @@ code-example(language="json").
327330
You'll need to create a NPM account, login on your local machine, and then you can publish updated
328331
by running `npm publish`.
329332

330-
Remember to document your library, follow [Semantic Versioning](http://semver.org/) and
331-
setup a Continuous Integration solution to test your library (included is a `travis.yml`
332-
file for [Travis CI](https://docs.travis-ci.com/user/getting-started/))!
333+
.l-sub-section
334+
:marked
335+
### Be a good library maintainer
336+
337+
Remember to document your library,
338+
[manage your dependencies properly](appendix-dependency-management),
339+
follow [Semantic Versioning](http://semver.org/) and
340+
setup a Continuous Integration solution to test your library (included is a `travis.yml`
341+
file for [Travis CI](https://docs.travis-ci.com/user/getting-started/))!
333342

334343

335344
.l-main-section
@@ -384,3 +393,46 @@ code-example(language="json").
384393
To create a more flexible developer experience, a JIT compatible build of the library should be published as well. The format of the JIT bundle is `umd`, which stands for Universal Module Definition. Shipping the bundle as `umd` ensures compatibility with most common module loading formats.
385394

386395
The `umd` bundle will ship as a single file containing ES5 JavaScript and inlined versions of any external templates or css.
396+
397+
398+
.l-main-section
399+
:marked
400+
## Appendix: Dependency Management
401+
402+
As a library maintainer, it's important to properly manage your dependencies in `package.json`.
403+
404+
There are [three kinds of dependencies](https://docs.npmjs.com/files/package.json#dependencies):
405+
`dependencies`, `devDependencies` and `peerDependencies`.
406+
407+
- `dependencies`: here go all the other libraries yours depends on when being used.
408+
A good way to figure out these is to go through your library source code (in `src/lib` **only**)
409+
and list all the libraries there.
410+
- `devDependencies`: libraries that you need while developing, testing and building your app
411+
go here.
412+
When a user installs your library, these won't be installed.
413+
Users don't need to develop, build or test your library, they just need to run it.
414+
your app.
415+
- `peerDependencies`: these are similar to `dependencies` since your library expects them to be
416+
there at runtime.
417+
The difference is that you don't want to install a new version of these, but instead use
418+
the one already available.
419+
420+
A good example of a peer dependency is `@angular/core` and all other main Angular libraries.
421+
If you listed these in `dependencies`, a new one - with a different version! - could be installed
422+
for your library to use.
423+
This isn't what you wanted though. You want your library to use *the exact same* `@angular/core`
424+
that the app is using.
425+
426+
You'll usually used `@angular/*` libraries listed in both `devDependencies` and
427+
`peerDependencies`.
428+
This is normal and expected, because when you're developing your library also need a copy of
429+
them installed.
430+
431+
Another thing to remember is to keep your dependencies from changing too much unexpectedly.
432+
Different versions of libraries can have different features, and if you inadvertently are too
433+
lenient with allowed versions your library might stop working because a dependency changed.
434+
435+
You can choose what versions you allow by using [ranges](https://docs.npmjs.com/misc/semver).
436+
437+
A good rule of thumb is to have all `dependencies` specified with a tilde `~`(`~1.2.3`),
438+
while your `peerDependencies` have a range (`"@angular/core": ">=4.0.0 <5.0.0 || >=4.0.0-beta <5.0.0"`).

0 commit comments

Comments
 (0)