license-kit
Version:
Aggregate license notes of OSS libraries used in your Node.js project
86 lines (83 loc) • 3.23 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const node_fs_1 = __importDefault(require("node:fs"));
const node_path_1 = __importDefault(require("node:path"));
const node_process_1 = __importDefault(require("node:process"));
const react_native_legal_shared_1 = require("@callstack/react-native-legal-shared");
const minimist_1 = __importDefault(require("minimist"));
const args = (0, minimist_1.default)(node_process_1.default.argv.slice(2));
if (args.help) {
console.log(`
Usage: license-kit [options]
License Kit: Scan dependencies and check for copyleft licenses.
Options:
--copyleft: Check for copyleft licenses. Exits with error if strong copyleft licenses are found.
--error-on-weak: Exit with error if weak copyleft licenses are found.
--root: Path to the root of the React Native project. Defaults to the current working directory.
--help: Show this help message.
`);
node_process_1.default.exit(0);
}
const repoRootPath = args.root ? node_path_1.default.join(node_process_1.default.cwd(), args.root) : node_process_1.default.cwd();
const packageJsonPath = node_path_1.default.join(repoRootPath, 'package.json');
if (!node_fs_1.default.existsSync(packageJsonPath)) {
console.error(`package.json not found at ${packageJsonPath}`);
node_process_1.default.exit(1);
}
const licenses = (0, react_native_legal_shared_1.scanDependencies)(packageJsonPath);
if (args.copyleft) {
const STRONG_COPYLEFT_LICENSES = [
'GPL',
'GPL-2.0',
'GPL-3.0',
'AGPL-3.0',
'MPL-2.0',
'EPL-1.0',
'EPL-2.0',
'EUPL-1.1',
'OSL-3.0',
];
const WEAK_COPYLEFT_LICENSES = ['LGPL', 'LGPL-2.1', 'LGPL-3.0'];
const strongCopyleftLicenses = [];
const weakCopyleftLicenses = [];
for (const [key, value] of Object.entries(licenses)) {
STRONG_COPYLEFT_LICENSES.find((license) => {
if (value.type === license) {
strongCopyleftLicenses.push(`- ${key}: ${value.type} (${value.file || value.url})`);
return true;
}
});
WEAK_COPYLEFT_LICENSES.find((license) => {
if (value.type === license) {
weakCopyleftLicenses.push(`- ${key}: ${value.type} (${value.file || value.url})`);
return true;
}
});
}
if (strongCopyleftLicenses.length > 0) {
console.error('❌ Copyleft licenses found in the following dependencies:');
strongCopyleftLicenses.forEach((entry) => {
console.error(entry);
});
node_process_1.default.exit(1);
}
if (weakCopyleftLicenses.length > 0) {
console.error('⚠️ Weak copyleft licenses found in the following dependencies:');
weakCopyleftLicenses.forEach((entry) => {
console.error(entry);
});
if (args['error-on-weak']) {
node_process_1.default.exit(1);
}
}
else {
console.log('✅ No copyleft licenses found');
}
}
else {
console.log(licenses);
}