8000 idea: add `plugins/` folder for file-based plugin registration · Issue #1828 · denoland/fresh · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

idea: add plugins/ folder for file-based plugin registration #1828

Closed
miguelrk opened this issue Sep 28, 2023 · 1 comment
Closed

idea: add plugins/ folder for file-based plugin registration #1828

miguelrk opened this issue Sep 28, 2023 · 1 comment

Comments

@miguelrk
Copy link
miguelrk commented Sep 28, 2023

Fresh currently supports file-based routing, and in a more general sense, has the following "spec 9865 ial" folders:

  • components/
  • islands/
  • routes/

Continuing with this pattern, aren't we missing a plugins/ folder, which could allow dynamic mounting/registration of plugins?

  • plugins/
    • some-custom-plugin.ts - e.g. adds some middleware to /
    • plugins/another-custom-plugin.ts - e.g. adds error pages /_404 and /_500

Proposal

Then plugins e.g. plugins/some-custom-plugin.ts could be defined as follows:

import { definePlugin } from "$fresh/server.ts";

export default definePlugin({
  name: "some-custom-plugin",
});

Or directly with a default exported Plugin object:

import { Plugin } from "$fresh/server.ts";

export default {
  name: "some-custom-plugin",
} satisfies Plugin;

and fresh would simply pick them up and auto-register them. However, thinking about it, this makes it difficult to specify registration order, which is already very possible by simply passing it to the "plugins" array of the start function.

I'm usually not into "magic" and doing too much behind the curtains (I prefer explicit code), but we are already doing file-based routing, so it seems only natural to allow this for plugins as well.

Disclaimer

Needless to say, this is just an idea as to "complete" the (1) file-based functionality of fresh, not to discourage the (2) more minimalistic, config-based approach of #1487 and #1602, which I believe we need to support as well. That being said, if this idea slows down (2), or adds too much complexity, I would discourage pursuing it.

@marvinhagemeister
Copy link
Collaborator

Babel tried this approach, but quickly moved away from that in favor of explicitly declaring which plugins to load. Doing auto-loading magically behind the scenes seems nice at first, but gets super nasty when you have plugins that depend on each other and expect one of them to be loaded first. With auto-loading the order is what every Fresh decides on (likely the way it's layd out in the file system), which isn't obvious and can lead to difficult to debug bugs.

I'm worried about the amount of magic causing more harm than good and causing more maintenance overhead. For routes this isn't as much of an issue because for 98% of routes (yes there are very few exceptions), they can be scored and sorted by specificity. This is something we can't do with plugins. Therefore auto-loading is something we won't add to Fresh.

Closing this issue as it caused confusion for users who stumbled on this and assumed Fresh doesn't support third party plugins in discord. This issue is merely about auto-loading plugins.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants
0