npm-pkg.1 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318
  1. .TH "NPM\-PKG" "1" "October 2021" "" ""
  2. .SH "NAME"
  3. \fBnpm-pkg\fR \- Manages your package\.json
  4. .SS Synopsis
  5. .P
  6. .RS 2
  7. .nf
  8. npm pkg get [<field> [\.<subfield> \.\.\.]]
  9. npm pkg set <field>=<value> [\.<subfield>=<value> \.\.\.]
  10. npm pkg delete <field> [\.<subfield> \.\.\.]
  11. .fi
  12. .RE
  13. .SS Description
  14. .P
  15. A command that automates the management of \fBpackage\.json\fP files\.
  16. \fBnpm pkg\fP provide 3 different sub commands that allow you to modify or retrieve
  17. values for given object keys in your \fBpackage\.json\fP\|\.
  18. .P
  19. The syntax to retrieve and set fields is a dot separated representation of
  20. the nested object properties to be found within your \fBpackage\.json\fP, it's the
  21. same notation used in npm help \fBview\fP to retrieve information
  22. from the registry manifest, below you can find more examples on how to use it\.
  23. .P
  24. Returned values are always in \fBjson\fR format\.
  25. .RS 0
  26. .IP \(bu 2
  27. \fBnpm pkg get <field>\fP
  28. Retrieves a value \fBkey\fP, defined in your \fBpackage\.json\fP file\.
  29. For example, in order to retrieve the name of the current package, you
  30. can run:
  31. .P
  32. .RS 2
  33. .nf
  34. npm pkg get name
  35. .fi
  36. .RE
  37. It's also possible to retrieve multiple values at once:
  38. .P
  39. .RS 2
  40. .nf
  41. npm pkg get name version
  42. .fi
  43. .RE
  44. You can view child fields by separating them with a period\. To retrieve
  45. the value of a test \fBscript\fP value, you would run the following command:
  46. .P
  47. .RS 2
  48. .nf
  49. npm pkg get scripts\.test
  50. .fi
  51. .RE
  52. For fields that are arrays, requesting a non\-numeric field will return
  53. all of the values from the objects in the list\. For example, to get all
  54. the contributor emails for a package, you would run:
  55. .P
  56. .RS 2
  57. .nf
  58. npm pkg get contributors\.email
  59. .fi
  60. .RE
  61. You may also use numeric indices in square braces to specifically select
  62. an item in an array field\. To just get the email address of the first
  63. contributor in the list, you can run:
  64. .P
  65. .RS 2
  66. .nf
  67. npm pkg get contributors[0]\.email
  68. .fi
  69. .RE
  70. .IP \(bu 2
  71. \fBnpm pkg set <field>=<value>\fP
  72. Sets a \fBvalue\fP in your \fBpackage\.json\fP based on the \fBfield\fP value\. When
  73. saving to your \fBpackage\.json\fP file the same set of rules used during
  74. \fBnpm install\fP and other cli commands that touches the \fBpackage\.json\fP file
  75. are used, making sure to respect the existing indentation and possibly
  76. applying some validation prior to saving values to the file\.
  77. The same syntax used to retrieve values from your package can also be used
  78. to define new properties or overriding existing ones, below are some
  79. examples of how the dot separated syntax can be used to edit your
  80. \fBpackage\.json\fP file\.
  81. Defining a new bin named \fBmynewcommand\fP in your \fBpackage\.json\fP that points
  82. to a file \fBcli\.js\fP:
  83. .P
  84. .RS 2
  85. .nf
  86. npm pkg set bin\.mynewcommand=cli\.js
  87. .fi
  88. .RE
  89. Setting multiple fields at once is also possible:
  90. .P
  91. .RS 2
  92. .nf
  93. npm pkg set description='Awesome package' engines\.node='>=10'
  94. .fi
  95. .RE
  96. It's also possible to add to array values, for example to add a new
  97. contributor entry:
  98. .P
  99. .RS 2
  100. .nf
  101. npm pkg set contributors[0]\.name='Foo' contributors[0]\.email='foo@bar\.ca'
  102. .fi
  103. .RE
  104. You may also append items to the end of an array using the special
  105. empty bracket notation:
  106. .P
  107. .RS 2
  108. .nf
  109. npm pkg set contributors[]\.name='Foo' contributors[]\.name='Bar'
  110. .fi
  111. .RE
  112. It's also possible to parse values as json prior to saving them to your
  113. \fBpackage\.json\fP file, for example in order to set a \fB"private": true\fP
  114. property:
  115. .P
  116. .RS 2
  117. .nf
  118. npm pkg set private=true \-\-json
  119. .fi
  120. .RE
  121. It also enables saving values as numbers:
  122. .P
  123. .RS 2
  124. .nf
  125. npm pkg set tap\.timeout=60 \-\-json
  126. .fi
  127. .RE
  128. .IP \(bu 2
  129. \fBnpm pkg delete <key>\fP
  130. Deletes a \fBkey\fP from your \fBpackage\.json\fP
  131. The same syntax used to set values from your package can also be used
  132. to remove existing ones\. For example, in order to remove a script named
  133. build:
  134. .P
  135. .RS 2
  136. .nf
  137. npm pkg delete scripts\.build
  138. .fi
  139. .RE
  140. .RE
  141. .SS Workspaces support
  142. .P
  143. You can set/get/delete items across your configured workspaces by using the
  144. \fBworkspace\fP or \fBworkspaces\fP config options\.
  145. .P
  146. For example, setting a \fBfunding\fP value across all configured workspaces
  147. of a project:
  148. .P
  149. .RS 2
  150. .nf
  151. npm pkg set funding=https://example\.com \-\-ws
  152. .fi
  153. .RE
  154. .P
  155. When using \fBnpm pkg get\fP to retrieve info from your configured workspaces, the
  156. returned result will be in a json format in which top level keys are the
  157. names of each workspace, the values of these keys will be the result values
  158. returned from each of the configured workspaces, e\.g:
  159. .P
  160. .RS 2
  161. .nf
  162. npm pkg get name version \-\-ws
  163. {
  164. "a": {
  165. "name": "a",
  166. "version": "1\.0\.0"
  167. },
  168. "b": {
  169. "name": "b",
  170. "version": "1\.0\.0"
  171. }
  172. }
  173. .fi
  174. .RE
  175. .SS Configuration
  176. <!\-\- AUTOGENERATED CONFIG DESCRIPTIONS START \-\->
  177. <!\-\- automatically generated, do not edit manually \-\->
  178. <!\-\- see lib/utils/config/definitions\.js \-\->
  179. .SS \fBforce\fP
  180. .RS 0
  181. .IP \(bu 2
  182. Default: false
  183. .IP \(bu 2
  184. Type: Boolean
  185. .RE
  186. .P
  187. Removes various protections against unfortunate side effects, common
  188. mistakes, unnecessary performance degradation, and malicious input\.
  189. .RS 0
  190. .IP \(bu 2
  191. Allow clobbering non\-npm files in global installs\.
  192. .IP \(bu 2
  193. Allow the \fBnpm version\fP command to work on an unclean git repository\.
  194. .IP \(bu 2
  195. Allow deleting the cache folder with \fBnpm cache clean\fP\|\.
  196. .IP \(bu 2
  197. Allow installing packages that have an \fBengines\fP declaration requiring a
  198. different version of npm\.
  199. .IP \(bu 2
  200. Allow installing packages that have an \fBengines\fP declaration requiring a
  201. different version of \fBnode\fP, even if \fB\-\-engine\-strict\fP is enabled\.
  202. .IP \(bu 2
  203. Allow \fBnpm audit fix\fP to install modules outside your stated dependency
  204. range (including SemVer\-major changes)\.
  205. .IP \(bu 2
  206. Allow unpublishing all versions of a published package\.
  207. .IP \(bu 2
  208. Allow conflicting peerDependencies to be installed in the root project\.
  209. .IP \(bu 2
  210. Implicitly set \fB\-\-yes\fP during \fBnpm init\fP\|\.
  211. .IP \(bu 2
  212. Allow clobbering existing values in \fBnpm pkg\fP
  213. .RE
  214. .P
  215. If you don't have a clear idea of what you want to do, it is strongly
  216. recommended that you do not use this option!
  217. <!\-\- automatically generated, do not edit manually \-\->
  218. <!\-\- see lib/utils/config/definitions\.js \-\->
  219. .SS \fBjson\fP
  220. .RS 0
  221. .IP \(bu 2
  222. Default: false
  223. .IP \(bu 2
  224. Type: Boolean
  225. .RE
  226. .P
  227. Whether or not to output JSON data, rather than the normal output\.
  228. .RS 0
  229. .IP \(bu 2
  230. In \fBnpm pkg set\fP it enables parsing set values with JSON\.parse() before
  231. saving them to your \fBpackage\.json\fP\|\.
  232. .RE
  233. .P
  234. Not supported by all npm commands\.
  235. <!\-\- automatically generated, do not edit manually \-\->
  236. <!\-\- see lib/utils/config/definitions\.js \-\->
  237. .SS \fBworkspace\fP
  238. .RS 0
  239. .IP \(bu 2
  240. Default:
  241. .IP \(bu 2
  242. Type: String (can be set multiple times)
  243. .RE
  244. .P
  245. Enable running a command in the context of the configured workspaces of the
  246. current project while filtering by running only the workspaces defined by
  247. this configuration option\.
  248. .P
  249. Valid values for the \fBworkspace\fP config are either:
  250. .RS 0
  251. .IP \(bu 2
  252. Workspace names
  253. .IP \(bu 2
  254. Path to a workspace directory
  255. .IP \(bu 2
  256. Path to a parent workspace directory (will result in selecting all
  257. workspaces within that folder)
  258. .RE
  259. .P
  260. When set for the \fBnpm init\fP command, this may be set to the folder of a
  261. workspace which does not yet exist, to create the folder and set it up as a
  262. brand new workspace within the project\.
  263. .P
  264. This value is not exported to the environment for child processes\.
  265. <!\-\- automatically generated, do not edit manually \-\->
  266. <!\-\- see lib/utils/config/definitions\.js \-\->
  267. .SS \fBworkspaces\fP
  268. .RS 0
  269. .IP \(bu 2
  270. Default: null
  271. .IP \(bu 2
  272. Type: null or Boolean
  273. .RE
  274. .P
  275. Set to true to run the command in the context of \fBall\fR configured
  276. workspaces\.
  277. .P
  278. Explicitly setting this to false will cause commands like \fBinstall\fP to
  279. ignore workspaces altogether\. When not set explicitly:
  280. .RS 0
  281. .IP \(bu 2
  282. Commands that operate on the \fBnode_modules\fP tree (install, update, etc\.)
  283. will link workspaces into the \fBnode_modules\fP folder\. \- Commands that do
  284. other things (test, exec, publish, etc\.) will operate on the root project,
  285. \fIunless\fR one or more workspaces are specified in the \fBworkspace\fP config\.
  286. .RE
  287. .P
  288. This value is not exported to the environment for child processes\.
  289. <!\-\- automatically generated, do not edit manually \-\->
  290. <!\-\- see lib/utils/config/definitions\.js \-\->
  291. <!\-\- AUTOGENERATED CONFIG DESCRIPTIONS END \-\->
  292. .SH See Also
  293. .RS 0
  294. .IP \(bu 2
  295. npm help install
  296. .IP \(bu 2
  297. npm help init
  298. .IP \(bu 2
  299. npm help config
  300. .IP \(bu 2
  301. npm help set\-script
  302. .IP \(bu 2
  303. npm help workspaces
  304. .RE