Handle licenses for 'private: true' packages (#16480) (#16494)

This commit is contained in:
Kim Joar Bekkelund 2018-02-02 21:55:34 +01:00 committed by GitHub
parent 08115ed77c
commit c9b602b395
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 28 additions and 1 deletions

View file

@ -4,7 +4,8 @@ import expect from 'expect.js';
import { assertLicensesValid } from '../valid';
const NODE_MODULES = resolve(__dirname, '../../../../node_modules');
const ROOT = resolve(__dirname, '../../../../');
const NODE_MODULES = resolve(ROOT, './node_modules');
const PACKAGE = {
name: '@elastic/httpolyglot',
@ -14,6 +15,16 @@ const PACKAGE = {
relative: 'node_modules/@elastic/httpolyglot',
};
const INTERNAL_PACKAGE = {
name: '@kbn/internal',
version: '1.0.0',
// `license-checker` marks `private: true` packages as "unlicensed" _even_ if
// you add a `license` field to its `package.json`
licenses: ['UNLICENSED'],
directory: resolve(ROOT, 'packages/kbn-internal'),
relative: 'packages/kbn-internal',
};
describe('tasks/lib/licenses', () => {
describe('assertLicensesValid()', () => {
it('returns undefined when package has valid license', () => {
@ -23,6 +34,13 @@ describe('tasks/lib/licenses', () => {
})).to.be(undefined);
});
it('returns undefined if internal package that is marked as "UNLICENSED"', () => {
expect(assertLicensesValid({
packages: [INTERNAL_PACKAGE],
validLicenses: ['MIT', 'Apache-2.0']
})).to.be(undefined);
});
it('throw an error when the packages license is invalid', () => {
expect(() => {
assertLicensesValid({

View file

@ -33,11 +33,20 @@ export function assertLicensesValid(options = {}) {
licenses.filter(license => !validLicenses.includes(license))
);
// If a package is not located in `node_modules`, we know it's a package from
// within the Kibana repo. The reason we need to exclude these when checking
// for valid licenses , is that our `license-checker` dependency marks all
// packages that have `private: true` in their `package.json` as "UNLICENSED".
const isInternalPackage = pkg => (
!pkg.relative.includes('node_modules/')
);
const isPackageInvalid = pkg => (
!pkg.licenses.length || getInvalid(pkg.licenses).length > 0
);
const invalidMsgs = packages
.filter(pkg => !isInternalPackage(pkg))
.filter(isPackageInvalid)
.map(describeInvalidLicenses(getInvalid));