Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@weedzcokie/plugin-loader

Package Overview
Dependencies
Maintainers
1
Versions
35
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@weedzcokie/plugin-loader

[![npm](https://img.shields.io/npm/v/@weedzcokie/plugin-loader?style=flat-square)](https://www.npmjs.com/package/@weedzcokie/plugin-loader)

  • 3.0.17
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
decreased by-100%
Maintainers
1
Weekly downloads
 
Created
Source

plugin-loader

npm

Usage

Define a base class and api for plugins:

// Plugin.ts
import { PluginBase } from "@weedzcokie/plugin-loader";

// this could be anything.
export type PluginApi = {
    x: number
    y: number
}

export default abstract class Plugin extends PluginBase<PluginApi> {
    x: number;
    y: number;
    
    init?(): void;

    constructor(api: PluginApi) {
        super(api);
        // `api` is also available from `this.api`.
        this.x = api.x;
        this.y = api.y;
    }
}

Plugin manifest (plugin.json)

{
    "name": "test-plugin",
    "version": "1.0.0"
}

version must be a semver compatible version string.

And with dependencies, similar to how package.json defines dependencies:

{
    "name": "plugin-2",
    "version": "1.0.0",
    "dependencies": {
        "test-plugin": "^1.0.0"
    }
}

Load plugins:

Assuming the following directory tree:

├─ plugins
│  ├─ test-plugin
│  │  ├── index.ts
│  │  └── plugin.json
│  └─ plugin-2
│     ├── index.ts
│     └── plugin.json
├─ index.ts
└─ Plugin.ts
// index.ts
import Loader, { NodeHandler } from "@weedzcokie/plugin-loader";
import Plugin, { PluginApi } from "./Plugin.ts":

const plugins = await Loader<Plugin, PluginApi>(["test-plugin"], {
    api: {
        x: 1,
        y: 2,
    },

    // Path to where plugins are located
    path: path.resolve('./plugins'),
    log: (msg: string) => console.log('[PluginLoader]', msg),
    handlers: {
        default: NodeHandler
    }
});

FAQs

Package last updated on 15 May 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc