From b980774c0965f964c72ca79ffe5268572dfb98a6 Mon Sep 17 00:00:00 2001 From: Ohtaka Kaoru <46368397+kkkaoru@users.noreply.github.com> Date: Wed, 17 May 2023 02:33:15 +0900 Subject: [PATCH] can remove null values (#5) --- .../utils/search-license.util.ts | 28 +++++++++---------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/packages/pnpm-license-exporter/src/pnpm/export-license/utils/search-license.util.ts b/packages/pnpm-license-exporter/src/pnpm/export-license/utils/search-license.util.ts index 0725f80..dc2b221 100644 --- a/packages/pnpm-license-exporter/src/pnpm/export-license/utils/search-license.util.ts +++ b/packages/pnpm-license-exporter/src/pnpm/export-license/utils/search-license.util.ts @@ -6,19 +6,17 @@ type PackageIfHasLicense = PnpmPackageWithLicenseTxt | PnpmPackageInfo; export function searchLicense(packages: PnpmPackageInfo[]) { return Promise.all( - packages - .map(async (pnpmPackage): Promise => { - 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; + packages.map(async (pnpmPackage): Promise => { + 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)); }