The libWrapper library has official support for all types of packages, including systems.
However, it is recommended that you read through the warnings and recommendations in this section before you use it inside a system.
Most of the benefits provided by libWrapper are specific to modules. This is because systems should always load before any module, with the exception of modules with "library": true
in their manifest (although those should not introduce compatibility issues).
⚠ The above is only strictly true since Foundry 0.8.3. See this FoundryVTT issue for more information.
Given that systems go first, they are guaranteed to have first go at patching core methods as long as they do everything as soon as possible (i.e. immediately on system execution, on the init hook, etc). From the point-of-view of modules, whatever modifications the system did to the core Foundry code should be transparent, and not even libWrapper would know they have been modified.
In short, as long as you follow the following rules, libWrapper should be completely unnecessary:
async
before wrapping or patching core code, as they might allow modules to run before the rest of your code.There are some situations where libWrapper does introduce benefits, and its use should be considered:
OVERRIDE
wrappers.If your use-case falls under these (or you have another situation where libWrapper becomes necessary), it is not recommended to require libWrapper to be installed unless absolutely necessary. Instead, you should use the provided shim (or a custom compatibility layer), and recommend the use of libWrapper.
There are multiple reasons for this:
Foundry's dependency system is not perfect. It is possible to enable packages or systems without their listed dependencies being present.
While libWrapper is well-tested, as with any piece of software it might contain bugs. While we endeavour to fix bugs ASAP, this is a hobby project done in our spare time, and we make absolutely zero guarantees about the time scales for a fix.
A compatibility layer will allow you to triage issues with libWrapper both enabled and disabled.
If you do find a bug, you and you and your users do not need to wait for a fix.
If libWrapper breaks at any point (e.g. after a Foundry update), you and your users do not need to wait for a fix.
Many modules use libWrapper, and a common method of triaging module failures it to toggle libWrapper off. This is not possible if the system requires libWrapper to work.
There are some rare situations where the full functionality of the libWrapper library is necessary, and the shim (or a custom compatibility layer) is not an adequate replacement.
In such a case, making libWrapper a hard dependency might be your best choice. However, you should keep to the following rules:
Ensure your manifest lists lib-wrapper
as a dependency. Refer to the installation section of the README for further details.
It is possible that libWrapper might not be active (on purpose or by mistake) when your system loads. As such, you must ensure that:
The game still loads even without libWrapper enabled.
Loading without libWrapper enabled does not corrupt any world data.
The user is given a clear error message that they should enable libWrapper if it is disabled.
Important basic functionality should still work. A user should be able to at a minimum export their data (such as character sheets), if necessary.
Although libWrapper's API should be backwards-compatible, we make no guarantees this will always be the case.
You should very clearly document which versions of libWrapper you have tested with, so the user can downgrade libWrapper if necessary.
You should warn the user if the libWrapper version is older than the one you tested against, so they can upgrade if necessary.
If at all possible, use try/catch
statements when calling libWrapper.register
and handle failures gracefully, for instance by disabling specific functionality only.