Skip to content

Commit f5d6761

Browse files
committed
fix: apply second-round copilot review suggestions
- Rename pure helper useVersionTags to getVersionTags - Format publish dates in local time instead of UTC - Drop maintainer email (PII) from the UI - Use type=search with a stable name and autocomplete off - Replace test setTimeout waits with waitFor
1 parent 1809236 commit f5d6761

6 files changed

Lines changed: 17 additions & 14 deletions

File tree

‎apps/web/app/components/cnpm/MaintainersCard.tsx‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,6 @@ function MaintainerRow({ maintainer }: { maintainer: Maintainer }) {
3131
</Avatar>
3232
<div className="min-w-0">
3333
<div className="truncate text-sm font-medium text-foreground">{maintainer.name}</div>
34-
{maintainer.email && (
35-
<div className="truncate text-xs text-muted-foreground">{maintainer.email}</div>
36-
)}
3734
</div>
3835
</div>
3936
);

‎apps/web/app/components/cnpm/NpmSearchForm.tsx‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,9 @@ export function NpmSearchForm({
4343
<SearchIcon className={large ? "size-5" : "size-4"} />
4444
</InputGroupAddon>
4545
<InputGroupInput
46-
type="text"
46+
type="search"
47+
name="q"
48+
autoComplete="off"
4749
value={value}
4850
autoFocus={autoFocus}
4951
onChange={(event) => setValue(event.target.value)}

‎apps/web/app/components/cnpm/PkgHeader.tsx‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {
99
} from "~/components/ui/select";
1010
import { Badge } from "~/components/ui/badge";
1111
import { Button } from "~/components/ui/button";
12-
import { sortVersions, useVersionTags, type PkgTab } from "~/lib/registry/parse";
12+
import { sortVersions, getVersionTags, type PkgTab } from "~/lib/registry/parse";
1313
import type { RegistryManifest } from "~/lib/registry/types";
1414
import { PkgTabs } from "./PkgTabs";
1515

@@ -39,7 +39,7 @@ export function PkgHeader({
3939
onVersionChange: (version: string) => void;
4040
}) {
4141
const versions = sortVersions(manifest.versions);
42-
const tags = useVersionTags(manifest);
42+
const tags = getVersionTags(manifest);
4343
const [copied, setCopied] = useState(false);
4444
const installCommand = `npm install ${manifest.name}@${version}`;
4545
const repo = repoUrl(manifest.repository);

‎apps/web/app/components/cnpm/VersionTable.tsx‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,23 @@ import {
88
TableRow,
99
} from "~/components/ui/table";
1010
import { Badge } from "~/components/ui/badge";
11-
import { sortVersions, useVersionTags } from "~/lib/registry/parse";
11+
import { sortVersions, getVersionTags } from "~/lib/registry/parse";
1212
import type { RegistryManifest } from "~/lib/registry/types";
1313

1414
function formatDate(value: number | string | undefined) {
1515
if (value === undefined || value === null || value === "") return "-";
1616
const numeric = typeof value === "string" && /^\d+$/.test(value) ? Number(value) : value;
1717
const date = new Date(numeric);
1818
if (Number.isNaN(date.getTime())) return "-";
19-
return date.toISOString().slice(0, 10);
19+
const year = date.getFullYear();
20+
const month = String(date.getMonth() + 1).padStart(2, "0");
21+
const day = String(date.getDate()).padStart(2, "0");
22+
return `${year}-${month}-${day}`;
2023
}
2124

2225
export function VersionTable({ manifest, version }: { manifest: RegistryManifest; version: string }) {
2326
const versions = sortVersions(manifest.versions);
24-
const tags = useVersionTags(manifest);
27+
const tags = getVersionTags(manifest);
2528

2629
return (
2730
<Table>

‎apps/web/app/lib/registry/parse.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ export function normalizeVersionSpec(spec: string | undefined) {
4343
return spec;
4444
}
4545

46-
export function useVersionTags(manifest: RegistryManifest): Record<string, string[]> {
46+
export function getVersionTags(manifest: RegistryManifest): Record<string, string[]> {
4747
const tagsMap = manifest["dist-tags"] || {};
4848
const result: Record<string, string[]> = {};
4949
for (const [tag, version] of Object.entries(tagsMap)) {

‎apps/web/tests/CnpmRegistry.test.tsx‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { render, screen } from "@testing-library/react";
1+
import { render, screen, waitFor } from "@testing-library/react";
22
import { createMemoryRouter, RouterProvider } from "react-router";
33
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
44
import { REGISTRY } from "~/lib/registry/client";
@@ -71,7 +71,7 @@ describe("cnpm landing", () => {
7171
renderRoute(<CnpmLanding />, "/cnpm");
7272

7373
expect(screen.getByRole("search")).toBeInTheDocument();
74-
expect(screen.getByRole("textbox", { name: "搜索 npm 包" })).toBeInTheDocument();
74+
expect(screen.getByRole("searchbox", { name: "搜索 npm 包" })).toBeInTheDocument();
7575
expect(screen.getByRole("link", { name: "react" })).toHaveAttribute("href", "/cnpm/pkg/react");
7676
expect(await screen.findByText("包数量")).toBeInTheDocument();
7777
expect(screen.getByText("6m")).toBeInTheDocument();
@@ -86,8 +86,9 @@ describe("cnpm landing", () => {
8686
);
8787

8888
renderRoute(<CnpmLanding />, "/cnpm");
89-
await new Promise((resolve) => setTimeout(resolve, 20));
90-
expect(screen.queryByText("包数量")).not.toBeInTheDocument();
89+
await waitFor(() => {
90+
expect(screen.queryByText("包数量")).not.toBeInTheDocument();
91+
});
9192
});
9293
});
9394

0 commit comments

Comments
 (0)