Skip to content

Commit

Permalink
pnpm update 対応
Browse files Browse the repository at this point in the history
  • Loading branch information
NEKOYASAN committed May 9, 2024
1 parent 1b0f993 commit f932100
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 17 deletions.
2 changes: 1 addition & 1 deletion .tool-versions
Original file line number Diff line number Diff line change
@@ -1 +1 @@
nodejs 20.12.2
nodejs 20.13.0
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@luco-inc/pnpm-license-exporter",
"version": "3.0.4",
"version": "3.0.5",
"description": "Dependencies license exporter for projects using pnpm.",
"license": "MIT",
"type": "module",
Expand Down
7 changes: 4 additions & 3 deletions src/pnpm/export-license/types/export-licenses.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ export type PnpmPackageInfo = {
author: string;
description: string;
homepage: string;
path: string;
path?: string;
paths?: string[];
};

export type PnpmLicenses = {
Expand All @@ -15,9 +16,9 @@ export type PnpmLicenses = {
export type ExportedPnpmPackageInfo = {
licenseTxt?: string;
// path property is only not exported
} & Omit<PnpmPackageInfo, 'path'>;
} & Omit<PnpmPackageInfo, 'path' | 'paths'>;

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

export type LicensePackageKey = keyof LicensePackageInfo;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import type { PnpmPackageInfo, ExportedPnpmPackageInfo } from '../types/export-licenses.types';

export function buildExportedPnpmPackageInfo(pnpmPackage: PnpmPackageInfo, licenseTxt: undefined | string): ExportedPnpmPackageInfo {
export function buildExportedPnpmPackageInfo(
pnpmPackage: PnpmPackageInfo,
licenseTxt: undefined | string
): ExportedPnpmPackageInfo {
// remove path property
const { path, ...PnpmPackageInfo } = pnpmPackage;
return licenseTxt === undefined
? PnpmPackageInfo
: { ...PnpmPackageInfo, licenseTxt };
}
const { path, paths, ...PnpmPackageInfo } = pnpmPackage;
return licenseTxt === undefined ? PnpmPackageInfo : { ...PnpmPackageInfo, licenseTxt };
}
3 changes: 0 additions & 3 deletions src/pnpm/export-license/utils/find-license-dirent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@ import type { Dirent } from 'node:fs';
import { readdir } from 'node:fs/promises';

export async function findLicenseDirent(pnpmPackagePath: string): Promise<Dirent | undefined> {
if (!pnpmPackagePath) {
return undefined;
}
const dirents = await readdir(pnpmPackagePath, { withFileTypes: true });
return dirents.find((dirent) => dirent.name.toLowerCase().includes('license'));
}
8 changes: 5 additions & 3 deletions src/pnpm/export-license/utils/search-license.util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ export function searchLicense(
async (
pnpmPackage
): Promise<ExportedPnpmPackageInfo | undefined | (ExportedPnpmPackageInfo | undefined)[]> => {
if (Array.isArray(pnpmPackage.path)) {
if (pnpmPackage.paths) {
return await Promise.all(
pnpmPackage.path.map(async (path) => {
pnpmPackage.paths.map(async (path) => {
const licenseDirent = await findLicenseDirent(path);
if (licenseDirent === undefined) {
return undefined;
Expand All @@ -25,7 +25,7 @@ export function searchLicense(
return buildExportedPnpmPackageInfo(pnpmPackage, licenseTxt);
})
);
} else {
} else if (pnpmPackage.path) {
const licenseDirent = await findLicenseDirent(pnpmPackage.path);
if (licenseDirent === undefined) {
return undefined;
Expand All @@ -35,6 +35,8 @@ export function searchLicense(
licensePath: `${pnpmPackage.path}/${licenseDirent.name}`,
});
return buildExportedPnpmPackageInfo(pnpmPackage, licenseTxt);
} else {
return undefined;
}
}
)
Expand Down

0 comments on commit f932100

Please sign in to comment.