kevva / download

Download and extract files
MIT License
1.28k stars 199 forks source link

Tried to set `strict-ssl` to false in .nmprc file, but `process.env.npm_config_strict_ssl` return blank string #197

Open zwlijun opened 4 years ago

zwlijun commented 4 years ago

Tried to set strict-ssl to false in .nmprc file, but process.env.npm_config_strict_ssl return blank string. So, this setting is not worked. Can this problem be fixed in the next version?

Cause by: When npm-lifycycle dealing config values what It's return a '' when the value is !value

Source link: https://github.com/npm/npm-lifecycle/blob/latest/index.js#L464

  Object.keys(opts.config).forEach(function (i) {
    // in some rare cases (e.g. working with nerf darts), there are segmented
    // "private" (underscore-prefixed) config names -- don't export
    if ((i.charAt(0) === '_' && i.indexOf('_' + namePref) !== 0) || i.match(/:_/)) {
      return
    }
    var value = opts.config[i]
    if (value instanceof Stream || Array.isArray(value) || typeof value === 'function') return
    if (i.match(/umask/)) value = umask.toString(value)

    if (!value) value = ''
    else if (typeof value === 'number') value = '' + value
    else if (typeof value !== 'string') value = JSON.stringify(value)

    if (typeof value !== 'string') {
      return
    }

npm version: 6.14.7

.npmrc config

strict-ssl=false

Incorrect souce code

    opts = Object.assign({
        encoding: null,
        rejectUnauthorized: process.env.npm_config_strict_ssl !== 'false'
    }, opts);

Resolved source code ( PR: #200 )

    const strictSSL = process.env.npm_config_strict_ssl;
    opts = Object.assign({
        encoding: null,
        rejectUnauthorized: strictSSL ? (strictSSL !== 'false') : (!!strictSSL)
    }, opts);