deps: upgrade to npm 2.14.4
[platform/upstream/nodejs.git] / deps / npm / doc / files / package.json.md
1 package.json(5) -- Specifics of npm's package.json handling
2 ===========================================================
3
4 ## DESCRIPTION
5
6 This document is all you need to know about what's required in your package.json
7 file.  It must be actual JSON, not just a JavaScript object literal.
8
9 A lot of the behavior described in this document is affected by the config
10 settings described in `npm-config(7)`.
11
12 ## name
13
14 The *most* important things in your package.json are the name and version fields.
15 Those are actually required, and your package won't install without
16 them.  The name and version together form an identifier that is assumed
17 to be completely unique.  Changes to the package should come along with
18 changes to the version.
19
20 The name is what your thing is called.
21
22 Some rules:
23
24 * The name must be shorter than 214 characters. This includes the scope for
25   scoped packages.
26 * The name can't start with a dot or an underscore.
27 * New packages must not have uppercase letters in the name.
28 * The name ends up being part of a URL, an argument on the command line, and a
29   folder name. Therefore, the name can't contain any non-URL-safe characters.
30
31 Some tips:
32
33 * Don't use the same name as a core Node module.
34 * Don't put "js" or "node" in the name.  It's assumed that it's js, since you're
35   writing a package.json file, and you can specify the engine using the "engines"
36   field.  (See below.)
37 * The name will probably be passed as an argument to require(), so it should
38   be something short, but also reasonably descriptive.
39 * You may want to check the npm registry to see if there's something by that name
40   already, before you get too attached to it. <https://www.npmjs.com/>
41
42 A name can be optionally prefixed by a scope, e.g. `@myorg/mypackage`. See
43 `npm-scope(7)` for more detail.
44
45 ## version
46
47 The *most* important things in your package.json are the name and version fields.
48 Those are actually required, and your package won't install without
49 them.  The name and version together form an identifier that is assumed
50 to be completely unique.  Changes to the package should come along with
51 changes to the version.
52
53 Version must be parseable by
54 [node-semver](https://github.com/isaacs/node-semver), which is bundled
55 with npm as a dependency.  (`npm install semver` to use it yourself.)
56
57 More on version numbers and ranges at semver(7).
58
59 ## description
60
61 Put a description in it.  It's a string.  This helps people discover your
62 package, as it's listed in `npm search`.
63
64 ## keywords
65
66 Put keywords in it.  It's an array of strings.  This helps people
67 discover your package as it's listed in `npm search`.
68
69 ## homepage
70
71 The url to the project homepage.
72
73 **NOTE**: This is *not* the same as "url".  If you put a "url" field,
74 then the registry will think it's a redirection to your package that has
75 been published somewhere else, and spit at you.
76
77 Literally.  Spit.  I'm so not kidding.
78
79 ## bugs
80
81 The url to your project's issue tracker and / or the email address to which
82 issues should be reported. These are helpful for people who encounter issues
83 with your package.
84
85 It should look like this:
86
87     { "url" : "https://github.com/owner/project/issues"
88     , "email" : "project@hostname.com"
89     }
90
91 You can specify either one or both values. If you want to provide only a url,
92 you can specify the value for "bugs" as a simple string instead of an object.
93
94 If a url is provided, it will be used by the `npm bugs` command.
95
96 ## license
97
98 You should specify a license for your package so that people know how they are
99 permitted to use it, and any restrictions you're placing on it.
100
101 If you're using a common license such as BSD-2-Clause or MIT, add a
102 current SPDX license identifier for the license you're using, like this:
103
104     { "license" : "BSD-3-Clause" }
105
106 You can check [the full list of SPDX license IDs](https://spdx.org/licenses/).
107 Ideally you should pick one that is
108 [OSI](http://opensource.org/licenses/alphabetical) approved.
109
110 If your package is licensed under multiple common licenses, use an [SPDX license
111 expression syntax version 2.0 string](http://npmjs.com/package/spdx), like this:
112
113     { "license" : "(ISC OR GPL-3.0)" }
114
115 If you are using a license that hasn't been assigned an SPDX identifier, or if
116 you are using a custom license, use the following valid SPDX expression:
117
118     { "license" : "SEE LICENSE IN <filename>" }
119
120 Then include a file named `<filename>` at the top level of the package.
121
122 Some old packages used license objects or a "licenses" property containing an
123 array of license objects:
124
125     // Not valid metadata
126     { "license" :
127       { "type" : "ISC"
128       , "url" : "http://opensource.org/licenses/ISC"
129       }
130     }
131
132     // Not valid metadata
133     { "licenses" :
134       [
135         { "type": "MIT"
136         , "url": "http://www.opensource.org/licenses/mit-license.php"
137         }
138       , { "type": "Apache-2.0"
139         , "url": "http://opensource.org/licenses/apache2.0.php"
140         }
141       ]
142     }
143
144 Those styles are now deprecated. Instead, use SPDX expressions, like this:
145
146     { "license": "ISC" }
147
148     { "license": "(MIT OR Apache-2.0)" }
149
150 Finally, if you do not wish to grant others the right to use a private or
151 unpublished package under any terms:
152
153     { "license": "UNLICENSED"}
154
155 Consider also setting `"private": true` to prevent accidental publication.
156
157 ## people fields: author, contributors
158
159 The "author" is one person.  "contributors" is an array of people.  A "person"
160 is an object with a "name" field and optionally "url" and "email", like this:
161
162     { "name" : "Barney Rubble"
163     , "email" : "b@rubble.com"
164     , "url" : "http://barnyrubble.tumblr.com/"
165     }
166
167 Or you can shorten that all into a single string, and npm will parse it for you:
168
169     "Barney Rubble <b@rubble.com> (http://barnyrubble.tumblr.com/)"
170
171 Both email and url are optional either way.
172
173 npm also sets a top-level "maintainers" field with your npm user info.
174
175 ## files
176
177 The "files" field is an array of files to include in your project.  If
178 you name a folder in the array, then it will also include the files
179 inside that folder. (Unless they would be ignored by another rule.)
180
181 You can also provide a ".npmignore" file in the root of your package or
182 in subdirectories, which will keep files from being included, even
183 if they would be picked up by the files array.  The `.npmignore` file
184 works just like a `.gitignore`.
185
186 Certain files are always included, regardless of settings:
187
188 * `package.json`
189 * `README` (and its variants)
190 * `CHANGELOG` (and its variants)
191 * `LICENSE` / `LICENCE`
192
193 Conversely, some files are always ignored:
194
195 * `.git`
196 * `CVS`
197 * `.svn`
198 * `.hg`
199 * `.lock-wscript`
200 * `.wafpickle-N`
201 * `*.swp`
202 * `.DS_Store`
203 * `._*`
204 * `npm-debug.log`
205
206 ## main
207
208 The main field is a module ID that is the primary entry point to your program.
209 That is, if your package is named `foo`, and a user installs it, and then does
210 `require("foo")`, then your main module's exports object will be returned.
211
212 This should be a module ID relative to the root of your package folder.
213
214 For most modules, it makes the most sense to have a main script and often not
215 much else.
216
217 ## bin
218
219 A lot of packages have one or more executable files that they'd like to
220 install into the PATH. npm makes this pretty easy (in fact, it uses this
221 feature to install the "npm" executable.)
222
223 To use this, supply a `bin` field in your package.json which is a map of
224 command name to local file name. On install, npm will symlink that file into
225 `prefix/bin` for global installs, or `./node_modules/.bin/` for local
226 installs.
227
228
229 For example, myapp could have this:
230
231     { "bin" : { "myapp" : "./cli.js" } }
232
233 So, when you install myapp, it'll create a symlink from the `cli.js` script to
234 `/usr/local/bin/myapp`.
235
236 If you have a single executable, and its name should be the name
237 of the package, then you can just supply it as a string.  For example:
238
239     { "name": "my-program"
240     , "version": "1.2.5"
241     , "bin": "./path/to/program" }
242
243 would be the same as this:
244
245     { "name": "my-program"
246     , "version": "1.2.5"
247     , "bin" : { "my-program" : "./path/to/program" } }
248
249 ## man
250
251 Specify either a single file or an array of filenames to put in place for the
252 `man` program to find.
253
254 If only a single file is provided, then it's installed such that it is the
255 result from `man <pkgname>`, regardless of its actual filename.  For example:
256
257     { "name" : "foo"
258     , "version" : "1.2.3"
259     , "description" : "A packaged foo fooer for fooing foos"
260     , "main" : "foo.js"
261     , "man" : "./man/doc.1"
262     }
263
264 would link the `./man/doc.1` file in such that it is the target for `man foo`
265
266 If the filename doesn't start with the package name, then it's prefixed.
267 So, this:
268
269     { "name" : "foo"
270     , "version" : "1.2.3"
271     , "description" : "A packaged foo fooer for fooing foos"
272     , "main" : "foo.js"
273     , "man" : [ "./man/foo.1", "./man/bar.1" ]
274     }
275
276 will create files to do `man foo` and `man foo-bar`.
277
278 Man files must end with a number, and optionally a `.gz` suffix if they are
279 compressed.  The number dictates which man section the file is installed into.
280
281     { "name" : "foo"
282     , "version" : "1.2.3"
283     , "description" : "A packaged foo fooer for fooing foos"
284     , "main" : "foo.js"
285     , "man" : [ "./man/foo.1", "./man/foo.2" ]
286     }
287
288 will create entries for `man foo` and `man 2 foo`
289
290 ## directories
291
292 The CommonJS [Packages](http://wiki.commonjs.org/wiki/Packages/1.0) spec details a
293 few ways that you can indicate the structure of your package using a `directories`
294 object. If you look at [npm's package.json](https://registry.npmjs.org/npm/latest),
295 you'll see that it has directories for doc, lib, and man.
296
297 In the future, this information may be used in other creative ways.
298
299 ### directories.lib
300
301 Tell people where the bulk of your library is.  Nothing special is done
302 with the lib folder in any way, but it's useful meta info.
303
304 ### directories.bin
305
306 If you specify a `bin` directory in `directories.bin`, all the files in
307 that folder will be added.
308
309 Because of the way the `bin` directive works, specifying both a
310 `bin` path and setting `directories.bin` is an error. If you want to
311 specify individual files, use `bin`, and for all the files in an
312 existing `bin` directory, use `directories.bin`.
313
314 ### directories.man
315
316 A folder that is full of man pages.  Sugar to generate a "man" array by
317 walking the folder.
318
319 ### directories.doc
320
321 Put markdown files in here.  Eventually, these will be displayed nicely,
322 maybe, someday.
323
324 ### directories.example
325
326 Put example scripts in here.  Someday, it might be exposed in some clever way.
327
328 ## repository
329
330 Specify the place where your code lives. This is helpful for people who
331 want to contribute.  If the git repo is on GitHub, then the `npm docs`
332 command will be able to find you.
333
334 Do it like this:
335
336     "repository" :
337       { "type" : "git"
338       , "url" : "https://github.com/npm/npm.git"
339       }
340
341     "repository" :
342       { "type" : "svn"
343       , "url" : "https://v8.googlecode.com/svn/trunk/"
344       }
345
346 The URL should be a publicly available (perhaps read-only) url that can be handed
347 directly to a VCS program without any modification.  It should not be a url to an
348 html project page that you put in your browser.  It's for computers.
349
350 For GitHub, GitHub gist, Bitbucket, or GitLab repositories you can use the same
351 shortcut syntax you use for `npm install`:
352
353     "repository": "npm/npm"
354
355     "repository": "gist:11081aaa281"
356
357     "repository": "bitbucket:example/repo"
358
359     "repository": "gitlab:another/repo"
360
361 ## scripts
362
363 The "scripts" property is a dictionary containing script commands that are run
364 at various times in the lifecycle of your package.  The key is the lifecycle
365 event, and the value is the command to run at that point.
366
367 See `npm-scripts(7)` to find out more about writing package scripts.
368
369 ## config
370
371 A "config" object can be used to set configuration parameters used in package
372 scripts that persist across upgrades.  For instance, if a package had the
373 following:
374
375     { "name" : "foo"
376     , "config" : { "port" : "8080" } }
377
378 and then had a "start" command that then referenced the
379 `npm_package_config_port` environment variable, then the user could
380 override that by doing `npm config set foo:port 8001`.
381
382 See `npm-config(7)` and `npm-scripts(7)` for more on package
383 configs.
384
385 ## dependencies
386
387 Dependencies are specified in a simple object that maps a package name to a
388 version range. The version range is a string which has one or more
389 space-separated descriptors.  Dependencies can also be identified with a
390 tarball or git URL.
391
392 **Please do not put test harnesses or transpilers in your
393 `dependencies` object.**  See `devDependencies`, below.
394
395 See semver(7) for more details about specifying version ranges.
396
397 * `version` Must match `version` exactly
398 * `>version` Must be greater than `version`
399 * `>=version` etc
400 * `<version`
401 * `<=version`
402 * `~version` "Approximately equivalent to version"  See semver(7)
403 * `^version` "Compatible with version"  See semver(7)
404 * `1.2.x` 1.2.0, 1.2.1, etc., but not 1.3.0
405 * `http://...` See 'URLs as Dependencies' below
406 * `*` Matches any version
407 * `""` (just an empty string) Same as `*`
408 * `version1 - version2` Same as `>=version1 <=version2`.
409 * `range1 || range2` Passes if either range1 or range2 are satisfied.
410 * `git...` See 'Git URLs as Dependencies' below
411 * `user/repo` See 'GitHub URLs' below
412 * `tag` A specific version tagged and published as `tag`  See `npm-tag(1)`
413 * `path/path/path` See Local Paths below
414
415 For example, these are all valid:
416
417     { "dependencies" :
418       { "foo" : "1.0.0 - 2.9999.9999"
419       , "bar" : ">=1.0.2 <2.1.2"
420       , "baz" : ">1.0.2 <=2.3.4"
421       , "boo" : "2.0.1"
422       , "qux" : "<1.0.0 || >=2.3.1 <2.4.5 || >=2.5.2 <3.0.0"
423       , "asd" : "http://asdf.com/asdf.tar.gz"
424       , "til" : "~1.2"
425       , "elf" : "~1.2.3"
426       , "two" : "2.x"
427       , "thr" : "3.3.x"
428       , "lat" : "latest"
429       , "dyl" : "file:../dyl"
430       }
431     }
432
433 ### URLs as Dependencies
434
435 You may specify a tarball URL in place of a version range.
436
437 This tarball will be downloaded and installed locally to your package at
438 install time.
439
440 ### Git URLs as Dependencies
441
442 Git urls can be of the form:
443
444     git://github.com/user/project.git#commit-ish
445     git+ssh://user@hostname:project.git#commit-ish
446     git+ssh://user@hostname/project.git#commit-ish
447     git+http://user@hostname/project/blah.git#commit-ish
448     git+https://user@hostname/project/blah.git#commit-ish
449
450 The `commit-ish` can be any tag, sha, or branch which can be supplied as
451 an argument to `git checkout`.  The default is `master`.
452
453 ## GitHub URLs
454
455 As of version 1.1.65, you can refer to GitHub urls as just "foo":
456 "user/foo-project".  Just as with git URLs, a `commit-ish` suffix can be
457 included.  For example:
458
459     {
460       "name": "foo",
461       "version": "0.0.0",
462       "dependencies": {
463         "express": "visionmedia/express",
464         "mocha": "visionmedia/mocha#4727d357ea"
465       }
466     }
467
468 ## Local Paths
469
470 As of version 2.0.0 you can provide a path to a local directory that contains a
471 package. Local paths can be saved using `npm install --save`, using any of
472 these forms:
473
474     ../foo/bar
475     ~/foo/bar
476     ./foo/bar
477     /foo/bar
478
479 in which case they will be normalized to a relative path and added to your
480 `package.json`. For example:
481
482     {
483       "name": "baz",
484       "dependencies": {
485         "bar": "file:../foo/bar"
486       }
487     }
488
489 This feature is helpful for local offline development and creating
490 tests that require npm installing where you don't want to hit an
491 external server, but should not be used when publishing packages
492 to the public registry.
493
494 ## devDependencies
495
496 If someone is planning on downloading and using your module in their
497 program, then they probably don't want or need to download and build
498 the external test or documentation framework that you use.
499
500 In this case, it's best to map these additional items in a `devDependencies`
501 object.
502
503 These things will be installed when doing `npm link` or `npm install`
504 from the root of a package, and can be managed like any other npm
505 configuration param.  See `npm-config(7)` for more on the topic.
506
507 For build steps that are not platform-specific, such as compiling
508 CoffeeScript or other languages to JavaScript, use the `prepublish`
509 script to do this, and make the required package a devDependency.
510
511 For example:
512
513     { "name": "ethopia-waza",
514       "description": "a delightfully fruity coffee varietal",
515       "version": "1.2.3",
516       "devDependencies": {
517         "coffee-script": "~1.6.3"
518       },
519       "scripts": {
520         "prepublish": "coffee -o lib/ -c src/waza.coffee"
521       },
522       "main": "lib/waza.js"
523     }
524
525 The `prepublish` script will be run before publishing, so that users
526 can consume the functionality without requiring them to compile it
527 themselves.  In dev mode (ie, locally running `npm install`), it'll
528 run this script as well, so that you can test it easily.
529
530 ## peerDependencies
531
532 In some cases, you want to express the compatibility of your package with a
533 host tool or library, while not necessarily doing a `require` of this host.
534 This is usually referred to as a *plugin*. Notably, your module may be exposing
535 a specific interface, expected and specified by the host documentation.
536
537 For example:
538
539     {
540       "name": "tea-latte",
541       "version": "1.3.5",
542       "peerDependencies": {
543         "tea": "2.x"
544       }
545     }
546
547 This ensures your package `tea-latte` can be installed *along* with the second
548 major version of the host package `tea` only. `npm install tea-latte` could
549 possibly yield the following dependency graph:
550
551     ├── tea-latte@1.3.5
552     └── tea@2.2.0
553
554 **NOTE: npm versions 1 and 2 will automatically install `peerDependencies` if
555 they are not explicitly depended upon higher in the dependency tree. In the
556 next major version of npm (npm@3), this will no longer be the case. You will
557 receive a warning that the peerDependency is not installed instead.** The
558 behavior in npms 1 & 2 was frequently confusing and could easily put you into
559 dependency hell, a situation that npm is designed to avoid as much as possible.
560
561 Trying to install another plugin with a conflicting requirement will cause an
562 error. For this reason, make sure your plugin requirement is as broad as
563 possible, and not to lock it down to specific patch versions.
564
565 Assuming the host complies with [semver](http://semver.org/), only changes in
566 the host package's major version will break your plugin. Thus, if you've worked
567 with every 1.x version of the host package, use `"^1.0"` or `"1.x"` to express
568 this. If you depend on features introduced in 1.5.2, use `">= 1.5.2 < 2"`.
569
570 ## bundledDependencies
571
572 Array of package names that will be bundled when publishing the package.
573
574 If this is spelled `"bundleDependencies"`, then that is also honored.
575
576 ## optionalDependencies
577
578 If a dependency can be used, but you would like npm to proceed if it cannot be
579 found or fails to install, then you may put it in the `optionalDependencies`
580 object.  This is a map of package name to version or url, just like the
581 `dependencies` object.  The difference is that build failures do not cause
582 installation to fail.
583
584 It is still your program's responsibility to handle the lack of the
585 dependency.  For example, something like this:
586
587     try {
588       var foo = require('foo')
589       var fooVersion = require('foo/package.json').version
590     } catch (er) {
591       foo = null
592     }
593     if ( notGoodFooVersion(fooVersion) ) {
594       foo = null
595     }
596
597     // .. then later in your program ..
598
599     if (foo) {
600       foo.doFooThings()
601     }
602
603 Entries in `optionalDependencies` will override entries of the same name in
604 `dependencies`, so it's usually best to only put in one place.
605
606 ## engines
607
608 You can specify the version of node that your stuff works on:
609
610     { "engines" : { "node" : ">=0.10.3 <0.12" } }
611
612 And, like with dependencies, if you don't specify the version (or if you
613 specify "\*" as the version), then any version of node will do.
614
615 If you specify an "engines" field, then npm will require that "node" be
616 somewhere on that list. If "engines" is omitted, then npm will just assume
617 that it works on node.
618
619 You can also use the "engines" field to specify which versions of npm
620 are capable of properly installing your program.  For example:
621
622     { "engines" : { "npm" : "~1.0.20" } }
623
624 Note that, unless the user has set the `engine-strict` config flag, this
625 field is advisory only.
626
627 ## engineStrict
628
629 **NOTE: This feature is deprecated and will be removed in npm 3.0.0.**
630
631 If you are sure that your module will *definitely not* run properly on
632 versions of Node/npm other than those specified in the `engines` object,
633 then you can set `"engineStrict": true` in your package.json file.
634 This will override the user's `engine-strict` config setting.
635
636 Please do not do this unless you are really very very sure.  If your
637 engines object is something overly restrictive, you can quite easily and
638 inadvertently lock yourself into obscurity and prevent your users from
639 updating to new versions of Node.  Consider this choice carefully.
640
641 ## os
642
643 You can specify which operating systems your
644 module will run on:
645
646     "os" : [ "darwin", "linux" ]
647
648 You can also blacklist instead of whitelist operating systems,
649 just prepend the blacklisted os with a '!':
650
651     "os" : [ "!win32" ]
652
653 The host operating system is determined by `process.platform`
654
655 It is allowed to both blacklist, and whitelist, although there isn't any
656 good reason to do this.
657
658 ## cpu
659
660 If your code only runs on certain cpu architectures,
661 you can specify which ones.
662
663     "cpu" : [ "x64", "ia32" ]
664
665 Like the `os` option, you can also blacklist architectures:
666
667     "cpu" : [ "!arm", "!mips" ]
668
669 The host architecture is determined by `process.arch`
670
671 ## preferGlobal
672
673 If your package is primarily a command-line application that should be
674 installed globally, then set this value to `true` to provide a warning
675 if it is installed locally.
676
677 It doesn't actually prevent users from installing it locally, but it
678 does help prevent some confusion if it doesn't work as expected.
679
680 ## private
681
682 If you set `"private": true` in your package.json, then npm will refuse
683 to publish it.
684
685 This is a way to prevent accidental publication of private repositories.  If
686 you would like to ensure that a given package is only ever published to a
687 specific registry (for example, an internal registry), then use the
688 `publishConfig` dictionary described below to override the `registry` config
689 param at publish-time.
690
691 ## publishConfig
692
693 This is a set of config values that will be used at publish-time. It's
694 especially handy if you want to set the tag, registry or access, so that
695 you can ensure that a given package is not tagged with "latest", published
696 to the global public registry or that a scoped module is private by default.
697
698 Any config values can be overridden, but of course only "tag", "registry" and
699 "access" probably matter for the purposes of publishing.
700
701 See `npm-config(7)` to see the list of config options that can be
702 overridden.
703
704 ## DEFAULT VALUES
705
706 npm will default some values based on package contents.
707
708 * `"scripts": {"start": "node server.js"}`
709
710   If there is a `server.js` file in the root of your package, then npm
711   will default the `start` command to `node server.js`.
712
713 * `"scripts":{"preinstall": "node-gyp rebuild"}`
714
715   If there is a `binding.gyp` file in the root of your package, npm will
716   default the `preinstall` command to compile using node-gyp.
717
718 * `"contributors": [...]`
719
720   If there is an `AUTHORS` file in the root of your package, npm will
721   treat each line as a `Name <email> (url)` format, where email and url
722   are optional.  Lines which start with a `#` or are blank, will be
723   ignored.
724
725 ## SEE ALSO
726
727 * semver(7)
728 * npm-init(1)
729 * npm-version(1)
730 * npm-config(1)
731 * npm-config(7)
732 * npm-help(1)
733 * npm-faq(7)
734 * npm-install(1)
735 * npm-publish(1)
736 * npm-rm(1)