diff --git a/lib/common.js b/lib/common.js index b811280..f3c5922 100644 --- a/lib/common.js +++ b/lib/common.js @@ -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; } diff --git a/test/lib/common.test.js b/test/lib/common.test.js index 19ab276..6d71671 100644 --- a/test/lib/common.test.js +++ b/test/lib/common.test.js @@ -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); }); }); });