Skip to content
This repository has been archived by the owner on Jan 16, 2022. It is now read-only.

Commit

Permalink
fix: support deprecated license object properties
Browse files Browse the repository at this point in the history
  • Loading branch information
griffithtp committed Jul 6, 2019
1 parent 283464f commit b2e420d
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 45 deletions.
30 changes: 14 additions & 16 deletions src/components/Dist/Dist.tsx
Expand Up @@ -6,6 +6,7 @@ import { DetailContextConsumer, VersionPageConsumerProps } from '../../pages/ver
import { Heading, DistListItem, DistChips } from './styles';
import fileSizeSI from '../../utils/file-size';
import { PackageMetaInterface } from 'types/packageMeta';
import { formatLicense } from '../../utils/package';

class Dist extends Component {
public render(): JSX.Element {
Expand All @@ -18,28 +19,25 @@ class Dist extends Component {
);
}

private renderChips(dist, license: string): JSX.Element | never[] {
private renderChips(dist, license: PackageMetaInterface['latest']['license']): (JSX.Element | undefined)[] {
const distDict = {
'file-count': dist.fileCount,
size: dist.unpackedSize && fileSizeSI(dist.unpackedSize),
license,
};

const chipsList = Object.keys(distDict).reduce((componentList, title, key) => {
// @ts-ignore
const value = distDict[title];
if (value) {
const label = (
<span>
{/* eslint-disable-next-line */}
<b>{title.split('-').join(' ')}</b>:{value}
</span>
);
// @ts-ignore is not assignable to parameter of type 'never'
componentList.push(<DistChips key={key} label={label} />);
}
return componentList;
}, []);
const chipsList = Object.keys(distDict).map((dist, key) => {
if (!distDict[dist]) return;

const value = dist === 'license' ? formatLicense(distDict[dist]) : distDict[dist];
const label = (
<span>
{/* eslint-disable-next-line */}
<b>{dist.replace('-', ' ')}</b>: {value}
</span>
);
return <DistChips key={key} label={label} />;
});

return chipsList;
}
Expand Down
44 changes: 21 additions & 23 deletions src/components/Package/Package.tsx
Expand Up @@ -6,10 +6,29 @@ import HomeIcon from '@material-ui/icons/Home';
import ListItem from '@material-ui/core/ListItem';
import Tooltip from '@material-ui/core/Tooltip';

import { PackageMetaInterface } from 'types/packageMeta';
import Tag from '../Tag';
import fileSizeSI from '../../utils/file-size';
import { formatDate, formatDateDistance } from '../../utils/package';

import {
Author,
Avatar,
Description,
Details,
GridRightAligned,
Icon,
IconButton,
OverviewItem,
PackageList,
PackageListItem,
PackageListItemText,
PackageTitle,
Published,
TagContainer,
Text,
WrapperLink,
} from './styles';
import { isURL } from '../../utils/url';
interface Author {
name: string;
avatar?: string;
Expand All @@ -30,32 +49,11 @@ export interface PackageInterface {
author: Author;
description?: string;
keywords?: string[];
license?: string | null;
license?: PackageMetaInterface['latest']['license'];
homepage?: string;
bugs?: Bugs;
dist?: Dist;
}
// interface Props {} & PackageInterface;

import {
Author,
Avatar,
Description,
Details,
GridRightAligned,
Icon,
IconButton,
OverviewItem,
PackageList,
PackageListItem,
PackageListItemText,
PackageTitle,
Published,
TagContainer,
Text,
WrapperLink,
} from './styles';
import { isURL } from '../../utils/url';

const Package: React.FC<PackageInterface> = ({
author: { name: authorName, avatar: authorAvatar },
Expand Down
5 changes: 0 additions & 5 deletions src/utils/package.ts
Expand Up @@ -6,11 +6,6 @@ import { isObject } from 'util';

export const TIMEFORMAT = 'DD.MM.YYYY, HH:mm:ss';

export interface License {
type: string;
url: string;
}

/**
* Formats license field for webui.
* @see https://docs.npmjs.com/files/package.json#license
Expand Down
7 changes: 6 additions & 1 deletion types/packageMeta.ts
Expand Up @@ -5,7 +5,12 @@ export interface PackageMetaInterface {
fileCount: number;
unpackedSize: number;
};
license: string;
license?: Partial<LicenseInterface> | string | null;
};
_uplinks: {};
}

interface LicenseInterface {
type: string;
url: string;
}

0 comments on commit b2e420d

Please sign in to comment.