diff options
author | isaacs <i@izs.me> | 2020-03-09 01:02:23 +0300 |
---|---|---|
committer | isaacs <i@izs.me> | 2020-05-08 04:12:27 +0300 |
commit | 99848a731edd515a60cedea0e8ac5a5c8af75805 (patch) | |
tree | d9b41a8fcbaf3242b3b8a725aba48529ca7d22a2 /lib | |
parent | fbc8993974796e1d61c636442fbd8bd803263193 (diff) |
Set non-default configs in the environment
Setting up for the switch from npm-lifecycle to @npmcli/run-script.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/config.js | 10 | ||||
-rw-r--r-- | lib/config/defaults.js | 4 | ||||
-rw-r--r-- | lib/config/flat-options.js | 2 | ||||
-rw-r--r-- | lib/config/set-envs.js | 21 |
4 files changed, 28 insertions, 9 deletions
diff --git a/lib/config.js b/lib/config.js index 5f9819879..8873c38fa 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 c979dd0ce..8f3322099 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 6bde734ec..77913b825 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 faa75b5f5..63c6006f5 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) } } |