feat(FN-3883): fix dependency-graph plugin exports and add CLI bundle entry
Fixed the `@fusion-plugin/dependency-graph` plugin's exports and build entry points so it bundles correctly with the CLI, added test coverage for plugin enable success and error-state toasts, and included the plugin's dist in the CLI bundle via tsup config. Fusion-Task-Id: FN-3883
This commit is contained in:
5
.changeset/FN-3883-fix-dependency-graph-enable.md
Normal file
5
.changeset/FN-3883-fix-dependency-graph-enable.md
Normal file
@@ -0,0 +1,5 @@
|
||||
---
|
||||
"@runfusion/fusion": patch
|
||||
---
|
||||
|
||||
Fix Dependency Graph plugin failing to enable from Settings by correcting package exports/build output and ensuring bundled CLI staging includes compiled plugin dist assets. Also surface the loader's actual enable error in Plugin Manager toast messaging when enable returns `state: "error"`.
|
||||
@@ -414,7 +414,13 @@ export function PluginManager({ addToast, projectId }: PluginManagerProps) {
|
||||
|
||||
const handleEnable = async (plugin: PluginInstallation) => {
|
||||
try {
|
||||
await enablePlugin(plugin.id, projectId);
|
||||
const enabledPlugin = await enablePlugin(plugin.id, projectId);
|
||||
if (enabledPlugin.state === "error") {
|
||||
addToast(`Failed to enable ${plugin.name}: ${enabledPlugin.error ?? "Unknown error"}`, "error");
|
||||
await loadPlugins();
|
||||
return;
|
||||
}
|
||||
|
||||
addToast(`${plugin.name} enabled for this project`, "success");
|
||||
await loadPlugins();
|
||||
} catch (err) {
|
||||
|
||||
@@ -517,7 +517,7 @@ describe("PluginManager", () => {
|
||||
|
||||
it("enables plugin when toggle is clicked", async () => {
|
||||
vi.mocked(fetchPlugins).mockResolvedValueOnce([{ ...mockPlugins[0], enabled: false }]);
|
||||
vi.mocked(enablePlugin).mockResolvedValueOnce({ ...mockPlugins[0], enabled: true });
|
||||
vi.mocked(enablePlugin).mockResolvedValueOnce({ ...mockPlugins[0], enabled: true, state: "started" });
|
||||
|
||||
render(<PluginManager addToast={addToast} />);
|
||||
|
||||
@@ -534,6 +534,53 @@ describe("PluginManager", () => {
|
||||
await waitFor(() => {
|
||||
expect(enablePlugin).toHaveBeenCalledWith("plugin-a", undefined);
|
||||
});
|
||||
|
||||
expect(addToast).toHaveBeenCalledWith("Test Plugin A enabled for this project", "success");
|
||||
expect(addToast).not.toHaveBeenCalledWith(expect.stringContaining("Failed to enable"), "error");
|
||||
});
|
||||
|
||||
it("shows loader error toast when enable returns error state", async () => {
|
||||
vi.mocked(fetchPlugins).mockResolvedValueOnce([{ ...mockPlugins[0], enabled: false }]);
|
||||
vi.mocked(enablePlugin).mockResolvedValueOnce({
|
||||
...mockPlugins[0],
|
||||
enabled: true,
|
||||
state: "error",
|
||||
error: "Cannot find module dependency-graph",
|
||||
});
|
||||
|
||||
render(<PluginManager addToast={addToast} />);
|
||||
|
||||
await waitFor(() => {
|
||||
expect(screen.getByText("Test Plugin A")).toBeTruthy();
|
||||
});
|
||||
|
||||
await userEvent.click(screen.getByRole("checkbox"));
|
||||
|
||||
await waitFor(() => {
|
||||
expect(addToast).toHaveBeenCalledWith(
|
||||
expect.stringContaining("Cannot find module dependency-graph"),
|
||||
"error",
|
||||
);
|
||||
});
|
||||
|
||||
expect(addToast).not.toHaveBeenCalledWith("Test Plugin A enabled for this project", "success");
|
||||
});
|
||||
|
||||
it("shows transport error toast when enable request rejects", async () => {
|
||||
vi.mocked(fetchPlugins).mockResolvedValueOnce([{ ...mockPlugins[0], enabled: false }]);
|
||||
vi.mocked(enablePlugin).mockRejectedValueOnce(new Error("network"));
|
||||
|
||||
render(<PluginManager addToast={addToast} />);
|
||||
|
||||
await waitFor(() => {
|
||||
expect(screen.getByText("Test Plugin A")).toBeTruthy();
|
||||
});
|
||||
|
||||
await userEvent.click(screen.getByRole("checkbox"));
|
||||
|
||||
await waitFor(() => {
|
||||
expect(addToast).toHaveBeenCalledWith("Failed to enable plugin: network", "error");
|
||||
});
|
||||
});
|
||||
|
||||
it("disables plugin when toggle is clicked", async () => {
|
||||
|
||||
@@ -6,16 +6,16 @@
|
||||
"private": true,
|
||||
"exports": {
|
||||
".": {
|
||||
"types": "./src/index.ts",
|
||||
"import": "./src/index.ts"
|
||||
"types": "./dist/index.d.ts",
|
||||
"import": "./dist/index.js"
|
||||
},
|
||||
"./dashboard-view": {
|
||||
"types": "./src/dashboard-view.tsx",
|
||||
"import": "./src/dashboard-view.tsx"
|
||||
"types": "./dist/dashboard-view.d.ts",
|
||||
"import": "./dist/dashboard-view.js"
|
||||
}
|
||||
},
|
||||
"scripts": {
|
||||
"build": "tsc",
|
||||
"build": "tsc && cp src/*.css dist/ && mkdir -p dist/styles && cp src/styles/*.css dist/styles/",
|
||||
"test": "vitest run --silent=passed-only --reporter=dot"
|
||||
},
|
||||
"dependencies": {
|
||||
|
||||
@@ -2,7 +2,6 @@ import { mkdtempSync } from "node:fs";
|
||||
import { rm } from "node:fs/promises";
|
||||
import { tmpdir } from "node:os";
|
||||
import { dirname, join } from "node:path";
|
||||
import { pathToFileURL } from "node:url";
|
||||
import { PluginLoader, PluginStore } from "@fusion/core";
|
||||
import { afterEach, describe, expect, it } from "vitest";
|
||||
import plugin from "../index";
|
||||
@@ -25,10 +24,15 @@ describe("dependency graph plugin index", () => {
|
||||
);
|
||||
});
|
||||
|
||||
it("loads src/index.ts via Node dynamic import", async () => {
|
||||
const moduleUrl = pathToFileURL(join(process.cwd(), "src/index.ts")).href;
|
||||
const module = await import(moduleUrl);
|
||||
expect(module.default?.manifest?.id).toBe("fusion-plugin-dependency-graph");
|
||||
it("is loadable through package exports", async () => {
|
||||
const entryModule = await import("@fusion-plugin-examples/dependency-graph");
|
||||
expect(entryModule.default?.manifest?.id).toBe("fusion-plugin-dependency-graph");
|
||||
expect(entryModule.default?.dashboardViews?.[0]).toEqual(
|
||||
expect.objectContaining({ componentPath: "./dashboard-view" }),
|
||||
);
|
||||
|
||||
const viewModule = await import("@fusion-plugin-examples/dependency-graph/dashboard-view");
|
||||
expect(typeof viewModule.default).toBe("function");
|
||||
});
|
||||
|
||||
it("is loadable by PluginLoader without throwing", async () => {
|
||||
@@ -38,7 +42,7 @@ describe("dependency graph plugin index", () => {
|
||||
const pluginStore = new PluginStore(rootDir, { inMemoryDb: true, centralGlobalDir: rootDir });
|
||||
await pluginStore.init();
|
||||
|
||||
const pluginPath = join(process.cwd(), "src/index.ts");
|
||||
const pluginPath = join(process.cwd(), "dist/index.js");
|
||||
await pluginStore.registerPlugin({ manifest: plugin.manifest, path: pluginPath });
|
||||
|
||||
const loader = new PluginLoader({
|
||||
|
||||
@@ -4,6 +4,17 @@ declare module "@fusion/dashboard/app/utils/taskStuck" {
|
||||
export function isTaskStuck(task: Task, taskStuckTimeoutMs?: number, lastFetchTimeMs?: number): boolean;
|
||||
}
|
||||
|
||||
declare module "@fusion/dashboard/app/plugins/types" {
|
||||
import type { Task, TaskDetail, WorkflowStep } from "@fusion/core";
|
||||
|
||||
export interface PluginDashboardViewContext {
|
||||
tasks: Task[];
|
||||
projectId?: string;
|
||||
workflowSteps?: WorkflowStep[];
|
||||
openTaskDetail?: (task: Task | TaskDetail) => void;
|
||||
}
|
||||
}
|
||||
|
||||
declare module "@fusion/dashboard/app/components/TaskCard" {
|
||||
import type { Column, Task, TaskDetail } from "@fusion/core";
|
||||
import type { ReactElement } from "react";
|
||||
|
||||
@@ -16,4 +16,6 @@ export function DependencyGraphDashboardView({ context }: { context?: PluginDash
|
||||
});
|
||||
}
|
||||
|
||||
export default DependencyGraphDashboardView;
|
||||
|
||||
export { DependencyGraph };
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
"extends": "../tsconfig.base.json",
|
||||
"compilerOptions": {
|
||||
"outDir": "dist",
|
||||
"rootDir": "../..",
|
||||
"rootDir": "./src",
|
||||
"jsx": "react-jsx",
|
||||
"module": "esnext",
|
||||
"moduleResolution": "bundler",
|
||||
@@ -10,7 +10,7 @@
|
||||
"paths": {
|
||||
"@fusion/dashboard/app/components/TaskCard": ["./src/dashboard-interop.d.ts"],
|
||||
"@fusion/dashboard/app/utils/taskStuck": ["./src/dashboard-interop.d.ts"],
|
||||
"@fusion/dashboard/app/plugins/types": ["../../packages/dashboard/app/plugins/types.ts"]
|
||||
"@fusion/dashboard/app/plugins/types": ["./src/dashboard-interop.d.ts"]
|
||||
}
|
||||
},
|
||||
"include": ["src/**/*.ts", "src/**/*.tsx", "src/**/*.d.ts"],
|
||||
|
||||
@@ -6,12 +6,26 @@ const maxWorkers = computeMaxWorkers();
|
||||
|
||||
export default defineConfig({
|
||||
resolve: {
|
||||
alias: {
|
||||
"@fusion/core": fileURLToPath(new URL("../../packages/core/src/index.ts", import.meta.url)),
|
||||
"@fusion/plugin-sdk": fileURLToPath(new URL("../../packages/plugin-sdk/src/index.ts", import.meta.url)),
|
||||
"@fusion/dashboard": fileURLToPath(new URL("../../packages/dashboard", import.meta.url)),
|
||||
"lucide-react": fileURLToPath(new URL("../../packages/dashboard/node_modules/lucide-react", import.meta.url)),
|
||||
},
|
||||
alias: [
|
||||
{
|
||||
find: /^@fusion-plugin-examples\/dependency-graph\/dashboard-view$/,
|
||||
replacement: fileURLToPath(new URL("./src/dashboard-view.tsx", import.meta.url)),
|
||||
},
|
||||
{
|
||||
find: /^@fusion-plugin-examples\/dependency-graph$/,
|
||||
replacement: fileURLToPath(new URL("./src/index.ts", import.meta.url)),
|
||||
},
|
||||
{ find: "@fusion/core", replacement: fileURLToPath(new URL("../../packages/core/src/index.ts", import.meta.url)) },
|
||||
{
|
||||
find: "@fusion/plugin-sdk",
|
||||
replacement: fileURLToPath(new URL("../../packages/plugin-sdk/src/index.ts", import.meta.url)),
|
||||
},
|
||||
{ find: "@fusion/dashboard", replacement: fileURLToPath(new URL("../../packages/dashboard", import.meta.url)) },
|
||||
{
|
||||
find: "lucide-react",
|
||||
replacement: fileURLToPath(new URL("../../packages/dashboard/node_modules/lucide-react", import.meta.url)),
|
||||
},
|
||||
],
|
||||
},
|
||||
test: {
|
||||
include: ["src/**/*.test.{ts,tsx}"],
|
||||
|
||||
Reference in New Issue
Block a user