• Stars
    star
    497
  • Rank 88,652 (Top 2 %)
  • Language
    JavaScript
  • License
    Other
  • Created almost 9 years ago
  • Updated 5 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Make `npm install` fast and easy.

npminstall

NPM version Node CI Test coverage Known Vulnerabilities npm download FOSSA Status

Make npm install fast and handy.

Node.js and Python required

  • Node.js >= 14.x
  • Python >= 3.x

Use as Cli

Install

$ npm install npminstall -g

Usage

In cnpm

It is integrated in cnpm.

$ npm install cnpm -g
# will use npminstall
$ cnpm install

npminstall

Usage:

  npminstall
  npminstall <pkg>
  npminstall <pkg>@<tag>
  npminstall <pkg>@<version>
  npminstall <pkg>@<version range>
  npminstall <alias>@npm:<name>
  npminstall <folder>
  npminstall <tarball file>
  npminstall <tarball url>
  npminstall <git:// url>
  npminstall <github username>/<github project>

Can specify one or more: npm install ./foo.tgz bar@stable /some/folder
If no argument is supplied, installs dependencies from ./package.json.

Options:

  --production: won't install devDependencies
  --save, --save-dev, --save-optional: save installed dependencies into package.json
  -g, --global: install devDependencies to global directory which specified in `$ npm config get prefix`
  -r, --registry: specify custom registry
  -c, --china: specify in china, will automatically using chinese npm registry and other binary's mirrors
  -d, --detail: show detail log of installation
  --trace: show memory and cpu usages traces of installation
  --ignore-scripts: ignore all preinstall / install and postinstall scripts during the installation
  --no-optional: ignore optionalDependencies during the installation
  --forbidden-licenses: forbit install packages which used these licenses
  --engine-strict: refuse to install (or even consider installing) any package that claims to not be compatible with the current Node.js version.
  --flatten: flatten dependencies by matching ancestors dependencies
  --registry-only: make sure that all packages are installed from registry. Any package that is installed from remote(e.g.: git, remote url) will lead to a failure of installation.
  --cache-strict: use disk cache even on production env

npmuninstall

Usage:

  npmuninstall <pkg>
  npmuninstall <pkg>@<version>
  npmuninstall <pkg>@<version> [<pkg>@<version>]
  npminstall <alias>@npm:<name>

npmlink

Usage:

  npmlink <folder>

Use as Lib

Install

$ npm install npminstall --save

Usage

const npminstall = require('npminstall');

(async () => {
  await npminstall({
    // install root dir
    root: process.cwd(),
    // optional packages need to install, default is package.json's dependencies and devDependencies
    // pkgs: [
    //   { name: 'foo', version: '~1.0.0' },
    // ],
    // install to specific directory, default to root
    // targetDir: '/home/admin/.global/lib',
    // link bin to specific directory (for global install)
    // binDir: '/home/admin/.global/bin',
    // registry, default is https://registry.npmjs.org
    // registry: 'https://registry.npmjs.org',
    // debug: false,
    // storeDir: root + 'node_modules',
    // ignoreScripts: true, // ignore pre/post install scripts, default is `false`
    // forbiddenLicenses: forbit install packages which used these licenses
  });
})().catch(err => {
  console.error(err);
});

Support Features

  • all types of npm package
    • a) a folder containing a program described by a package.json file (npm install file:eslint-rule)
    • b) a gzipped tarball containing (a) (npm install ./rule.tgz)
    • c) a url that resolves to (b) (npm install https://github.com/indexzero/forever/tarball/v0.5.6)
    • d) a @ that is published on the registry with (c)
    • e) a @ (see npm-dist-tag) that points to (d)
    • f) a that has a "latest" tag satisfying (e)
    • g) a that resolves to (a) (npm install git://github.com/timaschew/cogent#fix-redirects)
  • All platform support
  • global install (-g, --global)
  • preinstall, install, postinstall scripts
  • node-gyp@9, only support Python@3
    • node-pre-gyp
  • bin ([email protected], [email protected])
  • scoped package
  • bundleDependencies / bundledDependencies ([email protected], [email protected])
  • optionalDependencies ([email protected])
  • peerDependencies ([email protected], [email protected], [email protected])
  • deprecate message
  • --production mode
  • save, save-dev, save-optional
  • support ignore-scripts
  • uninstall
  • resolutions
  • npm alias
  • npm workspaces

Different with NPM

This project is inspired by pnpm, and has a similar store structure like pnpm. You can read pnpm vs npm to see the different with npm.

Limitations

  • You can't install from shrinkwrap(and don't want to support for now).
  • Peer dependencies are a little trickier to deal with(see rule 1 below).
  • You can't publish npm modules with bundleDependencies managed by npminstall(because of rule 2 below).
  • npminstall will collect all postinstall scripts, and execute them until all dependencies installed.
  • If last install failed, better to cleanup node_modules directory before retry.

node_modules directory

Two rules:

  1. The latest version of modules will link at options.storeDir's node_modules.
  2. Module's dependencies will link at module's node_modules.

e.g.:

  • app: { "dependencies": { "debug": "2.2.0" } } (root)
  • [email protected]: { "dependencies": { "ms": "0.7.1" } }
app/
โ”œโ”€โ”€ package.json
โ””โ”€โ”€ node_modules
    โ”œโ”€โ”€ [email protected]@debug
    โ”‚ย ย  โ”œโ”€โ”€ node_modules
    โ”‚ย ย  โ”‚ย ย  โ””โ”€โ”€ ms -> ../../[email protected]@ms
    โ”œโ”€โ”€ _ms0.7.1@ms
    โ”œโ”€โ”€ debug -> [email protected]@debug
    โ””โ”€โ”€ ms -> [email protected]@ms # for peerDependencies

flattened vs nested

npminstall will always try to install the maximal matched version of semver:

root/
  [email protected]
  mod/
    koa@~1.1.0
# will install two different version of koa when use npminstall.

you can enable flatten mode by --flatten flag, in this mod, npminstall will try to use ancestors' dependencies to minimize the dependence-tree.

root/
  [email protected]
  mod/
    koa@~1.1.0

root/
  [email protected]
  mod/
    koa@^1.1.0
# both the same version: 1.1.0

root/
  koa@~1.1.0
  mod/
    koa@^1.1.0
# both the same version: 1.1.2

root/
  mod/
    koa@^1.1.0
  moe/
    koa@~1.1.0
# two different versions

npminstall will always treat n.x and n.m.x as flattened

root/
  [email protected]
  mod/
    [email protected]
both the same version: 1.1.0

root/
  koa@~1.1.0
  mod/
    [email protected]
both the same version: 1.1.2

Resolutions

support selective version resolutions like yarn. which lets you define custom package versions inside your dependencies through the resolutions field in your package.json file.

resolutions also supports npm alias. It's a workaround feature to fix some archived/inactive/ package by uploading your own bug-fixed version to npm registry.

see use case at unittest package.json.

Benchmarks

https://github.com/cnpm/npminstall-benchmark

cnpmjs.org install

cli real user sys
npminstall 0m10.908s 0m8.733s 0m4.282s
npminstall with cache 0m8.815s 0m7.492s 0m3.644s
npminstall --no-cache 0m10.279s 0m8.255s 0m3.932s
pnpm 0m13.509s 0m11.650s 0m4.443s
npm 0m28.171s 0m26.085s 0m8.219s
npm with cache 0m20.939s 0m19.415s 0m6.302s

pnpm benchmark

see https://github.com/pnpm/pnpm#benchmark

npminstall babel-preset-es2015 browserify chalk debug minimist mkdirp
    real	0m8.929s       user	0m5.606s       sys	0m2.913s
pnpm i babel-preset-es2015 browserify chalk debug minimist mkdirp
    real	0m12.998s      user	0m8.653s       sys	0m3.362s
npm i babel-preset-es2015 browserify chalk debug minimist mkdirp
    real	1m4.729s       user	0m55.589s      sys	0m23.135s

License

MIT

Contributors


fengmk2


dead-horse


gemwuu


semantic-release-bot


killagu


ibigbug


vagusX


afc163


yesmeck


popomore


we11adam


whatwewant


emma-owen


weihong1028


HomyeeKing


nightink


XadillaX


LeoYuan


cnlon


Moudicat


hanzhao


marcbachmann


MondoGao


snyk-bot


Solais


thonatos


atian25


tommytroylin


wssgcg1213


yibn2008


fossabot


hugohua


hyj1991


mansonchor


givingwu


Abreto

This project follows the git-contributor spec, auto updated at Sat Mar 25 2023 22:23:53 GMT+0800.

More Repositories

1

cnpmjs.org

โ€ผ๏ธ โ€ผ๏ธ โ€ผ๏ธ โ€ผ๏ธ DEPRECATED, please use https://github.com/cnpm/cnpmcore โ€ผ๏ธ โ€ผ๏ธ โ€ผ๏ธ โ€ผ๏ธ
JavaScript
3,551
star
2

cnpm

cnpm: npm client for China mirror of npm
JavaScript
2,016
star
3

cnpmcore

Private NPM Registry for Enterprise
TypeScript
608
star
4

koa-middlewares

easy way to use some useful koa middlewares
JavaScript
177
star
5

binary-mirror-config

Binary mirror config for prebuild and node-pre-gyp
JavaScript
162
star
6

cnpmweb

Web for cnpmcore
TypeScript
90
star
7

bug-versions

collect all bug versions on npm package.
JavaScript
83
star
8

nodeinstall

Another node installer that bundle node with application.
JavaScript
83
star
9

mirrors

โ€ผ๏ธ โ€ผ๏ธ โ€ผ๏ธ โ€ผ๏ธ DEPRECATED, please use https://github.com/cnpm/cnpmcore โ€ผ๏ธ โ€ผ๏ธ โ€ผ๏ธ โ€ผ๏ธ
JavaScript
73
star
10

rapid

The fastest way to install npm packages.
Rust
38
star
11

koa-limit

koa middleware for limiting requests by ip
JavaScript
31
star
12

unpkg-white-list

npmmirror.com ๅ…่ฎธๅผ€ๅฏ unpkg ๅŠŸ่ƒฝ็š„็™ฝๅๅ•ๅˆ—่กจ๏ผŒ้ฟๅ…่ขซๅฝ“ไฝœ็ฝ‘็›˜ๆปฅ็”จ
JavaScript
30
star
13

web.cnpmjs.org

Web app of registry.cnpmjs.org
JavaScript
14
star
14

oss-cnpm

oss wraper for https://cnpmjs.org
JavaScript
11
star
15

upyun-storage

Upyun wrapper for cnpm
JavaScript
9
star
16

sfs

Simple file store
JavaScript
7
star
17

rapid.app

The desktop app for rapid npm installation.
JavaScript
5
star
18

fs-cnpm

fs storage wrapper for cnpm
JavaScript
4
star
19

errors

cnpm errors
TypeScript
4
star
20

safe-publish-tag

Get the safe publish tag when you `npm publish`
JavaScript
3
star
21

npminstall-ci

CI Tests for [npminstall](https://npmjs.com/npminstall)
Shell
2
star
22

r.cnpmjs.org

r.cnpmjs.org base on cnpmcore
TypeScript
2
star
23

tfs-cnpm

a tfs api wraper for cnpm
JavaScript
1
star
24

upyun-cnpm

co-upyun-storage for cnpm
JavaScript
1
star
25

npminstall-benchmark

npminstall vs npm vs pnpm vs yarn
Makefile
1
star
26

co-upyun-storage

Upyun-storage for co
JavaScript
1
star
27

cos-cnpm

tencent-cloud cos wrapper for cnpm
JavaScript
1
star
28

qn-cnpm

qn wrapper for cnpm
JavaScript
1
star