diff --git a/api/src/api.ts b/api/src/api.ts index a0efa8829a2..6a6efee7578 100644 --- a/api/src/api.ts +++ b/api/src/api.ts @@ -5,3 +5,8 @@ export interface Api { ...[endpoint, request]: RequestOf extends void ? [E] : [E, RequestOf] ): Promise>; } + +export type FrameworkPluginInfo = { + name: string; + apiVersion: number; +}; diff --git a/api/src/rpcs.ts b/api/src/rpcs.ts index 46905ddb05a..763a5f13a05 100644 --- a/api/src/rpcs.ts +++ b/api/src/rpcs.ts @@ -1,7 +1,17 @@ import type { SerializableValue } from "@previewjs/serializable-values"; import type { CollectedTypes, ValueType } from "@previewjs/type-analyzer"; +import type { FrameworkPluginInfo } from "./api.js"; import type { RPC } from "./rpc.js"; +export const GetInfo: RPC< + Record, + { + frameworkPlugin: FrameworkPluginInfo; + } +> = { + path: "info", +}; + export const Analyze: RPC< { previewableIds: string[]; diff --git a/core/src/index.ts b/core/src/index.ts index ad49c043ee8..5658b87b39e 100644 --- a/core/src/index.ts +++ b/core/src/index.ts @@ -171,6 +171,9 @@ export async function createWorkspace({ types, }; }); + router.registerRPC(RPCs.GetInfo, async () => ({ + frameworkPlugin: frameworkPluginFactory.info, + })); router.registerRPC(RPCs.CrawlFiles, (options) => crawlFiles(logger, workspace, frameworkPlugin, options) ); diff --git a/core/src/plugins/framework.ts b/core/src/plugins/framework.ts index ed05cf4bded..55b62db19e2 100644 --- a/core/src/plugins/framework.ts +++ b/core/src/plugins/framework.ts @@ -1,12 +1,12 @@ import type { Analyzer } from "@previewjs/analyzer-api"; +import type { FrameworkPluginInfo } from "@previewjs/api"; import type { Reader } from "@previewjs/vfs"; import type { Logger } from "pino"; import type * as vite from "vite"; import type { PackageDependencies } from "./dependencies.js"; export interface FrameworkPluginFactory { - /** This will always be set in current plugin versions. */ - info?: FrameworkPluginInfo; + info: FrameworkPluginInfo; isCompatible(dependencies: PackageDependencies): Promise; create(options: { rootDir: string; @@ -22,8 +22,3 @@ export interface FrameworkPlugin extends Analyzer { viteConfig: (configuredPlugins: vite.Plugin[]) => vite.UserConfig; dispose(): void; } - -type FrameworkPluginInfo = { - name: string; - apiVersion: number; -};