luqin / blog

My blog
https://github.com/luqin/blog/issues
64 stars 11 forks source link

CNPM 使用文档 #4

Open luqin opened 8 years ago

luqin commented 8 years ago

如何搭建私有 NPM 仓库请移步:CNPM 搭建私有 NPM 服务

本地 CNPM 服务地址:

* http://myip:7001       # registry
* http://myip:7002       # web

安装 CNPM

$ npm install -g cnpm --registry=https://r.cnpmjs.org

修改 CNPM 默认仓库地址

$ cnpm set registry http://myip:7001

登录私有仓库

$ cnpm login
Username: myname
Password: ***
Email: (this IS public) myname@mycompany.com

发布私有 package

Private package should be a scoped package

$ cd /tmp
$ mkdir helloworld && cd helloworld
$ cnpm init
name: (helloworld) @my-company-name/helloworld
version: (1.0.0)

{
  "name": "@my-company-name/helloworld",
  "version": "1.0.0",
  "description": "my first scoped package",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC"
}

$ cnpm publish
+ @my-company-name/helloworld@1.0.0

查看私有 package

$ # 浏览器访问 http://myip:7002/@my-company-name/helloworld

或者使用 cnpm info

$ cnpm info

安装 package

$ cnpm install [name]

同步 package

直接通过 sync 命令马上同步一个模块, 只有 cnpm 命令行才有此功能:

$ cnpm sync jquery

当然, 你可以直接通过 web 方式来同步: /sync/jquery

管理 package owner

npm owner ls 
npm owner add  # 增加 owner 
npm owner rm # 删除
lycandjava commented 8 years ago

请教几个问题,先再此谢谢了: 1、怎么从阿里同步相关的npm包到npm仓库。 2、通过web界面搜索后同步,为什么我这里面的totalpackages依然是0呢 3、客户端(例外一台机器)通过cnpm install 的node_modules包信息会出现在,web界面中吗?比如cnpm sync jquery,我机器上的jquery下载后没有出现在http://myip:7002的界面中

luqin commented 8 years ago

@lycandjava 只有搭建的是npm镜像仓库才会同步所有的npm包。 一般我们搭建的私有npm仓库不是镜像,所以没有totalpackages,上传的私有仓库会显示。 cnpm sync jquery 是指淘宝镜像从npm官方同步

xiyangjun commented 7 years ago

私有包和公有包可以混用么?

luqin commented 7 years ago

可以的

sustwater commented 7 years ago

我登录成功了,但是发布一直报错,说是没有权限。这个权限怎么设置呢?

E:\portal\portal\helloworld>cnpm login Username: (admin) Password: (or leave unchanged) Email: (this IS public) (aa@aa.com) Logged in as admin on http://localhost:7001/.

E:\portal\portal\helloworld>cnpm publish helloworld npm ERR! publish Failed PUT 403 npm ERR! Windows_NT 6.1.7601 npm ERR! argv "D:\Program Files\nodejs\node.exe" "D:\Program Files\nodejs\ node_global\node_modules\cnpm\node_modules\npm\bin\npm-cli.js" "--userconf ig=C:\Users\Administrator\.cnpmrc" "--disturl=https://npm.taobao.org/mirrors/ node" "--registry=http://localhost:7001/" "publish" "helloworld" npm ERR! node v6.2.2 npm ERR! npm v3.10.10 npm ERR! code E403

npm ERR! forbidden user admin not authorized to modify helloworld, please contac t maintainers: avianflu: helloworld npm ERR! npm ERR! If you need help, you may report this error at: npm ERR! https://github.com/npm/npm/issues

npm ERR! Please include the following file with any support request: npm ERR! E:\portal\portal\helloworld\npm-debug.log

E:\portal\portal\helloworld>

luqin commented 7 years ago

@sustwater 发布的包不能与npm中的重复:`helloworld'

sustwater commented 7 years ago

@luqin 谢谢,我的publish成功了,在web页面和数据库都可以看到发布好的工程。但是install的时候出错了。错误原因应该是get的路径不对,应该指向我本地库,但实际指向的是r.cnpmjs.org,可是我已经设置了cnpm set registry http://myip:7001

E:\TEMP\tmcportal>cnpm install testtmc | Installing testtmc@*Error: GET http://r.cnpmjs.org/testtmc/download/testtmc-1. 0.2.tgz response 404 status at get (D:\Program Files\nodejs\node_global\node_modules\cnpm\node_modules\n pminstall\lib\get.js:49:17) at next (native) at onFulfilled (D:\Program Files\nodejs\node_global\node_modules\cnpm\node_m odules\co\index.js:65:19) npminstall version: 2.15.0 npminstall args: D:\Program Files\nodejs\node.exe D:\Program Files\nodejs\node_g lobal\node_modules\cnpm\node_modules\npminstall\bin\install.js --china --usercon fig=C:\Users\Administrator.cnpmrc --disturl=https://npm.taobao.org/mirrors/node --registry=http://127.0.0.1:7001 testtmc

sustwater commented 7 years ago

我又试验了下用cnpm publish --registry=http://127.0.0.1:7001发布 用cnpm install testtmc --registry=http://127.0.0.1:7001下载,结果还是不行,运行结果如下所示

E:\portal\testtmc>cnpm publish --registry=http://127.0.0.1:7001

E:\TEMP\tmcportal>cnpm install testtmc --registry=http://127.0.0.1:7001 \ Installing testtmc@*Error: GET http://r.cnpmjs.org/testtmc/download/testtmc-1. 0.3.tgz response 404 status at get (D:\Program Files\nodejs\node_global\node_modules\cnpm\node_modules\n pminstall\lib\get.js:49:17) at next (native) at onFulfilled (D:\Program Files\nodejs\node_global\node_modules\cnpm\node_m odules\co\index.js:65:19) npminstall version: 2.15.0 npminstall args: D:\Program Files\nodejs\node.exe D:\Program Files\nodejs\node_g lobal\node_modules\cnpm\node_modules\npminstall\bin\install.js --china --usercon fig=C:\Users\Administrator.cnpmrc --disturl=https://npm.taobao.org/mirrors/node --registry=http://127.0.0.1:7001 testtmc

E:\TEMP\tmcportal>

qinmeifang commented 5 years ago

请问楼主问题解决了吗