Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ref(*): fix all the things #1155

Merged
merged 1 commit into from
Jan 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 12 additions & 7 deletions client/src/components/package-details/MinimalPackageTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ import { ArchDistroString } from '../../types/package-info'
import MinimalPackageTableRow from './MinimalPackageTableRow'
import { useTranslation } from 'react-i18next'

const MinimalPackageTable: FC<{ packages: (ArchDistroString | string)[] }> = ({
packages,
}) => {
const MinimalPackageTable: FC<{
packages: (ArchDistroString | string)[]
type: string
}> = ({ packages, type }) => {
const { t } = useTranslation()
return (
<Table variant={'simple'}>
<Table variant='simple'>
<Thead>
<Tr>
<Th>{t('packageDetails.requiredByModal.name')}</Th>
Expand All @@ -21,9 +22,13 @@ const MinimalPackageTable: FC<{ packages: (ArchDistroString | string)[] }> = ({
<Tbody>
{packages.map((pkg, i) => (
<MinimalPackageTableRow
external={typeof pkg === 'string'}
key={(typeof pkg === 'string' ? pkg : pkg.value) + i}
pkg={typeof pkg === 'string' ? pkg : pkg.value}
external={
type !== 'requiredBy' &&
type !== 'pacstallDependencies'
}
key={(pkg.value || pkg.packageName) + i}
pkg={pkg.value || pkg.packageName}
description={pkg.description || null}
/>
))}
</Tbody>
Expand Down
29 changes: 9 additions & 20 deletions client/src/components/package-details/MinimalPackageTableRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,11 @@ import { FC } from 'react'
import { useTranslation } from 'react-i18next'
import { Link as Rlink } from 'react-router-dom'

const getDescription = (nameWithDescription: string): string | null => {
return nameWithDescription?.includes(':')
? nameWithDescription.split(':')[1].trim()
: null
}

const getName = (nameWithDescription: string): string => {
return nameWithDescription?.includes(':')
? nameWithDescription.split(':')[0]
: nameWithDescription
}

const MinimalPackageTableRow: FC<{ pkg: string; external: boolean }> = ({
pkg,
external,
}) => {
const MinimalPackageTableRow: FC<{
pkg: string
description: string
external: boolean
}> = ({ pkg, description, external }) => {
const { t } = useTranslation()

return (
Expand All @@ -34,13 +23,13 @@ const MinimalPackageTableRow: FC<{ pkg: string; external: boolean }> = ({
<Tooltip
openDelay={500}
label={
getDescription(pkg) ||
description ||
t('packageDetails.dependenciesModal.noDescription')
}
>
<Text fontSize='md' fontWeight='500'>
{external ? (
<>{getName(pkg)}</>
<>{pkg}</>
) : (
<Link
as={Rlink}
Expand All @@ -49,9 +38,9 @@ const MinimalPackageTableRow: FC<{ pkg: string; external: boolean }> = ({
'pink.600',
'pink.400',
)}
to={`/packages/${getName(pkg)}`}
to={`/packages/${pkg}`}
>
{getName(pkg)}
{pkg}
</Link>
)}
</Text>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ const PackageDependenciesModal: FC<{ name: string } & UseDisclosureProps> = ({
packages={
data!.runtimeDependencies || []
}
type='runtimeDependencies'
/>
</Box>
)}
Expand All @@ -64,6 +65,7 @@ const PackageDependenciesModal: FC<{ name: string } & UseDisclosureProps> = ({
</Heading>
<MinimalPackageTable
packages={data!.buildDependencies || []}
type='buildDependencies'
/>
</Box>
)}
Expand All @@ -79,6 +81,7 @@ const PackageDependenciesModal: FC<{ name: string } & UseDisclosureProps> = ({
packages={
data!.optionalDependencies || []
}
type='optionalDependencies'
/>
</Box>
)}
Expand All @@ -94,6 +97,7 @@ const PackageDependenciesModal: FC<{ name: string } & UseDisclosureProps> = ({
packages={
data!.pacstallDependencies || []
}
type='pacstallDependencies'
/>
</Box>
)}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { HStack, Heading, Text } from '@chakra-ui/react'
import { FC } from 'react'
import PackageInfo from '../../types/package-info'
import InstallNowButton from './InstallNowButton'

const PackageDetailsHeader: FC<{ data: PackageInfo; isMobile: boolean }> = (
{ data },
Expand All @@ -13,7 +12,6 @@ const PackageDetailsHeader: FC<{ data: PackageInfo; isMobile: boolean }> = (
<HStack>
<Heading>{data.packageName}</Heading>
</HStack>
{!isMobile && <InstallNowButton />}
</HStack>

<Text mt='5'>{data.description}</Text>
Expand Down
8 changes: 7 additions & 1 deletion client/src/components/package-details/PackageDetailsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,13 @@ const PackageDetailsPage: FC<PackageDetailsPageProps> = ({
requiredByModal={requiredByModal}
/>
<HowToInstall
name={data.packageName}
name={
data.baseTotal > 1
? data.baseIndex === 0
? `${data.packageBase}:pkgbase`
: `${data.packageBase}:${data.packageName}`
: data.packageName
}
prettyName={data.packageName}
isMobile={isMobile}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ const PackageDetailsTable: FC<{
<Link
color='pink.400'
isExternal
href={`https://github.com/pacstall/pacstall-programs/blob/master/packages/${data.packageName}/${data.packageName}.pacscript`}
href={`https://github.com/pacstall/pacstall-programs/blob/master/packages/${data.packageBase}/${data.packageBase}.pacscript`}
>
{t('packageDetails.openInGithub')}{' '}
<Icon
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ const PackageRequiredByModal: FC<{ name: string } & UseDisclosureProps> = ({
const { data, loading, error } = usePackageRequiredBy(name)
const { t } = useTranslation()

const ComputedPackageList = () => <MinimalPackageTable packages={data} />
const ComputedPackageList = () => (
<MinimalPackageTable packages={data} type='requiredBy' />
)

return (
<Modal scrollBehavior='inside' isOpen={isOpen!} onClose={onClose!}>
Expand Down
11 changes: 10 additions & 1 deletion client/src/components/packages/PackageTableRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,16 @@ const PackageTableRow: FC<{ pkg: PackageInfo; disabled?: boolean }> = ({
display={useBreakpointValue({ base: 'none', md: 'table-cell' })}
>
<Text fontSize='sm'>
<SmartCodeSnippetInstall size='sm' name={pkg.packageName} />
<SmartCodeSnippetInstall
size='sm'
name={
pkg.baseTotal > 1
? pkg.baseIndex === 0
? `${pkg.packageBase}:pkgbase`
: `${pkg.packageBase}:${pkg.packageName}`
: pkg.packageName
}
/>
</Text>
</Td>
</Tr>
Expand Down
52 changes: 41 additions & 11 deletions client/src/hooks/usePackageDependencies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,50 @@ const usePackageDependencies = (name: string) => {
const [error, setError] = useState(false)

useEffect(() => {
setError(false)
setLoading(true)
axios
.get<PackageDependencies>(
serverConfig.host + `/api/packages/${name}/dependencies`,
)
.then(result => {
const fetchDependencies = async () => {
setError(false)
setLoading(true)

try {
const result = await axios.get<PackageDependencies>(
`${serverConfig.host}/api/packages/${name}/dependencies`,
)

const pacdeps = result.data.pacstallDependencies || []

const descriptionDeps = await Promise.all(
pacdeps.map(async dep => {
try {
const depResult = await axios.get(
`${serverConfig.host}/api/packages/${dep.value}`,
)
return {
...dep,
description: depResult.data.description,
}
} catch (e) {
console.error(
`Failed to fetch description for ${dep.value}`,
e,
)
return { ...dep, description: null }
}
}),
)

setData({
...result.data,
pacstallDependencies: descriptionDeps,
})
setLoading(false)
setData(result.data)
})
.catch(() => {
} catch (e) {
console.error('Error fetching package dependencies:', e)
setError(true)
setLoading(false)
})
}
}

fetchDependencies()
}, [name])

return {
Expand Down
4 changes: 4 additions & 0 deletions client/src/types/package-info.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
export default interface PackageInfo {
packageName: string
prettyName: string
packageBase: string
baseIndex: int
baseTotal: int
description: string
version: string
sourceVersion: string
release: string
epoch: string
latestVersion?: string
Expand Down
2 changes: 1 addition & 1 deletion server/types/pac/parser/last_updated.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func setLastUpdatedAt(packages []*pac.Script) error {

for _, pkg := range packages {
if tuple, err := array.FindBy(lastUpdatedTuples, func(tuple packageLastUpdatedTuple) bool {
return tuple.packageName == pkg.PackageName
return tuple.packageName == pkg.PackageBase
}); err == nil {
pkg.LastUpdatedAt = tuple.lastUpdated
} else {
Expand Down
2 changes: 2 additions & 0 deletions server/types/pac/parser/pacsh/git_version.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@ func ApplyGitVersion(p *pac.Script) error {
}

if p.Epoch != "" {
p.SourceVersion = version
p.Version = p.Epoch + ":" + version + "-" + p.Release
} else {
p.SourceVersion = version
p.Version = version + "-" + p.Release
}

Expand Down
12 changes: 7 additions & 5 deletions server/types/pac/parser/pacsh/parse_pac_output.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,17 @@ import (
"pacstall.dev/webserver/types/pac"
)

func ParsePacOutput(data []byte) (*pac.Script, error) {
func ParsePacOutput(data []byte) ([]*pac.Script, error) {
var scripts []*pac.Script
out, err := srcinfo.Parse(string(data))
if err != nil {
return nil, err
}

ps := pac.FromSrcInfo(*out)
scripts = pac.FromSrcInfo(*out)
for idx := range scripts {
scripts[idx].PrettyName = getPrettyName(scripts[idx])
}

ps.PrettyName = getPrettyName(ps)

return ps, nil
return scripts, nil
}
37 changes: 26 additions & 11 deletions server/types/pac/parser/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func ParseAll() error {
}))

pacstore.Update(loadedPacscripts)
log.Info("successfully loaded %v (%v / %v) packages", types.Percent(float64(len(loadedPacscripts))/float64(len(pkgList))), len(loadedPacscripts), len(pkgList))
log.Info("successfully loaded %v packages from %v pacscripts", len(loadedPacscripts), len(pkgList))

return nil
}
Expand All @@ -79,11 +79,19 @@ func readKnownPacscriptNames() ([]string, error) {
}

names := strings.Split(strings.TrimSpace(string(bytes)), "\n")
for idx := range names {
names[idx] = strings.TrimSpace(names[idx])
}
var filteredNames []string

for idx := range names {
names[idx] = strings.TrimSpace(names[idx])

if strings.HasSuffix(names[idx], ":pkgbase") {
filteredNames = append(filteredNames, strings.TrimSuffix(names[idx], ":pkgbase"))
} else if !strings.Contains(names[idx], ":") {
filteredNames = append(filteredNames, names[idx])
}
}

return names, nil
return filteredNames, nil
}

func parsePacscriptFiles(names []string) ([]*pac.Script, error) {
Expand All @@ -92,19 +100,26 @@ func parsePacscriptFiles(names []string) ([]*pac.Script, error) {
}

log.Info("parsing pacscripts...")
outChan := batch.Run(int(config.MaxOpenFiles), names, func(pacName string) (*pac.Script, error) {
outChan := batch.Run(int(config.MaxOpenFiles), names, func(pacName string) ([]*pac.Script, error) {
out, err := ParsePacscriptFile(config.GitClonePath, pacName)

if config.Repology.Enabled {
if err := repology.Sync(out); err != nil {
log.Debug("failed to sync %v with repology. Error: %+v", pacName, err)
}
for _, script := range out {
if err := repology.Sync(script); err != nil {
log.Debug("failed to sync %v with repology. Error: %+v", pacName, err)
}
}
}

return out, err
})
results := channels.ToSlice(outChan)
var allScripts []*pac.Script
for _, scripts := range results {
allScripts = append(allScripts, scripts...)
}

return channels.ToSlice(outChan), nil
return allScripts, nil
}

func readPacscriptFile(rootDir, name string) (scriptBytes []byte, fileName string, err error) {
Expand All @@ -118,7 +133,7 @@ func readPacscriptFile(rootDir, name string) (scriptBytes []byte, fileName strin
return scriptBytes, consts.SRCINFO_FILE_EXTENSION, nil
}

func ParsePacscriptFile(programsDirPath, name string) (*pac.Script, error) {
func ParsePacscriptFile(programsDirPath, name string) ([]*pac.Script, error) {
srcInfoData, _, err := readPacscriptFile(programsDirPath, name)
if err != nil {
return nil, errorx.Decorate(err, "failed to read pacscript '%v'", name)
Expand Down
1 change: 1 addition & 0 deletions server/types/pac/parser/search.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ func FilterPackages(packages []*pac.Script, filter, filterBy string) []*pac.Scri
case "name":
return filterByFunc(func(pi *pac.Script) bool {
return strings.Contains(pi.PackageName, filter) ||
strings.Contains(pi.PackageBase, filter) ||
func(ps []pac.ArchDistroString, filter string) bool {
return array.Any(ps, func(it pac.ArchDistroString) bool {
return strings.Contains(it.Value, filter)
Expand Down
Loading
Loading