-
Notifications
You must be signed in to change notification settings - Fork 8
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
base: master
Are you sure you want to change the base?
feat: add license compliance check tool #66
Conversation
scripts/check-license-compliance.js
Outdated
/** | ||
* 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); | ||
}); | ||
}); | ||
}; |
There was a problem hiding this comment.
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);
406e881
to
c030afd
Compare
c030afd
to
acfc3d5
Compare
.license-checker.cjs
Outdated
|
||
module.exports = { | ||
|
||
allowList: [ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about this?
allowList: [ | |
permittedLicenses: [ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did it
scripts/check-license-compliance.js
Outdated
|
||
(async () => { | ||
const projectDirectoryPath = await packageDirectory(), | ||
projectConfigPath = `${projectDirectoryPath}/.license-checker.cjs`, |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
scripts/check-license-compliance.js
Outdated
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); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
scripts/check-license-compliance.js
Outdated
moduleInfoReport[moduleName].licenses.forEach((license) => { | ||
licenseRecord[moduleName] = { | ||
module: moduleName, | ||
license: license, | ||
...moduleInfoReport[moduleName], | ||
}; | ||
}); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
scripts/check-license-compliance.js
Outdated
.forEach((moduleName) => { | ||
const licenses = moduleInfoReport[moduleName].licenses; | ||
|
||
if (!licenses) { |
There was a problem hiding this comment.
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)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, good point!
There was a problem hiding this comment.
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) => { |
There was a problem hiding this comment.
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
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, sounds good.
There was a problem hiding this comment.
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
acfc3d5
to
ccc6ebb
Compare
ccc6ebb
to
93f1035
Compare
No description provided.