get-packages-without-license.js 748 B

123456789101112131415161718192021
  1. "use strict";
  2. const path = require("path");
  3. module.exports.getPackagesWithoutLicense = getPackagesWithoutLicense;
  4. /**
  5. * Retrieve a list of packages that lack a license file.
  6. * @param {Project} project
  7. * @param {Package[]} packagesToPublish
  8. * @returns {Package[]}
  9. */
  10. function getPackagesWithoutLicense(project, packagesToPublish) {
  11. return project.getPackageLicensePaths().then((licensePaths) => {
  12. // this assumes any existing license is a sibling of package.json, which is pretty safe
  13. // it also dedupes package locations, since we don't care about duplicate license files
  14. const licensed = new Set(licensePaths.map((lp) => path.dirname(lp)));
  15. return packagesToPublish.filter((pkg) => !licensed.has(pkg.location));
  16. });
  17. }