diff --git a/swc-plugins/app/api/versions/from-plugin-runner/[version]/page.tsx b/swc-plugins/app/api/versions/from-plugin-runner/[version]/page.tsx new file mode 100644 index 0000000..5a82260 --- /dev/null +++ b/swc-plugins/app/api/versions/from-plugin-runner/[version]/page.tsx @@ -0,0 +1,12 @@ +export default async function Page({ + params: { version }, +}: { + params: { version: string }; +}) { + // TODO: Reverse mapping from plugin runner version to swc version + return ( +
+

swc_plugin_runner: {version}

+
+ ); +} diff --git a/swc-plugins/app/import/ranges/page.tsx b/swc-plugins/app/import/ranges/page.tsx index 05d61b3..ef1909b 100644 --- a/swc-plugins/app/import/ranges/page.tsx +++ b/swc-plugins/app/import/ranges/page.tsx @@ -26,7 +26,7 @@ export default async function Page() { }); } - const runtimes = ["@swc/core", "next", "rspack"]; + const runtimes = ["@swc/core", "next", "rspack", "farm"]; for (const runtime of runtimes) { await db.swcRuntime.upsert({ diff --git a/swc-plugins/app/import/runtime/route.ts b/swc-plugins/app/import/runtime/route.ts index 74172a9..d5e30d8 100644 --- a/swc-plugins/app/import/runtime/route.ts +++ b/swc-plugins/app/import/runtime/route.ts @@ -34,13 +34,6 @@ export async function POST(req: NextRequest) { }); const api = await createCaller(); - const items: { - runtimeId: bigint; - version: string; - compatRangeId: bigint; - swcCoreVersion: string; - }[] = []; - for (const version of versions) { const compatRange = await api.compatRange.byVersion({ version: version.swcCoreVersion, @@ -50,20 +43,33 @@ export async function POST(req: NextRequest) { continue; } - items.push({ - runtimeId: rt.id, - // Just to ensure it's a valid semver - version: version.version.replace("v", ""), - compatRangeId: compatRange.id, - // Just to ensure it's a valid semver - swcCoreVersion: version.swcCoreVersion.replace("v", ""), - }); + try { + await db.swcRuntimeVersion.upsert({ + where: { + runtimeId_version: { + runtimeId: rt.id, + version: version.version.replace("v", ""), + }, + }, + update: { + compatRangeId: compatRange.id, + swcCoreVersion: version.swcCoreVersion.replace("v", ""), + }, + create: { + runtimeId: rt.id, + version: version.version.replace("v", ""), + compatRangeId: compatRange.id, + swcCoreVersion: version.swcCoreVersion.replace("v", ""), + }, + }); + } catch (e) { + console.error( + `Failed to create compat range for ${version.swcCoreVersion}: ${e}` + ); + continue; + } } - await db.swcRuntimeVersion.createMany({ - data: items, - }); - return NextResponse.json({ ok: true, }); diff --git a/swc-plugins/lib/api/compatRange/router.ts b/swc-plugins/lib/api/compatRange/router.ts index 1b110e2..94f186a 100644 --- a/swc-plugins/lib/api/compatRange/router.ts +++ b/swc-plugins/lib/api/compatRange/router.ts @@ -122,7 +122,10 @@ export const compatRangeRouter = router({ }); for (const range of versions) { - if (semver.gt(version, range.from) && semver.lt(version, range.to)) { + if ( + semver.gt(version, range.from) && + (range.to === "*" || semver.lt(version, range.to)) + ) { return range; } } diff --git a/swc-plugins/prisma/schema.prisma b/swc-plugins/prisma/schema.prisma index 13f46d8..97efebf 100644 --- a/swc-plugins/prisma/schema.prisma +++ b/swc-plugins/prisma/schema.prisma @@ -155,16 +155,18 @@ model SwcRuntime { } model SwcRuntimeVersion { - id BigInt @id @default(autoincrement()) - runtime SwcRuntime @relation(fields: [runtimeId], references: [id], onDelete: Cascade) - runtimeId BigInt - version String - /// The version of `swc_core` used by the plugin. - swcCoreVersion String - compatRange CompatRange @relation(fields: [compatRangeId], references: [id]) - compatRangeId BigInt - createdAt DateTime @default(now()) - updatedAt DateTime @updatedAt + id BigInt @id @default(autoincrement()) + runtime SwcRuntime @relation(fields: [runtimeId], references: [id], onDelete: Cascade) + runtimeId BigInt + version String + /// The version of `swc_core` used by the runtime. + swcCoreVersion String + /// The version of `swc_plugin_runner` used by the runtime. + swcPluginRunnerVersion String? + compatRange CompatRange @relation(fields: [compatRangeId], references: [id]) + compatRangeId BigInt + createdAt DateTime @default(now()) + updatedAt DateTime @updatedAt @@unique([runtimeId, version]) } diff --git a/swc-plugins/scripts/import-runtime.mjs b/swc-plugins/scripts/import-runtime.mjs index 64f8963..fe106d6 100755 --- a/swc-plugins/scripts/import-runtime.mjs +++ b/swc-plugins/scripts/import-runtime.mjs @@ -27,7 +27,7 @@ console.log("Cargo.lock path:", cargoLockPath); console.log("Relative path to Cargo.lock:", relativePathToCargoLock); // Get all git tags -const gitTags = (await $$`git tag`.text()).split("\n"); +const gitTags = (await $$`git tag`.text()).trim().split("\n").reverse(); const data = { runtime: runtimeName, @@ -62,7 +62,7 @@ for (const tag of gitTags) { } // Send the data to the server - if (data.versions.length >= 20) { + if (data.versions.length >= 10) { await fetch("http://localhost:50000/import/runtime", { method: "POST", headers: {