mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 01:38:56 -04:00
Handle licenses for 'private: true' packages (#16480)
This commit is contained in:
parent
37e42432c6
commit
ec62e4f942
2 changed files with 28 additions and 1 deletions
|
@ -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({
|
||||
|
|
|
@ -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));
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue