神刀安全网

Npm-as – Run any npm command as a specific user

@NiftyCo/npm-as

Run npm as a certain user.

What? Why?

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) opensource@example.com  ~/projects/cool-package $ npm publish --access public +@example/cool-package@1.0.0  ~/projects/cool-package $ npm owner add rad-maintainer  ~/projects/cool-package $ npm login Username: rad-maintainer Password: hunter2 Email: (this IS public) info@example.com

For every package you publish. This is very cumbersome and time consuming to do.

In steps npm-as . This package is a simple passthru package that adds a simple token management system and --as flag to npm commands.

Install

$ npm install -g @niftyco/npm-as

Usage

To use 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 //registry.npmjs.org/:_authToken=${NPM_TOKEN} .

npm-as uses the NPM_TOKEN environment variable to swap your tokens when you issue an --as flag.

$ 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 to npm-as You will need to remove the alias temporarily and login, then redo the setup steps.

转载本站任何文章请注明:转载至神刀安全网,谢谢神刀安全网 » Npm-as – Run any npm command as a specific user

分享到:更多 ()

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址