Compare commits
25 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ff50946cd3 | ||
|
|
3637eeefdd | ||
|
|
cecb41e6ea | ||
|
|
72b3240ef5 | ||
|
|
869d5681ce | ||
|
|
ff1bfd5acc | ||
|
|
7e3129c8b8 | ||
|
|
0618c732d7 | ||
|
|
9b34ab408c | ||
|
|
d990d3aa91 | ||
|
|
03ef728049 | ||
|
|
f00ed85d41 | ||
|
|
685af2a367 | ||
|
|
818f216fb4 | ||
|
|
1b47495565 | ||
|
|
0ab314f27c | ||
|
|
95076c8787 | ||
|
|
4e6eb0a9cc | ||
|
|
29f17dd5d1 | ||
|
|
3a48637ef1 | ||
|
|
e1029b005f | ||
|
|
66771dfc3b | ||
|
|
66f05a2f07 | ||
|
|
6660cabbb6 | ||
|
|
fbe1971957 |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -22,3 +22,4 @@ docs/web/history.md
|
||||
view/web/_layout.html
|
||||
bin/mysql.js
|
||||
bin/test.sql
|
||||
coverage/
|
||||
|
||||
@@ -10,3 +10,4 @@ backup/*.json
|
||||
backup/*.gz
|
||||
view/web/_layout.html
|
||||
bin/mysql.js
|
||||
coverage/
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
language: node_js
|
||||
node_js:
|
||||
- '0.11'
|
||||
script: make test-coveralls
|
||||
|
||||
2
AUTHORS
2
AUTHORS
@@ -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)
|
||||
|
||||
26
History.md
26
History.md
@@ -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
|
||||
==================
|
||||
|
||||
|
||||
38
Makefile
38
Makefile
@@ -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
|
||||
|
||||
|
||||
@@ -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;
|
||||
};
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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]
|
||||
|
||||
@@ -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);
|
||||
|
||||
27
package.json
27
package.json
@@ -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": {
|
||||
|
||||
@@ -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());
|
||||
|
||||
|
||||
@@ -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');
|
||||
|
||||
|
||||
@@ -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 () {
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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();
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user