Code Monkey home page Code Monkey logo

npminstall's Introduction

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.

npminstall's People

Contributors

abreto avatar afc163 avatar atian25 avatar cnlon avatar dead-horse avatar elrrrrrrr avatar feichao93 avatar fengmk2 avatar fossabot avatar gemwuu avatar givingwu avatar hanzhao avatar hugohua avatar hyj1991 avatar ibigbug avatar killagu avatar mansonchor avatar marcbachmann avatar mondogao avatar moudicat avatar popomore avatar semantic-release-bot avatar snyk-bot avatar solais avatar thonatos avatar tommytroylin avatar vagusx avatar wssgcg1213 avatar yesmeck avatar yibn2008 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

npminstall's Issues

Randomly miss some packages

Hi,

first of all thank for all your work it's a really nice project !

I'm wondering why I need to install twice sometimes, it's like npminstall do not see some packages at first run.

For example, if I clone one of my repo : https://github.com/maxime1992/web-template

Then inside it I run npminstall and run npm run dev it says "recess" is not installed. I run again npminstall and it works. I start from a fresh install and then it says it cannot find a sass module.

I also have some errors with phantomJS :
image

If I'm missing anything I would be glad to know.

Cheers :)

安装常用的冒号分割的 Url 出错

git url

see https://git-scm.com/docs/git-clone#_git_urls_a_id_urls_a

git clone ssh://[user@]host.xz[:port]/path/to/repo.git/
git clone [user@]host.xz:path/to/repo.git/

npm deps

https://docs.npmjs.com/files/package.json#git-urls-as-dependencies

npm 支持使用上述这两种

"module1":  "git+ssh://[user@]host.xz[:port]/path/to/repo.git/",
"module2": "git+ssh://[user@]host.xz:path/to/repo.git/"

现象

安装结果

  • npm 是可以安装的
  • cnpm 安装出错, 可以看到报错为 sh -c git clone ssh://[email protected]:user/project.git

其实应该运行的命令是 sh -c git clone [email protected]:user/project.git

解决

  1. 不使用 : 分割的路径, 改为 [email protected]:user/project.git -> [email protected]/user/project.git 即可
  2. 这里应该是 npm 处理了, cnpm 没有处理, 但是冒号:分隔比较常用, 所以来报个bug

Question : why did you not PR the ied repository

Hi

Your repository is great :) , i met one problèm about the timeout random during the npminstall which change everytime. Not on the same dependancies . Also i ask me why you d ont do a PR at ied repository ? Maybe some contributors can help you to increase the features and fix some bugs :). This repository has a really potential ')

bug: Libraries are missing randomly

I think i met some troubles with the dependancies and it's random, even after the upgrade in 1.0.8.

If you try npminstall with this repository => https://github.com/kevincaradant/web-template and then you try to build with the command npm run prod. Libraries are missing randomly. Sometimes, it's imagemin-pngquant, or 'recess'.

Sometimes that work the first time and sometimes not :/. Did you have any idea why ?

Thank you

image

And this module is in the package.json.

TODOs

https://docs.npmjs.com/cli/install

  • global install (-g, --global)
  • postinstall script
    • support Windows
  • node-gyp
    • 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
  • cleanup when install failed
  • 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)
  • save, save-dev, save-optional

standard can't work

standard require eslint plugin, and eslint is deped by standard.

app/
 - node_modules/standard   -> .npminstall/standard/x.x.x
 - node_modules/standard/node_modules/eslint -> ../../.npminstall/eslint/x.x.x
 - node_modules/standard/node_modules/eslint-config-standard -> ../../.npminstall/eslint-config-standard/x.x.x

eslint will require('eslint-config-standard'), because using link, eslint can't require eslint-config-standard.

eslint require('eslint-config-standard') will try files:

  • app/node_modules/.npminstall/eslint/x.x.x/node_modules/eslint-config-standard
  • app/node_modules/.npminstall/node_modules/eslint-config-standard
  • app/node_modules/eslint-config-standard

These 3 paths will not exists in npminstall link mode.

prepare and prepublishOnly hooks

  • Introduce a new prepare lifecycle event, which has the current behavior of the prepublish event – it runs before the package tarball is packed and uploaded to the registry during the publishing process, as well as when you run npm install (with no package name) after cloning a package, to prepare it for use (i.e. by transpiling source).
  • Introduce a new prepublishOnly lifecycle event, which runs only at prepublish time.

npm/npm#10074

how to use with proxy

I had read this issue #33
but it didn't work

I simply read the source code but didn't find any lines about proxy.

Request with 'referer'

Just like npm does.

182.201.187.173 - 100.97.90.145 [31/Mar/2016:15:41:36 +0800] "GET /cross-spawn-async HTTP/1.0" 304 0 "install generator-react-fullstack" "npm/3.3.12 node/v5.4.0 win32 ia32" 0.028 0.027

install ant-design with error

$ git clone [email protected]:ant-design/ant-design.git
$ cd ant-design
$ tnpm ii
& tnpm start

Then visit http://127.0.0.1:8001

ERROR in ./site/component/utils.js
Module not found: Error: Cannot resolve module 'highlight.js' in /Users/afc163/Projects/ant-design/site/component
 @ ./site/component/utils.js 19:17-40

Bug: jpegtran-bin not found

Hi

I come with a little bug :

image

This module is not found. But the installation have not error.
This problem seems to be only on Windows ...

Any idea guys ? :)

Thank you

Working under proxy ?

I wanted to see if V1.1.0 fixed this issue : #30

But now I have this :
image

Hint : I tried that command at work and there's a proxy.
I think I might have to set strict-ssl=false, is that possible ?

npm install 失败

master 分支:http://github.com/ant-design/ant-design
操作:tnpm install

[[email protected]] scripts.postinstall success, use 72ms
[[email protected]] scripts.prepublish: "antd-tools run guard"
antd-tools run guard

/Users/afc163/Projects/ant-design/node_modules/.0.3.7@orchestrator/index.js:153
            throw err;
            ^
1
Error: Run "sh -c antd-tools run guard" error, exit code 1
    at ChildProcess.<anonymous> (/usr/local/lib/node_modules/tnpm/node_modules/runscript/index.js:67:21)
    at emitTwo (events.js:100:13)
    at ChildProcess.emit (events.js:185:7)
    at maybeClose (internal/child_process.js:850:16)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:215:5)
npminstall version: 2.2.1
npminstall args: /usr/local/bin/node /usr/local/lib/node_modules/tnpm/node_modules/npminstall/bin/install.js --tmp=/Users/afc163/.tnpm_tmp --progress=false --no-proxy --disturl=https://x/dist/node --userconfig=/Users/afc163/.tnpmrc --registry=http://registry.npm.x.com -d --china --prefix=/usr/local --forbidden-licenses=AGPL,CPAL,OSL --custom-china-mirror-url=https://x/dist
$ tnpm -v
[email protected] (/usr/local/lib/node_modules/tnpm/bin/tnpm.js)
[email protected] (/usr/local/lib/node_modules/tnpm/node_modules/npm/lib/npm.js)
[email protected] (/usr/local/bin/node)
[email protected] (/usr/local/lib/node_modules/tnpm/node_modules/npminstall/lib/index.js)
prefix=/usr/local (load prefix from: $ npm config get prefix)
darwin x64 15.5.0 
registry=http://registry.npm.x.com

Failed to install scoped packages

When install scoped packages (such a typescript typings packages: @type/whatwg-fetch, ...), it throws error:

Error: GET https://registry.npmjs.com/@types%2Fwhatwg-fetch/0.0.31 response 401 status, ERROR: you cannot fetch versions for scoped packages
    at get (/Users/yanghanxing/.nvm/versions/node/v5.0.0/lib/node_modules/npminstall/lib/get.js:43:17)
    at next (native)
    at onFulfilled (/Users/yanghanxing/.nvm/versions/node/v5.0.0/lib/node_modules/npminstall/node_modules/co/index.js:65:19)
    at process._tickCallback (node.js:377:9)

tnpm ii 无法更新到版本

tnpm ii [email protected] 装的是 2.4.1 这个版本。
装完后,我更新组件 用的命令是 tnpm ii react-router@^2.4.0
理论上,装的应该是[email protected] 这个版本, 但实际上装的还是2.4.1

如果我把node_modules 删掉,重新用tnpm ii react-router@^2.4.0 安装,这样就能正常安装到2.5.2 这个版本了。

使用:

 tnpm ii react-router  
 tnpm ii [email protected] 

这两个命令都是可以的
image

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.