Compare commits

...

25 Commits
0.3.1 ... 0.3.4

Author SHA1 Message Date
fengmk2
ff50946cd3 Release 0.3.4 2014-03-04 16:32:25 +08:00
fengmk2
3637eeefdd add cov 2014-03-04 16:31:22 +08:00
dead_horse
cecb41e6ea Merge pull request #243 from cnpm/coverage
use istanbul run test coverage
2014-03-03 21:52:52 +08:00
fengmk2
72b3240ef5 use istanbul run test coverage 2014-03-03 21:02:11 +08:00
dead_horse
869d5681ce Merge pull request #242 from cnpm/gzip
gzip support. fix #241
2014-03-03 16:45:37 +08:00
fengmk2
ff1bfd5acc gzip support. fix #241 2014-03-03 16:44:29 +08:00
dead_horse
7e3129c8b8 Merge pull request #240 from stanzheng/patch-1
readme spelling patch
2014-03-03 00:42:27 +08:00
Stanley Zheng
0618c732d7 thanks dead_horse 2014-03-02 11:39:30 -05:00
Stanley Zheng
9b34ab408c readme spelling patch 2014-03-02 11:10:40 -05:00
fengmk2
d990d3aa91 Merge pull request #234 from cnpm/issue233-remove-readme
Issue233 remove readme
2014-02-28 23:25:08 +08:00
dead_horse
03ef728049 default readme to null, fixed #233 2014-02-28 22:37:45 +08:00
dead_horse
f00ed85d41 remove readme in versions 2014-02-28 22:32:44 +08:00
fengmk2
685af2a367 Release 0.3.3 2014-02-28 17:41:09 +08:00
dead_horse
818f216fb4 Merge pull request #232 from cnpm/host-hotfix
get request host from request.headers
2014-02-28 16:36:44 +08:00
fengmk2
1b47495565 get request host from request.headers 2014-02-28 16:35:51 +08:00
dead_horse
0ab314f27c Merge pull request #231 from cnpm/bug-fix
fix deps display bug#230 and nsf.url TypeError#229
2014-02-28 15:40:04 +08:00
fengmk2
95076c8787 fix deps display bug#230 and nsf.url TypeError#229 2014-02-28 15:35:37 +08:00
fengmk2
4e6eb0a9cc Release 0.3.2 2014-02-28 14:46:17 +08:00
fengmk2
29f17dd5d1 Merge pull request #228 from cnpm/update-sess
update koa-sess and koa-redis
2014-02-28 14:42:03 +08:00
dead_horse
3a48637ef1 update koa-sess and koa-redis 2014-02-28 14:40:47 +08:00
fengmk2
e1029b005f Merge pull request #227 from cnpm/fix-nfs
Fix nfs
2014-02-28 12:20:43 +08:00
dead_horse
66771dfc3b fix sync all test 2014-02-28 12:15:30 +08:00
dead_horse
66f05a2f07 remove nfs.downloadStream first, fix tmppath error 2014-02-28 12:04:28 +08:00
fengmk2
6660cabbb6 Merge pull request #226 from cnpm/giturl-bug-fix
fix fengmk2/giturl#1 bug
2014-02-27 20:53:33 +08:00
fengmk2
fbe1971957 fix fengmk2/giturl#1 bug 2014-02-27 20:52:19 +08:00
16 changed files with 112 additions and 85 deletions

1
.gitignore vendored
View File

@@ -22,3 +22,4 @@ docs/web/history.md
view/web/_layout.html
bin/mysql.js
bin/test.sql
coverage/

View File

@@ -10,3 +10,4 @@ backup/*.json
backup/*.gz
view/web/_layout.html
bin/mysql.js
coverage/

View File

@@ -1,4 +1,3 @@
language: node_js
node_js:
- '0.11'
script: make test-coveralls

View File

@@ -1,5 +1,5 @@
# Ordered by date of first contribution.
# Auto-generated by 'contributors' on Fri, 24 Jan 2014 08:35:59 GMT.
# Auto-generated by 'contributors' on Mon, 03 Mar 2014 13:01:28 GMT.
# https://github.com/xingrz/node-contributors
fengmk2 <fengmk2@gmail.com> (https://github.com/fengmk2)

View File

@@ -1,4 +1,30 @@
0.3.4 / 2014-03-04
==================
* add cov
* use istanbul run test coverage
* gzip support. fix #241
* readme spelling patch (@stanzheng)
* default readme to null, fixed #233
* remove readme in versions
0.3.3 / 2014-02-28
==================
* Merge pull request #232 from cnpm/host-hotfix
* get request host from request.headers
* Merge pull request #231 from cnpm/bug-fix
* fix deps display bug#230 and nsf.url TypeError#229
0.3.2 / 2014-02-28
==================
* update koa-sess and koa-redis
* fix sync all test
* remove nfs.downloadStream first, fix tmppath error
* fix fengmk2/giturl#1 bug
0.3.1 / 2014-02-27
==================

View File

@@ -4,35 +4,33 @@ TIMEOUT = 30000
MOCHA_OPTS =
install:
@npm install --registry=http://registry.cnpmjs.org --cache=${HOME}/.npm/.cache/cnpm --disturl=http://dist.u.qiniudn.com
@npm install --registry=http://registry.cnpmjs.org \
--cache=${HOME}/.npm/.cache/cnpm --disturl=http://dist.u.qiniudn.com
test: install
@NODE_ENV=test ./node_modules/mocha/bin/mocha \
--harmony-generators \
test:
@NODE_ENV=test node --harmony \
node_modules/.bin/istanbul cover ./node_modules/.bin/_mocha \
-- -u exports \
--reporter $(REPORTER) \
--timeout $(TIMEOUT) \
--require should \
$(MOCHA_OPTS) \
$(TESTS)
@-$(MAKE) check-coverage
test-cov:
@$(MAKE) test MOCHA_OPTS='--require blanket' REPORTER=travis-cov
check-coverage:
@./node_modules/.bin/istanbul check-coverage \
--statements 100 \
--functions 100 \
--branches 100 \
--lines 100
test-cov-html:
@rm -f coverage.html
@$(MAKE) test MOCHA_OPTS='--require blanket' REPORTER=html-cov > coverage.html
@ls -lh coverage.html
cov:
@./node_modules/.bin/cov coverage
test-coveralls: test
@echo TRAVIS_JOB_ID $(TRAVIS_JOB_ID)
@-$(MAKE) test MOCHA_OPTS='--require blanket' REPORTER=mocha-lcov-reporter | ./node_modules/coveralls/bin/coveralls.js
contributors:
@./node_modules/.bin/contributors -f plain -o AUTHORS
test-all: test test-cov
contributors: install
@./node_modules/contributors/bin/contributors -f plain -o AUTHORS
autod: install
autod:
@./node_modules/.bin/autod -w -e public,view,docs,backup
@$(MAKE) install

View File

@@ -69,7 +69,7 @@ exports.show = function *(next) {
var nextMod = null;
var latestMod = null;
var readme = null;
// set tags
var distTags = {};
for (var i = 0; i < tags.length; i++) {
@@ -94,7 +94,9 @@ exports.show = function *(next) {
times[pkg.version] = row.publish_time ? new Date(row.publish_time) : row.gmt_modified;
if ((!distTags.latest && !latestMod) || distTags.latest === row.version) {
latestMod = row;
readme = pkg.readme;
}
delete pkg.readme;
}
if (!latestMod) {
@@ -121,7 +123,7 @@ exports.show = function *(next) {
author: latestMod.package.author,
repository: latestMod.package.repository,
versions: versions,
readme: latestMod.package.readme,
readme: readme,
_attachments: attachments,
};
@@ -182,10 +184,14 @@ exports.download = function *(next) {
var version = filename.slice(name.length + 1, -4);
var row = yield Module.get(name, version);
// can not get dist
var url = nfs.url(common.getCDNKey(name, filename));
var url = null;
if (typeof nfs.url === 'function') {
url = nfs.url(common.getCDNKey(name, filename));
}
if (!row || !row.package || !row.package.dist) {
if (!nfs.url) {
if (!url) {
return yield next;
}
this.status = 302;
@@ -193,6 +199,7 @@ exports.download = function *(next) {
_downloads[name] = (_downloads[name] || 0) + 1;
return;
}
var dist = row.package.dist;
if (!dist.key) {
debug('get tarball by 302');
@@ -203,7 +210,7 @@ exports.download = function *(next) {
}
// else use `dist.key` to get tarball from nfs
if (!nfs.downloadStream && !nfs.download) {
if (!nfs.download) {
return yield next;
}
@@ -216,13 +223,9 @@ exports.download = function *(next) {
this.set('Content-Disposition', 'attachment; filename="' + filename + '"');
this.set('ETag', dist.shasum);
if (nfs.downloadStream) {
yield nfs.downloadStream(dist.key, this.res, {timeout: DOWNLOAD_TIMEOUT});
return;
}
// use download file api
var tmpPath = path.join(config.uploadDir, utility.randomString() + dist.key);
var tmpPath = path.join(config.uploadDir,
utility.randomString() + dist.key.replace(/\//g, '-'));
function cleanup() {
fs.unlink(tmpPath, utility.noop);
}
@@ -233,8 +236,8 @@ exports.download = function *(next) {
this.throw(err);
}
var tarball = fs.createReadStream(tmpPath);
tarball.on('error', cleanup);
tarball.on('end', cleanup);
tarball.once('error', cleanup);
tarball.once('end', cleanup);
this.body = tarball;
};

View File

@@ -51,7 +51,9 @@ exports.display = function *(next) {
];
var pkg = r[0];
var download = r[1];
var dependents = r[2];
var dependents = (r[2] || []).map(function (item) {
return item.deps;
});
if (!pkg || !pkg.package) {
return yield next;
@@ -90,7 +92,7 @@ exports.display = function *(next) {
}
if (pkg.repository && pkg.repository.url) {
pkg.repository.weburl = giturl.parse(pkg.repository.url);
pkg.repository.weburl = giturl.parse(pkg.repository.url) || pkg.repository.url;
}
setLicense(pkg);

View File

@@ -139,7 +139,7 @@ $ npm install cnpm -g
### install
Install package from [r.cnpmjs.org](http://r.cnpmjs.org). When isntall a package or version not exist, it will try to install from official registry([registry.npmjs.org](http://registry.npmjs.org)), and sync this package to cnpm in the backend.
Install package from [r.cnpmjs.org](http://r.cnpmjs.org). When installing a package or version does not exist, it will try to install from the official registry([registry.npmjs.org](http://registry.npmjs.org)), and sync this package to cnpm in the backend.
```
$ cnpm install [name]

View File

@@ -31,7 +31,7 @@ exports.getCDNKey = function (name, filename) {
exports.setDownloadURL = function (pkg, ctx, host) {
if (pkg.dist) {
host = host || ctx.host;
host = host || ctx.get('host') || ctx.host;
pkg.dist.tarball = util.format('%s://%s/%s/download/%s-%s.tgz',
ctx.protocol,
host, pkg.name, pkg.name, pkg.version);

View File

@@ -1,35 +1,32 @@
{
"name": "cnpmjs.org",
"version": "0.3.1",
"version": "0.3.4",
"description": "Private npm registry and web for Enterprise, base on MySQL and Simple Store Service",
"main": "index.js",
"scripts": {
"test": "make test-all",
"test": "make test",
"start": "./bin/nodejsctl start && cp History.md docs/web/history.md",
"status": "./bin/nodejsctl status",
"stop": "./bin/nodejsctl stop"
},
"config": {
"blanket": {
"pattern": "//^((?!(node_modules|test|common)).)*$/"
},
"travis-cov": {
"threshold": 90
"cov": {
"threshold": 83
}
},
"dependencies": {
"co-read": "0.0.1",
"co-write": "0.3.0",
"debug": "0.7.4",
"eventproxy": "0.2.6",
"eventproxy": "0.3.0",
"forward": "0.0.4",
"giturl": "0.0.1",
"giturl": "0.0.2",
"graceful": "0.0.6",
"gravatar": "1.0.6",
"humanize-number": "0.0.2",
"koa": "0.5.0",
"koa-markdown": "0.0.2",
"koa-middlewares": "0.0.5",
"koa-middlewares": "0.0.8",
"logfilestream": "0.1.0",
"marked": "0.3.1",
"microtime": "0.5.1",
@@ -42,22 +39,20 @@
"qn": "0.2.0",
"ready": "0.1.1",
"semver": "2.2.1",
"thunkify-wrap": "0.0.1",
"thunkify-wrap": "0.0.3",
"urllib": "0.5.5",
"utility": "0.1.10"
},
"devDependencies": {
"autod": ">=0.0.13",
"blanket": "*",
"contributors": "*",
"coveralls": "*",
"cov": "*",
"istanbul": "git://github.com/gotwarlost/istanbul.git#harmony",
"mm": "0.2.0",
"mocha": "*",
"mocha-lcov-reporter": "*",
"pedding": "0.0.3",
"should": "3.1.3",
"supertest": "0.9.0",
"travis-cov": "*"
"supertest": "0.9.0"
},
"homepage": "https://github.com/cnpm/cnpmjs.org",
"repository": {

View File

@@ -40,6 +40,7 @@ app.use(middlewares.bodyParser({jsonLimit: config.jsonLimit}));
app.use(auth());
app.use(notFound);
app.use(middlewares.gzip());
app.use(middlewares.fresh());
app.use(middlewares.etag());

View File

@@ -45,6 +45,10 @@ app.use(session);
app.use(middlewares.bodyParser());
app.use(notFound);
app.use(middlewares.gzip());
app.use(middlewares.fresh());
app.use(middlewares.etag());
var viewDir = path.join(rootdir, 'view', 'web');
var docDir = path.join(rootdir, 'docs', 'web');

View File

@@ -86,6 +86,26 @@ describe('controllers/registry/module.test.js', function () {
});
});
it('should return module info and gzip when accept-encoding=gzip', function (done) {
request(app)
.get('/cnpmjs.org')
.set('accept-encoding', 'gzip')
.expect('content-encoding', 'gzip')
.expect(200, function (err, res) {
// console.log(res.headers)
should.not.exist(err);
// should have etag
res.headers.should.have.property('etag');
etag = res.headers.etag;
res.body.should.have.keys('_id', '_rev', 'name', 'description',
'versions', 'dist-tags', 'readme', 'maintainers',
'time', 'author', 'repository', '_attachments');
res.body.name.should.equal('cnpmjs.org');
res.body.versions[Object.keys(res.body.versions)[0]].dist.tarball.should.include('/cnpmjs.org/download');
done();
});
});
it('should 304 when etag match', function (done) {
request(app)
.get('/cnpmjs.org')
@@ -537,34 +557,6 @@ describe('controllers/registry/module.test.js', function () {
.expect('Location', 'http://qtestbucket.qiniudn.com/cutter/-/cutter-0.0.2.tgz')
.expect(302, done)
});
it('should download a file direct from nfs stream', function (done) {
var nfs = require('../../../common/nfs');
mm(nfs, 'downloadStream', thunkify(function (key, writeStream, options, callback) {
options.timeout.should.equal(600000);
nfs._client.download(key, {writeStream: writeStream, timeout: options.timeout}, callback);
}));
Module.__get__ = Module.get;
mm(Module, 'get', thunkify(function (name, version, callback) {
Module.__get__(name, version, function (err, info) {
info.package.dist.key = 'cutter/-/cutter-0.0.2.tgz';
callback(err, info);
});
}));
request(app)
.get('/cutter/download/cutter-0.0.2.tgz')
.expect('ETag', 'c61fde5e8c26d053574d0c722097029fd1bc963a')
.expect('Content-Type', 'application/octet-stream')
.expect('Content-Length', '3139')
.expect('Content-Disposition', 'attachment; filename="cutter-0.0.2.tgz"')
.expect(200)
.end(function (err, res) {
should.not.exist(err);
// TODO: why supertest change buffer to text?
// res.text.length.should.equal(3139);
done();
});
});
});
describe('DELETE /:name/download/:filename/-rev/:rev', function () {

View File

@@ -78,9 +78,14 @@ describe('controllers/web/package.test.js', function () {
request(app)
.get('/package/cutter')
.expect(200)
.expect('content-encoding', 'gzip')
.expect(/<div id="package">/)
.expect(/<th>Maintainers<\/th>/)
.expect(/<th>Version<\/th>/, done);
.expect(/<th>Version<\/th>/, function (err, res) {
should.not.exist(err);
res.should.have.header('etag');
done();
});
});
it('should get 404', function (done) {

View File

@@ -50,7 +50,7 @@ describe('sync/sync_all.js', function () {
mm.data(Module, 'listAllModuleNames', [{name: 'cnpmjs.org'}, {name: 'cutter'}]);
sync(function (err, data) {
should.not.exist(err);
data.successes.should.eql(['cnpm', 'cnpmjs.org', 'cutter']);
data.successes.should.eql(['cnpmjs.org', 'cutter']);
done();
});
});