npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@ruxuwu/jin

v0.1.7

Published

A description of your package

Downloads

239

Readme

Jin 插件系统

一个轻量级、灵活的 JavaScript/TypeScript 插件系统,基于 Vue 3 构建,支持动态加载和管理插件。

特性

  • 🔌 插件生命周期管理
  • 🚀 异步插件加载
  • 🛠 TypeScript 支持
  • 📦 支持 ESM 和 IIFE 格式
  • 🔄 插件依赖管理
  • 🎯 事件驱动的激活机制

安装

npm install @ruxuwu/jin

# 或使用 yarn
yarn add @ruxuwu/jin

# 或使用 pnpm
pnpm add @ruxuwu/jin

使用方法

基础使用

import { SimplePluginManager, PluginManifest } from "@ruxuwu/jin";
// 创建插件管理器
const pluginManager = new SimplePluginManager();
// 创建插件清单
const manifest: PluginManifest = {
    id: "my-plugin",
    name: "My Plugin",
    version: "1.0.0",
    url: "https://example.com/my-plugin.js",
};

// 注册插件
await pluginManager.registerPlugin(manifest);

// 或者使用工厂函数注册插件
await pluginManager.registerPlugin({
    id: "local-plugin",
    name: "Local Plugin",
    version: "1.0.0"
}, async () => {
  // 返回插件实例
  return {
    activate(context) {
        // 插件激活时的逻辑
        console.log("Plugin activated!");
        // 注册需要在插件停用时释放的资源
        context.subscriptions.push({
            dispose: () => console.log("Resource disposed!")
        });
    },
    deactivate() {
        // 插件停用时的逻辑
        console.log("Plugin deactivated!");
    },
  };
});
// 设置共享的插件上下文
pluginManager.setPluginContext({
    api: {
        doSomething: () => console.log("Doing something...")
    }
});

// 激活插件
await pluginManager.activatePlugin("my-plugin");
await pluginManager.activatePlugin("local-plugin");
// 停用插件
await pluginManager.deactivatePlugin("my-plugin");
<script src="https://example.com/my-plugin.js"></script>
<script>
    // Jin 会在全局创建 ruxuwu 对象
    const { pluginManager } = window.ruxuwu;
    // 注册插件
    window.ruxuwu.plugins.push({
        id: "my-browser-plugin",
        name: "My Browser Plugin",
        version: "1.0.0",
        url: "https://example.com/my-plugin.js"
    });
    // 激活插件
    pluginManager.activatePlugin("my-browser-plugin");
</script>

插件开发指南

插件结构

一个标准的 Jin 插件需要实现 JinPlugin 接口:

interface JinPlugin {
  activate(context: PluginContext): void | Promise<void>;
  deactivate?(): void | Promise<void>;
}

插件上下文

插件上下文提供了与系统交互的能力:

interface PluginContext {
    // 插件订阅的资源列表,这些资源将在插件停用时自动释放
    subscriptions: Disposable[];
    // 允许添加其他上下文属性
    [key: string]: any;
}

// 可释放资源接口
interface Disposable {
    dispose(): void;
}

插件清单

每个插件都需要一个清单文件来描述其基本信息:

interface PluginManifest {
    // 插件唯一标识
    id: string;
    // 插件名称
    name: string;
    // 插件版本
    version: string;
    // 插件加载地址
    url: string;
    // 插件依赖项
    dependencies?: Record<string, string>;
    // 激活事件
    activationEvents?: string[];
}

构建和测试

# 安装依赖
pnpm install

# 构建
pnpm build

# 运行测试
pnpm test

许可证

MIT