使用组织设置配置 npm 客户端

作为组织成员,你可以将 npm 客户端配置为:

🌐 As an organization member, you can configure your npm client to:

  • 使你在本地创建的单个包或所有新包都使用你组织的范围
  • 使你在本地创建的单个包或所有新包具有默认的公共可见性

在配置你的 npm 客户端之前,你必须先 安装 npm

🌐 Before configuring your npm client, you must install npm.

配置你的 npm 客户端来使用你组织的范围

🌐 Configuring your npm client to use your organization's scope

如果你经常以贵组织的作用域发布包,你可以将贵组织的作用域添加到全局 .npmrc 配置文件中。

🌐 If you will be publishing packages with your organization's scope often, you can add your organization's scope to your global .npmrc configuration file.

为所有新的包设置组织范围

🌐 Setting your organization scope for all new packages

注意: 使用以下步骤设置组织范围只会对新软件包生效;对于已有的软件包,你需要在 package.json 中更新 name 字段。

在命令行中运行以下命令,将 <org-name> 替换为你组织的名称:

🌐 On the command line, run the following command, replacing <org-name> with the name of your organization:

npm config set scope <org-name> --global

对于你不想以组织范围发布的包,你必须手动编辑该包的 package.json,从 name 字段中移除组织范围。

🌐 For packages you do not want to publish with your organization's scope, you must manually edit the package's package.json to remove the organization scope from the name field.

为单个包设置组织范围

🌐 Setting your organization scope for a single package

  1. 在命令行上,导航到包目录。

    cd /path/to/package
  2. 运行以下命令,将 <org-name> 替换为你的组织名称:

    npm config set scope <org-name>

将默认包可见性更改为公共

🌐 Changing default package visibility to public

默认情况下,使用 npm publish 发布范围包时,该包将被发布为私有。如果你是免费组织计划的组织成员,或者你在付费组织计划中但想将范围包发布为公共包,则必须使用 --access public 标志:

🌐 By default, publishing a scoped package with npm publish will publish the package as private. If you are a member of an organization on the free organization plan, or are on the paid organization plan but want to publish a scoped package as public, you must pass the --access public flag:

npm publish --access public

将单个包的包可见性设置为公开

🌐 Setting package visibility to public for a single package

你可以为单个软件包设置,使其将 --access public 传递给你为该软件包发出的每个 npm publish 命令。

🌐 You can set a single package to pass --access public to every npm publish command that you issue for that package.

  1. 在命令行上,导航到包目录。

    cd /path/to/package
  2. 运行以下命令:

    npm config set access public

将所有包的包可见性设置为公开

🌐 Setting package visibility to public for all packages

你可以设置所有包在你对该包发出的每个 npm publish 命令中传递 --access public

🌐 You can set all packages to pass --access public to every npm publish command that you issue for that package.

警告: 在全局 .npmrc 中将软件包访问权限设置为 public 会影响你创建的所有软件包,包括属于个人账户范围的软件包以及属于你组织范围的软件包。

在命令行上,运行以下命令:

🌐 On the command line, run the following command:

npm config set access public --global