Skip to content

Commit

Permalink
config: Only translate environment variables up to the first colon
Browse files Browse the repository at this point in the history
As discussed on npm.community[1], the fact that
npm registry authentication tokens
cannot be defined using environment variables
does not seem justified anymore.

The restriction is caused by the config loader translating
* all `_` to `-`
* the whole variable name to lowercase
while the credential checker expects a key ending in `:_authToken`.

As suggested, this change fixes the problem
by limiting the translation by the config loader
to the part *before* the first colon.

Closes #15565

[1]: https://npm.community/t/cannot-set-npm-config-keys-containing-underscores-registry-auth-tokens-for-example-via-npm-config-environment-variables/233
  • Loading branch information
mkhl committed Jun 20, 2018
1 parent 4c65cd9 commit 53eb15f
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions lib/config/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -346,11 +346,13 @@ Conf.prototype.addEnv = function (env) {
.forEach(function (k) {
if (!env[k]) return

// leave first char untouched, even if
// it is a '_' - convert all other to '-'
var p = k.toLowerCase()
// leave first char untouched, even if it is a '_'
// convert all other to '-', up to the first ':'
var ps = k.split(':')
ps[0] = ps[0].toLowerCase()
.replace(/^npm_config_/, '')
.replace(/(?!^)_/g, '-')
var p = ps.join(':')
conf[p] = env[k]
})
return CC.prototype.addEnv.call(this, '', conf, 'env')
Expand Down

0 comments on commit 53eb15f

Please sign in to comment.