diff --git a/lib/config.js b/lib/config.js index 5f9819879be23..8873c38fa2a75 100644 --- a/lib/config.js +++ b/lib/config.js @@ -269,9 +269,13 @@ function list (cb) { var defKeys = getKeys(defaults) msg += '; default values\n' defKeys.forEach(function (k) { - if (defaults[k] && typeof defaults[k] === 'object') return - var val = JSON.stringify(defaults[k]) - if (defaults[k] !== npm.config.get(k)) { + const def = defaults[k] + // XXX remove this skip when we stop putting log in the npm.config set. + if (def && typeof def === 'object' && !Array.isArray(def)) { + return + } + var val = JSON.stringify(def) + if (def !== npm.config.get(k)) { msg += '; ' + k + ' = ' + val + ' (overridden)\n' } else msg += k + ' = ' + val + '\n' }) diff --git a/lib/config/defaults.js b/lib/config/defaults.js index c979dd0ce7ee9..8f3322099d35f 100644 --- a/lib/config/defaults.js +++ b/lib/config/defaults.js @@ -4,7 +4,6 @@ var path = require('path') var url = require('url') var Stream = require('stream').Stream var semver = require('semver') -var stableFamily = semver.parse(process.version) var nopt = require('nopt') var os = require('os') var osenv = require('osenv') @@ -68,9 +67,6 @@ nopt.invalidHandler = function (k, val, type) { } } -if (!stableFamily || (+stableFamily.minor % 2)) stableFamily = null -else stableFamily = stableFamily.major + '.' + stableFamily.minor - var defaults var temp = osenv.tmpdir() diff --git a/lib/config/flat-options.js b/lib/config/flat-options.js index 6bde734ec4ef2..77913b8251dc4 100644 --- a/lib/config/flat-options.js +++ b/lib/config/flat-options.js @@ -159,7 +159,7 @@ const flatOptions = npm => npm.flatOptions || Object.freeze({ packageLockOnly: npm.config.get('package-lock-only'), globalStyle: npm.config.get('global-style'), legacyBundling: npm.config.get('legacy-bundling'), - scriptShell: npm.config.get('script-shell'), + scriptShell: npm.config.get('script-shell') || undefined, omit: buildOmitList(npm), // used to build up the appropriate {add:{...}} options to Arborist.reify diff --git a/lib/config/set-envs.js b/lib/config/set-envs.js index faa75b5f58b10..63c6006f5bfb3 100644 --- a/lib/config/set-envs.js +++ b/lib/config/set-envs.js @@ -5,6 +5,9 @@ const envName = name => `npm_config_${name.replace(/-/g, '_')}` +// Return the env key if this is a thing that belongs in the env. +// Ie, if the key isn't a @scope, //nerf.dart, or _private, +// and the value is a string or array. Otherwise return false. const envKey = (key, val) => { return !/^[\/@_]/.test(key) && (typeof val === 'string' || Array.isArray(val)) && @@ -13,6 +16,22 @@ const envKey = (key, val) => { const envVal = val => Array.isArray(val) ? val.join('\n\n') : val +const sameConfigValue = (def, val) => + !Array.isArray(val) || !Array.isArray(def) ? def === val + : sameArrayValue(def, val) + +const sameArrayValue = (def, val) => { + if (def.length !== val.length) { + return false + } + for (let i = 0; i < def.length; i++) { + if (def[i] !== val[i]) { + return false + } + } + return true +} + const setEnvs = npm => { // The objects in the config.list array are arranged in // a prototype chain, so we can just for/in over the top @@ -23,7 +42,7 @@ const setEnvs = npm => { for (const key in configs) { const val = configs[key] const environ = envKey(key, val) - if (defaults[key] !== val && environ) { + if (!sameConfigValue(defaults[key], val) && environ) { process.env[environ] = envVal(val) } }