Add VendorModuleService for Composer-based Webtrees modules#5227
Add VendorModuleService for Composer-based Webtrees modules#5227magicsunday wants to merge 1 commit into
Conversation
|
Together with Webtrees 2.2.4 or dev-main, this can currently be tested using the magicsunday/webtrees-fan-chart package, for example. To do this, the WIP branch must be checked out.
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #5227 +/- ##
============================================
- Coverage 35.49% 35.45% -0.04%
- Complexity 11212 11229 +17
============================================
Files 1166 1167 +1
Lines 48081 48139 +58
============================================
+ Hits 17064 17067 +3
- Misses 31017 31072 +55 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
I develop modules purely for my own use. I have no need or interest in using composer. I know there are many others doing the same. For us modules_v4 is simple and works well. So how does this proposal affect us? There is no mention of users like us in this. |
|
Thanks for raising this — it’s an important point. To be clear: this proposal does not remove or break the existing What this PR does is add an additional option for distributing and installing modules via Composer, using the new
So to summarize:
The goal here is to expand possibilities without taking anything away. |
|
Hi @fisharebest, I hope you're well. I'd appreciate it if you'd take a look at this PR. If you find any issues, I'm happy to adjust or improve it. Thank you for your time and feedback! |
|
Nice work! |
|
Thanks for the kind feedback! Let me clarify: What steps are needed to publish a module?
That’s it — Composer takes care of the rest (autoloading, versioning, installation path, etc.). Does this add more dependencies for webtrees?
So in short:
|
|
As I understand it, this approach will complicate things tremendously for site admins that 'simply' want to install or try out a vendor module. Currently all that's needed is unzip the module source code into a subdirectory of With this mechanism they need to clone the webtrees git repo, edit some file, have a local PHP development environment in order to execute Thus the requirements for using such modules are raised significantly. Or am I missing something? |
|
Hi @BertKoor |
|
Thanks for pointing that out, @kiwi3685 . I thought I had read the complete discussion, but apparently I had misunderstood some nuances. You addressed concerns from the point of view of a module developer. It was mentioned that this "does not remove or break the existing Now should I understand that "composer"-ised modules can be installed the old way as well? In my experience more options leads to confusion, especially on unknown territory. And I hope that n>1 for this feature, but I have my doubts. |
@fisharebest |
|
Instead of modifying webtrees to search for modules in a new location ( From reading the composer documentation, I think that the following steps are required
{
"extra": {
"installer-paths": {
"modules_v4": ["type:webtrees-module"]
}
}
}If you want to script this, you can use this command line to make the edit. jq '.extra["installer-paths"]["modules_v4"] = ["type:webtrees-module"]' composer.json > tmp && mv tmp composer.json
On the webtrees system, you should be able to run Does this work? |
|
/edit The installation path might need to be |
|
I was wondering if |
|
I have created a minimal webtrees module installer. It's just a few lines of code. I see that @magicsunday has created a much more comprehensive installer. I didn't look to see what additional features it provides. But a module should be able to use any installer, not just one of these two. Now, if a module specifies its type ( e.g. this is an example module that you can install now.
|
8064170 to
bde39f5
Compare
|
Hi @fisharebest, thank you so much for looking into this and creating the minimal installer – I really appreciate your effort! I'd like to share my thoughts on why I believe the VendorModuleService approach offers significant technical advantages over the installer-based approach. To clarify, this isn't a core change, but rather a core extension. The existing code remains unchanged; only an additional path for module discovery is added. A real-world use case: Development workflow. Developing and maintaining multiple interdependent modules using the modules_v4 approach is cumbersome in practice. My modules (fan-chart, pedigree-chart, descendants-chart) all depend on a common base package (webtrees-module-base). With modules_v4, any change to the base package requires manually copying or creating symbolic links – and synchronizing all modules is prone to errors. With the VendorModuleService, Composer manages the entire dependency graph automatically. A You can see this in action in my project https://github.com/magicsunday/webtrees-docker. There, the entire Webtrees stack (including custom modules) is managed through a single Established pattern in the PHP ecosystem: This approach follows the pattern used by major frameworks. For example, TYPO3 uses the package type
With the VendorModuleService, this workaround is unnecessary, as the Composer autoloader already knows the module's namespace.
I am happy to adapt the implementation if you have concerns about specific code sections. However, I am convinced that keeping the modules in |
9e17ce4 to
15d4318
Compare
Add
VendorModuleServicefor Composer-based Webtrees modules🚀 Feature: Vendor Module Support via Composer (
VendorModuleService)Overview
This PR introduces a new service class,
VendorModuleService, that allows Webtrees to seamlessly load modules installed via Composer.A key part of this feature is the introduction of a new Composer package type:
webtrees-module. This package type signals that a Composer package is a Webtrees extension, making it automatically discoverable and loadable by the Webtrees core.This modernizes module management and brings Webtrees closer in line with practices used by frameworks such as Symfony, Laravel, and TYPO3.
Why?
Currently, Webtrees modules are installed and managed manually in the
modules_v4directory. While functional, this approach has limitations:By enabling Composer-managed modules (via
webtrees-module), we provide:composer require vendor/package)This makes Webtrees more attractive to external developers and lowers the barrier for creating and sharing extensions.
How It Works
The
VendorModuleServiceleverages Composer’s InstalledVersions API to:webtrees-modulemodule.phpentrypointModuleServiceFlashMessagesInternally:
composer.json→"type": "webtrees-module"_mypackage_)Benefits
📦 Example
composer.jsonfor a Webtrees Module{ "name": "my-vendor/my-webtrees-module", "description": "An example Webtrees module distributed via Composer.", "type": "webtrees-module", "license": "GPL-3.0-or-later", "authors": [ { "name": "Your Name", "email": "you@example.com" } ], "require": { "php": ">=8.1", "fisharebest/webtrees": "^2.2" }, "autoload": { "psr-4": { "MyVendor\\MyWebtreesModule\\": "src/" } } }