PenguLoader / PenguLoader

✨ The ultimate JavaScript plugin loader, build your unmatched LoL Client.
https://pengu.lol
Do What The F*ck You Want To Public License
346 stars 56 forks source link

Feature: PluginFS API #71

Open BakaFT opened 9 months ago

BakaFT commented 9 months ago

Community devs often need to access the file system to complete certain operations, such as opening a folder for users to add or delete files, outputting logs to a file, and so on.

So a PluginFS API is needed, and it should be plugin scoped meaning that a plugin only have permission on it's own folder. In this case top-level js will not have any permission because it don't have its own folder.

Actually I've done some job on that using std::filesystem from C++17, so I think if is ok we can move to C++17 to gain more convenience and improved cross-platform compatibility.

BakaFT commented 8 months ago

We have added a sync-blocking PluginFS implementation in #75 API Docs: https://beta.pengu.lol/runtime-api/plugin-fs

nomi-san commented 6 months ago

There's a way to isolate the PluginFS for scoped plugin folder.

First remove the global PluginFS and turn it into a class.

class PluginFS {
  constructor(name) { }
  read(path) { /*do path check*/ }
  // ...
}

Pass an instance for each plugin init call.

function loadPlugin(name) {
  // ...
  ctx.fs = new PluginFS(name)
  // ...
} 
export function init(ctx) {
  ctx.read('some/path/to/file')
}

[!IMPORTANT] With top-level JS files (aka single file plugins), they should not access fs and skip this prop.