NPM Package Registry
当前中文文档翻译不是最新版,访问英文版本查看最新内容,或帮助我们翻译
为您的用户或组织发布 npm 包。
要使用 npm 包注册表,您需要安装 Node.js 以及与之配套的软件包管理器,例如 Yarn 或 npm 本身。
该注册表支持作用域和非作用域软件包。
以下示例使用具有作用域 @test 的 npm 工具。
配置软件包注册表
Section titled “配置软件包注册表”要注册软件包注册表,您需要配置一个新的软件包源。
npm config set {scope}:registry=https://gitea.example.com/api/packages/{owner}/npm/npm config set -- '//gitea.example.com/api/packages/{owner}/npm/:_authToken' "{token}"| 参数 | 描述 |
|---|---|
scope |
软件包的作用域 |
owner |
软件包的所有者 |
token |
您的个人访问令牌。 |
例如:
npm config set @test:registry=https://gitea.example.com/api/packages/testuser/npm/npm config set -- '//gitea.example.com/api/packages/testuser/npm/:_authToken' "personal_access_token"或者,不使用作用域:
npm config set registry https://gitea.example.com/api/packages/testuser/npm/npm config set -- '//gitea.example.com/api/packages/testuser/npm/:_authToken' "personal_access_token"在项目中运行以下命令发布软件包:
npm publish如果已经存在相同名称和版本的软件包,您无法发布该软件包。您必须先删除现有的软件包。
通过运行以下命令删除软件包:
npm unpublish {package_name}[@{package_version}]| 参数 | 描述 |
|---|---|
package_name |
软件包名称 |
package_version |
软件包版本 |
例如
npm unpublish @test/test_packagenpm unpublish @test/test_package@1.0.0要从软件包注册表中安装软件包,请执行以下命令:
npm install {package_name}| 参数 | 描述 |
|---|---|
package_name |
软件包名称 |
例如:
npm install @test/test_package给软件包打标签
Section titled “给软件包打标签”该注册表支持版本标签,可以通过 npm dist-tag 管理:
npm dist-tag add {package_name}@{version} {tag}| 参数 | 描述 |
|---|---|
package_name |
软件包名称 |
version |
软件包版本 |
tag |
软件包标签 |
例如:
npm dist-tag add test_package@1.0.2 release标签名称不能是有效的版本。所有可解析为版本的标签名称都将被拒绝。
该注册表支持搜索,但不支持像 author:gitea 这样的特殊搜索限定符。
npm installnpm cinpm publishnpm unpublishnpm dist-tagnpm viewnpm search