Plugin Development

Extend OptiPrune with framework-specific analysis

Plugin Architecture

OptiPrune uses a Plugin Adapter architecture. Plugins hook into the analysis lifecycle to recognize framework patterns that would otherwise be marked as unused.

import { AnalyzerPlugin } from "../types.js";
import * as t from "@babel/types";

export const MyFrameworkPlugin: AnalyzerPlugin = {
  name: "my-framework-plugin",
  version: "1.0.0",
  
  detect: async (adapter) => {
    const pkg = await adapter.readJson('package.json');
    return !!pkg?.dependencies?.['my-framework'];
  },
  
  lifecycle: {
    onFileStart: (fileId, adapter) => {
      if (fileId.endsWith('.vue')) {
        adapter.markAsUsed(fileId);
      }
    },
    onASTNode: (node, fileId, adapter) => {
      // Synchronous AST traversal
    }
  }
};

Submit Your Plugin

Built a plugin for a framework we don't support yet? We'd love to include it!

How to contribute:

  1. Fork the optiprune repository
  2. Create your plugin in src/plugins/
  3. Add tests in tests/plugins/
  4. Submit a Pull Request
Open GitHub Repo