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

feat: include module paths in Dependencies #556

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
52 changes: 48 additions & 4 deletions frontend/routes/package/dependencies.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,15 @@ export default function Deps(
) {
const iam = scopeIAM(state, data.member);

const deps: Record<string, { link: string; constraints: Set<string> }> = {};
const deps: Record<
string,
{
link: string;
constraints: Set<string>;
modules: Record<string, string | undefined>;
defaultModule: boolean;
}
> = {};

for (const dep of data.deps) {
const key = `${dep.kind}:${dep.name}`;
Expand All @@ -36,8 +44,17 @@ export default function Deps(
dep.kind === "jsr" ? "/" : "https://www.npmjs.com/package/"
}${dep.name}`,
constraints: new Set(),
modules: {},
defaultModule: false,
};
deps[key].constraints.add(dep.constraint);
if (dep.path) {
deps[key].modules[dep.path] = dep.kind === "jsr"
? `/${dep.name}/doc/${dep.path}/~`
: undefined;
} else {
deps[key].defaultModule = true;
}
}

const list = Object.entries(deps);
Expand Down Expand Up @@ -80,8 +97,9 @@ export default function Deps(
: (
<Table
columns={[
{ title: "Name", class: "w-1/3" },
{ title: "Versions", class: "w-auto" },
{ title: "Package", class: "w-1/3" },
{ title: "Versions", class: "w-1/3" },
{ title: "Modules", class: "w-auto" },
]}
currentUrl={url}
>
Expand All @@ -90,6 +108,8 @@ export default function Deps(
name={name}
link={info.link}
constraints={[...info.constraints]}
modules={Object.entries(info.modules)}
defaultModule={info.defaultModule}
/>
))}
</Table>
Expand All @@ -100,10 +120,12 @@ export default function Deps(
}

function Dependency(
{ name, link, constraints }: {
{ name, link, constraints, modules, defaultModule }: {
name: string;
link: string;
constraints: string[];
modules: [path: string, link?: string][];
defaultModule: boolean;
},
) {
return (
Expand All @@ -116,6 +138,28 @@ function Dependency(
<TableData class="space-x-4">
{constraints.map((constraint) => <span>{constraint}</span>)}
</TableData>
<TableData>
{modules.length > 0 && (
<ul>
{defaultModule && <li class="italic">(default)</li>}
{modules.map(([path, link]) => (
<li>
{link
? (
<a href={link} class="link">
{path}
</a>
)
: (
<span>
{path}
</span>
)}
</li>
))}
</ul>
)}
</TableData>
</TableRow>
);
}
Expand Down
Loading