Compare commits
10 Commits
snyk-fix-f
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8b29cd8b04 | ||
|
|
6769a46d71 | ||
|
|
cd60a7aa82 | ||
|
|
a289d7dd5e | ||
|
|
922aa8ff1b | ||
|
|
af9f5f7499 | ||
|
|
bc0d1db782 | ||
|
|
1964d66abf | ||
|
|
8ac988ae88 | ||
|
|
d8b5c9f7a9 |
2
.github/workflows/nodejs.yml
vendored
2
.github/workflows/nodejs.yml
vendored
@@ -28,7 +28,7 @@ jobs:
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
node-version: [10, 12, 14, 16]
|
||||
node-version: [14, 16]
|
||||
os: [ubuntu-latest]
|
||||
|
||||
steps:
|
||||
|
||||
52
History.md
52
History.md
@@ -1,4 +1,56 @@
|
||||
|
||||
3.0.0-rc.66 / 2023-03-25
|
||||
==================
|
||||
|
||||
**features**
|
||||
* [[`a289d7d`](http://github.com/cnpm/cnpmjs.org/commit/a289d7dd5ec4881e86c6f500c72cab134388782b)] - feat: ignore sync private pkg (#1747) (elrrrrrrr <<elrrrrrrr@gmail.com>>)
|
||||
* [[`af9f5f7`](http://github.com/cnpm/cnpmjs.org/commit/af9f5f749979d1f389d61e98eab7dfbf639c995b)] - feat: add changes delay (#1739) (elrrrrrrr <<elrrrrrrr@gmail.com>>)
|
||||
|
||||
**fixes**
|
||||
* [[`6769a46`](http://github.com/cnpm/cnpmjs.org/commit/6769a46d71508a24f4e2d4dc14aa4aebd826bf38)] - fix: download row create error (#1749) (elrrrrrrr <<elrrrrrrr@gmail.com>>)
|
||||
|
||||
3.0.0-rc.63 / 2022-08-31
|
||||
==================
|
||||
|
||||
**features**
|
||||
* [[`1964d66`](http://github.com/cnpm/cnpmjs.org/commit/1964d66abf3a78bc97022db2bfd1b88fa2c1fa37)] - feat: remove block version changes (#1737) (elrrrrrrr <<elrrrrrrr@gmail.com>>)
|
||||
|
||||
3.0.0-rc.62 / 2022-07-28
|
||||
==================
|
||||
|
||||
**features**
|
||||
* [[`d8b5c9f`](http://github.com/cnpm/cnpmjs.org/commit/d8b5c9f7a9a4648460415936e492ee0bb9cba9b0)] - feat: add changes api (#1734) (elrrrrrrr <<elrrrrrrr@gmail.com>>)
|
||||
* [[`f52e9c3`](http://github.com/cnpm/cnpmjs.org/commit/f52e9c3382ef3583a9cac9be5510e11a3ab17b8c)] - feat: support sync private package from define registry (#1701) (XXBeii <<36651530+XXBeii@users.noreply.github.com>>)
|
||||
* [[`97d501c`](http://github.com/cnpm/cnpmjs.org/commit/97d501c088aee43af30e31aef279b3036a7cc5f7)] - feat: support bug-versions on server (#1684) (fengmk2 <<fengmk2@gmail.com>>)
|
||||
* [[`3c5bc9d`](http://github.com/cnpm/cnpmjs.org/commit/3c5bc9dc5ef46c567e718705d18edc1f57009b5e)] - feat: support package version block list (#1683) (fengmk2 <<fengmk2@gmail.com>>)
|
||||
* [[`abc1723`](http://github.com/cnpm/cnpmjs.org/commit/abc1723bef5eb12168d084cc16916998288e879b)] - feat: support dist.integrity (#1677) (fengmk2 <<fengmk2@gmail.com>>)
|
||||
|
||||
**fixes**
|
||||
* [[`4d534ca`](http://github.com/cnpm/cnpmjs.org/commit/4d534cad024f08923b7d4df57d87d14fa96a975a)] - fix: listModulesByUser map error (#1731) (Ke Wu <<gemwuu@163.com>>)
|
||||
* [[`b7bbf84`](http://github.com/cnpm/cnpmjs.org/commit/b7bbf84ea31b5c15a48edd596bbb87a72f7de595)] - fix: add missing config property for bug-versions (#1685) (fengmk2 <<fengmk2@gmail.com>>)
|
||||
* [[`74d408d`](http://github.com/cnpm/cnpmjs.org/commit/74d408d006b1c7a08283b178e842ef98f850fcf2)] - fix: database dialect config detect error (#1503) (alsotang <<alsotang@gmail.com>>)
|
||||
* [[`37ba629`](http://github.com/cnpm/cnpmjs.org/commit/37ba6290284f260230e6d4461311bb8739088191)] - fix: get count missing name (#1674) (Solais <<924615994@qq.com>>)
|
||||
|
||||
**others**
|
||||
* [[`f8bcca1`](http://github.com/cnpm/cnpmjs.org/commit/f8bcca1ea0c0ad952fffd0539b625de69b9099f0)] - 🐛 FIX: path url maybe encode (#1729) (fengmk2 <<fengmk2@gmail.com>>)
|
||||
* [[`8663e21`](http://github.com/cnpm/cnpmjs.org/commit/8663e215f038b812b74948e28a05b704d5d7780c)] - 🐛 FIX: Should show sync button on scoped package not exists (#1728) (fengmk2 <<fengmk2@gmail.com>>)
|
||||
* [[`8573c4a`](http://github.com/cnpm/cnpmjs.org/commit/8573c4a600077585681ac1eddcebc4b2abff4f8e)] - 📖 DOC: DEPRECATED, please use https://github.com/cnpm/cnpmcore instead (fengmk2 <<fengmk2@gmail.com>>)
|
||||
* [[`83497f2`](http://github.com/cnpm/cnpmjs.org/commit/83497f20521dd5016c119500aff0ccb64cf5a929)] - 👌 IMPROVE: Return libc field on abbreviated manifests (#1721) (fengmk2 <<fengmk2@gmail.com>>)
|
||||
* [[`1e0f7e0`](http://github.com/cnpm/cnpmjs.org/commit/1e0f7e06bb7df40f1dca309b7e8e533130293ab6)] - 📖 DOC: Modify comments (#1710) (AN <<455454007@qq.com>>)
|
||||
* [[`e682e7a`](http://github.com/cnpm/cnpmjs.org/commit/e682e7a0a39f750c61d7a2a46de862d118e61e73)] - 📖 DOC: Update contributors (fengmk2 <<fengmk2@gmail.com>>)
|
||||
* [[`19e5c3d`](http://github.com/cnpm/cnpmjs.org/commit/19e5c3def257f4ceab3256a1c9d615d002c5fe49)] - chore: Add license scan report and status (#1708) (fossabot <<badges@fossa.io>>)
|
||||
* [[`9f8dca4`](http://github.com/cnpm/cnpmjs.org/commit/9f8dca4ac0292ba87c59149972f0f635bd17ec37)] - refactor: Sync exists package from cnpmcore changes stream (#1707) (fengmk2 <<fengmk2@gmail.com>>)
|
||||
* [[`f2c4b9f`](http://github.com/cnpm/cnpmjs.org/commit/f2c4b9f1c8d0b97b0b1890ac3aec058a99f0b224)] - 📖 DOC: Use git-contributor instead (fengmk2 <<fengmk2@gmail.com>>)
|
||||
* [[`ac07b21`](http://github.com/cnpm/cnpmjs.org/commit/ac07b215a73f80aa11e9631d3e6c9be4c4db87a2)] - 🐛 FIX: Support new bson logId (fengmk2 <<fengmk2@gmail.com>>)
|
||||
* [[`559d5ba`](http://github.com/cnpm/cnpmjs.org/commit/559d5baccfc3f5fa582461856f7048927aac3f23)] - 📦 NEW: sync web support webDataRemoteRegistry (#1697) (fengmk2 <<fengmk2@gmail.com>>)
|
||||
* [[`e5c5179`](http://github.com/cnpm/cnpmjs.org/commit/e5c5179e9e12be054aa733a5b0befbb064f32a44)] - 📦 NEW: Support set registry to new cnpmcore registry (#1696) (fengmk2 <<fengmk2@gmail.com>>)
|
||||
* [[`ad622d5`](http://github.com/cnpm/cnpmjs.org/commit/ad622d55e384743b48e79bb6aec574a7f354ee9f)] - chore: update contributors (fengmk2 <<fengmk2@gmail.com>>)
|
||||
* [[`c6973a9`](http://github.com/cnpm/cnpmjs.org/commit/c6973a98cef8207b56219e1b813575f7efe13653)] - fix(db.sql): use utf8mb4 on description column (#1681) (hellojukay <<hellojukay@163.com>>)
|
||||
* [[`f22a3e7`](http://github.com/cnpm/cnpmjs.org/commit/f22a3e7370792eef1c7b613188411af2354e59a6)] - refactor: dist tarbar url don't contains querystring (#1682) (fengmk2 <<fengmk2@gmail.com>>)
|
||||
* [[`a49deec`](http://github.com/cnpm/cnpmjs.org/commit/a49deec3b2e1e8483801dea757c727054df34b34)] - chore: remove unused config (#1495) (alsotang <<alsotang@gmail.com>>)
|
||||
* [[`7f0aa2a`](http://github.com/cnpm/cnpmjs.org/commit/7f0aa2ad95dedef7ec50fbebeb6df92839b42621)] - chore: update contributors (fengmk2 <<fengmk2@gmail.com>>)
|
||||
* [[`39cf77a`](http://github.com/cnpm/cnpmjs.org/commit/39cf77ae0f676584d93ada77c6ea61c3d044b267)] - refactor: use remote abbreviated version data (#1675) (fengmk2 <<fengmk2@gmail.com>>)
|
||||
|
||||
3.0.0-rc.50 / 2021-11-04
|
||||
==================
|
||||
|
||||
|
||||
@@ -201,6 +201,11 @@ var config = {
|
||||
officialNpmReplicate: 'https://replicate.npmjs.com',
|
||||
cnpmRegistry: 'https://r.cnpmjs.com',
|
||||
|
||||
// /-/all/changes
|
||||
// since different changes are aggregated through many tables
|
||||
// prevent changesStream changes collisions
|
||||
changesDelay: 5000,
|
||||
|
||||
// sync source, upstream registry
|
||||
// If you want to directly sync from official npm's registry
|
||||
// please drop them an email first
|
||||
|
||||
53
controllers/registry/package/changes.js
Normal file
53
controllers/registry/package/changes.js
Normal file
@@ -0,0 +1,53 @@
|
||||
'use strict';
|
||||
|
||||
var packageService = require('../../../services/package');
|
||||
var lodash = require('lodash');
|
||||
var gather = require('co-gather');
|
||||
|
||||
// GET /-/_changes?since={timestamp}&limit={number}&cursorId={number}
|
||||
// List changes since the timestamp
|
||||
// Similar with https://registry.npmmirror.com/_changes?since=1658974943840
|
||||
// Change types:
|
||||
// 1. ✅ PACKAGE_VERSION_ADDED
|
||||
// 2. ✅ PACKAGE_TAG_ADDED
|
||||
// 3. 🆕 PACKAGE_UNPUBLISHED
|
||||
// 5. ❎ PACKAGE_MAINTAINER_REMOVED
|
||||
// 6. ❎ PACKAGE_MAINTAINER_CHANGED
|
||||
// 7. ❎ PACKAGE_TAG_CHANGED
|
||||
//
|
||||
// Since we don't have the previous data,
|
||||
// We can't compute the reliable seqId
|
||||
// use gmt_modified cinstead of seqId
|
||||
module.exports = function* listSince() {
|
||||
var query = this.query;
|
||||
var since = query.since;
|
||||
var limit = Number(query.limit);
|
||||
|
||||
// ensure limit
|
||||
if (Number.isNaN(limit)) {
|
||||
limit = 1000;
|
||||
}
|
||||
var queryResults = yield gather(
|
||||
[
|
||||
"listVersionSince",
|
||||
"listTagSince",
|
||||
"listUnpublishedModuleSince",
|
||||
].map(function (method) {
|
||||
return packageService[method](since, limit);
|
||||
})
|
||||
);
|
||||
|
||||
var validResults = queryResults.map(function (result) {
|
||||
if (!result.isError) {
|
||||
return result.value;
|
||||
}
|
||||
return [];
|
||||
});
|
||||
|
||||
var results = lodash.orderBy(
|
||||
lodash.flatten(validResults).filter(Boolean),
|
||||
"gmt_modified",
|
||||
"asc"
|
||||
).slice(0, limit);
|
||||
this.body = { results };
|
||||
};
|
||||
@@ -130,9 +130,12 @@ defer.setInterval(function* () {
|
||||
err.message += '; name: ' + name + ', count: ' + count + ', date: ' + date;
|
||||
logger.error(err);
|
||||
}
|
||||
// save back to globalDownloads, try again next time
|
||||
count = (globalDownloads.get(name) || 0) + count;
|
||||
globalDownloads.set(name, count);
|
||||
var pkgExist = yield packageService.getModuleLastModified(name);
|
||||
if (pkgExist) {
|
||||
// save back to globalDownloads, try again next time
|
||||
count = (globalDownloads.get(name) || 0) + count;
|
||||
globalDownloads.set(name, count);
|
||||
}
|
||||
}
|
||||
}
|
||||
saving = false;
|
||||
|
||||
@@ -159,3 +159,10 @@ exports.getOssLicenseUrlFromName = function (name) {
|
||||
return licenseMap[name.toLowerCase()] ?
|
||||
base + licenseMap[name.toLowerCase()] : base + name;
|
||||
};
|
||||
|
||||
exports.ensureSinceIsDate = function(since) {
|
||||
if (!(since instanceof Date)) {
|
||||
return new Date(Number(since));
|
||||
}
|
||||
return since;
|
||||
}
|
||||
|
||||
@@ -97,6 +97,9 @@ exports.isMaintainer = function (user, maintainers) {
|
||||
exports.isLocalModule = function (mods) {
|
||||
for (var i = 0; i < mods.length; i++) {
|
||||
var r = mods[i];
|
||||
if (config.privatePackages.includes(r.name)) {
|
||||
return true;
|
||||
}
|
||||
if (r.package && r.package._publish_on_cnpm) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "cnpmjs.org",
|
||||
"version": "3.0.0-rc.60",
|
||||
"version": "3.0.0-rc.66",
|
||||
"description": "Private npm registry and web for Enterprise, base on MySQL and Simple Store Service",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
@@ -54,6 +54,7 @@
|
||||
"koa-rewrite": "^1.1.2",
|
||||
"koa-rt": "^1.0.0",
|
||||
"koa-safe-jsonp": "^0.3.1",
|
||||
"lodash": "^4.17.21",
|
||||
"markdown-it": "^8.3.2",
|
||||
"mime": "^1.3.6",
|
||||
"mini-logger": "^1.1.3",
|
||||
|
||||
@@ -14,6 +14,7 @@ var listAll = require('../controllers/registry/package/list_all');
|
||||
var listAllPackageVersions = require('../controllers/registry/package/list_versions');
|
||||
var listShorts = require('../controllers/registry/package/list_shorts');
|
||||
var listSince = require('../controllers/registry/package/list_since');
|
||||
var changes = require('../controllers/registry/package/changes');
|
||||
var listAllVersions = require('../controllers/registry/package/list');
|
||||
var listDependents = require('../controllers/registry/package/list_dependents');
|
||||
var getOneVersion = require('../controllers/registry/package/show');
|
||||
@@ -50,10 +51,10 @@ function routes(app) {
|
||||
}
|
||||
|
||||
app.get('/', jsonp, showTotal);
|
||||
|
||||
// before /:name/:version
|
||||
// get all modules, for npm search
|
||||
app.get('/-/all', listAll);
|
||||
app.get('/-/all/changes', changes);
|
||||
app.get('/-/all/since', listSince);
|
||||
// get all module names, for auto completion
|
||||
app.get('/-/short', listShorts);
|
||||
|
||||
@@ -14,3 +14,10 @@ exports.isPrivatePackage = function (name) {
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
exports.CHANGE_TYPE = {
|
||||
PACKAGE_TAG_ADDED: 'PACKAGE_TAG_ADDED',
|
||||
PACKAGE_VERSION_ADDED: 'PACKAGE_VERSION_ADDED',
|
||||
PACKAGE_UNPUBLISHED: 'PACKAGE_UNPUBLISHED',
|
||||
PACKAGE_VERSION_BLOCKED: 'PACKAGE_VERSION_BLOCKED'
|
||||
};
|
||||
|
||||
@@ -5,6 +5,8 @@ var models = require('../models');
|
||||
var common = require('./common');
|
||||
var libCommon = require('../lib/common');
|
||||
var config = require('../config');
|
||||
var { ensureSinceIsDate } = require('../controllers/utils');
|
||||
var { BlockPackageVersion } = require('../models');
|
||||
var Tag = models.Tag;
|
||||
var User = models.User;
|
||||
var Module = models.Module;
|
||||
@@ -15,6 +17,8 @@ var ModuleDependency = models.ModuleDependency;
|
||||
var ModuleUnpublished = models.ModuleUnpublished;
|
||||
var NpmModuleMaintainer = models.NpmModuleMaintainer;
|
||||
|
||||
var CHANGE_TYPE = common.CHANGE_TYPE;
|
||||
|
||||
// module
|
||||
var _parseRow = function (row) {
|
||||
if (row.package.indexOf('%7B%22') === 0) {
|
||||
@@ -198,6 +202,84 @@ exports.listPublicModuleNamesByUser = function* (username) {
|
||||
return names;
|
||||
};
|
||||
|
||||
exports.listModelSince = function(Model, attributes, mapper) {
|
||||
|
||||
return function*(since, limit) {
|
||||
|
||||
var start = ensureSinceIsDate(since);
|
||||
var findCondition = {
|
||||
attributes: attributes,
|
||||
where: {
|
||||
gmt_modified: {
|
||||
gte: start,
|
||||
// 添加延时,防止同一时间多个数据未同步
|
||||
lte: new Date(Date.now() - config.changesDelay || 5000),
|
||||
},
|
||||
},
|
||||
order: [
|
||||
["gmt_modified", "ASC"],
|
||||
["id", "ASC"],
|
||||
],
|
||||
};
|
||||
if (limit) {
|
||||
findCondition.limit = limit;
|
||||
}
|
||||
var rows = yield Model.findAll(findCondition);
|
||||
return rows.map(mapper);
|
||||
}
|
||||
}
|
||||
|
||||
exports.listTagSince = this.listModelSince(
|
||||
Tag,
|
||||
['id', 'name', 'tag', 'gmt_modified'],
|
||||
function (row) {
|
||||
return {
|
||||
type: CHANGE_TYPE.PACKAGE_TAG_ADDED,
|
||||
id: row.name,
|
||||
changes: [{tag: row.tag}],
|
||||
gmt_modified: row.gmt_modified,
|
||||
};
|
||||
}
|
||||
);
|
||||
|
||||
exports.listVersionSince = this.listModelSince(
|
||||
Module,
|
||||
['id', 'name', 'version', 'gmt_modified'],
|
||||
function (row) {
|
||||
return {
|
||||
type: CHANGE_TYPE.PACKAGE_VERSION_ADDED,
|
||||
id: row.name,
|
||||
changes: [{version: row.version}],
|
||||
gmt_modified: row.gmt_modified,
|
||||
};
|
||||
}
|
||||
);
|
||||
|
||||
exports.listUnpublishedModuleSince = this.listModelSince(
|
||||
ModuleUnpublished,
|
||||
['id', 'name', 'gmt_modified'],
|
||||
function(row) {
|
||||
return {
|
||||
type: CHANGE_TYPE.PACKAGE_UNPUBLISHED,
|
||||
id: row.name,
|
||||
gmt_modified: row.gmt_modified,
|
||||
};
|
||||
}
|
||||
);
|
||||
|
||||
exports.listBlockVersionSince = this.listModelSince(
|
||||
BlockPackageVersion,
|
||||
['id', 'name', 'version', 'gmt_modified'],
|
||||
function(row) {
|
||||
return {
|
||||
type: CHANGE_TYPE.PACKAGE_VERSION_BLOCKED,
|
||||
id: row.name,
|
||||
gmt_modified: row.gmt_modified,
|
||||
};
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
// start must be a date or timestamp
|
||||
exports.listPublicModuleNamesSince = function* listPublicModuleNamesSince(start) {
|
||||
if (!(start instanceof Date)) {
|
||||
|
||||
100
test/controllers/registry/package/changes.test.js
Normal file
100
test/controllers/registry/package/changes.test.js
Normal file
@@ -0,0 +1,100 @@
|
||||
'use strict';
|
||||
|
||||
var should = require('should');
|
||||
var request = require('supertest');
|
||||
var mm = require('mm');
|
||||
var config = require('../../../../config');
|
||||
var app = require('../../../../servers/registry');
|
||||
var utils = require('../../../utils');
|
||||
var CHANGE_TYPE = require('../../../../services/common').CHANGE_TYPE;
|
||||
|
||||
describe('test/controllers/registry/package/changes.test.js', function () {
|
||||
afterEach(mm.restore);
|
||||
|
||||
var since;
|
||||
before(function (done) {
|
||||
mm(config, 'changesDelay', 0);
|
||||
setTimeout(() => {
|
||||
since = Date.now();
|
||||
var pkg = utils.getPackage('@cnpmtest/test_changes', '0.0.1', utils.admin, 'alpha');
|
||||
request(app)
|
||||
.put('/' + pkg.name)
|
||||
.set('authorization', utils.adminAuth)
|
||||
.send(pkg)
|
||||
.expect(201, function() {
|
||||
setTimeout(function() {
|
||||
pkg = utils.getPackage('@cnpmtest/test_changes_gogo', '0.0.2', utils.admin, 'beta');
|
||||
request(app)
|
||||
.put('/' + pkg.name)
|
||||
.set('authorization', utils.adminAuth)
|
||||
.send(pkg)
|
||||
.expect(201, done);
|
||||
}, 2000);
|
||||
});
|
||||
}, 1000);
|
||||
});
|
||||
|
||||
describe('GET /-/all/changes', function () {
|
||||
it('should 200', function (done) {
|
||||
request(app)
|
||||
.get("/-/all/changes?since=" + since)
|
||||
.expect(200, function (err, res) {
|
||||
should.not.exist(err);
|
||||
res.body.results.should.be.an.Array();
|
||||
|
||||
res.body.results
|
||||
.filter(function (item) {
|
||||
return item.type === CHANGE_TYPE.PACKAGE_VERSION_ADDED;
|
||||
})
|
||||
.length.should.equal(2);
|
||||
res.body.results
|
||||
.filter(function (item) {
|
||||
return item.type === CHANGE_TYPE.PACKAGE_VERSION_ADDED;
|
||||
})
|
||||
.length.should.equal(2);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('changes delay should work', function(done) {
|
||||
mm(config, 'changesDelay', 10000);
|
||||
request(app)
|
||||
.get("/-/all/changes?since=" + since)
|
||||
.expect(200, function (err, res) {
|
||||
should.not.exist(err);
|
||||
res.body.results.should.be.an.Array();
|
||||
res.body.results
|
||||
.filter(function (item) {
|
||||
return item.type === CHANGE_TYPE.PACKAGE_VERSION_ADDED;
|
||||
})
|
||||
.length.should.equal(0);
|
||||
done();
|
||||
});
|
||||
})
|
||||
|
||||
it('since should work', function (done) {
|
||||
var now = Date.now();
|
||||
request(app)
|
||||
.get("/-/all/changes?since=" + now + 5000)
|
||||
.expect(200, function (err, res) {
|
||||
should.not.exist(err);
|
||||
res.body.results.should.be.an.Array();
|
||||
res.body.results.length.should.equal(0);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('limit should work', function (done) {
|
||||
mm(config, 'changesDelay', 0);
|
||||
request(app)
|
||||
.get('/-/all/changes?limit=1&since=' + since)
|
||||
.expect(200, function (err, res) {
|
||||
should.not.exist(err);
|
||||
res.body.results.should.be.an.Array();
|
||||
res.body.results.length.should.equal(1);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
@@ -11,28 +11,50 @@
|
||||
|
||||
'use strict';
|
||||
|
||||
const { co } = require('co');
|
||||
const mm = require('mm');
|
||||
const config = require('../../config');
|
||||
const createModule = require('../utils').createModule;
|
||||
const packageService = require('../../services/package');
|
||||
/**
|
||||
* Module dependencies.
|
||||
*/
|
||||
|
||||
var common = require('../../lib/common');
|
||||
|
||||
describe('test/lib/common.test.js', function () {
|
||||
describe('isAdmin()', function () {
|
||||
it('should admin is admin', function () {
|
||||
common.isAdmin('admin').should.equal(true);
|
||||
common.isAdmin('fengmk2').should.equal(true);
|
||||
common.isAdmin('constructor').should.equal(false);
|
||||
common.isAdmin('toString').should.equal(false);
|
||||
describe("test/lib/common.test.js", function () {
|
||||
describe("isAdmin()", function () {
|
||||
it("should admin is admin", function () {
|
||||
common.isAdmin("admin").should.equal(true);
|
||||
common.isAdmin("fengmk2").should.equal(true);
|
||||
common.isAdmin("constructor").should.equal(false);
|
||||
common.isAdmin("toString").should.equal(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe('getCDNKey()', function () {
|
||||
it('should auto fix scope filename', function () {
|
||||
common.getCDNKey('foo', 'foo-1.0.0.tgz').should.equal('/foo/-/foo-1.0.0.tgz');
|
||||
common.getCDNKey('@bar/foo', 'foo-1.0.0.tgz').should.equal('/@bar/foo/-/@bar/foo-1.0.0.tgz');
|
||||
common.getCDNKey('@bar/foo', '@bar/foo-1.0.0.tgz').should.equal('/@bar/foo/-/@bar/foo-1.0.0.tgz');
|
||||
common.getCDNKey('@bar/foo', '@bar1/foo-1.0.0.tgz').should.equal('/@bar/foo/-/@bar1/foo-1.0.0.tgz');
|
||||
describe("getCDNKey()", function () {
|
||||
it("should auto fix scope filename", function () {
|
||||
common
|
||||
.getCDNKey("foo", "foo-1.0.0.tgz")
|
||||
.should.equal("/foo/-/foo-1.0.0.tgz");
|
||||
common
|
||||
.getCDNKey("@bar/foo", "foo-1.0.0.tgz")
|
||||
.should.equal("/@bar/foo/-/@bar/foo-1.0.0.tgz");
|
||||
common
|
||||
.getCDNKey("@bar/foo", "@bar/foo-1.0.0.tgz")
|
||||
.should.equal("/@bar/foo/-/@bar/foo-1.0.0.tgz");
|
||||
common
|
||||
.getCDNKey("@bar/foo", "@bar1/foo-1.0.0.tgz")
|
||||
.should.equal("/@bar/foo/-/@bar1/foo-1.0.0.tgz");
|
||||
});
|
||||
});
|
||||
|
||||
describe("isLocalModule", function () {
|
||||
it("should ignore private packages", function * () {
|
||||
yield createModule("banana", "1.0.0");
|
||||
const modules = yield packageService.listModulesByName('banana');
|
||||
mm(config, "privatePackages", ["banana"]);
|
||||
common.isLocalModule(modules).should.equal(true);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -5,6 +5,8 @@ var sleep = require('co-sleep');
|
||||
var Package = require('../../services/package');
|
||||
var utils = require('../utils');
|
||||
var common = require('../../services/common');
|
||||
var config = require('../../config');
|
||||
var mm = require('mm');
|
||||
|
||||
describe('test/services/package.test.js', function () {
|
||||
describe('addModuleTag()', function () {
|
||||
@@ -130,6 +132,71 @@ describe('test/services/package.test.js', function () {
|
||||
});
|
||||
});
|
||||
|
||||
describe('listModelSince()', function () {
|
||||
it('list tags since', function* () {
|
||||
mm(config, 'changesDelay', 0);
|
||||
yield utils.createModule('test-listModuleSince-module-0', '1.0.0');
|
||||
yield sleep(2100);
|
||||
var start = Date.now() - 1000;
|
||||
yield utils.createModule('test-listModuleSince-module-1', '1.0.0');
|
||||
yield utils.createModule('test-listModuleSince-module-1', '1.0.1', null, 'beta');
|
||||
yield utils.createModule('test-listModuleSince-module-2', '1.0.0');
|
||||
var tags = yield Package.listTagSince(start);
|
||||
|
||||
var modules = tags.map(function (item) {
|
||||
return { name: item.id, tag: item.changes[0].tag };
|
||||
});
|
||||
|
||||
modules
|
||||
.should.eql([
|
||||
{ name: "test-listModuleSince-module-1", tag: "latest" },
|
||||
{ name: "test-listModuleSince-module-1", tag: "beta" },
|
||||
{ name: "test-listModuleSince-module-2", tag: "latest" },
|
||||
]);
|
||||
|
||||
tags = yield Package.listTagSince(start, 2);
|
||||
modules = tags.map(function (item) {
|
||||
return { name: item.id, tag: item.changes[0].tag};
|
||||
});
|
||||
modules
|
||||
.should.eql([
|
||||
{ name: "test-listModuleSince-module-1", tag: "latest" },
|
||||
{ name: "test-listModuleSince-module-1", tag: "beta" },
|
||||
]);
|
||||
});
|
||||
it('list package version since', function* () {
|
||||
mm(config, 'changesDelay', 0);
|
||||
yield utils.createModule('test-listModuleSince-module-0', '1.0.0');
|
||||
yield sleep(2100);
|
||||
var start = Date.now() - 1000;
|
||||
yield utils.createModule('test-listModuleSince-module-1', '1.0.0');
|
||||
yield utils.createModule('test-listModuleSince-module-1', '1.0.1', null, 'beta');
|
||||
yield utils.createModule('test-listModuleSince-module-2', '1.0.0');
|
||||
var tags = yield Package.listVersionSince(start);
|
||||
|
||||
var modules = tags.map(function (item) {
|
||||
return { name: item.id, version: item.changes[0].version };
|
||||
});
|
||||
|
||||
modules
|
||||
.should.eql([
|
||||
{ name: "test-listModuleSince-module-1", version: "1.0.0" },
|
||||
{ name: "test-listModuleSince-module-1", version: "1.0.1" },
|
||||
{ name: "test-listModuleSince-module-2", version: "1.0.0" },
|
||||
]);
|
||||
|
||||
tags = yield Package.listVersionSince(start, 2);
|
||||
modules = tags.map(function (item) {
|
||||
return { name: item.id, version: item.changes[0].version};
|
||||
});
|
||||
modules
|
||||
.should.eql([
|
||||
{ name: "test-listModuleSince-module-1", version: "1.0.0" },
|
||||
{ name: "test-listModuleSince-module-1", version: "1.0.1" },
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('listPublicModuleNamesSince(), listAllPublicModuleNames()', function () {
|
||||
it('should got those module names', function* () {
|
||||
yield utils.createModule('test-listPublicModuleNamesSince-module-0', '1.0.0');
|
||||
|
||||
Reference in New Issue
Block a user