Simple email application for Android. Original source code: https://framagit.org/dystopia-project/simple-email
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

966 lines
28 KiB

  1. .TH "PACKAGE\.JSON" "5" "August 2018" "" ""
  2. .SH "NAME"
  3. \fBpackage.json\fR \- Specifics of npm's package\.json handling
  4. .SH DESCRIPTION
  5. .P
  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. .P
  9. A lot of the behavior described in this document is affected by the config
  10. settings described in npm help 7 \fBnpm\-config\fP\|\.
  11. .SH name
  12. .P
  13. If you plan to publish your package, the \fImost\fR important things in your
  14. package\.json are the name and version fields as they will be required\. The name
  15. and version together form an identifier that is assumed to be completely unique\.
  16. Changes to the package should come along with changes to the version\. If you don't
  17. plan to publish your package, the name and version fields are optional\.
  18. .P
  19. The name is what your thing is called\.
  20. .P
  21. Some rules:
  22. .RS 0
  23. .IP \(bu 2
  24. The name must be less than or equal to 214 characters\. This includes the scope for
  25. scoped packages\.
  26. .IP \(bu 2
  27. The name can't start with a dot or an underscore\.
  28. .IP \(bu 2
  29. New packages must not have uppercase letters in the name\.
  30. .IP \(bu 2
  31. The name ends up being part of a URL, an argument on the command line, and a
  32. folder name\. Therefore, the name can't contain any non\-URL\-safe characters\.
  33. .RE
  34. .P
  35. Some tips:
  36. .RS 0
  37. .IP \(bu 2
  38. Don't use the same name as a core Node module\.
  39. .IP \(bu 2
  40. Don't put "js" or "node" in the name\. It's assumed that it's js, since you're
  41. writing a package\.json file, and you can specify the engine using the "engines"
  42. field\. (See below\.)
  43. .IP \(bu 2
  44. The name will probably be passed as an argument to require(), so it should
  45. be something short, but also reasonably descriptive\.
  46. .IP \(bu 2
  47. You may want to check the npm registry to see if there's something by that name
  48. already, before you get too attached to it\. https://www\.npmjs\.com/
  49. .RE
  50. .P
  51. A name can be optionally prefixed by a scope, e\.g\. \fB@myorg/mypackage\fP\|\. See
  52. npm help 7 \fBnpm\-scope\fP for more detail\.
  53. .SH version
  54. .P
  55. If you plan to publish your package, the \fImost\fR important things in your
  56. package\.json are the name and version fields as they will be required\. The name
  57. and version together form an identifier that is assumed to be completely unique\.
  58. Changes to the package should come along with changes to the version\. If you don't
  59. plan to publish your package, the name and version fields are optional\.
  60. .P
  61. Version must be parseable by
  62. node\-semver \fIhttps://github\.com/isaacs/node\-semver\fR, which is bundled
  63. with npm as a dependency\. (\fBnpm install semver\fP to use it yourself\.)
  64. .P
  65. More on version numbers and ranges at npm help 7 semver\.
  66. .SH description
  67. .P
  68. Put a description in it\. It's a string\. This helps people discover your
  69. package, as it's listed in \fBnpm search\fP\|\.
  70. .SH keywords
  71. .P
  72. Put keywords in it\. It's an array of strings\. This helps people
  73. discover your package as it's listed in \fBnpm search\fP\|\.
  74. .SH homepage
  75. .P
  76. The url to the project homepage\.
  77. .P
  78. Example:
  79. .P
  80. .RS 2
  81. .nf
  82. "homepage": "https://github\.com/owner/project#readme"
  83. .fi
  84. .RE
  85. .SH bugs
  86. .P
  87. The url to your project's issue tracker and / or the email address to which
  88. issues should be reported\. These are helpful for people who encounter issues
  89. with your package\.
  90. .P
  91. It should look like this:
  92. .P
  93. .RS 2
  94. .nf
  95. { "url" : "https://github\.com/owner/project/issues"
  96. , "email" : "project@hostname\.com"
  97. }
  98. .fi
  99. .RE
  100. .P
  101. You can specify either one or both values\. If you want to provide only a url,
  102. you can specify the value for "bugs" as a simple string instead of an object\.
  103. .P
  104. If a url is provided, it will be used by the \fBnpm bugs\fP command\.
  105. .SH license
  106. .P
  107. You should specify a license for your package so that people know how they are
  108. permitted to use it, and any restrictions you're placing on it\.
  109. .P
  110. If you're using a common license such as BSD\-2\-Clause or MIT, add a
  111. current SPDX license identifier for the license you're using, like this:
  112. .P
  113. .RS 2
  114. .nf
  115. { "license" : "BSD\-3\-Clause" }
  116. .fi
  117. .RE
  118. .P
  119. You can check the full list of SPDX license IDs \fIhttps://spdx\.org/licenses/\fR\|\.
  120. Ideally you should pick one that is
  121. OSI \fIhttps://opensource\.org/licenses/alphabetical\fR approved\.
  122. .P
  123. If your package is licensed under multiple common licenses, use an SPDX license
  124. expression syntax version 2\.0 string \fIhttps://www\.npmjs\.com/package/spdx\fR, like this:
  125. .P
  126. .RS 2
  127. .nf
  128. { "license" : "(ISC OR GPL\-3\.0)" }
  129. .fi
  130. .RE
  131. .P
  132. If you are using a license that hasn't been assigned an SPDX identifier, or if
  133. you are using a custom license, use a string value like this one:
  134. .P
  135. .RS 2
  136. .nf
  137. { "license" : "SEE LICENSE IN <filename>" }
  138. .fi
  139. .RE
  140. .P
  141. Then include a file named \fB<filename>\fP at the top level of the package\.
  142. .P
  143. Some old packages used license objects or a "licenses" property containing an
  144. array of license objects:
  145. .P
  146. .RS 2
  147. .nf
  148. // Not valid metadata
  149. { "license" :
  150. { "type" : "ISC"
  151. , "url" : "https://opensource\.org/licenses/ISC"
  152. }
  153. }
  154. // Not valid metadata
  155. { "licenses" :
  156. [
  157. { "type": "MIT"
  158. , "url": "https://www\.opensource\.org/licenses/mit\-license\.php"
  159. }
  160. , { "type": "Apache\-2\.0"
  161. , "url": "https://opensource\.org/licenses/apache2\.0\.php"
  162. }
  163. ]
  164. }
  165. .fi
  166. .RE
  167. .P
  168. Those styles are now deprecated\. Instead, use SPDX expressions, like this:
  169. .P
  170. .RS 2
  171. .nf
  172. { "license": "ISC" }
  173. { "license": "(MIT OR Apache\-2\.0)" }
  174. .fi
  175. .RE
  176. .P
  177. Finally, if you do not wish to grant others the right to use a private or
  178. unpublished package under any terms:
  179. .P
  180. .RS 2
  181. .nf
  182. { "license": "UNLICENSED" }
  183. .fi
  184. .RE
  185. .P
  186. Consider also setting \fB"private": true\fP to prevent accidental publication\.
  187. .SH people fields: author, contributors
  188. .P
  189. The "author" is one person\. "contributors" is an array of people\. A "person"
  190. is an object with a "name" field and optionally "url" and "email", like this:
  191. .P
  192. .RS 2
  193. .nf
  194. { "name" : "Barney Rubble"
  195. , "email" : "b@rubble\.com"
  196. , "url" : "http://barnyrubble\.tumblr\.com/"
  197. }
  198. .fi
  199. .RE
  200. .P
  201. Or you can shorten that all into a single string, and npm will parse it for you:
  202. .P
  203. .RS 2
  204. .nf
  205. "Barney Rubble <b@rubble\.com> (http://barnyrubble\.tumblr\.com/)"
  206. .fi
  207. .RE
  208. .P
  209. Both email and url are optional either way\.
  210. .P
  211. npm also sets a top\-level "maintainers" field with your npm user info\.
  212. .SH files
  213. .P
  214. The optional \fBfiles\fP field is an array of file patterns that describes
  215. the entries to be included when your package is installed as a
  216. dependency\. File patterns follow a similar syntax to \fB\|\.gitignore\fP, but
  217. reversed: including a file, directory, or glob pattern (\fB*\fP, \fB**/*\fP, and such)
  218. will make it so that file is included in the tarball when it's packed\. Omitting
  219. the field will make it default to \fB["*"]\fP, which means it will include all files\.
  220. .P
  221. Some special files and directories are also included or excluded regardless of
  222. whether they exist in the \fBfiles\fP array (see below)\.
  223. .P
  224. You can also provide a \fB\|\.npmignore\fP file in the root of your package or
  225. in subdirectories, which will keep files from being included\. At the
  226. root of your package it will not override the "files" field, but in
  227. subdirectories it will\. The \fB\|\.npmignore\fP file works just like a
  228. \fB\|\.gitignore\fP\|\. If there is a \fB\|\.gitignore\fP file, and \fB\|\.npmignore\fP is
  229. missing, \fB\|\.gitignore\fP\|'s contents will be used instead\.
  230. .P
  231. Files included with the "package\.json#files" field \fIcannot\fR be excluded
  232. through \fB\|\.npmignore\fP or \fB\|\.gitignore\fP\|\.
  233. .P
  234. Certain files are always included, regardless of settings:
  235. .RS 0
  236. .IP \(bu 2
  237. \fBpackage\.json\fP
  238. .IP \(bu 2
  239. \fBREADME\fP
  240. .IP \(bu 2
  241. \fBCHANGES\fP / \fBCHANGELOG\fP / \fBHISTORY\fP
  242. .IP \(bu 2
  243. \fBLICENSE\fP / \fBLICENCE\fP
  244. .IP \(bu 2
  245. \fBNOTICE\fP
  246. .IP \(bu 2
  247. The file in the "main" field
  248. .RE
  249. .P
  250. \fBREADME\fP, \fBCHANGES\fP, \fBLICENSE\fP & \fBNOTICE\fP can have any case and extension\.
  251. .P
  252. Conversely, some files are always ignored:
  253. .RS 0
  254. .IP \(bu 2
  255. \fB\|\.git\fP
  256. .IP \(bu 2
  257. \fBCVS\fP
  258. .IP \(bu 2
  259. \fB\|\.svn\fP
  260. .IP \(bu 2
  261. \fB\|\.hg\fP
  262. .IP \(bu 2
  263. \fB\|\.lock\-wscript\fP
  264. .IP \(bu 2
  265. \fB\|\.wafpickle\-N\fP
  266. .IP \(bu 2
  267. \fB\|\.*\.swp\fP
  268. .IP \(bu 2
  269. \fB\|\.DS_Store\fP
  270. .IP \(bu 2
  271. \fB\|\._*\fP
  272. .IP \(bu 2
  273. \fBnpm\-debug\.log\fP
  274. .IP \(bu 2
  275. \fB\|\.npmrc\fP
  276. .IP \(bu 2
  277. \fBnode_modules\fP
  278. .IP \(bu 2
  279. \fBconfig\.gypi\fP
  280. .IP \(bu 2
  281. \fB*\.orig\fP
  282. .IP \(bu 2
  283. \fBpackage\-lock\.json\fP (use shrinkwrap instead)
  284. .RE
  285. .SH main
  286. .P
  287. The main field is a module ID that is the primary entry point to your program\.
  288. That is, if your package is named \fBfoo\fP, and a user installs it, and then does
  289. \fBrequire("foo")\fP, then your main module's exports object will be returned\.
  290. .P
  291. This should be a module ID relative to the root of your package folder\.
  292. .P
  293. For most modules, it makes the most sense to have a main script and often not
  294. much else\.
  295. .SH browser
  296. .P
  297. If your module is meant to be used client\-side the browser field should be
  298. used instead of the main field\. This is helpful to hint users that it might
  299. rely on primitives that aren't available in Node\.js modules\. (e\.g\. \fBwindow\fP)
  300. .SH bin
  301. .P
  302. A lot of packages have one or more executable files that they'd like to
  303. install into the PATH\. npm makes this pretty easy (in fact, it uses this
  304. feature to install the "npm" executable\.)
  305. .P
  306. To use this, supply a \fBbin\fP field in your package\.json which is a map of
  307. command name to local file name\. On install, npm will symlink that file into
  308. \fBprefix/bin\fP for global installs, or \fB\|\./node_modules/\.bin/\fP for local
  309. installs\.
  310. .P
  311. For example, myapp could have this:
  312. .P
  313. .RS 2
  314. .nf
  315. { "bin" : { "myapp" : "\./cli\.js" } }
  316. .fi
  317. .RE
  318. .P
  319. So, when you install myapp, it'll create a symlink from the \fBcli\.js\fP script to
  320. \fB/usr/local/bin/myapp\fP\|\.
  321. .P
  322. If you have a single executable, and its name should be the name
  323. of the package, then you can just supply it as a string\. For example:
  324. .P
  325. .RS 2
  326. .nf
  327. { "name": "my\-program"
  328. , "version": "1\.2\.5"
  329. , "bin": "\./path/to/program" }
  330. .fi
  331. .RE
  332. .P
  333. would be the same as this:
  334. .P
  335. .RS 2
  336. .nf
  337. { "name": "my\-program"
  338. , "version": "1\.2\.5"
  339. , "bin" : { "my\-program" : "\./path/to/program" } }
  340. .fi
  341. .RE
  342. .P
  343. Please make sure that your file(s) referenced in \fBbin\fP starts with
  344. \fB#!/usr/bin/env node\fP, otherwise the scripts are started without the node
  345. executable!
  346. .SH man
  347. .P
  348. Specify either a single file or an array of filenames to put in place for the
  349. \fBman\fP program to find\.
  350. .P
  351. If only a single file is provided, then it's installed such that it is the
  352. result from \fBman <pkgname>\fP, regardless of its actual filename\. For example:
  353. .P
  354. .RS 2
  355. .nf
  356. { "name" : "foo"
  357. , "version" : "1\.2\.3"
  358. , "description" : "A packaged foo fooer for fooing foos"
  359. , "main" : "foo\.js"
  360. , "man" : "\./man/doc\.1"
  361. }
  362. .fi
  363. .RE
  364. .P
  365. would link the \fB\|\./man/doc\.1\fP file in such that it is the target for \fBman foo\fP
  366. .P
  367. If the filename doesn't start with the package name, then it's prefixed\.
  368. So, this:
  369. .P
  370. .RS 2
  371. .nf
  372. { "name" : "foo"
  373. , "version" : "1\.2\.3"
  374. , "description" : "A packaged foo fooer for fooing foos"
  375. , "main" : "foo\.js"
  376. , "man" : [ "\./man/foo\.1", "\./man/bar\.1" ]
  377. }
  378. .fi
  379. .RE
  380. .P
  381. will create files to do \fBman foo\fP and \fBman foo\-bar\fP\|\.
  382. .P
  383. Man files must end with a number, and optionally a \fB\|\.gz\fP suffix if they are
  384. compressed\. The number dictates which man section the file is installed into\.
  385. .P
  386. .RS 2
  387. .nf
  388. { "name" : "foo"
  389. , "version" : "1\.2\.3"
  390. , "description" : "A packaged foo fooer for fooing foos"
  391. , "main" : "foo\.js"
  392. , "man" : [ "\./man/foo\.1", "\./man/foo\.2" ]
  393. }
  394. .fi
  395. .RE
  396. .P
  397. will create entries for \fBman foo\fP and \fBman 2 foo\fP
  398. .SH directories
  399. .P
  400. The CommonJS Packages \fIhttp://wiki\.commonjs\.org/wiki/Packages/1\.0\fR spec details a
  401. few ways that you can indicate the structure of your package using a \fBdirectories\fP
  402. object\. If you look at npm's package\.json \fIhttps://registry\.npmjs\.org/npm/latest\fR,
  403. you'll see that it has directories for doc, lib, and man\.
  404. .P
  405. In the future, this information may be used in other creative ways\.
  406. .SS directories\.lib
  407. .P
  408. Tell people where the bulk of your library is\. Nothing special is done
  409. with the lib folder in any way, but it's useful meta info\.
  410. .SS directories\.bin
  411. .P
  412. If you specify a \fBbin\fP directory in \fBdirectories\.bin\fP, all the files in
  413. that folder will be added\.
  414. .P
  415. Because of the way the \fBbin\fP directive works, specifying both a
  416. \fBbin\fP path and setting \fBdirectories\.bin\fP is an error\. If you want to
  417. specify individual files, use \fBbin\fP, and for all the files in an
  418. existing \fBbin\fP directory, use \fBdirectories\.bin\fP\|\.
  419. .SS directories\.man
  420. .P
  421. A folder that is full of man pages\. Sugar to generate a "man" array by
  422. walking the folder\.
  423. .SS directories\.doc
  424. .P
  425. Put markdown files in here\. Eventually, these will be displayed nicely,
  426. maybe, someday\.
  427. .SS directories\.example
  428. .P
  429. Put example scripts in here\. Someday, it might be exposed in some clever way\.
  430. .SS directories\.test
  431. .P
  432. Put your tests in here\. It is currently not exposed, but it might be in the
  433. future\.
  434. .SH repository
  435. .P
  436. Specify the place where your code lives\. This is helpful for people who
  437. want to contribute\. If the git repo is on GitHub, then the \fBnpm docs\fP
  438. command will be able to find you\.
  439. .P
  440. Do it like this:
  441. .P
  442. .RS 2
  443. .nf
  444. "repository": {
  445. "type" : "git",
  446. "url" : "https://github\.com/npm/cli\.git"
  447. }
  448. "repository": {
  449. "type" : "svn",
  450. "url" : "https://v8\.googlecode\.com/svn/trunk/"
  451. }
  452. .fi
  453. .RE
  454. .P
  455. The URL should be a publicly available (perhaps read\-only) url that can be handed
  456. directly to a VCS program without any modification\. It should not be a url to an
  457. html project page that you put in your browser\. It's for computers\.
  458. .P
  459. For GitHub, GitHub gist, Bitbucket, or GitLab repositories you can use the same
  460. shortcut syntax you use for \fBnpm install\fP:
  461. .P
  462. .RS 2
  463. .nf
  464. "repository": "npm/npm"
  465. "repository": "github:user/repo"
  466. "repository": "gist:11081aaa281"
  467. "repository": "bitbucket:user/repo"
  468. "repository": "gitlab:user/repo"
  469. .fi
  470. .RE
  471. .SH scripts
  472. .P
  473. The "scripts" property is a dictionary containing script commands that are run
  474. at various times in the lifecycle of your package\. The key is the lifecycle
  475. event, and the value is the command to run at that point\.
  476. .P
  477. See npm help 7 \fBnpm\-scripts\fP to find out more about writing package scripts\.
  478. .SH config
  479. .P
  480. A "config" object can be used to set configuration parameters used in package
  481. scripts that persist across upgrades\. For instance, if a package had the
  482. following:
  483. .P
  484. .RS 2
  485. .nf
  486. { "name" : "foo"
  487. , "config" : { "port" : "8080" } }
  488. .fi
  489. .RE
  490. .P
  491. and then had a "start" command that then referenced the
  492. \fBnpm_package_config_port\fP environment variable, then the user could
  493. override that by doing \fBnpm config set foo:port 8001\fP\|\.
  494. .P
  495. See npm help 7 \fBnpm\-config\fP and npm help 7 \fBnpm\-scripts\fP for more on package
  496. configs\.
  497. .SH dependencies
  498. .P
  499. Dependencies are specified in a simple object that maps a package name to a
  500. version range\. The version range is a string which has one or more
  501. space\-separated descriptors\. Dependencies can also be identified with a
  502. tarball or git URL\.
  503. .P
  504. \fBPlease do not put test harnesses or transpilers in your
  505. \fBdependencies\fP object\.\fR See \fBdevDependencies\fP, below\.
  506. .P
  507. See npm help 7 semver for more details about specifying version ranges\.
  508. .RS 0
  509. .IP \(bu 2
  510. \fBversion\fP Must match \fBversion\fP exactly
  511. .IP \(bu 2
  512. \fB>version\fP Must be greater than \fBversion\fP
  513. .IP \(bu 2
  514. \fB>=version\fP etc
  515. .IP \(bu 2
  516. \fB<version\fP
  517. .IP \(bu 2
  518. \fB<=version\fP
  519. .IP \(bu 2
  520. \fB~version\fP "Approximately equivalent to version" See npm help 7 semver
  521. .IP \(bu 2
  522. \fB^version\fP "Compatible with version" See npm help 7 semver
  523. .IP \(bu 2
  524. \fB1\.2\.x\fP 1\.2\.0, 1\.2\.1, etc\., but not 1\.3\.0
  525. .IP \(bu 2
  526. \fBhttp://\.\.\.\fP See 'URLs as Dependencies' below
  527. .IP \(bu 2
  528. \fB*\fP Matches any version
  529. .IP \(bu 2
  530. \fB""\fP (just an empty string) Same as \fB*\fP
  531. .IP \(bu 2
  532. \fBversion1 \- version2\fP Same as \fB>=version1 <=version2\fP\|\.
  533. .IP \(bu 2
  534. \fBrange1 || range2\fP Passes if either range1 or range2 are satisfied\.
  535. .IP \(bu 2
  536. \fBgit\.\.\.\fP See 'Git URLs as Dependencies' below
  537. .IP \(bu 2
  538. \fBuser/repo\fP See 'GitHub URLs' below
  539. .IP \(bu 2
  540. \fBtag\fP A specific version tagged and published as \fBtag\fP See npm help \fBnpm\-dist\-tag\fP
  541. .IP \(bu 2
  542. \fBpath/path/path\fP See Local Paths \fI#local\-paths\fR below
  543. .RE
  544. .P
  545. For example, these are all valid:
  546. .P
  547. .RS 2
  548. .nf
  549. { "dependencies" :
  550. { "foo" : "1\.0\.0 \- 2\.9999\.9999"
  551. , "bar" : ">=1\.0\.2 <2\.1\.2"
  552. , "baz" : ">1\.0\.2 <=2\.3\.4"
  553. , "boo" : "2\.0\.1"
  554. , "qux" : "<1\.0\.0 || >=2\.3\.1 <2\.4\.5 || >=2\.5\.2 <3\.0\.0"
  555. , "asd" : "http://asdf\.com/asdf\.tar\.gz"
  556. , "til" : "~1\.2"
  557. , "elf" : "~1\.2\.3"
  558. , "two" : "2\.x"
  559. , "thr" : "3\.3\.x"
  560. , "lat" : "latest"
  561. , "dyl" : "file:\.\./dyl"
  562. }
  563. }
  564. .fi
  565. .RE
  566. .SS URLs as Dependencies
  567. .P
  568. You may specify a tarball URL in place of a version range\.
  569. .P
  570. This tarball will be downloaded and installed locally to your package at
  571. install time\.
  572. .SS Git URLs as Dependencies
  573. .P
  574. Git urls are of the form:
  575. .P
  576. .RS 2
  577. .nf
  578. <protocol>://[<user>[:<password>]@]<hostname>[:<port>][:][/]<path>[#<commit\-ish> | #semver:<semver>]
  579. .fi
  580. .RE
  581. .P
  582. \fB<protocol>\fP is one of \fBgit\fP, \fBgit+ssh\fP, \fBgit+http\fP, \fBgit+https\fP, or
  583. \fBgit+file\fP\|\.
  584. .P
  585. If \fB#<commit\-ish>\fP is provided, it will be used to clone exactly that
  586. commit\. If the commit\-ish has the format \fB#semver:<semver>\fP, \fB<semver>\fP can
  587. be any valid semver range or exact version, and npm will look for any tags
  588. or refs matching that range in the remote repository, much as it would for a
  589. registry dependency\. If neither \fB#<commit\-ish>\fP or \fB#semver:<semver>\fP is
  590. specified, then \fBmaster\fP is used\.
  591. .P
  592. Examples:
  593. .P
  594. .RS 2
  595. .nf
  596. git+ssh://git@github\.com:npm/cli\.git#v1\.0\.27
  597. git+ssh://git@github\.com:npm/cli#semver:^5\.0
  598. git+https://isaacs@github\.com/npm/cli\.git
  599. git://github\.com/npm/cli\.git#v1\.0\.27
  600. .fi
  601. .RE
  602. .SS GitHub URLs
  603. .P
  604. As of version 1\.1\.65, you can refer to GitHub urls as just "foo":
  605. "user/foo\-project"\. Just as with git URLs, a \fBcommit\-ish\fP suffix can be
  606. included\. For example:
  607. .P
  608. .RS 2
  609. .nf
  610. {
  611. "name": "foo",
  612. "version": "0\.0\.0",
  613. "dependencies": {
  614. "express": "expressjs/express",
  615. "mocha": "mochajs/mocha#4727d357ea",
  616. "module": "user/repo#feature\\/branch"
  617. }
  618. }
  619. .fi
  620. .RE
  621. .SS Local Paths
  622. .P
  623. As of version 2\.0\.0 you can provide a path to a local directory that contains a
  624. package\. Local paths can be saved using \fBnpm install \-S\fP or
  625. \fBnpm install \-\-save\fP, using any of these forms:
  626. .P
  627. .RS 2
  628. .nf
  629. \|\.\./foo/bar
  630. ~/foo/bar
  631. \|\./foo/bar
  632. /foo/bar
  633. .fi
  634. .RE
  635. .P
  636. in which case they will be normalized to a relative path and added to your
  637. \fBpackage\.json\fP\|\. For example:
  638. .P
  639. .RS 2
  640. .nf
  641. {
  642. "name": "baz",
  643. "dependencies": {
  644. "bar": "file:\.\./foo/bar"
  645. }
  646. }
  647. .fi
  648. .RE
  649. .P
  650. This feature is helpful for local offline development and creating
  651. tests that require npm installing where you don't want to hit an
  652. external server, but should not be used when publishing packages
  653. to the public registry\.
  654. .SH devDependencies
  655. .P
  656. If someone is planning on downloading and using your module in their
  657. program, then they probably don't want or need to download and build
  658. the external test or documentation framework that you use\.
  659. .P
  660. In this case, it's best to map these additional items in a \fBdevDependencies\fP
  661. object\.
  662. .P
  663. These things will be installed when doing \fBnpm link\fP or \fBnpm install\fP
  664. from the root of a package, and can be managed like any other npm
  665. configuration param\. See npm help 7 \fBnpm\-config\fP for more on the topic\.
  666. .P
  667. For build steps that are not platform\-specific, such as compiling
  668. CoffeeScript or other languages to JavaScript, use the \fBprepare\fP
  669. script to do this, and make the required package a devDependency\.
  670. .P
  671. For example:
  672. .P
  673. .RS 2
  674. .nf
  675. { "name": "ethopia\-waza",
  676. "description": "a delightfully fruity coffee varietal",
  677. "version": "1\.2\.3",
  678. "devDependencies": {
  679. "coffee\-script": "~1\.6\.3"
  680. },
  681. "scripts": {
  682. "prepare": "coffee \-o lib/ \-c src/waza\.coffee"
  683. },
  684. "main": "lib/waza\.js"
  685. }
  686. .fi
  687. .RE
  688. .P
  689. The \fBprepare\fP script will be run before publishing, so that users
  690. can consume the functionality without requiring them to compile it
  691. themselves\. In dev mode (ie, locally running \fBnpm install\fP), it'll
  692. run this script as well, so that you can test it easily\.
  693. .SH peerDependencies
  694. .P
  695. In some cases, you want to express the compatibility of your package with a
  696. host tool or library, while not necessarily doing a \fBrequire\fP of this host\.
  697. This is usually referred to as a \fIplugin\fR\|\. Notably, your module may be exposing
  698. a specific interface, expected and specified by the host documentation\.
  699. .P
  700. For example:
  701. .P
  702. .RS 2
  703. .nf
  704. {
  705. "name": "tea\-latte",
  706. "version": "1\.3\.5",
  707. "peerDependencies": {
  708. "tea": "2\.x"
  709. }
  710. }
  711. .fi
  712. .RE
  713. .P
  714. This ensures your package \fBtea\-latte\fP can be installed \fIalong\fR with the second
  715. major version of the host package \fBtea\fP only\. \fBnpm install tea\-latte\fP could
  716. possibly yield the following dependency graph:
  717. .P
  718. .RS 2
  719. .nf
  720. ├── tea\-latte@1\.3\.5
  721. └── tea@2\.2\.0
  722. .fi
  723. .RE
  724. .P
  725. \fBNOTE: npm versions 1 and 2 will automatically install \fBpeerDependencies\fP if
  726. they are not explicitly depended upon higher in the dependency tree\. In the
  727. next major version of npm (npm@3), this will no longer be the case\. You will
  728. receive a warning that the peerDependency is not installed instead\.\fR The
  729. behavior in npms 1 & 2 was frequently confusing and could easily put you into
  730. dependency hell, a situation that npm is designed to avoid as much as possible\.
  731. .P
  732. Trying to install another plugin with a conflicting requirement will cause an
  733. error\. For this reason, make sure your plugin requirement is as broad as
  734. possible, and not to lock it down to specific patch versions\.
  735. .P
  736. Assuming the host complies with semver \fIhttps://semver\.org/\fR, only changes in
  737. the host package's major version will break your plugin\. Thus, if you've worked
  738. with every 1\.x version of the host package, use \fB"^1\.0"\fP or \fB"1\.x"\fP to express
  739. this\. If you depend on features introduced in 1\.5\.2, use \fB">= 1\.5\.2 < 2"\fP\|\.
  740. .SH bundledDependencies
  741. .P
  742. This defines an array of package names that will be bundled when publishing
  743. the package\.
  744. .P
  745. In cases where you need to preserve npm packages locally or have them
  746. available through a single file download, you can bundle the packages in a
  747. tarball file by specifying the package names in the \fBbundledDependencies\fP
  748. array and executing \fBnpm pack\fP\|\.
  749. .P
  750. For example:
  751. .P
  752. If we define a package\.json like this:
  753. .P
  754. .RS 2
  755. .nf
  756. {
  757. "name": "awesome\-web\-framework",
  758. "version": "1\.0\.0",
  759. "bundledDependencies": [
  760. "renderized", "super\-streams"
  761. ]
  762. }
  763. .fi
  764. .RE
  765. .P
  766. we can obtain \fBawesome\-web\-framework\-1\.0\.0\.tgz\fP file by running \fBnpm pack\fP\|\.
  767. This file contains the dependencies \fBrenderized\fP and \fBsuper\-streams\fP which
  768. can be installed in a new project by executing \fBnpm install
  769. awesome\-web\-framework\-1\.0\.0\.tgz\fP\|\.
  770. .P
  771. If this is spelled \fB"bundleDependencies"\fP, then that is also honored\.
  772. .SH optionalDependencies
  773. .P
  774. If a dependency can be used, but you would like npm to proceed if it cannot be
  775. found or fails to install, then you may put it in the \fBoptionalDependencies\fP
  776. object\. This is a map of package name to version or url, just like the
  777. \fBdependencies\fP object\. The difference is that build failures do not cause
  778. installation to fail\.
  779. .P
  780. It is still your program's responsibility to handle the lack of the
  781. dependency\. For example, something like this:
  782. .P
  783. .RS 2
  784. .nf
  785. try {
  786. var foo = require('foo')
  787. var fooVersion = require('foo/package\.json')\.version
  788. } catch (er) {
  789. foo = null
  790. }
  791. if ( notGoodFooVersion(fooVersion) ) {
  792. foo = null
  793. }
  794. // \.\. then later in your program \.\.
  795. if (foo) {
  796. foo\.doFooThings()
  797. }
  798. .fi
  799. .RE
  800. .P
  801. Entries in \fBoptionalDependencies\fP will override entries of the same name in
  802. \fBdependencies\fP, so it's usually best to only put in one place\.
  803. .SH engines
  804. .P
  805. You can specify the version of node that your stuff works on:
  806. .P
  807. .RS 2
  808. .nf
  809. { "engines" : { "node" : ">=0\.10\.3 <0\.12" } }
  810. .fi
  811. .RE
  812. .P
  813. And, like with dependencies, if you don't specify the version (or if you
  814. specify "*" as the version), then any version of node will do\.
  815. .P
  816. If you specify an "engines" field, then npm will require that "node" be
  817. somewhere on that list\. If "engines" is omitted, then npm will just assume
  818. that it works on node\.
  819. .P
  820. You can also use the "engines" field to specify which versions of npm
  821. are capable of properly installing your program\. For example:
  822. .P
  823. .RS 2
  824. .nf
  825. { "engines" : { "npm" : "~1\.0\.20" } }
  826. .fi
  827. .RE
  828. .P
  829. Unless the user has set the \fBengine\-strict\fP config flag, this
  830. field is advisory only and will only produce warnings when your package is installed as a dependency\.
  831. .SH engineStrict
  832. .P
  833. \fBThis feature was removed in npm 3\.0\.0\fR
  834. .P
  835. Prior to npm 3\.0\.0, this feature was used to treat this package as if the
  836. user had set \fBengine\-strict\fP\|\. It is no longer used\.
  837. .SH os
  838. .P
  839. You can specify which operating systems your
  840. module will run on:
  841. .P
  842. .RS 2
  843. .nf
  844. "os" : [ "darwin", "linux" ]
  845. .fi
  846. .RE
  847. .P
  848. You can also blacklist instead of whitelist operating systems,
  849. just prepend the blacklisted os with a '!':
  850. .P
  851. .RS 2
  852. .nf
  853. "os" : [ "!win32" ]
  854. .fi
  855. .RE
  856. .P
  857. The host operating system is determined by \fBprocess\.platform\fP
  858. .P
  859. It is allowed to both blacklist, and whitelist, although there isn't any
  860. good reason to do this\.
  861. .SH cpu
  862. .P
  863. If your code only runs on certain cpu architectures,
  864. you can specify which ones\.
  865. .P
  866. .RS 2
  867. .nf
  868. "cpu" : [ "x64", "ia32" ]
  869. .fi
  870. .RE
  871. .P
  872. Like the \fBos\fP option, you can also blacklist architectures:
  873. .P
  874. .RS 2
  875. .nf
  876. "cpu" : [ "!arm", "!mips" ]
  877. .fi
  878. .RE
  879. .P
  880. The host architecture is determined by \fBprocess\.arch\fP
  881. .SH preferGlobal
  882. .P
  883. \fBDEPRECATED\fR
  884. .P
  885. This option used to trigger an npm warning, but it will no longer warn\. It is
  886. purely there for informational purposes\. It is now recommended that you install
  887. any binaries as local devDependencies wherever possible\.
  888. .SH private
  889. .P
  890. If you set \fB"private": true\fP in your package\.json, then npm will refuse
  891. to publish it\.
  892. .P
  893. This is a way to prevent accidental publication of private repositories\. If
  894. you would like to ensure that a given package is only ever published to a
  895. specific registry (for example, an internal registry), then use the
  896. \fBpublishConfig\fP dictionary described below to override the \fBregistry\fP config
  897. param at publish\-time\.
  898. .SH publishConfig
  899. .P
  900. This is a set of config values that will be used at publish\-time\. It's
  901. especially handy if you want to set the tag, registry or access, so that
  902. you can ensure that a given package is not tagged with "latest", published
  903. to the global public registry or that a scoped module is private by default\.
  904. .P
  905. Any config values can be overridden, but only "tag", "registry" and "access"
  906. probably matter for the purposes of publishing\.
  907. .P
  908. See npm help 7 \fBnpm\-config\fP to see the list of config options that can be
  909. overridden\.
  910. .SH DEFAULT VALUES
  911. .P
  912. npm will default some values based on package contents\.
  913. .RS 0
  914. .IP \(bu 2
  915. \fB"scripts": {"start": "node server\.js"}\fP
  916. If there is a \fBserver\.js\fP file in the root of your package, then npm
  917. will default the \fBstart\fP command to \fBnode server\.js\fP\|\.
  918. .IP \(bu 2
  919. \fB"scripts":{"install": "node\-gyp rebuild"}\fP
  920. If there is a \fBbinding\.gyp\fP file in the root of your package and you have not defined an \fBinstall\fP or \fBpreinstall\fP script, npm will
  921. default the \fBinstall\fP command to compile using node\-gyp\.
  922. .IP \(bu 2
  923. \fB"contributors": [\.\.\.]\fP
  924. If there is an \fBAUTHORS\fP file in the root of your package, npm will
  925. treat each line as a \fBName <email> (url)\fP format, where email and url
  926. are optional\. Lines which start with a \fB#\fP or are blank, will be
  927. ignored\.
  928. .RE
  929. .SH SEE ALSO
  930. .RS 0
  931. .IP \(bu 2
  932. npm help 7 semver
  933. .IP \(bu 2
  934. npm help init
  935. .IP \(bu 2
  936. npm help version
  937. .IP \(bu 2
  938. npm help config
  939. .IP \(bu 2
  940. npm help 7 config
  941. .IP \(bu 2
  942. npm help help
  943. .IP \(bu 2
  944. npm help install
  945. .IP \(bu 2
  946. npm help publish
  947. .IP \(bu 2
  948. npm help uninstall
  949. .RE