Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add license compliance check tool #66

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

pbredenberg
Copy link
Contributor

No description provided.

@pbredenberg pbredenberg self-assigned this Jul 7, 2023
Comment on lines 16 to 30
/**
* Async wrapper around `licence-checker`'s init function.
* @param options
*/
const initAsync = async (options) => {
return new Promise((resolve, reject) => {
init(options, (err, packages) => {
if (err) {
reject(err);
}

resolve(packages);
});
});
};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would something like this work?

const { init } = require('license-checker'),
      util = require('util'),
      initLicenseChecker = util.promisify(init);

@pbredenberg pbredenberg force-pushed the pb/feat-license-checker branch from 406e881 to c030afd Compare August 10, 2023 13:58
@pbredenberg pbredenberg force-pushed the pb/feat-license-checker branch from c030afd to acfc3d5 Compare August 18, 2023 13:11

module.exports = {

allowList: [
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about this?

Suggested change
allowList: [
permittedLicenses: [

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did it


(async () => {
const projectDirectoryPath = await packageDirectory(),
projectConfigPath = `${projectDirectoryPath}/.license-checker.cjs`,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any particular reason this is .cjs and not just .js?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Haha, no. I have no idea why I did that.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

console.info(`This project has ${Object.values(licenseRecord).length} licenses.`);

unsupportedLicenses = Object.values(licenseRecord).filter((record) => {
return !ALLOWED_LICENSES.includes(record.license) && !allowList.includes(record.license);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If a project supplies a list of permitted licenses, should we keep checking the default license list?

Copy link
Contributor Author

@pbredenberg pbredenberg Aug 24, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was imagining the licenses passed in would be in addition to default set declared inside the tool.

Comment on lines 65 to 71
moduleInfoReport[moduleName].licenses.forEach((license) => {
licenseRecord[moduleName] = {
module: moduleName,
license: license,
...moduleInfoReport[moduleName],
};
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This only keeps the last license. Would it be better to have a list of all the licenses and see if any are in the list of permitted licenses?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right! I neglected to revisit this block of code. Here's the situation: in the many projects I've tested it in, I've never seen const licenses = moduleInfoReport[moduleName].licenses; evaluate to an array.

That's probably because the library is handling an edge case due to what the NPM docs say here regarding license data which they refer to as invalid.

In short, I don't think this block is actually needed from looking at the source linked above.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm now simply taking whatever value it sends. Let me know if you think we should still support this case.

.forEach((moduleName) => {
const licenses = moduleInfoReport[moduleName].licenses;

if (!licenses) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If there are no licenses, should we assume that the package is UNLICENSED (i.e. the package cannot be used by anyone but the copyright holder)?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, good point!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did it


Object
.keys(moduleInfoReport)
.forEach((moduleName) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We'll also need a way to note what packages are permitted regardless of their license. Perhaps a config option like permittedPackages?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, sounds good.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@onebytegone this hath been added, my liege

@pbredenberg pbredenberg force-pushed the pb/feat-license-checker branch from acfc3d5 to ccc6ebb Compare August 24, 2023 12:53
@pbredenberg pbredenberg force-pushed the pb/feat-license-checker branch from ccc6ebb to 93f1035 Compare August 24, 2023 18:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants