npm-publish.html 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383
  1. <html><head>
  2. <title>npm-publish</title>
  3. <style>
  4. body {
  5. background-color: #ffffff;
  6. color: #24292e;
  7. margin: 0;
  8. line-height: 1.5;
  9. font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji";
  10. }
  11. #rainbar {
  12. height: 10px;
  13. background-image: linear-gradient(139deg, #fb8817, #ff4b01, #c12127, #e02aff);
  14. }
  15. a {
  16. text-decoration: none;
  17. color: #0366d6;
  18. }
  19. a:hover {
  20. text-decoration: underline;
  21. }
  22. pre {
  23. margin: 1em 0px;
  24. padding: 1em;
  25. border: solid 1px #e1e4e8;
  26. border-radius: 6px;
  27. display: block;
  28. overflow: auto;
  29. white-space: pre;
  30. background-color: #f6f8fa;
  31. color: #393a34;
  32. }
  33. code {
  34. font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace;
  35. font-size: 85%;
  36. padding: 0.2em 0.4em;
  37. background-color: #f6f8fa;
  38. color: #393a34;
  39. }
  40. pre > code {
  41. padding: 0;
  42. background-color: inherit;
  43. color: inherit;
  44. }
  45. h1, h2, h3 {
  46. font-weight: 600;
  47. }
  48. #logobar {
  49. background-color: #333333;
  50. margin: 0 auto;
  51. padding: 1em 4em;
  52. }
  53. #logobar .logo {
  54. float: left;
  55. }
  56. #logobar .title {
  57. font-weight: 600;
  58. color: #dddddd;
  59. float: left;
  60. margin: 5px 0 0 1em;
  61. }
  62. #logobar:after {
  63. content: "";
  64. display: block;
  65. clear: both;
  66. }
  67. #content {
  68. margin: 0 auto;
  69. padding: 0 4em;
  70. }
  71. #table_of_contents > h2 {
  72. font-size: 1.17em;
  73. }
  74. #table_of_contents ul:first-child {
  75. border: solid 1px #e1e4e8;
  76. border-radius: 6px;
  77. padding: 1em;
  78. background-color: #f6f8fa;
  79. color: #393a34;
  80. }
  81. #table_of_contents ul {
  82. list-style-type: none;
  83. padding-left: 1.5em;
  84. }
  85. #table_of_contents li {
  86. font-size: 0.9em;
  87. }
  88. #table_of_contents li a {
  89. color: #000000;
  90. }
  91. header.title {
  92. border-bottom: solid 1px #e1e4e8;
  93. }
  94. header.title > h1 {
  95. margin-bottom: 0.25em;
  96. }
  97. header.title > .description {
  98. display: block;
  99. margin-bottom: 0.5em;
  100. line-height: 1;
  101. }
  102. footer#edit {
  103. border-top: solid 1px #e1e4e8;
  104. margin: 3em 0 4em 0;
  105. padding-top: 2em;
  106. }
  107. </style>
  108. </head>
  109. <body>
  110. <div id="banner">
  111. <div id="rainbar"></div>
  112. <div id="logobar">
  113. <svg class="logo" role="img" height="32" width="32" viewBox="0 0 700 700">
  114. <polygon fill="#cb0000" points="0,700 700,700 700,0 0,0"></polygon>
  115. <polygon fill="#ffffff" points="150,550 350,550 350,250 450,250 450,550 550,550 550,150 150,150"></polygon>
  116. </svg>
  117. <div class="title">
  118. npm command-line interface
  119. </div>
  120. </div>
  121. </div>
  122. <section id="content">
  123. <header class="title">
  124. <h1 id="npm-publish">npm-publish</h1>
  125. <span class="description">Publish a package</span>
  126. </header>
  127. <section id="table_of_contents">
  128. <h2 id="table-of-contents">Table of contents</h2>
  129. <div id="_table_of_contents"><ul><li><a href="#synopsis">Synopsis</a></li><li><a href="#description">Description</a></li><li><a href="#files-included-in-package">Files included in package</a></li><li><a href="#configuration">Configuration</a></li><ul><li><a href="#tag"><code>tag</code></a></li><li><a href="#access"><code>access</code></a></li><li><a href="#dry-run"><code>dry-run</code></a></li><li><a href="#otp"><code>otp</code></a></li><li><a href="#workspace"><code>workspace</code></a></li><li><a href="#workspaces"><code>workspaces</code></a></li><li><a href="#include-workspace-root"><code>include-workspace-root</code></a></li></ul><li><a href="#see-also">See Also</a></li></ul></div>
  130. </section>
  131. <div id="_content"><h3 id="synopsis">Synopsis</h3>
  132. <pre lang="bash"><code>npm publish [&lt;tarball&gt;|&lt;folder&gt;] [--tag &lt;tag&gt;] [--access &lt;public|restricted&gt;] [--otp otpcode] [--dry-run]
  133. Publishes '.' if no argument supplied
  134. Sets tag 'latest' if no --tag specified
  135. </code></pre>
  136. <h3 id="description">Description</h3>
  137. <p>Publishes a package to the registry so that it can be installed by name.</p>
  138. <p>By default npm will publish to the public registry. This can be overridden
  139. by specifying a different default registry or using a
  140. <a href="../using-npm/scope.html"><code>scope</code></a> in the name (see
  141. <a href="../configuring-npm/package-json.html"><code>package.json</code></a>).</p>
  142. <ul>
  143. <li>
  144. <p><code>&lt;folder&gt;</code>: A folder containing a package.json file</p>
  145. </li>
  146. <li>
  147. <p><code>&lt;tarball&gt;</code>: A url or file path to a gzipped tar archive containing a
  148. single folder with a package.json file inside.</p>
  149. </li>
  150. <li>
  151. <p><code>[--tag &lt;tag&gt;]</code>: Registers the published package with the given tag, such
  152. that <code>npm install &lt;name&gt;@&lt;tag&gt;</code> will install this version. By default,
  153. <code>npm publish</code> updates and <code>npm install</code> installs the <code>latest</code> tag. See
  154. <a href="npm-dist-tag"><code>npm-dist-tag</code></a> for details about tags.</p>
  155. </li>
  156. <li>
  157. <p><code>[--access &lt;public|restricted&gt;]</code>: Tells the registry whether this package
  158. should be published as public or restricted. Only applies to scoped
  159. packages, which default to <code>restricted</code>. If you don’t have a paid
  160. account, you must publish with <code>--access public</code> to publish scoped
  161. packages.</p>
  162. </li>
  163. <li>
  164. <p><code>[--otp &lt;otpcode&gt;]</code>: If you have two-factor authentication enabled in
  165. <code>auth-and-writes</code> mode then you can provide a code from your
  166. authenticator with this. If you don’t include this and you’re running
  167. from a TTY then you’ll be prompted.</p>
  168. </li>
  169. <li>
  170. <p><code>[--dry-run]</code>: As of <code>npm@6</code>, does everything publish would do except
  171. actually publishing to the registry. Reports the details of what would
  172. have been published.</p>
  173. </li>
  174. <li>
  175. <p><code>[--workspaces]</code>: Enables workspace context while publishing. All
  176. workspace packages will be published.</p>
  177. </li>
  178. <li>
  179. <p><code>[--workspace]</code>: Enables workspaces context and limits results to only
  180. those specified by this config item. Only the packages in the
  181. workspaces given will be published.</p>
  182. </li>
  183. </ul>
  184. <p>The publish will fail if the package name and version combination already
  185. exists in the specified registry.</p>
  186. <p>Once a package is published with a given name and version, that specific
  187. name and version combination can never be used again, even if it is removed
  188. with <a href="../commands/npm-unpublish.html"><code>npm unpublish</code></a>.</p>
  189. <p>As of <code>npm@5</code>, both a sha1sum and an integrity field with a sha512sum of the
  190. tarball will be submitted to the registry during publication. Subsequent
  191. installs will use the strongest supported algorithm to verify downloads.</p>
  192. <p>Similar to <code>--dry-run</code> see <a href="../commands/npm-pack.html"><code>npm pack</code></a>, which figures
  193. out the files to be included and packs them into a tarball to be uploaded
  194. to the registry.</p>
  195. <h3 id="files-included-in-package">Files included in package</h3>
  196. <p>To see what will be included in your package, run <code>npx npm-packlist</code>. All
  197. files are included by default, with the following exceptions:</p>
  198. <ul>
  199. <li>
  200. <p>Certain files that are relevant to package installation and distribution
  201. are always included. For example, <code>package.json</code>, <code>README.md</code>,
  202. <code>LICENSE</code>, and so on.</p>
  203. </li>
  204. <li>
  205. <p>If there is a “files” list in
  206. <a href="../configuring-npm/package-json.html"><code>package.json</code></a>, then only the files
  207. specified will be included. (If directories are specified, then they
  208. will be walked recursively and their contents included, subject to the
  209. same ignore rules.)</p>
  210. </li>
  211. <li>
  212. <p>If there is a <code>.gitignore</code> or <code>.npmignore</code> file, then ignored files in
  213. that and all child directories will be excluded from the package. If
  214. <em>both</em> files exist, then the <code>.gitignore</code> is ignored, and only the
  215. <code>.npmignore</code> is used.</p>
  216. <p><code>.npmignore</code> files follow the <a href="https://git-scm.com/book/en/v2/Git-Basics-Recording-Changes-to-the-Repository#_ignoring">same pattern
  217. rules</a>
  218. as <code>.gitignore</code> files</p>
  219. </li>
  220. <li>
  221. <p>If the file matches certain patterns, then it will <em>never</em> be included,
  222. unless explicitly added to the <code>"files"</code> list in <code>package.json</code>, or
  223. un-ignored with a <code>!</code> rule in a <code>.npmignore</code> or <code>.gitignore</code> file.</p>
  224. </li>
  225. <li>
  226. <p>Symbolic links are never included in npm packages.</p>
  227. </li>
  228. </ul>
  229. <p>See <a href="../using-npm/developers.html"><code>developers</code></a> for full details on what’s
  230. included in the published package, as well as details on how the package is
  231. built.</p>
  232. <h3 id="configuration">Configuration</h3>
  233. <!-- raw HTML omitted -->
  234. <!-- raw HTML omitted -->
  235. <!-- raw HTML omitted -->
  236. <h4 id="tag"><code>tag</code></h4>
  237. <ul>
  238. <li>Default: “latest”</li>
  239. <li>Type: String</li>
  240. </ul>
  241. <p>If you ask npm to install a package and don’t tell it a specific version,
  242. then it will install the specified tag.</p>
  243. <p>Also the tag that is added to the package@version specified by the <code>npm tag</code>
  244. command, if no explicit tag is given.</p>
  245. <p>When used by the <code>npm diff</code> command, this is the tag used to fetch the
  246. tarball that will be compared with the local files by default.</p>
  247. <!-- raw HTML omitted -->
  248. <!-- raw HTML omitted -->
  249. <h4 id="access"><code>access</code></h4>
  250. <ul>
  251. <li>Default: ‘restricted’ for scoped packages, ‘public’ for unscoped packages</li>
  252. <li>Type: null, “restricted”, or “public”</li>
  253. </ul>
  254. <p>When publishing scoped packages, the access level defaults to <code>restricted</code>.
  255. If you want your scoped package to be publicly viewable (and installable)
  256. set <code>--access=public</code>. The only valid values for <code>access</code> are <code>public</code> and
  257. <code>restricted</code>. Unscoped packages <em>always</em> have an access level of <code>public</code>.</p>
  258. <p>Note: Using the <code>--access</code> flag on the <code>npm publish</code> command will only set
  259. the package access level on the initial publish of the package. Any
  260. subsequent <code>npm publish</code> commands using the <code>--access</code> flag will not have an
  261. effect to the access level. To make changes to the access level after the
  262. initial publish use <code>npm access</code>.</p>
  263. <!-- raw HTML omitted -->
  264. <!-- raw HTML omitted -->
  265. <h4 id="dry-run"><code>dry-run</code></h4>
  266. <ul>
  267. <li>Default: false</li>
  268. <li>Type: Boolean</li>
  269. </ul>
  270. <p>Indicates that you don’t want npm to make any changes and that it should
  271. only report what it would have done. This can be passed into any of the
  272. commands that modify your local installation, eg, <code>install</code>, <code>update</code>,
  273. <code>dedupe</code>, <code>uninstall</code>, as well as <code>pack</code> and <code>publish</code>.</p>
  274. <p>Note: This is NOT honored by other network related commands, eg <code>dist-tags</code>,
  275. <code>owner</code>, etc.</p>
  276. <!-- raw HTML omitted -->
  277. <!-- raw HTML omitted -->
  278. <h4 id="otp"><code>otp</code></h4>
  279. <ul>
  280. <li>Default: null</li>
  281. <li>Type: null or String</li>
  282. </ul>
  283. <p>This is a one-time password from a two-factor authenticator. It’s needed
  284. when publishing or changing package permissions with <code>npm access</code>.</p>
  285. <p>If not set, and a registry response fails with a challenge for a one-time
  286. password, npm will prompt on the command line for one.</p>
  287. <!-- raw HTML omitted -->
  288. <!-- raw HTML omitted -->
  289. <h4 id="workspace"><code>workspace</code></h4>
  290. <ul>
  291. <li>Default:</li>
  292. <li>Type: String (can be set multiple times)</li>
  293. </ul>
  294. <p>Enable running a command in the context of the configured workspaces of the
  295. current project while filtering by running only the workspaces defined by
  296. this configuration option.</p>
  297. <p>Valid values for the <code>workspace</code> config are either:</p>
  298. <ul>
  299. <li>Workspace names</li>
  300. <li>Path to a workspace directory</li>
  301. <li>Path to a parent workspace directory (will result in selecting all
  302. workspaces within that folder)</li>
  303. </ul>
  304. <p>When set for the <code>npm init</code> command, this may be set to the folder of a
  305. workspace which does not yet exist, to create the folder and set it up as a
  306. brand new workspace within the project.</p>
  307. <p>This value is not exported to the environment for child processes.</p>
  308. <!-- raw HTML omitted -->
  309. <!-- raw HTML omitted -->
  310. <h4 id="workspaces"><code>workspaces</code></h4>
  311. <ul>
  312. <li>Default: null</li>
  313. <li>Type: null or Boolean</li>
  314. </ul>
  315. <p>Set to true to run the command in the context of <strong>all</strong> configured
  316. workspaces.</p>
  317. <p>Explicitly setting this to false will cause commands like <code>install</code> to
  318. ignore workspaces altogether. When not set explicitly:</p>
  319. <ul>
  320. <li>Commands that operate on the <code>node_modules</code> tree (install, update, etc.)
  321. will link workspaces into the <code>node_modules</code> folder. - Commands that do
  322. other things (test, exec, publish, etc.) will operate on the root project,
  323. <em>unless</em> one or more workspaces are specified in the <code>workspace</code> config.</li>
  324. </ul>
  325. <p>This value is not exported to the environment for child processes.</p>
  326. <!-- raw HTML omitted -->
  327. <!-- raw HTML omitted -->
  328. <h4 id="include-workspace-root"><code>include-workspace-root</code></h4>
  329. <ul>
  330. <li>Default: false</li>
  331. <li>Type: Boolean</li>
  332. </ul>
  333. <p>Include the workspace root when workspaces are enabled for a command.</p>
  334. <p>When false, specifying individual workspaces via the <code>workspace</code> config, or
  335. all workspaces via the <code>workspaces</code> flag, will cause npm to operate only on
  336. the specified workspaces, and not on the root project.</p>
  337. <!-- raw HTML omitted -->
  338. <!-- raw HTML omitted -->
  339. <!-- raw HTML omitted -->
  340. <h3 id="see-also">See Also</h3>
  341. <ul>
  342. <li><a href="http://npm.im/npm-packlist">npm-packlist package</a></li>
  343. <li><a href="../using-npm/registry.html">npm registry</a></li>
  344. <li><a href="../using-npm/scope.html">npm scope</a></li>
  345. <li><a href="../commands/npm-adduser.html">npm adduser</a></li>
  346. <li><a href="../commands/npm-owner.html">npm owner</a></li>
  347. <li><a href="../commands/npm-deprecate.html">npm deprecate</a></li>
  348. <li><a href="../commands/npm-dist-tag.html">npm dist-tag</a></li>
  349. <li><a href="../commands/npm-pack.html">npm pack</a></li>
  350. <li><a href="../commands/npm-profile.html">npm profile</a></li>
  351. </ul>
  352. </div>
  353. <footer id="edit">
  354. <a href="https://github.com/npm/cli/edit/latest/docs/content/commands/npm-publish.md">
  355. <svg role="img" viewBox="0 0 16 16" width="16" height="16" fill="currentcolor" style="vertical-align: text-bottom; margin-right: 0.3em;">
  356. <path fill-rule="evenodd" d="M11.013 1.427a1.75 1.75 0 012.474 0l1.086 1.086a1.75 1.75 0 010 2.474l-8.61 8.61c-.21.21-.47.364-.756.445l-3.251.93a.75.75 0 01-.927-.928l.929-3.25a1.75 1.75 0 01.445-.758l8.61-8.61zm1.414 1.06a.25.25 0 00-.354 0L10.811 3.75l1.439 1.44 1.263-1.263a.25.25 0 000-.354l-1.086-1.086zM11.189 6.25L9.75 4.81l-6.286 6.287a.25.25 0 00-.064.108l-.558 1.953 1.953-.558a.249.249 0 00.108-.064l6.286-6.286z"></path>
  357. </svg>
  358. Edit this page on GitHub
  359. </a>
  360. </footer>
  361. </section>
  362. </body></html>