Skip to content

Commit

Permalink
feat(swc-plugins): Improve UI (#58)
Browse files Browse the repository at this point in the history
Closes #49
Closes #48
  • Loading branch information
kdy1 authored Aug 27, 2024
1 parent 07798b5 commit 942fcba
Show file tree
Hide file tree
Showing 3 changed files with 142 additions and 80 deletions.
53 changes: 42 additions & 11 deletions apps/swc-plugins/app/versions/range/[compatRangeId]/page.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"use client";

import { Checkbox } from "@/components/ui/checkbox";
import {
Table,
TableBody,
Expand All @@ -10,22 +11,39 @@ import {
TableRow,
} from "@/components/ui/table";
import { apiClient } from "@/lib/trpc/web-client";
import { useState } from "react";

export default function Page({
params: { compatRangeId },
}: {
params: { compatRangeId: string };
}) {
const [includePrerelease, setIncludePrerelease] = useState(false);
const [compatRange] = apiClient.compatRange.get.useSuspenseQuery({
id: BigInt(compatRangeId),
includePrerelease,
});

return (
<div>
<h1 className="text-2xl font-bold">
<kbd>swc_core</kbd>@<kbd>{compatRange.from}</kbd> -{" "}
<kbd>{compatRange.to}</kbd>
</h1>
<div className="flex flex-row justify-between">
<h1 className="mr-10 flex flex-col text-2xl font-bold">
<kbd>swc_core</kbd>
<span className="text-sm">
@<kbd>{compatRange.from}</kbd> - <kbd>{compatRange.to}</kbd>
</span>
</h1>

<div>
<Checkbox
checked={includePrerelease}
onCheckedChange={(v) => {
setIncludePrerelease(!!v);
}}
/>
<label>Include Prerelease</label>
</div>
</div>

<Table>
<TableCaption>Runtime Version Ranges</TableCaption>
Expand All @@ -48,13 +66,26 @@ export default function Page({
</Table>

<h2 className="text-xl font-bold">Plugins</h2>
<ul>
{compatRange.plugins.map((plugin) => (
<li key={plugin.name}>
<kbd>{plugin.name}</kbd>
</li>
))}
</ul>

<Table>
<TableCaption>Compatible Plugins</TableCaption>
<TableHeader>
<TableRow>
<TableHead className="w-[200px]">Plugin</TableHead>
<TableHead>Minimum Version</TableHead>
<TableHead>Maximum Version</TableHead>
</TableRow>
</TableHeader>
<TableBody>
{compatRange.plugins.map((plugin) => (
<TableRow key={plugin.name}>
<TableCell className="font-medium">{plugin.name}</TableCell>
<TableCell>{plugin.minVersion}</TableCell>
<TableCell>{plugin.maxVersion}</TableCell>
</TableRow>
))}
</TableBody>
</Table>
</div>
);
}
Expand Down
25 changes: 24 additions & 1 deletion apps/swc-plugins/lib/api/compatRange/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export const compatRangeRouter = router({
.input(
z.object({
id: z.bigint(),
includePrerelease: z.boolean().default(false),
})
)
.output(
Expand All @@ -40,7 +41,7 @@ export const compatRangeRouter = router({
runtimes: z.array(VersionRangeSchema),
})
)
.query(async ({ ctx, input: { id } }) => {
.query(async ({ ctx, input: { id, includePrerelease } }) => {
const range = await db.compatRange.findUnique({
where: {
id: id,
Expand All @@ -50,6 +51,17 @@ export const compatRangeRouter = router({
from: true,
to: true,
plugins: {
where: {
...(includePrerelease
? {}
: {
version: {
not: {
contains: "-",
},
},
}),
},
select: {
id: true,
version: true,
Expand All @@ -61,6 +73,17 @@ export const compatRangeRouter = router({
},
},
runtimes: {
where: {
...(includePrerelease
? {}
: {
version: {
not: {
contains: "-",
},
},
}),
},
select: {
id: true,
version: true,
Expand Down
144 changes: 76 additions & 68 deletions apps/swc-plugins/lib/api/updater/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,47 +45,51 @@ export const updaterRouter = router({
const api = await (await import("@/lib/api/server")).createCaller(ctx);

for (const pkg of input.pkgs) {
const plugin = await db.swcPlugin.upsert({
where: {
name: pkg.name,
},
create: {
name: pkg.name,
},
update: {},
});

for (const version of pkg.versions) {
const swcCoreVersion = version.swcCoreVersion;
const compatRange = await api.compatRange.byCoreVersion({
version: swcCoreVersion,
try {
const plugin = await db.swcPlugin.upsert({
where: {
name: pkg.name,
},
create: {
name: pkg.name,
},
update: {},
});

if (!compatRange) {
throw new TRPCError({
code: "NOT_FOUND",
message: `Compat range not found for SWC core version ${swcCoreVersion}`,
for (const version of pkg.versions) {
const swcCoreVersion = version.swcCoreVersion;
const compatRange = await api.compatRange.byCoreVersion({
version: swcCoreVersion,
});
}

await db.swcPluginVersion.upsert({
where: {
pluginId_version: {
if (!compatRange) {
throw new TRPCError({
code: "NOT_FOUND",
message: `Compat range not found for SWC core version ${swcCoreVersion}`,
});
}

await db.swcPluginVersion.upsert({
where: {
pluginId_version: {
pluginId: plugin.id,
version: version.version,
},
},
create: {
pluginId: plugin.id,
version: version.version,
compatRangeId: compatRange.id,
swcCoreVersion,
},
},
create: {
pluginId: plugin.id,
version: version.version,
compatRangeId: compatRange.id,
swcCoreVersion,
},
update: {
compatRangeId: compatRange.id,
swcCoreVersion,
},
});
update: {
compatRangeId: compatRange.id,
swcCoreVersion,
},
});
}
} catch (e) {
console.error(`Error updating wasm plugins for ${pkg.name}`, e);
}
}
}),
Expand Down Expand Up @@ -117,45 +121,49 @@ export const updaterRouter = router({
}

for (const pkg of input.pkgs) {
const runtime = await db.swcRuntime.upsert({
where: {
name: pkg.name,
},
create: {
name: pkg.name,
},
update: {},
});

for (const version of pkg.versions) {
const swcCoreVersion = version.swcCoreVersion;
const compatRange = byVersion(swcCoreVersion);

if (!compatRange) {
throw new TRPCError({
code: "NOT_FOUND",
message: `Compat range not found for SWC core version ${swcCoreVersion}`,
});
}

await db.swcRuntimeVersion.upsert({
try {
const runtime = await db.swcRuntime.upsert({
where: {
runtimeId_version: {
runtimeId: runtime.id,
version: version.version,
},
name: pkg.name,
},
create: {
runtimeId: runtime.id,
version: version.version,
compatRangeId: compatRange.id,
swcCoreVersion,
},
update: {
compatRangeId: compatRange.id,
swcCoreVersion,
name: pkg.name,
},
update: {},
});

for (const version of pkg.versions) {
const swcCoreVersion = version.swcCoreVersion;
const compatRange = byVersion(swcCoreVersion);

if (!compatRange) {
throw new TRPCError({
code: "NOT_FOUND",
message: `Compat range not found for SWC core version ${swcCoreVersion}`,
});
}

await db.swcRuntimeVersion.upsert({
where: {
runtimeId_version: {
runtimeId: runtime.id,
version: version.version,
},
},
create: {
runtimeId: runtime.id,
version: version.version,
compatRangeId: compatRange.id,
swcCoreVersion,
},
update: {
compatRangeId: compatRange.id,
swcCoreVersion,
},
});
}
} catch (e) {
console.error(`Error updating runtimes for ${pkg.name}`, e);
}
}
}),
Expand Down

0 comments on commit 942fcba

Please sign in to comment.