mirror of
https://github.com/modrinth/code.git
synced 2026-08-31 20:17:16 +00:00
feat: remove duplicated dependencies
This commit is contained in:
@@ -1,8 +1,14 @@
|
|||||||
<template>
|
<template>
|
||||||
<div v-if="downloadRows.length > 0" class="flex flex-col gap-1">
|
<div v-if="downloadRows.length > 0" class="flex flex-col gap-1">
|
||||||
<div v-if="showTitle" class="flex flex-wrap items-center justify-between gap-2">
|
<div v-if="showTitle" class="flex flex-wrap items-center justify-between gap-2">
|
||||||
<h3 class="m-0 text-base font-semibold text-contrast">
|
<h3 class="m-0 flex items-center gap-1.5 text-base font-semibold text-contrast">
|
||||||
{{ sectionTitle }}
|
{{ sectionTitle }}
|
||||||
|
<InfoIcon
|
||||||
|
v-if="visibleDependencyRows.length > 0"
|
||||||
|
v-tooltip="formatMessage(messages.duplicateDependenciesHidden)"
|
||||||
|
aria-hidden="true"
|
||||||
|
class="size-4 text-secondary"
|
||||||
|
/>
|
||||||
</h3>
|
</h3>
|
||||||
</div>
|
</div>
|
||||||
<div class="flex flex-col gap-2">
|
<div class="flex flex-col gap-2">
|
||||||
@@ -18,7 +24,7 @@
|
|||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import type { Labrinth } from '@modrinth/api-client'
|
import type { Labrinth } from '@modrinth/api-client'
|
||||||
import { FileIcon } from '@modrinth/assets'
|
import { FileIcon, InfoIcon } from '@modrinth/assets'
|
||||||
import {
|
import {
|
||||||
type CdnDownloadReason,
|
type CdnDownloadReason,
|
||||||
defineMessages,
|
defineMessages,
|
||||||
@@ -242,6 +248,10 @@ const dependencyRows = computed<DownloadDependencyRow[]>(
|
|||||||
() => props.dependencies || resolvedDependencyRows.value,
|
() => props.dependencies || resolvedDependencyRows.value,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const visibleDependencyRows = computed<DownloadDependencyRow[]>(() =>
|
||||||
|
dedupeDependencyRows(dependencyRows.value),
|
||||||
|
)
|
||||||
|
|
||||||
const additionalFileRows = computed<DownloadDependencyRow[]>(() =>
|
const additionalFileRows = computed<DownloadDependencyRow[]>(() =>
|
||||||
props.additionalFiles.map((file) => ({
|
props.additionalFiles.map((file) => ({
|
||||||
key: `additional-file-${additionalFileKey(file)}`,
|
key: `additional-file-${additionalFileKey(file)}`,
|
||||||
@@ -256,18 +266,20 @@ const additionalFileRows = computed<DownloadDependencyRow[]>(() =>
|
|||||||
)
|
)
|
||||||
|
|
||||||
const downloadRows = computed<DownloadDependencyRow[]>(() => [
|
const downloadRows = computed<DownloadDependencyRow[]>(() => [
|
||||||
...dependencyRows.value,
|
...visibleDependencyRows.value,
|
||||||
...additionalFileRows.value,
|
...additionalFileRows.value,
|
||||||
])
|
])
|
||||||
|
|
||||||
const sectionTitle = computed(() =>
|
const sectionTitle = computed(() =>
|
||||||
formatMessage(
|
formatMessage(
|
||||||
dependencyRows.value.length > 0 ? messages.dependenciesTitle : messages.additionalFilesTitle,
|
visibleDependencyRows.value.length > 0
|
||||||
|
? messages.dependenciesTitle
|
||||||
|
: messages.additionalFilesTitle,
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
const downloadableDependencyFiles = computed<DownloadableDependencyFile[]>(() =>
|
const downloadableDependencyFiles = computed<DownloadableDependencyFile[]>(() =>
|
||||||
collectDownloadableDependencyFiles(dependencyRows.value),
|
collectDownloadableDependencyFiles(visibleDependencyRows.value),
|
||||||
)
|
)
|
||||||
|
|
||||||
watch(
|
watch(
|
||||||
@@ -283,7 +295,9 @@ function primaryFileForVersion(version?: Labrinth.Versions.v3.Version) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function shouldShowDependency(dependency: ResolvedContent) {
|
function shouldShowDependency(dependency: ResolvedContent) {
|
||||||
return !('reason' in dependency && dependency.reason === 'quilt_fabric_api')
|
return !(
|
||||||
|
'reason' in dependency && ['duplicate_project', 'quilt_fabric_api'].includes(dependency.reason)
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
function createDependencyRow(dependency: ResolvedContent): DownloadDependencyRow | null {
|
function createDependencyRow(dependency: ResolvedContent): DownloadDependencyRow | null {
|
||||||
@@ -356,6 +370,29 @@ function additionalFileKey(file: Labrinth.Versions.v3.VersionFile) {
|
|||||||
return file.hashes?.sha1 ?? file.filename
|
return file.hashes?.sha1 ?? file.filename
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function dedupeDependencyRows(
|
||||||
|
rows: DownloadDependencyRow[],
|
||||||
|
seenDependencies = new Set<string>(),
|
||||||
|
): DownloadDependencyRow[] {
|
||||||
|
return rows.flatMap((row) => {
|
||||||
|
const identity = dependencyRowIdentity(row)
|
||||||
|
if (seenDependencies.has(identity)) return []
|
||||||
|
|
||||||
|
seenDependencies.add(identity)
|
||||||
|
|
||||||
|
return [
|
||||||
|
{
|
||||||
|
...row,
|
||||||
|
dependencies: dedupeDependencyRows(row.dependencies, seenDependencies),
|
||||||
|
},
|
||||||
|
]
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
function dependencyRowIdentity(row: DownloadDependencyRow) {
|
||||||
|
return row.projectHref ?? row.downloadHref ?? row.key
|
||||||
|
}
|
||||||
|
|
||||||
function collectDownloadableDependencyFiles(
|
function collectDownloadableDependencyFiles(
|
||||||
rows: DownloadDependencyRow[],
|
rows: DownloadDependencyRow[],
|
||||||
seenHrefs = new Set<string>(),
|
seenHrefs = new Set<string>(),
|
||||||
@@ -392,6 +429,10 @@ const messages = defineMessages({
|
|||||||
id: 'project.download.dependencies-title',
|
id: 'project.download.dependencies-title',
|
||||||
defaultMessage: 'Dependencies',
|
defaultMessage: 'Dependencies',
|
||||||
},
|
},
|
||||||
|
duplicateDependenciesHidden: {
|
||||||
|
id: 'project.download.duplicate-dependencies-hidden',
|
||||||
|
defaultMessage: 'Duplicate dependencies are hidden',
|
||||||
|
},
|
||||||
additionalFilesTitle: {
|
additionalFilesTitle: {
|
||||||
id: 'project.download.additional-files-title',
|
id: 'project.download.additional-files-title',
|
||||||
defaultMessage: 'Additional files',
|
defaultMessage: 'Additional files',
|
||||||
|
|||||||
Reference in New Issue
Block a user