buf registry login should update .npmrc
With the upcoming release of the BSR npm registry, we should make buf registry login automatically add/update credentials for the relevant registry in ~/.npmrc. The structure of credentials in this file are as follows:
//<REGISTRY_HOSTNAME>:_authToken=<TOKEN>
We should support both adding and updating credentials matching the provided hostname, so we may need some clever regular expression.
See https://docs.npmjs.com/using-private-packages-in-a-ci-cd-workflow#create-and-check-in-a-project-specific-npmrc-file for more information on the format (not much).
It may be possible to mutate the config file using the npm config commands.
If we don't want this to write the token unconditionally, we could look for npm on the path to decide whether to write it.
It's worth noting that the credentials above are not enough to install something from the BSR npm registry. NPM will also need to be told that package names starting with @buf/ should be routed to that registry hostname (second line):
//npm.buf.build:_authToken=<TOKEN>
@buf:registry=https://npm.buf.build
Yes, it's possible to set those values via npm.
Yarn is actually pretty popular, but unfortunately started using a different configuration format in v2.
npm login --registry=https://npm.buf.build --scope=@buf
This seems a really useful oneliner, maybe with this we can skip this issue altogether and just document this?
False alarm, that cannot be used unless we implement an obscure login endpoint on the NPM registry side, so lets skip that for now.
@timostamm is this still relevant / do we have any plans for this? I noticed the docs outline the steps manually (link).
We do not have any plans for this ATM. The issue with creating/updating ~/.npmrc is that the alternative package manager Yarn (actually more popular than npm) uses a different configuration file, so we would only improve the experience for a subset of a subset of our users.
I think we are better off closing this, and perhaps revisit implementing the login endpoint (opened BSR-461 for this).