d8d65526c6
* [codeshift] add proper ignore comments * [codeshift] apply require-to-import transform * [codeshift/fixup] remove duplicate imports * [eslint] upgrade config for react "unused" support * [codeshift] apply remove-unused-imports transform * [codeshift] apply remove-unused-basic-requires transform * [codeshift] apply remove-unused-function-arguments transform * [lintroller] fix argument list spacing * [codeshift] apply remove-unused-basic-bars transform * [codeshift/fixup] fixup unused basic var removals * manually apply remove-unused-assignments transform * [codeshift] reapply remove-unused-imports transform * [codeshift] reapply remove-unused-function-arguments transform * [eslint] autofix param spacing * manually fix remaining no-undef errors * use more descriptive file ignore pattern * add eslint-plugin-react peerDependency * replace values that looked unused in tests * remove // kibana-jscodeshift-no-babel comment * remove import statements from code required by api tests * Remove '// kibana-jscodeshift-ignore' comments * address review feedback * remove remnant of removed if condition
75 lines
1.9 KiB
JavaScript
75 lines
1.9 KiB
JavaScript
import _ from 'lodash';
|
|
import { fromNode } from 'bluebird';
|
|
import npmLicense from 'license-checker';
|
|
|
|
export default function licenses(grunt) {
|
|
grunt.registerTask('licenses', 'Checks dependency licenses', async function () {
|
|
const config = this.options();
|
|
const done = this.async();
|
|
|
|
const options = {
|
|
start: process.cwd(),
|
|
production: true,
|
|
json: true
|
|
};
|
|
|
|
const packages = await fromNode(cb => {
|
|
npmLicense.init(options, result => {
|
|
cb(undefined, result);
|
|
});
|
|
});
|
|
|
|
/**
|
|
* Licenses for a package by name with overrides
|
|
*
|
|
* @param {String} name
|
|
* @return {Array}
|
|
*/
|
|
|
|
function licensesForPackage(name) {
|
|
let licenses = packages[name].licenses;
|
|
|
|
if (config.overrides.hasOwnProperty(name)) {
|
|
licenses = config.overrides[name];
|
|
}
|
|
|
|
return typeof licenses === 'string' ? [licenses] : licenses;
|
|
}
|
|
|
|
/**
|
|
* Determine if a package has a valid license
|
|
*
|
|
* @param {String} name
|
|
* @return {Boolean}
|
|
*/
|
|
|
|
function isInvalidLicense(name) {
|
|
const licenses = licensesForPackage(name);
|
|
|
|
// verify all licenses for the package are in the config
|
|
return _.intersection(licenses, config.licenses).length < licenses.length;
|
|
}
|
|
|
|
// Build object containing only invalid packages
|
|
const invalidPackages = _.pick(packages, (pkg, name) => {
|
|
return isInvalidLicense(name);
|
|
});
|
|
|
|
if (Object.keys(invalidPackages).length) {
|
|
const execSync = require('child_process').execSync;
|
|
const names = Object.keys(invalidPackages);
|
|
|
|
// Uses npm ls to create tree for package locations
|
|
const tree = execSync(`npm ls ${names.join(' ')}`);
|
|
|
|
grunt.log.debug(JSON.stringify(invalidPackages, null, 2));
|
|
grunt.fail.warn(
|
|
`Non-confirming licenses:\n ${names.join('\n ')}\n\n${tree}`,
|
|
invalidPackages.length
|
|
);
|
|
}
|
|
|
|
done();
|
|
});
|
|
}
|