Compare commits

...

38 Commits

Author SHA1 Message Date
fengmk2
17f47732a0 Release 2.7.0 2016-02-01 13:16:35 +08:00
fengmk2
3a46b97544 Merge pull request #816 from cnpm/feat-semver
feat: support semver
2016-02-01 11:56:21 +08:00
dead_horse
44976f4afa test: fix all test cases 2016-02-01 01:42:09 +08:00
dead_horse
9da7c6ccf2 test: fix unpublish 2016-01-31 00:14:46 +08:00
dead_horse
4b68eecf53 test: add complex range test case 2016-01-30 23:08:27 +08:00
dead_horse
8d7058b947 feat: support semver
e.x. `/npm/~1.0.0`
2016-01-30 20:42:59 +08:00
dead_horse
933ae69d0b Release 2.6.2 2016-01-19 11:44:23 +08:00
Yiyu He
1af36f0a7a Merge pull request #799 from cnpm/jsonp
feat: list & show support jsonp
2016-01-19 11:43:24 +08:00
dead_horse
f4e9de5094 feat: list & show support jsonp 2016-01-18 11:07:21 +08:00
Yiyu He
2ccaf404ab Merge pull request #795 from cnpm/greenkeeper-urllib-2.7.0
Update urllib to version 2.7.0 🚀
2016-01-14 11:11:53 +08:00
greenkeeperio-bot
44c79c7646 chore(package): update urllib to version 2.7.0
http://greenkeeper.io/
2016-01-14 01:30:25 +08:00
alsotang
a845d3f74d Delete install.md
this file is deprecated, see https://github.com/cnpm/cnpmjs.org/wiki/Deploy for deploy
2016-01-13 11:54:59 +08:00
fengmk2
730113424c Release 2.6.1 2016-01-12 17:34:23 +08:00
fengmk2
658be3004f fix: source registry is not cnpm, ignore check status 2016-01-12 17:33:53 +08:00
fengmk2
214d0ad5c3 Release 2.6.0 2016-01-12 11:54:25 +08:00
Yiyu He
ca70c8a06d Merge pull request #786 from cnpm/add-sync-expired-check
feat(sync): monitor sync status
2016-01-12 10:20:02 +08:00
fengmk2
1c680367a7 feat(sync): monitor sync status
if last_sync_time > 2 x syncInterval, send the expired
warning message to admin
2016-01-12 10:11:20 +08:00
Yiyu He
3bd43d5ba9 Merge pull request #759 from cnpm/greenkeeper-urllib-2.6.0
Update urllib to version 2.6.0 🚀
2016-01-07 00:25:43 +08:00
Yiyu He
0965f8f8e5 Merge pull request #779 from cnpm/greenkeeper-agentkeepalive-2.0.3
Update agentkeepalive to version 2.0.3 🚀
2016-01-06 10:47:57 +08:00
greenkeeperio-bot
005eb603ae chore(package): update agentkeepalive to version 2.0.3
http://greenkeeper.io/
2016-01-05 20:40:22 +08:00
Yiyu He
65a9303dff Merge pull request #777 from gniavaj/master
fix SequelizeDatabaseError: ER_NO_SUCH_TABLE: Table 'qnpm.total' does…
2016-01-05 16:26:36 +08:00
gniavaj
3bc6b625ec fix SequelizeDatabaseError: ER_NO_SUCH_TABLE: Table 'qnpm.total' doesn't exist\nreproduce this bug:\nthe first startup of cnpmjs.org 2016-01-04 21:43:50 +08:00
Yiyu He
2b0dc6d17f Merge pull request #773 from cnpm/greenkeeper-moment-2.11.0
Update moment to version 2.11.0 🚀
2016-01-04 10:39:49 +08:00
Yiyu He
842d790dcb Merge pull request #774 from cnpm/greenkeeper-xss-0.2.10
xss@0.2.10 breaks build 🚨
2016-01-04 10:37:26 +08:00
greenkeeperio-bot
20eac48349 chore(package): update moment to version 2.11.0
http://greenkeeper.io/
2016-01-03 07:42:58 +08:00
greenkeeperio-bot
efb80e8c33 chore(package): update xss to version 0.2.10
http://greenkeeper.io/
2015-12-23 12:42:54 +08:00
alsotang
35fbc651cd remove bluebird
same as #767
2015-12-17 13:34:33 +08:00
Yiyu He
e55779ffa7 Merge pull request #767 from liyangready/master
remove bluebird
2015-12-17 11:12:23 +08:00
leon.lee
878176ea9c remove bluebird
maybe forget remove bluebird in this file
2015-12-17 11:08:49 +08:00
Yiyu He
e3a2eab000 Merge pull request #764 from cnpm/greenkeeper-pg-hstore-2.3.2
pg-hstore@2.3.2 breaks build ⚠️
2015-12-14 15:54:29 +08:00
greenkeeperio-bot
7478846754 chore(package): update pg-hstore to version 2.3.2
http://greenkeeper.io/
2015-12-14 08:31:56 +08:00
Yiyu He
8b244e6c26 Merge pull request #761 from cnpm/greenkeeper-mini-logger-1.1.0
Update mini-logger to version 1.1.0 🚀
2015-12-12 00:10:05 +08:00
greenkeeperio-bot
19217de010 chore(package): update mini-logger to version 1.1.0
http://greenkeeper.io/
2015-12-11 12:04:38 +08:00
greenkeeperio-bot
93a57b5dae chore(package): update urllib to version 2.6.0
http://greenkeeper.io/
2015-12-09 14:13:25 +08:00
Yiyu He
defb447f29 Merge pull request #756 from cnpm/fix-package-decode-error
fix: row.package will json parse error
2015-12-08 20:45:03 +08:00
fengmk2
93b73de164 Merge pull request #754 from cnpm/remove_bluebird
remove bluebird
2015-12-08 16:44:50 +08:00
fengmk2
ffc6124c0e fix: row.package will json parse error
need to ignore it.

also remove array.map on parseRow
2015-12-08 16:20:47 +08:00
Jackson Tian
ab40a992c2 remove bluebird 2015-12-08 12:03:36 +08:00
17 changed files with 209 additions and 166 deletions

View File

@@ -1,4 +1,39 @@
2.7.0 / 2016-02-01
==================
* test: fix all test cases
* test: fix unpublish
* test: add complex range test case
* feat: support semver
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
==================
* feat(sync): monitor sync status
* chore(package): update agentkeepalive to version 2.0.3
* fix SequelizeDatabaseError: ER_NO_SUCH_TABLE: Table 'qnpm.total' doesn't exist\nreproduce this bug:\nthe first startup of cnpmjs.org
* chore(package): update moment to version 2.11.0
* chore(package): update xss to version 0.2.10
* chore(package): update pg-hstore to version 2.3.2
* chore(package): update mini-logger to version 1.1.0
* chore(package): update urllib to version 2.6.0
* fix: row.package will json parse error
* remove bluebird
* chore(package): update utility to version 1.6.0
2.5.1 / 2015-12-02
==================
@@ -59,7 +94,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
@@ -156,10 +191,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
==================

View File

@@ -112,7 +112,7 @@ autod: install
@node_modules/.bin/autod -w \
--prefix "~" \
--exclude public,view,docs,backup,coverage \
--dep bluebird,mysql \
--dep mysql \
--keep should,supertest,should-http,chunkstream,mm,pedding
@$(MAKE) install

View File

@@ -83,9 +83,10 @@ function start(options) {
debug('save config %s to %s', configJSON, configfile);
// if sqlite db file not exists, init first
initDatabase();
initDatabase(function() {
require('../dispatch');
});
require('../dispatch');
fs.writeFileSync(path.join(dataDir, 'pid'), process.pid + '');
}
@@ -105,7 +106,7 @@ function stop(options) {
}
}
function initDatabase() {
function initDatabase(callback) {
var models = require('../models');
models.sequelize.sync({ force: false })
@@ -117,6 +118,7 @@ function initDatabase() {
throw err;
} else {
console.log('[models/init_script.js] `sqlite` sequelize sync and init success');
callback();
}
});
})

View File

@@ -1,11 +1,9 @@
/**!
* cnpmjs.org - controllers/registry/package/list.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';
@@ -130,6 +128,10 @@ module.exports = function* list() {
for (var i = 0; i < rows.length; i++) {
var row = rows[i];
var pkg = row.package;
// pkg is string ... ignore it
if (typeof pkg === 'string') {
continue;
}
common.setDownloadURL(pkg, this);
pkg._cnpm_publish_time = row.publish_time;
versions[pkg.version] = pkg;
@@ -196,5 +198,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;
};

View File

@@ -31,12 +31,16 @@ module.exports = function* show() {
var name = this.params.name || this.params[0];
var tag = this.params.version || this.params[1];
var version = semver.valid(tag);
var range = semver.validRange(tag);
var mod;
if (version) {
mod = yield* packageService.getModule(name, version);
} else if (range) {
mod = yield* packageService.getModuleByRange(name, range);
} else {
mod = yield* packageService.getModuleByTag(name, tag);
}
if (mod) {
setDownloadURL(mod.package, this);
mod.package._cnpm_publish_time = mod.publish_time;
@@ -44,14 +48,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
};

View File

@@ -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
```

View File

@@ -1,6 +1,6 @@
{
"name": "cnpmjs.org",
"version": "2.5.1",
"version": "2.7.0",
"description": "Private npm registry and web for Enterprise, base on MySQL and Simple Store Service",
"main": "index.js",
"scripts": {
@@ -13,8 +13,7 @@
"cnpmjs.org": "bin/cli.js"
},
"dependencies": {
"agentkeepalive": "~1.2.0",
"bluebird": "~3.0.6",
"agentkeepalive": "~2.0.3",
"bytes": "~2.2.0",
"cfork": "~1.4.0",
"co": "~4.6.0",
@@ -41,9 +40,9 @@
"koa-safe-jsonp": "~0.3.0",
"markdown-it": "~3.0.6",
"mime": "~1.3.4",
"mini-logger": "~1.0.0",
"mini-logger": "~1.1.0",
"mkdirp": "~0.5.0",
"moment": "~2.10.6",
"moment": "~2.11.0",
"mysql": "~2.5.4",
"nodemailer": "~1.3.0",
"semver": "~5.1.0",
@@ -51,9 +50,9 @@
"thunkify-wrap": "~1.0.4",
"treekill": "~1.0.0",
"tunnel-agent": "^0.4.0",
"urllib": "~2.5.0",
"urllib": "~2.7.0",
"utility": "~1.6.0",
"xss": "~0.2.8"
"xss": "~0.2.10"
},
"devDependencies": {
"autod": "*",
@@ -67,7 +66,7 @@
"node-dev": "*",
"pedding": "*",
"pg": "~4.4.2",
"pg-hstore": "~2.3.1",
"pg-hstore": "~2.3.2",
"should": "~7.1.0",
"should-http": "*",
"sqlite3": "*",

View File

@@ -65,9 +65,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);

View File

@@ -15,7 +15,6 @@
* Module dependencies.
*/
global.Promise = require('bluebird');
var koa = require('koa');
var app = module.exports = koa();
var http = require('http');

View File

@@ -15,7 +15,6 @@
* Module dependencies.
*/
global.Promise = require('bluebird');
var opensearch = require('../middleware/opensearch');
var notFound = require('../middleware/web_not_found');
var staticCache = require('../middleware/static');

View File

@@ -1,4 +1,4 @@
/**!
/**
* Copyright(c) cnpm and other contributors.
* MIT Licensed
*
@@ -12,6 +12,7 @@
* Module dependencies.
*/
var semver = require('semver');
var models = require('../models');
var common = require('./common');
var Tag = models.Tag;
@@ -73,6 +74,18 @@ exports.getModuleByTag = function* (name, tag) {
return yield* exports.getModule(tag.name, tag.version);
};
exports.getModuleByRange = function* (name, range) {
var rows = yield* exports.listModulesByName(name);
var versionMap = {};
var versions = rows.map(function(row) {
versionMap[row.version] = row;
return row.version;
});
var version = semver.maxSatisfying(versions, range);
return versionMap[version];
};
exports.getLatestModule = function* (name) {
return yield* exports.getModuleByTag(name, 'latest');
};
@@ -233,10 +246,11 @@ exports.listModulesByName = function* (moduleName) {
},
order: [ ['id', 'DESC'] ]
});
return mods.map(function (mod) {
for (var mod of mods) {
parseRow(mod);
return mod;
});
}
return mods;
};
exports.getModuleLastModified = function* (name) {

View File

@@ -1,11 +1,9 @@
/**!
* cnpmjs.org - services/total.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';

View File

@@ -1,11 +1,10 @@
/**!
* cnpmjs.org - sync/index.js
*
* Copyright(c) cnpmjs.org and other contributors.
/**
* 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';
@@ -14,7 +13,6 @@
* Module dependencies.
*/
global.Promise = require('bluebird');
var debug = require('debug')('cnpmjs.org:sync:index');
var co = require('co');
var ms = require('humanize-ms');
@@ -49,7 +47,8 @@ function onerror(err) {
//set sync_status = 0 at first
co(function* () {
yield* totalService.updateSyncStatus(0);
yield totalService.updateSyncStatus(0);
yield checkSyncStatus();
}).catch(onerror);
var syncInterval = ms(config.syncInterval);
@@ -68,7 +67,7 @@ var syncFn = co.wrap(function* () {
var data;
var error;
try {
data = yield* sync();
data = yield sync();
} catch (err) {
error = err;
error.message += ' (sync package error)';
@@ -80,6 +79,9 @@ var syncFn = co.wrap(function* () {
}
syncing = false;
}
// check last_sync_time and last_exist_sync_time
yield checkSyncStatus();
});
if (sync) {
@@ -104,7 +106,7 @@ var syncPopularFn = co.wrap(function* syncPopular() {
var data;
var error;
try {
data = yield* startSyncPopular();
data = yield startSyncPopular();
} catch (err) {
error = err;
error.message += ' (sync package error)';
@@ -174,3 +176,27 @@ function sendMailToAdmin(err, result, syncTime) {
});
}
}
function* checkSyncStatus() {
// if source registry not cnpm, ignore it. e.g.: cnpmjs.org source registry is npmjs.org
if (!config.sourceNpmRegistryIsCNpm) {
return;
}
var total = yield totalService.getTotalInfo();
var lastSyncTime;
if (config.syncModel === 'all') {
lastSyncTime = total.last_sync_time;
} else if (config.syncModel === 'exist') {
lastSyncTime = total.last_exist_sync_time;
}
debug('checkSyncStatus start, lastSyncTime: %s, syncInterval: %s', lastSyncTime, syncInterval);
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';
sendMailToAdmin(err, null, new Date());
}
}

View File

@@ -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();
});
});

View File

@@ -29,7 +29,15 @@ describe('controllers/registry/package/show.test.js', function () {
.put('/' + pkg.name)
.set('authorization', utils.adminAuth)
.send(pkg)
.expect(201, done);
.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);
});
});
it('should return one version', function (done) {
@@ -45,6 +53,52 @@ 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 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 +106,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();
});
});

View File

@@ -121,7 +121,7 @@ describe('controllers/web/package/show.test.js', function () {
it('should display unpublished info', function (done) {
mm(config, 'syncModel', 'all');
request(app)
.get('/package/tfs')
.get('/package/moduletest1')
.expect(200)
.expect(/This package has been unpublished\./, done);
});

View File

@@ -331,6 +331,26 @@ 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');
});
});
describe('updateModulePackage()', function () {
it('should update not exists package return null', function* () {
var r = yield* Package.updateModulePackage(101010101, {});