Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to migrate NPM package to an organization @scope

Tags:

node.js

npm

NPM has recently introduced @scopes / organizations for the modules. 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?

like image 362
Yuri Astrakhan Avatar asked Mar 24 '17 19:03

Yuri Astrakhan


People also ask

How do I publish an npm package to an organization?

To publish an organization scoped package as public, use npm publish --access public . On the command line, navigate to the package directory. Run npm publish --access public .

What is scoped and Unscoped packages npm?

Scoped packages can be published and installed as of npm@2 and are supported by the primary npm registry. Unscoped packages can depend on scoped packages and vice versa. The npm client is backwards-compatible with unscoped registries, so it can be used to work with scoped and unscoped registries at the same time.


2 Answers

You can change your package.json from:

"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. Instead of the command-line argument you can set access to "public" in the publishConfig section of your package.json:

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

(Thanks to Danilo Bargen and Greg Pratt for pointing it out in the comments!)

See: 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 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

like image 168
rsp Avatar answered Sep 28 '22 07:09

rsp


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"). 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.

like image 33
suddjian Avatar answered Sep 28 '22 07:09

suddjian