-
Notifications
You must be signed in to change notification settings - Fork 240
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
RFC for --default-command #279
Conversation
Implementation spike for npm/rfcs#279
### Alternative 2 - just make `help` know about scripts | ||
|
||
Another alternative would be to make the current default `help-search` | ||
behavior look at the `"scripts"` field in the current project's | ||
`package.json` file. If the term matches there, it could suggest that the | ||
user might be thinking of the `run-script` command. |
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 seems like a good improvement regardless, and would help the default/common case.
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.
Yeah, it's somewhat orthogonal to this RFC, and something we could just do regardless.
- `npm config set default-command exec` This turns npm into something like | ||
a more powerful `npx`. You can do `npm install` to install your | ||
dependencies, `npm create-react-app` to init a new react app, or `npm | ||
rimraf folder` to remove a folder recursively. | ||
- `npm config set default-command install` Since `npm install` is the most | ||
common use case for npm, why not just drop the `install`? Run `npm` with | ||
no args to install all your dependencies, or `npm react --save-peer` to | ||
install react and save as a peer dependency. |
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 seems like it would be really confusing for a non-advanced user who uses a project with default-command set in .npmrc
.
Maybe it could provide some kind of output like:
> npm foo
Running `npm run-script foo`...
"Output of npm foo here"
> npm foo --silent
"Output of npm foo here"
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.
That's a good idea. Could also probably want to have a npm.log.notice('default command notice blah')
so that it automatically gets placed in the debug log when stuff goes sideways.
Current status:
|
@isaacs i could see also wanting the default to be |
I could definitely see myself setting the default command to |
As a yarn user and npm user, I would definitely use this. However, I would take it a step further and change the default from I didn't even realize that |
I think is not explicitly specified but I think it will be covered out of the box: I think it would be a nice to have when if we consider a |
|
Running scripts without specifying I know people including myself using |
So if I'm reading this correctly, if we set the the opt-in is interesting. I like this proposal, but I'm a bit worried that people will wonder why |
The much bigger obstacle, honestly, is that it means There's some support for adding a third bin called |
Makes sense, thanks! Most projects don't have an npmrc file and relying on a global config isnt ideal. I can't see people wanting to add another config file to their project to get a shortcut. As much as I want it. It's unpopular, but I think you should just let us use anything, and if you choose to release 'npm styles' for whatever reason, just warn that there is overlap and npm takes precedence |
I think yarn has this right out of the door and npm should just copy its behavior, the npm CLI should look up:
When looking up a command like ReasoningToday when instructing someone show to use an npm vendored binary, you have to either recommend someone does: npm install danger
# now edit your scripts to have "danger":"danger"
npm run danger Which you can't automate. or
Which is a different command - but with the odd side-effect of if you get used to using If you switch to yarn style:
It's simpler, and doesn't need to have special cases like test or start etc. |
What I always find confusing with npm: Given 3 |
I agree with the comments here of making it default. We're all pretty used to it already with Only thing I'd say is if released in v7, make it default to |
imo it would be far too disruptive to make it a default; there are far more users (and docs/tutorials) used to npm's behavior than are used to yarn's. @orta i believe in npm 7, |
I don't think that should be a problem, all of the current npm behavior is accounted for in the yarn behavior described above to my knowledge. E.g. it won't change any current working examples, and broken examples may start working. The current behavior is much more confusing: why would it default to help when there are scripts and binaries with the name you're looking for? You'll never want This RFC looks at the answer very conservatively, but the config doesn't really make sense - run-scripts is the only useful config setting and that's only one small step. If it's per-user or per-project no-one can rely on it, and it doesn't really improve the ecosystem. The biggest issue is around the idea of a package script being broken by having an npm command taking priority, but that's a reasonable trade-off (and one discussed above a lot) |
The pnpm folks just said they'd be open to the yarn pattern of command look-ups in their CLI. I'm open to going through the npm RFC process for adding this behavior to npm as an alternative to this RFC, then we can get consistent behavior everywhere. |
This is not a direction we're going to go.
Closing this now, as the initial issue is better addressed by #339. |
rendered