Skip to content

Commit 942fcba

Browse files
authored
feat(swc-plugins): Improve UI (#58)
Closes #49 Closes #48
1 parent 07798b5 commit 942fcba

File tree

3 files changed

+142
-80
lines changed

3 files changed

+142
-80
lines changed

apps/swc-plugins/app/versions/range/[compatRangeId]/page.tsx

+42-11
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"use client";
22

3+
import { Checkbox } from "@/components/ui/checkbox";
34
import {
45
Table,
56
TableBody,
@@ -10,22 +11,39 @@ import {
1011
TableRow,
1112
} from "@/components/ui/table";
1213
import { apiClient } from "@/lib/trpc/web-client";
14+
import { useState } from "react";
1315

1416
export default function Page({
1517
params: { compatRangeId },
1618
}: {
1719
params: { compatRangeId: string };
1820
}) {
21+
const [includePrerelease, setIncludePrerelease] = useState(false);
1922
const [compatRange] = apiClient.compatRange.get.useSuspenseQuery({
2023
id: BigInt(compatRangeId),
24+
includePrerelease,
2125
});
2226

2327
return (
2428
<div>
25-
<h1 className="text-2xl font-bold">
26-
<kbd>swc_core</kbd>@<kbd>{compatRange.from}</kbd> -{" "}
27-
<kbd>{compatRange.to}</kbd>
28-
</h1>
29+
<div className="flex flex-row justify-between">
30+
<h1 className="mr-10 flex flex-col text-2xl font-bold">
31+
<kbd>swc_core</kbd>
32+
<span className="text-sm">
33+
@<kbd>{compatRange.from}</kbd> - <kbd>{compatRange.to}</kbd>
34+
</span>
35+
</h1>
36+
37+
<div>
38+
<Checkbox
39+
checked={includePrerelease}
40+
onCheckedChange={(v) => {
41+
setIncludePrerelease(!!v);
42+
}}
43+
/>
44+
<label>Include Prerelease</label>
45+
</div>
46+
</div>
2947

3048
<Table>
3149
<TableCaption>Runtime Version Ranges</TableCaption>
@@ -48,13 +66,26 @@ export default function Page({
4866
</Table>
4967

5068
<h2 className="text-xl font-bold">Plugins</h2>
51-
<ul>
52-
{compatRange.plugins.map((plugin) => (
53-
<li key={plugin.name}>
54-
<kbd>{plugin.name}</kbd>
55-
</li>
56-
))}
57-
</ul>
69+
70+
<Table>
71+
<TableCaption>Compatible Plugins</TableCaption>
72+
<TableHeader>
73+
<TableRow>
74+
<TableHead className="w-[200px]">Plugin</TableHead>
75+
<TableHead>Minimum Version</TableHead>
76+
<TableHead>Maximum Version</TableHead>
77+
</TableRow>
78+
</TableHeader>
79+
<TableBody>
80+
{compatRange.plugins.map((plugin) => (
81+
<TableRow key={plugin.name}>
82+
<TableCell className="font-medium">{plugin.name}</TableCell>
83+
<TableCell>{plugin.minVersion}</TableCell>
84+
<TableCell>{plugin.maxVersion}</TableCell>
85+
</TableRow>
86+
))}
87+
</TableBody>
88+
</Table>
5889
</div>
5990
);
6091
}

apps/swc-plugins/lib/api/compatRange/router.ts

+24-1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ export const compatRangeRouter = router({
2929
.input(
3030
z.object({
3131
id: z.bigint(),
32+
includePrerelease: z.boolean().default(false),
3233
})
3334
)
3435
.output(
@@ -40,7 +41,7 @@ export const compatRangeRouter = router({
4041
runtimes: z.array(VersionRangeSchema),
4142
})
4243
)
43-
.query(async ({ ctx, input: { id } }) => {
44+
.query(async ({ ctx, input: { id, includePrerelease } }) => {
4445
const range = await db.compatRange.findUnique({
4546
where: {
4647
id: id,
@@ -50,6 +51,17 @@ export const compatRangeRouter = router({
5051
from: true,
5152
to: true,
5253
plugins: {
54+
where: {
55+
...(includePrerelease
56+
? {}
57+
: {
58+
version: {
59+
not: {
60+
contains: "-",
61+
},
62+
},
63+
}),
64+
},
5365
select: {
5466
id: true,
5567
version: true,
@@ -61,6 +73,17 @@ export const compatRangeRouter = router({
6173
},
6274
},
6375
runtimes: {
76+
where: {
77+
...(includePrerelease
78+
? {}
79+
: {
80+
version: {
81+
not: {
82+
contains: "-",
83+
},
84+
},
85+
}),
86+
},
6487
select: {
6588
id: true,
6689
version: true,

apps/swc-plugins/lib/api/updater/router.ts

+76-68
Original file line numberDiff line numberDiff line change
@@ -45,47 +45,51 @@ export const updaterRouter = router({
4545
const api = await (await import("@/lib/api/server")).createCaller(ctx);
4646

4747
for (const pkg of input.pkgs) {
48-
const plugin = await db.swcPlugin.upsert({
49-
where: {
50-
name: pkg.name,
51-
},
52-
create: {
53-
name: pkg.name,
54-
},
55-
update: {},
56-
});
57-
58-
for (const version of pkg.versions) {
59-
const swcCoreVersion = version.swcCoreVersion;
60-
const compatRange = await api.compatRange.byCoreVersion({
61-
version: swcCoreVersion,
48+
try {
49+
const plugin = await db.swcPlugin.upsert({
50+
where: {
51+
name: pkg.name,
52+
},
53+
create: {
54+
name: pkg.name,
55+
},
56+
update: {},
6257
});
6358

64-
if (!compatRange) {
65-
throw new TRPCError({
66-
code: "NOT_FOUND",
67-
message: `Compat range not found for SWC core version ${swcCoreVersion}`,
59+
for (const version of pkg.versions) {
60+
const swcCoreVersion = version.swcCoreVersion;
61+
const compatRange = await api.compatRange.byCoreVersion({
62+
version: swcCoreVersion,
6863
});
69-
}
7064

71-
await db.swcPluginVersion.upsert({
72-
where: {
73-
pluginId_version: {
65+
if (!compatRange) {
66+
throw new TRPCError({
67+
code: "NOT_FOUND",
68+
message: `Compat range not found for SWC core version ${swcCoreVersion}`,
69+
});
70+
}
71+
72+
await db.swcPluginVersion.upsert({
73+
where: {
74+
pluginId_version: {
75+
pluginId: plugin.id,
76+
version: version.version,
77+
},
78+
},
79+
create: {
7480
pluginId: plugin.id,
7581
version: version.version,
82+
compatRangeId: compatRange.id,
83+
swcCoreVersion,
7684
},
77-
},
78-
create: {
79-
pluginId: plugin.id,
80-
version: version.version,
81-
compatRangeId: compatRange.id,
82-
swcCoreVersion,
83-
},
84-
update: {
85-
compatRangeId: compatRange.id,
86-
swcCoreVersion,
87-
},
88-
});
85+
update: {
86+
compatRangeId: compatRange.id,
87+
swcCoreVersion,
88+
},
89+
});
90+
}
91+
} catch (e) {
92+
console.error(`Error updating wasm plugins for ${pkg.name}`, e);
8993
}
9094
}
9195
}),
@@ -117,45 +121,49 @@ export const updaterRouter = router({
117121
}
118122

119123
for (const pkg of input.pkgs) {
120-
const runtime = await db.swcRuntime.upsert({
121-
where: {
122-
name: pkg.name,
123-
},
124-
create: {
125-
name: pkg.name,
126-
},
127-
update: {},
128-
});
129-
130-
for (const version of pkg.versions) {
131-
const swcCoreVersion = version.swcCoreVersion;
132-
const compatRange = byVersion(swcCoreVersion);
133-
134-
if (!compatRange) {
135-
throw new TRPCError({
136-
code: "NOT_FOUND",
137-
message: `Compat range not found for SWC core version ${swcCoreVersion}`,
138-
});
139-
}
140-
141-
await db.swcRuntimeVersion.upsert({
124+
try {
125+
const runtime = await db.swcRuntime.upsert({
142126
where: {
143-
runtimeId_version: {
144-
runtimeId: runtime.id,
145-
version: version.version,
146-
},
127+
name: pkg.name,
147128
},
148129
create: {
149-
runtimeId: runtime.id,
150-
version: version.version,
151-
compatRangeId: compatRange.id,
152-
swcCoreVersion,
153-
},
154-
update: {
155-
compatRangeId: compatRange.id,
156-
swcCoreVersion,
130+
name: pkg.name,
157131
},
132+
update: {},
158133
});
134+
135+
for (const version of pkg.versions) {
136+
const swcCoreVersion = version.swcCoreVersion;
137+
const compatRange = byVersion(swcCoreVersion);
138+
139+
if (!compatRange) {
140+
throw new TRPCError({
141+
code: "NOT_FOUND",
142+
message: `Compat range not found for SWC core version ${swcCoreVersion}`,
143+
});
144+
}
145+
146+
await db.swcRuntimeVersion.upsert({
147+
where: {
148+
runtimeId_version: {
149+
runtimeId: runtime.id,
150+
version: version.version,
151+
},
152+
},
153+
create: {
154+
runtimeId: runtime.id,
155+
version: version.version,
156+
compatRangeId: compatRange.id,
157+
swcCoreVersion,
158+
},
159+
update: {
160+
compatRangeId: compatRange.id,
161+
swcCoreVersion,
162+
},
163+
});
164+
}
165+
} catch (e) {
166+
console.error(`Error updating runtimes for ${pkg.name}`, e);
159167
}
160168
}
161169
}),

0 commit comments

Comments
 (0)