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

Commit b2e420d

Browse files
committed
fix: support deprecated license object properties
1 parent 283464f commit b2e420d

File tree

4 files changed

+41
-45
lines changed

4 files changed

+41
-45
lines changed

src/components/Dist/Dist.tsx

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { DetailContextConsumer, VersionPageConsumerProps } from '../../pages/ver
66
import { Heading, DistListItem, DistChips } from './styles';
77
import fileSizeSI from '../../utils/file-size';
88
import { PackageMetaInterface } from 'types/packageMeta';
9+
import { formatLicense } from '../../utils/package';
910

1011
class Dist extends Component {
1112
public render(): JSX.Element {
@@ -18,28 +19,25 @@ class Dist extends Component {
1819
);
1920
}
2021

21-
private renderChips(dist, license: string): JSX.Element | never[] {
22+
private renderChips(dist, license: PackageMetaInterface['latest']['license']): (JSX.Element | undefined)[] {
2223
const distDict = {
2324
'file-count': dist.fileCount,
2425
size: dist.unpackedSize && fileSizeSI(dist.unpackedSize),
2526
license,
2627
};
2728

28-
const chipsList = Object.keys(distDict).reduce((componentList, title, key) => {
29-
// @ts-ignore
30-
const value = distDict[title];
31-
if (value) {
32-
const label = (
33-
<span>
34-
{/* eslint-disable-next-line */}
35-
<b>{title.split('-').join(' ')}</b>:{value}
36-
</span>
37-
);
38-
// @ts-ignore is not assignable to parameter of type 'never'
39-
componentList.push(<DistChips key={key} label={label} />);
40-
}
41-
return componentList;
42-
}, []);
29+
const chipsList = Object.keys(distDict).map((dist, key) => {
30+
if (!distDict[dist]) return;
31+
32+
const value = dist === 'license' ? formatLicense(distDict[dist]) : distDict[dist];
33+
const label = (
34+
<span>
35+
{/* eslint-disable-next-line */}
36+
<b>{dist.replace('-', ' ')}</b>: {value}
37+
</span>
38+
);
39+
return <DistChips key={key} label={label} />;
40+
});
4341

4442
return chipsList;
4543
}

src/components/Package/Package.tsx

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,29 @@ import HomeIcon from '@material-ui/icons/Home';
66
import ListItem from '@material-ui/core/ListItem';
77
import Tooltip from '@material-ui/core/Tooltip';
88

9+
import { PackageMetaInterface } from 'types/packageMeta';
910
import Tag from '../Tag';
1011
import fileSizeSI from '../../utils/file-size';
1112
import { formatDate, formatDateDistance } from '../../utils/package';
12-
13+
import {
14+
Author,
15+
Avatar,
16+
Description,
17+
Details,
18+
GridRightAligned,
19+
Icon,
20+
IconButton,
21+
OverviewItem,
22+
PackageList,
23+
PackageListItem,
24+
PackageListItemText,
25+
PackageTitle,
26+
Published,
27+
TagContainer,
28+
Text,
29+
WrapperLink,
30+
} from './styles';
31+
import { isURL } from '../../utils/url';
1332
interface Author {
1433
name: string;
1534
avatar?: string;
@@ -30,32 +49,11 @@ export interface PackageInterface {
3049
author: Author;
3150
description?: string;
3251
keywords?: string[];
33-
license?: string | null;
52+
license?: PackageMetaInterface['latest']['license'];
3453
homepage?: string;
3554
bugs?: Bugs;
3655
dist?: Dist;
3756
}
38-
// interface Props {} & PackageInterface;
39-
40-
import {
41-
Author,
42-
Avatar,
43-
Description,
44-
Details,
45-
GridRightAligned,
46-
Icon,
47-
IconButton,
48-
OverviewItem,
49-
PackageList,
50-
PackageListItem,
51-
PackageListItemText,
52-
PackageTitle,
53-
Published,
54-
TagContainer,
55-
Text,
56-
WrapperLink,
57-
} from './styles';
58-
import { isURL } from '../../utils/url';
5957

6058
const Package: React.FC<PackageInterface> = ({
6159
author: { name: authorName, avatar: authorAvatar },

src/utils/package.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,6 @@ import { isObject } from 'util';
66

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

9-
export interface License {
10-
type: string;
11-
url: string;
12-
}
13-
149
/**
1510
* Formats license field for webui.
1611
* @see https://docs.npmjs.com/files/package.json#license

types/packageMeta.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,12 @@ export interface PackageMetaInterface {
55
fileCount: number;
66
unpackedSize: number;
77
};
8-
license: string;
8+
license?: Partial<LicenseInterface> | string | null;
99
};
1010
_uplinks: {};
1111
}
12+
13+
interface LicenseInterface {
14+
type: string;
15+
url: string;
16+
}

0 commit comments

Comments
 (0)