Skip to content

Commit

Permalink
remove path property in exported license (#8)
Browse files Browse the repository at this point in the history
  • Loading branch information
kkkaoru authored May 17, 2023
1 parent 00657a1 commit def8620
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 9 deletions.
6 changes: 6 additions & 0 deletions packages/pnpm-license-exporter/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# @luco-inc/pnpm-license-exporter

## 1.0.1

### Patch Changes

- remoe path property in exported license

## 1.0.0

### Major Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/pnpm-license-exporter/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@luco-inc/pnpm-license-exporter",
"version": "1.0.0",
"version": "1.0.1",
"description": "",
"keywords": [],
"files": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ export type PnpmLicenses = {
[license: string]: PnpmPackageInfo[];
};

export type PnpmPackageWithLicenseTxt = {
licenseTxt: string;
} & PnpmPackageInfo;
export type ExportedPnpmPackageInfo = {
licenseTxt?: string;
// path property is only not exported
} & Omit<PnpmPackageInfo, 'path'>;

export type LicensePackageInfo = Omit<PnpmPackageInfo, 'path'>;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import { readdir } from 'node:fs/promises';
import type { PnpmPackageInfo, PnpmPackageWithLicenseTxt } from '../types/export-licenses.types';
import type { PnpmPackageInfo, ExportedPnpmPackageInfo } from '../types/export-licenses.types';
import { readLicense } from './read-license.util';

type PackageIfHasLicense = PnpmPackageWithLicenseTxt | PnpmPackageInfo;

export function searchLicense(packages: PnpmPackageInfo[]) {
return Promise.all(
packages.map(async (pnpmPackage): Promise<PackageIfHasLicense | undefined> => {
packages.map(async (pnpmPackage): Promise<ExportedPnpmPackageInfo | undefined> => {
const dirents = await readdir(pnpmPackage.path, { withFileTypes: true });
const licenseDirent = dirents.find((dirent) => dirent.name.toLowerCase().includes('license'));
if (licenseDirent === undefined) {
Expand All @@ -16,7 +14,9 @@ export function searchLicense(packages: PnpmPackageInfo[]) {
name: pnpmPackage.name,
licensePath: `${pnpmPackage.path}/${licenseDirent.name}`,
});
return licenseTxt === undefined ? pnpmPackage : { ...pnpmPackage, licenseTxt };
// remove path property
const { path, ...PnpmPackageInfo } = pnpmPackage;
return licenseTxt === undefined ? PnpmPackageInfo : { ...PnpmPackageInfo, licenseTxt };
}),
).then((licenses) => licenses.filter(Boolean));
}

0 comments on commit def8620

Please sign in to comment.