npm / npm/rfcs

[RRFC] New subcommand “npm clone”

Open
#192 9 comments 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
777
Forks
267
PR merge metrics
No merged PRs in 30d

Description

Motivation ("The Why")

Most publicly available NPM packages are usually also open source and provide a link to their code repository through the repository field in their package.json file.

However, starting to work on the code for a package is not exactly a quick thing to do . You first have to find it (it doesn't necessarily have to live on GitHub) and then manually install the dependencies before you may begin.

I came up with a much simpler solution: npm clone

How

Cloning from a source

npm clone <packageName>

would go look into the repository configuration of packageName on the NPM registry (default, can be overridden with --registry as usual) and clones it from there with whatever program can be found that might make sense (git, svn, hg?).

It would look at the repository.type set in the package.json.

  • "type": "git" -> use git
  • "type": "svn" -> use something like TortoiseSVN.
npm clone <URL>

would clone from the given URL and, if it's an NPM package (package.json or package-lock.json was found), then do the same as above.

After cloning

Unless an option like --no-install is given, npm clone could then install the dependencies for that package or run a script!

Options
Option Parameters Default Meaning
-d / --dest <path> The current directory Where to clone the code to
-w / --work-dir <path> The root directory of the repository Where to run the npm commands (such as npm install) inside the cloned worktree
-s / --script <script> A script to run after cloning
-n / --no-install No automatic install will be run

Note: These options names are mere suggestions. If you can come up with something that makes more sense, please let me know.

Example

Command Result
npm clone express -s test Clones the source of the express package and runs tests.
npm clone typescript -n Clones TypeScript from GitHub and then does nothing.
npm clone https://github.com/badges/shields -w gh-badges Clones the shields repository from GitHub and installs the dependencies of the gh-badges package in the gh-badges directory.

Current Behaviour

You have to do these things:

  1. Find out where the code lives.
  2. Clone it from there.
  3. Install the dependencies.

Desired Behaviour

Run npm clone <package> with whatever options suit your case and you're good to go.

References

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

No implementation files, tests, or entry points are named. Start by reviewing the RFC proposal and the npm CLI’s existing subcommand conventions, then resolve the source detection, VCS support, destination, installation, and script behavior. Done means the proposal has a settled, implementable specification.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
cli, tooling
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.