package-json.5 29 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013
  1. .TH "PACKAGE\.JSON" "5" "August 2021" "" ""
  2. .SH "NAME"
  3. \fBpackage.json\fR \- Specifics of npm's package\.json handling
  4. .SS 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 \fBconfig\fP\|\.
  11. .SS 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 names of scoped packages can begin with a dot or an underscore\. This is not permitted without a scope\.
  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 \fBscope\fP for more detail\.
  53. .SS 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 semver\.
  66. .SS 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. .SS 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. .SS 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. .SS 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. .SS 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. .SS 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. .SS funding
  213. .P
  214. You can specify an object containing an URL that provides up\-to\-date
  215. information about ways to help fund development of your package, or
  216. a string URL, or an array of these:
  217. .P
  218. .RS 2
  219. .nf
  220. "funding": {
  221. "type" : "individual",
  222. "url" : "http://example\.com/donate"
  223. }
  224. "funding": {
  225. "type" : "patreon",
  226. "url" : "https://www\.patreon\.com/my\-account"
  227. }
  228. "funding": "http://example\.com/donate"
  229. "funding": [
  230. {
  231. "type" : "individual",
  232. "url" : "http://example\.com/donate"
  233. },
  234. "http://example\.com/donateAlso",
  235. {
  236. "type" : "patreon",
  237. "url" : "https://www\.patreon\.com/my\-account"
  238. }
  239. ]
  240. .fi
  241. .RE
  242. .P
  243. Users can use the \fBnpm fund\fP subcommand to list the \fBfunding\fP URLs of all
  244. dependencies of their project, direct and indirect\. A shortcut to visit each
  245. funding url is also available when providing the project name such as:
  246. \fBnpm fund <projectname>\fP (when there are multiple URLs, the first one will be
  247. visited)
  248. .SS files
  249. .P
  250. The optional \fBfiles\fP field is an array of file patterns that describes
  251. the entries to be included when your package is installed as a
  252. dependency\. File patterns follow a similar syntax to \fB\|\.gitignore\fP, but
  253. reversed: including a file, directory, or glob pattern (\fB*\fP, \fB**/*\fP, and such)
  254. will make it so that file is included in the tarball when it's packed\. Omitting
  255. the field will make it default to \fB["*"]\fP, which means it will include all files\.
  256. .P
  257. Some special files and directories are also included or excluded regardless of
  258. whether they exist in the \fBfiles\fP array (see below)\.
  259. .P
  260. You can also provide a \fB\|\.npmignore\fP file in the root of your package or
  261. in subdirectories, which will keep files from being included\. At the
  262. root of your package it will not override the "files" field, but in
  263. subdirectories it will\. The \fB\|\.npmignore\fP file works just like a
  264. \fB\|\.gitignore\fP\|\. If there is a \fB\|\.gitignore\fP file, and \fB\|\.npmignore\fP is
  265. missing, \fB\|\.gitignore\fP\|'s contents will be used instead\.
  266. .P
  267. Files included with the "package\.json#files" field \fIcannot\fR be excluded
  268. through \fB\|\.npmignore\fP or \fB\|\.gitignore\fP\|\.
  269. .P
  270. Certain files are always included, regardless of settings:
  271. .RS 0
  272. .IP \(bu 2
  273. \fBpackage\.json\fP
  274. .IP \(bu 2
  275. \fBREADME\fP
  276. .IP \(bu 2
  277. \fBCHANGES\fP / \fBCHANGELOG\fP / \fBHISTORY\fP
  278. .IP \(bu 2
  279. \fBLICENSE\fP / \fBLICENCE\fP
  280. .IP \(bu 2
  281. \fBNOTICE\fP
  282. .IP \(bu 2
  283. The file in the "main" field
  284. .RE
  285. .P
  286. \fBREADME\fP, \fBCHANGES\fP, \fBLICENSE\fP & \fBNOTICE\fP can have any case and extension\.
  287. .P
  288. Conversely, some files are always ignored:
  289. .RS 0
  290. .IP \(bu 2
  291. \fB\|\.git\fP
  292. .IP \(bu 2
  293. \fBCVS\fP
  294. .IP \(bu 2
  295. \fB\|\.svn\fP
  296. .IP \(bu 2
  297. \fB\|\.hg\fP
  298. .IP \(bu 2
  299. \fB\|\.lock\-wscript\fP
  300. .IP \(bu 2
  301. \fB\|\.wafpickle\-N\fP
  302. .IP \(bu 2
  303. \fB\|\.DS_Store\fP
  304. .IP \(bu 2
  305. \fBnpm\-debug\.log\fP
  306. .IP \(bu 2
  307. \fB\|\.npmrc\fP
  308. .IP \(bu 2
  309. \fBnode_modules\fP
  310. .IP \(bu 2
  311. \fBconfig\.gypi\fP
  312. .IP \(bu 2
  313. \fBpackage\-lock\.json\fP (use shrinkwrap instead)
  314. .IP \(bu 2
  315. All files containing a \fB*\fP character (incompatible with Windows)
  316. .RE
  317. .SS main
  318. .P
  319. The main field is a module ID that is the primary entry point to your program\.
  320. That is, if your package is named \fBfoo\fP, and a user installs it, and then does
  321. \fBrequire("foo")\fP, then your main module's exports object will be returned\.
  322. .P
  323. This should be a module ID relative to the root of your package folder\.
  324. .P
  325. For most modules, it makes the most sense to have a main script and often not
  326. much else\.
  327. .SS browser
  328. .P
  329. If your module is meant to be used client\-side the browser field should be
  330. used instead of the main field\. This is helpful to hint users that it might
  331. rely on primitives that aren't available in Node\.js modules\. (e\.g\. \fBwindow\fP)
  332. .SS bin
  333. .P
  334. A lot of packages have one or more executable files that they'd like to
  335. install into the PATH\. npm makes this pretty easy (in fact, it uses this
  336. feature to install the "npm" executable\.)
  337. .P
  338. To use this, supply a \fBbin\fP field in your package\.json which is a map of
  339. command name to local file name\. On install, npm will symlink that file into
  340. \fBprefix/bin\fP for global installs, or \fB\|\./node_modules/\.bin/\fP for local
  341. installs\.
  342. .P
  343. For example, myapp could have this:
  344. .P
  345. .RS 2
  346. .nf
  347. { "bin" : { "myapp" : "\./cli\.js" } }
  348. .fi
  349. .RE
  350. .P
  351. So, when you install myapp, it'll create a symlink from the \fBcli\.js\fP script to
  352. \fB/usr/local/bin/myapp\fP\|\.
  353. .P
  354. If you have a single executable, and its name should be the name
  355. of the package, then you can just supply it as a string\. For example:
  356. .P
  357. .RS 2
  358. .nf
  359. { "name": "my\-program"
  360. , "version": "1\.2\.5"
  361. , "bin": "\./path/to/program" }
  362. .fi
  363. .RE
  364. .P
  365. would be the same as this:
  366. .P
  367. .RS 2
  368. .nf
  369. { "name": "my\-program"
  370. , "version": "1\.2\.5"
  371. , "bin" : { "my\-program" : "\./path/to/program" } }
  372. .fi
  373. .RE
  374. .P
  375. Please make sure that your file(s) referenced in \fBbin\fP starts with
  376. \fB#!/usr/bin/env node\fP, otherwise the scripts are started without the node
  377. executable!
  378. .SS man
  379. .P
  380. Specify either a single file or an array of filenames to put in place for the
  381. \fBman\fP program to find\.
  382. .P
  383. If only a single file is provided, then it's installed such that it is the
  384. result from \fBman <pkgname>\fP, regardless of its actual filename\. For example:
  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/doc\.1"
  393. }
  394. .fi
  395. .RE
  396. .P
  397. would link the \fB\|\./man/doc\.1\fP file in such that it is the target for \fBman foo\fP
  398. .P
  399. If the filename doesn't start with the package name, then it's prefixed\.
  400. So, this:
  401. .P
  402. .RS 2
  403. .nf
  404. { "name" : "foo"
  405. , "version" : "1\.2\.3"
  406. , "description" : "A packaged foo fooer for fooing foos"
  407. , "main" : "foo\.js"
  408. , "man" : [ "\./man/foo\.1", "\./man/bar\.1" ]
  409. }
  410. .fi
  411. .RE
  412. .P
  413. will create files to do \fBman foo\fP and \fBman foo\-bar\fP\|\.
  414. .P
  415. Man files must end with a number, and optionally a \fB\|\.gz\fP suffix if they are
  416. compressed\. The number dictates which man section the file is installed into\.
  417. .P
  418. .RS 2
  419. .nf
  420. { "name" : "foo"
  421. , "version" : "1\.2\.3"
  422. , "description" : "A packaged foo fooer for fooing foos"
  423. , "main" : "foo\.js"
  424. , "man" : [ "\./man/foo\.1", "\./man/foo\.2" ]
  425. }
  426. .fi
  427. .RE
  428. .P
  429. will create entries for \fBman foo\fP and \fBman 2 foo\fP
  430. .SS directories
  431. .P
  432. The CommonJS Packages \fIhttp://wiki\.commonjs\.org/wiki/Packages/1\.0\fR spec details a
  433. few ways that you can indicate the structure of your package using a \fBdirectories\fP
  434. object\. If you look at npm's package\.json \fIhttps://registry\.npmjs\.org/npm/latest\fR,
  435. you'll see that it has directories for doc, lib, and man\.
  436. .P
  437. In the future, this information may be used in other creative ways\.
  438. .SS directories\.lib
  439. .P
  440. Tell people where the bulk of your library is\. Nothing special is done
  441. with the lib folder in any way, but it's useful meta info\.
  442. .SS directories\.bin
  443. .P
  444. If you specify a \fBbin\fP directory in \fBdirectories\.bin\fP, all the files in
  445. that folder will be added\.
  446. .P
  447. Because of the way the \fBbin\fP directive works, specifying both a
  448. \fBbin\fP path and setting \fBdirectories\.bin\fP is an error\. If you want to
  449. specify individual files, use \fBbin\fP, and for all the files in an
  450. existing \fBbin\fP directory, use \fBdirectories\.bin\fP\|\.
  451. .SS directories\.man
  452. .P
  453. A folder that is full of man pages\. Sugar to generate a "man" array by
  454. walking the folder\.
  455. .SS directories\.doc
  456. .P
  457. Put markdown files in here\. Eventually, these will be displayed nicely,
  458. maybe, someday\.
  459. .SS directories\.example
  460. .P
  461. Put example scripts in here\. Someday, it might be exposed in some clever way\.
  462. .SS directories\.test
  463. .P
  464. Put your tests in here\. It is currently not exposed, but it might be in the
  465. future\.
  466. .SS repository
  467. .P
  468. Specify the place where your code lives\. This is helpful for people who
  469. want to contribute\. If the git repo is on GitHub, then the \fBnpm docs\fP
  470. command will be able to find you\.
  471. .P
  472. Do it like this:
  473. .P
  474. .RS 2
  475. .nf
  476. "repository": {
  477. "type" : "git",
  478. "url" : "https://github\.com/npm/cli\.git"
  479. }
  480. "repository": {
  481. "type" : "svn",
  482. "url" : "https://v8\.googlecode\.com/svn/trunk/"
  483. }
  484. .fi
  485. .RE
  486. .P
  487. The URL should be a publicly available (perhaps read\-only) url that can be handed
  488. directly to a VCS program without any modification\. It should not be a url to an
  489. html project page that you put in your browser\. It's for computers\.
  490. .P
  491. For GitHub, GitHub gist, Bitbucket, or GitLab repositories you can use the same
  492. shortcut syntax you use for \fBnpm install\fP:
  493. .P
  494. .RS 2
  495. .nf
  496. "repository": "npm/npm"
  497. "repository": "github:user/repo"
  498. "repository": "gist:11081aaa281"
  499. "repository": "bitbucket:user/repo"
  500. "repository": "gitlab:user/repo"
  501. .fi
  502. .RE
  503. .P
  504. If the \fBpackage\.json\fP for your package is not in the root directory (for example
  505. if it is part of a monorepo), you can specify the directory in which it lives:
  506. .P
  507. .RS 2
  508. .nf
  509. "repository": {
  510. "type" : "git",
  511. "url" : "https://github\.com/facebook/react\.git",
  512. "directory": "packages/react\-dom"
  513. }
  514. .fi
  515. .RE
  516. .SS scripts
  517. .P
  518. The "scripts" property is a dictionary containing script commands that are run
  519. at various times in the lifecycle of your package\. The key is the lifecycle
  520. event, and the value is the command to run at that point\.
  521. .P
  522. See npm help \fBscripts\fP to find out more about writing package scripts\.
  523. .SS config
  524. .P
  525. A "config" object can be used to set configuration parameters used in package
  526. scripts that persist across upgrades\. For instance, if a package had the
  527. following:
  528. .P
  529. .RS 2
  530. .nf
  531. { "name" : "foo"
  532. , "config" : { "port" : "8080" } }
  533. .fi
  534. .RE
  535. .P
  536. and then had a "start" command that then referenced the
  537. \fBnpm_package_config_port\fP environment variable, then the user could
  538. override that by doing \fBnpm config set foo:port 8001\fP\|\.
  539. .P
  540. See npm help \fBconfig\fP and npm help \fBscripts\fP for more on package
  541. configs\.
  542. .SS dependencies
  543. .P
  544. Dependencies are specified in a simple object that maps a package name to a
  545. version range\. The version range is a string which has one or more
  546. space\-separated descriptors\. Dependencies can also be identified with a
  547. tarball or git URL\.
  548. .P
  549. \fBPlease do not put test harnesses or transpilers in your
  550. \fBdependencies\fP object\.\fR See \fBdevDependencies\fP, below\.
  551. .P
  552. See npm help semver for more details about specifying version ranges\.
  553. .RS 0
  554. .IP \(bu 2
  555. \fBversion\fP Must match \fBversion\fP exactly
  556. .IP \(bu 2
  557. \fB>version\fP Must be greater than \fBversion\fP
  558. .IP \(bu 2
  559. \fB>=version\fP etc
  560. .IP \(bu 2
  561. \fB<version\fP
  562. .IP \(bu 2
  563. \fB<=version\fP
  564. .IP \(bu 2
  565. \fB~version\fP "Approximately equivalent to version" See npm help semver
  566. .IP \(bu 2
  567. \fB^version\fP "Compatible with version" See npm help semver
  568. .IP \(bu 2
  569. \fB1\.2\.x\fP 1\.2\.0, 1\.2\.1, etc\., but not 1\.3\.0
  570. .IP \(bu 2
  571. \fBhttp://\.\.\.\fP See 'URLs as Dependencies' below
  572. .IP \(bu 2
  573. \fB*\fP Matches any version
  574. .IP \(bu 2
  575. \fB""\fP (just an empty string) Same as \fB*\fP
  576. .IP \(bu 2
  577. \fBversion1 \- version2\fP Same as \fB>=version1 <=version2\fP\|\.
  578. .IP \(bu 2
  579. \fBrange1 || range2\fP Passes if either range1 or range2 are satisfied\.
  580. .IP \(bu 2
  581. \fBgit\.\.\.\fP See 'Git URLs as Dependencies' below
  582. .IP \(bu 2
  583. \fBuser/repo\fP See 'GitHub URLs' below
  584. .IP \(bu 2
  585. \fBtag\fP A specific version tagged and published as \fBtag\fP See npm help \fBdist\-tag\fP
  586. .IP \(bu 2
  587. \fBpath/path/path\fP See Local Paths \fI#local\-paths\fR below
  588. .RE
  589. .P
  590. For example, these are all valid:
  591. .P
  592. .RS 2
  593. .nf
  594. { "dependencies" :
  595. { "foo" : "1\.0\.0 \- 2\.9999\.9999"
  596. , "bar" : ">=1\.0\.2 <2\.1\.2"
  597. , "baz" : ">1\.0\.2 <=2\.3\.4"
  598. , "boo" : "2\.0\.1"
  599. , "qux" : "<1\.0\.0 || >=2\.3\.1 <2\.4\.5 || >=2\.5\.2 <3\.0\.0"
  600. , "asd" : "http://asdf\.com/asdf\.tar\.gz"
  601. , "til" : "~1\.2"
  602. , "elf" : "~1\.2\.3"
  603. , "two" : "2\.x"
  604. , "thr" : "3\.3\.x"
  605. , "lat" : "latest"
  606. , "dyl" : "file:\.\./dyl"
  607. }
  608. }
  609. .fi
  610. .RE
  611. .SS URLs as Dependencies
  612. .P
  613. You may specify a tarball URL in place of a version range\.
  614. .P
  615. This tarball will be downloaded and installed locally to your package at
  616. install time\.
  617. .SS Git URLs as Dependencies
  618. .P
  619. Git urls are of the form:
  620. .P
  621. .RS 2
  622. .nf
  623. <protocol>://[<user>[:<password>]@]<hostname>[:<port>][:][/]<path>[#<commit\-ish> | #semver:<semver>]
  624. .fi
  625. .RE
  626. .P
  627. \fB<protocol>\fP is one of \fBgit\fP, \fBgit+ssh\fP, \fBgit+http\fP, \fBgit+https\fP, or
  628. \fBgit+file\fP\|\.
  629. .P
  630. If \fB#<commit\-ish>\fP is provided, it will be used to clone exactly that
  631. commit\. If the commit\-ish has the format \fB#semver:<semver>\fP, \fB<semver>\fP can
  632. be any valid semver range or exact version, and npm will look for any tags
  633. or refs matching that range in the remote repository, much as it would for a
  634. registry dependency\. If neither \fB#<commit\-ish>\fP or \fB#semver:<semver>\fP is
  635. specified, then \fBmaster\fP is used\.
  636. .P
  637. Examples:
  638. .P
  639. .RS 2
  640. .nf
  641. git+ssh://git@github\.com:npm/cli\.git#v1\.0\.27
  642. git+ssh://git@github\.com:npm/cli#semver:^5\.0
  643. git+https://isaacs@github\.com/npm/cli\.git
  644. git://github\.com/npm/cli\.git#v1\.0\.27
  645. .fi
  646. .RE
  647. .SS GitHub URLs
  648. .P
  649. As of version 1\.1\.65, you can refer to GitHub urls as just "foo":
  650. "user/foo\-project"\. Just as with git URLs, a \fBcommit\-ish\fP suffix can be
  651. included\. For example:
  652. .P
  653. .RS 2
  654. .nf
  655. {
  656. "name": "foo",
  657. "version": "0\.0\.0",
  658. "dependencies": {
  659. "express": "expressjs/express",
  660. "mocha": "mochajs/mocha#4727d357ea",
  661. "module": "user/repo#feature\\/branch"
  662. }
  663. }
  664. .fi
  665. .RE
  666. .SS Local Paths
  667. .P
  668. As of version 2\.0\.0 you can provide a path to a local directory that contains a
  669. package\. Local paths can be saved using \fBnpm install \-S\fP or
  670. \fBnpm install \-\-save\fP, using any of these forms:
  671. .P
  672. .RS 2
  673. .nf
  674. \|\.\./foo/bar
  675. ~/foo/bar
  676. \|\./foo/bar
  677. /foo/bar
  678. .fi
  679. .RE
  680. .P
  681. in which case they will be normalized to a relative path and added to your
  682. \fBpackage\.json\fP\|\. For example:
  683. .P
  684. .RS 2
  685. .nf
  686. {
  687. "name": "baz",
  688. "dependencies": {
  689. "bar": "file:\.\./foo/bar"
  690. }
  691. }
  692. .fi
  693. .RE
  694. .P
  695. This feature is helpful for local offline development and creating
  696. tests that require npm installing where you don't want to hit an
  697. external server, but should not be used when publishing packages
  698. to the public registry\.
  699. .SS devDependencies
  700. .P
  701. If someone is planning on downloading and using your module in their
  702. program, then they probably don't want or need to download and build
  703. the external test or documentation framework that you use\.
  704. .P
  705. In this case, it's best to map these additional items in a \fBdevDependencies\fP
  706. object\.
  707. .P
  708. These things will be installed when doing \fBnpm link\fP or \fBnpm install\fP
  709. from the root of a package, and can be managed like any other npm
  710. configuration param\. See npm help \fBconfig\fP for more on the topic\.
  711. .P
  712. For build steps that are not platform\-specific, such as compiling
  713. CoffeeScript or other languages to JavaScript, use the \fBprepare\fP
  714. script to do this, and make the required package a devDependency\.
  715. .P
  716. For example:
  717. .P
  718. .RS 2
  719. .nf
  720. { "name": "ethopia\-waza",
  721. "description": "a delightfully fruity coffee varietal",
  722. "version": "1\.2\.3",
  723. "devDependencies": {
  724. "coffee\-script": "~1\.6\.3"
  725. },
  726. "scripts": {
  727. "prepare": "coffee \-o lib/ \-c src/waza\.coffee"
  728. },
  729. "main": "lib/waza\.js"
  730. }
  731. .fi
  732. .RE
  733. .P
  734. The \fBprepare\fP script will be run before publishing, so that users
  735. can consume the functionality without requiring them to compile it
  736. themselves\. In dev mode (ie, locally running \fBnpm install\fP), it'll
  737. run this script as well, so that you can test it easily\.
  738. .SS peerDependencies
  739. .P
  740. In some cases, you want to express the compatibility of your package with a
  741. host tool or library, while not necessarily doing a \fBrequire\fP of this host\.
  742. This is usually referred to as a \fIplugin\fR\|\. Notably, your module may be exposing
  743. a specific interface, expected and specified by the host documentation\.
  744. .P
  745. For example:
  746. .P
  747. .RS 2
  748. .nf
  749. {
  750. "name": "tea\-latte",
  751. "version": "1\.3\.5",
  752. "peerDependencies": {
  753. "tea": "2\.x"
  754. }
  755. }
  756. .fi
  757. .RE
  758. .P
  759. This ensures your package \fBtea\-latte\fP can be installed \fIalong\fR with the second
  760. major version of the host package \fBtea\fP only\. \fBnpm install tea\-latte\fP could
  761. possibly yield the following dependency graph:
  762. .P
  763. .RS 2
  764. .nf
  765. ├── tea\-latte@1\.3\.5
  766. └── tea@2\.2\.0
  767. .fi
  768. .RE
  769. .P
  770. \fBNOTE: npm versions 1 and 2 will automatically install \fBpeerDependencies\fP if
  771. they are not explicitly depended upon higher in the dependency tree\. In the
  772. next major version of npm (npm@3), this will no longer be the case\. You will
  773. receive a warning that the peerDependency is not installed instead\.\fR The
  774. behavior in npms 1 & 2 was frequently confusing and could easily put you into
  775. dependency hell, a situation that npm is designed to avoid as much as possible\.
  776. .P
  777. Trying to install another plugin with a conflicting requirement will cause an
  778. error\. For this reason, make sure your plugin requirement is as broad as
  779. possible, and not to lock it down to specific patch versions\.
  780. .P
  781. Assuming the host complies with semver \fIhttps://semver\.org/\fR, only changes in
  782. the host package's major version will break your plugin\. Thus, if you've worked
  783. with every 1\.x version of the host package, use \fB"^1\.0"\fP or \fB"1\.x"\fP to express
  784. this\. If you depend on features introduced in 1\.5\.2, use \fB">= 1\.5\.2 < 2"\fP\|\.
  785. .SS bundledDependencies
  786. .P
  787. This defines an array of package names that will be bundled when publishing
  788. the package\.
  789. .P
  790. In cases where you need to preserve npm packages locally or have them
  791. available through a single file download, you can bundle the packages in a
  792. tarball file by specifying the package names in the \fBbundledDependencies\fP
  793. array and executing \fBnpm pack\fP\|\.
  794. .P
  795. For example:
  796. .P
  797. If we define a package\.json like this:
  798. .P
  799. .RS 2
  800. .nf
  801. {
  802. "name": "awesome\-web\-framework",
  803. "version": "1\.0\.0",
  804. "bundledDependencies": [
  805. "renderized", "super\-streams"
  806. ]
  807. }
  808. .fi
  809. .RE
  810. .P
  811. we can obtain \fBawesome\-web\-framework\-1\.0\.0\.tgz\fP file by running \fBnpm pack\fP\|\.
  812. This file contains the dependencies \fBrenderized\fP and \fBsuper\-streams\fP which
  813. can be installed in a new project by executing \fBnpm install
  814. awesome\-web\-framework\-1\.0\.0\.tgz\fP\|\. Note that the package names do not include
  815. any versions, as that information is specified in \fBdependencies\fP\|\.
  816. .P
  817. If this is spelled \fB"bundleDependencies"\fP, then that is also honored\.
  818. .SS optionalDependencies
  819. .P
  820. If a dependency can be used, but you would like npm to proceed if it cannot be
  821. found or fails to install, then you may put it in the \fBoptionalDependencies\fP
  822. object\. This is a map of package name to version or url, just like the
  823. \fBdependencies\fP object\. The difference is that build failures do not cause
  824. installation to fail\. Running \fBnpm install \-\-no\-optional\fP will prevent these
  825. dependencies from being installed\.
  826. .P
  827. It is still your program's responsibility to handle the lack of the
  828. dependency\. For example, something like this:
  829. .P
  830. .RS 2
  831. .nf
  832. try {
  833. var foo = require('foo')
  834. var fooVersion = require('foo/package\.json')\.version
  835. } catch (er) {
  836. foo = null
  837. }
  838. if ( notGoodFooVersion(fooVersion) ) {
  839. foo = null
  840. }
  841. // \.\. then later in your program \.\.
  842. if (foo) {
  843. foo\.doFooThings()
  844. }
  845. .fi
  846. .RE
  847. .P
  848. Entries in \fBoptionalDependencies\fP will override entries of the same name in
  849. \fBdependencies\fP, so it's usually best to only put in one place\.
  850. .SS engines
  851. .P
  852. You can specify the version of node that your stuff works on:
  853. .P
  854. .RS 2
  855. .nf
  856. { "engines" : { "node" : ">=0\.10\.3 <0\.12" } }
  857. .fi
  858. .RE
  859. .P
  860. And, like with dependencies, if you don't specify the version (or if you
  861. specify "*" as the version), then any version of node will do\.
  862. .P
  863. If you specify an "engines" field, then npm will require that "node" be
  864. somewhere on that list\. If "engines" is omitted, then npm will just assume
  865. that it works on node\.
  866. .P
  867. You can also use the "engines" field to specify which versions of npm
  868. are capable of properly installing your program\. For example:
  869. .P
  870. .RS 2
  871. .nf
  872. { "engines" : { "npm" : "~1\.0\.20" } }
  873. .fi
  874. .RE
  875. .P
  876. Unless the user has set the \fBengine\-strict\fP config flag, this
  877. field is advisory only and will only produce warnings when your package is installed as a dependency\.
  878. .SS engineStrict
  879. .P
  880. \fBThis feature was removed in npm 3\.0\.0\fR
  881. .P
  882. Prior to npm 3\.0\.0, this feature was used to treat this package as if the
  883. user had set \fBengine\-strict\fP\|\. It is no longer used\.
  884. .SS os
  885. .P
  886. You can specify which operating systems your
  887. module will run on:
  888. .P
  889. .RS 2
  890. .nf
  891. "os" : [ "darwin", "linux" ]
  892. .fi
  893. .RE
  894. .P
  895. You can also blacklist instead of whitelist operating systems,
  896. just prepend the blacklisted os with a '!':
  897. .P
  898. .RS 2
  899. .nf
  900. "os" : [ "!win32" ]
  901. .fi
  902. .RE
  903. .P
  904. The host operating system is determined by \fBprocess\.platform\fP
  905. .P
  906. It is allowed to both blacklist, and whitelist, although there isn't any
  907. good reason to do this\.
  908. .SS cpu
  909. .P
  910. If your code only runs on certain cpu architectures,
  911. you can specify which ones\.
  912. .P
  913. .RS 2
  914. .nf
  915. "cpu" : [ "x64", "ia32" ]
  916. .fi
  917. .RE
  918. .P
  919. Like the \fBos\fP option, you can also blacklist architectures:
  920. .P
  921. .RS 2
  922. .nf
  923. "cpu" : [ "!arm", "!mips" ]
  924. .fi
  925. .RE
  926. .P
  927. The host architecture is determined by \fBprocess\.arch\fP
  928. .SS preferGlobal
  929. .P
  930. \fBDEPRECATED\fR
  931. .P
  932. This option used to trigger an npm warning, but it will no longer warn\. It is
  933. purely there for informational purposes\. It is now recommended that you install
  934. any binaries as local devDependencies wherever possible\.
  935. .SS private
  936. .P
  937. If you set \fB"private": true\fP in your package\.json, then npm will refuse
  938. to publish it\.
  939. .P
  940. This is a way to prevent accidental publication of private repositories\. If
  941. you would like to ensure that a given package is only ever published to a
  942. specific registry (for example, an internal registry), then use the
  943. \fBpublishConfig\fP dictionary described below to override the \fBregistry\fP config
  944. param at publish\-time\.
  945. .SS publishConfig
  946. .P
  947. This is a set of config values that will be used at publish\-time\. It's
  948. especially handy if you want to set the tag, registry or access, so that
  949. you can ensure that a given package is not tagged with "latest", published
  950. to the global public registry or that a scoped module is private by default\.
  951. .P
  952. Any config values can be overridden, but only "tag", "registry" and "access"
  953. probably matter for the purposes of publishing\.
  954. .P
  955. See npm help \fBconfig\fP to see the list of config options that can be
  956. overridden\.
  957. .SS DEFAULT VALUES
  958. .P
  959. npm will default some values based on package contents\.
  960. .RS 0
  961. .IP \(bu 2
  962. \fB"scripts": {"start": "node server\.js"}\fP
  963. If there is a \fBserver\.js\fP file in the root of your package, then npm
  964. will default the \fBstart\fP command to \fBnode server\.js\fP\|\.
  965. .IP \(bu 2
  966. \fB"scripts":{"install": "node\-gyp rebuild"}\fP
  967. 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
  968. default the \fBinstall\fP command to compile using node\-gyp\.
  969. .IP \(bu 2
  970. \fB"contributors": [\.\.\.]\fP
  971. If there is an \fBAUTHORS\fP file in the root of your package, npm will
  972. treat each line as a \fBName <email> (url)\fP format, where email and url
  973. are optional\. Lines which start with a \fB#\fP or are blank, will be
  974. ignored\.
  975. .RE
  976. .SS SEE ALSO
  977. .RS 0
  978. .IP \(bu 2
  979. npm help semver
  980. .IP \(bu 2
  981. npm help init
  982. .IP \(bu 2
  983. npm help version
  984. .IP \(bu 2
  985. npm help config
  986. .IP \(bu 2
  987. npm help help
  988. .IP \(bu 2
  989. npm help install
  990. .IP \(bu 2
  991. npm help publish
  992. .IP \(bu 2
  993. npm help uninstall
  994. .RE