-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
Use @npmcli/run-script for exec, explore; add interactive exec #2202
Conversation
b93460b
to
ec904f5
Compare
Can the |
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.
As per @ljharb's note, I think it would be good if we ensured this interactive mode wasn't something that could trip up CI environments... I've suggested two changes that should support that.
|
||
if (call && args.length) | ||
throw usage | ||
|
||
const pathArr = [...PATH] | ||
|
||
// nothing to maybe install, skip the arborist dance | ||
if (!call && !args.length && !packages.length) { |
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 (!call && !args.length && !packages.length) { | |
if (!call && !args.length && !packages.length && isTTY && !ciDetect()) { |
docs/content/commands/npm-exec.md
Outdated
@@ -30,6 +33,10 @@ This command allows you to run an arbitrary command from an npm package | |||
(either one installed locally, or fetched remotely), in a similar context | |||
as running it via `npm run`. | |||
|
|||
Run without positional arguments or `--call`, this allows you to | |||
interactively run commands in the same sort of shell environment that | |||
`package.json` scripts are run. |
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.
`package.json` scripts are run. | |
`package.json` scripts are run; Only available in TTY/non-CI environments. |
@@ -59,15 +60,14 @@ const ciDetect = require('@npmcli/ci-detect') | |||
const crypto = require('crypto') | |||
const pacote = require('pacote') | |||
const npa = require('npm-package-arg') | |||
const escapeArg = require('./utils/escape-arg.js') | |||
const fileExists = require('./utils/file-exists.js') | |||
const PATH = require('./utils/path.js') | |||
|
|||
const cmd = (args, cb) => exec(args).then(() => cb()).catch(cb) |
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.
Remove the isTTY
definition on line 197
& hoist it up.
const cmd = (args, cb) => exec(args).then(() => cb()).catch(cb) | |
const cmd = (args, cb) => exec(args).then(() => cb()).catch(cb) | |
const isTTY = process.stdin.isTTY && process.stdout.isTTY |
Hm, if stdin is not a TTY, then it just means it'll read from whatever it is, and close when it closes.
But, yes, if it's CI and it is a TTY, we should not do that. And if it's not a TTY, we should probably not show the helpful help banner. |
So, wait, if it is in CI, and we abort, that means you can't run commands from stdin in CI, which seems like a suboptimal situation? What if you have a bunch of shell commands in a file, and want to run I think the only situation we should exit early in is if it's CI and a TTY, with a warning that we're doing so. |
Updated with the logic described. Also simplified some of the |
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.
✅ LGTM
This removes all other arg/shell escaping mechanisms, as they are no longer needed, and will be un-done by puka in @npmcli/run-script anyway. Adds an interactive shell mode when `npm exec` is run without any arguments, allowing users to interactively test out commands in an npm script environment. Previously, this would do nothing, and just exit. Prevent weird behavior from `npm explore ../blah`. `explore` now can _only_ be used to explore packages that are actually found in the relevant `node_modules` folder.
Credit: @isaacs PR-URL: #2202 Close: #2202 Reviewed-by: @darcyclarke
1df4876
to
f864b7b
Compare
Credit: @isaacs PR-URL: #2202 Close: #2202 Reviewed-by: @darcyclarke PR-URL: #2202 Credit: @isaacs Close: #2202 Reviewed-by: @ruyadorno
f864b7b
to
4f94d42
Compare
Credit: @isaacs PR-URL: #2202 Close: #2202 Reviewed-by: @darcyclarke
This removes all other arg/shell escaping mechanisms, as they are no
longer needed, and will be un-done by puka in @npmcli/run-script anyway.
Adds an interactive shell mode when
npm exec
is run without anyarguments, allowing users to interactively test out commands in an npm
script environment. Previously, this would do nothing, and just exit.
Prevent weird behavior from
npm explore ../blah
.explore
now canonly be used to explore packages that are actually found in the
relevant
node_modules
folder.References