Skip to content

Commit

Permalink
can remove null values (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
kkkaoru authored May 16, 2023
1 parent b696442 commit b980774
Showing 1 changed file with 13 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,17 @@ type PackageIfHasLicense = PnpmPackageWithLicenseTxt | PnpmPackageInfo;

export function searchLicense(packages: PnpmPackageInfo[]) {
return Promise.all(
packages
.map(async (pnpmPackage): Promise<PackageIfHasLicense | undefined> => {
const dirents = await readdir(pnpmPackage.path, { withFileTypes: true });
const licenseDirent = dirents.find((dirent) => dirent.name.toLowerCase().includes('license'));
if (licenseDirent === undefined) {
return undefined;
}
const licenseTxt = await readLicense({
name: pnpmPackage.name,
licensePath: `${pnpmPackage.path}/${licenseDirent.name}`,
});
return licenseTxt === undefined ? pnpmPackage : { ...pnpmPackage, licenseTxt };
})
.filter(Boolean),
) as Promise<PackageIfHasLicense[]>;
packages.map(async (pnpmPackage): Promise<PackageIfHasLicense | undefined> => {
const dirents = await readdir(pnpmPackage.path, { withFileTypes: true });
const licenseDirent = dirents.find((dirent) => dirent.name.toLowerCase().includes('license'));
if (licenseDirent === undefined) {
return undefined;
}
const licenseTxt = await readLicense({
name: pnpmPackage.name,
licensePath: `${pnpmPackage.path}/${licenseDirent.name}`,
});
return licenseTxt === undefined ? pnpmPackage : { ...pnpmPackage, licenseTxt };
}),
).then((licenses) => licenses.filter(Boolean));
}

0 comments on commit b980774

Please sign in to comment.