cnpm 高速版本 beta 征集
cnpm 高速版本目前正在 beta,为了更加大范围地支持 npm install 很慢的项目,需要大家来帮忙测试。
- 如果你当前日常的项目每次重新 npm install 你都需要走开去喝咖啡喝茶的,那么你就是我们这次发布的重点关注对象了。
- 如果你是公司里面负责前端工程的同学,你是不是每天都在吐槽"尼玛 build 一个 react app 比 build Java 还慢"?回答 yes?那么你就是我们这次发布的重点关注对象了。
- 在 Twitter 上每天都有很多人抱怨 npm install 超级慢,你是不是也在抱怨呢?回答 yes?那么你就是我们这次发布的重点关注对象了。
ddd.png
如何参加 beta 测试
直接安装 cnpm@beta 版本即可
$ npm i -g cnpm[@beta](/user/beta) --registry=https://registry.npm.taobao.org
$ cnpm -v
4.2.0-beta.3
能快多少?
目前我测试下来,安装 cnpmjs.org 这个模块能大大节约 npm install 时间:
- Before:
cnpm@3.4.1
$ cnpm cache clean
$ time cnpm install cnpmjs.org
real 0m24.370s
user 0m12.982s
sys 0m4.170s
- After:
cnpm@4.2.0
$ cnpm cache clean
$ time cnpm install cnpmjs.org --no-cache
[cnpmjs.org@*] installed at node_modules/.npminstall/cnpmjs.org/2.8.0/cnpmjs.org (0 packages, use 5s, speed 1.04MB/s, json 1.44MB, tarball 3.74MB)
All packages installed (215 packages installed from npm registry, use 5s, speed 1.03MB/s, json 266(1.44MB), tarball 3.74MB)
real 0m6.220s
user 0m4.871s
sys 0m2.072s
Why we can improve the install speed? Check out npminstall and take a look.
本周某个时间,等大家的反馈稳定后,cnpm 将合并 https://github.com/cnpm/cnpm/pull/72 代码发布正式版本。
@fengmk2 似乎是webpack自身的问题:http://webpack.github.io/docs/troubleshooting.html#npm-linked-modules-doesn-t-find-their-dependencies
链接过来的模块在webpack中编译会报错找不到模块
[rd@0.0.2] installed at node_modules/.npminstall/rd/0.0.2/rd (0 packages, use 2s, speed 4.62kB/s, json 10.67kB, tarball 0B)
[debug@^2.2.0] existed at node_modules/.npminstall/debug/2.2.0/debug (0 packages, use 5s, speed 12.91kB/s, json 58.37kB, tarball 3.67kB)
[project-core@0.0.16] installed at node_modules/.npminstall/project-core/0.0.16/project-core (0 packages, use 6s, speed 33.57kB/s, json 144.38kB, tarball 43.85kB)
[connect@^3.4.1] installed at node_modules/.npminstall/connect/3.4.1/connect (0 packages, use 6s, speed 33.35kB/s, json 145.78kB, tarball 43.85kB)
[serve-static@^1.10.2] installed at node_modules/.npminstall/serve-static/1.10.2/serve-static (0 packages, use 4s, speed 38.44kB/s, json 184.68kB, tarball 56.37kB)
[body-parser@^1.15.0] installed at node_modules/.npminstall/body-parser/1.15.0/body-parser (0 packages, use 6s, speed 38.81kB/s, json 184.68kB, tarball 59.66kB)
[ecc-jsbn@>=0.0.1 <1.0.0] optional install error:
Error: getaddrinfo ENOTFOUND registry.npmjs.org registry.npmjs.org:80
at errnoException (dns.js:26:10)
at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:77:26)
[bl@1.0.3] install error: Error: ENOTEMPTY: directory not empty, rmdir '/home/www/hxapi/node_modules/.npminstall/readable-stream/2.0.5/readable-stream/node_modules', parentDir: /home/www/hxapi/node_modules/.npminstall/request/2.69.0/request, remove /home/www/hxapi/node_modules/.npminstall/bl/1.0.3/bl
error stack: Error: ENOTEMPTY: directory not empty, rmdir '/home/www/hxapi/node_modules/.npminstall/readable-stream/2.0.5/readable-stream/node_modules'
at Error (native)
[request@2.69.0] install error: Error: ENOTEMPTY: directory not empty, rmdir '/home/www/hxapi/node_modules/.npminstall/readable-stream/2.0.5/readable-stream/node_modules', parentDir: /home/www/hxapi, remove /home/www/hxapi/node_modules/.npminstall/request/2.69.0/request
error stack: Error: ENOTEMPTY: directory not empty, rmdir '/home/www/hxapi/node_modules/.npminstall/readable-stream/2.0.5/readable-stream/node_modules'
at Error (native)
Error: ENOTEMPTY: directory not empty, rmdir '/home/www/hxapi/node_modules/.npminstall/readable-stream/2.0.5/readable-stream/node_modules'
Error: ENOTEMPTY: directory not empty, rmdir '/home/www/hxapi/node_modules/.npminstall/readable-stream/2.0.5/readable-stream/node_modules'
at Error (native)
npm WARN optional dep failed, continuing fsevents@1.0.8
npm WARN deprecated graceful-fs@2.0.3: graceful-fs version 3 and before will fail on newer node releases. Please update to graceful-fs@^4.0.0 as soon as possible.
/
这些奇怪的错误是啥东西?
@fengmk2 能否选择支持 npm 和 npminstall 切换,因为我有一些旧的项目是使用 npm3 安装的,和 npminstall 似乎是不兼容吧。还有,能否有进度条显示,就算是跟 npm2 时代的 /|- 一样也行呀。
@xadillax 大概看了一下打印出来的信息,原理应该是这样的:
- 用以下方式组织模块结构:
+ .npminstall
----+ 模块名
--------+ 版本1
--------+ 版本2
- 这样保证了同一模块同一版本号在
node_modules目录下只会有一份 node_modules目录下所有模块目录直接链接到.npminstall/模块名/版本
@leizongmin https://ci.appveyor.com/project/fengmk2/npminstall appveyor 上有配置单元测试。可以的
@xadillax 原理看回复 https://cnodejs.org/topic/56dcd2cc502596633dc2c3e9#56dff4a4f5d830306e2f0f34
其实就是将 npm 认为无法并行的任务并行了。只要你的 cpu 和网络够快,安装速度就够快。而且还完成支持 lib 模式,你的应用也可以动态安装模块,实现类似 https://tonicdev.com/npm/chalk 的功能了。