Skip to content

[RRFC] New subcommand “npm clone” #192

@cactysman

Description

@cactysman

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions