Skip to content

Commit

Permalink
feat(core): add GetInfo RPC endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
fwouts committed Dec 15, 2024
1 parent 3b8a9b6 commit 60ea49b
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 7 deletions.
5 changes: 5 additions & 0 deletions api/src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,8 @@ export interface Api {
...[endpoint, request]: RequestOf<E> extends void ? [E] : [E, RequestOf<E>]
): Promise<ResponseOf<E>>;
}

export type FrameworkPluginInfo = {
name: string;
apiVersion: number;
};
10 changes: 10 additions & 0 deletions api/src/rpcs.ts
Original file line number Diff line number Diff line change
@@ -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<string, never>,
{
frameworkPlugin: FrameworkPluginInfo;
}
> = {
path: "info",
};

export const Analyze: RPC<
{
previewableIds: string[];
Expand Down
3 changes: 3 additions & 0 deletions core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
);
Expand Down
9 changes: 2 additions & 7 deletions core/src/plugins/framework.ts
Original file line number Diff line number Diff line change
@@ -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<boolean>;
create(options: {
rootDir: string;
Expand All @@ -22,8 +22,3 @@ export interface FrameworkPlugin extends Analyzer {
viteConfig: (configuredPlugins: vite.Plugin[]) => vite.UserConfig;
dispose(): void;
}

type FrameworkPluginInfo = {
name: string;
apiVersion: number;
};

0 comments on commit 60ea49b

Please sign in to comment.