what do lines starting with double-slash '//&#

2019-06-06 20:18发布

问题:

I'd naively assumed that .npmrc lines with double slash ('//') indicate a comment, but that's clearly not the case, because when I delete them, I'm unable to publish to my local registry.

Example:

registry=https://npm.myregistry.io/
//email=me@mydomain.com
//npm.myregistry.io/:_authToken="Pgwb34F123EQdHqE7OoZA=="

If I remove the above // lines, publish results in

npm ERR! code ENEEDAUTH
npm ERR! need auth auth required for publishing
npm ERR! need auth You need to authorize this machine using `npm adduser`

I can't find any reference to this syntax in npmrc documentation or the ini module parser documentation. I'm assuming it has something to do with synthesized properties?

回答1:

// has no special meaning in .npmrc or any other .ini file.

The ini syntax is key = value. So in this case the key is //npm.myregistry.io/:_authToken.

This is a Protocol-relative URL, meaning an URL that will take the protocol automatically from the current page (you can actually type //google.com in the browser, and it should take you to https://google.com)

Note that this may not necessarily be the URL used by npm for authentication. It's just a format chosen by the developers to hold the authToken (or other values) in the same string with the registry URL.



标签: node.js npm