-
Notifications
You must be signed in to change notification settings - Fork 3.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Isaacs/lifecycle envs #999
Changes from all commits
b2a7e16
9ea7f05
391933e
a012888
2fb8c26
6371f26
30ce3a9
b919531
c7dd395
9cf75ed
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -45,6 +45,9 @@ const flatOptions = npm => npm.flatOptions || Object.freeze({ | |
color: !!npm.color, | ||
includeStaged: npm.config.get('include-staged'), | ||
|
||
preferDedupe: npm.config.get('prefer-dedupe'), | ||
ignoreScripts: npm.config.get('ignore-scripts'), | ||
|
||
projectScope: npm.projectScope, | ||
npmVersion: npm.version, | ||
nodeVersion: npm.config.get('node-version'), | ||
|
@@ -57,7 +60,8 @@ const flatOptions = npm => npm.flatOptions || Object.freeze({ | |
localPrefix: npm.localPrefix, | ||
global: npm.config.get('global'), | ||
|
||
metricsRegistry: npm.config.get('metrics-registry'), | ||
metricsRegistry: npm.config.get('metrics-registry') || | ||
npm.config.get('registry'), | ||
sendMetrics: npm.config.get('send-metrics'), | ||
registry: npm.config.get('registry'), | ||
get scope () { | ||
|
@@ -159,7 +163,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, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Question: What's the default returned value of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can be literally anything.
But @npmcli/run-script only allows Boolean or undefined. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Er, only allows strings. (Sorry, was thinkign of another flag.) So this is the case that would be a problem:
And the effect of setting that |
||
omit: buildOmitList(npm), | ||
|
||
// used to build up the appropriate {add:{...}} options to Arborist.reify | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
// Set environment variables for any non-default configs, | ||
// so that they're already there when we run lifecycle scripts. | ||
// | ||
// See https://github.com/npm/rfcs/pull/90 | ||
|
||
const envName = name => `npm_config_${name.replace(/-/g, '_')}` | ||
mikemimik marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
// 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) && | ||
mikemimik marked this conversation as resolved.
Show resolved
Hide resolved
|
||
(typeof val === 'string' || Array.isArray(val)) && | ||
`npm_config_${key.replace(/-/g, '_').toLowerCase()}` | ||
mikemimik marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
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 | ||
// of the stack and grab any that don't match the default | ||
const { config: { list: [ configs ] } } = npm | ||
const { defaults } = require('./defaults.js') | ||
const set = {} | ||
for (const key in configs) { | ||
const val = configs[key] | ||
const environ = envKey(key, val) | ||
if (!sameConfigValue(defaults[key], val) && environ) { | ||
process.env[environ] = envVal(val) | ||
} | ||
} | ||
|
||
process.env.npm_execpath = require.main.filename | ||
process.env.npm_node_execpath = process.execPath | ||
process.env.npm_command = npm.command | ||
|
||
// note: this doesn't afect the *current* node process, of course, since | ||
// it's already started, but it does affect the options passed to scripts. | ||
if (configs['node-options']) { | ||
process.env.NODE_OPTIONS = configs['node-options'] | ||
} | ||
} | ||
|
||
module.exports = setEnvs |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -92,19 +92,11 @@ | |
var commandCache = {} | ||
var aliasNames = Object.keys(aliases) | ||
|
||
var littleGuys = [ 'isntall', 'verison' ] | ||
var fullList = cmdList.concat(aliasNames).filter(function (c) { | ||
var fullList = npm.fullList = cmdList.concat(aliasNames).filter(c => { | ||
return plumbing.indexOf(c) === -1 | ||
}) | ||
var abbrevs = abbrev(fullList) | ||
|
||
// we have our reasons | ||
fullList = npm.fullList = fullList.filter(function (c) { | ||
return littleGuys.indexOf(c) === -1 | ||
}) | ||
|
||
var registryRefer | ||
|
||
Object.keys(abbrevs).concat(plumbing).forEach(function addCommand (c) { | ||
Object.defineProperty(npm.commands, c, { get: function () { | ||
if (!loaded) { | ||
|
@@ -113,19 +105,20 @@ | |
'See the README.md or bin/npm-cli.js for example usage.' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Line 106: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, registryRefer should be removed, since we're not sending the referer header any more. Istr there's a difference between "affordances" and "littleGuys", but I don't recall it offhand. Will dig in and sort that out. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nope, no difference. Just apparently something that got overlooked 4 years ago when it stopped being relevant. |
||
) | ||
} | ||
var a = npm.deref(c) | ||
var actualCommand = npm.deref(c) | ||
if (c === 'la' || c === 'll') { | ||
npm.config.set('long', true) | ||
} | ||
|
||
npm.command = c | ||
npm.config.set('command', c) | ||
npm.command = actualCommand | ||
npm.flatOptions = require('./config/flat-options.js')(npm) | ||
if (commandCache[a]) return commandCache[a] | ||
require('./config/set-envs.js')(npm) | ||
|
||
var cmd = require(path.join(__dirname, a + '.js')) | ||
if (commandCache[actualCommand]) return commandCache[actualCommand] | ||
|
||
commandCache[a] = function () { | ||
var cmd = require(path.join(__dirname, actualCommand + '.js')) | ||
|
||
commandCache[actualCommand] = function () { | ||
var args = Array.prototype.slice.call(arguments, 0) | ||
if (typeof args[args.length - 1] !== 'function') { | ||
args.push(defaultCb) | ||
|
@@ -140,30 +133,14 @@ | |
} | ||
}) | ||
|
||
if (!registryRefer) { | ||
registryRefer = [a].concat(args[0]).map(function (arg) { | ||
// exclude anything that might be a URL, path, or private module | ||
// Those things will always have a slash in them somewhere | ||
if (arg && arg.match && arg.match(/\/|\\/)) { | ||
return '[REDACTED]' | ||
} else { | ||
return arg | ||
} | ||
}).filter(function (arg) { | ||
return arg && arg.match | ||
}).join(' ') | ||
npm.referer = registryRefer | ||
npm.config.set('refer', npm.referer) | ||
} | ||
|
||
cmd.apply(npm, args) | ||
} | ||
|
||
Object.keys(cmd).forEach(function (k) { | ||
commandCache[a][k] = cmd[k] | ||
commandCache[actualCommand][k] = cmd[k] | ||
}) | ||
|
||
return commandCache[a] | ||
return commandCache[actualCommand] | ||
}, | ||
enumerable: fullList.indexOf(c) !== -1, | ||
configurable: true }) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Question: Are these the same thing?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unless specified explicitly,
metrics-registry
defaults to the public registry.