作为一个组织,如何将私有 npm 包发布并安装到 GitHub 包?

Xii*_*ryo 6 npm google-cloud-functions lerna monorepo github-package-registry

我们有一个带有名为“@myorganization/common”的共享包的 monorepo,该包由应用程序和 Google 云功能使用。

Google 云函数要求将包发布到存储库才能使用它,因为我们不发布编译后的代码(可以包含本地包),而是直接发布原始 TypeScript。

我找到了一些教程,但没有找到结合私有包和组织的用例。

我 cd 进入 packages/common 目录。

我将以下几行添加到我的 packages.json 中:

"publishConfig": { "registry": "https://npm.pkg.github.com/" },
"repository": {
  "url": "git@github.myorganization/common.git"
},
Run Code Online (Sandbox Code Playgroud)

我在 GitHub 上创建了一个个人身份验证令牌,具有完整的存储库、包和组织权限。

然后我登录到我的组织:

npm login --registry=https://npm.pkg.github.com --scope=@myorganization
Run Code Online (Sandbox Code Playgroud)

然后我打了:

npm publish
Run Code Online (Sandbox Code Playgroud)

我收到以下错误:

npm ERR! code EPRIVATE
npm ERR! This package has been marked as private
npm ERR! Remove the 'private' field from the package.json to publish it.
Run Code Online (Sandbox Code Playgroud)

我希望这个包只能由组织成员使用。当 React Native 使用时,它应用作 lerna monorepo 中的本地私有包,并且通过从 GitHub 包获取它来由 Google Cloud Function 使用。但其他人无法访问它。

这是可能的事吗?

问候

编辑:

我尝试更新 packages.json,删除 private=true 并尝试确保将其发布到我的私人组织:

"publishConfig": {
    "registry": "https://npm.pkg.github.com/:_authToken=xxxx --scope=@myorganization"
  },
Run Code Online (Sandbox Code Playgroud)

我现在收到错误:

npm ERR! code E404
npm ERR! 404 Not Found - PUT https://npm.pkg.github.com/@myorganization%2fcommon - The expected resource was not found.
npm ERR! 404
npm ERR! 404  '@myorganization/common@0.0.7' is not in the npm registry.
npm ERR! 404 You should bug the author to publish it (or use the name yourself!)
Run Code Online (Sandbox Code Playgroud)

Has*_*aig 2

我面临着完全相同的问题。这对我有用。

我必须在 GitHub 上创建组织(即myorganization在您的示例中),并在该组织下创建一个与存储库同名的存储库(即common在您的示例中),并且它有效。