npm-init.1 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322
  1. .TH "NPM\-INIT" "1" "October 2021" "" ""
  2. .SH "NAME"
  3. \fBnpm-init\fR \- Create a package\.json file
  4. .SS Synopsis
  5. .P
  6. .RS 2
  7. .nf
  8. npm init [\-\-yes|\-y|\-\-scope]
  9. npm init <@scope> (same as `npm exec <@scope>/create`)
  10. npm init [<@scope>/]<name> (same as `npm exec [<@scope>/]create\-<name>`)
  11. npm init [\-w <dir>] [args\.\.\.]
  12. .fi
  13. .RE
  14. .SS Description
  15. .P
  16. \fBnpm init <initializer>\fP can be used to set up a new or existing npm
  17. package\.
  18. .P
  19. \fBinitializer\fP in this case is an npm package named \fBcreate\-<initializer>\fP,
  20. which will be installed by npm help \fBnpm\-exec\fP, and then have its
  21. main bin executed \-\- presumably creating or updating \fBpackage\.json\fP and
  22. running any other initialization\-related operations\.
  23. .P
  24. The init command is transformed to a corresponding \fBnpm exec\fP operation as
  25. follows:
  26. .RS 0
  27. .IP \(bu 2
  28. \fBnpm init foo\fP \-> \fBnpm exec create\-foo\fP
  29. .IP \(bu 2
  30. \fBnpm init @usr/foo\fP \-> \fBnpm exec @usr/create\-foo\fP
  31. .IP \(bu 2
  32. \fBnpm init @usr\fP \-> \fBnpm exec @usr/create\fP
  33. .RE
  34. .P
  35. If the initializer is omitted (by just calling \fBnpm init\fP), init will fall
  36. back to legacy init behavior\. It will ask you a bunch of questions, and
  37. then write a package\.json for you\. It will attempt to make reasonable
  38. guesses based on existing fields, dependencies, and options selected\. It is
  39. strictly additive, so it will keep any fields and values that were already
  40. set\. You can also use \fB\-y\fP/\fB\-\-yes\fP to skip the questionnaire altogether\. If
  41. you pass \fB\-\-scope\fP, it will create a scoped package\.
  42. .SS Forwarding additional options
  43. .P
  44. Any additional options will be passed directly to the command, so \fBnpm init
  45. foo \-\- \-\-hello\fP will map to \fBnpm exec \-\- create\-foo \-\-hello\fP\|\.
  46. .P
  47. To better illustrate how options are forwarded, here's a more evolved
  48. example showing options passed to both the \fBnpm cli\fR and a create package,
  49. both following commands are equivalent:
  50. .RS 0
  51. .IP \(bu 2
  52. \fBnpm init foo \-y \-\-registry=<url> \-\- \-\-hello \-a\fP
  53. .IP \(bu 2
  54. \fBnpm exec \-y \-\-registry=<url> \-\- create\-foo \-\-hello \-a\fP
  55. .RE
  56. .SS Examples
  57. .P
  58. Create a new React\-based project using
  59. \fBcreate\-react\-app\fP \fIhttps://npm\.im/create\-react\-app\fR:
  60. .P
  61. .RS 2
  62. .nf
  63. $ npm init react\-app \./my\-react\-app
  64. .fi
  65. .RE
  66. .P
  67. Create a new \fBesm\fP\-compatible package using
  68. \fBcreate\-esm\fP \fIhttps://npm\.im/create\-esm\fR:
  69. .P
  70. .RS 2
  71. .nf
  72. $ mkdir my\-esm\-lib && cd my\-esm\-lib
  73. $ npm init esm \-\-yes
  74. .fi
  75. .RE
  76. .P
  77. Generate a plain old package\.json using legacy init:
  78. .P
  79. .RS 2
  80. .nf
  81. $ mkdir my\-npm\-pkg && cd my\-npm\-pkg
  82. $ git init
  83. $ npm init
  84. .fi
  85. .RE
  86. .P
  87. Generate it without having it ask any questions:
  88. .P
  89. .RS 2
  90. .nf
  91. $ npm init \-y
  92. .fi
  93. .RE
  94. .SS Workspaces support
  95. .P
  96. It's possible to create a new workspace within your project by using the
  97. \fBworkspace\fP config option\. When using \fBnpm init \-w <dir>\fP the cli will
  98. create the folders and boilerplate expected while also adding a reference
  99. to your project \fBpackage\.json\fP \fB"workspaces": []\fP property in order to make
  100. sure that new generated \fBworkspace\fR is properly set up as such\.
  101. .P
  102. Given a project with no workspaces, e\.g:
  103. .P
  104. .RS 2
  105. .nf
  106. \|\.
  107. +\-\- package\.json
  108. .fi
  109. .RE
  110. .P
  111. You may generate a new workspace using the legacy init:
  112. .P
  113. .RS 2
  114. .nf
  115. $ npm init \-w packages/a
  116. .fi
  117. .RE
  118. .P
  119. That will generate a new folder and \fBpackage\.json\fP file, while also updating
  120. your top\-level \fBpackage\.json\fP to add the reference to this new workspace:
  121. .P
  122. .RS 2
  123. .nf
  124. \|\.
  125. +\-\- package\.json
  126. `\-\- packages
  127. `\-\- a
  128. `\-\- package\.json
  129. .fi
  130. .RE
  131. .P
  132. The workspaces init also supports the \fBnpm init <initializer> \-w <dir>\fP
  133. syntax, following the same set of rules explained earlier in the initial
  134. \fBDescription\fR section of this page\. Similar to the previous example of
  135. creating a new React\-based project using
  136. \fBcreate\-react\-app\fP \fIhttps://npm\.im/create\-react\-app\fR, the following syntax
  137. will make sure to create the new react app as a nested \fBworkspace\fR within your
  138. project and configure your \fBpackage\.json\fP to recognize it as such:
  139. .P
  140. .RS 2
  141. .nf
  142. npm init \-w packages/my\-react\-app react\-app \.
  143. .fi
  144. .RE
  145. .P
  146. This will make sure to generate your react app as expected, one important
  147. consideration to have in mind is that \fBnpm exec\fP is going to be run in the
  148. context of the newly created folder for that workspace, and that's the reason
  149. why in this example the initializer uses the initializer name followed with a
  150. dot to represent the current directory in that context, e\.g: \fBreact\-app \.\fP:
  151. .P
  152. .RS 2
  153. .nf
  154. \|\.
  155. +\-\- package\.json
  156. `\-\- packages
  157. +\-\- a
  158. | `\-\- package\.json
  159. `\-\- my\-react\-app
  160. +\-\- README
  161. +\-\- package\.json
  162. `\-\- \.\.\.
  163. .fi
  164. .RE
  165. .SS Configuration
  166. <!\-\- AUTOGENERATED CONFIG DESCRIPTIONS START \-\->
  167. <!\-\- automatically generated, do not edit manually \-\->
  168. <!\-\- see lib/utils/config/definitions\.js \-\->
  169. .SS \fByes\fP
  170. .RS 0
  171. .IP \(bu 2
  172. Default: null
  173. .IP \(bu 2
  174. Type: null or Boolean
  175. .RE
  176. .P
  177. Automatically answer "yes" to any prompts that npm might print on the
  178. command line\.
  179. <!\-\- automatically generated, do not edit manually \-\->
  180. <!\-\- see lib/utils/config/definitions\.js \-\->
  181. .SS \fBforce\fP
  182. .RS 0
  183. .IP \(bu 2
  184. Default: false
  185. .IP \(bu 2
  186. Type: Boolean
  187. .RE
  188. .P
  189. Removes various protections against unfortunate side effects, common
  190. mistakes, unnecessary performance degradation, and malicious input\.
  191. .RS 0
  192. .IP \(bu 2
  193. Allow clobbering non\-npm files in global installs\.
  194. .IP \(bu 2
  195. Allow the \fBnpm version\fP command to work on an unclean git repository\.
  196. .IP \(bu 2
  197. Allow deleting the cache folder with \fBnpm cache clean\fP\|\.
  198. .IP \(bu 2
  199. Allow installing packages that have an \fBengines\fP declaration requiring a
  200. different version of npm\.
  201. .IP \(bu 2
  202. Allow installing packages that have an \fBengines\fP declaration requiring a
  203. different version of \fBnode\fP, even if \fB\-\-engine\-strict\fP is enabled\.
  204. .IP \(bu 2
  205. Allow \fBnpm audit fix\fP to install modules outside your stated dependency
  206. range (including SemVer\-major changes)\.
  207. .IP \(bu 2
  208. Allow unpublishing all versions of a published package\.
  209. .IP \(bu 2
  210. Allow conflicting peerDependencies to be installed in the root project\.
  211. .IP \(bu 2
  212. Implicitly set \fB\-\-yes\fP during \fBnpm init\fP\|\.
  213. .IP \(bu 2
  214. Allow clobbering existing values in \fBnpm pkg\fP
  215. .RE
  216. .P
  217. If you don't have a clear idea of what you want to do, it is strongly
  218. recommended that you do not use this option!
  219. <!\-\- automatically generated, do not edit manually \-\->
  220. <!\-\- see lib/utils/config/definitions\.js \-\->
  221. .SS \fBworkspace\fP
  222. .RS 0
  223. .IP \(bu 2
  224. Default:
  225. .IP \(bu 2
  226. Type: String (can be set multiple times)
  227. .RE
  228. .P
  229. Enable running a command in the context of the configured workspaces of the
  230. current project while filtering by running only the workspaces defined by
  231. this configuration option\.
  232. .P
  233. Valid values for the \fBworkspace\fP config are either:
  234. .RS 0
  235. .IP \(bu 2
  236. Workspace names
  237. .IP \(bu 2
  238. Path to a workspace directory
  239. .IP \(bu 2
  240. Path to a parent workspace directory (will result in selecting all
  241. workspaces within that folder)
  242. .RE
  243. .P
  244. When set for the \fBnpm init\fP command, this may be set to the folder of a
  245. workspace which does not yet exist, to create the folder and set it up as a
  246. brand new workspace within the project\.
  247. .P
  248. This value is not exported to the environment for child processes\.
  249. <!\-\- automatically generated, do not edit manually \-\->
  250. <!\-\- see lib/utils/config/definitions\.js \-\->
  251. .SS \fBworkspaces\fP
  252. .RS 0
  253. .IP \(bu 2
  254. Default: null
  255. .IP \(bu 2
  256. Type: null or Boolean
  257. .RE
  258. .P
  259. Set to true to run the command in the context of \fBall\fR configured
  260. workspaces\.
  261. .P
  262. Explicitly setting this to false will cause commands like \fBinstall\fP to
  263. ignore workspaces altogether\. When not set explicitly:
  264. .RS 0
  265. .IP \(bu 2
  266. Commands that operate on the \fBnode_modules\fP tree (install, update, etc\.)
  267. will link workspaces into the \fBnode_modules\fP folder\. \- Commands that do
  268. other things (test, exec, publish, etc\.) will operate on the root project,
  269. \fIunless\fR one or more workspaces are specified in the \fBworkspace\fP config\.
  270. .RE
  271. .P
  272. This value is not exported to the environment for child processes\.
  273. <!\-\- automatically generated, do not edit manually \-\->
  274. <!\-\- see lib/utils/config/definitions\.js \-\->
  275. .SS \fBinclude\-workspace\-root\fP
  276. .RS 0
  277. .IP \(bu 2
  278. Default: false
  279. .IP \(bu 2
  280. Type: Boolean
  281. .RE
  282. .P
  283. Include the workspace root when workspaces are enabled for a command\.
  284. .P
  285. When false, specifying individual workspaces via the \fBworkspace\fP config, or
  286. all workspaces via the \fBworkspaces\fP flag, will cause npm to operate only on
  287. the specified workspaces, and not on the root project\.
  288. <!\-\- automatically generated, do not edit manually \-\->
  289. <!\-\- see lib/utils/config/definitions\.js \-\->
  290. <!\-\- AUTOGENERATED CONFIG DESCRIPTIONS END \-\->
  291. .SS See Also
  292. .RS 0
  293. .IP \(bu 2
  294. init\-package\-json module \fIhttp://npm\.im/init\-package\-json\fR
  295. .IP \(bu 2
  296. npm help package\.json
  297. .IP \(bu 2
  298. npm help version
  299. .IP \(bu 2
  300. npm help scope
  301. .IP \(bu 2
  302. npm help exec
  303. .IP \(bu 2
  304. npm help workspaces
  305. .RE