简体   繁体   English

如何将 NPM package 迁移到组织 @scope

[英]How to migrate NPM package to an organization @scope

NPM has recently introduced @scopes / organizations for the modules. NPM最近为模块引入了@scopes / organizations。 Is there a good way to migrate existing modules to the organization?有没有好的方法可以将现有模块迁移到组织中? Are there any tools for automating it for a large number of packages?是否有任何工具可以为大量包实现自动化? Does NPM support redirects, so that other software could still use the old name, yet get a notification that it should be updated? NPM 是否支持重定向,以便其他软件仍然可以使用旧名称,但会收到应该更新的通知?

You can change your package.json from: 您可以从以下位置更改package.json:

"name": "project-name"

to: 至:

"name": "@scope/project-name"

and publish the package: 并发布包:

npm publish --access=public

Update: The --access=public argument is needed to make the scoped package public - otherwise it will be private by default. 更新:需要--access=public参数才能使作用域包公开 - 否则默认情况下它将是私有的。 Instead of the command-line argument you can set access to "public" in the publishConfig section of your package.json : 您可以在package.jsonpublishConfig部分中设置对"public" access ,而不是命令行参数:

"publishConfig": {
  "access": "public"
}

(Thanks to Danilo Bargen and Greg Pratt for pointing it out in the comments!) (感谢Danilo BargenGreg Pratt在评论中指出它!)

See: https://docs.npmjs.com/getting-started/scoped-packages 请参阅: https//docs.npmjs.com/getting-started/scoped-packages

The npm doesn't support redirects from old names to new names but you can deprecate the old package with: npm不支持从旧名称到新名称的重定向,但您可以弃用旧包:

npm deprecate <pkg>[@<version>] <message>

So that people who install the old version would be notified that they should install another package instead. 因此,安装旧版本的人会收到通知他们应该安装另一个软件包。

See: https://docs.npmjs.com/cli/deprecate 请参阅: https//docs.npmjs.com/cli/deprecate

Another way to do this that doesn't involve renaming the package, is to go to the team settings in your organization on the npm website (there's a default team called "developers"). 另一种不涉及重命名包的方法是在npm网站上找到组织中的团队设置(有一个名为“开发人员”的默认团队)。 There's a button there to add an existing package to the team. 那里有一个按钮可以向团队添加现有的包。

This way you actually transfer the package, instead of republishing it under a different name. 这样您实际上就可以转移包,而不是以不同的名称重新发布它。

One can give a team in a NPM organization access via the command:可以通过以下命令为 NPM 组织中的团队授予访问权限:

npm access grant <read-only|read-write> <org:team> [<package>]

See " Adding package access to a team using the CLI ".请参阅“ 使用 CLI 添加对团队的 package 访问权限”。

Alternatively, there is also a way to do this via the web UI.或者,还有一种方法可以通过 web UI 执行此操作。 See " Adding package access to a team on the web ".请参阅“ 将 package 添加到 web 上的团队”。

Both ways seem to require admin permissions.这两种方式似乎都需要管理员权限。

After one has given an organization team permissions, one can remove package access for the single users.在授予组织团队权限后,可以删除单个用户的 package 访问权限。

This can be either done via CLI:这可以通过 CLI 完成:

npm owner rm <your-username> <package-name>

See " npm-owner ".请参阅“ npm-owner ”。

Or the web UI via the package settings.或者通过 package 设置的 web 用户界面。

Users, who are in a team that has access, still have access to the package, after they have been removed.具有访问权限的团队中的用户在被删除后仍然可以访问 package。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM