import React, { useMemo } from 'react'; import { BUNDLE_PACKAGES_DUPLICATE, PACKAGES_SEPARATOR, PACKAGE_ID_SEPARATOR, MetricRunInfo, getBundleModulesBySearch, getBundlePackagesByNameComponentLink, } from '@bundle-stats/utils'; import { Package } from '@bundle-stats/utils/types/webpack'; import { FlexStack } from '../../layout/flex-stack'; import { Stack } from '../../layout/stack'; import { ComponentLink } from '../component-link'; import { FileName } from '../../ui/file-name'; import { Tag } from '../../ui/tag'; import { EntryInfo } from '../entry-info'; import css from './package-info.module.css'; import { Icon } from '../../ui'; interface PackageInfoProps { item: { label: string; duplicate?: boolean; runs: Array; }; labels: Array; customComponentLink?: React.ElementType; onClose: () => void; } export const PackageInfo = (props: PackageInfoProps & React.ComponentProps<'div'>) => { const { className = '', item, labels, customComponentLink: CustomComponentLink = ComponentLink, onClose, } = props; const packages = item.label.split(PACKAGES_SEPARATOR); const name = packages[packages.length - 1]; const fallbackPackagePath = `node_modules/${item.label .split(PACKAGES_SEPARATOR) .join('/node_modules/')}`; const normalizedPackagePath = `${item.runs?.[0]?.path || fallbackPackagePath}/`; const [normalizedName, packageId] = name.split(PACKAGE_ID_SEPARATOR); const packageTitle = useMemo( () => ( {normalizedName} {packageId && ( {PACKAGE_ID_SEPARATOR} {packageId} )} ), [normalizedName, packageId], ); const tags = useMemo(() => { if (!item.duplicate) { return null; } return (
Duplicate
); }, [item]); return ( {item.duplicate && (
View all duplicate instances
)} Search modules by package path
npmjs.com bundlephobia.com
); };