Run npm as a certain user.
npm-as is a solution to a problem we have been having. npm, Inc does not offer teams for open source projects. Scoped packages only work for teams and regular users. Because we’re using scoped packages for open source projects, our only two options are to pay for private packages even though we don’t need them to use teams, or we use user accounts as a makeshift team.
We chose option 2. One of the biggest issues with this route is that to create a package and publish it, you have to
npm login as that user, publish the package, then add all the owners you want to have access to it for them to publish. The workflow for this usually comes out to the following steps.
~/projects/cool-package $ npm login Username: example Password: hunter2 Email: (this IS public) email@example.com ~/projects/cool-package $ npm publish --access public +@firstname.lastname@example.org ~/projects/cool-package $ npm owner add rad-maintainer ~/projects/cool-package $ npm login Username: rad-maintainer Password: hunter2 Email: (this IS public) email@example.com
For every package you publish. This is very cumbersome and time consuming to do.
npm-as . This package is a simple passthru package that adds a simple token management system and
--as flag to npm commands.
$ npm install -g @niftyco/npm-as
npm-as You can either use it as is by issuing all commands to
npm-as instead of
npm . Or you can alias it to npm.
After that you need to edit your
$HOME/.npmrc file to use an environment variable over a token in the registry url.
Look for the line that looks something like this
//registry.npmjs.org/:_authToken= and replace it all with
npm-as uses the
NPM_TOKEN environment variable to swap your tokens when you issue an
$ export alias npm="npm-as" $ npm whoami rad-maintainer $ npm whoami --as example example
You can add users by using the tokens sub command:
$ npm tokens add steve afe246n-345adf-adsf235 you can now `--as steve`
NOTE:You need to have logged in under this account with npm cli at least once to generate the token. You can access all your tokens on npm . If you have aliased
npm-as You will need to remove the alias temporarily and login, then redo the setup steps.