Table of contents
1. About organizational scope and packages
1.1 Managing unscoped packages
2. Configure npm client with organization settings
2.1 Configure your npm client to use your organization's scope
Set org-wide for all new packages
Set organization scope for a single package
2.2 Change default package visibility to public
Set the package visibility of a single package to public
Set the package visibility of all packages to public
3. Create and publish organization-wide packages
3.1 Create an organization-wide package
3.2 Publishing private org-wide packages
3.3 Publishing public org-wide packages
1. About organizational scope and packages
Each organization is granted an organization scope, which is a unique namespace for packages owned by the organization that matches the organization name. For example, an organization named "wombat" would have a scope @wombat
.
You can use scopes:
- Maintain a fork of a package: @wombat/request
- Avoid name disputes with popular names: @wombat/web
- Easily find packages in the same namespace
A scoped package must follow the same naming guidelines as an unscoped package.
1.1 Managing unscoped packages
Although an organization is granted a scope by default when it is created, you can also use an organization to manage unscoped packages or packages under other scopes, such as the user scope.
2. Configure npm client with organization settings
As an organization member, you can configure the npm client to:
- Make individual packages or all new packages you create locally use your organization's scope
- Make locally created individual packages or all new packages have default public visibility
2.1 Configure your npm client to use your organization's scope
If you will frequently publish packages with an org scope, you can add the org scope to the global .npmrc
configuration file.
Set org-wide for all new packages
NOTE: Using the following steps to set the organization scope will only set the scope for new packages; for existing packages, you will need to update the fields
name
inpackage.json
.
At the command line, run the following command, replacing org-name with your organization name:
npm config set scope <org-name> --global
For packages that do not want to publish with organization scope, you must manually edit the package's package.json
to name
remove organization scope from the field.
Set organization scope for a single package
1. On the command line, switch to the package directory:
cd /path/to/package
2. Run the following command, replacing org-name with the organization name:
npm config set scope <org-name>
2.2 Change default package visibility to public
By default, using npm publish
publish with a scoped package will publish the package privately . If you are an organization member on a free organization plan, or an organization member on a paid organization plan, but want to publish a scoped package as public, you must pass the flag --access public
:
npm publish --access public
Set the package visibility of a single package to public
You can set up an individual package so that it will be --access public
passed to every command you issue for that package npm publish
.
1. On the command line, switch to the package directory:
cd /path/to/package
2. Run the following command:
npm config set access public
Set the package visibility of all packages to public
You can set all packages to be --access public
passed to every command you issue for that package npm publish
.
Warning : Setting package access to Global
public
will.npmrc
affect all packages you create, including packages scoped to your personal account as well as packages scoped to your organization.
On the command line, run the following command:
npm config set access public --global
3. Create and publish organization-wide packages
As an organization member, you can create and publish public and private packages organization-wide.
3.1 Create an organization-wide package
1. On the command line, create a directory with the name of the package you want to create.
2. Switch to the newly created package directory
3. To create an organization-wide package, run on the command line:
npm init --scope=<your_org_name>
4. To verify whether the package uses your organization scope, please open the file of the package in a text editor package.json
and check whether the name is @your_org_name/<pkg_name>
, or you can directly modify the name field and your_org_name
replace it with your organization name.
3.2 Publishing private org-wide packages
By default, npm publish
a scoped package will be published as a private package.
By default, packages of any scope are published as private packages. However, if you're in an organization that doesn't have the "private packages" feature, npm publish will fail unless you pass the access flag.
1. On the command line, switch to the package directory.
2. Run npm publish
If you enable two-factor authentication, you need to open the bottom link in the figure above, and return the one-time password after performing two-factor authentication, then paste the password and copy it to the current window, and it will be published as an organization-wide private package.
Private packages will be displayed under the package name on the npm website private
. For example, as shown in the figure below:
3.3 Publishing public org-wide packages
To publish an organization-wide package as a public package, use npm publish --access public
.
1. On the command line, switch to the package directory.
2. Run npm publish --access public
The public package will be on the npm website with a public logo, as shown in the following figure:
After the release is successful, there will be an email to remind you that the package has been released successfully, and you can log in to the npm website to view it.