Skip to content

Instantly share code, notes, and snippets.

@pylixonly
Last active August 28, 2024 05:08
Show Gist options
  • Save pylixonly/bd2e46f85314e74074c71722af7baf0a to your computer and use it in GitHub Desktop.
Save pylixonly/bd2e46f85314e74074c71722af7baf0a to your computer and use it in GitHub Desktop.
Requesting a plugin proxy in bn-plugins

Requesting a Plugin Proxy in bn-plugins

To proxy a plugin, follow the same steps as with Vendetta:

1. Ensure the original source code is public/open-source with a suitable license.
2. Build your plugin and host it publicly, such as on GitHub Pages or your own domain.
3. Post your plugin URL in the #proxy-requests channel.
4. Staff will review and update the proxy.

To streamline the review process, developers must make the following changes before requesting a proxy. These modifications make it easier to review build artifacts. If you've customized your build scripts, you can skip any unnecessary steps.

Updating SWC configuration for accurate transformation

If you're using Vendetta's plugin template, note that the build file ./build.mjs (line 37-43) has incomplete SWC configuration. Replace the env section with the following to avoid unnecessary polyfills:

env: {
    targets: "fully supports es6",
    include: [
        "transform-block-scoping",
        "transform-classes",
        "transform-async-to-generator",
        "transform-async-generator-functions"
    ],
    exclude: [
        "transform-parameters",
        "transform-template-literals",
        "transform-exponentiation-operator",
        "transform-named-capturing-groups-regex",
        "transform-nullish-coalescing-operator",
        "transform-object-rest-spread",
        "transform-optional-chaining",
        "transform-logical-assignment-operators"
    ]
},

Serve your JS bundle unminified

Typically, your plugin's JS bundle is minified. While it's possible for proxy managers to review minified JS (yes, this is how it's been done), why would we reverse-engineer open-source code? To proxy plugins in bn-proxy, your JS bundle must be unminified.

Optionally, you can introduce a "min-main" field to specify your minified files for users who directly use your plugin from the source.

manifest.json:

{
  "name": "Template Plugin",
  // ...
  "main": "index.js", // main entry point
  "min-main": "index.min.js", // also the main point, but minified and takes priority
  // ...
  "hash": "6cb6594aa032b83a1f24c2bb3d63e8aeb8e1652e0361e7d7a0e415850cc9c406"
}

Reference: https://github.com/pyoncord/Bunny

After reviewing your JS bundle, we will minify it and overwrite the path specified in "min-main". If "min-main" is not specified, we will perform a manifest.main.replace(/(?:\.js)?$/, ".min.js")* and write the file there. The minification configuration will be shared later.
*This snippet replaces .js with .min.js. If the file name doesn't end with .js, .min.js will be appended.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment