node.js 如何将私有项目发布到 Sinopia(私有注册的 npm adduser 失败)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/22636885/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Howto publish private projects to Sinopia (npm adduser for private registry fails)
提问by cdanea
Ok so I finally managed to get a private npm registry using Sinopia. But I cannot publish anything to it.
好的,所以我终于设法使用 Sinopia 获得了一个私有的 npm 注册表。但我不能向它发布任何内容。
TL;DR: Sinopia does not support npm adduser, but has its own user management. Also npm needs a valid user created before npm publishthrough npm adduser, which fails because the internal Sinopia server throws an error at the unsupported command....
TL;DR:Sinopia 不支持npm adduser,但有自己的用户管理。另外,npm 需要在npm 发布之前 通过npm adduser创建一个有效用户,这会失败,因为内部 Sinopia 服务器在不支持的命令上抛出错误....
How does one use Sinopia as a private registry with proper users and passwords
如何使用 Sinopia 作为具有正确用户和密码的私有注册表
- create a global user in npmjs.org, and then another with the same password in Sinopia?
- Or is there an easier way to tell npm to just use a fixed user/pass.
- Or even better prompt me somehow for username and password?
- something else?
- 在 npmjs.org 中创建一个全局用户,然后在 Sinopia 中创建另一个具有相同密码的用户?
- 或者有没有更简单的方法告诉 npm 只使用固定的用户/通行证。
- 或者甚至更好地提示我输入用户名和密码?
- 还有什么?
Synopsis:
概要:
Sinopia does not depend on Couch.DB and will hapilly fetch packages it does not already have from a master (default is the global npmjs.org).
Sinopia 不依赖于 Couch.DB,并且会很高兴地从 master 中获取它没有的包(默认是全局 npmjs.org)。
Sinopia starts perfectly and is configured to listen on all interfaces. It works wonders in serving packages to
Sinopia 完美启动并配置为在所有接口上收听。它在提供包裹方面产生了奇迹
npm install
I even configured ~/.npmrc to always point to the internal registry.
我什至将 ~/.npmrc 配置为始终指向内部注册表。
All projects' package.json file is set to
所有项目的 package.json 文件都设置为
....
"publishConfig" : {
"registry" : "http://internal-npm:4873"
},
....
Also I managed to add custom users in sinopia by manipulating the config.yaml with the help of js-yaml
我还通过在 js-yaml 的帮助下操作 config.yaml 设法在 sinopia 中添加自定义用户
crypto.createHash('sha1').update('theBigPassword').digest('hex')
Now I am stuck at
现在我被困在
npm --registry=http://internal-npm:4873 --ca=null publish
After a long wait I get:
经过漫长的等待,我得到:
npm ERR! need auth auth and email required for publishing
npm ERR! need auth You need to authorize this machine using `npm adduser`
npm ERR! System Linux 3.11.0-18-generic
npm ERR! command "/usr/bin/nodejs" "/usr/bin/npm" "--registry=http://internal-npm:4873" "--ca=null" "publish"
npm ERR! cwd /home/ciprian/workspace/netop-npm
npm ERR! node -v v0.10.15
npm ERR! npm -v 1.2.18
npm ERR! code ENEEDAUTH
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR! /home/ciprian/workspace/netop-npm/npm-debug.log
npm ERR! not ok code 0
The business end of the log file tells me that the user is not optional
日志文件的业务端告诉我用户不是可选的
86 error need auth auth and email required for publishing
86 error need auth You need to authorize this machine using `npm adduser`
87 error System Linux 3.11.0-18-generic
88 error command "/usr/bin/nodejs" "/usr/bin/npm" "--registry=http://internal-npm:4873" "--ca=null" "publish"
89 error cwd /home/ciprian/workspace/netop-npm
90 error node -v v0.10.15
91 error npm -v 1.2.18
92 error code ENEEDAUTH
93 verbose exit [ 1, true ]
Now, the chicken and eggissue is that Sinopia does not support npm adduser, but has its own user management like I mentioned above. Also npm needs a valid user created through npm adduser, which fails because the internal Sinopia server throws an error at the unsupported command.
现在,鸡和蛋的问题是Sinopia不支持npm adduser,但有自己的用户管理,就像我上面提到的。此外,npm 需要通过创建的有效用户npm adduser,这会失败,因为内部 Sinopia 服务器在不支持的命令上抛出错误。
回答by alex
First of all, it is not "chicken and egg" problem.
首先,这不是“鸡与蛋”的问题。
"npm adduser" does two things:
“npm adduser”做两件事:
- it creates a new user on the remote server, or verifies that it exists
- it adds _auth to your .npmrc
- 它在远程服务器上创建一个新用户,或验证它是否存在
- 它将 _auth 添加到您的 .npmrc
Sinopia will complain if user doesn't exist, but if it does, it'll happily report success.
如果用户不存在,Sinopia 会抱怨,但如果存在,它会很高兴地报告成功。
So, what you have to do is this:
所以,你需要做的是:
- add user/pass to config.yaml (see josh's answer) and restart sinopia server
- run
npm adduser --registry http://internal-npm:4873/
- 将 user/pass 添加到 config.yaml(参见 josh 的回答)并重启 sinopia 服务器
- 跑
npm adduser --registry http://internal-npm:4873/
Yes, "adduser" command is confusing, because it won't actually add a new user. It'll just verify that user exists in config.
是的,“adduser”命令令人困惑,因为它实际上不会添加新用户。它只会验证用户是否存在于配置中。
If you want, you can use "npm login" command. It is less confusing even though it does exactly the same thing. :)
如果需要,可以使用“npm login”命令。即使它做完全相同的事情,它也不那么令人困惑。:)
Second of all, add this to your package.json:
其次,将其添加到您的 package.json 中:
"publishConfig": {
"registry": "http://internal-npm:4873/"
}
This way npm won't publish it to the public registry anymore, even if it's a default one.
这样 npm 就不会再将它发布到公共注册表,即使它是默认的。
And lastly, you can't use two registries (npmjs and your private one) at the same time with the same npmrc. It's even less securethan you think.
最后,您不能在同一个 npmrc 中同时使用两个注册表(npmjs 和您的私有注册表)。它甚至比你想象的更不安全。
It's okay in most cases, but if you haveto use both of them (for example, you maintain public and private packages at the same time), use yapminstead of npm and write something like this to your .npmrc:
大多数情况下都可以,但是如果您必须同时使用它们(例如,您同时维护公共包和私有包),请使用yapm而不是 npm 并在您的 .npmrc 中写入如下内容:
[registries."https://registry.npmjs.org/"]
_auth = (your auth string for public registry)
[registries."http://internal-npm:4873/"]
_auth = (your auth string for private registry)
always-auth = true
It'll prevent exposing your passwords to public registry in all cases.
在所有情况下,它都会防止将您的密码暴露给公共注册表。
回答by josh3736
The Sinopia README tells you exactly what to do.
Sinopia README 会准确地告诉您要做什么。
Adding a new user
There is no utility to add a new user but you can at least use node on the command-line to generate a password. You will need to edit the config and add the user manually.
Start node and enter the following code replacing 'newpass' with the password you want to get the hash for.
$ node > crypto.createHash('sha1').update('newpass').digest('hex') '6c55803d6f1d7a177a0db3eb4b343b0d50f9c111' > [CTRL-D]
添加新用户
没有用于添加新用户的实用程序,但您至少可以在命令行上使用 node 来生成密码。您将需要编辑配置并手动添加用户。
启动节点并输入以下代码,将“newpass”替换为您想要获取哈希的密码。
$ node > crypto.createHash('sha1').update('newpass').digest('hex') '6c55803d6f1d7a177a0db3eb4b343b0d50f9c111' > [CTRL-D]
Insert the new user into your config.yaml file.
将新用户插入您的 config.yaml 文件中。
You then run npm adduserto login. (adduseris the command used for both account creation and login; sinopia does not support the creation part.)
然后运行npm adduser登录。(adduser是用于创建账号和登录的命令;sinopia不支持创建部分。)
回答by cdanea
Option 1 works, but I'm not really happy with it. So I'll keep on searching
选项 1 有效,但我对此并不满意。所以我会继续寻找
YES, if I add a valid npmjs.org user, then swith the repo:
是的,如果我添加了一个有效的 npmjs.org 用户,那么使用 repo:
npm config set registry http://internal-npm:4873/
The publish command will work if the same user/pass exists in Sinopia
如果 Sinopia 中存在相同的用户/密码,则发布命令将起作用
npm publish --registry=http://internal-npm:4873/
The downsideis that if someone forgets to explicitly set the private registry, the publish will 100% work on the global npmjs.org, which would be a disaster.
缺点是如果有人忘记明确设置私有注册表,发布将 100% 工作在全局 npmjs.org 上,这将是一场灾难。
回答by mvermand
As of version 0.13, Sinopia does support the creation of a new user through
从 0.13 版本开始,Sinopia 确实支持通过以下方式创建新用户
npm adduser --registry example.com:port
npm adduser --registry example.com:port
For more details see: HOW TO CREATE A NEW SINOPIA USER
有关更多详细信息,请参阅:如何创建新 SINOPIA 用户
回答by darky
Me help contributor of sinopia :) See here: https://github.com/rlidwka/sinopia/issues/230#issuecomment-91825660
我帮助 sinopia 的贡献者 :) 见这里:https: //github.com/rlidwka/sinopia/issues/230#issuecomment-91825660

