-
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
Conversation
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.
Couple things I found:
- small nits about using regexp
- few questions around config we're setting in
lib/config/flat-options.js
- out of file scope cleanup in
lib/npm.js
- logical questions in
lib/run-script.js
lib/run-script.js
Outdated
} | ||
} | ||
cmds = [cmd] | ||
const allScripts = scripts ? Object.keys(scripts) : {} |
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.
If scripts
is truthy then you get an array of strings, if scripts
is falsy you get an empty object. Seems like this should be the same value.
On line 146
we are using a for...of
statement which is meant for array's and not objects (it will throw if it gets an object)
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.
Confirmed, this is an oversight.
const prefix = ' ' | ||
const cmds = [] | ||
const runScripts = [] | ||
for (const script of allScripts) { |
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.
Could be a problem (from comment above)
const cmds = [] | ||
const runScripts = [] | ||
for (const script of allScripts) { | ||
const list = cmdList.includes(script) ? cmds : runScripts |
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.
Both cmds
and runScripts
start as an empty array. I'm not sure why we need to check if cmdList
has the script
in it, if in both cases we return an empty array.
for (const script of runScripts) { | ||
output(prefix + script + indent + scripts[script]) | ||
} | ||
return allScripts |
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.
The conditional if
logic above is a little confusing. I now realise the point of the cmdList.includes()
is to find out if what you typed as a user was, for example, npm run test
. That output should be different than if you ran, for example, npm run myscript
.
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.
This is for listing out scripts that are runnable as a command differently from those that have to be run with npm run
.
Eg:
$ node . run
Lifecycle scripts included in npm:
preversion
bash scripts/update-authors.sh && git add AUTHORS && git commit -m "update AUTHORS" || true
test
npm run test-tap --
posttest
npm run lint
available via `npm run-script`:
dumpconf
env | grep npm | sort | uniq
prepare
node bin/npm-cli.js rebuild && node bin/npm-cli.js --no-audit --no-timing prune --prefix=. --no-global && rimraf test/*/*/node_modules && make -j4 mandocs
...
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.
I think I understand. I guess the distinction wasn't clear when reading through the code. I'm not sure if that's indicative of me needing more context or the code not being clear enough.
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.
When you run npm run
without any args, it calls the list
function, which dumps a list of which scripts are available.
The conditional on 147 is deciding which list to push the command name into, and then we loop over both lists to print out which ones are command lifecycles, and which have to be run explicitly.
@@ -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 comment
The reason will be displayed to describe this comment to others. Learn more.
Question: What's the default returned value of npm.config.get('...')
which doesn't find the key ...
?
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.
Can be literally anything.
$ npm config get script-shell --script-shell=420lol
420lol
But @npmcli/run-script only allows Boolean or undefined.
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.
Er, only allows strings. (Sorry, was thinkign of another flag.)
So this is the case that would be a problem:
npm run foo --no-script-shell
And the effect of setting that false
value to undefined
is to fall back to the system default (/bin/sh
or cmd.exe
).
@@ -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'), |
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.
@@ -113,19 +113,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 comment
The reason will be displayed to describe this comment to others. Learn more.
Line 106: var registryRefer
is defined by never used
Line 95: var littleGuys
is a reference to incorrect spelling, but lib/config/cmd-list.js
already has an affordances
section; shouldn't we be using that?
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.
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 comment
The 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.
Last bit of #930
This sets environment variables for npm_command, npm_execpath, npm_node_execpath, NODE_OPTIONS, and any non-default configs that do not start with @, /, or _ (as those are potentially sensitive, or at least not useful). This is in preparation for the move from npm-lifecycle to @npmcli/run-script for running lifecycle scripts.
Setting up for the switch from npm-lifecycle to @npmcli/run-script.
The 'littleGuys' (ie, isntall, verison, udpate) are included in the cmdList.affordances section, so are no longer printed in the default help banner anyway. We can remove this variable.
251b751
to
9cf75ed
Compare
Landed as part of #1021 |
Use
@npmcli/run-script
for the run-script command, and add a few missing configs to flatOptions.