Skip to content
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

Fallback to kebab-case command #357

Closed
wants to merge 3 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions accepted/0000-fallback-kebab-case-command.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Fallback to kebab-case command

## Summary

If the command is unknown, then fallback to the kebab-case version of it if it is in the `PATH`.
Yash-Singh1 marked this conversation as resolved.
Show resolved Hide resolved

## Motivation

It allows users to create custom commands for `npm` such as:

```sh
npm my-command
```

## Detailed Explanation

Let's say that `npm my-command` is run. Then `npm` should first see if their is a builtin command called `my-command`. If not then it will look through the path for `npm-my-command`. If that fails, then the current fallback will be run:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what's the advantage of using npm-my-command? is this a convention that's used (besides perhaps git)?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't completely understand your question. If you were asking why I chose my-command, that was just an example. If you meant why custom commands should be a thing: Creating custom npm command will allow developers to "extend" npm with more CLI features for users.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Allowing that would make "npm adds a new top-level command" a breaking change, and would also make npm's interface different on a per-package basis.


1. Command exists?
2. Custom command on `PATH`?
3. Fallback

## Rationale and Alternatives

It is currently not possible to do this.

## Implementation

All that will have to be done is have a conditional check before the fallback checking if there is a custom command. If there is, then the arguments will be passed to it.

## Prior Art

N/A

## Related resources and links

https://github.com/npm/rfcs/pull/332 was related to this proposal