Compare commits
99 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8789dadaef | ||
|
|
1c936d4b73 | ||
|
|
7c2f947518 | ||
|
|
bfbfef87d2 | ||
|
|
ea3beceef7 | ||
|
|
b0f0bc0331 | ||
|
|
932547af2a | ||
|
|
79ac9fb823 | ||
|
|
a437eb01eb | ||
|
|
6d921a9c46 | ||
|
|
abcb81d28c | ||
|
|
ea54f32805 | ||
|
|
3dbf29afac | ||
|
|
2c520d97a9 | ||
|
|
38148b24cb | ||
|
|
97895bdfa5 | ||
|
|
0c1c12680c | ||
|
|
6485e4b019 | ||
|
|
ee1e084455 | ||
|
|
5c8d679a6d | ||
|
|
94dc13088c | ||
|
|
9b572d77aa | ||
|
|
c1fa6de038 | ||
|
|
227e1927b4 | ||
|
|
ea98b61ddf | ||
|
|
9d1d60b764 | ||
|
|
7509d909e8 | ||
|
|
9612f64aba | ||
|
|
1b04d59539 | ||
|
|
e6998506f3 | ||
|
|
576397b2b0 | ||
|
|
6c1935bc61 | ||
|
|
1e68cfa568 | ||
|
|
8188d9a07a | ||
|
|
d7ae8d28c1 | ||
|
|
afa5639752 | ||
|
|
e0213e18a0 | ||
|
|
a74d60c7eb | ||
|
|
fcabc49d39 | ||
|
|
ad0722b57b | ||
|
|
6e11a2c8a7 | ||
|
|
0329cfad61 | ||
|
|
ede8a3ce5f | ||
|
|
cde4f2179e | ||
|
|
374dc17a6b | ||
|
|
626259c379 | ||
|
|
36644bda67 | ||
|
|
236e9e2fb3 | ||
|
|
b551216517 | ||
|
|
c8d9d9f075 | ||
|
|
4d43588b10 | ||
|
|
5f71add418 | ||
|
|
3fcfc6306d | ||
|
|
e78c774dbf | ||
|
|
6a54b1328f | ||
|
|
47c8273b7d | ||
|
|
0f01a4c076 | ||
|
|
17b43e3ae4 | ||
|
|
7fd6b10ddf | ||
|
|
7f16050f9e | ||
|
|
f57d525452 | ||
|
|
f05046b8bd | ||
|
|
a34aa7d72f | ||
|
|
72646ffee2 | ||
|
|
060fc65ffb | ||
|
|
4169ee9c6e | ||
|
|
51f380a800 | ||
|
|
c90062e7a0 | ||
|
|
26007f8318 | ||
|
|
0146ce5c30 | ||
|
|
87518df394 | ||
|
|
e49f5474f6 | ||
|
|
af4401fc62 | ||
|
|
c2d608a5cc | ||
|
|
b91b160b66 | ||
|
|
46a3df95bd | ||
|
|
d08aee047e | ||
|
|
406d8cf9a1 | ||
|
|
e1b9ab6b09 | ||
|
|
71f9014777 | ||
|
|
adca5adff2 | ||
|
|
1857f1d0e5 | ||
|
|
2d56820e8b | ||
|
|
119094b230 | ||
|
|
744b6e1e15 | ||
|
|
17f47732a0 | ||
|
|
3a46b97544 | ||
|
|
44976f4afa | ||
|
|
9da7c6ccf2 | ||
|
|
4b68eecf53 | ||
|
|
8d7058b947 | ||
|
|
933ae69d0b | ||
|
|
1af36f0a7a | ||
|
|
f4e9de5094 | ||
|
|
2ccaf404ab | ||
|
|
44c79c7646 | ||
|
|
a845d3f74d | ||
|
|
730113424c | ||
|
|
658be3004f |
@@ -1,11 +1,10 @@
|
||||
sudo: false
|
||||
language: node_js
|
||||
node_js:
|
||||
- '2'
|
||||
- '4'
|
||||
- '5'
|
||||
- '6'
|
||||
addons:
|
||||
- postgresql: '9.3'
|
||||
script: 'make test-travis-all'
|
||||
after_script:
|
||||
- "npm i codecov.io && cat ./coverage/coverage.json | ./node_modules/codecov.io/bin/codecov.io.js"
|
||||
- 'npm i codecov && codecov'
|
||||
|
||||
2
AUTHORS
2
AUTHORS
@@ -6,4 +6,6 @@ alsotang <alsotang@gmail.com> (https://github.com/alsotang)
|
||||
4simple <wondger@qq.com> (https://github.com/4simple)
|
||||
afc163 <afc163@gmail.com> (https://github.com/afc163)
|
||||
Yuwei Ba <i@xiaoba.me> (https://github.com/ibigbug)
|
||||
dickeylth <dickeylth@gmail.com> (https://github.com/dickeylth)
|
||||
wenbing <wenbing@users.noreply.github.com> (https://github.com/wenbing)
|
||||
|
||||
|
||||
143
History.md
143
History.md
@@ -1,4 +1,141 @@
|
||||
|
||||
2.14.0 / 2016-08-04
|
||||
==================
|
||||
|
||||
* feat: password may contains ":" (#999)
|
||||
* fix: limit sync fails email notice (#1006)
|
||||
|
||||
2.13.0 / 2016-07-26
|
||||
==================
|
||||
|
||||
* feat: enable maxrequests middleware (#1003)
|
||||
|
||||
2.12.2 / 2016-07-11
|
||||
==================
|
||||
|
||||
* fix: getModuleByRange don't list all packages (#990)
|
||||
* fix: should show new version package count (#984)
|
||||
|
||||
2.12.1 / 2016-07-01
|
||||
==================
|
||||
|
||||
* fix: make sure chagnes stream destroy (#982)
|
||||
* chore(package): update semver to version 5.2.0 (#978)
|
||||
* deps: use ^ instead of ~ (#976)
|
||||
* chore(package): update mini-logger to version 1.1.1 (#973)
|
||||
|
||||
2.12.0 / 2016-06-26
|
||||
==================
|
||||
|
||||
* fix: logger seperator should be one EOL ([#972](https://github.com/cnpm/cnpmjs.org/issues/972))
|
||||
* feat: add security check badge for public package ([#971](https://github.com/cnpm/cnpmjs.org/issues/971))
|
||||
|
||||
2.11.0 / 2016-06-25
|
||||
==================
|
||||
|
||||
* feat: add changes stream syncer ([#970](https://github.com/cnpm/cnpmjs.org/issues/970))
|
||||
* chore(package): update pg to version 5.1.0 ([#953](https://github.com/cnpm/cnpmjs.org/issues/953))
|
||||
|
||||
2.10.1 / 2016-06-05
|
||||
==================
|
||||
|
||||
* fix: should sync missing public scoped package on install ([#946](https://github.com/cnpm/cnpmjs.org/issues/946))
|
||||
* chore(package): update bytes to version 2.4.0 ([#943](https://github.com/cnpm/cnpmjs.org/issues/943))
|
||||
* userService ([#926](https://github.com/cnpm/cnpmjs.org/issues/926))
|
||||
* chore(package): update should to version 8.4.0 ([#928](https://github.com/cnpm/cnpmjs.org/issues/928))
|
||||
* chore(package): update humanize-ms to version 1.2.0 ([#927](https://github.com/cnpm/cnpmjs.org/issues/927))
|
||||
* chore(package): update kcors to version 1.2.1 ([#918](https://github.com/cnpm/cnpmjs.org/issues/918))
|
||||
* chore(package): update urllib to version 2.9.0 ([#898](https://github.com/cnpm/cnpmjs.org/issues/898))
|
||||
|
||||
2.10.0 / 2016-04-15
|
||||
==================
|
||||
|
||||
* feat: show tarball url on package page ([#894](https://github.com/cnpm/cnpmjs.org/issues/894))
|
||||
* chore(package): update koa-mock to version 1.6.1 ([#891](https://github.com/cnpm/cnpmjs.org/issues/891))
|
||||
|
||||
2.9.5 / 2016-04-12
|
||||
==================
|
||||
|
||||
* fix: change logo url to a better https source
|
||||
* fix: http://cnpmjs.org/package/fms pre style ([#739](https://github.com/cnpm/cnpmjs.org/issues/739))
|
||||
|
||||
2.9.4 / 2016-04-09
|
||||
==================
|
||||
|
||||
* fix: don't sync constructor package on exists mode ([#883](https://github.com/cnpm/cnpmjs.org/issues/883))
|
||||
* Update utility to version 1.7.0 🚀
|
||||
* chore: update sponsor link
|
||||
|
||||
2.9.3 / 2016-04-05
|
||||
==================
|
||||
|
||||
* fix: use better diff time to check sync status
|
||||
* Update sequelize to version 3.21.0 🚀
|
||||
* chore(package): update agentkeepalive to version 2.1.0
|
||||
* chore(package): update pg to version 4.5.2
|
||||
|
||||
2.9.2 / 2016-03-29
|
||||
==================
|
||||
|
||||
* fix: override antd for ul & ol list number & icon.
|
||||
|
||||
2.9.1 / 2016-03-29
|
||||
==================
|
||||
|
||||
* refactor: add more ua info on syncer
|
||||
|
||||
2.9.0 / 2016-03-26
|
||||
==================
|
||||
|
||||
* feat: only admin can unpublish
|
||||
* chore(package): update gravatar to version 1.5.0
|
||||
* chore(package): update sequelize to version 3.20.0
|
||||
* fix: fix save download count unqiue constraint error
|
||||
* chore(package): update moment to version 2.12.0
|
||||
|
||||
2.8.1 / 2016-03-07
|
||||
==================
|
||||
|
||||
* fix: only send warning email if no any sync data after 24h
|
||||
* chore(package): update kcors to version 1.1.0
|
||||
* chore(package): update koa to version 1.2.0
|
||||
* chore(package): update urllib to version 2.8.0
|
||||
|
||||
2.8.0 / 2016-02-23
|
||||
==================
|
||||
|
||||
* fix: convert `*` to latest tag
|
||||
* deps: upgrade deps and remove node 2.0.0 support
|
||||
* doc: update sponsors on readme
|
||||
* fix: update copyright year
|
||||
* doc: fix disturl typo
|
||||
* deps: sequelize@3.19.0
|
||||
|
||||
2.7.1 / 2016-02-01
|
||||
==================
|
||||
|
||||
* fix(semver): when have invalid version([#817](https://github.com/cnpm/cnpmjs.org/issues/817))
|
||||
|
||||
2.7.0 / 2016-02-01
|
||||
==================
|
||||
|
||||
* test: fix all test cases
|
||||
* test: fix unpublish
|
||||
* test: add complex range test case
|
||||
* feat: support semver([#816](https://github.com/cnpm/cnpmjs.org/issues/816))
|
||||
|
||||
2.6.2 / 2016-01-19
|
||||
==================
|
||||
|
||||
* feat: list & show support jsonp
|
||||
* chore(package): update urllib to version 2.7.0
|
||||
* Delete install.md
|
||||
|
||||
2.6.1 / 2016-01-12
|
||||
==================
|
||||
|
||||
* fix: source registry is not cnpm, ignore check status
|
||||
|
||||
2.6.0 / 2016-01-12
|
||||
==================
|
||||
|
||||
@@ -74,7 +211,7 @@
|
||||
* Add mock data.
|
||||
* refactor: add more sync log
|
||||
* Fix sidebar overflow.
|
||||
* Merge pull request #680 from ibigbug/ant-design
|
||||
* Merge pull request [#680](https://github.com/cnpm/cnpmjs.org/issues/680) from ibigbug/ant-design
|
||||
* Clean code.
|
||||
* Indent.
|
||||
* chore(package): update debug to version 2.2.0
|
||||
@@ -171,10 +308,10 @@
|
||||
|
||||
* feat: support always-auth
|
||||
* fix mysql select args = [] bug
|
||||
* fix #597 sequelize raw query.
|
||||
* fix [#597](https://github.com/cnpm/cnpmjs.org/issues/597) sequelize raw query.
|
||||
* fix(markdown): hotfix markdown-it cpu problem
|
||||
* feat: upgrade to co4
|
||||
* use kcors fixes #594
|
||||
* use kcors fixes [#594](https://github.com/cnpm/cnpmjs.org/issues/594)
|
||||
|
||||
2.0.0-rc.13 / 2015-02-04
|
||||
==================
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
This software is licensed under the MIT License.
|
||||
|
||||
Copyright(c) cnpmjs.org and other contributors.
|
||||
Copyright(c) cnpm and other contributors.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
|
||||
51
Makefile
51
Makefile
@@ -3,26 +3,12 @@ REPORTER = spec
|
||||
TIMEOUT = 30000
|
||||
MOCHA_OPTS =
|
||||
DB = sqlite
|
||||
DISTURL = https://npm.taobao.org/mirrors/iojs
|
||||
BIN = iojs
|
||||
|
||||
ifeq ($(findstring io.js, $(shell which node)),)
|
||||
BIN = node
|
||||
DISTURL = https://npm.taobao.org/mirrors/node
|
||||
endif
|
||||
|
||||
install:
|
||||
@npm install --build-from-source --registry=http://registry.npm.taobao.org \
|
||||
--disturl=$(DISTURL)
|
||||
|
||||
install-production production:
|
||||
@NODE_ENV=production $(MAKE) install
|
||||
|
||||
jshint: install
|
||||
@-node_modules/.bin/jshint ./
|
||||
jshint:
|
||||
@node_modules/.bin/jshint .
|
||||
|
||||
init-database:
|
||||
@$(BIN) test/init_db.js
|
||||
@node test/init_db.js
|
||||
|
||||
init-mysql:
|
||||
@mysql -uroot -e 'DROP DATABASE IF EXISTS cnpmjs_test;'
|
||||
@@ -32,13 +18,13 @@ init-pg:
|
||||
@psql -c 'DROP DATABASE IF EXISTS cnpmjs_test;'
|
||||
@psql -c 'CREATE DATABASE cnpmjs_test;'
|
||||
|
||||
test: install init-database
|
||||
test: init-database
|
||||
@NODE_ENV=test DB=${DB} node_modules/.bin/mocha \
|
||||
--reporter $(REPORTER) \
|
||||
--timeout $(TIMEOUT) \
|
||||
--require should \
|
||||
--require should-http \
|
||||
--require co-mocha \
|
||||
--require thunk-mocha \
|
||||
--require ./test/init.js \
|
||||
$(MOCHA_OPTS) \
|
||||
$(TESTS)
|
||||
@@ -54,16 +40,16 @@ test-pg: init-pg
|
||||
|
||||
test-all: test-sqlite test-mysql
|
||||
|
||||
test-cov cov: install init-database
|
||||
@NODE_ENV=test DB=${DB} $(BIN) \
|
||||
node_modules/.bin/istanbul cover --preserve-comments \
|
||||
test-cov cov: init-database
|
||||
@NODE_ENV=test DB=${DB} node \
|
||||
node_modules/.bin/istanbul cover \
|
||||
node_modules/.bin/_mocha \
|
||||
-- -u exports \
|
||||
--reporter $(REPORTER) \
|
||||
--timeout $(TIMEOUT) \
|
||||
--require should \
|
||||
--require should-http \
|
||||
--require co-mocha \
|
||||
--require thunk-mocha \
|
||||
--require ./test/init.js \
|
||||
$(MOCHA_OPTS) \
|
||||
$(TESTS)
|
||||
@@ -74,17 +60,17 @@ test-cov-sqlite:
|
||||
test-cov-mysql: init-mysql
|
||||
@$(MAKE) test-cov DB=mysql
|
||||
|
||||
test-travis: install init-database
|
||||
@NODE_ENV=test DB=${DB} CNPM_SOURCE_NPM=http://registry.npmjs.com CNPM_SOURCE_NPM_ISCNPM=false \
|
||||
$(BIN) \
|
||||
node_modules/.bin/istanbul cover --preserve-comments \
|
||||
test-travis: init-database
|
||||
@NODE_ENV=test DB=${DB} CNPM_SOURCE_NPM=https://registry.npmjs.com CNPM_SOURCE_NPM_ISCNPM=false \
|
||||
node \
|
||||
node_modules/.bin/istanbul cover \
|
||||
node_modules/.bin/_mocha \
|
||||
-- -u exports \
|
||||
--reporter dot \
|
||||
--timeout $(TIMEOUT) \
|
||||
--require should \
|
||||
--require should-http \
|
||||
--require co-mocha \
|
||||
--require thunk-mocha \
|
||||
--require ./test/init.js \
|
||||
$(MOCHA_OPTS) \
|
||||
$(TESTS)
|
||||
@@ -100,20 +86,19 @@ test-travis-pg:
|
||||
@psql -c 'CREATE DATABASE cnpmjs_test;' -U postgres
|
||||
@DB_PORT=5432 DB_USER=postgres $(MAKE) test-travis DB=postgres
|
||||
|
||||
test-travis-all: test-travis-sqlite test-travis-mysql test-travis-pg
|
||||
test-travis-all: jshint test-travis-sqlite test-travis-mysql test-travis-pg
|
||||
|
||||
dev:
|
||||
@NODE_ENV=development $(BIN) node_modules/.bin/node-dev --harmony dispatch.js
|
||||
@NODE_ENV=development node node_modules/.bin/node-dev dispatch.js
|
||||
|
||||
contributors: install
|
||||
contributors:
|
||||
@node_modules/.bin/contributors -f plain -o AUTHORS
|
||||
|
||||
autod: install
|
||||
autod:
|
||||
@node_modules/.bin/autod -w \
|
||||
--prefix "~" \
|
||||
--exclude public,view,docs,backup,coverage \
|
||||
--dep mysql \
|
||||
--keep should,supertest,should-http,chunkstream,mm,pedding
|
||||
@$(MAKE) install
|
||||
|
||||
.PHONY: test
|
||||
|
||||
14
README.md
14
README.md
@@ -3,18 +3,21 @@ cnpmjs.org
|
||||
|
||||
[![NPM version][npm-image]][npm-url]
|
||||
[![build status][travis-image]][travis-url]
|
||||
[![Test coverage][cov-image]][cov-url]
|
||||
[![Test coverage][codecov-image]][codecov-url]
|
||||
[![David deps][david-image]][david-url]
|
||||
[![Known Vulnerabilities][snyk-image]][snyk-url]
|
||||
[![npm download][download-image]][download-url]
|
||||
|
||||
[npm-image]: http://cnpmjs.org/badge/v/cnpmjs.org.svg?style=flat-square
|
||||
[npm-url]: http://cnpmjs.org/package/cnpmjs.org
|
||||
[travis-image]: https://img.shields.io/travis/cnpm/cnpmjs.org.svg?style=flat-square
|
||||
[travis-url]: https://travis-ci.org/cnpm/cnpmjs.org
|
||||
[cov-image]: http://codecov.io/github/cnpm/cnpmjs.org/coverage.svg?branch=master
|
||||
[cov-url]: http://codecov.io/github/cnpm/cnpmjs.org?branch=master
|
||||
[codecov-image]: https://codecov.io/gh/cnpm/cnpmjs.org/branch/master/graph/badge.svg
|
||||
[codecov-url]: https://codecov.io/gh/cnpm/cnpmjs.org
|
||||
[david-image]: https://img.shields.io/david/cnpm/cnpmjs.org.svg?style=flat-square
|
||||
[david-url]: https://david-dm.org/cnpm/cnpmjs.org
|
||||
[snyk-image]: https://snyk.io/test/npm/cnpmjs.org/badge.svg?style=flat-square
|
||||
[snyk-url]: https://snyk.io/test/npm/cnpmjs.org
|
||||
[download-image]: https://img.shields.io/npm/dm/cnpmjs.org.svg?style=flat-square
|
||||
[download-url]: https://npmjs.org/package/cnpmjs.org
|
||||
|
||||
@@ -71,7 +74,7 @@ as well as [New features in 2.x](https://github.com/cnpm/cnpmjs.org/wiki/New-fea
|
||||
|
||||
### Dependencies
|
||||
|
||||
* [node](http://nodejs.org) >=0.11.12, use `--harmony`
|
||||
* [node](http://nodejs.org) >= 4.3.1
|
||||
* Databases: only required one type
|
||||
* [sqlite3](https://npm.taobao.org/package/sqlite3) >= 3.0.2, we use `sqlite3` by default
|
||||
* [MySQL](http://dev.mysql.com/downloads/) >= 0.5.0, include `mysqld` and `mysql cli`. I test on `mysql@5.6.16`.
|
||||
@@ -111,7 +114,8 @@ Tips: make sure your code is following the [node-style-guide](https://github.com
|
||||
|
||||
## Sponsors
|
||||
|
||||
- [](http://www.ucloud.cn?sem=sdk-CNPMJS)
|
||||
- [](http://click.aliyun.com/m/4288/) (2016.2 - now)
|
||||
- [](http://www.ucloud.cn?sem=sdk-CNPMJS) (2015.3 - 2016.3)
|
||||
|
||||
## License
|
||||
|
||||
|
||||
@@ -1,62 +1,56 @@
|
||||
/**!
|
||||
* cnpmjs.org - common/logger.js
|
||||
*
|
||||
* Copyright(c) cnpmjs.org and other contributors.
|
||||
* MIT Licensed
|
||||
*
|
||||
* Authors:
|
||||
* dead_horse <dead_horse@qq.com> (http://deadhorse.me)
|
||||
* fengmk2 <fengmk2@gmail.com> (http://fengmk2.github.com)
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* Module dependencies.
|
||||
*/
|
||||
const debug = require('debug')('cnpmjs.org:logger');
|
||||
const formater = require('error-formater');
|
||||
const Logger = require('mini-logger');
|
||||
const utility = require('utility');
|
||||
const util = require('util');
|
||||
const os = require('os');
|
||||
const config = require('../config');
|
||||
const mail = require('./mail');
|
||||
|
||||
var formater = require('error-formater');
|
||||
var Logger = require('mini-logger');
|
||||
var utility = require('utility');
|
||||
var util = require('util');
|
||||
var config = require('../config');
|
||||
var mail = require('./mail');
|
||||
const isTEST = process.env.NODE_ENV === 'test';
|
||||
const categories = ['sync_info', 'sync_error'];
|
||||
|
||||
var isTEST = process.env.NODE_ENV === 'test';
|
||||
var categories = ['sync_info', 'sync_error'];
|
||||
|
||||
var logger = module.exports = Logger({
|
||||
const logger = module.exports = Logger({
|
||||
categories: categories,
|
||||
dir: config.logdir,
|
||||
duration: '1d',
|
||||
format: '[{category}.]YYYY-MM-DD[.log]',
|
||||
stdout: config.debug && !isTEST,
|
||||
errorFormater: errorFormater
|
||||
errorFormater: errorFormater,
|
||||
seperator: os.EOL,
|
||||
});
|
||||
|
||||
var to = [];
|
||||
const to = [];
|
||||
for (var user in config.admins) {
|
||||
to.push(config.admins[user]);
|
||||
}
|
||||
|
||||
function errorFormater(err) {
|
||||
var msg = formater.both(err);
|
||||
const msg = formater.both(err);
|
||||
mail.error(to, msg.json.name, msg.text);
|
||||
return msg.text;
|
||||
}
|
||||
|
||||
logger.syncInfo = function () {
|
||||
var args = [].slice.call(arguments);
|
||||
const args = [].slice.call(arguments);
|
||||
if (typeof args[0] === 'string') {
|
||||
args[0] = util.format('[%s][%s] ', utility.logDate(), process.pid) + args[0];
|
||||
}
|
||||
if (debug.enabled) {
|
||||
debug.apply(debug, args);
|
||||
}
|
||||
logger.sync_info.apply(logger, args);
|
||||
};
|
||||
|
||||
logger.syncError =function () {
|
||||
var args = [].slice.call(arguments);
|
||||
const args = [].slice.call(arguments);
|
||||
if (typeof args[0] === 'string') {
|
||||
args[0] = util.format('[%s][%s] ', utility.logDate(), process.pid) + args[0];
|
||||
}
|
||||
if (debug.enabled) {
|
||||
debug.apply(debug, args);
|
||||
}
|
||||
logger.sync_error.apply(logger, arguments);
|
||||
};
|
||||
|
||||
@@ -1,18 +1,5 @@
|
||||
/**!
|
||||
* Copyright(c) cnpmjs.org and other contributors.
|
||||
* MIT Licensed
|
||||
*
|
||||
* Authors:
|
||||
* dead_horse <dead_horse@qq.com>
|
||||
* fengmk2 <m@fengmk2.com> (http://fengmk2.com)
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* Module dependencies.
|
||||
*/
|
||||
|
||||
var mkdirp = require('mkdirp');
|
||||
var copy = require('copy-to');
|
||||
var path = require('path');
|
||||
@@ -26,6 +13,7 @@ var dataDir = path.join(process.env.HOME || root, '.cnpmjs.org');
|
||||
|
||||
var config = {
|
||||
version: version,
|
||||
dataDir: dataDir,
|
||||
|
||||
/**
|
||||
* Cluster mode
|
||||
@@ -93,7 +81,7 @@ var config = {
|
||||
}
|
||||
},
|
||||
|
||||
logoURL: '//ww4.sinaimg.cn/large/69c1d4acgw1ebfly5kjlij208202oglr.jpg', // cnpm logo image url
|
||||
logoURL: 'https://os.alipayobjects.com/rmsportal/oygxuIUkkrRccUz.jpg', // cnpm logo image url
|
||||
adBanner: '',
|
||||
customReadmeFile: '', // you can use your custom readme file instead the cnpm one
|
||||
customFooter: '', // you can add copyright and site total script html here
|
||||
@@ -209,11 +197,17 @@ var config = {
|
||||
// sync devDependencies or not, default is false
|
||||
syncDevDependencies: false,
|
||||
|
||||
// changes streaming sync
|
||||
syncChangesStream: false,
|
||||
handleSyncRegistry: 'http://127.0.0.1:7001',
|
||||
|
||||
// badge subject on http://shields.io/
|
||||
badgePrefixURL: 'https://img.shields.io/badge',
|
||||
badgeSubject: 'cnpm',
|
||||
|
||||
// custom user service, @see https://github.com/cnpm/cnpmjs.org/wiki/Use-Your-Own-User-Authorization
|
||||
// when you not intend to ingegrate with your company's user system, then use null, it would
|
||||
// use the default cnpm user system
|
||||
userService: null,
|
||||
|
||||
// always-auth https://docs.npmjs.com/misc/config#always-auth
|
||||
|
||||
@@ -107,10 +107,12 @@ defer.setInterval(function* () {
|
||||
try {
|
||||
yield* downloadTotalService.plusModuleTotal({ name: name, date: date, count: count });
|
||||
} catch (err) {
|
||||
err.message += '; name: ' + name + ', count: ' + count + ', date: ' + date;
|
||||
logger.error(err);
|
||||
if (err.name !== 'SequelizeUniqueConstraintError') {
|
||||
err.message += '; name: ' + name + ', count: ' + count + ', date: ' + date;
|
||||
logger.error(err);
|
||||
}
|
||||
// save back to _downloads, try again next time
|
||||
_downloads[name] = (_downloads[name] || 0) + count;
|
||||
}
|
||||
}
|
||||
}, 5000);
|
||||
}, 5000 + Math.ceil(Math.random() * 1000));
|
||||
|
||||
@@ -1,11 +1,3 @@
|
||||
/**
|
||||
* Copyright(c) cnpm and other contributors.
|
||||
* MIT Licensed
|
||||
*
|
||||
* Authors:
|
||||
* fengmk2 <fengmk2@gmail.com> (http://fengmk2.com)
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
@@ -99,7 +91,7 @@ module.exports = function* list() {
|
||||
this.status = 404;
|
||||
this.body = {
|
||||
error: 'not_found',
|
||||
reason: 'document not found'
|
||||
reason: 'document not found',
|
||||
};
|
||||
return;
|
||||
}
|
||||
@@ -198,5 +190,5 @@ module.exports = function* list() {
|
||||
info.license = pkg.license;
|
||||
|
||||
debug('show module %s: %s, latest: %s', orginalName, rev, latestMod.version);
|
||||
this.body = info;
|
||||
this.jsonp = info;
|
||||
};
|
||||
|
||||
@@ -30,13 +30,20 @@ var config = require('../../../config');
|
||||
module.exports = function* show() {
|
||||
var name = this.params.name || this.params[0];
|
||||
var tag = this.params.version || this.params[1];
|
||||
if (tag === '*') {
|
||||
tag = 'latest';
|
||||
}
|
||||
var version = semver.valid(tag);
|
||||
var range = semver.validRange(tag);
|
||||
var mod;
|
||||
if (version) {
|
||||
mod = yield* packageService.getModule(name, version);
|
||||
mod = yield packageService.getModule(name, version);
|
||||
} else if (range) {
|
||||
mod = yield packageService.getModuleByRange(name, range);
|
||||
} else {
|
||||
mod = yield* packageService.getModuleByTag(name, tag);
|
||||
mod = yield packageService.getModuleByTag(name, tag);
|
||||
}
|
||||
|
||||
if (mod) {
|
||||
setDownloadURL(mod.package, this);
|
||||
mod.package._cnpm_publish_time = mod.publish_time;
|
||||
@@ -44,14 +51,14 @@ module.exports = function* show() {
|
||||
if (maintainers.length > 0) {
|
||||
mod.package.maintainers = maintainers;
|
||||
}
|
||||
this.body = mod.package;
|
||||
this.jsonp = mod.package;
|
||||
return;
|
||||
}
|
||||
|
||||
// if not fond, sync from source registry
|
||||
if (!this.allowSync) {
|
||||
this.status = 404;
|
||||
this.body = {
|
||||
this.jsonp = {
|
||||
error: 'not exist',
|
||||
reason: 'version not found: ' + version
|
||||
};
|
||||
@@ -59,7 +66,7 @@ module.exports = function* show() {
|
||||
}
|
||||
|
||||
// start sync
|
||||
var logId = yield* SyncModuleWorker.sync(name, 'sync-by-install');
|
||||
var logId = yield SyncModuleWorker.sync(name, 'sync-by-install');
|
||||
debug('start sync %s, get log id %s', name, logId);
|
||||
|
||||
this.redirect(config.officialNpmRegistry + this.url);
|
||||
|
||||
@@ -1,18 +1,5 @@
|
||||
/**!
|
||||
* Copyright(c) cnpmjs.org and other contributors.
|
||||
* MIT Licensed
|
||||
*
|
||||
* Authors:
|
||||
* fengmk2 <fengmk2@gmail.com> (http://fengmk2.com)
|
||||
* dead_horse <dead_horse@qq.com> (http://deadhorse.me)
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* Module dependencies.
|
||||
*/
|
||||
|
||||
var debug = require('debug')('cnpmjs.org:sync_module_worker');
|
||||
var co = require('co');
|
||||
var gather = require('co-gather');
|
||||
@@ -38,7 +25,11 @@ var User = require('../models').User;
|
||||
var os = require('os');
|
||||
|
||||
var USER_AGENT = 'sync.cnpmjs.org/' + config.version +
|
||||
' hostname/' + os.hostname() + ' ' + urllib.USER_AGENT;
|
||||
' hostname/' + os.hostname() +
|
||||
' syncModel/' + config.syncModel +
|
||||
' syncInterval/' + config.syncInterval +
|
||||
' syncConcurrency/' + config.syncConcurrency +
|
||||
' ' + urllib.USER_AGENT;
|
||||
|
||||
function SyncModuleWorker(options) {
|
||||
EventEmitter.call(this);
|
||||
@@ -68,6 +59,7 @@ function SyncModuleWorker(options) {
|
||||
|
||||
this.successes = [];
|
||||
this.fails = [];
|
||||
this.updates = [];
|
||||
}
|
||||
|
||||
util.inherits(SyncModuleWorker, EventEmitter);
|
||||
@@ -136,7 +128,7 @@ SyncModuleWorker.prototype.start = function () {
|
||||
// sync upstream
|
||||
if (that.syncUpstreamFirst) {
|
||||
try {
|
||||
yield* that.syncUpstream(that.startName);
|
||||
yield that.syncUpstream(that.startName);
|
||||
} catch (err) {
|
||||
logger.error(err);
|
||||
}
|
||||
@@ -189,7 +181,7 @@ SyncModuleWorker.prototype._doneOne = function* (concurrencyId, name, success) {
|
||||
var that = this;
|
||||
// relase the stack: https://github.com/cnpm/cnpmjs.org/issues/328
|
||||
defer.setImmediate(function* () {
|
||||
yield* that.next(concurrencyId);
|
||||
yield that.next(concurrencyId);
|
||||
});
|
||||
};
|
||||
|
||||
@@ -309,13 +301,13 @@ SyncModuleWorker.prototype.next = function* (concurrencyId) {
|
||||
if (common.isPrivateScopedPackage(name)) {
|
||||
this.log('[c#%d] [%s] ignore sync private scoped %j package',
|
||||
concurrencyId, name, config.scopes);
|
||||
yield* this._doneOne(concurrencyId, name, true);
|
||||
yield this._doneOne(concurrencyId, name, true);
|
||||
return;
|
||||
}
|
||||
|
||||
// get from npm
|
||||
try {
|
||||
var result = yield* npmSerivce.request('/' + name.replace('/', '%2f'));
|
||||
var result = yield npmSerivce.request('/' + name.replace('/', '%2f'));
|
||||
pkg = result.data;
|
||||
status = result.status;
|
||||
} catch (err) {
|
||||
@@ -342,7 +334,7 @@ SyncModuleWorker.prototype.next = function* (concurrencyId) {
|
||||
if (!pkg) {
|
||||
that.log('[c#%s] [error] [%s] get package error: package not exists, status: %s',
|
||||
concurrencyId, name, status);
|
||||
yield* that._doneOne(concurrencyId, name, true);
|
||||
yield that._doneOne(concurrencyId, name, true);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -350,31 +342,36 @@ SyncModuleWorker.prototype.next = function* (concurrencyId) {
|
||||
|
||||
if (unpublishedInfo) {
|
||||
try {
|
||||
yield* that._unpublished(name, unpublishedInfo);
|
||||
yield that._unpublished(name, unpublishedInfo);
|
||||
} catch (err) {
|
||||
that.log('[c#%s] [error] [%s] sync error: %s', concurrencyId, name, err.stack);
|
||||
yield* that._doneOne(concurrencyId, name, false);
|
||||
yield that._doneOne(concurrencyId, name, false);
|
||||
return;
|
||||
}
|
||||
return yield* that._doneOne(concurrencyId, name, true);
|
||||
return yield that._doneOne(concurrencyId, name, true);
|
||||
}
|
||||
|
||||
var versions;
|
||||
try {
|
||||
versions = yield* that._sync(name, pkg);
|
||||
versions = yield that._sync(name, pkg);
|
||||
} catch (err) {
|
||||
that.log('[c#%s] [error] [%s] sync error: %s', concurrencyId, name, err.stack);
|
||||
yield* that._doneOne(concurrencyId, name, false);
|
||||
yield that._doneOne(concurrencyId, name, false);
|
||||
return;
|
||||
}
|
||||
|
||||
// has new version
|
||||
if (versions.length > 0) {
|
||||
that.updates.push(name);
|
||||
}
|
||||
|
||||
this.log('[c#%d] [%s] synced success, %d versions: %s',
|
||||
concurrencyId, name, versions.length, versions.join(', '));
|
||||
yield* this._doneOne(concurrencyId, name, true);
|
||||
yield this._doneOne(concurrencyId, name, true);
|
||||
};
|
||||
|
||||
function* _listStarUsers(modName) {
|
||||
var users = yield* packageService.listStarUserNames(modName);
|
||||
var users = yield packageService.listStarUserNames(modName);
|
||||
var userMap = {};
|
||||
users.forEach(function (user) {
|
||||
userMap[user] = true;
|
||||
@@ -672,7 +669,7 @@ SyncModuleWorker.prototype._sync = function* (name, pkg) {
|
||||
continue;
|
||||
}
|
||||
try {
|
||||
yield* that._syncOneVersion(index, syncModule);
|
||||
yield that._syncOneVersion(index, syncModule);
|
||||
syncedVersionNames.push(syncModule.version);
|
||||
} catch (err) {
|
||||
that.log(' [%s:%d] sync error, version: %s, %s: %s',
|
||||
@@ -932,7 +929,7 @@ SyncModuleWorker.prototype._syncOneVersion = function *(versionIndex, sourcePack
|
||||
}
|
||||
|
||||
// add module dependence
|
||||
yield* packageService.addDependencies(sourcePackage.name, dependencies);
|
||||
yield packageService.addDependencies(sourcePackage.name, dependencies);
|
||||
|
||||
var shasum = crypto.createHash('sha1');
|
||||
var dataSize = 0;
|
||||
@@ -954,6 +951,7 @@ SyncModuleWorker.prototype._syncOneVersion = function *(versionIndex, sourcePack
|
||||
var err = new Error('Download ' + downurl + ' fail, status: ' + statusCode);
|
||||
err.name = 'DownloadTarballError';
|
||||
err.data = sourcePackage;
|
||||
logger.syncInfo('[sync_module_worker] %s', err.message);
|
||||
throw err;
|
||||
}
|
||||
|
||||
@@ -970,6 +968,7 @@ SyncModuleWorker.prototype._syncOneVersion = function *(versionIndex, sourcePack
|
||||
var err = new Error('Download ' + downurl + ' file size is zero');
|
||||
err.name = 'DownloadTarballSizeZeroError';
|
||||
err.data = sourcePackage;
|
||||
logger.syncInfo('[sync_module_worker] %s', err.message);
|
||||
throw err;
|
||||
}
|
||||
|
||||
@@ -980,6 +979,7 @@ SyncModuleWorker.prototype._syncOneVersion = function *(versionIndex, sourcePack
|
||||
' not match ' + sourcePackage.dist.shasum);
|
||||
err.name = 'DownloadTarballShasumError';
|
||||
err.data = sourcePackage;
|
||||
logger.syncInfo('[sync_module_worker] %s', err.message);
|
||||
throw err;
|
||||
}
|
||||
|
||||
@@ -998,8 +998,9 @@ SyncModuleWorker.prototype._syncOneVersion = function *(versionIndex, sourcePack
|
||||
throw err;
|
||||
}
|
||||
logger.syncInfo('[sync_module_worker] uploaded, saving %j to database', result);
|
||||
var r = yield *afterUpload(result);
|
||||
logger.syncInfo('[sync_module_worker] sync %s@%s done!', sourcePackage.name, sourcePackage.version);
|
||||
var r = yield afterUpload(result);
|
||||
logger.syncInfo('[sync_module_worker] sync %s@%s done!',
|
||||
sourcePackage.name, sourcePackage.version);
|
||||
return r;
|
||||
} finally {
|
||||
// remove tmp file whatever
|
||||
@@ -1043,7 +1044,7 @@ SyncModuleWorker.prototype._syncOneVersion = function *(versionIndex, sourcePack
|
||||
}
|
||||
|
||||
mod.package.dist = dist;
|
||||
var r = yield* packageService.saveModule(mod);
|
||||
var r = yield packageService.saveModule(mod);
|
||||
|
||||
that.log(' [%s:%s] done, insertId: %s, author: %s, version: %s, '
|
||||
+ 'size: %d, publish_time: %j, publish on cnpm: %s',
|
||||
|
||||
@@ -1,18 +1,5 @@
|
||||
/**!
|
||||
* Copyright(c) cnpm and other contributors.
|
||||
* MIT Licensed
|
||||
*
|
||||
* Authors:
|
||||
* fengmk2 <fengmk2@gmail.com> (http://fengmk2.com)
|
||||
* dead_horse <dead_horse@qq.com> (http://deadhorse.me)
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* Module dependencies.
|
||||
*/
|
||||
|
||||
const Total = require('../services/total');
|
||||
const version = require('../package.json').version;
|
||||
const config = require('../config');
|
||||
|
||||
@@ -1,18 +1,5 @@
|
||||
/**!
|
||||
* Copyright(c) cnpm and other contributors.
|
||||
* MIT Licensed
|
||||
*
|
||||
* Authors:
|
||||
* dead_horse <dead_horse@qq.com> (http://deadhorse.me)
|
||||
* fengmk2 <fengmk2@gmail.com> (http://fengmk2.com)
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* Module dependencies.
|
||||
*/
|
||||
|
||||
var debug = require('debug')('cnpmjs.org:controllers:web:package:show');
|
||||
var bytes = require('bytes');
|
||||
var giturl = require('giturl');
|
||||
@@ -183,6 +170,17 @@ module.exports = function* show(next) {
|
||||
}
|
||||
}
|
||||
|
||||
if (pkg._publish_on_cnpm) {
|
||||
pkg.isPrivate = true;
|
||||
} else {
|
||||
pkg.isPrivate = false;
|
||||
// add security check badge
|
||||
pkg.snyk = {
|
||||
badge: `https://snyk.io/test/npm/${pkg.name}/badge.svg?style=flat-square`,
|
||||
url: `https://snyk.io/test/npm/${pkg.name}`,
|
||||
};
|
||||
}
|
||||
|
||||
yield this.render('package', {
|
||||
title: 'Package - ' + pkg.name,
|
||||
package: pkg,
|
||||
|
||||
13
dispatch.js
13
dispatch.js
@@ -1,18 +1,5 @@
|
||||
/**!
|
||||
* Copyright(c) cnpmjs.org and other contributors.
|
||||
* MIT Licensed
|
||||
*
|
||||
* Authors:
|
||||
* dead_horse <dead_horse@qq.com>
|
||||
* fengmk2 <fengmk2@gmail.com> (http://fengmk2.com)
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* Module dependencies.
|
||||
*/
|
||||
|
||||
var childProcess = require('child_process');
|
||||
var path = require('path');
|
||||
var util = require('util');
|
||||
|
||||
BIN
docs/network.png
Normal file
BIN
docs/network.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 123 KiB |
98
docs/network.puml
Normal file
98
docs/network.puml
Normal file
@@ -0,0 +1,98 @@
|
||||
@startuml
|
||||
|
||||
title cnpmjs.org, npm.taobao.org Network
|
||||
|
||||
node "China User" {
|
||||
[cnpm cli]
|
||||
}
|
||||
|
||||
node "OSS: aliyuncs.com" {
|
||||
[tnpm-hz.oss-cn-hangzhou]
|
||||
}
|
||||
|
||||
node "SLB: 114.55.80.225 Hangzhou" {
|
||||
[npm.taobao.org]
|
||||
[registry.npm.taobao.org]
|
||||
}
|
||||
|
||||
node "npmtaobao3: 121.41.*" {
|
||||
[nginx 5]
|
||||
[registry 5]
|
||||
[web 5]
|
||||
[syncer 5]
|
||||
}
|
||||
|
||||
node "npmtaobao4: 120.26.*" {
|
||||
[nginx 6]
|
||||
[registry 6]
|
||||
[web 6]
|
||||
}
|
||||
|
||||
node "cnpm6: 47.88.189.193 Singapore" {
|
||||
[cnpmjs.org]
|
||||
[r.cnpmjs.org]
|
||||
[nginx 7]
|
||||
[registry 7]
|
||||
[web 7]
|
||||
[syncer 7]
|
||||
}
|
||||
|
||||
node "Aliyun CDN" {
|
||||
[cdn.npm.taobao.org]
|
||||
}
|
||||
|
||||
node "qiniu CDN" {
|
||||
[cnpmjs.up.qiniu.com]
|
||||
[dn-cnpm.qbox.me]
|
||||
}
|
||||
|
||||
database "taobaonpm DB" {
|
||||
[rds2860*.mysql.rds.aliyuncs.com]
|
||||
}
|
||||
|
||||
database "cnpm DB" {
|
||||
[rdsqiz*.mysql.rds.aliyuncs.com]
|
||||
}
|
||||
|
||||
node "npmjs.com" {
|
||||
[registry.npmjs.com]
|
||||
[www.npmjs.com]
|
||||
}
|
||||
|
||||
[cnpm cli] -down-> [registry.npm.taobao.org]: Read, Write
|
||||
[cnpm cli] -down-> [cdn.npm.taobao.org]: Read tgz
|
||||
[cnpm cli] -down-> [npm.taobao.org]: "Read /mirrors"
|
||||
|
||||
[registry.npm.taobao.org] -down-> [nginx 5]
|
||||
[nginx 5] -down-> [registry 5]
|
||||
[npm.taobao.org] -down-> [nginx 5]
|
||||
[nginx 5] -down-> [web 5]
|
||||
[registry.npm.taobao.org] -down-> [nginx 6]
|
||||
[nginx 6] -down-> [registry 6]
|
||||
[npm.taobao.org] -down-> [nginx 6]
|
||||
[nginx 6] -down-> [web 6]
|
||||
|
||||
[registry 5] -down-> [rds2860*.mysql.rds.aliyuncs.com]: Read, Write
|
||||
[web 5] -down-> [rds2860*.mysql.rds.aliyuncs.com]: Read
|
||||
[syncer 5] -down-> [rds2860*.mysql.rds.aliyuncs.com]: Read, Write
|
||||
[syncer 5] -down-> [tnpm-hz.oss-cn-hangzhou]: Write
|
||||
[syncer 5] -> [r.cnpmjs.org]: Read
|
||||
[syncer 5] -> [dn-cnpm.qbox.me]: Read tgz
|
||||
[registry 6] -down-> [rds2860*.mysql.rds.aliyuncs.com]: Read, Write
|
||||
[web 6] -down-> [rds2860*.mysql.rds.aliyuncs.com]: Read
|
||||
|
||||
[cnpmjs.org] -down-> [nginx 7]
|
||||
[nginx 7] -down-> [registry 7]
|
||||
[r.cnpmjs.org] -down-> [nginx 7]
|
||||
[nginx 7] -down-> [web 7]
|
||||
|
||||
[registry 7] -down-> [rdsqiz*.mysql.rds.aliyuncs.com]: Read, Write
|
||||
[web 7] -down-> [rdsqiz*.mysql.rds.aliyuncs.com]: Read
|
||||
[syncer 7] -down-> [rdsqiz*.mysql.rds.aliyuncs.com]: Read, Write
|
||||
[syncer 7] -down-> [cnpmjs.up.qiniu.com]: Write
|
||||
[syncer 7] -down-> [registry.npmjs.com]: Read
|
||||
|
||||
[cdn.npm.taobao.org] -down-> [tnpm-hz.oss-cn-hangzhou]: Read
|
||||
[dn-cnpm.qbox.me] -down-> [cnpmjs.up.qiniu.com]: Read
|
||||
|
||||
@enduml
|
||||
@@ -1,115 +0,0 @@
|
||||
# Install & Get Started
|
||||
|
||||
## Deps
|
||||
|
||||
* MySQL Server: http://db4free.net/
|
||||
* qiniu CDN: http://www.qiniu.com/
|
||||
* redis session: https://garantiadata.com Support 24MB free spaces.
|
||||
* node: >=0.10.21
|
||||
|
||||
## Clone
|
||||
|
||||
```bash
|
||||
$ git clone git://github.com/fengmk2/cnpmjs.org.git $HOME/cnpmjs.org
|
||||
$ cd $HOME/cnpmjs.org
|
||||
```
|
||||
|
||||
## Create your `config.js`
|
||||
|
||||
```bash
|
||||
$ vim config/config.js
|
||||
```
|
||||
|
||||
`config.js` content sample:
|
||||
|
||||
```js
|
||||
module.exports = {
|
||||
debug: false,
|
||||
enableCluster: true, // enable cluster mode
|
||||
logdir: 'your application log dir',
|
||||
mysqlServers: [
|
||||
{
|
||||
host: 'your mysql host',
|
||||
port: 3306,
|
||||
user: 'yourname',
|
||||
password: 'your password'
|
||||
}
|
||||
],
|
||||
mysqlDatabase: 'cnpmjs',
|
||||
redis: {
|
||||
host: 'your redist host',
|
||||
port: 6379,
|
||||
},
|
||||
qn: {
|
||||
accessKey: "your qiniu appkey",
|
||||
secretKey: "your secret key",
|
||||
bucket: "foobucket",
|
||||
domain: "http://foobucket.u.qiniudn.com"
|
||||
},
|
||||
nfs: null, // you can set a nfs to replace qiniu cdn
|
||||
enablePrivate: true, // enable private mode, only admin can publish, other use just can sync package from source npm
|
||||
admins: {
|
||||
admin: 'admin@cnpmjs.org',
|
||||
},
|
||||
syncModel: 'exist', //`all` sync all packages, `exist` only update exist packages, `none` do nothing
|
||||
};
|
||||
```
|
||||
|
||||
## Create MySQL Database and Tables
|
||||
|
||||
```bash
|
||||
$ mysql -u yourname -p
|
||||
|
||||
mysql> use cnpmjs;
|
||||
mysql> source docs/db.sql
|
||||
```
|
||||
|
||||
## Use your own CDN
|
||||
If you wan to use your own CDN instead of qiniu. Just look at `common/qnfs.js` and implement the interface like it, then pass it by set `config.nfs`.
|
||||
|
||||
## npm install
|
||||
|
||||
```bash
|
||||
$ npm install
|
||||
```
|
||||
|
||||
## start
|
||||
|
||||
```bash
|
||||
$ ./bin/nodejsctl start
|
||||
|
||||
Starting cnpmjs.org ...
|
||||
Start nodejs success. PID=27175
|
||||
```
|
||||
|
||||
## open registry and web
|
||||
|
||||
```bash
|
||||
# registry
|
||||
$ open http://localhost:7001
|
||||
# web
|
||||
$ open http://localhost:7002
|
||||
```
|
||||
|
||||
## use cnpm cli with your own registry
|
||||
You do not need to write another command line tool with your own registry,
|
||||
just alias [cnpm](http://github.com/fengmk2/cnpm), then you can get a npm client for you own registry.
|
||||
|
||||
```
|
||||
# install cnpm first
|
||||
npm install -g cnpm
|
||||
|
||||
# then alias lnpm to cnpm, but change config to your own registry
|
||||
alias lnpm='cnpm --registry=http://localhost:7001\
|
||||
--registryweb=http://localhost:7002\
|
||||
--cache=$HOME/.npm/.cache/lnpm\
|
||||
--disturl=http://cnpmjs.org/dist\
|
||||
--userconfig=$HOME/.lnpmrc'
|
||||
|
||||
#or put this in .zshrc or .bashrc
|
||||
echo "#lnpm alias\nalias lnpm='cnpm --registry=http://localhost:7001\
|
||||
--registryweb=http://localhost:7002\
|
||||
--cache=$HOME/.npm/.cache/lnpm\
|
||||
--disturl=http://cnpmjs.org/dist\
|
||||
--userconfig=$HOME/.lnpmrc'" >> $HOME/.zshrc && source $HOME/.zshrc
|
||||
```
|
||||
@@ -4,10 +4,10 @@ So `cnpm` is meaning: **Company npm**.
|
||||
|
||||
## Registry
|
||||
|
||||
- Our public registry: [r.cnpmjs.org](//r.cnpmjs.org), syncing from [registry.npmjs.org](//registry.npmjs.org)
|
||||
- Our public registry: [r.cnpmjs.org](https://r.cnpmjs.org), syncing from [registry.npmjs.com](https://registry.npmjs.com)
|
||||
- [cnpmjs.org](/) version: <span id="app-version"></span>
|
||||
- [Node.js](https://nodejs.org) version: <span id="node-version"></span>
|
||||
- For developers behind the GFW, please visit [the Chinese mirror](https://npm.taobao.org). 中国用户请访问[国内镜像站点](https://npm.taobao.org/)。
|
||||
- For developers in China, please visit [the China mirror](https://npm.taobao.org). 中国用户请访问[国内镜像站点](https://npm.taobao.org)。
|
||||
|
||||
<div class="ant-table">
|
||||
<table class="downloads">
|
||||
@@ -65,7 +65,7 @@ Default style is `flat-square`.
|
||||
|
||||
### Version
|
||||
|
||||
Badge URL: `http://cnpmjs.org/badge/v/cnpmjs.org.svg` 
|
||||
Badge URL: `https://cnpmjs.org/badge/v/cnpmjs.org.svg` 
|
||||
|
||||
* `<0.1.0 & >=0.0.0`: 
|
||||
* `<1.0.0 & >=0.1.0`: 
|
||||
@@ -73,34 +73,34 @@ Badge URL: `http://cnpmjs.org/badge/v/cnpmjs.org.svg` 
|
||||
Badge URL: `https://cnpmjs.org/badge/d/cnpmjs.org.svg` 
|
||||
|
||||
## Usage
|
||||
|
||||
use our npm client [cnpm](https://github.com/cnpm/cnpm)(More suitable with cnpmjs.org and gzip support), you can get our client through npm:
|
||||
|
||||
```bash
|
||||
$ npm install -g cnpm --registry=http://registry.npm.taobao.org
|
||||
$ npm install -g cnpm --registry=https://registry.npm.taobao.org
|
||||
```
|
||||
|
||||
Or you can alias NPM to use it:
|
||||
|
||||
```bash
|
||||
alias cnpm="npm --registry=http://registry.npm.taobao.org \
|
||||
alias cnpm="npm --registry=https://registry.npm.taobao.org \
|
||||
--cache=$HOME/.npm/.cache/cnpm \
|
||||
--disturl=http://registry.npm.taobao.org/mirrors/node \
|
||||
--disturl=https://npm.taobao.org/mirrors/node \
|
||||
--userconfig=$HOME/.cnpmrc"
|
||||
|
||||
#Or alias it in .bashrc or .zshrc
|
||||
$ echo '\n#alias for cnpm\nalias cnpm="npm --registry=http://registry.npm.taobao.org \
|
||||
$ echo '\n#alias for cnpm\nalias cnpm="npm --registry=https://registry.npm.taobao.org \
|
||||
--cache=$HOME/.npm/.cache/cnpm \
|
||||
--disturl=http://registry.npm.taobao.org/mirrors/node \
|
||||
--disturl=https://npm.taobao.org/mirrors/node \
|
||||
--userconfig=$HOME/.cnpmrc"' >> ~/.zshrc && source ~/.zshrc
|
||||
```
|
||||
|
||||
### install
|
||||
|
||||
Install package from [r.cnpmjs.org](//r.cnpmjs.org). When installing a package or version does not exist, it will try to install from the official registry([registry.npmjs.org](//registry.npmjs.org)), and sync this package to cnpm in the backend.
|
||||
Install package from [r.cnpmjs.org](//r.cnpmjs.org). When installing a package or version does not exist, it will try to install from the official registry([registry.npmjs.org](https://registry.npmjs.org)), and sync this package to cnpm in the backend.
|
||||
|
||||
```bash
|
||||
$ cnpm install [name]
|
||||
@@ -145,10 +145,11 @@ $ cnpm info cnpm
|
||||
|
||||
Release [History](/history).
|
||||
|
||||
## npm and cnpm relation
|
||||
## npmjs.org, cnpmjs.org and npm.taobao.org relation
|
||||
|
||||

|
||||
[](https://dn-cnpm.qbox.me/network.png)
|
||||
|
||||
## Sponsors
|
||||
|
||||
- [](http://www.ucloud.cn?sem=sdk-CNPMJS)
|
||||
- [](http://click.aliyun.com/m/4288/) (2016.2 - now)
|
||||
- [](http://www.ucloud.cn?sem=sdk-CNPMJS) (2015.3 - 2016.3)
|
||||
|
||||
@@ -34,13 +34,14 @@ module.exports = function () {
|
||||
return yield* unauthorized.call(this, next);
|
||||
}
|
||||
|
||||
authorization = new Buffer(authorization, 'base64').toString().split(':');
|
||||
if (authorization.length !== 2) {
|
||||
return yield* unauthorized.call(this, next);
|
||||
authorization = new Buffer(authorization, 'base64').toString();
|
||||
var pos = authorization.indexOf(':');
|
||||
if (pos === -1) {
|
||||
return yield* unauthorized.call(this, next);
|
||||
}
|
||||
|
||||
var username = authorization[0];
|
||||
var password = authorization[1];
|
||||
var username = authorization.slice(0, pos);
|
||||
var password = authorization.slice(pos + 1);
|
||||
|
||||
var row;
|
||||
try {
|
||||
|
||||
@@ -1,12 +1,3 @@
|
||||
/**!
|
||||
* cnpmjs.org - middleware/proxy_to_npm.js
|
||||
*
|
||||
* Copyright(c) Alibaba Group Holding Limited.
|
||||
*
|
||||
* Authors:
|
||||
* 苏千 <suqian.yf@alipay.com> (http://fengmk2.com)
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
@@ -33,11 +24,11 @@ module.exports = function (options) {
|
||||
}
|
||||
return function* proxyToNpm(next) {
|
||||
if (config.syncModel !== 'none') {
|
||||
return yield* next;
|
||||
return yield next;
|
||||
}
|
||||
// only proxy read requests
|
||||
if (this.method !== 'GET' && this.method !== 'HEAD') {
|
||||
return yield* next;
|
||||
return yield next;
|
||||
}
|
||||
|
||||
var pathname = this.path;
|
||||
@@ -49,7 +40,7 @@ module.exports = function (options) {
|
||||
}
|
||||
}
|
||||
if (!match) {
|
||||
return yield* next;
|
||||
return yield next;
|
||||
}
|
||||
|
||||
var url = redirectUrl + this.url;
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
/**!
|
||||
* cnpmjs.org - middleware/sync_by_install.js
|
||||
*
|
||||
* Copyright(c) cnpmjs.org and other contributors.
|
||||
/**
|
||||
* Copyright(c) cnpm and other contributors.
|
||||
* MIT Licensed
|
||||
*
|
||||
* Authors:
|
||||
@@ -17,33 +15,36 @@
|
||||
var config = require('../config');
|
||||
|
||||
/**
|
||||
* this.allowSync - allow sync triggle by cnpm install
|
||||
* {Boolean} this.allowSync - allow sync triggle by cnpm install
|
||||
*/
|
||||
|
||||
module.exports = function* syncByInstall(next) {
|
||||
this.allowSync = false;
|
||||
if (!config.syncByInstall) {
|
||||
// only config.enablePrivate should enable sync on install
|
||||
return yield* next;
|
||||
return yield next;
|
||||
}
|
||||
// request not by node, consider it request from web, dont sync
|
||||
// request not by node, consider it request from web, don't sync
|
||||
var ua = this.get('user-agent');
|
||||
if (!ua || ua.indexOf('node') < 0) {
|
||||
return yield* next;
|
||||
return yield next;
|
||||
}
|
||||
|
||||
// if request with `/xxx?write=true`, meaning the read request using for write, dont sync
|
||||
// if request with `/xxx?write=true`, meaning the read request using for write, don't sync
|
||||
if (this.query.write) {
|
||||
return yield* next;
|
||||
return yield next;
|
||||
}
|
||||
|
||||
var name = this.params.name || this.params[0];
|
||||
|
||||
// scoped package dont sync
|
||||
// private scoped package don't sync
|
||||
if (name && name[0] === '@') {
|
||||
return yield* next;
|
||||
var scope = name.split('/')[0];
|
||||
if (config.scopes.indexOf(scope) >= 0) {
|
||||
return yield next;
|
||||
}
|
||||
}
|
||||
|
||||
this.allowSync = true;
|
||||
yield* next;
|
||||
yield next;
|
||||
};
|
||||
|
||||
24
middleware/unpublishable.js
Normal file
24
middleware/unpublishable.js
Normal file
@@ -0,0 +1,24 @@
|
||||
/**!
|
||||
* cnpmjs.org - middleware/unpublishable.js
|
||||
*
|
||||
* Copyright(c) cnpmjs.org and other contributors.
|
||||
* MIT Licensed
|
||||
*
|
||||
* Authors:
|
||||
* dead_horse <dead_horse@qq.com>
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
module.exports = function *unpublishable(next) {
|
||||
// only admin user can unpublish
|
||||
if (!this.user.isAdmin) {
|
||||
this.status = 403;
|
||||
this.body = {
|
||||
error: 'no_perms',
|
||||
reason: 'Only administrators can unpublish module',
|
||||
};
|
||||
return;
|
||||
}
|
||||
yield next;
|
||||
};
|
||||
@@ -37,7 +37,7 @@ module.exports = {
|
||||
|
||||
query: function* (sql, args) {
|
||||
var options = { replacements: args };
|
||||
var data = yield this.sequelize.query(sql, options).spread();
|
||||
var data = yield this.sequelize.query(sql, options);
|
||||
if (/select /i.test(sql)) {
|
||||
return data[0];
|
||||
}
|
||||
|
||||
@@ -35,7 +35,10 @@ if (username) {
|
||||
|
||||
var models = require('./');
|
||||
|
||||
models.sequelize.sync({ force: force })
|
||||
models.sequelize.sync({
|
||||
force: force,
|
||||
logging: console.log,
|
||||
})
|
||||
.then(function () {
|
||||
models.Total.init(function (err) {
|
||||
if (err) {
|
||||
|
||||
@@ -70,7 +70,7 @@ module.exports = function (sequelize, DataTypes) {
|
||||
});
|
||||
if (row) {
|
||||
row.package = pkg;
|
||||
if (row.isDirty) {
|
||||
if (row.changed()) {
|
||||
row = yield row.save(['package']);
|
||||
}
|
||||
return row;
|
||||
|
||||
@@ -155,7 +155,7 @@ module.exports = function (sequelize, DataTypes) {
|
||||
user.json = data;
|
||||
user.email = data.email || '';
|
||||
user.rev = data._rev || '';
|
||||
if (user.isDirty) {
|
||||
if (user.changed()) {
|
||||
user = yield user.save();
|
||||
}
|
||||
return user;
|
||||
@@ -182,7 +182,7 @@ module.exports = function (sequelize, DataTypes) {
|
||||
user.rev = rev;
|
||||
user.salt = salt;
|
||||
user.password_sha = passwordSha;
|
||||
if (user.isDirty) {
|
||||
if (user.changed()) {
|
||||
user = yield user.save();
|
||||
}
|
||||
return user;
|
||||
|
||||
96
package.json
96
package.json
@@ -1,9 +1,10 @@
|
||||
{
|
||||
"name": "cnpmjs.org",
|
||||
"version": "2.6.0",
|
||||
"version": "2.14.0",
|
||||
"description": "Private npm registry and web for Enterprise, base on MySQL and Simple Store Service",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"dev": "DEBUG=cnpm* node dispatch.js",
|
||||
"test": "make jshint && make test",
|
||||
"start": "./bin/nodejsctl start && cp History.md docs/web/history.md",
|
||||
"status": "./bin/nodejsctl status",
|
||||
@@ -13,51 +14,54 @@
|
||||
"cnpmjs.org": "bin/cli.js"
|
||||
},
|
||||
"dependencies": {
|
||||
"agentkeepalive": "~2.0.3",
|
||||
"bytes": "~2.2.0",
|
||||
"cfork": "~1.4.0",
|
||||
"co": "~4.6.0",
|
||||
"co-defer": "~1.0.0",
|
||||
"co-gather": "~0.0.1",
|
||||
"co-sleep": "~0.0.1",
|
||||
"commander": "~2.6.0",
|
||||
"copy-to": "~2.0.1",
|
||||
"debug": "~2.2.0",
|
||||
"error-formater": "~1.0.3",
|
||||
"fs-cnpm": "~1.2.0",
|
||||
"agentkeepalive": "^2.2.0",
|
||||
"await-event": "^1.0.0",
|
||||
"bytes": "^2.4.0",
|
||||
"cfork": "^1.5.1",
|
||||
"changes-stream": "^1.1.0",
|
||||
"co": "^4.6.0",
|
||||
"co-defer": "^1.0.0",
|
||||
"co-gather": "^0.0.1",
|
||||
"co-sleep": "^0.0.1",
|
||||
"commander": "^2.9.0",
|
||||
"copy-to": "^2.0.1",
|
||||
"debug": "^2.2.0",
|
||||
"error-formater": "^1.0.3",
|
||||
"fs-cnpm": "^1.2.0",
|
||||
"giturl": "^1.0.0",
|
||||
"graceful": "~1.0.0",
|
||||
"gravatar": "~1.1.0",
|
||||
"humanize-ms": "~1.0.1",
|
||||
"humanize-number": "~0.0.2",
|
||||
"is-type-of": "~1.0.0",
|
||||
"kcors": "~1.0.1",
|
||||
"koa": "~1.1.0",
|
||||
"koa-limit": "~1.0.2",
|
||||
"koa-markdown": "~2.0.1",
|
||||
"koa-middlewares": "~2.1.0",
|
||||
"koa-mock": "~1.5.0",
|
||||
"koa-safe-jsonp": "~0.3.0",
|
||||
"markdown-it": "~3.0.6",
|
||||
"mime": "~1.3.4",
|
||||
"mini-logger": "~1.1.0",
|
||||
"mkdirp": "~0.5.0",
|
||||
"moment": "~2.11.0",
|
||||
"mysql": "~2.5.4",
|
||||
"nodemailer": "~1.3.0",
|
||||
"semver": "~5.1.0",
|
||||
"sequelize": "~2.0.1",
|
||||
"thunkify-wrap": "~1.0.4",
|
||||
"treekill": "~1.0.0",
|
||||
"graceful": "^1.0.0",
|
||||
"gravatar": "^1.5.0",
|
||||
"humanize-ms": "^1.2.0",
|
||||
"humanize-number": "^0.0.2",
|
||||
"is-type-of": "^1.0.0",
|
||||
"kcors": "^1.2.1",
|
||||
"koa": "^1.2.0",
|
||||
"koa-limit": "^1.0.2",
|
||||
"koa-markdown": "^2.0.1",
|
||||
"koa-maxrequests": "^1.0.0",
|
||||
"koa-middlewares": "^2.1.0",
|
||||
"koa-mock": "^1.6.1",
|
||||
"koa-safe-jsonp": "^0.3.1",
|
||||
"markdown-it": "^3.0.6",
|
||||
"mime": "^1.3.4",
|
||||
"mini-logger": "^1.1.1",
|
||||
"mkdirp": "^0.5.0",
|
||||
"moment": "^2.12.0",
|
||||
"mysql": "^2.10.2",
|
||||
"mz": "^2.4.0",
|
||||
"nodemailer": "^1.3.0",
|
||||
"semver": "^5.2.0",
|
||||
"sequelize": "^3.23.4",
|
||||
"thunkify-wrap": "^1.0.4",
|
||||
"treekill": "^1.0.0",
|
||||
"tunnel-agent": "^0.4.0",
|
||||
"urllib": "~2.6.0",
|
||||
"utility": "~1.6.0",
|
||||
"xss": "~0.2.10"
|
||||
"urllib": "^2.11.0",
|
||||
"utility": "^1.8.0",
|
||||
"xss": "^0.2.13"
|
||||
},
|
||||
"devDependencies": {
|
||||
"autod": "*",
|
||||
"chunkstream": "*",
|
||||
"co-mocha": "*",
|
||||
"contributors": "*",
|
||||
"istanbul": "*",
|
||||
"jshint": "*",
|
||||
@@ -65,12 +69,14 @@
|
||||
"mocha": "*",
|
||||
"node-dev": "*",
|
||||
"pedding": "*",
|
||||
"pg": "~4.4.2",
|
||||
"pg-hstore": "~2.3.2",
|
||||
"should": "~7.1.0",
|
||||
"pg": "5",
|
||||
"pg-hstore": "2",
|
||||
"should": "8",
|
||||
"should-http": "*",
|
||||
"sqlite3": "*",
|
||||
"supertest": "*"
|
||||
"supertest": "1",
|
||||
"supertest-as-promised": "3",
|
||||
"thunk-mocha": "1"
|
||||
},
|
||||
"homepage": "https://github.com/cnpm/cnpmjs.org",
|
||||
"repository": {
|
||||
@@ -90,7 +96,7 @@
|
||||
"registry"
|
||||
],
|
||||
"engines": {
|
||||
"node": ">= 2.0.0"
|
||||
"node": ">= 4.3.1"
|
||||
},
|
||||
"author": [
|
||||
"fengmk2 <fengmk2@gmail.com> (http://fengmk2.com)",
|
||||
|
||||
@@ -453,6 +453,7 @@
|
||||
font-size: 85%;
|
||||
line-height: 1.45;
|
||||
background-color: #f7f7f7;
|
||||
color:#333;
|
||||
border-radius: 3px;
|
||||
}
|
||||
|
||||
|
||||
@@ -201,6 +201,12 @@ pre code {
|
||||
font-size: 28px;
|
||||
line-height: 48px;
|
||||
}
|
||||
|
||||
.pack-ver a.badge-link {
|
||||
font-size: inherit;
|
||||
border-bottom: 0px;
|
||||
}
|
||||
|
||||
.pack-lastup {
|
||||
font-size: 14px;
|
||||
display: inline-block;
|
||||
@@ -292,3 +298,6 @@ pre code {
|
||||
height: 30px;
|
||||
margin-right: 10px;
|
||||
}
|
||||
ul, ol{
|
||||
list-style: initial;
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@ var publishable = require('../middleware/publishable');
|
||||
var syncByInstall = require('../middleware/sync_by_install');
|
||||
var editable = require('../middleware/editable');
|
||||
var existsPackage = require('../middleware/exists_package');
|
||||
var unpublishable = require('../middleware/unpublishable');
|
||||
|
||||
var showTotal = require('../controllers/total');
|
||||
|
||||
@@ -65,9 +66,9 @@ function routes(app) {
|
||||
|
||||
// module
|
||||
// scope package: params: [$name]
|
||||
app.get(/^\/(@[\w\-\.]+\/[\w\-\.]+)$/, syncByInstall, listAllVersions);
|
||||
app.get(/^\/(@[\w\-\.]+\/[^\/]+)$/, syncByInstall, listAllVersions);
|
||||
// scope package: params: [$name, $version]
|
||||
app.get(/^\/(@[\w\-\.]+\/[\w\-\.]+)\/([\w\.\-]+)$/, syncByInstall, getOneVersion);
|
||||
app.get(/^\/(@[\w\-\.]+\/[\w\-\.]+)\/([^\/]+)$/, syncByInstall, getOneVersion);
|
||||
|
||||
app.get('/:name', syncByInstall, listAllVersions);
|
||||
app.get('/:name/:version', syncByInstall, getOneVersion);
|
||||
@@ -94,16 +95,16 @@ function routes(app) {
|
||||
|
||||
// delete tarball and remove one version
|
||||
app.delete(/^\/(@[\w\-\.]+\/[\w\-\.]+)\/download\/(@[\w\-\.]+\/[\w\-\.]+)\/\-rev\/([\w\-\.]+)$/,
|
||||
login, publishable, editable, removeOneVersion);
|
||||
app.delete('/:name/download/:filename/-rev/:rev', login, publishable, editable, removeOneVersion);
|
||||
login, unpublishable, removeOneVersion);
|
||||
app.delete('/:name/download/:filename/-rev/:rev', login, unpublishable, removeOneVersion);
|
||||
|
||||
// update module, unpublish will PUT this
|
||||
app.put(/^\/(@[\w\-\.]+\/[\w\-\.]+)\/\-rev\/([\w\-\.]+)$/, login, publishable, editable, updatePackage);
|
||||
app.put('/:name/-rev/:rev', login, publishable, editable, updatePackage);
|
||||
|
||||
// remove all versions
|
||||
app.delete(/^\/(@[\w\-\.]+\/[\w\-\.]+)\/\-rev\/([\w\-\.]+)$/, login, publishable, editable, removePackage);
|
||||
app.delete('/:name/-rev/:rev', login, publishable, editable, removePackage);
|
||||
app.delete(/^\/(@[\w\-\.]+\/[\w\-\.]+)\/\-rev\/([\w\-\.]+)$/, login, unpublishable, removePackage);
|
||||
app.delete('/:name/-rev/:rev', login, unpublishable, removePackage);
|
||||
|
||||
// try to create a new user
|
||||
// https://registry.npmjs.org/-/user/org.couchdb.user:fengmk2
|
||||
|
||||
@@ -1,19 +1,4 @@
|
||||
/**!
|
||||
* cnpmjs.org - servers/registry.js
|
||||
*
|
||||
* Copyright(c) cnpmjs.org and other contributors.
|
||||
* MIT Licensed
|
||||
*
|
||||
* Authors:
|
||||
* dead_horse <dead_horse@qq.com>
|
||||
* fengmk2 <fengmk2@gmail.com> (http://fengmk2.github.com)
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
|
||||
/**
|
||||
* Module dependencies.
|
||||
*/
|
||||
'use strict';
|
||||
|
||||
var koa = require('koa');
|
||||
var app = module.exports = koa();
|
||||
@@ -28,25 +13,27 @@ var staticCache = require('../middleware/static');
|
||||
var notFound = require('../middleware/registry_not_found');
|
||||
var cors = require('kcors');
|
||||
var proxyToNpm = require('../middleware/proxy_to_npm');
|
||||
var maxrequests = require('koa-maxrequests');
|
||||
|
||||
app.use(maxrequests());
|
||||
app.use(block());
|
||||
middlewares.jsonp(app);
|
||||
app.use(middlewares.rt({headerName: 'X-ReadTime'}));
|
||||
app.use(middlewares.rt({ headerName: 'X-ReadTime' }));
|
||||
app.use(middlewares.rewrite('/favicon.ico', '/favicon.png'));
|
||||
app.use(staticCache);
|
||||
|
||||
app.keys = ['todokey', config.sessionSecret];
|
||||
app.proxy = true;
|
||||
app.use(middlewares.bodyParser({jsonLimit: config.jsonLimit}));
|
||||
app.use(middlewares.bodyParser({ jsonLimit: config.jsonLimit }));
|
||||
app.use(cors({
|
||||
allowMethods: 'GET,HEAD'
|
||||
allowMethods: 'GET,HEAD',
|
||||
}));
|
||||
app.use(auth());
|
||||
app.use(proxyToNpm());
|
||||
app.use(notFound);
|
||||
|
||||
if (config.enableCompress) {
|
||||
app.use(middlewares.compress({threshold: 150}));
|
||||
app.use(middlewares.compress({ threshold: 150 }));
|
||||
}
|
||||
app.use(middlewares.conditional());
|
||||
app.use(middlewares.etag());
|
||||
|
||||
@@ -1,19 +1,4 @@
|
||||
/**!
|
||||
* cnpmjs.org - servers/web.js
|
||||
*
|
||||
* Copyright(c) cnpmjs.org and other contributors.
|
||||
* MIT Licensed
|
||||
*
|
||||
* Authors:
|
||||
* dead_horse <dead_horse@qq.com>
|
||||
* fengmk2 <m@fengmk2.com> (http://fengmk2.com)
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
|
||||
/**
|
||||
* Module dependencies.
|
||||
*/
|
||||
'use strict';
|
||||
|
||||
var opensearch = require('../middleware/opensearch');
|
||||
var notFound = require('../middleware/web_not_found');
|
||||
@@ -32,6 +17,7 @@ var path = require('path');
|
||||
var http = require('http');
|
||||
var koa = require('koa');
|
||||
var fs = require('fs');
|
||||
var maxrequests = require('koa-maxrequests');
|
||||
|
||||
var app = koa();
|
||||
|
||||
@@ -39,6 +25,7 @@ jsonp(app);
|
||||
|
||||
var rootdir = path.dirname(__dirname);
|
||||
|
||||
app.use(maxrequests());
|
||||
app.use(block());
|
||||
app.use(middlewares.rt({headerName: 'X-ReadTime'}));
|
||||
app.use(middlewares.rewrite('/favicon.ico', '/favicon.png'));
|
||||
|
||||
@@ -72,7 +72,7 @@ exports.plusModuleTotal = function* (data) {
|
||||
row[field] = utility.toSafeNumber(row[field]);
|
||||
}
|
||||
row[field] += data.count;
|
||||
if (row.isDirty) {
|
||||
if (row.changed()) {
|
||||
yield row.save();
|
||||
}
|
||||
|
||||
@@ -94,7 +94,7 @@ exports.plusModuleTotal = function* (data) {
|
||||
row[field] = utility.toSafeNumber(row[field]);
|
||||
}
|
||||
row[field] += data.count;
|
||||
if (row.isDirty) {
|
||||
if (row.changed()) {
|
||||
return yield row.save();
|
||||
}
|
||||
return row;
|
||||
|
||||
@@ -50,5 +50,5 @@ exports.append = function* (id, log) {
|
||||
};
|
||||
|
||||
exports.get = function* (id) {
|
||||
return yield ModuleLog.find(id);
|
||||
return yield ModuleLog.findById(id);
|
||||
};
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
* Module dependencies.
|
||||
*/
|
||||
|
||||
var semver = require('semver');
|
||||
var models = require('../models');
|
||||
var common = require('./common');
|
||||
var Tag = models.Tag;
|
||||
@@ -54,7 +55,7 @@ function stringifyPackage(pkg) {
|
||||
}
|
||||
|
||||
exports.getModuleById = function* (id) {
|
||||
var row = yield Module.find(Number(id));
|
||||
var row = yield Module.findById(Number(id));
|
||||
parseRow(row);
|
||||
return row;
|
||||
};
|
||||
@@ -73,6 +74,25 @@ exports.getModuleByTag = function* (name, tag) {
|
||||
return yield* exports.getModule(tag.name, tag.version);
|
||||
};
|
||||
|
||||
exports.getModuleByRange = function* (name, range) {
|
||||
var rows = yield exports.listModulesByName(name, [ 'id', 'version' ]);
|
||||
var versionMap = {};
|
||||
var versions = rows.map(function(row) {
|
||||
versionMap[row.version] = row;
|
||||
return row.version;
|
||||
}).filter(function(version) {
|
||||
return semver.valid(version);
|
||||
});
|
||||
|
||||
var version = semver.maxSatisfying(versions, range);
|
||||
if (!versionMap[version]) {
|
||||
return null;
|
||||
}
|
||||
|
||||
var id = versionMap[version].id;
|
||||
return yield exports.getModuleById(id);
|
||||
};
|
||||
|
||||
exports.getLatestModule = function* (name) {
|
||||
return yield* exports.getModuleByTag(name, 'latest');
|
||||
};
|
||||
@@ -226,12 +246,13 @@ exports.listAllPublicModuleNames = function* () {
|
||||
});
|
||||
};
|
||||
|
||||
exports.listModulesByName = function* (moduleName) {
|
||||
exports.listModulesByName = function* (moduleName, attributes) {
|
||||
var mods = yield Module.findAll({
|
||||
where: {
|
||||
name: moduleName
|
||||
},
|
||||
order: [ ['id', 'DESC'] ]
|
||||
order: [ ['id', 'DESC'] ],
|
||||
attributes,
|
||||
});
|
||||
|
||||
for (var mod of mods) {
|
||||
@@ -282,7 +303,7 @@ exports.saveModule = function* (mod) {
|
||||
item.dist_size = dist.size;
|
||||
item.description = description;
|
||||
|
||||
if (item.isDirty) {
|
||||
if (item.changed()) {
|
||||
item = yield item.save();
|
||||
}
|
||||
var result = {
|
||||
@@ -314,7 +335,7 @@ exports.saveModule = function* (mod) {
|
||||
};
|
||||
|
||||
exports.updateModulePackage = function* (id, pkg) {
|
||||
var mod = yield Module.find(Number(id));
|
||||
var mod = yield Module.findById(Number(id));
|
||||
if (!mod) {
|
||||
// not exists
|
||||
return null;
|
||||
@@ -367,8 +388,9 @@ exports.updateModuleLastModified = function* (name) {
|
||||
if (!row) {
|
||||
return null;
|
||||
}
|
||||
row.gmt_modified = new Date();
|
||||
return yield row.save(['gmt_modified']);
|
||||
// gmt_modified is readonly, we must use setDataValue
|
||||
row.setDataValue('gmt_modified', new Date());
|
||||
return yield row.save();
|
||||
};
|
||||
|
||||
exports.removeModulesByName = function* (name) {
|
||||
@@ -405,7 +427,7 @@ exports.addModuleTag = function* (name, tag, version) {
|
||||
}
|
||||
row.module_id = mod.id;
|
||||
row.version = version;
|
||||
if (row.isDirty) {
|
||||
if (row.changed()) {
|
||||
return yield row.save();
|
||||
}
|
||||
return row;
|
||||
@@ -581,7 +603,7 @@ exports.addKeyword = function* (data) {
|
||||
item = ModuleKeyword.build(data);
|
||||
}
|
||||
item.description = data.description;
|
||||
if (item.isDirty) {
|
||||
if (item.changed()) {
|
||||
// make sure object will change, otherwise will cause empty sql error
|
||||
// @see https://github.com/cnpm/cnpmjs.org/issues/533
|
||||
return yield item.save();
|
||||
|
||||
85
sync/changes_stream_syncer.js
Normal file
85
sync/changes_stream_syncer.js
Normal file
@@ -0,0 +1,85 @@
|
||||
'use strict';
|
||||
|
||||
const ChangesStream = require('changes-stream');
|
||||
const path = require('path');
|
||||
const fs = require('mz/fs');
|
||||
const urllib = require('urllib');
|
||||
const streamAwait = require('await-event');
|
||||
const logger = require('../common/logger');
|
||||
const config = require('../config');
|
||||
|
||||
const db = 'https://replicate.npmjs.com';
|
||||
const lastSeqFile = path.join(config.dataDir, '.cnpmjs.org.last_seq.txt');
|
||||
let _STREAM_ID = 0;
|
||||
|
||||
module.exports = function* sync() {
|
||||
const since = yield getLastSequence();
|
||||
const streamId = _STREAM_ID++;
|
||||
let changesCount = 0;
|
||||
logger.syncInfo('start changes stream#%d, since: %s', streamId, since);
|
||||
const changes = new ChangesStream({
|
||||
db,
|
||||
since,
|
||||
include_docs: false,
|
||||
});
|
||||
changes.await = streamAwait;
|
||||
changes.on('data', change => {
|
||||
changesCount++;
|
||||
logger.syncInfo('stream#%d get change#%d: %j', streamId, changesCount, change);
|
||||
syncPackage(change);
|
||||
});
|
||||
|
||||
try {
|
||||
yield changes.await('error');
|
||||
} catch (err) {
|
||||
// make sure changes steam is destroy
|
||||
changes.destroy();
|
||||
err.message += `, stream#${streamId}, changesCount#${changesCount}`;
|
||||
throw err;
|
||||
}
|
||||
};
|
||||
|
||||
function syncPackage(change) {
|
||||
const url = `${config.handleSyncRegistry}/${change.id}/sync`;
|
||||
urllib.request(url, {
|
||||
method: 'PUT',
|
||||
dataType: 'json',
|
||||
timeout: 10000,
|
||||
}, (err, data) => {
|
||||
if (err) {
|
||||
logger.syncInfo('%s:%s PUT %s error: %s, retry after 5s',
|
||||
change.seq, change.id, url, err);
|
||||
logger.syncError(err);
|
||||
syncPackage(change);
|
||||
setTimeout(() => syncPackage(change), 5000);
|
||||
} else {
|
||||
saveLastSequence(change.seq);
|
||||
logger.syncInfo('%s:%s sync request sent, log: %s/log/%s',
|
||||
change.seq, change.id, url, data.logId);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function* getLastSequence() {
|
||||
let lastSeq;
|
||||
if (yield fs.exists(lastSeqFile)) {
|
||||
lastSeq = yield fs.readFile(lastSeqFile, 'utf8');
|
||||
lastSeq = Number(lastSeq);
|
||||
}
|
||||
if (!lastSeq) {
|
||||
lastSeq = 2649694;
|
||||
}
|
||||
// const r = yield urllib.request(db, {
|
||||
// dataType: 'json',
|
||||
// timeout: 15000,
|
||||
// });
|
||||
// logger.syncInfo('get registry info: %j', r.data);
|
||||
// if (lastSeq < r.data.update_seq) {
|
||||
// lastSeq = r.data.update_seq;
|
||||
// }
|
||||
return lastSeq;
|
||||
}
|
||||
|
||||
function saveLastSequence(seq) {
|
||||
fs.writeFile(lastSeqFile, String(seq), () => {});
|
||||
}
|
||||
221
sync/index.js
221
sync/index.js
@@ -1,36 +1,23 @@
|
||||
/**
|
||||
* Copyright(c) cnpm and other contributors.
|
||||
* MIT Licensed
|
||||
*
|
||||
* Authors:
|
||||
* dead_horse <dead_horse@qq.com> (http://deadhorse.me)
|
||||
* fengmk2 <fengmk2@gmail.com> (http://fengmk2.com)
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* Module dependencies.
|
||||
*/
|
||||
const debug = require('debug')('cnpmjs.org:sync:index');
|
||||
const co = require('co');
|
||||
const ms = require('humanize-ms');
|
||||
const util = require('util');
|
||||
const config = require('../config');
|
||||
const mail = require('../common/mail');
|
||||
const logger = require('../common/logger');
|
||||
const totalService = require('../services/total');
|
||||
|
||||
var debug = require('debug')('cnpmjs.org:sync:index');
|
||||
var co = require('co');
|
||||
var ms = require('humanize-ms');
|
||||
var util = require('util');
|
||||
var config = require('../config');
|
||||
var mail = require('../common/mail');
|
||||
var logger = require('../common/logger');
|
||||
var totalService = require('../services/total');
|
||||
|
||||
var sync = null;
|
||||
let sync = null;
|
||||
|
||||
switch (config.syncModel) {
|
||||
case 'all':
|
||||
sync = require('./sync_all');
|
||||
break;
|
||||
case 'exist':
|
||||
sync = require('./sync_exist');
|
||||
break;
|
||||
case 'all':
|
||||
sync = require('./sync_all');
|
||||
break;
|
||||
case 'exist':
|
||||
sync = require('./sync_exist');
|
||||
break;
|
||||
}
|
||||
|
||||
if (!sync && config.enableCluster) {
|
||||
@@ -38,34 +25,72 @@ if (!sync && config.enableCluster) {
|
||||
process.exit(0);
|
||||
}
|
||||
|
||||
console.log('[%s] [sync_worker:%s] syncing with %s mode',
|
||||
Date(), process.pid, config.syncModel);
|
||||
console.log('[%s] [sync_worker:%s] syncing with %s mode, changesStreamingSync: %s',
|
||||
Date(), process.pid, config.syncModel, config.changesStreamingSync);
|
||||
|
||||
function onerror(err) {
|
||||
logger.error(err);
|
||||
}
|
||||
|
||||
//set sync_status = 0 at first
|
||||
// set sync_status = 0 at first
|
||||
co(function* () {
|
||||
yield totalService.updateSyncStatus(0);
|
||||
yield checkSyncStatus();
|
||||
}).catch(onerror);
|
||||
|
||||
var syncInterval = ms(config.syncInterval);
|
||||
var minSyncInterval = ms('5m');
|
||||
let syncInterval = ms(config.syncInterval);
|
||||
const minSyncInterval = ms('5m');
|
||||
if (!syncInterval || syncInterval < minSyncInterval) {
|
||||
syncInterval = minSyncInterval;
|
||||
}
|
||||
|
||||
// the same time only sync once
|
||||
var syncing = false;
|
||||
var syncFn = co.wrap(function* () {
|
||||
debug('mode: %s, syncing: %s', config.syncModel, syncing);
|
||||
if (!syncing) {
|
||||
if (sync) {
|
||||
// the same time only sync once
|
||||
let syncing = false;
|
||||
const syncFn = co.wrap(function*() {
|
||||
debug('mode: %s, syncing: %s', config.syncModel, syncing);
|
||||
if (!syncing) {
|
||||
syncing = true;
|
||||
debug('start syncing');
|
||||
let data;
|
||||
let error;
|
||||
try {
|
||||
data = yield sync();
|
||||
} catch (err) {
|
||||
error = err;
|
||||
error.message += ' (sync package error)';
|
||||
logger.syncError(error);
|
||||
}
|
||||
data && logger.syncInfo(data);
|
||||
if (!config.debug) {
|
||||
sendMailToAdmin(error, data, new Date());
|
||||
}
|
||||
syncing = false;
|
||||
}
|
||||
|
||||
// check last_sync_time and last_exist_sync_time
|
||||
yield checkSyncStatus();
|
||||
});
|
||||
|
||||
syncFn().catch(onerror);
|
||||
setInterval(() => syncFn().catch(onerror), syncInterval);
|
||||
}
|
||||
|
||||
/**
|
||||
* sync popular modules
|
||||
*/
|
||||
|
||||
if (config.syncPopular) {
|
||||
const sync = require('./sync_popular');
|
||||
let syncing = false;
|
||||
const syncFn = co.wrap(function*() {
|
||||
if (syncing) {
|
||||
return;
|
||||
}
|
||||
syncing = true;
|
||||
debug('start syncing');
|
||||
var data;
|
||||
var error;
|
||||
logger.syncInfo('Start syncing popular modules...');
|
||||
let data;
|
||||
let error;
|
||||
try {
|
||||
data = yield sync();
|
||||
} catch (err) {
|
||||
@@ -73,79 +98,60 @@ var syncFn = co.wrap(function* () {
|
||||
error.message += ' (sync package error)';
|
||||
logger.syncError(error);
|
||||
}
|
||||
data && logger.syncInfo(data);
|
||||
|
||||
if (data) {
|
||||
logger.syncInfo(data);
|
||||
}
|
||||
if (!config.debug) {
|
||||
sendMailToAdmin(error, data, new Date());
|
||||
}
|
||||
syncing = false;
|
||||
}
|
||||
});
|
||||
|
||||
// check last_sync_time and last_exist_sync_time
|
||||
yield checkSyncStatus();
|
||||
});
|
||||
|
||||
if (sync) {
|
||||
syncFn().catch(onerror);
|
||||
setInterval(function () {
|
||||
syncFn().catch(onerror);
|
||||
}, syncInterval);
|
||||
setInterval(() => syncFn().catch(onerror), ms(config.syncPopularInterval));
|
||||
}
|
||||
|
||||
/**
|
||||
* sync popular modules
|
||||
*/
|
||||
if (config.syncChangesStream) {
|
||||
const sync = require('./changes_stream_syncer');
|
||||
let syncing = false;
|
||||
const syncFn = co.wrap(function*() {
|
||||
if (syncing) {
|
||||
return;
|
||||
}
|
||||
syncing = true;
|
||||
logger.syncInfo('Start changes stream syncing...');
|
||||
try {
|
||||
yield sync();
|
||||
} catch (err) {
|
||||
err.message += ' (sync changes stream error)';
|
||||
logger.syncError(err);
|
||||
}
|
||||
syncing = false;
|
||||
});
|
||||
|
||||
var startSyncPopular = require('./sync_popular');
|
||||
var syncingPopular = false;
|
||||
var syncPopularFn = co.wrap(function* syncPopular() {
|
||||
if (syncingPopular) {
|
||||
return;
|
||||
}
|
||||
syncingPopular = true;
|
||||
logger.syncInfo('Start syncing popular modules...');
|
||||
var data;
|
||||
var error;
|
||||
try {
|
||||
data = yield startSyncPopular();
|
||||
} catch (err) {
|
||||
error = err;
|
||||
error.message += ' (sync package error)';
|
||||
logger.syncError(error);
|
||||
}
|
||||
|
||||
if (data) {
|
||||
logger.syncInfo(data);
|
||||
}
|
||||
if (!config.debug) {
|
||||
sendMailToAdmin(error, data, new Date());
|
||||
}
|
||||
|
||||
syncingPopular = false;
|
||||
});
|
||||
|
||||
if (config.syncPopular) {
|
||||
syncPopularFn().catch(onerror);
|
||||
setInterval(function () {
|
||||
syncPopularFn().catch(onerror);
|
||||
}, ms(config.syncPopularInterval));
|
||||
} else {
|
||||
logger.syncInfo('sync popular module disable');
|
||||
syncFn().catch(onerror);
|
||||
setInterval(() => syncFn().catch(onerror), ms('1m'));
|
||||
}
|
||||
|
||||
function sendMailToAdmin(err, result, syncTime) {
|
||||
result = result || {};
|
||||
var to = [];
|
||||
const to = [];
|
||||
for (var name in config.admins) {
|
||||
to.push(config.admins[name]);
|
||||
}
|
||||
debug('Send email to all admins: %j, with err message: %s, result: %j, start sync time: %s.',
|
||||
to, err ? err.message : '', result, syncTime);
|
||||
var subject;
|
||||
var type;
|
||||
var html;
|
||||
let subject;
|
||||
let type;
|
||||
let html;
|
||||
if (err) {
|
||||
// ignore 503 error
|
||||
if (err.status === 503) {
|
||||
// ignore 503, 504 error
|
||||
// 504: Gateway Time-out
|
||||
if (err.status === 503 || err.status === 504) {
|
||||
return;
|
||||
}
|
||||
if (err.name === 'JSONResponseFormatError') {
|
||||
return;
|
||||
}
|
||||
subject = 'Sync Error';
|
||||
@@ -159,6 +165,10 @@ function sendMailToAdmin(err, result, syncTime) {
|
||||
'Start sync time is %s.\n %d packges sync failed: %j ...\n %d packages sync successes :%j ...',
|
||||
syncTime, result.fails.length, result.fails.slice(0, 10),
|
||||
result.successes.length, result.successes.slice(0, 10));
|
||||
// skip email notice when fails items small then 3
|
||||
if (result.fails.length < 3) {
|
||||
type = 'log';
|
||||
}
|
||||
} else if (result.successes && result.successes.length) {
|
||||
subject = 'Sync Finished';
|
||||
type = 'log';
|
||||
@@ -169,7 +179,7 @@ function sendMailToAdmin(err, result, syncTime) {
|
||||
debug('send email with type: %s, subject: %s, html: %s', type, subject, html);
|
||||
logger.syncInfo('send email with type: %s, subject: %s, html: %s', type, subject, html);
|
||||
if (type && type !== 'log') {
|
||||
mail[type](to, subject, html, function (err) {
|
||||
mail[type](to, subject, html, err => {
|
||||
if (err) {
|
||||
logger.error(err);
|
||||
}
|
||||
@@ -178,8 +188,12 @@ function sendMailToAdmin(err, result, syncTime) {
|
||||
}
|
||||
|
||||
function* checkSyncStatus() {
|
||||
var total = yield totalService.getTotalInfo();
|
||||
var lastSyncTime;
|
||||
// if source registry not cnpm, ignore it. e.g.: cnpmjs.org source registry is npmjs.org
|
||||
if (!config.sourceNpmRegistryIsCNpm) {
|
||||
return;
|
||||
}
|
||||
const total = yield totalService.getTotalInfo();
|
||||
let lastSyncTime;
|
||||
if (config.syncModel === 'all') {
|
||||
lastSyncTime = total.last_sync_time;
|
||||
} else if (config.syncModel === 'exist') {
|
||||
@@ -189,10 +203,13 @@ function* checkSyncStatus() {
|
||||
if (!lastSyncTime) {
|
||||
return;
|
||||
}
|
||||
var diff = Date.now() - lastSyncTime;
|
||||
if (diff > syncInterval * 2) {
|
||||
var err = new Error('Last sync time is expired in ' + diff + ' ms, lastSyncTime: ' + new Date(lastSyncTime));
|
||||
err.name = 'SyncExpriedError';
|
||||
const diff = Date.now() - lastSyncTime;
|
||||
const oneDay = 3600000 * 24;
|
||||
const maxTime = Math.max(oneDay, syncInterval * 2);
|
||||
if (diff > maxTime) {
|
||||
const err = new Error('Last sync time is expired in ' + diff + ' ms, lastSyncTime: ' +
|
||||
new Date(lastSyncTime) + ', maxTime: ' + maxTime + ' ms');
|
||||
err.name = 'SyncExpiredError';
|
||||
sendMailToAdmin(err, null, new Date());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,19 +1,5 @@
|
||||
/*!
|
||||
* cnpmjs.org - sync/status.js
|
||||
*
|
||||
* Copyright(c) cnpmjs.org and other contributors.
|
||||
* MIT Licensed
|
||||
*
|
||||
* Authors:
|
||||
* dead_horse <dead_horse@qq.com> (http://deadhorse.me)
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* Module dependencies.
|
||||
*/
|
||||
|
||||
var debug = require('debug')('cnpmjs.org:sync:status');
|
||||
var co = require('co');
|
||||
var Total = require('../services/total');
|
||||
@@ -36,7 +22,7 @@ Status.prototype.log = function (syncDone) {
|
||||
lastSyncModule: this.lastSyncModule,
|
||||
};
|
||||
co(function* () {
|
||||
yield* Total.updateSyncNum(params);
|
||||
yield Total.updateSyncNum(params);
|
||||
}).catch(function () {});
|
||||
};
|
||||
|
||||
|
||||
@@ -1,20 +1,5 @@
|
||||
/**!
|
||||
* cnpmjs.org - sync/sync_all.js
|
||||
*
|
||||
* Copyright(c) cnpmjs.org and other contributors.
|
||||
* MIT Licensed
|
||||
*
|
||||
* Authors:
|
||||
* dead_horse <dead_horse@qq.com> (http://deadhorse.me)
|
||||
* fengmk2 <m@fengmk2.com> (http://fengmk2.com)
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* Module dependencies.
|
||||
*/
|
||||
|
||||
var thunkify = require('thunkify-wrap');
|
||||
var config = require('../config');
|
||||
var Status = require('./status');
|
||||
@@ -72,19 +57,22 @@ module.exports = function* sync() {
|
||||
concurrency: config.syncConcurrency,
|
||||
syncUpstreamFirst: false,
|
||||
});
|
||||
Status.init({need: packages.length}, worker);
|
||||
Status.init({
|
||||
need: packages.length,
|
||||
}, worker);
|
||||
worker.start();
|
||||
var end = thunkify.event(worker);
|
||||
yield end();
|
||||
|
||||
logger.syncInfo('All packages sync done, successes %d, fails %d',
|
||||
worker.successes.length, worker.fails.length);
|
||||
logger.syncInfo('All packages sync done, successes %d, fails %d, updates %d',
|
||||
worker.successes.length, worker.fails.length, worker.updates.length);
|
||||
//only when all succss, set last sync time
|
||||
if (!worker.fails.length) {
|
||||
yield* totalService.setLastSyncTime(syncTime);
|
||||
yield totalService.setLastSyncTime(syncTime);
|
||||
}
|
||||
return {
|
||||
successes: worker.successes,
|
||||
fails: worker.fails
|
||||
fails: worker.fails,
|
||||
updates: worker.updates,
|
||||
};
|
||||
};
|
||||
|
||||
@@ -1,17 +1,5 @@
|
||||
/*!
|
||||
* Copyright(c) cnpmjs.org and other contributors.
|
||||
* MIT Licensed
|
||||
*
|
||||
* Authors:
|
||||
* dead_horse <dead_horse@qq.com> (http://deadhorse.me)
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* Module dependencies.
|
||||
*/
|
||||
|
||||
var debug = require('debug')('cnpmjs.org:sync:sync_exist');
|
||||
var Status = require('./status');
|
||||
var thunkify = require('thunkify-wrap');
|
||||
@@ -31,7 +19,7 @@ function intersection(arrOne, arrTwo) {
|
||||
map[name] = true;
|
||||
});
|
||||
arrTwo.forEach(function (name) {
|
||||
map[name] && results.push(name);
|
||||
map[name] === true && results.push(name);
|
||||
});
|
||||
return results;
|
||||
}
|
||||
@@ -48,7 +36,7 @@ module.exports = function* sync() {
|
||||
|
||||
var allPackages;
|
||||
if (!info.last_exist_sync_time) {
|
||||
var pkgs = yield* npmService.getShort();
|
||||
var pkgs = yield npmService.getShort();
|
||||
debug('First time sync all packages from official registry, got %d packages', pkgs.length);
|
||||
if (info.last_sync_module) {
|
||||
// start from last success
|
||||
@@ -74,7 +62,7 @@ module.exports = function* sync() {
|
||||
fails: []
|
||||
};
|
||||
}
|
||||
debug('Total %d packages to sync', packages.length);
|
||||
debug('Total %d packages to sync, top 10: %j', packages.length, packages.slice(0, 10));
|
||||
|
||||
var worker = new SyncModuleWorker({
|
||||
username: 'admin',
|
||||
|
||||
@@ -1,19 +1,5 @@
|
||||
/*!
|
||||
* cnpmjs.org - sync/sync_popular.js
|
||||
*
|
||||
* Copyright(c) cnpmjs.org and other contributors.
|
||||
* MIT Licensed
|
||||
*
|
||||
* Authors:
|
||||
* dead_horse <dead_horse@qq.com> (http://deadhorse.me)
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* Module dependencies.
|
||||
*/
|
||||
|
||||
var debug = require('debug')('cnpmjs.org:sync:sync_popular');
|
||||
var thunkify = require('thunkify-wrap');
|
||||
var config = require('../config');
|
||||
|
||||
@@ -1,19 +1,5 @@
|
||||
/**!
|
||||
* sync packages since by some days ago
|
||||
*
|
||||
* Copyright(c) cnpmjs.org and other contributors.
|
||||
* MIT Licensed
|
||||
*
|
||||
* Authors:
|
||||
* fengmk2 <m@fengmk2.com> (http://fengmk2.com)
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* Module dependencies.
|
||||
*/
|
||||
|
||||
const thunkify = require('thunkify-wrap');
|
||||
const co = require('co');
|
||||
const ms = require('humanize-ms');
|
||||
|
||||
@@ -1,13 +1,3 @@
|
||||
/**!
|
||||
* cnpmjs.org - test/controllers/registry/module/scope_package.test.js
|
||||
*
|
||||
* Copyright(c) fengmk2 and other contributors.
|
||||
* MIT Licensed
|
||||
*
|
||||
* Authors:
|
||||
* fengmk2 <fengmk2@gmail.com> (http://fengmk2.github.com)
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
@@ -21,7 +11,7 @@ var config = require('../../../../config');
|
||||
var app = require('../../../../servers/registry');
|
||||
var utils = require('../../../utils');
|
||||
|
||||
describe('controllers/registry/module/scope_package.test.js', function () {
|
||||
describe('test/controllers/registry/module/scope_package.test.js', function () {
|
||||
var pkgname = '@cnpm/test-scope-package';
|
||||
var pkgURL = '/@' + encodeURIComponent(pkgname.substring(1));
|
||||
before(function (done) {
|
||||
@@ -52,16 +42,17 @@ describe('controllers/registry/module/scope_package.test.js', function () {
|
||||
|
||||
afterEach(mm.restore);
|
||||
|
||||
it('should get 404 when do not support scope', function (done) {
|
||||
it('should get 302 when do not support scope', function (done) {
|
||||
mm(config, 'scopes', []);
|
||||
request(app)
|
||||
.get('/@invalid/test')
|
||||
.expect(404, done);
|
||||
.expect('Location', 'https://registry.npmjs.com/@invalid/test')
|
||||
.expect(302, done);
|
||||
});
|
||||
|
||||
it('should get 400 when scope not match', function (done) {
|
||||
it('should get 404 when scope is private', function (done) {
|
||||
request(app)
|
||||
.get('/@invalid/test')
|
||||
.get('/@cnpmtest/test')
|
||||
.expect(404, done);
|
||||
});
|
||||
|
||||
|
||||
@@ -89,6 +89,13 @@ describe('controllers/registry/package/list.test.js', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('should support jsonp', function (done) {
|
||||
request(app.listen())
|
||||
.get('/@cnpmtest/testmodule-list-1?callback=jsonp')
|
||||
.expect(/jsonp\(\{/)
|
||||
.expect(200, done);
|
||||
});
|
||||
|
||||
it('should 404 when package not exists', function (done) {
|
||||
request(app.listen())
|
||||
.get('/@cnpmtest/not-exists-package')
|
||||
@@ -130,18 +137,17 @@ describe('controllers/registry/package/list.test.js', function () {
|
||||
|
||||
describe('unpublished', function () {
|
||||
before(function (done) {
|
||||
utils.sync('tfs', done);
|
||||
utils.sync('moduletest1', done);
|
||||
});
|
||||
|
||||
it('should show unpublished info', function (done) {
|
||||
mm(config, 'syncModel', 'all');
|
||||
request(app.listen())
|
||||
.get('/tfs')
|
||||
.get('/moduletest1')
|
||||
.expect(404, function (err, res) {
|
||||
should.not.exist(err);
|
||||
var data = res.body;
|
||||
data.time.unpublished.name.should.equal('fengmk2');
|
||||
data.time.unpublished.description.should.equal('tfs');
|
||||
data.time.unpublished.name.should.equal('dead_horse');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -27,10 +27,10 @@ describe('test/controllers/registry/package/remove.test.js', function () {
|
||||
afterEach(mm.restore);
|
||||
|
||||
before(function (done) {
|
||||
var pkg = utils.getPackage('@cnpmtest/testmodule-remove-1', '1.0.0', utils.admin);
|
||||
var pkg = utils.getPackage('@cnpmtest/testmodule-remove-1', '1.0.0', utils.otherUser);
|
||||
request(app.listen())
|
||||
.put('/' + pkg.name)
|
||||
.set('authorization', utils.adminAuth)
|
||||
.set('authorization', utils.otherUserAuth)
|
||||
.send(pkg)
|
||||
.expect(201, done);
|
||||
});
|
||||
@@ -56,47 +56,13 @@ describe('test/controllers/registry/package/remove.test.js', function () {
|
||||
.expect(404, done);
|
||||
});
|
||||
|
||||
it('should delete 403 when user is not admin on config.enablePrivate = true', function (done) {
|
||||
mm(config, 'enablePrivate', true);
|
||||
it('should delete 403 when user is not admin', function (done) {
|
||||
request(app)
|
||||
.del('/@cnpmtest/testmodule-remove-1/-rev/1')
|
||||
.set('authorization', utils.otherUserAuth)
|
||||
.expect({
|
||||
error: 'no_perms',
|
||||
reason: 'Private mode enable, only admin can publish this module'
|
||||
})
|
||||
.expect(403, done);
|
||||
});
|
||||
|
||||
it('should 400 when scope not exists', function (done) {
|
||||
request(app)
|
||||
.del('/@cnpm-not-exists/testmodule-remove-1/-rev/1')
|
||||
.set('authorization', utils.otherUserAuth)
|
||||
.expect({
|
||||
error: 'invalid scope',
|
||||
reason: 'scope @cnpm-not-exists not match legal scopes: @cnpm, @cnpmtest, @cnpm-test'
|
||||
})
|
||||
.expect(400, done);
|
||||
});
|
||||
|
||||
it('should 403 when delete non scoped package', function (done) {
|
||||
request(app)
|
||||
.del('/testmodule-remove-1/-rev/1')
|
||||
.set('authorization', utils.otherUserAuth)
|
||||
.expect({
|
||||
error: 'no_perms',
|
||||
reason: 'only allow publish with @cnpm, @cnpmtest, @cnpm-test scope(s)'
|
||||
})
|
||||
.expect(403, done);
|
||||
});
|
||||
|
||||
it('should 403 when user not maintainer', function (done) {
|
||||
request(app)
|
||||
.del('/@cnpmtest/testmodule-remove-1/-rev/1')
|
||||
.set('authorization', utils.otherUserAuth)
|
||||
.expect({
|
||||
error: 'forbidden user',
|
||||
reason: 'cnpmjstest101 not authorized to modify @cnpmtest/testmodule-remove-1'
|
||||
reason: 'Only administrators can unpublish module'
|
||||
})
|
||||
.expect(403, done);
|
||||
});
|
||||
|
||||
@@ -27,10 +27,10 @@ describe('controllers/registry/package/remove_version.test.js', function () {
|
||||
|
||||
var lastRev;
|
||||
before(function (done) {
|
||||
var pkg = utils.getPackage('@cnpmtest/testmodule-remove_version-1', '0.0.1', utils.admin);
|
||||
var pkg = utils.getPackage('@cnpmtest/testmodule-remove_version-1', '0.0.1', utils.otherUser);
|
||||
request(app.listen())
|
||||
.put('/' + pkg.name)
|
||||
.set('authorization', utils.adminAuth)
|
||||
.set('authorization', utils.otherUserAuth)
|
||||
.send(pkg)
|
||||
.expect(201, function (err, res) {
|
||||
should.not.exist(err);
|
||||
@@ -78,7 +78,7 @@ describe('controllers/registry/package/remove_version.test.js', function () {
|
||||
.expect(401, done);
|
||||
});
|
||||
|
||||
it('should 403 when auth error', function (done) {
|
||||
it('should 403 when not admin', function (done) {
|
||||
request(app)
|
||||
.del('/@cnpmtest/testmodule-remove_version-1/download/@cnpmtest/testmodule-remove_version-1-0.0.1.tgz/-rev/' + lastRev)
|
||||
.set('authorization', utils.otherUserAuth)
|
||||
@@ -94,10 +94,10 @@ describe('controllers/registry/package/remove_version.test.js', function () {
|
||||
|
||||
describe('mock error', function () {
|
||||
before(function (done) {
|
||||
var pkg = utils.getPackage('@cnpmtest/testmodule-remove_version-1', '0.0.2', utils.admin);
|
||||
var pkg = utils.getPackage('@cnpmtest/testmodule-remove_version-1', '0.0.2', utils.otherUser);
|
||||
request(app.listen())
|
||||
.put('/' + pkg.name)
|
||||
.set('authorization', utils.adminAuth)
|
||||
.set('authorization', utils.otherUserAuth)
|
||||
.send(pkg)
|
||||
.expect(201, done);
|
||||
});
|
||||
|
||||
@@ -1,11 +1,9 @@
|
||||
/**!
|
||||
* cnpmjs.org - test/controllers/registry/package/show.test.js
|
||||
*
|
||||
* Copyright(c) cnpmjs.org and other contributors.
|
||||
/**
|
||||
* Copyright(c) cnpm and other contributors.
|
||||
* MIT Licensed
|
||||
*
|
||||
* Authors:
|
||||
* fengmk2 <fengmk2@gmail.com> (http://fengmk2.github.com)
|
||||
* fengmk2 <fengmk2@gmail.com> (http://fengmk2.com)
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
@@ -20,15 +18,32 @@ var mm = require('mm');
|
||||
var app = require('../../../../servers/registry');
|
||||
var utils = require('../../../utils');
|
||||
|
||||
describe('controllers/registry/package/show.test.js', function () {
|
||||
describe('test/controllers/registry/package/show.test.js', function () {
|
||||
afterEach(mm.restore);
|
||||
|
||||
before(function (done) {
|
||||
before(function(done) {
|
||||
var pkg = utils.getPackage('@cnpmtest/testmodule-show', '0.0.1', utils.admin);
|
||||
request(app.listen())
|
||||
.put('/' + pkg.name)
|
||||
.set('authorization', utils.adminAuth)
|
||||
.send(pkg)
|
||||
.expect(201, function(err) {
|
||||
should.not.exist(err);
|
||||
pkg = utils.getPackage('@cnpmtest/testmodule-show', '1.1.0', utils.admin);
|
||||
request(app.listen())
|
||||
.put('/' + pkg.name)
|
||||
.set('authorization', utils.adminAuth)
|
||||
.send(pkg)
|
||||
.expect(201, done);
|
||||
});
|
||||
});
|
||||
|
||||
before(function(done) {
|
||||
var pkg = utils.getPackage('@cnpmtest/testmodule-only-beta', '1.0.0-beta.1', utils.admin);
|
||||
request(app.listen())
|
||||
.put('/' + pkg.name)
|
||||
.set('authorization', utils.adminAuth)
|
||||
.send(pkg)
|
||||
.expect(201, done);
|
||||
});
|
||||
|
||||
@@ -45,6 +60,65 @@ describe('controllers/registry/package/show.test.js', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('should return max satisfied package with semver range', function (done) {
|
||||
request(app.listen())
|
||||
.get('/@cnpmtest/testmodule-show/^1.0.0')
|
||||
.expect(200, function (err, res) {
|
||||
should.not.exist(err);
|
||||
var data = res.body;
|
||||
data.name.should.equal('@cnpmtest/testmodule-show');
|
||||
data.version.should.equal('1.1.0');
|
||||
data.dist.tarball.should.containEql('/@cnpmtest/testmodule-show/download/@cnpmtest/testmodule-show-1.1.0.tgz');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should return max satisfied package with complex semver range', function (done) {
|
||||
request(app.listen())
|
||||
.get('/@cnpmtest/testmodule-show/>1.2.0 <=2 || 0.0.1')
|
||||
.expect(200, function (err, res) {
|
||||
should.not.exist(err);
|
||||
var data = res.body;
|
||||
data.name.should.equal('@cnpmtest/testmodule-show');
|
||||
data.version.should.equal('0.0.1');
|
||||
data.dist.tarball.should.containEql('/@cnpmtest/testmodule-show/download/@cnpmtest/testmodule-show-0.0.1.tgz');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should return max satisfied package with *', function (done) {
|
||||
request(app.listen())
|
||||
.get('/@cnpmtest/testmodule-show/*')
|
||||
.expect(200, function (err, res) {
|
||||
should.not.exist(err);
|
||||
var data = res.body;
|
||||
data.name.should.equal('@cnpmtest/testmodule-show');
|
||||
data.version.should.equal('1.1.0');
|
||||
data.dist.tarball.should.containEql('/@cnpmtest/testmodule-show/download/@cnpmtest/testmodule-show-1.1.0.tgz');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should return the only beta version', function (done) {
|
||||
request(app.listen())
|
||||
.get('/@cnpmtest/testmodule-only-beta/*')
|
||||
.expect(200, function (err, res) {
|
||||
should.not.exist(err);
|
||||
var data = res.body;
|
||||
data.name.should.equal('@cnpmtest/testmodule-only-beta');
|
||||
data.version.should.equal('1.0.0-beta.1');
|
||||
data.dist.tarball.should.containEql('/@cnpmtest/testmodule-only-beta/download/@cnpmtest/testmodule-only-beta-1.0.0-beta.1.tgz');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should support jsonp', function (done) {
|
||||
request(app.listen())
|
||||
.get('/@cnpmtest/testmodule-show/0.0.1?callback=jsonp')
|
||||
.expect(/jsonp\(\{/)
|
||||
.expect(200, done);
|
||||
});
|
||||
|
||||
it('should return latest tag', function (done) {
|
||||
request(app.listen())
|
||||
.get('/@cnpmtest/testmodule-show/latest')
|
||||
@@ -52,7 +126,7 @@ describe('controllers/registry/package/show.test.js', function () {
|
||||
should.not.exist(err);
|
||||
var data = res.body;
|
||||
data.name.should.equal('@cnpmtest/testmodule-show');
|
||||
data.version.should.equal('0.0.1');
|
||||
data.version.should.equal('1.1.0');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,11 +1,3 @@
|
||||
/**!
|
||||
* Copyright(c) cnpmjs.org and other contributors.
|
||||
* MIT Licensed
|
||||
*
|
||||
* Authors:
|
||||
* fengmk2 <fengmk2@gmail.com> (http://fengmk2.com)
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
@@ -69,6 +61,7 @@ describe('test/controllers/sync_module_worker.test.js', function () {
|
||||
var worker = new SyncModuleWorker({
|
||||
name: '@sindresorhus/df',
|
||||
username: 'fengmk2',
|
||||
noDep: true,
|
||||
});
|
||||
worker.start();
|
||||
var end = thunkify.event(worker, 'end');
|
||||
|
||||
@@ -1,28 +1,14 @@
|
||||
/*!
|
||||
* cnpmjs.org - test/controllers/web/package/show.test.js
|
||||
*
|
||||
* Copyright(c) cnpmjs.org and other contributors.
|
||||
* MIT Licensed
|
||||
*
|
||||
* Authors:
|
||||
* dead_horse <dead_horse@qq.com> (http://deadhorse.me)
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* Module dependencies.
|
||||
*/
|
||||
|
||||
var should = require('should');
|
||||
var request = require('supertest');
|
||||
var request = require('supertest-as-promised');
|
||||
var mm = require('mm');
|
||||
var config = require('../../../../config');
|
||||
var app = require('../../../../servers/web');
|
||||
var registry = require('../../../../servers/registry');
|
||||
var utils = require('../../../utils');
|
||||
|
||||
describe('controllers/web/package/show.test.js', function () {
|
||||
describe('controllers/web/package/show.test.js', () => {
|
||||
before(function (done) {
|
||||
var pkg = utils.getPackage('@cnpmtest/testmodule-web-show', '0.0.1', utils.admin);
|
||||
pkg.versions['0.0.1'].dependencies = {
|
||||
@@ -113,17 +99,17 @@ describe('controllers/web/package/show.test.js', function () {
|
||||
});
|
||||
});
|
||||
|
||||
describe('unpublished package', function () {
|
||||
before(function (done) {
|
||||
utils.sync('tfs', done);
|
||||
describe('unpublished package', () => {
|
||||
before(done => {
|
||||
utils.sync('mk2testmodule', done);
|
||||
});
|
||||
|
||||
it('should display unpublished info', function (done) {
|
||||
it('should display unpublished info', () => {
|
||||
mm(config, 'syncModel', 'all');
|
||||
request(app)
|
||||
.get('/package/tfs')
|
||||
.expect(200)
|
||||
.expect(/This package has been unpublished\./, done);
|
||||
return request(app)
|
||||
.get('/package/mk2testmodule')
|
||||
.expect(200)
|
||||
.expect(/This package has been unpublished\./);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -149,20 +135,22 @@ describe('controllers/web/package/show.test.js', function () {
|
||||
});
|
||||
});
|
||||
|
||||
describe('show npm package', function () {
|
||||
before(function (done) {
|
||||
describe('show npm package', () => {
|
||||
before(done => {
|
||||
mm(config, 'syncModel', 'exists');
|
||||
utils.sync('pedding', done);
|
||||
});
|
||||
|
||||
it('should show pedding package info and contributors', function (done) {
|
||||
it('should show pedding package info and contributors', () => {
|
||||
mm(config, 'syncModel', 'exists');
|
||||
request(app)
|
||||
.get('/package/pedding')
|
||||
.expect(200)
|
||||
// https://github.com/cnpm/cnpmjs.org/issues/497
|
||||
.expect(/by <a href="\/\~fengmk2">fengmk2<\/a>/)
|
||||
.expect(/pedding/, done);
|
||||
return request(app)
|
||||
.get('/package/pedding')
|
||||
.expect(200)
|
||||
// https://github.com/cnpm/cnpmjs.org/issues/497
|
||||
.expect(/by <a href="\/\~fengmk2">fengmk2<\/a>/)
|
||||
// snyk link
|
||||
.expect(/<a class="badge-link" href="https:\/\/snyk\.io\/test\/npm\/pedding" target="_blank"><img title="Known Vulnerabilities" src="https:\/\/snyk\.io\/test\/npm\/pedding\/badge\.svg\?style=flat-square"><\/a>/)
|
||||
.expect(/pedding/);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
10
test/init.js
10
test/init.js
@@ -1,13 +1,3 @@
|
||||
/**!
|
||||
* cnpmjs.org - test/init.js
|
||||
*
|
||||
* Copyright(c) fengmk2 and other contributors.
|
||||
* MIT Licensed
|
||||
*
|
||||
* Authors:
|
||||
* fengmk2 <fengmk2@gmail.com> (http://fengmk2.github.com)
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,13 +1,3 @@
|
||||
/**!
|
||||
* cnpmjs.org - test/init_db.js
|
||||
*
|
||||
* Copyright(c) fengmk2 and other contributors.
|
||||
* MIT Licensed
|
||||
*
|
||||
* Authors:
|
||||
* fengmk2 <fengmk2@gmail.com> (http://fengmk2.github.com)
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
@@ -22,7 +12,7 @@ var config = require('../config');
|
||||
|
||||
// init db first
|
||||
var initscript = path.join(__dirname, '..', 'models', 'init_script.js');
|
||||
var cmd = ['node', '--harmony', initscript, 'true',
|
||||
var cmd = ['node', initscript, 'true',
|
||||
config.database.dialect, config.database.port, config.database.username].join(' ');
|
||||
console.log('$ %s', cmd);
|
||||
var stdout = childProcess.execSync(cmd);
|
||||
@@ -35,6 +25,7 @@ var usernames = [
|
||||
'cnpmjstest101',
|
||||
'cnpmjstest102',
|
||||
'cnpmjstest103',
|
||||
['cnpmjstest104', 'cnpmjs:test104'],
|
||||
'cnpmjstest10', // admin
|
||||
'cnpmjstestAdmin2', // other admin
|
||||
'cnpmjstestAdmin3', // other admin
|
||||
@@ -43,6 +34,13 @@ var usernames = [
|
||||
|
||||
var count = usernames.length;
|
||||
usernames.forEach(function (name) {
|
||||
var pass;
|
||||
if (Array.isArray(name)) {
|
||||
name = name[0];
|
||||
pass = name[1];
|
||||
} else {
|
||||
pass = name;
|
||||
}
|
||||
var user = User.build({
|
||||
name: name,
|
||||
email: 'fengmk2@gmail.com',
|
||||
@@ -50,7 +48,7 @@ usernames.forEach(function (name) {
|
||||
rev: '1',
|
||||
});
|
||||
user.salt = crypto.randomBytes(30).toString('hex');
|
||||
user.password_sha = User.createPasswordSha(name, user.salt);
|
||||
user.password_sha = User.createPasswordSha(pass, user.salt);
|
||||
user.save().then(function () {
|
||||
count--;
|
||||
if (count === 0) {
|
||||
|
||||
@@ -53,6 +53,13 @@ describe('middleware/auth.test.js', function () {
|
||||
.expect(200, done);
|
||||
});
|
||||
|
||||
it('should pass with authorization (password contains ":") and check ok', function (done) {
|
||||
request(app)
|
||||
.get('/-/user/org.couchdb.user:cnpmjstest104')
|
||||
.set('authorization', 'basic ' + new Buffer('cnpmjstest104:cnpmjs:test104').toString('base64'))
|
||||
.expect(200, done);
|
||||
});
|
||||
|
||||
describe('config.customUserService = true', function () {
|
||||
beforeEach(function () {
|
||||
mm(config, 'customUserService', true);
|
||||
|
||||
@@ -1,13 +1,3 @@
|
||||
/**!
|
||||
* cnpmjs.org - test/middleware/proxy_to_npm.test.js
|
||||
*
|
||||
* Copyright(c) cnpmjs.org and other contributors.
|
||||
* MIT Licensed
|
||||
*
|
||||
* Authors:
|
||||
* fengmk2 <fengmk2@gmail.com> (http://fengmk2.github.com)
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
@@ -19,44 +9,51 @@ var mm = require('mm');
|
||||
var app = require('../../servers/registry');
|
||||
var config = require('../../config');
|
||||
|
||||
describe('middleware/proxy_to_npm.test.js', function () {
|
||||
beforeEach(function () {
|
||||
describe('test/middleware/proxy_to_npm.test.js', () => {
|
||||
beforeEach(() => {
|
||||
mm(config, 'syncModel', 'none');
|
||||
});
|
||||
|
||||
afterEach(mm.restore);
|
||||
|
||||
describe('package', function () {
|
||||
it('should proxy to source registry when package not exists', function (done) {
|
||||
describe('package', () => {
|
||||
it('should proxy to source registry when package not exists', done => {
|
||||
request(app.listen())
|
||||
.get('/ms')
|
||||
.expect('location', config.sourceNpmRegistry + '/ms')
|
||||
.expect(302, done);
|
||||
});
|
||||
|
||||
it('should proxy to source registry when package is not local', function (done) {
|
||||
it('should proxy to source registry when package is not local', done => {
|
||||
request(app.listen())
|
||||
.get('/baidu?write=true')
|
||||
.expect('location', config.sourceNpmRegistry + '/baidu?write=true')
|
||||
.expect(302, done);
|
||||
});
|
||||
|
||||
it('should not proxy to source registry when package is scoped', function (done) {
|
||||
it('should not proxy to source registry when package is private scoped', done => {
|
||||
request(app.listen())
|
||||
.get('/@scoped/test-package-name')
|
||||
.get('/@cnpmtest/test-package-name')
|
||||
.expect(404, done);
|
||||
});
|
||||
|
||||
it('should proxy to source registry when package is public scoped', done => {
|
||||
request(app.listen())
|
||||
.get('/@jkroso/type')
|
||||
.expect('Location', 'https://registry.npmjs.com/@jkroso/type')
|
||||
.expect(302, done);
|
||||
});
|
||||
});
|
||||
|
||||
describe('dist-tags', function () {
|
||||
it('should proxy to source registry when package not exists', function (done) {
|
||||
describe('dist-tags', () => {
|
||||
it('should proxy to source registry when package not exists', done => {
|
||||
request(app.listen())
|
||||
.get('/-/package/ms/dist-tags')
|
||||
.expect('location', config.sourceNpmRegistry + '/-/package/ms/dist-tags')
|
||||
.expect(302, done);
|
||||
});
|
||||
|
||||
it('should dont proxy scoped package', function (done) {
|
||||
it('should dont proxy scoped package', done => {
|
||||
request(app.listen())
|
||||
.get('/-/package/@scoped/ms/dist-tags')
|
||||
.expect(404, done);
|
||||
|
||||
34
test/middleware/sync_by_install.test.js
Normal file
34
test/middleware/sync_by_install.test.js
Normal file
@@ -0,0 +1,34 @@
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* Module dependencies.
|
||||
*/
|
||||
|
||||
var request = require('supertest');
|
||||
var app = require('../../servers/registry');
|
||||
var mm = require('mm');
|
||||
var config = require('../../config');
|
||||
var userService = require('../../services/user');
|
||||
|
||||
describe('test/middleware/sync_by_install.test.js', () => {
|
||||
afterEach(mm.restore);
|
||||
|
||||
it('should ignore sync on install private scoped package', done => {
|
||||
request(app.listen())
|
||||
.get('/@cnpmtest/foo')
|
||||
.set('User-Agent', 'node/v4.4.4')
|
||||
.expect({
|
||||
error: 'not_found',
|
||||
reason: 'document not found',
|
||||
})
|
||||
.expect(404, done);
|
||||
});
|
||||
|
||||
it('should sync and redirect to npmjs.com on install public scoped package', done => {
|
||||
request(app.listen())
|
||||
.get('/@jkroso/type')
|
||||
.set('User-Agent', 'node/v4.4.4')
|
||||
.expect('Location', 'https://registry.npmjs.com/@jkroso/type')
|
||||
.expect(302, done);
|
||||
});
|
||||
});
|
||||
@@ -1,11 +1,9 @@
|
||||
/**!
|
||||
* cnpmjs.org - test/services/default_user_service.test.js
|
||||
*
|
||||
* Copyright(c) fengmk2 and other contributors.
|
||||
/**
|
||||
* Copyright(c) cnpm and other contributors.
|
||||
* MIT Licensed
|
||||
*
|
||||
* Authors:
|
||||
* fengmk2 <fengmk2@gmail.com> (http://fengmk2.github.com)
|
||||
* fengmk2 <fengmk2@gmail.com> (http://fengmk2.com)
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
@@ -47,7 +45,7 @@ describe('services/default_user_service.test.js', function () {
|
||||
email: 'fengmk2@gmail.com',
|
||||
name: 'cnpmjstest10',
|
||||
html_url: 'http://cnpmjs.org/~cnpmjstest10',
|
||||
avatar_url: 'https://secure.gravatar.com/avatar/95b9d41231617a05ced5604d242c9670?s=50&d=retro',
|
||||
avatar_url: 'https://s.gravatar.com/avatar/95b9d41231617a05ced5604d242c9670?s=50&d=retro',
|
||||
im_url: '',
|
||||
site_admin: true,
|
||||
scopes: ['@cnpm', '@cnpmtest'],
|
||||
@@ -69,7 +67,7 @@ describe('services/default_user_service.test.js', function () {
|
||||
email: 'fengmk2@gmail.com',
|
||||
name: 'cnpmjstest10',
|
||||
html_url: 'http://cnpmjs.org/~cnpmjstest10',
|
||||
avatar_url: 'https://secure.gravatar.com/avatar/95b9d41231617a05ced5604d242c9670?s=50&d=retro',
|
||||
avatar_url: 'https://s.gravatar.com/avatar/95b9d41231617a05ced5604d242c9670?s=50&d=retro',
|
||||
im_url: '',
|
||||
site_admin: true,
|
||||
scopes: ['@cnpm', '@cnpmtest'],
|
||||
@@ -84,7 +82,7 @@ describe('services/default_user_service.test.js', function () {
|
||||
email: 'fengmk2@gmail.com',
|
||||
name: 'cnpmjstest101',
|
||||
html_url: 'http://cnpmjs.org/~cnpmjstest101',
|
||||
avatar_url: 'https://secure.gravatar.com/avatar/95b9d41231617a05ced5604d242c9670?s=50&d=retro',
|
||||
avatar_url: 'https://s.gravatar.com/avatar/95b9d41231617a05ced5604d242c9670?s=50&d=retro',
|
||||
im_url: '',
|
||||
site_admin: false,
|
||||
scopes: ['@cnpm', '@cnpmtest'],
|
||||
@@ -99,7 +97,7 @@ describe('services/default_user_service.test.js', function () {
|
||||
email: 'fengmk2@gmail.com',
|
||||
name: 'Yuan Feng',
|
||||
html_url: 'http://cnpmjs.org/~fengmk2',
|
||||
avatar_url: 'https://secure.gravatar.com/avatar/95b9d41231617a05ced5604d242c9670?s=50&d=retro',
|
||||
avatar_url: 'https://s.gravatar.com/avatar/95b9d41231617a05ced5604d242c9670?s=50&d=retro',
|
||||
im_url: '',
|
||||
site_admin: true,
|
||||
scopes: ['@cnpm', '@cnpmtest'],
|
||||
|
||||
@@ -331,6 +331,36 @@ describe('test/services/package.test.js', function () {
|
||||
});
|
||||
});
|
||||
|
||||
describe('getModuleByRange()', function() {
|
||||
it('should get undefined when not match semver range', function* () {
|
||||
yield* createModule('test-getModuleByRange-module-0', '1.0.0');
|
||||
yield* createModule('test-getModuleByRange-module-0', '1.1.0');
|
||||
yield* createModule('test-getModuleByRange-module-0', '2.0.0');
|
||||
var mod = yield* Package.getModuleByRange('test-getModuleByRange-module-0', '~2.1.0');
|
||||
should.not.exist(mod);
|
||||
});
|
||||
|
||||
it('should get package with semver range', function* () {
|
||||
yield* createModule('test-getModuleByRange-module-1', '1.0.0');
|
||||
yield* createModule('test-getModuleByRange-module-1', '1.1.0');
|
||||
yield* createModule('test-getModuleByRange-module-1', '2.0.0');
|
||||
var mod = yield* Package.getModuleByRange('test-getModuleByRange-module-1', '1');
|
||||
mod.package.name.should.equal(mod.name);
|
||||
mod.name.should.equal('test-getModuleByRange-module-1');
|
||||
mod.version.should.equal('1.1.0');
|
||||
});
|
||||
|
||||
it('should get package with semver range when have invalid version', function* () {
|
||||
yield* createModule('test-getModuleByRange-module-2', '1.0.0');
|
||||
yield* createModule('test-getModuleByRange-module-2', '1.1.0');
|
||||
yield* createModule('test-getModuleByRange-module-2', 'next');
|
||||
var mod = yield* Package.getModuleByRange('test-getModuleByRange-module-2', '1');
|
||||
mod.package.name.should.equal(mod.name);
|
||||
mod.name.should.equal('test-getModuleByRange-module-2');
|
||||
mod.version.should.equal('1.1.0');
|
||||
});
|
||||
});
|
||||
|
||||
describe('updateModulePackage()', function () {
|
||||
it('should update not exists package return null', function* () {
|
||||
var r = yield* Package.updateModulePackage(101010101, {});
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
Copyright 2013 - 2014 © cnpmjs.org
|
||||
Copyright 2013 - 2016 © cnpmjs.org
|
||||
|
|
||||
<a href="/">Home</a>
|
||||
|
|
||||
<script>var cnzz_protocol = (("https:" == document.location.protocol) ? " https://" : " http://");document.write(unescape("%3Cspan id='cnzz_stat_icon_5757157'%3E%3C/span%3E%3Cscript src='" + cnzz_protocol + "s17.cnzz.com/stat.php%3Fid%3D5757157%26online%3D1%26show%3Dline' type='text/javascript'%3E%3C/script%3E"));</script>
|
||||
<script>var cnzz_protocol = (("https:" == document.location.protocol) ? " https://" : " http://");document.write(unescape("%3Cspan id='cnzz_stat_icon_5757157'%3E%3C/span%3E%3Cscript src='" + cnzz_protocol + "s17.cnzz.com/stat.php%3Fid%3D5757157%26online%3D1%26show%3Dline' type='text/javascript'%3E%3C/script%3E"));</script>
|
||||
|
||||
@@ -15,13 +15,16 @@
|
||||
<% } %>
|
||||
<div class="pack-ver">
|
||||
<img title="<%= package.version %>" src="/badge/v/<%= package.name %>.svg?style=flat-square">
|
||||
<% if (package.engines) {%>
|
||||
<% if (package.engines) { %>
|
||||
<% for (var k in package.engines) {
|
||||
var engine = package.engines[k];
|
||||
%>
|
||||
<img title="<%= engine.title %>" src="<%- engine.badgeURL %>">
|
||||
<% }
|
||||
}%>
|
||||
} %>
|
||||
<% if (package.snyk) { %>
|
||||
<a class="badge-link" href="<%= package.snyk.url %>" target="_blank"><img title="Known Vulnerabilities" src="<%- package.snyk.badge %>"></a>
|
||||
<% } %>
|
||||
</div>
|
||||
<div class="pack-repo">
|
||||
<% if (package.fromNow) { %>
|
||||
@@ -52,14 +55,19 @@
|
||||
|
||||
<% if (package.license || package.repository || package.bugs.url) {%> · <% } %>
|
||||
|
||||
<% if (!package._publish_on_cnpm) { %>
|
||||
<% if (!package.isPrivate) { %>
|
||||
<a href="https://www.npmjs.org/package/<%= package.name %>" target="_blank">Original npm</a>
|
||||
<% } %>
|
||||
|
||||
<% if (package.dist.tarball) { %>
|
||||
·
|
||||
<a href="<%= package.dist.tarball %>" target="_blank">Tarball</a>
|
||||
<% } %>
|
||||
</div>
|
||||
<div class="pack-install">
|
||||
<pre class="sh">$ <%- config.npmClientName %> install <%= package.name %> <% if (package.preferGlobal) { %>-g<% } %></pre>
|
||||
<div class="pack-sync">
|
||||
<% if (package._publish_on_cnpm) { %>
|
||||
<% if (package.isPrivate) { %>
|
||||
Private package
|
||||
<% } else { %>
|
||||
<a href="/sync/<%= package.name %>" target="_blank">SYNC</a> missed versions from
|
||||
|
||||
13
worker.js
13
worker.js
@@ -1,18 +1,5 @@
|
||||
/**!
|
||||
* Copyright(c) cnpmjs.org and other contributors.
|
||||
* MIT Licensed
|
||||
*
|
||||
* Authors:
|
||||
* dead_horse <dead_horse@qq.com>
|
||||
* fengmk2 <fengmk2@gmail.com> (http://fengmk2.com)
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* Module dependencies.
|
||||
*/
|
||||
|
||||
var graceful = require('graceful');
|
||||
var registry = require('./servers/registry');
|
||||
var web = require('./servers/web');
|
||||
|
||||
Reference in New Issue
Block a user