scope.7 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. .TH "SCOPE" "7" "August 2021" "" ""
  2. .SH "NAME"
  3. \fBscope\fR \- Scoped packages
  4. .SS Description
  5. .P
  6. All npm packages have a name\. Some package names also have a scope\. A scope
  7. follows the usual rules for package names (URL\-safe characters, no leading dots
  8. or underscores)\. When used in package names, scopes are preceded by an \fB@\fP symbol
  9. and followed by a slash, e\.g\.
  10. .P
  11. .RS 2
  12. .nf
  13. @somescope/somepackagename
  14. .fi
  15. .RE
  16. .P
  17. Scopes are a way of grouping related packages together, and also affect a few
  18. things about the way npm treats the package\.
  19. .P
  20. Each npm user/organization has their own scope, and only you can add packages
  21. in your scope\. This means you don't have to worry about someone taking your
  22. package name ahead of you\. Thus it is also a good way to signal official packages
  23. for organizations\.
  24. .P
  25. Scoped packages can be published and installed as of \fBnpm@2\fP and are supported
  26. by the primary npm registry\. Unscoped packages can depend on scoped packages and
  27. vice versa\. The npm client is backwards\-compatible with unscoped registries,
  28. so it can be used to work with scoped and unscoped registries at the same time\.
  29. .SS Installing scoped packages
  30. .P
  31. Scoped packages are installed to a sub\-folder of the regular installation
  32. folder, e\.g\. if your other packages are installed in \fBnode_modules/packagename\fP,
  33. scoped modules will be installed in \fBnode_modules/@myorg/packagename\fP\|\. The scope
  34. folder (\fB@myorg\fP) is simply the name of the scope preceded by an \fB@\fP symbol, and can
  35. contain any number of scoped packages\.
  36. .P
  37. A scoped package is installed by referencing it by name, preceded by an
  38. \fB@\fP symbol, in \fBnpm install\fP:
  39. .P
  40. .RS 2
  41. .nf
  42. npm install @myorg/mypackage
  43. .fi
  44. .RE
  45. .P
  46. Or in \fBpackage\.json\fP:
  47. .P
  48. .RS 2
  49. .nf
  50. "dependencies": {
  51. "@myorg/mypackage": "^1\.3\.0"
  52. }
  53. .fi
  54. .RE
  55. .P
  56. Note that if the \fB@\fP symbol is omitted, in either case, npm will instead attempt to
  57. install from GitHub; see npm help \fBinstall\fP\|\.
  58. .SS Requiring scoped packages
  59. .P
  60. Because scoped packages are installed into a scope folder, you have to
  61. include the name of the scope when requiring them in your code, e\.g\.
  62. .P
  63. .RS 2
  64. .nf
  65. require('@myorg/mypackage')
  66. .fi
  67. .RE
  68. .P
  69. There is nothing special about the way Node treats scope folders\. This
  70. simply requires the \fBmypackage\fP module in the folder named \fB@myorg\fP\|\.
  71. .SS Publishing scoped packages
  72. .P
  73. Scoped packages can be published from the CLI as of \fBnpm@2\fP and can be
  74. published to any registry that supports them, including the primary npm
  75. registry\.
  76. .P
  77. (As of 2015\-04\-19, and with npm 2\.0 or better, the primary npm registry
  78. \fBdoes\fR support scoped packages\.)
  79. .P
  80. If you wish, you may associate a scope with a registry; see below\.
  81. .SS Publishing public scoped packages to the primary npm registry
  82. .P
  83. To publish a public scoped package, you must specify \fB\-\-access public\fP with
  84. the initial publication\. This will publish the package and set access
  85. to \fBpublic\fP as if you had run \fBnpm access public\fP after publishing\.
  86. .SS Publishing private scoped packages to the npm registry
  87. .P
  88. To publish a private scoped package to the npm registry, you must have
  89. an npm Private Modules \fIhttps://docs\.npmjs\.com/private\-modules/intro\fR
  90. account\.
  91. .P
  92. You can then publish the module with \fBnpm publish\fP or \fBnpm publish
  93. \-\-access restricted\fP, and it will be present in the npm registry, with
  94. restricted access\. You can then change the access permissions, if
  95. desired, with \fBnpm access\fP or on the npmjs\.com website\.
  96. .SS Associating a scope with a registry
  97. .P
  98. Scopes can be associated with a separate registry\. This allows you to
  99. seamlessly use a mix of packages from the primary npm registry and one or more
  100. private registries, such as npm Enterprise\.
  101. .P
  102. You can associate a scope with a registry at login, e\.g\.
  103. .P
  104. .RS 2
  105. .nf
  106. npm login \-\-registry=http://reg\.example\.com \-\-scope=@myco
  107. .fi
  108. .RE
  109. .P
  110. Scopes have a many\-to\-one relationship with registries: one registry can
  111. host multiple scopes, but a scope only ever points to one registry\.
  112. .P
  113. You can also associate a scope with a registry using \fBnpm config\fP:
  114. .P
  115. .RS 2
  116. .nf
  117. npm config set @myco:registry http://reg\.example\.com
  118. .fi
  119. .RE
  120. .P
  121. Once a scope is associated with a registry, any \fBnpm install\fP for a package
  122. with that scope will request packages from that registry instead\. Any
  123. \fBnpm publish\fP for a package name that contains the scope will be published to
  124. that registry instead\.
  125. .SS See also
  126. .RS 0
  127. .IP \(bu 2
  128. npm help install
  129. .IP \(bu 2
  130. npm help publish
  131. .IP \(bu 2
  132. npm help access
  133. .IP \(bu 2
  134. npm help registry
  135. .RE