Skip to content
This repository has been archived by the owner on Jun 2, 2024. It is now read-only.

Commit

Permalink
feat: ignore sync private pkg (#1747)
Browse files Browse the repository at this point in the history
> Ignore sync requests for private pacakges.
* update isLocalModule Logic, follow the #privatePackages field in
config.
  • Loading branch information
elrrrrrrr authored Feb 6, 2023
1 parent 922aa8f commit a289d7d
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 13 deletions.
3 changes: 3 additions & 0 deletions lib/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
48 changes: 35 additions & 13 deletions test/lib/common.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});
});

0 comments on commit a289d7d

Please sign in to comment.