Use @npmcli/run-script for exec, explore; add interactive exec#2202
Use @npmcli/run-script for exec, explore; add interactive exec#2202ruyadorno merged 2 commits intorelease/v7.1.0from
Conversation
b93460b to
ec904f5
Compare
|
Can the |
darcyclarke
left a comment
There was a problem hiding this comment.
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.
| const pathArr = [...PATH] | ||
|
|
||
| // nothing to maybe install, skip the arborist dance | ||
| if (!call && !args.length && !packages.length) { |
There was a problem hiding this comment.
| if (!call && !args.length && !packages.length) { | |
| if (!call && !args.length && !packages.length && isTTY && !ciDetect()) { |
docs/content/commands/npm-exec.md
Outdated
|
|
||
| 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.
| `package.json` scripts are run. | |
| `package.json` scripts are run; Only available in TTY/non-CI environments. |
| 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.
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 |
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 execis 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.explorenow canonly be used to explore packages that are actually found in the
relevant
node_modulesfolder.References